Skip to content

Commit

Permalink
Check return value and print out ML-KEM public key for fun
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewhop committed Feb 7, 2025
1 parent c46e296 commit a7f44ac
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions util/fipstools/test_fips.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <openssl/rsa.h>
#include <openssl/sha.h>

#include "../../crypto/fipsmodule/evp/internal.h"
#include "../../crypto/fipsmodule/kem/internal.h"
#include "../../crypto/fipsmodule/rand/internal.h"
#include "../../crypto/internal.h"

Expand Down Expand Up @@ -428,11 +430,17 @@ int main(int argc, char **argv) {
hexdump(ed_signature, sizeof(ed_signature));

/* ML-KEM */
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_KEM, NULL);
EVP_PKEY_CTX_kem_set_params(ctx, NID_MLKEM512);
EVP_PKEY_keygen_init(ctx);
printf("About to Generate ML-KEM key\n");
EVP_PKEY *raw = NULL;
EVP_PKEY_keygen(ctx, &raw);
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)) {
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);

Expand Down

0 comments on commit a7f44ac

Please sign in to comment.