Coverage Report

Created: 2024-11-21 07:03

/src/SymCrypt/lib/hmacsha256.c
Line
Count
Source (jump to first uncovered line)
1
//
2
// HmacSha256.c
3
//
4
// Copyright (c) Microsoft Corporation. Licensed under the MIT license.
5
//
6
7
#include "precomp.h"
8
9
#define ALG SHA256
10
#define Alg Sha256
11
11.2k
#define SET_DATALENGTH( state, len )    {state.dataLengthL = len;}
12
#include "hmac_pattern.c"
13
#undef SET_DATALENGTH
14
#undef Alg
15
#undef ALG
16
17
const SYMCRYPT_MAC SymCryptHmacSha256Algorithm_default = {
18
    SymCryptHmacSha256ExpandKey,
19
    SymCryptHmacSha256Init,
20
    SymCryptHmacSha256Append,
21
    SymCryptHmacSha256Result,
22
    sizeof(SYMCRYPT_HMAC_SHA256_EXPANDED_KEY),
23
    sizeof(SYMCRYPT_HMAC_SHA256_STATE),
24
    SYMCRYPT_HMAC_SHA256_RESULT_SIZE,
25
    &SymCryptSha256Algorithm,
26
    SYMCRYPT_FIELD_OFFSET( SYMCRYPT_HMAC_SHA256_EXPANDED_KEY, outerState ),
27
};
28
29
const PCSYMCRYPT_MAC SymCryptHmacSha256Algorithm = &SymCryptHmacSha256Algorithm_default;
30
31
static const BYTE hmacSha256Kat[32] = {
32
    0xd6, 0x01, 0xcc, 0x17, 0x75, 0x59, 0xb0, 0x24, 
33
    0x84, 0x59, 0x78, 0x7f, 0x7e, 0x80, 0x4e, 0xd7, 
34
    0xf2, 0x76, 0x89, 0xb5, 0x99, 0x5c, 0x59, 0xb6, 
35
    0x61, 0x80, 0x2d, 0x96, 0x82, 0xfd, 0xf8, 0xd2,
36
};
37
38
39
VOID
40
SYMCRYPT_CALL
41
SymCryptHmacSha256Selftest(void)
42
0
{
43
0
    SYMCRYPT_HMAC_SHA256_EXPANDED_KEY xKey;
44
0
    BYTE res[SYMCRYPT_HMAC_SHA256_RESULT_SIZE];
45
46
0
    SymCryptHmacSha256ExpandKey( &xKey, SymCryptTestKey32, 16 );
47
0
    SymCryptHmacSha256( &xKey, SymCryptTestMsg3, sizeof( SymCryptTestMsg3 ), res );
48
49
0
    SymCryptInjectError( res, sizeof( res ) );
50
    
51
0
    if( memcmp( res, hmacSha256Kat, sizeof( res ) ) != 0 ) 
52
0
    {
53
0
        SymCryptFatal( 'hsh2' );
54
0
    }
55
56
    //
57
    // Normally we would wipe the expanded key structure here,
58
    // but as this is a selftest with known data this is not needed.
59
    //
60
0
}
61