ReactOS 0.4.17-dev-1005-g171e1de
kmac.c
Go to the documentation of this file.
1//
2// kmac.c
3//
4// Copyright (c) Microsoft Corporation. Licensed under the MIT license.
5//
6
7#include "precomp.h"
8
9
10//
11// KMAC128
12//
13#define Alg Kmac128
14#define ALG KMAC128
15#define SYMCRYPT_CSHAKEXXX_INIT SymCryptCShake128Init
16#define SYMCRYPT_CSHAKEXXX_STATE SYMCRYPT_CSHAKE128_STATE
17#define SYMCRYPT_KMACXXX_RESULT_SIZE SYMCRYPT_KMAC128_RESULT_SIZE
18#include "kmac_pattern.c"
19#undef SYMCRYPT_KMACXXX_RESULT_SIZE
20#undef SYMCRYPT_CSHAKEXXX_STATE
21#undef SYMCRYPT_CSHAKEXXX_INIT
22#undef ALG
23#undef Alg
24
25// MAC interface
34 NULL, // ppHashAlgorithm
35 0, // outerChainingStateOffset
36};
37
39
41 0xea, 0xe9, 0xde, 0xd3, 0xee, 0x2f, 0x34, 0x8a,
42 0xd6, 0xd2, 0xcb, 0x70, 0x4b, 0xba, 0xd4, 0x47,
43 0x15, 0x32, 0x46, 0x82, 0x8e, 0x41, 0x3a, 0xf5,
44 0xf5, 0x62, 0x96, 0x1a, 0xf7, 0x67, 0x48, 0xc1
45};
46
47VOID
50{
52 static const unsigned char Sstr[] = { 'S' };
54
55 SymCryptKmac128ExpandKeyEx(&expandedKey, SymCryptTestKey32, 16, Sstr, sizeof(Sstr));
56
58
60
61 if (memcmp(result, kmac128KATAnswer, sizeof(result)) != 0)
62 {
63 SymCryptFatal('kmac');
64 }
65}
66
67
68//
69// KMAC256
70//
71#define Alg Kmac256
72#define ALG KMAC256
73#define SYMCRYPT_CSHAKEXXX_INIT SymCryptCShake256Init
74#define SYMCRYPT_CSHAKEXXX_STATE SYMCRYPT_CSHAKE256_STATE
75#define SYMCRYPT_KMACXXX_RESULT_SIZE SYMCRYPT_KMAC256_RESULT_SIZE
76#include "kmac_pattern.c"
77#undef SYMCRYPT_KMACXXX_RESULT_SIZE
78#undef SYMCRYPT_CSHAKEXXX_STATE
79#undef SYMCRYPT_CSHAKEXXX_INIT
80#undef ALG
81#undef Alg
82
83// MAC interface
92 NULL, // ppHashAlgorithm
93 0, // outerChainingStateOffset
94};
95
97
99 0xa9, 0x1d, 0x09, 0x00, 0x71, 0x0c, 0x63, 0xc5, 0x0f, 0xb6, 0x4d, 0xfa, 0xd8, 0x75, 0x4d, 0x78,
100 0x2d, 0xc0, 0x82, 0x4b, 0x87, 0x97, 0xda, 0xf2, 0x36, 0xde, 0xe9, 0x35, 0x69, 0x2e, 0x50, 0x81,
101 0x0a, 0xea, 0x3b, 0x05, 0xaf, 0x1b, 0x82, 0x3b, 0xc8, 0xa1, 0x9e, 0xe9, 0x9c, 0x5f, 0xd5, 0x5a,
102 0x20, 0x92, 0x89, 0x46, 0xa4, 0xe4, 0x1a, 0xdd, 0x3d, 0xb6, 0x47, 0x4d, 0xf2, 0xa5, 0xfc, 0x73
103};
104
105VOID
108{
110 static const unsigned char Sstr[] = { 'S' };
112
113 SymCryptKmac256ExpandKeyEx(&expandedKey, SymCryptTestKey32, 32, Sstr, sizeof(Sstr));
114
116
118
119 if (memcmp(result, kmac256KATAnswer, sizeof(result)) != 0)
120 {
121 SymCryptFatal('kmac');
122 }
123}
#define NULL
Definition: types.h:112
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2807
GLuint64EXT * result
Definition: glext.h:11304
static const BYTE kmac256KATAnswer[SYMCRYPT_KMAC256_RESULT_SIZE]
Definition: kmac.c:98
const PCSYMCRYPT_MAC SymCryptKmac256Algorithm
Definition: kmac.c:96
const PCSYMCRYPT_MAC SymCryptKmac128Algorithm
Definition: kmac.c:38
VOID SYMCRYPT_CALL SymCryptKmac256Selftest(void)
Definition: kmac.c:107
const SYMCRYPT_MAC SymCryptKmac256Algorithm_Default
Definition: kmac.c:84
VOID SYMCRYPT_CALL SymCryptKmac128Selftest(void)
Definition: kmac.c:49
const SYMCRYPT_MAC SymCryptKmac128Algorithm_Default
Definition: kmac.c:26
static const BYTE kmac128KATAnswer[SYMCRYPT_KMAC128_RESULT_SIZE]
Definition: kmac.c:40
const BYTE SymCryptTestMsg16[16]
Definition: selftest.c:15
VOID SYMCRYPT_CALL SymCryptInjectError(PBYTE pbData, SIZE_T cbData)
const BYTE SymCryptTestKey32[32]
Definition: selftest.c:10
#define SYMCRYPT_KMAC256_RESULT_SIZE
Definition: symcrypt.h:3762
VOID SYMCRYPT_CALL SymCryptKmac256Append(_Inout_ PSYMCRYPT_KMAC256_STATE pState, _In_reads_(cbData) PCBYTE pbData, SIZE_T cbData)
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptKmac256ExpandKeyEx(_Out_ PSYMCRYPT_KMAC256_EXPANDED_KEY pExpandedKey, _In_reads_bytes_(cbKey) PCBYTE pbKey, SIZE_T cbKey, _In_reads_bytes_(cbCustomizationString) PCBYTE pbCustomizationString, SIZE_T cbCustomizationString)
_Analysis_noreturn_ VOID SYMCRYPT_CALL SymCryptFatal(UINT32 fatalCode)
VOID SYMCRYPT_CALL SymCryptKmac128Init(_Out_ PSYMCRYPT_KMAC128_STATE pState, _In_ PCSYMCRYPT_KMAC128_EXPANDED_KEY pExpandedKey)
#define SYMCRYPT_KMAC128_RESULT_SIZE
Definition: symcrypt.h:3674
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptKmac256ExpandKey(_Out_ PSYMCRYPT_KMAC256_EXPANDED_KEY pExpandedKey, _In_reads_bytes_(cbKey) PCBYTE pbKey, SIZE_T cbKey)
VOID SYMCRYPT_CALL SymCryptKmac256Init(_Out_ PSYMCRYPT_KMAC256_STATE pState, _In_ PCSYMCRYPT_KMAC256_EXPANDED_KEY pExpandedKey)
VOID SYMCRYPT_CALL SymCryptKmac256Result(_Inout_ PSYMCRYPT_KMAC256_STATE pState, _Out_writes_(SYMCRYPT_KMAC256_RESULT_SIZE) PBYTE pbResult)
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptKmac128ExpandKeyEx(_Out_ PSYMCRYPT_KMAC128_EXPANDED_KEY pExpandedKey, _In_reads_bytes_(cbKey) PCBYTE pbKey, SIZE_T cbKey, _In_reads_bytes_(cbCustomizationString) PCBYTE pbCustomizationString, SIZE_T cbCustomizationString)
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptKmac128ExpandKey(_Out_ PSYMCRYPT_KMAC128_EXPANDED_KEY pExpandedKey, _In_reads_bytes_(cbKey) PCBYTE pbKey, SIZE_T cbKey)
VOID SYMCRYPT_CALL SymCryptKmac256(_In_ PCSYMCRYPT_KMAC256_EXPANDED_KEY pExpandedKey, _In_reads_bytes_(cbInput) PCBYTE pbInput, SIZE_T cbInput, _Out_writes_bytes_(SYMCRYPT_KMAC256_RESULT_SIZE) PBYTE pbResult)
VOID SYMCRYPT_CALL SymCryptKmac128Result(_Inout_ PSYMCRYPT_KMAC128_STATE pState, _Out_writes_(SYMCRYPT_KMAC128_RESULT_SIZE) PBYTE pbResult)
VOID SYMCRYPT_CALL SymCryptKmac128(_In_ PCSYMCRYPT_KMAC128_EXPANDED_KEY pExpandedKey, _In_reads_bytes_(cbInput) PCBYTE pbInput, SIZE_T cbInput, _Out_writes_bytes_(SYMCRYPT_KMAC128_RESULT_SIZE) PBYTE pbResult)
VOID SYMCRYPT_CALL SymCryptKmac128Append(_Inout_ PSYMCRYPT_KMAC128_STATE pState, _In_reads_(cbData) PCBYTE pbData, SIZE_T cbData)
#define SYMCRYPT_CALL
SYMCRYPT_MAGIC_FIELD SYMCRYPT_KMAC128_STATE
SYMCRYPT_MAGIC_FIELD SYMCRYPT_KMAC256_EXPANDED_KEY
SYMCRYPT_MAGIC_FIELD SYMCRYPT_KMAC128_EXPANDED_KEY
SYMCRYPT_MAGIC_FIELD SYMCRYPT_KMAC256_STATE
unsigned char BYTE
Definition: xxhash.c:193