forked from microsoft/SymCrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhmacsha1.c
66 lines (54 loc) · 1.83 KB
/
hmacsha1.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
64
65
66
//
// HmacSha1.c
//
// Copyright (c) Microsoft Corporation. Licensed under the MIT license.
//
#include "precomp.h"
//
// This implementation of HMAC uses extensive knowledge of the internal workings of the
// SHA1 implementation and uses internal routines.
// This reduces the overhead per HMAC computation by up to 20%, which is significant
// enough to take on the added complexity.
//
#define ALG SHA1
#define Alg Sha1
#define SET_DATALENGTH( state, len ) {state.dataLengthL = len;}
#include "hmac_pattern.c"
#undef SET_DATALENGTH
#undef Alg
#undef ALG
const SYMCRYPT_MAC SymCryptHmacSha1Algorithm_default = {
SymCryptHmacSha1ExpandKey,
SymCryptHmacSha1Init,
SymCryptHmacSha1Append,
SymCryptHmacSha1Result,
sizeof(SYMCRYPT_HMAC_SHA1_EXPANDED_KEY),
sizeof(SYMCRYPT_HMAC_SHA1_STATE),
SYMCRYPT_HMAC_SHA1_RESULT_SIZE,
&SymCryptSha1Algorithm,
SYMCRYPT_FIELD_OFFSET( SYMCRYPT_HMAC_SHA1_EXPANDED_KEY, outerState ),
};
const PCSYMCRYPT_MAC SymCryptHmacSha1Algorithm = &SymCryptHmacSha1Algorithm_default;
static const BYTE hmacSha1Kat[20] = {
0x2a, 0x29, 0x85, 0x40, 0x23, 0xba, 0x2e, 0xf1,
0x49, 0x0f, 0x8c, 0xd8, 0x97, 0xa8, 0xcc, 0x6b,
0x55, 0x7b, 0x2a, 0x12,
};
VOID
SYMCRYPT_CALL
SymCryptHmacSha1Selftest(void)
{
SYMCRYPT_HMAC_SHA1_EXPANDED_KEY xKey;
BYTE res[SYMCRYPT_HMAC_SHA1_RESULT_SIZE];
SymCryptHmacSha1ExpandKey( &xKey, SymCryptTestKey32, 16 );
SymCryptHmacSha1( &xKey, SymCryptTestMsg3, sizeof( SymCryptTestMsg3 ), res );
SymCryptInjectError( res, sizeof( res ) );
if( memcmp( res, hmacSha1Kat, sizeof( res ) ) != 0 )
{
SymCryptFatal( 'hSh1' );
}
//
// Normally we would wipe the expanded key structure here,
// but as this is a selftest with known data this is not needed.
//
}