Skip to content
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

Adding NISTDSA API to support ML-DSA-44 and ML-DSA-87 #1949

Closed
wants to merge 11 commits into from
66 changes: 66 additions & 0 deletions crypto/dilithium/internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR ISC

#ifndef AWSLC_HEADER_SIG_INTERNAL_H
#define AWSLC_HEADER_SIG_INTERNAL_H

#include <openssl/base.h>

#if defined(__cplusplus)
extern "C" {
#endif

// NISTDSA_METHOD structure and helper functions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should change the name NISTDSA, maybe to NIST_PQDSA or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to change the name -- originally wanted to use DSA but it was taken. I chose to add NIST because of the consistency between the FIPS 204, 205 standards, it seems as though any subsequent signature scheme standardizaed by NIST should follow these conventions. I didn't want to limit this to only signature schemes aimed towards PQ-secure use-cases.

typedef struct {
int (*keygen)(uint8_t *public_key,
uint8_t *secret_key);

int (*sign)(uint8_t *sig, size_t *sig_len,
const uint8_t *message,
size_t message_len,
const uint8_t *ctx,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's ctx?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctx was added to all NIST PQC candidates in the final version of the FIPS standards. It is a context string (byte string 255 or fewer bytes) that is used as additional input when signing. See page 17 of FIPS 204.

size_t ctx_len,
const uint8_t *secret_key);

int (*verify)(const uint8_t *message,
size_t message_len,
const uint8_t *sig,
size_t sig_len,
const uint8_t *ctx,
size_t ctx_len,
const uint8_t *public_key);

} NISTDSA_METHOD;

// NISTDSA structure and helper functions.
typedef struct {
int nid;
const uint8_t *oid;
uint8_t oid_len;
const char *comment;
size_t public_key_len;
size_t secret_key_len;
size_t signature_len;
size_t keygen_seed_len;
size_t sign_seed_len;
const NISTDSA_METHOD *method;
} NISTDSA;

// NISTDSA_KEY structure and helper functions.
struct nistdsa_st {
const NISTDSA *nistdsa;
uint8_t *public_key;
uint8_t *secret_key;
};

int NISTDSA_KEY_init(NISTDSA_KEY *key, const NISTDSA *nistdsa);
const NISTDSA * SIG_find_dsa_by_nid(int nid);
const NISTDSA *NISTDSA_KEY_get0_sig(NISTDSA_KEY* key);
NISTDSA_KEY *NISTDSA_KEY_new(void);
void NISTDSA_KEY_free(NISTDSA_KEY *key);

#if defined(__cplusplus)
} // extern C
#endif

#endif // AWSLC_HEADER_DSA_TEST_INTERNAL_H
902 changes: 902 additions & 0 deletions crypto/dilithium/kat/mldsa44.txt

Large diffs are not rendered by default.

902 changes: 902 additions & 0 deletions crypto/dilithium/kat/mldsa87.txt

Large diffs are not rendered by default.

Loading
Loading