-
Notifications
You must be signed in to change notification settings - Fork 122
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
Add runtime options to break the pairwise consistency test for Ed, ML-KEM, and ML-DSA #2192
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 OR ISC | ||
|
||
# This script attempts to break each of the key generation pair wise consistency tests and checks that doing so | ||
# seems to work and at least mentions the correct KAT in the output. | ||
|
||
set -x | ||
set -e | ||
|
||
TEST_FIPS_BIN="test_build_dir/util/fipstools/test_fips" | ||
|
||
if [ ! -f $TEST_FIPS_BIN ]; then | ||
echo "$TEST_FIPS_BIN is missing. Run this script from the top level of a" | ||
echo "BoringSSL checkout and ensure that ./build-fips-break-test-binaries.sh" | ||
echo "has been run first." | ||
exit 1 | ||
fi | ||
|
||
check_test_output() { | ||
local test_name="$1" | ||
local output="$2" | ||
case "$test_name" in | ||
"ECDSA_PWCT") expected="EC keygen checks failed" ;; | ||
"RSA_PWCT") expected="RSA keygen checks failed" ;; | ||
"MLKEM_PWCT") expected="ML-KEM keygen PCT failed" ;; | ||
"MLDSA_PWCT") expected="ML-DSA keygen PCT failed" ;; | ||
"EDDSA_PWCT") expected="Ed25519 keygen PCT failed" ;; | ||
*) echo "Unknown test: $test_name"; return 1 ;; | ||
esac | ||
|
||
if ! echo "$output" | grep -q "$expected"; then | ||
echo "Failure for ${test_name} did not contain expected message: '${expected}'" | ||
echo "Actual output was: '${output}'" | ||
return 1 | ||
fi | ||
return 0 | ||
} | ||
|
||
for runtime_test in ECDSA_PWCT RSA_PWCT EDDSA_PWCT MLKEM_PWCT MLDSA_PWCT; do | ||
output=$(2>&1 BORINGSSL_FIPS_BREAK_TEST=$runtime_test $TEST_FIPS_BIN 2>&1 >/dev/null || true) | ||
echo $output | ||
if ! check_test_output "$runtime_test" "$output"; then | ||
exit 1 | ||
fi | ||
done | ||
|
||
echo "All tests broken as expected" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
|
||
#include "../../crypto/fipsmodule/evp/internal.h" | ||
#include "../../crypto/fipsmodule/kem/internal.h" | ||
#include "../../crypto/fipsmodule/pqdsa/internal.h" | ||
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. Broader question, what is the purpose of 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. For example I'm pretty sure this doesn't have ed25519ph tested :) 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. You are correct, test_fips is a big file that turns into an executable with some of the algorithms. I think this file was used by BoringSSL to demonstrate certain things to their lab. We now use it in our CI to run/verify the break tests work as expected. In this case I needed to add algorithms to it to trigger the lazy self tests. The break-tests could use crypto_test, but it's a little hard to write tests for the FIPS failure abort cases. 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 doesn't need ed25519ph because this change is only adding support to break the pairwise consistency tests and all the Ed stuff uses the same keygen function. However I did need to add the the pre-hash changes to test breaking the self test and that's already checked in https://github.com/aws/aws-lc/blob/main/util/fipstools/test_fips.c#L416-L430. |
||
#include "../../crypto/fipsmodule/rand/internal.h" | ||
#include "../../crypto/internal.h" | ||
|
||
|
@@ -431,18 +432,33 @@ int main(int argc, char **argv) { | |
|
||
/* ML-KEM */ | ||
printf("About to Generate ML-KEM key\n"); | ||
EVP_PKEY *raw = NULL; | ||
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_KEM, NULL); | ||
if (ctx == NULL || !EVP_PKEY_CTX_kem_set_params(ctx, NID_MLKEM512) || | ||
!EVP_PKEY_keygen_init(ctx) || | ||
!EVP_PKEY_keygen(ctx, &raw)) { | ||
EVP_PKEY *kem_raw = NULL; | ||
EVP_PKEY_CTX *kem_ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_KEM, NULL); | ||
if (kem_ctx == NULL || !EVP_PKEY_CTX_kem_set_params(kem_ctx, NID_MLKEM512) || | ||
!EVP_PKEY_keygen_init(kem_ctx) || | ||
!EVP_PKEY_keygen(kem_ctx, &kem_raw)) { | ||
printf("ML-KEM keygen failed.\n"); | ||
goto err; | ||
} | ||
printf("Generated public key: "); | ||
hexdump(raw->pkey.kem_key->public_key, raw->pkey.kem_key->kem->public_key_len); | ||
EVP_PKEY_free(raw); | ||
EVP_PKEY_CTX_free(ctx); | ||
hexdump(kem_raw->pkey.kem_key->public_key, kem_raw->pkey.kem_key->kem->public_key_len); | ||
EVP_PKEY_free(kem_raw); | ||
EVP_PKEY_CTX_free(kem_ctx); | ||
|
||
/* ML-DSA */ | ||
printf("About to Generate ML-DSA key\n"); | ||
EVP_PKEY *dsa_raw = NULL; | ||
EVP_PKEY_CTX *dsa_ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_PQDSA, NULL); | ||
if (dsa_ctx == NULL || !EVP_PKEY_CTX_pqdsa_set_params(dsa_ctx, NID_MLDSA44) || | ||
!EVP_PKEY_keygen_init(dsa_ctx) || | ||
!EVP_PKEY_keygen(dsa_ctx, &dsa_raw)) { | ||
printf("ML-DSA keygen failed.\n"); | ||
goto err; | ||
} | ||
printf("Generated public key: "); | ||
hexdump(dsa_raw->pkey.pqdsa_key->public_key, dsa_raw->pkey.pqdsa_key->pqdsa->public_key_len); | ||
EVP_PKEY_free(dsa_raw); | ||
EVP_PKEY_CTX_free(dsa_ctx); | ||
|
||
/* DBRG */ | ||
CTR_DRBG_STATE drbg; | ||
|
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.
?