-
Notifications
You must be signed in to change notification settings - Fork 61
ACVP: Support FIPS203-tr1 encapDecap (v1.1.0.43) #1811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,6 +119,38 @@ static int decode_hex(const char *prefix, unsigned char *out, size_t out_len, | |
| return 1; | ||
| } | ||
|
|
||
| /* | ||
| * Decode the decapsulation-key argument into dk. It is either the expanded | ||
| * key ("dk=HEX", keyFormat 'expanded') or a seed d||z to expand via keyGen | ||
| * ("seed=HEX", keyFormat 'seed'). Returns 0 on success, 1 on failure. | ||
| * MLK_NOINLINE keeps the keyGen scratch (ek) out of the caller's (main's) | ||
| * stack frame; under -fsanitize=undefined it would not share slots and would | ||
| * overflow AVR RAM. | ||
| */ | ||
| static MLK_NOINLINE int decode_dk(const char *arg, | ||
| unsigned char dk[CRYPTO_SECRETKEYBYTES]) | ||
| { | ||
| size_t seed_len = strlen("seed="); | ||
|
|
||
| /* Prefix check via memcmp; strncmp is unavailable on baremetal builds. */ | ||
| if (strlen(arg) >= seed_len && memcmp(arg, "seed=", seed_len) == 0) | ||
| { | ||
| unsigned char ek[CRYPTO_PUBLICKEYBYTES]; | ||
| unsigned char coins[2 * MLKEM_SYMBYTES]; | ||
| if (decode_hex("seed", coins, sizeof(coins), arg) != 0) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NB: We should align this with mldsa-native, where |
||
| { | ||
| return 1; | ||
| } | ||
| if (crypto_kem_keypair_derand(ek, dk, coins) != 0) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This relates to pq-code-package/mldsa-native#1272. It would be nice to avoid the unused |
||
| { | ||
| fprintf(stderr, "Failed to expand seed into decapsulation key\n"); | ||
| return 1; | ||
| } | ||
| return 0; | ||
| } | ||
| return decode_hex("dk", dk, CRYPTO_SECRETKEYBYTES, arg); | ||
| } | ||
|
|
||
| static void print_hex(const char *name, const unsigned char *raw, size_t len) | ||
| { | ||
| if (name != NULL) | ||
|
|
@@ -321,8 +353,8 @@ int main(int argc, char *argv[]) | |
| goto decaps_usage; | ||
| } | ||
|
|
||
| /* Parse dk */ | ||
| if (argc == 0 || decode_hex("dk", dk, sizeof(dk), *argv) != 0) | ||
| /* Parse dk (expanded key, or a seed to expand) */ | ||
| if (argc == 0 || decode_dk(*argv, dk) != 0) | ||
| { | ||
| goto decaps_usage; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should open an issue to remove this once upstream is fixed