/src/SymCrypt/lib/hmac_pattern.c
Line | Count | Source (jump to first uncovered line) |
1 | | // |
2 | | // hmac_pattern.c |
3 | | // Copyright (c) Microsoft Corporation. Licensed under the MIT license. |
4 | | // |
5 | | |
6 | | VOID |
7 | | SYMCRYPT_CALL |
8 | | SYMCRYPT_HmacXxxStateCopy( |
9 | | _In_ PCSYMCRYPT_HMAC_XXX_STATE pSrc, |
10 | | _In_opt_ PCSYMCRYPT_HMAC_XXX_EXPANDED_KEY pExpandedKey, |
11 | | _Out_ PSYMCRYPT_HMAC_XXX_STATE pDst ) |
12 | 0 | { |
13 | 0 | SYMCRYPT_CHECK_MAGIC( pSrc ); |
14 | |
|
15 | 0 | SYMCRYPT_XxxStateCopy( &pSrc->hash, &pDst->hash ); |
16 | |
|
17 | 0 | if( pExpandedKey != NULL ) |
18 | 0 | { |
19 | 0 | SYMCRYPT_CHECK_MAGIC( pExpandedKey ); |
20 | 0 | pDst->pKey = pExpandedKey; |
21 | 0 | } |
22 | 0 | else |
23 | 0 | { |
24 | 0 | SYMCRYPT_CHECK_MAGIC( pSrc->pKey ); |
25 | 0 | pDst->pKey = pSrc->pKey; |
26 | 0 | } |
27 | 0 | SYMCRYPT_SET_MAGIC( pDst ); |
28 | 0 | } Unexecuted instantiation: SymCryptHmacMd5StateCopy Unexecuted instantiation: SymCryptHmacSha1StateCopy Unexecuted instantiation: SymCryptHmacSha256StateCopy Unexecuted instantiation: SymCryptHmacSha384StateCopy Unexecuted instantiation: SymCryptHmacSha512StateCopy |
29 | | |
30 | | VOID |
31 | | SYMCRYPT_CALL |
32 | | SYMCRYPT_HmacXxxKeyCopy( _In_ PCSYMCRYPT_HMAC_XXX_EXPANDED_KEY pSrc, _Out_ PSYMCRYPT_HMAC_XXX_EXPANDED_KEY pDst ) |
33 | 0 | { |
34 | 0 | SYMCRYPT_CHECK_MAGIC( pSrc ); |
35 | 0 | *pDst = *pSrc; |
36 | 0 | SYMCRYPT_SET_MAGIC( pDst ); |
37 | 0 | } Unexecuted instantiation: SymCryptHmacMd5KeyCopy Unexecuted instantiation: SymCryptHmacSha1KeyCopy Unexecuted instantiation: SymCryptHmacSha256KeyCopy Unexecuted instantiation: SymCryptHmacSha384KeyCopy Unexecuted instantiation: SymCryptHmacSha512KeyCopy |
38 | | |
39 | | SYMCRYPT_ERROR |
40 | | SYMCRYPT_CALL |
41 | | SYMCRYPT_HmacXxxExpandKey( |
42 | | _Out_ PSYMCRYPT_HMAC_XXX_EXPANDED_KEY pExpandedKey, |
43 | | _In_reads_opt_(cbKey) PCBYTE pbKey, |
44 | | SIZE_T cbKey ) |
45 | 1.24k | { |
46 | 1.24k | SYMCRYPT_XXX_STATE hashState; |
47 | 1.24k | SYMCRYPT_ALIGN BYTE iblock[ SYMCRYPT_XXX_INPUT_BLOCK_SIZE ]; // One input block for the hash function |
48 | 1.24k | SIZE_T tmp; |
49 | | |
50 | 1.24k | SYMCRYPT_SET_MAGIC( pExpandedKey ); |
51 | | |
52 | | // |
53 | | // Initialize our hash state and our input block |
54 | | // We wipe the whole block & then copy the key into it. This is often faster |
55 | | // as the compiler can optimize the wipe because it knows the size at compile time. |
56 | | // |
57 | 1.24k | SYMCRYPT_XxxInit( &hashState ); |
58 | 1.24k | memset( iblock, 0, sizeof( iblock ) ); |
59 | | |
60 | 1.24k | if( cbKey <= sizeof( iblock ) ) |
61 | 621 | { |
62 | 621 | if( cbKey > 0 ) |
63 | 542 | { |
64 | 542 | memcpy( iblock, pbKey, cbKey ); |
65 | 542 | } |
66 | 622 | } else { |
67 | | // |
68 | | // We can use the existing MD5 state to hash the long key. |
69 | | // The state is re-initialized by the SymCryptMd5Result() function. |
70 | | // |
71 | 622 | SYMCRYPT_XxxAppend( &hashState, pbKey, cbKey ); |
72 | 622 | SYMCRYPT_XxxResult( &hashState, iblock ); |
73 | 622 | } |
74 | | |
75 | 1.24k | XorByteIntoBuffer( iblock, sizeof( iblock )/8, HMAC_IPAD_BYTE ); |
76 | | |
77 | | // |
78 | | // Copy the initial chaining state to both states in the expanded key |
79 | | // |
80 | 1.24k | pExpandedKey->innerState = hashState.chain; |
81 | 1.24k | pExpandedKey->outerState = hashState.chain; |
82 | | |
83 | | // |
84 | | // Update the state in the expanded key directly |
85 | | // |
86 | 1.24k | SYMCRYPT_XxxAppendBlocks( &pExpandedKey->innerState, iblock, sizeof( iblock ), &tmp ); |
87 | | |
88 | 1.24k | XorByteIntoBuffer( iblock, sizeof( iblock )/8, HMAC_IPAD_BYTE ^ HMAC_OPAD_BYTE ); |
89 | | |
90 | 1.24k | SYMCRYPT_XxxAppendBlocks( &pExpandedKey->outerState, iblock, sizeof( iblock ), &tmp ); |
91 | | |
92 | 1.24k | SymCryptWipeKnownSize( iblock, sizeof( iblock ) ); |
93 | 1.24k | SymCryptWipeKnownSize( &hashState, sizeof( hashState ) ); |
94 | | |
95 | 1.24k | return SYMCRYPT_NO_ERROR; |
96 | 1.24k | } Line | Count | Source | 45 | 215 | { | 46 | 215 | SYMCRYPT_XXX_STATE hashState; | 47 | 215 | SYMCRYPT_ALIGN BYTE iblock[ SYMCRYPT_XXX_INPUT_BLOCK_SIZE ]; // One input block for the hash function | 48 | 215 | SIZE_T tmp; | 49 | | | 50 | 215 | SYMCRYPT_SET_MAGIC( pExpandedKey ); | 51 | | | 52 | | // | 53 | | // Initialize our hash state and our input block | 54 | | // We wipe the whole block & then copy the key into it. This is often faster | 55 | | // as the compiler can optimize the wipe because it knows the size at compile time. | 56 | | // | 57 | 215 | SYMCRYPT_XxxInit( &hashState ); | 58 | 215 | memset( iblock, 0, sizeof( iblock ) ); | 59 | | | 60 | 215 | if( cbKey <= sizeof( iblock ) ) | 61 | 96 | { | 62 | 96 | if( cbKey > 0 ) | 63 | 86 | { | 64 | 86 | memcpy( iblock, pbKey, cbKey ); | 65 | 86 | } | 66 | 119 | } else { | 67 | | // | 68 | | // We can use the existing MD5 state to hash the long key. | 69 | | // The state is re-initialized by the SymCryptMd5Result() function. | 70 | | // | 71 | 119 | SYMCRYPT_XxxAppend( &hashState, pbKey, cbKey ); | 72 | 119 | SYMCRYPT_XxxResult( &hashState, iblock ); | 73 | 119 | } | 74 | | | 75 | 215 | XorByteIntoBuffer( iblock, sizeof( iblock )/8, HMAC_IPAD_BYTE ); | 76 | | | 77 | | // | 78 | | // Copy the initial chaining state to both states in the expanded key | 79 | | // | 80 | 215 | pExpandedKey->innerState = hashState.chain; | 81 | 215 | pExpandedKey->outerState = hashState.chain; | 82 | | | 83 | | // | 84 | | // Update the state in the expanded key directly | 85 | | // | 86 | 215 | SYMCRYPT_XxxAppendBlocks( &pExpandedKey->innerState, iblock, sizeof( iblock ), &tmp ); | 87 | | | 88 | 215 | XorByteIntoBuffer( iblock, sizeof( iblock )/8, HMAC_IPAD_BYTE ^ HMAC_OPAD_BYTE ); | 89 | | | 90 | 215 | SYMCRYPT_XxxAppendBlocks( &pExpandedKey->outerState, iblock, sizeof( iblock ), &tmp ); | 91 | | | 92 | 215 | SymCryptWipeKnownSize( iblock, sizeof( iblock ) ); | 93 | 215 | SymCryptWipeKnownSize( &hashState, sizeof( hashState ) ); | 94 | | | 95 | 215 | return SYMCRYPT_NO_ERROR; | 96 | 215 | } |
SymCryptHmacSha1ExpandKey Line | Count | Source | 45 | 292 | { | 46 | 292 | SYMCRYPT_XXX_STATE hashState; | 47 | 292 | SYMCRYPT_ALIGN BYTE iblock[ SYMCRYPT_XXX_INPUT_BLOCK_SIZE ]; // One input block for the hash function | 48 | 292 | SIZE_T tmp; | 49 | | | 50 | 292 | SYMCRYPT_SET_MAGIC( pExpandedKey ); | 51 | | | 52 | | // | 53 | | // Initialize our hash state and our input block | 54 | | // We wipe the whole block & then copy the key into it. This is often faster | 55 | | // as the compiler can optimize the wipe because it knows the size at compile time. | 56 | | // | 57 | 292 | SYMCRYPT_XxxInit( &hashState ); | 58 | 292 | memset( iblock, 0, sizeof( iblock ) ); | 59 | | | 60 | 292 | if( cbKey <= sizeof( iblock ) ) | 61 | 117 | { | 62 | 117 | if( cbKey > 0 ) | 63 | 102 | { | 64 | 102 | memcpy( iblock, pbKey, cbKey ); | 65 | 102 | } | 66 | 175 | } else { | 67 | | // | 68 | | // We can use the existing MD5 state to hash the long key. | 69 | | // The state is re-initialized by the SymCryptMd5Result() function. | 70 | | // | 71 | 175 | SYMCRYPT_XxxAppend( &hashState, pbKey, cbKey ); | 72 | 175 | SYMCRYPT_XxxResult( &hashState, iblock ); | 73 | 175 | } | 74 | | | 75 | 292 | XorByteIntoBuffer( iblock, sizeof( iblock )/8, HMAC_IPAD_BYTE ); | 76 | | | 77 | | // | 78 | | // Copy the initial chaining state to both states in the expanded key | 79 | | // | 80 | 292 | pExpandedKey->innerState = hashState.chain; | 81 | 292 | pExpandedKey->outerState = hashState.chain; | 82 | | | 83 | | // | 84 | | // Update the state in the expanded key directly | 85 | | // | 86 | 292 | SYMCRYPT_XxxAppendBlocks( &pExpandedKey->innerState, iblock, sizeof( iblock ), &tmp ); | 87 | | | 88 | 292 | XorByteIntoBuffer( iblock, sizeof( iblock )/8, HMAC_IPAD_BYTE ^ HMAC_OPAD_BYTE ); | 89 | | | 90 | 292 | SYMCRYPT_XxxAppendBlocks( &pExpandedKey->outerState, iblock, sizeof( iblock ), &tmp ); | 91 | | | 92 | 292 | SymCryptWipeKnownSize( iblock, sizeof( iblock ) ); | 93 | 292 | SymCryptWipeKnownSize( &hashState, sizeof( hashState ) ); | 94 | | | 95 | 292 | return SYMCRYPT_NO_ERROR; | 96 | 292 | } |
SymCryptHmacSha256ExpandKey Line | Count | Source | 45 | 220 | { | 46 | 220 | SYMCRYPT_XXX_STATE hashState; | 47 | 220 | SYMCRYPT_ALIGN BYTE iblock[ SYMCRYPT_XXX_INPUT_BLOCK_SIZE ]; // One input block for the hash function | 48 | 220 | SIZE_T tmp; | 49 | | | 50 | 220 | SYMCRYPT_SET_MAGIC( pExpandedKey ); | 51 | | | 52 | | // | 53 | | // Initialize our hash state and our input block | 54 | | // We wipe the whole block & then copy the key into it. This is often faster | 55 | | // as the compiler can optimize the wipe because it knows the size at compile time. | 56 | | // | 57 | 220 | SYMCRYPT_XxxInit( &hashState ); | 58 | 220 | memset( iblock, 0, sizeof( iblock ) ); | 59 | | | 60 | 220 | if( cbKey <= sizeof( iblock ) ) | 61 | 115 | { | 62 | 115 | if( cbKey > 0 ) | 63 | 93 | { | 64 | 93 | memcpy( iblock, pbKey, cbKey ); | 65 | 93 | } | 66 | 115 | } else { | 67 | | // | 68 | | // We can use the existing MD5 state to hash the long key. | 69 | | // The state is re-initialized by the SymCryptMd5Result() function. | 70 | | // | 71 | 105 | SYMCRYPT_XxxAppend( &hashState, pbKey, cbKey ); | 72 | 105 | SYMCRYPT_XxxResult( &hashState, iblock ); | 73 | 105 | } | 74 | | | 75 | 220 | XorByteIntoBuffer( iblock, sizeof( iblock )/8, HMAC_IPAD_BYTE ); | 76 | | | 77 | | // | 78 | | // Copy the initial chaining state to both states in the expanded key | 79 | | // | 80 | 220 | pExpandedKey->innerState = hashState.chain; | 81 | 220 | pExpandedKey->outerState = hashState.chain; | 82 | | | 83 | | // | 84 | | // Update the state in the expanded key directly | 85 | | // | 86 | 220 | SYMCRYPT_XxxAppendBlocks( &pExpandedKey->innerState, iblock, sizeof( iblock ), &tmp ); | 87 | | | 88 | 220 | XorByteIntoBuffer( iblock, sizeof( iblock )/8, HMAC_IPAD_BYTE ^ HMAC_OPAD_BYTE ); | 89 | | | 90 | 220 | SYMCRYPT_XxxAppendBlocks( &pExpandedKey->outerState, iblock, sizeof( iblock ), &tmp ); | 91 | | | 92 | 220 | SymCryptWipeKnownSize( iblock, sizeof( iblock ) ); | 93 | 220 | SymCryptWipeKnownSize( &hashState, sizeof( hashState ) ); | 94 | | | 95 | 220 | return SYMCRYPT_NO_ERROR; | 96 | 220 | } |
SymCryptHmacSha384ExpandKey Line | Count | Source | 45 | 223 | { | 46 | 223 | SYMCRYPT_XXX_STATE hashState; | 47 | 223 | SYMCRYPT_ALIGN BYTE iblock[ SYMCRYPT_XXX_INPUT_BLOCK_SIZE ]; // One input block for the hash function | 48 | 223 | SIZE_T tmp; | 49 | | | 50 | 223 | SYMCRYPT_SET_MAGIC( pExpandedKey ); | 51 | | | 52 | | // | 53 | | // Initialize our hash state and our input block | 54 | | // We wipe the whole block & then copy the key into it. This is often faster | 55 | | // as the compiler can optimize the wipe because it knows the size at compile time. | 56 | | // | 57 | 223 | SYMCRYPT_XxxInit( &hashState ); | 58 | 223 | memset( iblock, 0, sizeof( iblock ) ); | 59 | | | 60 | 223 | if( cbKey <= sizeof( iblock ) ) | 61 | 124 | { | 62 | 124 | if( cbKey > 0 ) | 63 | 114 | { | 64 | 114 | memcpy( iblock, pbKey, cbKey ); | 65 | 114 | } | 66 | 124 | } else { | 67 | | // | 68 | | // We can use the existing MD5 state to hash the long key. | 69 | | // The state is re-initialized by the SymCryptMd5Result() function. | 70 | | // | 71 | 99 | SYMCRYPT_XxxAppend( &hashState, pbKey, cbKey ); | 72 | 99 | SYMCRYPT_XxxResult( &hashState, iblock ); | 73 | 99 | } | 74 | | | 75 | 223 | XorByteIntoBuffer( iblock, sizeof( iblock )/8, HMAC_IPAD_BYTE ); | 76 | | | 77 | | // | 78 | | // Copy the initial chaining state to both states in the expanded key | 79 | | // | 80 | 223 | pExpandedKey->innerState = hashState.chain; | 81 | 223 | pExpandedKey->outerState = hashState.chain; | 82 | | | 83 | | // | 84 | | // Update the state in the expanded key directly | 85 | | // | 86 | 223 | SYMCRYPT_XxxAppendBlocks( &pExpandedKey->innerState, iblock, sizeof( iblock ), &tmp ); | 87 | | | 88 | 223 | XorByteIntoBuffer( iblock, sizeof( iblock )/8, HMAC_IPAD_BYTE ^ HMAC_OPAD_BYTE ); | 89 | | | 90 | 223 | SYMCRYPT_XxxAppendBlocks( &pExpandedKey->outerState, iblock, sizeof( iblock ), &tmp ); | 91 | | | 92 | 223 | SymCryptWipeKnownSize( iblock, sizeof( iblock ) ); | 93 | 223 | SymCryptWipeKnownSize( &hashState, sizeof( hashState ) ); | 94 | | | 95 | 223 | return SYMCRYPT_NO_ERROR; | 96 | 223 | } |
SymCryptHmacSha512ExpandKey Line | Count | Source | 45 | 293 | { | 46 | 293 | SYMCRYPT_XXX_STATE hashState; | 47 | 293 | SYMCRYPT_ALIGN BYTE iblock[ SYMCRYPT_XXX_INPUT_BLOCK_SIZE ]; // One input block for the hash function | 48 | 293 | SIZE_T tmp; | 49 | | | 50 | 293 | SYMCRYPT_SET_MAGIC( pExpandedKey ); | 51 | | | 52 | | // | 53 | | // Initialize our hash state and our input block | 54 | | // We wipe the whole block & then copy the key into it. This is often faster | 55 | | // as the compiler can optimize the wipe because it knows the size at compile time. | 56 | | // | 57 | 293 | SYMCRYPT_XxxInit( &hashState ); | 58 | 293 | memset( iblock, 0, sizeof( iblock ) ); | 59 | | | 60 | 293 | if( cbKey <= sizeof( iblock ) ) | 61 | 169 | { | 62 | 169 | if( cbKey > 0 ) | 63 | 147 | { | 64 | 147 | memcpy( iblock, pbKey, cbKey ); | 65 | 147 | } | 66 | 169 | } else { | 67 | | // | 68 | | // We can use the existing MD5 state to hash the long key. | 69 | | // The state is re-initialized by the SymCryptMd5Result() function. | 70 | | // | 71 | 124 | SYMCRYPT_XxxAppend( &hashState, pbKey, cbKey ); | 72 | 124 | SYMCRYPT_XxxResult( &hashState, iblock ); | 73 | 124 | } | 74 | | | 75 | 293 | XorByteIntoBuffer( iblock, sizeof( iblock )/8, HMAC_IPAD_BYTE ); | 76 | | | 77 | | // | 78 | | // Copy the initial chaining state to both states in the expanded key | 79 | | // | 80 | 293 | pExpandedKey->innerState = hashState.chain; | 81 | 293 | pExpandedKey->outerState = hashState.chain; | 82 | | | 83 | | // | 84 | | // Update the state in the expanded key directly | 85 | | // | 86 | 293 | SYMCRYPT_XxxAppendBlocks( &pExpandedKey->innerState, iblock, sizeof( iblock ), &tmp ); | 87 | | | 88 | 293 | XorByteIntoBuffer( iblock, sizeof( iblock )/8, HMAC_IPAD_BYTE ^ HMAC_OPAD_BYTE ); | 89 | | | 90 | 293 | SYMCRYPT_XxxAppendBlocks( &pExpandedKey->outerState, iblock, sizeof( iblock ), &tmp ); | 91 | | | 92 | 293 | SymCryptWipeKnownSize( iblock, sizeof( iblock ) ); | 93 | 293 | SymCryptWipeKnownSize( &hashState, sizeof( hashState ) ); | 94 | | | 95 | 293 | return SYMCRYPT_NO_ERROR; | 96 | 293 | } |
|
97 | | |
98 | | |
99 | | SYMCRYPT_NOINLINE |
100 | | VOID |
101 | | SYMCRYPT_CALL |
102 | | SYMCRYPT_HmacXxxInit( |
103 | | _Out_ PSYMCRYPT_HMAC_XXX_STATE pState, |
104 | | _In_ PCSYMCRYPT_HMAC_XXX_EXPANDED_KEY pExpandedKey) |
105 | 42.2k | { |
106 | 42.2k | SYMCRYPT_CHECK_MAGIC( pExpandedKey ); |
107 | | |
108 | 42.2k | SYMCRYPT_SET_MAGIC( pState ); |
109 | | |
110 | | // |
111 | | // We don't call SymCryptXxxInit on the hash sub-state; |
112 | | // instead we directly initialize its fields. |
113 | | // |
114 | 42.2k | SYMCRYPT_SET_MAGIC( &pState->hash ); |
115 | 42.2k | pState->hash.chain = pExpandedKey->innerState; |
116 | 42.2k | SET_DATALENGTH( pState->hash, SYMCRYPT_XXX_INPUT_BLOCK_SIZE ); |
117 | 42.2k | pState->hash.bytesInBuffer = 0; |
118 | 42.2k | pState->pKey = pExpandedKey; |
119 | 42.2k | } Line | Count | Source | 105 | 11.3k | { | 106 | 11.3k | SYMCRYPT_CHECK_MAGIC( pExpandedKey ); | 107 | | | 108 | 11.3k | SYMCRYPT_SET_MAGIC( pState ); | 109 | | | 110 | | // | 111 | | // We don't call SymCryptXxxInit on the hash sub-state; | 112 | | // instead we directly initialize its fields. | 113 | | // | 114 | 11.3k | SYMCRYPT_SET_MAGIC( &pState->hash ); | 115 | 11.3k | pState->hash.chain = pExpandedKey->innerState; | 116 | 11.3k | SET_DATALENGTH( pState->hash, SYMCRYPT_XXX_INPUT_BLOCK_SIZE ); | 117 | 11.3k | pState->hash.bytesInBuffer = 0; | 118 | 11.3k | pState->pKey = pExpandedKey; | 119 | 11.3k | } |
Line | Count | Source | 105 | 11.0k | { | 106 | 11.0k | SYMCRYPT_CHECK_MAGIC( pExpandedKey ); | 107 | | | 108 | 11.0k | SYMCRYPT_SET_MAGIC( pState ); | 109 | | | 110 | | // | 111 | | // We don't call SymCryptXxxInit on the hash sub-state; | 112 | | // instead we directly initialize its fields. | 113 | | // | 114 | 11.0k | SYMCRYPT_SET_MAGIC( &pState->hash ); | 115 | 11.0k | pState->hash.chain = pExpandedKey->innerState; | 116 | 11.0k | SET_DATALENGTH( pState->hash, SYMCRYPT_XXX_INPUT_BLOCK_SIZE ); | 117 | 11.0k | pState->hash.bytesInBuffer = 0; | 118 | 11.0k | pState->pKey = pExpandedKey; | 119 | 11.0k | } |
Line | Count | Source | 105 | 5.62k | { | 106 | 5.62k | SYMCRYPT_CHECK_MAGIC( pExpandedKey ); | 107 | | | 108 | 5.62k | SYMCRYPT_SET_MAGIC( pState ); | 109 | | | 110 | | // | 111 | | // We don't call SymCryptXxxInit on the hash sub-state; | 112 | | // instead we directly initialize its fields. | 113 | | // | 114 | 5.62k | SYMCRYPT_SET_MAGIC( &pState->hash ); | 115 | 5.62k | pState->hash.chain = pExpandedKey->innerState; | 116 | 5.62k | SET_DATALENGTH( pState->hash, SYMCRYPT_XXX_INPUT_BLOCK_SIZE ); | 117 | 5.62k | pState->hash.bytesInBuffer = 0; | 118 | 5.62k | pState->pKey = pExpandedKey; | 119 | 5.62k | } |
Line | Count | Source | 105 | 6.07k | { | 106 | 6.07k | SYMCRYPT_CHECK_MAGIC( pExpandedKey ); | 107 | | | 108 | 6.07k | SYMCRYPT_SET_MAGIC( pState ); | 109 | | | 110 | | // | 111 | | // We don't call SymCryptXxxInit on the hash sub-state; | 112 | | // instead we directly initialize its fields. | 113 | | // | 114 | 6.07k | SYMCRYPT_SET_MAGIC( &pState->hash ); | 115 | 6.07k | pState->hash.chain = pExpandedKey->innerState; | 116 | 6.07k | SET_DATALENGTH( pState->hash, SYMCRYPT_XXX_INPUT_BLOCK_SIZE ); | 117 | 6.07k | pState->hash.bytesInBuffer = 0; | 118 | 6.07k | pState->pKey = pExpandedKey; | 119 | 6.07k | } |
Line | Count | Source | 105 | 8.12k | { | 106 | 8.12k | SYMCRYPT_CHECK_MAGIC( pExpandedKey ); | 107 | | | 108 | 8.12k | SYMCRYPT_SET_MAGIC( pState ); | 109 | | | 110 | | // | 111 | | // We don't call SymCryptXxxInit on the hash sub-state; | 112 | | // instead we directly initialize its fields. | 113 | | // | 114 | 8.12k | SYMCRYPT_SET_MAGIC( &pState->hash ); | 115 | 8.12k | pState->hash.chain = pExpandedKey->innerState; | 116 | 8.12k | SET_DATALENGTH( pState->hash, SYMCRYPT_XXX_INPUT_BLOCK_SIZE ); | 117 | 8.12k | pState->hash.bytesInBuffer = 0; | 118 | 8.12k | pState->pKey = pExpandedKey; | 119 | 8.12k | } |
|
120 | | |
121 | | VOID |
122 | | SYMCRYPT_CALL |
123 | | SYMCRYPT_HmacXxxAppend( |
124 | | _Inout_ PSYMCRYPT_HMAC_XXX_STATE pState, |
125 | | _In_reads_( cbData ) PCBYTE pbData, |
126 | | SIZE_T cbData ) |
127 | 189k | { |
128 | 189k | SYMCRYPT_XxxAppend( &pState->hash, pbData, cbData ); |
129 | 189k | } Line | Count | Source | 127 | 47.7k | { | 128 | 47.7k | SYMCRYPT_XxxAppend( &pState->hash, pbData, cbData ); | 129 | 47.7k | } |
Line | Count | Source | 127 | 42.0k | { | 128 | 42.0k | SYMCRYPT_XxxAppend( &pState->hash, pbData, cbData ); | 129 | 42.0k | } |
Line | Count | Source | 127 | 30.4k | { | 128 | 30.4k | SYMCRYPT_XxxAppend( &pState->hash, pbData, cbData ); | 129 | 30.4k | } |
Line | Count | Source | 127 | 25.5k | { | 128 | 25.5k | SYMCRYPT_XxxAppend( &pState->hash, pbData, cbData ); | 129 | 25.5k | } |
Line | Count | Source | 127 | 43.8k | { | 128 | 43.8k | SYMCRYPT_XxxAppend( &pState->hash, pbData, cbData ); | 129 | 43.8k | } |
|
130 | | |
131 | | C_ASSERT( SYMCRYPT_XXX_RESULT_SIZE == SYMCRYPT_HMAC_XXX_RESULT_SIZE ); |
132 | | |
133 | | SYMCRYPT_NOINLINE |
134 | | VOID |
135 | | SYMCRYPT_CALL |
136 | | SYMCRYPT_HmacXxxResult( |
137 | | _Inout_ PSYMCRYPT_HMAC_XXX_STATE pState, |
138 | | _Out_writes_( SYMCRYPT_HMAC_XXX_RESULT_SIZE ) PBYTE pbResult ) |
139 | 42.2k | { |
140 | 42.2k | BYTE innerRes[SYMCRYPT_XXX_RESULT_SIZE]; |
141 | | |
142 | 42.2k | SYMCRYPT_CHECK_MAGIC( pState ); |
143 | | |
144 | | // |
145 | | // We have to buffer the inner hash result. We can't put it directly in the |
146 | | // hash state data buffer as the Result() function wipes that buffer before returning. |
147 | | // |
148 | | |
149 | 42.2k | SYMCRYPT_XxxResult( &pState->hash, innerRes ); |
150 | | |
151 | 42.2k | SYMCRYPT_CHECK_MAGIC( pState->pKey ) |
152 | | |
153 | 42.2k | pState->hash.chain = pState->pKey->outerState; |
154 | | |
155 | | // |
156 | | // We put the data directly in the buffer, rather than call the Append function. |
157 | | // |
158 | 42.2k | memcpy( &pState->hash.buffer, innerRes, sizeof( innerRes ) ); |
159 | 42.2k | SET_DATALENGTH( pState->hash, SYMCRYPT_XXX_INPUT_BLOCK_SIZE + SYMCRYPT_XXX_RESULT_SIZE ); |
160 | 42.2k | pState->hash.bytesInBuffer = SYMCRYPT_XXX_RESULT_SIZE; |
161 | | |
162 | 42.2k | SYMCRYPT_XxxResult( &pState->hash, pbResult ); |
163 | | |
164 | | // |
165 | | // The SymCryptXxxResult already wipes the hash state. |
166 | | // We only need to wipe our own buffer. |
167 | | // |
168 | | // We also set the key pointer to NULL. This is not for security; |
169 | | // it creates a clear error when callers forget to call the Init routine |
170 | | // when re-using a state. Rather than the wrong result, they will get |
171 | | // a NULL pointer exception, and they will fix their code. |
172 | | // |
173 | | |
174 | 42.2k | SymCryptWipe( innerRes, sizeof( innerRes ) ); |
175 | 42.2k | pState->pKey = NULL; |
176 | 42.2k | } Line | Count | Source | 139 | 11.3k | { | 140 | 11.3k | BYTE innerRes[SYMCRYPT_XXX_RESULT_SIZE]; | 141 | | | 142 | 11.3k | SYMCRYPT_CHECK_MAGIC( pState ); | 143 | | | 144 | | // | 145 | | // We have to buffer the inner hash result. We can't put it directly in the | 146 | | // hash state data buffer as the Result() function wipes that buffer before returning. | 147 | | // | 148 | | | 149 | 11.3k | SYMCRYPT_XxxResult( &pState->hash, innerRes ); | 150 | | | 151 | 11.3k | SYMCRYPT_CHECK_MAGIC( pState->pKey ) | 152 | | | 153 | 11.3k | pState->hash.chain = pState->pKey->outerState; | 154 | | | 155 | | // | 156 | | // We put the data directly in the buffer, rather than call the Append function. | 157 | | // | 158 | 11.3k | memcpy( &pState->hash.buffer, innerRes, sizeof( innerRes ) ); | 159 | 11.3k | SET_DATALENGTH( pState->hash, SYMCRYPT_XXX_INPUT_BLOCK_SIZE + SYMCRYPT_XXX_RESULT_SIZE ); | 160 | 11.3k | pState->hash.bytesInBuffer = SYMCRYPT_XXX_RESULT_SIZE; | 161 | | | 162 | 11.3k | SYMCRYPT_XxxResult( &pState->hash, pbResult ); | 163 | | | 164 | | // | 165 | | // The SymCryptXxxResult already wipes the hash state. | 166 | | // We only need to wipe our own buffer. | 167 | | // | 168 | | // We also set the key pointer to NULL. This is not for security; | 169 | | // it creates a clear error when callers forget to call the Init routine | 170 | | // when re-using a state. Rather than the wrong result, they will get | 171 | | // a NULL pointer exception, and they will fix their code. | 172 | | // | 173 | | | 174 | 11.3k | SymCryptWipe( innerRes, sizeof( innerRes ) ); | 175 | 11.3k | pState->pKey = NULL; | 176 | 11.3k | } |
Line | Count | Source | 139 | 11.0k | { | 140 | 11.0k | BYTE innerRes[SYMCRYPT_XXX_RESULT_SIZE]; | 141 | | | 142 | 11.0k | SYMCRYPT_CHECK_MAGIC( pState ); | 143 | | | 144 | | // | 145 | | // We have to buffer the inner hash result. We can't put it directly in the | 146 | | // hash state data buffer as the Result() function wipes that buffer before returning. | 147 | | // | 148 | | | 149 | 11.0k | SYMCRYPT_XxxResult( &pState->hash, innerRes ); | 150 | | | 151 | 11.0k | SYMCRYPT_CHECK_MAGIC( pState->pKey ) | 152 | | | 153 | 11.0k | pState->hash.chain = pState->pKey->outerState; | 154 | | | 155 | | // | 156 | | // We put the data directly in the buffer, rather than call the Append function. | 157 | | // | 158 | 11.0k | memcpy( &pState->hash.buffer, innerRes, sizeof( innerRes ) ); | 159 | 11.0k | SET_DATALENGTH( pState->hash, SYMCRYPT_XXX_INPUT_BLOCK_SIZE + SYMCRYPT_XXX_RESULT_SIZE ); | 160 | 11.0k | pState->hash.bytesInBuffer = SYMCRYPT_XXX_RESULT_SIZE; | 161 | | | 162 | 11.0k | SYMCRYPT_XxxResult( &pState->hash, pbResult ); | 163 | | | 164 | | // | 165 | | // The SymCryptXxxResult already wipes the hash state. | 166 | | // We only need to wipe our own buffer. | 167 | | // | 168 | | // We also set the key pointer to NULL. This is not for security; | 169 | | // it creates a clear error when callers forget to call the Init routine | 170 | | // when re-using a state. Rather than the wrong result, they will get | 171 | | // a NULL pointer exception, and they will fix their code. | 172 | | // | 173 | | | 174 | 11.0k | SymCryptWipe( innerRes, sizeof( innerRes ) ); | 175 | 11.0k | pState->pKey = NULL; | 176 | 11.0k | } |
Line | Count | Source | 139 | 5.62k | { | 140 | 5.62k | BYTE innerRes[SYMCRYPT_XXX_RESULT_SIZE]; | 141 | | | 142 | 5.62k | SYMCRYPT_CHECK_MAGIC( pState ); | 143 | | | 144 | | // | 145 | | // We have to buffer the inner hash result. We can't put it directly in the | 146 | | // hash state data buffer as the Result() function wipes that buffer before returning. | 147 | | // | 148 | | | 149 | 5.62k | SYMCRYPT_XxxResult( &pState->hash, innerRes ); | 150 | | | 151 | 5.62k | SYMCRYPT_CHECK_MAGIC( pState->pKey ) | 152 | | | 153 | 5.62k | pState->hash.chain = pState->pKey->outerState; | 154 | | | 155 | | // | 156 | | // We put the data directly in the buffer, rather than call the Append function. | 157 | | // | 158 | 5.62k | memcpy( &pState->hash.buffer, innerRes, sizeof( innerRes ) ); | 159 | 5.62k | SET_DATALENGTH( pState->hash, SYMCRYPT_XXX_INPUT_BLOCK_SIZE + SYMCRYPT_XXX_RESULT_SIZE ); | 160 | 5.62k | pState->hash.bytesInBuffer = SYMCRYPT_XXX_RESULT_SIZE; | 161 | | | 162 | 5.62k | SYMCRYPT_XxxResult( &pState->hash, pbResult ); | 163 | | | 164 | | // | 165 | | // The SymCryptXxxResult already wipes the hash state. | 166 | | // We only need to wipe our own buffer. | 167 | | // | 168 | | // We also set the key pointer to NULL. This is not for security; | 169 | | // it creates a clear error when callers forget to call the Init routine | 170 | | // when re-using a state. Rather than the wrong result, they will get | 171 | | // a NULL pointer exception, and they will fix their code. | 172 | | // | 173 | | | 174 | 5.62k | SymCryptWipe( innerRes, sizeof( innerRes ) ); | 175 | 5.62k | pState->pKey = NULL; | 176 | 5.62k | } |
Line | Count | Source | 139 | 6.07k | { | 140 | 6.07k | BYTE innerRes[SYMCRYPT_XXX_RESULT_SIZE]; | 141 | | | 142 | 6.07k | SYMCRYPT_CHECK_MAGIC( pState ); | 143 | | | 144 | | // | 145 | | // We have to buffer the inner hash result. We can't put it directly in the | 146 | | // hash state data buffer as the Result() function wipes that buffer before returning. | 147 | | // | 148 | | | 149 | 6.07k | SYMCRYPT_XxxResult( &pState->hash, innerRes ); | 150 | | | 151 | 6.07k | SYMCRYPT_CHECK_MAGIC( pState->pKey ) | 152 | | | 153 | 6.07k | pState->hash.chain = pState->pKey->outerState; | 154 | | | 155 | | // | 156 | | // We put the data directly in the buffer, rather than call the Append function. | 157 | | // | 158 | 6.07k | memcpy( &pState->hash.buffer, innerRes, sizeof( innerRes ) ); | 159 | 6.07k | SET_DATALENGTH( pState->hash, SYMCRYPT_XXX_INPUT_BLOCK_SIZE + SYMCRYPT_XXX_RESULT_SIZE ); | 160 | 6.07k | pState->hash.bytesInBuffer = SYMCRYPT_XXX_RESULT_SIZE; | 161 | | | 162 | 6.07k | SYMCRYPT_XxxResult( &pState->hash, pbResult ); | 163 | | | 164 | | // | 165 | | // The SymCryptXxxResult already wipes the hash state. | 166 | | // We only need to wipe our own buffer. | 167 | | // | 168 | | // We also set the key pointer to NULL. This is not for security; | 169 | | // it creates a clear error when callers forget to call the Init routine | 170 | | // when re-using a state. Rather than the wrong result, they will get | 171 | | // a NULL pointer exception, and they will fix their code. | 172 | | // | 173 | | | 174 | 6.07k | SymCryptWipe( innerRes, sizeof( innerRes ) ); | 175 | 6.07k | pState->pKey = NULL; | 176 | 6.07k | } |
Line | Count | Source | 139 | 8.12k | { | 140 | 8.12k | BYTE innerRes[SYMCRYPT_XXX_RESULT_SIZE]; | 141 | | | 142 | 8.12k | SYMCRYPT_CHECK_MAGIC( pState ); | 143 | | | 144 | | // | 145 | | // We have to buffer the inner hash result. We can't put it directly in the | 146 | | // hash state data buffer as the Result() function wipes that buffer before returning. | 147 | | // | 148 | | | 149 | 8.12k | SYMCRYPT_XxxResult( &pState->hash, innerRes ); | 150 | | | 151 | 8.12k | SYMCRYPT_CHECK_MAGIC( pState->pKey ) | 152 | | | 153 | 8.12k | pState->hash.chain = pState->pKey->outerState; | 154 | | | 155 | | // | 156 | | // We put the data directly in the buffer, rather than call the Append function. | 157 | | // | 158 | 8.12k | memcpy( &pState->hash.buffer, innerRes, sizeof( innerRes ) ); | 159 | 8.12k | SET_DATALENGTH( pState->hash, SYMCRYPT_XXX_INPUT_BLOCK_SIZE + SYMCRYPT_XXX_RESULT_SIZE ); | 160 | 8.12k | pState->hash.bytesInBuffer = SYMCRYPT_XXX_RESULT_SIZE; | 161 | | | 162 | 8.12k | SYMCRYPT_XxxResult( &pState->hash, pbResult ); | 163 | | | 164 | | // | 165 | | // The SymCryptXxxResult already wipes the hash state. | 166 | | // We only need to wipe our own buffer. | 167 | | // | 168 | | // We also set the key pointer to NULL. This is not for security; | 169 | | // it creates a clear error when callers forget to call the Init routine | 170 | | // when re-using a state. Rather than the wrong result, they will get | 171 | | // a NULL pointer exception, and they will fix their code. | 172 | | // | 173 | | | 174 | 8.12k | SymCryptWipe( innerRes, sizeof( innerRes ) ); | 175 | 8.12k | pState->pKey = NULL; | 176 | 8.12k | } |
|
177 | | |
178 | | SYMCRYPT_NOINLINE |
179 | | VOID |
180 | | SYMCRYPT_CALL |
181 | | SYMCRYPT_HmacXxx( |
182 | | _In_ PCSYMCRYPT_HMAC_XXX_EXPANDED_KEY pExpandedKey, |
183 | | _In_reads_( cbData ) PCBYTE pbData, |
184 | | SIZE_T cbData, |
185 | | _Out_writes_( SYMCRYPT_HMAC_XXX_RESULT_SIZE ) PBYTE pbResult ) |
186 | 0 | { |
187 | 0 | SYMCRYPT_HMAC_XXX_STATE state; |
188 | |
|
189 | 0 | SYMCRYPT_HmacXxxInit( &state, pExpandedKey ); |
190 | 0 | SYMCRYPT_HmacXxxAppend( &state, pbData, cbData ); |
191 | 0 | SYMCRYPT_HmacXxxResult( &state, pbResult ); |
192 | |
|
193 | 0 | } Unexecuted instantiation: SymCryptHmacMd5 Unexecuted instantiation: SymCryptHmacSha1 Unexecuted instantiation: SymCryptHmacSha256 Unexecuted instantiation: SymCryptHmacSha384 Unexecuted instantiation: SymCryptHmacSha512 |