From 02879299c96e02e0ad6093d86b04468ab89d3cfe Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sun, 12 Apr 2015 15:53:39 +0100 Subject: [crypto] Add SHA-384 algorithm SHA-384 is almost identical to SHA-512, with differing initial hash values and a truncated output length. This implementation has been verified using the NIST SHA-384 test vectors. Signed-off-by: Michael Brown --- src/tests/sha512_test.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'src/tests') diff --git a/src/tests/sha512_test.c b/src/tests/sha512_test.c index f97e96e9..80dc2f4e 100644 --- a/src/tests/sha512_test.c +++ b/src/tests/sha512_test.c @@ -25,11 +25,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); /** @file * - * SHA-512 tests + * SHA-512 family tests * * NIST test vectors are taken from * * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA512.pdf + * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA384.pdf * */ @@ -73,8 +74,35 @@ DIGEST_TEST ( sha512_nist_abc_stu, &sha512_algorithm, DIGEST_NIST_ABC_STU, 0x26, 0x54, 0x5e, 0x96, 0xe5, 0x5b, 0x87, 0x4b, 0xe9, 0x09 ) ); +/* Empty test vector (digest obtained from "sha384sum /dev/null") */ +DIGEST_TEST ( sha384_empty, &sha384_algorithm, DIGEST_EMPTY, + DIGEST ( 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 ) ); + +/* NIST test vector "abc" */ +DIGEST_TEST ( sha384_nist_abc, &sha384_algorithm, DIGEST_NIST_ABC, + DIGEST ( 0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b, 0xb5, + 0xa0, 0x3d, 0x69, 0x9a, 0xc6, 0x50, 0x07, 0x27, 0x2c, + 0x32, 0xab, 0x0e, 0xde, 0xd1, 0x63, 0x1a, 0x8b, 0x60, + 0x5a, 0x43, 0xff, 0x5b, 0xed, 0x80, 0x86, 0x07, 0x2b, + 0xa1, 0xe7, 0xcc, 0x23, 0x58, 0xba, 0xec, 0xa1, 0x34, + 0xc8, 0x25, 0xa7 ) ); + +/* NIST test vector "abc...stu" */ +DIGEST_TEST ( sha384_nist_abc_stu, &sha384_algorithm, DIGEST_NIST_ABC_STU, + DIGEST ( 0x09, 0x33, 0x0c, 0x33, 0xf7, 0x11, 0x47, 0xe8, 0x3d, + 0x19, 0x2f, 0xc7, 0x82, 0xcd, 0x1b, 0x47, 0x53, 0x11, + 0x1b, 0x17, 0x3b, 0x3b, 0x05, 0xd2, 0x2f, 0xa0, 0x80, + 0x86, 0xe3, 0xb0, 0xf7, 0x12, 0xfc, 0xc7, 0xc7, 0x1a, + 0x55, 0x7e, 0x2d, 0xb9, 0x66, 0xc3, 0xe9, 0xfa, 0x91, + 0x74, 0x60, 0x39 ) ); + /** - * Perform SHA-512 self-test + * Perform SHA-512 family self-test * */ static void sha512_test_exec ( void ) { @@ -83,13 +111,18 @@ static void sha512_test_exec ( void ) { digest_ok ( &sha512_empty ); digest_ok ( &sha512_nist_abc ); digest_ok ( &sha512_nist_abc_stu ); + digest_ok ( &sha384_empty ); + digest_ok ( &sha384_nist_abc ); + digest_ok ( &sha384_nist_abc_stu ); /* Speed tests */ DBG ( "SHA512 required %ld cycles per byte\n", digest_cost ( &sha512_algorithm ) ); + DBG ( "SHA384 required %ld cycles per byte\n", + digest_cost ( &sha384_algorithm ) ); } -/** SHA-512 self-test */ +/** SHA-512 family self-test */ struct self_test sha512_test __self_test = { .name = "sha512", .exec = sha512_test_exec, -- cgit v1.2.3-55-g7522