Debian Codegraph @

debian/rust-vendor/aws-lc-sys/aws-lc/crypto/blake2/blake2_test.cc

raw
1 // Copyright (c) 2021, Google Inc.
2 // SPDX-License-Identifier: ISC
3
4 #include <openssl/blake2.h>
5
6 #include <gtest/gtest.h>
7
8 #include "../test/file_test.h"
9 #include "../test/test_util.h"
10
11 TEST(BLAKE2B256Test, ABC) {
12 // https://tools.ietf.org/html/rfc7693#appendix-A, except updated for the
13 // 256-bit hash output.
14 const uint8_t kExpected[] = {
15 0xbd, 0xdd, 0x81, 0x3c, 0x63, 0x42, 0x39, 0x72, 0x31, 0x71, 0xef,
16 0x3f, 0xee, 0x98, 0x57, 0x9b, 0x94, 0x96, 0x4e, 0x3b, 0xb1, 0xcb,
17 0x3e, 0x42, 0x72, 0x62, 0xc8, 0xc0, 0x68, 0xd5, 0x23, 0x19,
18 };
19
20 uint8_t digest[BLAKE2B256_DIGEST_LENGTH];
21 BLAKE2B256((const uint8_t *)"abc", 3, digest);
22 EXPECT_EQ(Bytes(kExpected), Bytes(digest));
23 }
24
25 TEST(BLAKE2B256Test, TestVectors) {
26 FileTestGTest("crypto/blake2/blake2b256_tests.txt", [](FileTest *t) {
27 std::vector<uint8_t> msg, expected;
28 ASSERT_TRUE(t->GetBytes(&msg, "IN"));
29 ASSERT_TRUE(t->GetBytes(&expected, "HASH"));
30
31 uint8_t digest[BLAKE2B256_DIGEST_LENGTH];
32 BLAKE2B256(msg.data(), msg.size(), digest);
33 EXPECT_EQ(Bytes(digest), Bytes(expected)) << msg.size();
34
35 OPENSSL_memset(digest, 0, sizeof(digest));
36 BLAKE2B_CTX b2b;
37 BLAKE2B256_Init(&b2b);
38 for (uint8_t b : msg) {
39 BLAKE2B256_Update(&b2b, &b, 1);
40 }
41 BLAKE2B256_Final(digest, &b2b);
42 EXPECT_EQ(Bytes(digest), Bytes(expected)) << msg.size();
43 });
44 }