20 #define HASH_STATE_SIZE sizeof( sha2_ctx )
22 #if defined( USE_SHA2_EXT ) && !defined( SHA512_DIGEST_SIZE )
23 #error SHA2-384/512 can only be used on a system with 64-bit data type support
26 #ifndef SHA384_DIGEST_SIZE
28 #define SHA384_DIGEST_SIZE 48
29 #define SHA512_DIGEST_SIZE 64
30 #define sha2_begin( size, ctx ) sha256_begin( ( ctx )->uu->ctx256 )
31 #define sha2_hash( data, len, ctx ) sha256_hash( data, len, ( ctx )->uu->ctx256 )
32 #define sha2_end( hash, ctx ) sha256_end( hash, ( ctx )->uu->ctx256 )
41 #ifndef CONFIG_NO_SELFTEST
51 const BYTE dig384[ SHA384_DIGEST_SIZE ];
52 const BYTE dig512[ SHA512_DIGEST_SIZE ];
55 { 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
56 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
57 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
58 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad },
59 { 0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b,
60 0xb5, 0xa0, 0x3d, 0x69, 0x9a, 0xc6, 0x50, 0x07,
61 0x27, 0x2c, 0x32, 0xab, 0x0e, 0xde, 0xd1, 0x63,
62 0x1a, 0x8b, 0x60, 0x5a, 0x43, 0xff, 0x5b, 0xed,
63 0x80, 0x86, 0x07, 0x2b, 0xa1, 0xe7, 0xcc, 0x23,
64 0x58, 0xba, 0xec, 0xa1, 0x34, 0xc8, 0x25, 0xa7 },
65 { 0xdd, 0xaf, 0x35, 0xa1, 0x93, 0x61, 0x7a, 0xba,
66 0xcc, 0x41, 0x73, 0x49, 0xae, 0x20, 0x41, 0x31,
67 0x12, 0xe6, 0xfa, 0x4e, 0x89, 0xa9, 0x7e, 0xa2,
68 0x0a, 0x9e, 0xee, 0xe6, 0x4b, 0x55, 0xd3, 0x9a,
69 0x21, 0x92, 0x99, 0x2a, 0x27, 0x4f, 0xc1, 0xa8,
70 0x36, 0xba, 0x3c, 0x23, 0xa3, 0xfe, 0xeb, 0xbd,
71 0x45, 0x4d, 0x44, 0x23, 0x64, 0x3c, 0xe8, 0x0e,
72 0x2a, 0x9a, 0xc9, 0x4f, 0xa5, 0x4c, 0xa4, 0x9f }
74 {
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56,
75 { 0x24, 0x8d, 0x6a, 0x61, 0xd2, 0x06, 0x38, 0xb8,
76 0xe5, 0xc0, 0x26, 0x93, 0x0c, 0x3e, 0x60, 0x39,
77 0xa3, 0x3c, 0xe4, 0x59, 0x64, 0xff, 0x21, 0x67,
78 0xf6, 0xec, 0xed, 0xd4, 0x19, 0xdb, 0x06, 0xc1 },
79 { 0x33, 0x91, 0xfd, 0xdd, 0xfc, 0x8d, 0xc7, 0x39,
80 0x37, 0x07, 0xa6, 0x5b, 0x1b, 0x47, 0x09, 0x39,
81 0x7c, 0xf8, 0xb1, 0xd1, 0x62, 0xaf, 0x05, 0xab,
82 0xfe, 0x8f, 0x45, 0x0d, 0xe5, 0xf3, 0x6b, 0xc6,
83 0xb0, 0x45, 0x5a, 0x85, 0x20, 0xbc, 0x4e, 0x6f,
84 0x5f, 0xe9, 0x5b, 0x1f, 0xe3, 0xc8, 0x45, 0x2b },
85 { 0x20, 0x4a, 0x8f, 0xc6, 0xdd, 0xa8, 0x2f, 0x0a,
86 0x0c, 0xed, 0x7b, 0xeb, 0x8e, 0x08, 0xa4, 0x16,
87 0x57, 0xc1, 0x6e, 0xf4, 0x68, 0xb2, 0x28, 0xa8,
88 0x27, 0x9b, 0xe3, 0x31, 0xa7, 0x03, 0xc3, 0x35,
89 0x96, 0xfd, 0x15, 0xc1, 0x3b, 0x1b, 0x07, 0xf9,
90 0xaa, 0x1d, 0x3b, 0xea, 0x57, 0x78, 0x9c, 0xa0,
91 0x31, 0xad, 0x85, 0xc7, 0xa7, 0x1d, 0xd7, 0x03,
92 0x54, 0xec, 0x63, 0x12, 0x38, 0xca, 0x34, 0x45 }
95 {
"aaaaa...", 1000000L,
96 { 0xcd, 0xc7, 0x6e, 0x5c, 0x99, 0x14, 0xfb, 0x92,
97 0x81, 0xa1, 0xc7, 0xe2, 0x84, 0xd7, 0x3e, 0x67,
98 0xf1, 0x80, 0x9a, 0x48, 0xa4, 0x97, 0x20, 0x0e,
99 0x04, 0x6d, 0x39, 0xcc, 0xc7, 0x11, 0x2c, 0xd0 },
100 { 0x9d, 0x0e, 0x18, 0x09, 0x71, 0x64, 0x74, 0xcb,
101 0x08, 0x6e, 0x83, 0x4e, 0x31, 0x0a, 0x4a, 0x1c,
102 0xed, 0x14, 0x9e, 0x9c, 0x00, 0xf2, 0x48, 0x52,
103 0x79, 0x72, 0xce, 0xc5, 0x70, 0x4c, 0x2a, 0x5b,
104 0x07, 0xb8, 0xb3, 0xdc, 0x38, 0xec, 0xc4, 0xeb,
105 0xae, 0x97, 0xdd, 0xd8, 0x7f, 0x3d, 0x89, 0x85 },
106 { 0xe7, 0x18, 0x48, 0x3d, 0x0c, 0xe7, 0x69, 0x64,
107 0x4e, 0x2e, 0x42, 0xc7, 0xbc, 0x15, 0xb4, 0x63,
108 0x8e, 0x1f, 0x98, 0xb1, 0x3b, 0x20, 0x44, 0x28,
109 0x56, 0x32, 0xa8, 0x03, 0xaf, 0xa9, 0x73, 0xeb,
110 0xde, 0x0f, 0xf2, 0x44, 0x87, 0x7e, 0xa6, 0x0a,
111 0x4c, 0xb0, 0x43, 0x2c, 0xe5, 0x77, 0xc3, 0x1b,
112 0xeb, 0x00, 0x9c, 0x5c, 0x2c, 0x49, 0xaa, 0x2e,
113 0x4e, 0xad, 0xb2, 0x17, 0xad, 0x8c, 0xc0, 0x9b } }
115 { NULL, 0, { 0 }, { 0 }, { 0 } }
118 static int selfTest(
void )
131 for( i = 0; digestValues[ i ].data != NULL; i++ )
133 status = testHash( capabilityInfo, hashState, digestValues[ i ].
data,
134 digestValues[ i ].
length, digestValues[ i ].dig256 );
141 #define selfTest NULL
158 assert( contextInfoPtr == NULL || \
160 assert( ( length == 0 &&
isWritePtr( data,
sizeof(
int ) ) ) || \
161 ( length > 0 &&
isWritePtr( data, length ) ) );
174 return( getDefaultInfo( type, contextInfoPtr, data, length ) );
196 sha2_hash( buffer, noBytes, shaInfo );
200 sha2_end( contextInfoPtr->ctxHash->hash, shaInfo );
218 outBuffer == NULL && outBufMaxLength == 0 ) || \
221 outBufMaxLength >= 32 ) );
222 assert( inBuffer == NULL ||
isReadPtr( inBuffer, inLength ) );
235 sha2_hash( (
BYTE * ) inBuffer, inLength, shaInfo );
239 if( inBuffer != NULL )
240 sha2_hash( (
BYTE * ) inBuffer, inLength, shaInfo );
241 sha2_end( outBuffer, shaInfo );
249 void sha2HashBufferAtomic(
BYTE *outBuffer,
const int outBufMaxLength,
250 const void *inBuffer,
const int inLength )
254 assert(
isWritePtr( outBuffer, outBufMaxLength ) && \
255 outBufMaxLength >= 32 );
256 assert(
isReadPtr( inBuffer, inLength ) );
258 if( outBufMaxLength < 32 || inLength <= 0 )
262 sha2_hash( (
BYTE * ) inBuffer, inLength, &shaInfo );
263 sha2_end( outBuffer, &shaInfo );
269 #if defined( CONFIG_SUITEB )
270 #define SHA2EXT_DIGEST_SIZE SHA384_DIGEST_SIZE
272 #define SHA2EXT_DIGEST_SIZE SHA512_DIGEST_SIZE
275 void sha2_ExtHashBuffer(
HASHINFO hashInfo,
BYTE *outBuffer,
276 const int outBufMaxLength,
const void *inBuffer,
277 const int inLength,
const HASH_STATE hashState )
284 outBuffer == NULL && outBufMaxLength == 0 ) || \
287 outBufMaxLength >= SHA2EXT_DIGEST_SIZE ) );
288 assert( inBuffer == NULL ||
isReadPtr( inBuffer, inLength ) );
291 outBufMaxLength < SHA2EXT_DIGEST_SIZE ) || \
298 if( sha2_begin( SHA2EXT_DIGEST_SIZE, shaInfo ) !=
EXIT_SUCCESS )
303 sha2_hash( (
BYTE * ) inBuffer, inLength, shaInfo );
307 if( inBuffer != NULL )
308 sha2_hash( (
BYTE * ) inBuffer, inLength, shaInfo );
309 sha2_end( outBuffer, shaInfo );
317 void sha2_ExtHashBufferAtomic(
BYTE *outBuffer,
const int outBufMaxLength,
322 assert(
isWritePtr( outBuffer, outBufMaxLength ) && \
323 outBufMaxLength >= 64 );
324 assert(
isReadPtr( inBuffer, inLength ) );
326 if( outBufMaxLength < 64 || inLength <= 0 )
329 if( sha2_begin( SHA2EXT_DIGEST_SIZE, &shaInfo ) !=
EXIT_SUCCESS )
331 memset( outBuffer, 0, outBufMaxLength );
334 sha2_hash( (
BYTE * ) inBuffer, inLength, &shaInfo );
335 sha2_end( outBuffer, &shaInfo );
368 selfTest, getInfo, NULL, NULL, NULL, NULL, hash, hash
374 selfTest, getInfo, NULL, NULL, NULL, NULL, hash, hash
390 if( dataLength != SHA384_DIGEST_SIZE )
392 contextInfoPtr->capabilityInfo = &capabilityInfo;
394 if( dataLength != SHA512_DIGEST_SIZE )
396 contextInfoPtr->capabilityInfo = &capabilityInfo;
406 return( initGenericParams( contextInfoPtr, paramType, data,
419 selfTest, getInfo, NULL,
initParams, NULL, NULL, hash, hash
424 return( &capabilityInfo );