chromium/components/webcrypto/algorithms/hmac_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/check.h"
#include "base/containers/contains.h"
#include "base/containers/flat_set.h"
#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 "testing/gtest/include/gtest/gtest.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 HMAC algorithm whose parameters struct is compatible with key
// generation. It is an error to call this with a hash_id that is not a SHA*.
// The key_length_bits parameter is optional, with zero meaning unspecified.
blink::WebCryptoAlgorithm CreateHmacKeyGenAlgorithm(
    blink::WebCryptoAlgorithmId hash_id,
    unsigned int key_length_bits) {}

blink::WebCryptoAlgorithm CreateHmacImportAlgorithmWithLength(
    blink::WebCryptoAlgorithmId hash_id,
    unsigned int length_bits) {}

blink::WebCryptoKey GenerateHmacKey(blink::WebCryptoAlgorithmId hash,
                                    size_t key_length_bits) {}

class WebCryptoHmacTest : public WebCryptoTestBase {};

struct HmacKnownAnswer {};

const HmacKnownAnswer kHmacKnownAnswers[] =;

blink::WebCryptoKey HmacKeyFromHexBytes(blink::WebCryptoAlgorithmId hash,
                                        const char* key) {}

std::vector<uint8_t> BytesFromHmacKey(blink::WebCryptoKey key) {}

std::vector<uint8_t> HmacSign(blink::WebCryptoKey key,
                              const std::vector<uint8_t>& message) {}

bool HmacVerify(blink::WebCryptoKey key,
                const std::vector<uint8_t>& message,
                const std::vector<uint8_t>& hmac) {}

TEST_F(WebCryptoHmacTest, KnownAnswers) {}

TEST_F(WebCryptoHmacTest, GeneratedKeysHaveExpectedProperties) {}

TEST_F(WebCryptoHmacTest, GeneratedKeysAreRandomIsh) {}

// If the key length is not provided, then the block size is used.
TEST_F(WebCryptoHmacTest, GeneratedKeysDefaultToBlockSize) {}

TEST_F(WebCryptoHmacTest, Generating1BitKeyWorks) {}

TEST_F(WebCryptoHmacTest, GenerateKeyEmptyUsage) {}

TEST_F(WebCryptoHmacTest, ImportKeyEmptyUsage) {}

TEST_F(WebCryptoHmacTest, ImportKeyJwkKeyOpsSignVerify) {}

// Test 'use' inconsistent with 'key_ops'.
TEST_F(WebCryptoHmacTest, ImportKeyJwkUseInconsisteWithKeyOps) {}

// Test JWK composite 'sig' use
TEST_F(WebCryptoHmacTest, ImportKeyJwkUseSig) {}

TEST_F(WebCryptoHmacTest, ImportJwkInputConsistency) {}

TEST_F(WebCryptoHmacTest, ImportJwkHappy) {}

TEST_F(WebCryptoHmacTest, ImportExportJwk) {}

TEST_F(WebCryptoHmacTest, ExportJwkEmptyKey) {}

// Imports an HMAC key contaning no byte data.
TEST_F(WebCryptoHmacTest, ImportRawEmptyKey) {}

// Imports an HMAC key contaning 1 byte data, however the length was set to 0.
TEST_F(WebCryptoHmacTest, ImportRawKeyWithZeroLength) {}

// Import a huge hmac key (UINT_MAX bytes).
TEST_F(WebCryptoHmacTest, ImportRawKeyTooLarge) {}

// Import an HMAC key with 120 bits of data, however request 128 bits worth.
TEST_F(WebCryptoHmacTest, ImportRawKeyLengthTooLarge) {}

// Import an HMAC key with 128 bits of data, however request 120 bits worth.
TEST_F(WebCryptoHmacTest, ImportRawKeyLengthTooSmall) {}

// Import an HMAC key with 16 bits of data and request a 12 bit key, using the
// "raw" format.
TEST_F(WebCryptoHmacTest, ImportRawKeyTruncation) {}

// The same test as above, but using the JWK format.
TEST_F(WebCryptoHmacTest, ImportJwkKeyTruncation) {}

}  // namespace

}  // namespace webcrypto