Coverage Report

Created: 2024-11-21 07:03

/src/SymCrypt/lib/hmacsha512.c
Line
Count
Source (jump to first uncovered line)
1
//
2
// HmacSha512.c
3
//
4
// Copyright (c) Microsoft Corporation. Licensed under the MIT license.
5
//
6
7
#include "precomp.h"
8
9
#define ALG SHA512
10
#define Alg Sha512
11
16.2k
#define SET_DATALENGTH( state, len )    {state.dataLengthL = len; state.dataLengthH = 0;}
12
#include "hmac_pattern.c"
13
#undef SET_DATALENGTH
14
#undef Alg
15
#undef ALG
16
17
const SYMCRYPT_MAC SymCryptHmacSha512Algorithm_default = {
18
    SymCryptHmacSha512ExpandKey,
19
    SymCryptHmacSha512Init,
20
    SymCryptHmacSha512Append,
21
    SymCryptHmacSha512Result,
22
    sizeof(SYMCRYPT_HMAC_SHA512_EXPANDED_KEY),
23
    sizeof(SYMCRYPT_HMAC_SHA512_STATE),
24
    SYMCRYPT_HMAC_SHA512_RESULT_SIZE,
25
    &SymCryptSha512Algorithm,
26
    SYMCRYPT_FIELD_OFFSET( SYMCRYPT_HMAC_SHA512_EXPANDED_KEY, outerState ),
27
};
28
29
const PCSYMCRYPT_MAC SymCryptHmacSha512Algorithm = &SymCryptHmacSha512Algorithm_default;
30
31
static const BYTE hmacSha512Kat[64] = {
32
    0x07, 0x64, 0xa6, 0x58, 0xeb, 0x3e, 0x2f, 0xb0, 0x2c, 0x06, 0x72, 0x93, 0xcd, 0xaa, 0x3c, 0x05, 
33
    0x28, 0x73, 0x15, 0xf2, 0xd3, 0xb4, 0x5a, 0x28, 0x10, 0x20, 0x1e, 0x26, 0xc3, 0x89, 0x35, 0x48, 
34
    0xe9, 0xea, 0xca, 0x72, 0xf0, 0x2e, 0x04, 0x19, 0x20, 0x31, 0x71, 0x68, 0xb5, 0x7a, 0x86, 0x40, 
35
    0x29, 0x1b, 0x3b, 0xb7, 0xaa, 0x4a, 0x5f, 0xaf, 0x80, 0x26, 0xb4, 0xad, 0x23, 0x5a, 0xc4, 0x25, 
36
};
37
38
39
VOID
40
SYMCRYPT_CALL
41
SymCryptHmacSha512Selftest(void)
42
0
{
43
0
    SYMCRYPT_HMAC_SHA512_EXPANDED_KEY xKey;
44
0
    BYTE res[SYMCRYPT_HMAC_SHA512_RESULT_SIZE];
45
46
0
    SymCryptHmacSha512ExpandKey( &xKey, SymCryptTestKey32, 16 );
47
0
    SymCryptHmacSha512( &xKey, SymCryptTestMsg3, sizeof( SymCryptTestMsg3 ), res );
48
49
0
    SymCryptInjectError( res, sizeof( res ) );
50
0
    if( memcmp( res, hmacSha512Kat, sizeof( res ) ) != 0 ) 
51
0
    {
52
0
        SymCryptFatal( 'hsh5' );
53
0
    }
54
55
    //
56
    // Normally we would wipe the expanded key structure here,
57
    // but as this is a selftest with known data this is not needed.
58
    //
59
0
}
60