-
Notifications
You must be signed in to change notification settings - Fork 113
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
PQC proof-of-concept from SPDM 1.4 #2957
base: 1.4WIP
Are you sure you want to change the base?
Changes from all commits
1c8086e
3b4a720
9e81ee3
856fc44
5a7aad1
17d298d
0638b6e
11e4687
db14eb1
acca92b
69c7dd2
2dbf287
7674190
353bb06
1b3ea11
5308b59
56e29a7
b731743
6b040b9
a6d2b66
0c42770
7926d2e
067c450
d7d4c66
50da625
bf4281a
fbc10c2
79255b9
414c22e
daf398c
5fa4a14
51d2d85
b2287b2
37a5a26
3960473
a90a3cc
635265b
84ea365
09c6a43
b0873a7
73b6457
acfd0fc
8ad2e15
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 |
---|---|---|
|
@@ -4,6 +4,8 @@ on: | |
paths-ignore: | ||
- 'doc/**' | ||
- '**/*.md' | ||
branches: | ||
- main | ||
permissions: {} | ||
jobs: | ||
Fuzzing: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Copyright Notice: | ||
* Copyright 2021-2024 DMTF. All rights reserved. | ||
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. All new files need 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. One question: When do you think we will merge into main? I prefer to change that when we merge to main. It is meaningless to change it to 2025 now, and change again if we merge in 2026. |
||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md | ||
**/ | ||
|
||
#ifndef CRYPTLIB_CERT_PQC_H | ||
#define CRYPTLIB_CERT_PQC_H | ||
|
||
#if LIBSPDM_CERT_PARSE_SUPPORT | ||
/** | ||
* Retrieve the mldsa public key from one DER-encoded X509 certificate. | ||
* | ||
* @param[in] cert Pointer to the DER-encoded X509 certificate. | ||
* @param[in] cert_size Size of the X509 certificate in bytes. | ||
* @param[out] dsa_context Pointer to newly generated mldsa context which contain the retrieved | ||
* mldsa public key component. Use mldsa_free() function to free the | ||
* resource. | ||
* | ||
* If cert is NULL, then return false. | ||
* If dsa_context is NULL, then return false. | ||
* | ||
* @retval true mldsa public key was retrieved successfully. | ||
* @retval false Fail to retrieve mldsa public key from X509 certificate. | ||
* | ||
**/ | ||
extern bool libspdm_mldsa_get_public_key_from_x509(const uint8_t *cert, size_t cert_size, | ||
void **dsa_context); | ||
#endif /* LIBSPDM_CERT_PARSE_SUPPORT */ | ||
|
||
#endif /* CRYPTLIB_CERT_H */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/** | ||
* Copyright Notice: | ||
* Copyright 2024 DMTF. All rights reserved. | ||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md | ||
**/ | ||
|
||
#ifndef CRYPTLIB_MLDSA_H | ||
#define CRYPTLIB_MLDSA_H | ||
|
||
#if LIBSPDM_ML_DSA_SUPPORT | ||
|
||
/** | ||
* Allocates and initializes one DSA context for subsequent use. | ||
* | ||
* @param nid cipher NID | ||
* | ||
* @return Pointer to the DSA context that has been initialized. | ||
**/ | ||
extern void *libspdm_mldsa_new(size_t nid); | ||
|
||
/** | ||
* Release the specified DSA context. | ||
* | ||
* @param[in] dsa_context Pointer to the DSA context to be released. | ||
**/ | ||
extern void libspdm_mldsa_free(void *dsa_context); | ||
|
||
/** | ||
* Sets the key component into the established DSA context. | ||
* | ||
* @param[in, out] dsa_context Pointer to DSA context being set. | ||
* @param[in] key_data Pointer to octet integer buffer. | ||
* @param[in] key_size Size of big number buffer in bytes. | ||
* | ||
* @retval true DSA key component was set successfully. | ||
**/ | ||
extern bool libspdm_mldsa_set_pubkey(void *dsa_context, const uint8_t *key_data, size_t key_size); | ||
|
||
/** | ||
* Sets the key component into the established DSA context. | ||
* | ||
* @param[in, out] dsa_context Pointer to DSA context being set. | ||
* @param[in] key_data Pointer to octet integer buffer. | ||
* @param[in] key_size Size of big number buffer in bytes. | ||
* | ||
* @retval true DSA key component was set successfully. | ||
**/ | ||
extern bool libspdm_mldsa_set_privkey(void *dsa_context, const uint8_t *key_data, size_t key_size); | ||
|
||
/** | ||
* Generates DSA context from DER-encoded public key data. | ||
* | ||
* The public key is ASN.1 DER-encoded as RFC7250 describes, | ||
* namely, the SubjectPublicKeyInfo structure of a X.509 certificate. | ||
* | ||
* OID is defined in https://datatracker.ietf.org/doc/html/draft-ietf-lamps-dilithium-certificates | ||
* | ||
* @param[in] der_data Pointer to the DER-encoded public key data. | ||
* @param[in] der_size Size of the DER-encoded public key data in bytes. | ||
* @param[out] dsa_context Pointer to newly generated DSA context which contains the | ||
* DSA public key component. | ||
* Use libspdm_mldsa_free() function to free the resource. | ||
* | ||
* If der_data is NULL, then return false. | ||
* If dsa_context is NULL, then return false. | ||
* | ||
* @retval true DSA context was generated successfully. | ||
* @retval false Invalid DER public key data. | ||
* | ||
**/ | ||
extern bool libspdm_mldsa_get_public_key_from_der(const uint8_t *der_data, | ||
size_t der_size, | ||
void **dsa_context); | ||
|
||
/** | ||
* Carries out the MLDSA signature generation. | ||
* | ||
* @param[in] dsa_context Pointer to DSA context for signature generation. | ||
* @param[in] context The MLDSA signing context. | ||
* @param[in] context_size Size of MLDSA signing context. | ||
* @param[in] message Pointer to octet message to be signed. | ||
* @param[in] message_size Size of the message in bytes. | ||
* @param[out] signature Pointer to buffer to receive DSA signature. | ||
* @param[in, out] sig_size On input, the size of signature buffer in bytes. | ||
* On output, the size of data returned in signature buffer in bytes. | ||
* | ||
* @retval true signature successfully generated. | ||
* @retval false signature generation failed. | ||
* @retval false sig_size is too small. | ||
* @retval false This interface is not supported. | ||
**/ | ||
extern bool libspdm_mldsa_sign(void *dsa_context, | ||
const uint8_t *context, size_t context_size, | ||
const uint8_t *message, size_t message_size, | ||
uint8_t *signature, size_t *sig_size); | ||
|
||
/** | ||
* Verifies the MLDSA signature. | ||
* | ||
* @param[in] dsa_context Pointer to DSA context for signature verification. | ||
* @param[in] context The MLDSA signing context. | ||
* @param[in] context_size Size of MLDSA signing context. | ||
* @param[in] message Pointer to octet message to be checked. | ||
* @param[in] message_size Size of the message in bytes. | ||
* @param[in] signature Pointer to DSA signature to be verified. | ||
* @param[in] sig_size Size of signature in bytes. | ||
* | ||
* @retval true Valid signature encoded. | ||
* @retval false Invalid signature or invalid DSA context. | ||
**/ | ||
extern bool libspdm_mldsa_verify(void *dsa_context, | ||
const uint8_t *context, size_t context_size, | ||
const uint8_t *message, size_t message_size, | ||
const uint8_t *signature, size_t sig_size); | ||
|
||
#endif /* LIBSPDM_ML_DSA_SUPPORT */ | ||
#endif /* CRYPTLIB_MLDSA_H */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* Copyright Notice: | ||
* Copyright 2024 DMTF. All rights reserved. | ||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md | ||
**/ | ||
|
||
#ifndef CRYPTLIB_MLKEM_H | ||
#define CRYPTLIB_MLKEM_H | ||
|
||
#if LIBSPDM_ML_KEM_SUPPORT | ||
/** | ||
* Allocates and initializes one KEM context for subsequent use with the NID. | ||
* | ||
* @param nid cipher NID | ||
* | ||
* @return Pointer to the KEM context that has been initialized. | ||
**/ | ||
extern void *libspdm_mlkem_new_by_name(size_t nid); | ||
|
||
/** | ||
* Release the specified KEM context. | ||
* | ||
* @param[in] kem_context Pointer to the KEM context to be released. | ||
**/ | ||
extern void libspdm_mlkem_free(void *kem_context); | ||
|
||
/** | ||
* Generates KEM public key. | ||
* | ||
* @param[in, out] kem_context Pointer to the KEM context. | ||
* @param[out] encap_key Pointer to the buffer to receive generated public key. | ||
* @param[in, out] encap_key_size On input, the size of public_key buffer in bytes. | ||
* On output, the size of data returned in public_key buffer in | ||
* bytes. | ||
* | ||
* @retval true KEM public key generation succeeded. | ||
* @retval false KEM public key generation failed. | ||
* @retval false public_key_size is not large enough. | ||
* @retval false This interface is not supported. | ||
**/ | ||
extern bool libspdm_mlkem_generate_key(void *kem_context, uint8_t *encap_key, size_t *encap_key_size); | ||
|
||
/** | ||
* Computes exchanged common key. | ||
* | ||
* @param[in, out] kem_context Pointer to the KEM context. | ||
* @param[in] peer_encap_key Pointer to the peer's public key. | ||
* @param[in] peer_encap_key_size size of peer's public key in bytes. | ||
* @param[out] key Pointer to the buffer to receive generated key. | ||
* @param[in, out] key_size On input, the size of key buffer in bytes. | ||
* On output, the size of data returned in key buffer in | ||
* bytes. | ||
* | ||
* @retval true KEM exchanged key generation succeeded. | ||
* @retval false KEM exchanged key generation failed. | ||
* @retval false key_size is not large enough. | ||
* @retval false This interface is not supported. | ||
**/ | ||
extern bool libspdm_mlkem_encapsulate(void *kem_context, const uint8_t *peer_encap_key, | ||
size_t peer_encap_key_size, uint8_t *cipher_text, | ||
size_t *cipher_text_size, uint8_t *shared_secret, | ||
size_t *shared_secret_size); | ||
|
||
/** | ||
* Computes exchanged common key. | ||
* | ||
* @param[in, out] kem_context Pointer to the KEM context. | ||
* @param[in] peer_encap_key Pointer to the peer's public key. | ||
* @param[in] peer_encap_key_size size of peer's public key in bytes. | ||
* @param[out] key Pointer to the buffer to receive generated key. | ||
* @param[in, out] key_size On input, the size of key buffer in bytes. | ||
* On output, the size of data returned in key buffer in | ||
* bytes. | ||
* | ||
* @retval true KEM exchanged key generation succeeded. | ||
* @retval false KEM exchanged key generation failed. | ||
* @retval false key_size is not large enough. | ||
* @retval false This interface is not supported. | ||
**/ | ||
extern bool libspdm_mlkem_decapsulate(void *kem_context, const uint8_t *peer_cipher_text, | ||
size_t peer_cipher_text_size, uint8_t *shared_secret, | ||
size_t *shared_secret_size); | ||
|
||
#endif /* LIBSPDM_ML_KEM_SUPPORT */ | ||
#endif /* CRYPTLIB_MLKEM_H */ |
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.
pqccryptlib_oqs
->cryptlib_liboqs
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.
I think we need to add
pqc
prefix -pqccryptlib_liboqs
, because it is not parallel tocryptlib_openssl
orcryptlib_mbedtls
.