chromium/components/webcrypto/algorithms/aes_cbc_unittest.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include <limits.h>
#include <stddef.h>
#include <stdint.h>

#include <memory>
#include <utility>

#include "base/containers/span.h"
#include "base/values.h"
#include "components/webcrypto/algorithm_dispatch.h"
#include "components/webcrypto/algorithms/test_helpers.h"
#include "components/webcrypto/status.h"
#include "third_party/blink/public/platform/web_crypto_algorithm_params.h"
#include "third_party/blink/public/platform/web_crypto_key_algorithm.h"

namespace webcrypto {

namespace {

// Creates an AES-CBC algorithm.
blink::WebCryptoAlgorithm CreateAesCbcAlgorithm(
    const std::vector<uint8_t>& iv) {}

blink::WebCryptoAlgorithm CreateAesCbcKeyGenAlgorithm(
    uint16_t key_length_bits) {}

blink::WebCryptoKey GetTestAesCbcKey() {}

blink::WebCryptoKey ImportRawKey(const std::vector<uint8_t>& key_bytes) {}

std::vector<uint8_t> EncryptOrDie(blink::WebCryptoKey key,
                                  const std::vector<uint8_t>& iv,
                                  const std::vector<uint8_t>& plaintext) {}

std::vector<uint8_t> DecryptOrDie(blink::WebCryptoKey key,
                                  const std::vector<uint8_t>& iv,
                                  const std::vector<uint8_t>& ciphertext) {}

std::string EncryptMustFail(blink::WebCryptoKey key,
                            const std::vector<uint8_t>& iv,
                            const std::vector<uint8_t>& plaintext) {}

std::string DecryptMustFail(blink::WebCryptoKey key,
                            const std::vector<uint8_t>& iv,
                            const std::vector<uint8_t>& ciphertext) {}

class WebCryptoAesCbcTest : public WebCryptoTestBase {};

TEST_F(WebCryptoAesCbcTest, InputTooLarge) {}

TEST_F(WebCryptoAesCbcTest, ExportKeyUnsupportedFormat) {}

struct AesCbcKnownAnswer {};

const AesCbcKnownAnswer kAesCbcKnownAnswers[] =;

TEST_F(WebCryptoAesCbcTest, KnownAnswers) {}

TEST_F(WebCryptoAesCbcTest, IVIsWrongSize) {}

TEST_F(WebCryptoAesCbcTest, ImportShortKey) {}

TEST_F(WebCryptoAesCbcTest, ImportKeyWrongFormat) {}

TEST_F(WebCryptoAesCbcTest, ImportAes192Key) {}

TEST_F(WebCryptoAesCbcTest, DecryptTruncatedCiphertextFails) {}

struct JwkImportFailureTest {};

const JwkImportFailureTest kJwkImportFailureTests[] =;

TEST_F(WebCryptoAesCbcTest, JwkImportFailures) {}

// TODO(eroman): Do this same test for AES-GCM, AES-KW, AES-CTR ?
TEST_F(WebCryptoAesCbcTest, GenerateKeyIsRandom) {}

TEST_F(WebCryptoAesCbcTest, GenerateKeyBadLength) {}

TEST_F(WebCryptoAesCbcTest, ImportKeyEmptyUsage) {}

// If key_ops is specified but empty, no key usages are allowed for the key.
TEST_F(WebCryptoAesCbcTest, ImportKeyJwkEmptyKeyOps) {}

// If key_ops is missing, then any key usages can be specified.
TEST_F(WebCryptoAesCbcTest, ImportKeyJwkNoKeyOps) {}

TEST_F(WebCryptoAesCbcTest, ImportKeyJwkKeyOpsEncryptDecrypt) {}

// Test failure if input usage is NOT a strict subset of the JWK usage.
TEST_F(WebCryptoAesCbcTest, ImportKeyJwkKeyOpsNotSuperset) {}

TEST_F(WebCryptoAesCbcTest, ImportKeyJwkUseEnc) {}

TEST_F(WebCryptoAesCbcTest, ImportJwkUnknownKeyOps) {}

TEST_F(WebCryptoAesCbcTest, ImportJwkInvalidJson) {}

// Fail on inconsistent key_ops - asking for "encrypt" however JWK contains
// only "foo".
TEST_F(WebCryptoAesCbcTest, ImportJwkKeyOpsLacksUsages) {}

TEST_F(WebCryptoAesCbcTest, ImportExportJwk) {}

// 192-bit AES is intentionally unsupported (http://crbug.com/533699).
TEST_F(WebCryptoAesCbcTest, GenerateAesCbc192) {}

// 192-bit AES is intentionally unsupported (http://crbug.com/533699).
TEST_F(WebCryptoAesCbcTest, UnwrapAesCbc192) {}

// Try importing an AES-CBC key with unsupported key usages using raw
// format. AES-CBC keys support the following usages:
//   'encrypt', 'decrypt', 'wrapKey', 'unwrapKey'
TEST_F(WebCryptoAesCbcTest, ImportKeyBadUsage_Raw) {}

// Generate an AES-CBC key with invalid usages. AES-CBC supports:
//   'encrypt', 'decrypt', 'wrapKey', 'unwrapKey'
TEST_F(WebCryptoAesCbcTest, GenerateKeyBadUsages) {}

// Generate an AES-CBC key with no usages.
TEST_F(WebCryptoAesCbcTest, GenerateKeyEmptyUsages) {}

// Generate an AES-CBC key and an RSA key pair. Use the AES-CBC key to wrap the
// key pair (using SPKI format for public key, PKCS8 format for private key).
// Then unwrap the wrapped key pair and verify that the key data is the same.
TEST_F(WebCryptoAesCbcTest, WrapUnwrapRoundtripSpkiPkcs8) {}

}  // namespace

}  // namespace webcrypto