forked from OP-TEE/optee_test
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
regression: 4002: add NIST hmac vectors
Adds NIST HMAC test vectors to regression case 4002 with CFG_HASH_NIST_VECTORS=y. Only the first test in each group is used if CFG_HASH_NIST_VECTORS_LIMITED=y. Without CFG_HASH_NIST_VECTORS=y, CFG_HASH_NIST_VECTORS_LIMITED has no effect. Signed-off-by: Olivier Masse <[email protected]>
- Loading branch information
1 parent
e611a33
commit 62aca5b
Showing
4 changed files
with
194 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
#!/usr/bin/env python3 | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
# | ||
# Copyright 2023 NXP | ||
# | ||
|
||
limited = False | ||
|
||
def to_compound_str(val): | ||
assert len(val) % 2 == 0, "Only even sized values supported" | ||
if len(val) > 0: | ||
import re | ||
a = re.findall('..', val) | ||
b = "(const uint8_t []){" | ||
for s in a: | ||
b += "0x" + s + ", " | ||
b += "}, " + repr(len(val) / 2) + "," | ||
else: | ||
b = "NULL, 0," | ||
return b | ||
|
||
|
||
def generate_case(outf, myvars, algo): | ||
if limited and myvars['Count'] != '0': | ||
return | ||
|
||
if algo == "SHA1": | ||
# hashsize is 20 bytes | ||
if int(myvars['Tlen']) != 20: | ||
return | ||
# SHA1 maximum key size is 512 bits | ||
if int(myvars['Klen']) > 64: | ||
return | ||
elif algo == "SHA224": | ||
# hashsize is 28 bytes | ||
if int(myvars['Tlen']) != 28: | ||
return | ||
# SHA224 maximum key size is 512 bits | ||
if int(myvars['Klen']) > 64: | ||
return | ||
elif algo == "SHA256": | ||
# hashsize is 32 bytes | ||
if int(myvars['Tlen']) != 32: | ||
return | ||
# SHA256 maximum key size is 1024 bits | ||
if int(myvars['Klen']) > 128: | ||
return | ||
elif algo == "SHA384": | ||
# hashsize is 48 bytes | ||
if int(myvars['Tlen']) != 48: | ||
return | ||
# SHA384 maximum key size is 1024 bits | ||
if int(myvars['Klen']) > 128: | ||
return | ||
elif algo == "SHA512": | ||
# hashsize is 64 bytes | ||
if int(myvars['Tlen']) != 64: | ||
return | ||
# SHA512 maximum key size is 1024 bits | ||
if int(myvars['Klen']) > 128: | ||
return | ||
|
||
outf.write('{ TEE_ALG_HMAC_' + algo + ', TEE_TYPE_HMAC_' + algo + ',\n') | ||
outf.write('/* Key */ ' + to_compound_str(myvars['Key']) + '\n') | ||
outf.write('0,\n') | ||
outf.write('/* Msg */ ' + to_compound_str(myvars['Msg']) + '\n') | ||
outf.write('/* Mac */ ' + to_compound_str(myvars['Mac']) + '\n') | ||
outf.write('false },\n') | ||
|
||
|
||
def get_args(): | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser() | ||
|
||
parser.add_argument('--inf', required=True, | ||
type=argparse.FileType('r'), | ||
help='Name of input RSP file') | ||
|
||
parser.add_argument('--outf', required=True, | ||
type=argparse.FileType('w'), | ||
help='Name of output C file') | ||
|
||
parser.add_argument('--limited', action="store_true", | ||
help='Only run one test case from each group') | ||
|
||
return parser.parse_args() | ||
|
||
|
||
def main(): | ||
import re | ||
global limited | ||
args = get_args() | ||
inf = args.inf | ||
outf = args.outf | ||
myvars = {} | ||
|
||
algo = "SHA1" | ||
limited = args.limited | ||
|
||
for line in inf: | ||
myl = line.strip() | ||
if len(myl) == 0: | ||
continue | ||
if re.match('^#', myl): | ||
continue | ||
s = re.split('\W+', myl) | ||
s = list(filter(None, s)) | ||
if len(s) == 0: | ||
continue | ||
name = s[0] | ||
|
||
if name == 'L': | ||
if s[1] == '20': | ||
algo = "SHA1" | ||
elif s[1] == '28': | ||
algo = "SHA224" | ||
elif s[1] == '32': | ||
algo = "SHA256" | ||
elif s[1] == '48': | ||
algo = "SHA384" | ||
elif s[1] == '64': | ||
algo = "SHA512" | ||
continue | ||
|
||
if name == 'Count': | ||
if len(myvars) > 1: | ||
generate_case(outf, myvars, algo) | ||
myvars = {} | ||
|
||
if len(s) < 2: | ||
myvars[s[0]] = '' | ||
else: | ||
myvars[s[0]] = s[1] | ||
|
||
if len(s) < 2: | ||
continue | ||
val = s[1] | ||
|
||
if val == '00': | ||
myvars[s[0]] = '' | ||
|
||
if len(myvars) > 1: | ||
generate_case(outf, myvars, algo) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |