Skip to content

Commit c913222

Browse files
guao-xiaomixiaoxiang781216
authored andcommitted
testing/crypto: add SHA2-224 HMAC test case
Add SHA2-224 HMAC verification to the crypto hmac test using CRYPTO_SHA2_224_HMAC through the /dev/crypto interface. Uses standard HMAC test vectors producing a 28-byte digest. Signed-off-by: guao <guao@xiaomi.com>
1 parent 6a19675 commit c913222

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

testing/drivers/crypto/hmac.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,20 @@ FAR char *sha1_result[] =
129129
"\x97\xc6\x33\x56"
130130
};
131131

132+
FAR char *sha224_result[] =
133+
{
134+
"\x4e\x84\x1c\xe7\xa4\xae\x83\xfb\xcf\x71\xe3\xcd\x64\xbf\xbf\x27"
135+
"\x7f\x73\xa1\x46\x80\xaa\xe8\xc5\x18\xac\x78\x61",
136+
"\xa3\x0e\x01\x09\x8b\xc6\xdb\xbf\x45\x69\x0f\x3a\x7e\x9e\x6d\x0f"
137+
"\x8b\xbe\xa2\xa3\x9e\x61\x48\x00\x8f\xd0\x5e\x44",
138+
"\xcb\xff\x7c\x27\x16\xbb\xaa\x7c\x77\xbe\xd4\xf4\x91\xd3\xe8\x45"
139+
"\x6c\xb6\xc5\x74\xe9\x2f\x67\x2b\x29\x1a\xcf\x5b",
140+
"\x1b\xf1\xc2\x0e\x5b\x2e\x25\x3f\x51\x39\x5e\x1f\x22\xe1\x52\x06"
141+
"\xb3\x99\x24\x1d\x72\xa9\xa1\xa4\x60\x2d\x3e\x31",
142+
"\x76\x7d\xf3\x5c\x24\xcd\x61\xa4\xd7\xd3\xf0\xf4\xc3\xa2\xf2\x53"
143+
"\x99\x8a\x1e\x4a\x4e\x54\x22\x3c\x19\x95\x14\x10"
144+
};
145+
132146
FAR char *sha256_result[] =
133147
{
134148
"\x49\x2c\xe0\x20\xfe\x25\x34\xa5\x78\x9d\xc3\x84\x88\x06\xc7\x8f"
@@ -245,6 +259,7 @@ int main(void)
245259
{
246260
char output[32];
247261
int ret = 0;
262+
248263
for (int i = 0; i < nitems(testcase); i++)
249264
{
250265
ret += syshmac(CRYPTO_MD5_HMAC, testcase[i].key,
@@ -291,6 +306,29 @@ int main(void)
291306
}
292307
}
293308

309+
for (int i = 0; i < nitems(testcase); i++)
310+
{
311+
ret = syshmac(CRYPTO_SHA2_224_HMAC, testcase[i].key,
312+
testcase[i].keylen,
313+
testcase[i].data, testcase[i].datalen, output);
314+
if (ret)
315+
{
316+
printf("syshamc sha224 failed\n");
317+
}
318+
319+
ret = match((unsigned char *)sha224_result[i],
320+
(unsigned char *)output,
321+
SHA224_DIGEST_LENGTH);
322+
if (ret)
323+
{
324+
printf("match sha224 failed\n");
325+
}
326+
else
327+
{
328+
printf("hmac sha224 success\n");
329+
}
330+
}
331+
294332
for (int i = 0; i < nitems(testcase); i++)
295333
{
296334
ret = syshmac(CRYPTO_SHA2_256_HMAC, testcase[i].key,

0 commit comments

Comments
 (0)