aboutsummaryrefslogtreecommitdiff
path: root/tests/test-rpc_hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-rpc_hash.c')
-rw-r--r--tests/test-rpc_hash.c150
1 files changed, 145 insertions, 5 deletions
diff --git a/tests/test-rpc_hash.c b/tests/test-rpc_hash.c
index 24f8ede..51fa2be 100644
--- a/tests/test-rpc_hash.c
+++ b/tests/test-rpc_hash.c
@@ -4,8 +4,9 @@
* Test code for RPC interface to Cryptech hash cores.
*
* Authors: Rob Austein, Paul Selkirk
- * Copyright (c) 2015-2016, NORDUnet A/S
- * All rights reserved.
+ * Copyright (c) 2015-2016, NORDUnet A/S All rights reserved.
+ * Copyright: 2021, The Commons Conservancy Cryptech Project
+ * SPDX-License-Identifier: BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -17,9 +18,9 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * - Neither the name of the NORDUnet nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
+ * - Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -43,6 +44,21 @@
/* Usual NIST sample messages. */
+/* "" */
+static const uint8_t nist_512_empty[] = { /* 0 bytes */
+};
+
+static const uint8_t sha1_empty_digest[] = { /* 20 bytes */
+ 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, 0x32, 0x55, 0xbf, 0xef,
+ 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8, 0x07, 0x09
+};
+
+static const uint8_t sha256_empty_digest[] = { /* 32 bytes */
+ 0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8,
+ 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c,
+ 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55
+};
+
/* "abc" */
static const uint8_t nist_512_single[] = { /* 3 bytes */
0x61, 0x62, 0x63
@@ -79,6 +95,54 @@ static const uint8_t sha256_double_digest[] = { /* 32 bytes */
0xf6, 0xec, 0xed, 0xd4, 0x19, 0xdb, 0x06, 0xc1
};
+/* "" */
+static const uint8_t nist_1024_empty[] = { /* 0 bytes */
+};
+
+static const uint8_t sha384_empty_digest[] = { /* 48 bytes */
+ 0x38, 0xb0, 0x60, 0xa7, 0x51, 0xac, 0x96, 0x38, 0x4c, 0xd9, 0x32, 0x7e,
+ 0xb1, 0xb1, 0xe3, 0x6a, 0x21, 0xfd, 0xb7, 0x11, 0x14, 0xbe, 0x07, 0x43,
+ 0x4c, 0x0c, 0xc7, 0xbf, 0x63, 0xf6, 0xe1, 0xda, 0x27, 0x4e, 0xde, 0xbf,
+ 0xe7, 0x6f, 0x65, 0xfb, 0xd5, 0x1a, 0xd2, 0xf1, 0x48, 0x98, 0xb9, 0x5b
+};
+
+static const uint8_t sha512_empty_digest[] = { /* 64 bytes */
+ 0xcf, 0x83, 0xe1, 0x35, 0x7e, 0xef, 0xb8, 0xbd, 0xf1, 0x54, 0x28, 0x50,
+ 0xd6, 0x6d, 0x80, 0x07, 0xd6, 0x20, 0xe4, 0x05, 0x0b, 0x57, 0x15, 0xdc,
+ 0x83, 0xf4, 0xa9, 0x21, 0xd3, 0x6c, 0xe9, 0xce, 0x47, 0xd0, 0xd1, 0x3c,
+ 0x5d, 0x85, 0xf2, 0xb0, 0xff, 0x83, 0x18, 0xd2, 0x87, 0x7e, 0xec, 0x2f,
+ 0x63, 0xb9, 0x31, 0xbd, 0x47, 0x41, 0x7a, 0x81, 0xa5, 0x38, 0x32, 0x7a,
+ 0xf9, 0x27, 0xda, 0x3e
+};
+
+static const uint8_t sha3_224_empty_digest[] = { /* 28 bytes */
+ 0x6b, 0x4e, 0x03, 0x42, 0x36, 0x67, 0xdb, 0xb7, 0x3b, 0x6e, 0x15, 0x45,
+ 0x4f, 0x0e, 0xb1, 0xab, 0xd4, 0x59, 0x7f, 0x9a, 0x1b, 0x07, 0x8e, 0x3f,
+ 0x5b, 0x5a, 0x6b, 0xc7
+};
+
+static const uint8_t sha3_256_empty_digest[] = { /* 32 bytes */
+ 0xa7, 0xff, 0xc6, 0xf8, 0xbf, 0x1e, 0xd7, 0x66, 0x51, 0xc1, 0x47, 0x56,
+ 0xa0, 0x61, 0xd6, 0x62, 0xf5, 0x80, 0xff, 0x4d, 0xe4, 0x3b, 0x49, 0xfa,
+ 0x82, 0xd8, 0x0a, 0x4b, 0x80, 0xf8, 0x43, 0x4a
+};
+
+static const uint8_t sha3_384_empty_digest[] = { /* 48 bytes */
+ 0x0c, 0x63, 0xa7, 0x5b, 0x84, 0x5e, 0x4f, 0x7d, 0x01, 0x10, 0x7d, 0x85,
+ 0x2e, 0x4c, 0x24, 0x85, 0xc5, 0x1a, 0x50, 0xaa, 0xaa, 0x94, 0xfc, 0x61,
+ 0x99, 0x5e, 0x71, 0xbb, 0xee, 0x98, 0x3a, 0x2a, 0xc3, 0x71, 0x38, 0x31,
+ 0x26, 0x4a, 0xdb, 0x47, 0xfb, 0x6b, 0xd1, 0xe0, 0x58, 0xd5, 0xf0, 0x04
+};
+
+static const uint8_t sha3_512_empty_digest[] = { /* 64 bytes */
+ 0xa6, 0x9f, 0x73, 0xcc, 0xa2, 0x3a, 0x9a, 0xc5, 0xc8, 0xb5, 0x67, 0xdc,
+ 0x18, 0x5a, 0x75, 0x6e, 0x97, 0xc9, 0x82, 0x16, 0x4f, 0xe2, 0x58, 0x59,
+ 0xe0, 0xd1, 0xdc, 0xc1, 0x47, 0x5c, 0x80, 0xa6, 0x15, 0xb2, 0x12, 0x3a,
+ 0xf1, 0xf5, 0xf9, 0x4c, 0x11, 0xe3, 0xe9, 0x40, 0x2c, 0x3a, 0xc5, 0x58,
+ 0xf5, 0x00, 0x19, 0x9d, 0x95, 0xb6, 0xd3, 0xe3, 0x01, 0x75, 0x85, 0x86,
+ 0x28, 0x1d, 0xcd, 0x26
+};
+
/* "abc" */
static const uint8_t nist_1024_single[] = { /* 3 bytes */
0x61, 0x62, 0x63
@@ -112,6 +176,34 @@ static const uint8_t sha512_single_digest[] = { /* 64 bytes */
0xa5, 0x4c, 0xa4, 0x9f
};
+static const uint8_t sha3_224_single_digest[] = { /* 28 bytes */
+ 0xe6, 0x42, 0x82, 0x4c, 0x3f, 0x8c, 0xf2, 0x4a, 0xd0, 0x92, 0x34, 0xee,
+ 0x7d, 0x3c, 0x76, 0x6f, 0xc9, 0xa3, 0xa5, 0x16, 0x8d, 0x0c, 0x94, 0xad,
+ 0x73, 0xb4, 0x6f, 0xdf
+};
+
+static const uint8_t sha3_256_single_digest[] = { /* 32 bytes */
+ 0x3a, 0x98, 0x5d, 0xa7, 0x4f, 0xe2, 0x25, 0xb2, 0x04, 0x5c, 0x17, 0x2d,
+ 0x6b, 0xd3, 0x90, 0xbd, 0x85, 0x5f, 0x08, 0x6e, 0x3e, 0x9d, 0x52, 0x5b,
+ 0x46, 0xbf, 0xe2, 0x45, 0x11, 0x43, 0x15, 0x32
+};
+
+static const uint8_t sha3_384_single_digest[] = { /* 48 bytes */
+ 0xec, 0x01, 0x49, 0x82, 0x88, 0x51, 0x6f, 0xc9, 0x26, 0x45, 0x9f, 0x58,
+ 0xe2, 0xc6, 0xad, 0x8d, 0xf9, 0xb4, 0x73, 0xcb, 0x0f, 0xc0, 0x8c, 0x25,
+ 0x96, 0xda, 0x7c, 0xf0, 0xe4, 0x9b, 0xe4, 0xb2, 0x98, 0xd8, 0x8c, 0xea,
+ 0x92, 0x7a, 0xc7, 0xf5, 0x39, 0xf1, 0xed, 0xf2, 0x28, 0x37, 0x6d, 0x25
+};
+
+static const uint8_t sha3_512_single_digest[] = { /* 64 bytes */
+ 0xb7, 0x51, 0x85, 0x0b, 0x1a, 0x57, 0x16, 0x8a, 0x56, 0x93, 0xcd, 0x92,
+ 0x4b, 0x6b, 0x09, 0x6e, 0x08, 0xf6, 0x21, 0x82, 0x74, 0x44, 0xf7, 0x0d,
+ 0x88, 0x4f, 0x5d, 0x02, 0x40, 0xd2, 0x71, 0x2e, 0x10, 0xe1, 0x16, 0xe9,
+ 0x19, 0x2a, 0xf3, 0xc9, 0x1a, 0x7e, 0xc5, 0x76, 0x47, 0xe3, 0x93, 0x40,
+ 0x57, 0x34, 0x0b, 0x4c, 0xf4, 0x08, 0xd5, 0xa5, 0x65, 0x92, 0xf8, 0x27,
+ 0x4e, 0xec, 0x53, 0xf0
+};
+
/* "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
"hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" */
static const uint8_t nist_1024_double[] = { /* 112 bytes */
@@ -155,6 +247,34 @@ static const uint8_t sha512_double_digest[] = { /* 64 bytes */
0x87, 0x4b, 0xe9, 0x09
};
+static const uint8_t sha3_224_double_digest[] = { /* 28 bytes */
+ 0x54, 0x3e, 0x68, 0x68, 0xe1, 0x66, 0x6c, 0x1a, 0x64, 0x36, 0x30, 0xdf,
+ 0x77, 0x36, 0x7a, 0xe5, 0xa6, 0x2a, 0x85, 0x07, 0x0a, 0x51, 0xc1, 0x4c,
+ 0xbf, 0x66, 0x5c, 0xbc
+};
+
+static const uint8_t sha3_256_double_digest[] = { /* 32 bytes */
+ 0x91, 0x6f, 0x60, 0x61, 0xfe, 0x87, 0x97, 0x41, 0xca, 0x64, 0x69, 0xb4,
+ 0x39, 0x71, 0xdf, 0xdb, 0x28, 0xb1, 0xa3, 0x2d, 0xc3, 0x6c, 0xb3, 0x25,
+ 0x4e, 0x81, 0x2b, 0xe2, 0x7a, 0xad, 0x1d, 0x18
+};
+
+static const uint8_t sha3_384_double_digest[] = { /* 48 bytes */
+ 0x79, 0x40, 0x7d, 0x3b, 0x59, 0x16, 0xb5, 0x9c, 0x3e, 0x30, 0xb0, 0x98,
+ 0x22, 0x97, 0x47, 0x91, 0xc3, 0x13, 0xfb, 0x9e, 0xcc, 0x84, 0x9e, 0x40,
+ 0x6f, 0x23, 0x59, 0x2d, 0x04, 0xf6, 0x25, 0xdc, 0x8c, 0x70, 0x9b, 0x98,
+ 0xb4, 0x3b, 0x38, 0x52, 0xb3, 0x37, 0x21, 0x61, 0x79, 0xaa, 0x7f, 0xc7
+};
+
+static const uint8_t sha3_512_double_digest[] = { /* 64 bytes */
+ 0xaf, 0xeb, 0xb2, 0xef, 0x54, 0x2e, 0x65, 0x79, 0xc5, 0x0c, 0xad, 0x06,
+ 0xd2, 0xe5, 0x78, 0xf9, 0xf8, 0xdd, 0x68, 0x81, 0xd7, 0xdc, 0x82, 0x4d,
+ 0x26, 0x36, 0x0f, 0xee, 0xbf, 0x18, 0xa4, 0xfa, 0x73, 0xe3, 0x26, 0x11,
+ 0x22, 0x94, 0x8e, 0xfc, 0xfd, 0x49, 0x2e, 0x74, 0xe8, 0x2e, 0x21, 0x89,
+ 0xed, 0x0f, 0xb4, 0x40, 0xd1, 0x87, 0xf3, 0x82, 0x27, 0x0c, 0xb4, 0x55,
+ 0xf2, 0x1d, 0xd1, 0x85
+};
+
/* HMAC-SHA-1 test cases from RFC 2202. */
static const uint8_t hmac_sha1_tc_1_key[] = { /* 20 bytes */
@@ -656,9 +776,11 @@ int main (int argc, char *argv[])
ok &= hal_rpc_client_init();
+ ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA1, nist_512_empty, sha1_empty_digest, "SHA-1 empty block");
ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA1, nist_512_single, sha1_single_digest, "SHA-1 single block");
ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA1, nist_512_double, sha1_double_digest, "SHA-1 double block");
+ ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA256, nist_512_empty, sha256_empty_digest, "SHA-256 empty block");
ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA256, nist_512_single, sha256_single_digest, "SHA-256 single block");
ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA256, nist_512_double, sha256_double_digest, "SHA-256 double block");
@@ -668,12 +790,30 @@ int main (int argc, char *argv[])
ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA512_256, nist_1024_single, sha512_256_single_digest, "SHA-512/256 single block");
ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA512_256, nist_1024_double, sha512_256_double_digest, "SHA-512/256 double block");
+ ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA384, nist_1024_empty, sha384_empty_digest, "SHA-384 empty block");
ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA384, nist_1024_single, sha384_single_digest, "SHA-384 single block");
ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA384, nist_1024_double, sha384_double_digest, "SHA-384 double block");
+ ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA512, nist_1024_empty, sha512_empty_digest, "SHA-512 empty block");
ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA512, nist_1024_single, sha512_single_digest, "SHA-512 single block");
ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA512, nist_1024_double, sha512_double_digest, "SHA-512 double block");
+ ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA3_224, nist_1024_empty, sha3_224_empty_digest, "SHA3-224 empty block");
+ ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA3_224, nist_1024_single, sha3_224_single_digest, "SHA3-224 single block");
+ ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA3_224, nist_1024_double, sha3_224_double_digest, "SHA3-224 double block");
+
+ ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA3_256, nist_1024_empty, sha3_256_empty_digest, "SHA3-256 empty block");
+ ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA3_256, nist_1024_single, sha3_256_single_digest, "SHA3-256 single block");
+ ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA3_256, nist_1024_double, sha3_256_double_digest, "SHA3-256 double block");
+
+ ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA3_384, nist_1024_empty, sha3_384_empty_digest, "SHA3-384 empty block");
+ ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA3_384, nist_1024_single, sha3_384_single_digest, "SHA3-384 single block");
+ ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA3_384, nist_1024_double, sha3_384_double_digest, "SHA3-384 double block");
+
+ ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA3_512, nist_1024_empty, sha3_512_empty_digest, "SHA3-512 empty block");
+ ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA3_512, nist_1024_single, sha3_512_single_digest, "SHA3-512 single block");
+ ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA3_512, nist_1024_double, sha3_512_double_digest, "SHA3-512 double block");
+
ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA1, hmac_sha1_tc_1_key, hmac_sha1_tc_1_data, hmac_sha1_tc_1_result_sha1, "HMAC-SHA-1 test case 1");
ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA1, hmac_sha1_tc_2_key, hmac_sha1_tc_2_data, hmac_sha1_tc_2_result_sha1, "HMAC-SHA-1 test case 2");
ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA1, hmac_sha1_tc_3_key, hmac_sha1_tc_3_data, hmac_sha1_tc_3_result_sha1, "HMAC-SHA-1 test case 3");