1
0
mirror of https://github.com/wolfSSL/wolfssl.git synced 2026-10-24 04:09:07 +03:00

Test the SHA-512 DRBG with personalization and additional input

This commit is contained in:
kaleb-himes
2026-10-19 05:54:37 -06:00
committed by Paul Adelsbach
parent 4e9a5576b1
commit 1069f95bc0

View File

@@ -30579,6 +30579,197 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void)
if (XMEMCMP(sha512test2Output, output512, sizeof(output512)) != 0)
return WC_TEST_RET_ENC_NC;
/* Tests 3 and 4: SP 800-90A 11.3.2 and 11.3.3 with a personalization
* string and additional input, without and with reseed. */
{
/* NIST CAVP drbgvectors_no_reseed Hash_DRBG.rsp line 8592,
* [SHA-512] perso and addl 256 bits, COUNT = 0 */
static const byte sha512_paNoReseed_entropy[] = {
/* EntropyInput (32 bytes) */
0x31, 0xe8, 0xd6, 0xfb, 0xdc, 0x90, 0x26, 0xb0,
0x70, 0x84, 0x05, 0xc2, 0x0b, 0x55, 0x8f, 0xcc,
0x0a, 0x10, 0x7f, 0x3f, 0xdc, 0x83, 0x6f, 0xe0,
0x56, 0xf0, 0x20, 0xdf, 0x30, 0xd9, 0xdc, 0x57
};
static const byte sha512_paNoReseed_nonce[] = {
/* Nonce (16 bytes) */
0x2b, 0x8b, 0xba, 0xb9, 0xb4, 0x86, 0xab, 0xb6,
0x59, 0xc4, 0xae, 0x8f, 0xf5, 0x97, 0x8e, 0x22
};
static const byte sha512_paNoReseed_perso[] = {
/* PersonalizationString (32 bytes) */
0x94, 0x9e, 0xb7, 0x53, 0x76, 0x28, 0x69, 0xaa,
0x5e, 0xa0, 0xce, 0x72, 0x55, 0x23, 0x59, 0x5f,
0x9b, 0xc9, 0xb2, 0x19, 0x73, 0x51, 0x13, 0xe7,
0x1f, 0xea, 0xb2, 0x28, 0xd0, 0x87, 0x2c, 0x38
};
static const byte sha512_paNoReseed_addlA[] = {
/* AdditionalInput (32 bytes) */
0x88, 0xf1, 0x18, 0x0d, 0x4e, 0xf5, 0x64, 0x31,
0x52, 0x80, 0xa9, 0x69, 0x2f, 0x10, 0x7e, 0xd9,
0xc0, 0x63, 0x9d, 0x79, 0xbb, 0x70, 0x40, 0xdf,
0xc3, 0xb7, 0xd5, 0x8b, 0xf2, 0x4e, 0xf8, 0xf5
};
static const byte sha512_paNoReseed_addlB[] = {
/* AdditionalInput (32 bytes) */
0xf4, 0xfc, 0x8a, 0x26, 0xe0, 0xad, 0x18, 0x18,
0x38, 0xf1, 0x39, 0x9f, 0xe5, 0xb8, 0xa4, 0xb8,
0x66, 0x70, 0xe9, 0x2a, 0xb9, 0x2b, 0x2c, 0x4d,
0xaf, 0x39, 0x13, 0x47, 0x07, 0x24, 0xd3, 0xf2
};
static const byte sha512_paNoReseed_output[] = {
/* ReturnedBits (256 bytes) */
0x10, 0x50, 0x96, 0x41, 0x33, 0x2a, 0x4d, 0x72,
0xa3, 0xc5, 0x93, 0x65, 0x12, 0xc3, 0x7c, 0xb9,
0xab, 0x98, 0x74, 0x69, 0x39, 0x02, 0xee, 0x4c,
0x76, 0xe9, 0x63, 0x67, 0x56, 0x27, 0xef, 0x86,
0xaa, 0x2e, 0x7d, 0x70, 0x29, 0xa1, 0x52, 0xb8,
0x00, 0x07, 0x2f, 0xc5, 0x3e, 0xeb, 0x6b, 0x41,
0xd1, 0x2f, 0x48, 0x1c, 0xde, 0x99, 0xb4, 0x67,
0xda, 0xc3, 0x48, 0x68, 0x36, 0xf6, 0xe1, 0x46,
0xe9, 0xa7, 0x9d, 0x3f, 0xb9, 0x0d, 0x9b, 0x26,
0xf2, 0x13, 0xdd, 0xbf, 0xac, 0x59, 0x0c, 0xa0,
0x83, 0xed, 0x83, 0xfd, 0xe4, 0x92, 0x43, 0x95,
0xd2, 0x5b, 0x64, 0x5b, 0x96, 0xa6, 0x98, 0x3e,
0x65, 0xfd, 0x66, 0x2c, 0xae, 0x66, 0x11, 0x2e,
0xbf, 0xa9, 0x90, 0xf0, 0x9b, 0x86, 0xb0, 0x12,
0x70, 0xb7, 0xf0, 0xef, 0x35, 0xf1, 0x83, 0xeb,
0x01, 0xff, 0xcb, 0xd7, 0xd5, 0xec, 0x6a, 0xdc,
0x48, 0x39, 0xcf, 0x38, 0x14, 0xda, 0xc8, 0x58,
0xe0, 0x13, 0xc6, 0xd7, 0x95, 0x28, 0xef, 0x27,
0x3d, 0xd8, 0x37, 0x24, 0xcc, 0xdc, 0x82, 0xb7,
0x3d, 0xc6, 0x36, 0x98, 0xfc, 0xf8, 0xef, 0x09,
0x24, 0xf2, 0x7b, 0x6a, 0x49, 0xd6, 0xd3, 0x8f,
0x0c, 0xe2, 0x61, 0xaa, 0x5a, 0x0a, 0x88, 0x77,
0x9e, 0x47, 0xa4, 0x13, 0xc2, 0x9e, 0x1d, 0x7d,
0x20, 0xe4, 0xab, 0x91, 0x4b, 0xba, 0xbd, 0x5e,
0x6e, 0x02, 0x41, 0xcf, 0x53, 0x26, 0x3a, 0x8e,
0xfa, 0x32, 0x1b, 0x4a, 0x63, 0x2e, 0xb0, 0x62,
0xb2, 0x55, 0xc0, 0xce, 0x5a, 0x08, 0x33, 0x11,
0x41, 0x61, 0xdd, 0x07, 0x3d, 0xd0, 0x37, 0x96,
0x7a, 0x1f, 0x03, 0xda, 0xf2, 0xdd, 0x7e, 0x92,
0x7b, 0x80, 0x1b, 0x40, 0xe6, 0x2f, 0x26, 0xc0,
0x87, 0x2e, 0xa1, 0x00, 0x13, 0x28, 0x07, 0x65,
0x02, 0x32, 0x12, 0x6a, 0xa8, 0xf2, 0x9d, 0x70
};
/* NIST CAVP drbgvectors_pr_false Hash_DRBG.rsp line 10602,
* [SHA-512] perso and addl 256 bits, COUNT = 0 */
static const byte sha512_paReseed_entropy[] = {
/* EntropyInput (32 bytes) */
0x4b, 0x23, 0x59, 0x5b, 0x0a, 0x36, 0x40, 0xcf,
0xab, 0xb0, 0xec, 0x34, 0xdf, 0x6a, 0x61, 0x33,
0x08, 0xb0, 0x44, 0x84, 0x88, 0xa5, 0xd9, 0xff,
0x99, 0xda, 0x42, 0x78, 0xe0, 0x72, 0xeb, 0x34
};
static const byte sha512_paReseed_nonce[] = {
/* Nonce (16 bytes) */
0x8e, 0x69, 0x6b, 0xff, 0xd9, 0xca, 0x3a, 0x71,
0xd2, 0xe2, 0xf0, 0x5e, 0x60, 0x0c, 0x83, 0x64
};
static const byte sha512_paReseed_perso[] = {
/* PersonalizationString (32 bytes) */
0x01, 0x0b, 0xa9, 0x3e, 0xa6, 0x8a, 0x3d, 0x4a,
0x20, 0x0e, 0x51, 0x45, 0x85, 0x9e, 0x29, 0x9c,
0x5b, 0x53, 0x49, 0xb7, 0x64, 0x5f, 0xb5, 0xbb,
0xca, 0xd6, 0x87, 0xab, 0xa7, 0xd6, 0x73, 0x13
};
static const byte sha512_paReseed_entropyReseed[] = {
/* EntropyInputReseed (32 bytes) */
0x04, 0xde, 0x4b, 0xab, 0xdb, 0xe1, 0x43, 0xbd,
0xe9, 0x9a, 0xa4, 0x45, 0x2f, 0x9a, 0xa4, 0x3b,
0x0a, 0x16, 0x4e, 0xb9, 0x27, 0x55, 0x5c, 0x04,
0x96, 0xaa, 0x0f, 0xc9, 0x32, 0x8a, 0x52, 0x1c
};
static const byte sha512_paReseed_addlReseed[] = {
/* AdditionalInputReseed (32 bytes) */
0x2b, 0x0c, 0x7c, 0x3e, 0xfb, 0x36, 0xb7, 0x1b,
0x91, 0x7a, 0x44, 0x08, 0x6d, 0x16, 0x83, 0x13,
0x67, 0x5b, 0x42, 0x6b, 0x17, 0xc5, 0xab, 0x3d,
0x0e, 0xb6, 0xaf, 0x75, 0x3f, 0x60, 0x40, 0xe0
};
static const byte sha512_paReseed_addlA[] = {
/* AdditionalInput (32 bytes) */
0xd0, 0xb7, 0xd1, 0xd1, 0x2a, 0xb1, 0x5d, 0x3b,
0xba, 0x8f, 0x4e, 0xba, 0x07, 0xfe, 0xe0, 0x97,
0x48, 0x38, 0x96, 0x2b, 0x24, 0x7b, 0xe4, 0x80,
0x68, 0x3b, 0x8e, 0x3d, 0x4a, 0x91, 0x03, 0x3a
};
static const byte sha512_paReseed_addlB[] = {
/* AdditionalInput (32 bytes) */
0x66, 0xc7, 0x8c, 0xa1, 0x2e, 0x45, 0xbd, 0xca,
0x00, 0x3b, 0x49, 0xcb, 0x64, 0x40, 0xb9, 0x77,
0xdd, 0x85, 0xb1, 0x67, 0xe7, 0xc8, 0x03, 0x89,
0x0e, 0xd1, 0xa7, 0x36, 0x66, 0xea, 0xa8, 0x69
};
static const byte sha512_paReseed_output[] = {
/* ReturnedBits (256 bytes) */
0x40, 0x08, 0xcb, 0xd8, 0x28, 0x1d, 0xc8, 0x2f,
0xd6, 0xc3, 0x68, 0xf6, 0x50, 0xef, 0x26, 0x09,
0xbb, 0x77, 0x1e, 0x80, 0xc6, 0x3d, 0x47, 0x8a,
0x77, 0xfa, 0x93, 0x82, 0x48, 0xdc, 0xbb, 0x8b,
0x79, 0xe5, 0x4e, 0xad, 0x02, 0x65, 0xf6, 0xff,
0x1e, 0xbf, 0xaf, 0xe4, 0xe3, 0x87, 0xc6, 0xe2,
0x7d, 0xf9, 0xf0, 0x3e, 0x4a, 0x52, 0x25, 0xe8,
0x6a, 0x44, 0x36, 0xe5, 0x6e, 0xbf, 0x03, 0xb3,
0xbe, 0x2c, 0xfb, 0xcb, 0x49, 0xc8, 0x9c, 0x92,
0xec, 0x1d, 0xfa, 0x5e, 0xe4, 0x45, 0xdd, 0x4f,
0x6f, 0x64, 0xe0, 0x2a, 0x24, 0x23, 0xa0, 0xb1,
0x8e, 0xbd, 0x02, 0xee, 0xc5, 0x2f, 0x5c, 0xc2,
0x1b, 0xc3, 0x56, 0x5e, 0x79, 0x6b, 0x3d, 0xed,
0x65, 0x52, 0xf1, 0xb5, 0xa5, 0x74, 0xa2, 0x01,
0xc3, 0xb1, 0x10, 0x18, 0x22, 0x28, 0x06, 0xf9,
0x61, 0x8d, 0x23, 0xd7, 0x7f, 0xd0, 0x2d, 0xb8,
0x79, 0xcf, 0x87, 0xfe, 0x24, 0xed, 0x7b, 0xa1,
0x1b, 0x3b, 0x10, 0x8b, 0x55, 0x96, 0x33, 0xdb,
0x1f, 0x95, 0xc5, 0x12, 0x1b, 0x28, 0x01, 0x1a,
0xa4, 0xdd, 0x20, 0x39, 0x9b, 0xd4, 0x97, 0x8e,
0x1f, 0x8b, 0x88, 0x80, 0xc3, 0x33, 0xa4, 0x7f,
0xf1, 0x75, 0x06, 0x79, 0xbf, 0x28, 0xd3, 0x29,
0x34, 0x7b, 0x26, 0xd3, 0x47, 0xaa, 0xe9, 0x0e,
0xe5, 0x62, 0xae, 0x80, 0x29, 0x57, 0x9c, 0xbe,
0x03, 0x36, 0xe0, 0x66, 0xd6, 0xb8, 0xba, 0x5e,
0x01, 0x69, 0xfe, 0xc8, 0x04, 0xc3, 0x01, 0x89,
0xa4, 0x43, 0x4c, 0x1b, 0xf8, 0xa5, 0xb0, 0xa2,
0x49, 0x95, 0x1d, 0x3d, 0x89, 0x55, 0x4d, 0xa3,
0x8f, 0xf0, 0x75, 0x1b, 0x8b, 0x1f, 0xef, 0x9a,
0xe1, 0x8a, 0x0a, 0xa2, 0xbc, 0x47, 0x77, 0x36,
0xd1, 0x99, 0xa0, 0x6f, 0x61, 0xd4, 0x00, 0x03,
0x9a, 0x4c, 0xc0, 0x38, 0x69, 0xbb, 0x10, 0xca
};
ret = wc_RNG_HealthTest_SHA512_ex(0,
sha512_paNoReseed_nonce, sizeof(sha512_paNoReseed_nonce),
sha512_paNoReseed_perso, sizeof(sha512_paNoReseed_perso),
sha512_paNoReseed_entropy,
sizeof(sha512_paNoReseed_entropy), NULL, 0,
sha512_paNoReseed_addlA, sizeof(sha512_paNoReseed_addlA),
sha512_paNoReseed_addlB, sizeof(sha512_paNoReseed_addlB),
output512, sizeof(output512), HEAP_HINT, devId);
if (ret != 0)
return WC_TEST_RET_ENC_EC(ret);
if (XMEMCMP(sha512_paNoReseed_output, output512,
sizeof(output512)) != 0)
return WC_TEST_RET_ENC_NC;
ret = wc_RNG_HealthTest_SHA512_ex2(0,
sha512_paReseed_nonce, sizeof(sha512_paReseed_nonce),
sha512_paReseed_perso, sizeof(sha512_paReseed_perso),
sha512_paReseed_entropy, sizeof(sha512_paReseed_entropy),
sha512_paReseed_entropyReseed,
sizeof(sha512_paReseed_entropyReseed), NULL, 0,
sha512_paReseed_addlA, sizeof(sha512_paReseed_addlA),
sha512_paReseed_addlB, sizeof(sha512_paReseed_addlB),
sha512_paReseed_addlReseed,
sizeof(sha512_paReseed_addlReseed),
output512, sizeof(output512), HEAP_HINT, devId);
if (ret != 0)
return WC_TEST_RET_ENC_EC(ret);
if (XMEMCMP(sha512_paReseed_output, output512,
sizeof(output512)) != 0)
return WC_TEST_RET_ENC_NC;
}
}
#endif /* WOLFSSL_DRBG_SHA512 && !HAVE_SELFTEST && FIPS v7+ */