forked from microsoft/SymCrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhmacsha512_256.c
63 lines (50 loc) · 1.85 KB
/
hmacsha512_256.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// HmacSha512_256.c
//
// Copyright (c) Microsoft Corporation. Licensed under the MIT license.
//
#include "precomp.h"
#define SymCryptSha512_256AppendBlocks SymCryptSha512AppendBlocks
#define ALG SHA512_256
#define Alg Sha512_256
#define SET_DATALENGTH( state, len ) {state.dataLengthL = len; state.dataLengthH = 0;}
#include "hmac_pattern.c"
#undef SET_DATALENGTH
#undef Alg
#undef ALG
const SYMCRYPT_MAC SymCryptHmacSha512_256Algorithm_default = {
SymCryptHmacSha512_256ExpandKey,
SymCryptHmacSha512_256Init,
SymCryptHmacSha512_256Append,
SymCryptHmacSha512_256Result,
sizeof(SYMCRYPT_HMAC_SHA512_256_EXPANDED_KEY),
sizeof(SYMCRYPT_HMAC_SHA512_256_STATE),
SYMCRYPT_HMAC_SHA512_256_RESULT_SIZE,
&SymCryptSha512_256Algorithm,
SYMCRYPT_FIELD_OFFSET( SYMCRYPT_HMAC_SHA512_256_EXPANDED_KEY, outerState ),
};
const PCSYMCRYPT_MAC SymCryptHmacSha512_256Algorithm = &SymCryptHmacSha512_256Algorithm_default;
static const BYTE hmacSha512_256Kat[32] = {
0x79, 0x44, 0xb9, 0x97, 0xc0, 0xaa, 0xf7, 0x11,
0xdd, 0xb3, 0x78, 0x60, 0x68, 0xdb, 0x2b, 0xa1,
0x40, 0x80, 0x4f, 0xdc, 0xb7, 0x02, 0x7b, 0x6a,
0xe9, 0x9f, 0x5a, 0x38, 0xc8, 0x28, 0x67, 0x4c
};
VOID
SYMCRYPT_CALL
SymCryptHmacSha512_256Selftest(void)
{
SYMCRYPT_HMAC_SHA512_256_EXPANDED_KEY xKey;
BYTE res[SYMCRYPT_HMAC_SHA512_256_RESULT_SIZE];
SymCryptHmacSha512_256ExpandKey( &xKey, SymCryptTestKey32, 16 );
SymCryptHmacSha512_256( &xKey, SymCryptTestMsg3, sizeof( SymCryptTestMsg3 ), res );
SymCryptInjectError( res, sizeof( res ) );
if( memcmp( res, hmacSha512_256Kat, sizeof( res ) ) != 0 )
{
SymCryptFatal( 'hsh4' );
}
//
// Normally we would wipe the expanded key structure here,
// but as this is a selftest with known data this is not needed.
//
}