-
Notifications
You must be signed in to change notification settings - Fork 16
Backport ML-KEM for SCOSSL 1.10 #171
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
Open
mamckee
wants to merge
17
commits into
scossl-1.10
Choose a base branch
from
mamckee-mlkem-backport
base: scossl-1.10
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
bc7f949
ML-KEM and ML-KEM hybrid (#103)
mamckee 33474ca
Fix use of uninitialized memory and consistency of code handling allo…
mamckee 5b32264
Update ML-KEM for compatibility with OpenSSL 3.5 implementation (#153)
mamckee ca4b35b
Update version
mamckee de7e934
Undo cleanup code
mamckee 64516cb
Isolate ml-kem hybrid changes
mamckee 565ac16
Backport ML-KEM decoder memory fix
mamckee 662aab8
Minor bugfixes and cleanup
mamckee e764854
PR comments
mamckee f50a083
PR comments
mamckee a0793ef
Potential fix for pull request finding
mamckee b78ffb1
PR comments
mamckee eeaeaac
PR comments
mamckee 8eae2fa
PR comments
mamckee ff96792
PR comments
mamckee 8a1646f
Remove unused parameter
mamckee 4e168d7
Additional cleanup
mamckee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| // | ||
| // Copyright (c) Microsoft Corporation. Licensed under the MIT license. | ||
| // | ||
|
|
||
| #include "p_scossl_bio.h" | ||
| #include "p_scossl_decode_common.h" | ||
|
|
||
| #include <openssl/asn1t.h> | ||
| #include <openssl/core_object.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| ASN1_NDEF_SEQUENCE(SUBJECT_PUBKEY_INFO) = { | ||
| ASN1_SIMPLE(SUBJECT_PUBKEY_INFO, x509Alg, X509_ALGOR), | ||
| ASN1_SIMPLE(SUBJECT_PUBKEY_INFO, subjectPublicKey, ASN1_BIT_STRING), | ||
| } ASN1_SEQUENCE_END(SUBJECT_PUBKEY_INFO) | ||
|
|
||
| IMPLEMENT_ASN1_FUNCTIONS(SUBJECT_PUBKEY_INFO) | ||
|
|
||
| const OSSL_PARAM p_scossl_der_to_key_settable_param_types[] = { | ||
| OSSL_PARAM_END}; | ||
|
|
||
| _Use_decl_annotations_ | ||
| SCOSSL_DECODE_CTX *p_scossl_decode_newctx(SCOSSL_PROVCTX *provctx, const SCOSSL_DECODE_KEYTYPE_DESC *desc) | ||
| { | ||
| SCOSSL_DECODE_CTX *ctx = OPENSSL_zalloc(sizeof(SCOSSL_DECODE_CTX)); | ||
|
|
||
| if (ctx != NULL) | ||
| { | ||
| ctx->provctx = provctx; | ||
| ctx->desc = desc; | ||
| } | ||
|
|
||
| return ctx; | ||
| } | ||
|
|
||
| _Use_decl_annotations_ | ||
| void p_scossl_decode_freectx(SCOSSL_DECODE_CTX *ctx) | ||
| { | ||
| if (ctx == NULL) | ||
| return; | ||
|
|
||
| OPENSSL_free(ctx); | ||
| } | ||
|
|
||
| SCOSSL_STATUS p_scossl_decode_set_ctx_params(ossl_unused void *ctx, ossl_unused const OSSL_PARAM params[]) | ||
| { | ||
| return SCOSSL_SUCCESS; | ||
| } | ||
|
|
||
| const OSSL_PARAM *p_scossl_decode_settable_ctx_params(ossl_unused void *ctx) | ||
| { | ||
| return p_scossl_der_to_key_settable_param_types; | ||
| } | ||
|
|
||
| _Use_decl_annotations_ | ||
| BOOL p_scossl_decode_does_selection(const SCOSSL_DECODE_KEYTYPE_DESC *desc, int selection) | ||
| { | ||
| if (selection == 0) | ||
| { | ||
| return TRUE; | ||
| } | ||
|
|
||
| // Supporting private key implies supporting public key. | ||
| // Both imply supporting key parameters | ||
| return ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0 && (desc->selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) || | ||
| ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0 && (desc->selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) || | ||
| ((selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0 && (desc->selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0); | ||
| } | ||
|
|
||
| // This function should return SCOSSL_SUCCESS if it successfully decodes something, | ||
| // or decodes nothing at all. Another decoder may be able to decode the data into something. | ||
| // This function should only return SCOSSL_FAILURE if the data could be decoded, but further | ||
| // validation of the data failed in a way that another decoder could not handle. | ||
| _Use_decl_annotations_ | ||
| SCOSSL_STATUS p_scossl_decode(SCOSSL_DECODE_CTX *ctx, OSSL_CORE_BIO *in, int selection, | ||
| OSSL_CALLBACK *dataCb, void *dataCbArg, | ||
| ossl_unused OSSL_PASSPHRASE_CALLBACK *passphraseCb, ossl_unused void *passphraseCbArg) | ||
| { | ||
| BIO *bio = NULL; | ||
| PVOID keyCtx = NULL; | ||
| OSSL_PARAM cbParams[4]; | ||
| SCOSSL_STATUS ret = SCOSSL_SUCCESS; | ||
|
|
||
| if (selection == 0) | ||
| { | ||
| selection = ctx->desc->selection; | ||
| } | ||
|
|
||
| if ((selection & ctx->desc->selection) != 0 && | ||
| (bio = p_scossl_bio_new_from_core_bio(ctx->provctx, in)) != NULL) | ||
| { | ||
| keyCtx = ctx->desc->decodeInternal(ctx, bio); | ||
| } | ||
|
|
||
| if (keyCtx != NULL) | ||
| { | ||
| int objectType = OSSL_OBJECT_PKEY; | ||
|
|
||
| cbParams[0] = OSSL_PARAM_construct_int(OSSL_OBJECT_PARAM_TYPE, &objectType); | ||
| cbParams[1] = OSSL_PARAM_construct_utf8_string(OSSL_OBJECT_PARAM_DATA_TYPE, (char *)ctx->desc->dataType, 0); | ||
| cbParams[2] = OSSL_PARAM_construct_octet_string(OSSL_OBJECT_PARAM_REFERENCE, &keyCtx, sizeof(keyCtx)); | ||
| cbParams[3] = OSSL_PARAM_construct_end(); | ||
|
|
||
| if (dataCb(cbParams, dataCbArg)) | ||
| { | ||
| keyCtx = NULL; | ||
| } | ||
| else | ||
| { | ||
| ret = SCOSSL_FAILURE; | ||
| } | ||
| } | ||
|
|
||
| ctx->desc->freeKeyCtx(keyCtx); | ||
| BIO_free(bio); | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| const ASN1_ITEM *p_scossl_decode_subject_pubkey_asn1_item() | ||
| { | ||
| return ASN1_ITEM_rptr(SUBJECT_PUBKEY_INFO); | ||
| } | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // | ||
| // Copyright (c) Microsoft Corporation. Licensed under the MIT license. | ||
| // | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "p_scossl_base.h" | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| #define select_PrivateKeyInfo OSSL_KEYMGMT_SELECT_PRIVATE_KEY | ||
| #define select_SubjectPublicKeyInfo OSSL_KEYMGMT_SELECT_PUBLIC_KEY | ||
|
|
||
| typedef PVOID (*PSCOSSL_DECODE_INTERNAL_FN) (_In_ PVOID decodeCtx, _In_ BIO *bio); | ||
|
|
||
| typedef struct | ||
| { | ||
| const char *dataType; | ||
| int selection; | ||
|
|
||
| PSCOSSL_DECODE_INTERNAL_FN decodeInternal; | ||
| OSSL_FUNC_keymgmt_free_fn *freeKeyCtx; | ||
| } SCOSSL_DECODE_KEYTYPE_DESC; | ||
|
|
||
| typedef struct scossl_decode_ctx_st | ||
| { | ||
| SCOSSL_PROVCTX *provctx; | ||
|
|
||
| const SCOSSL_DECODE_KEYTYPE_DESC *desc; | ||
| } SCOSSL_DECODE_CTX; | ||
|
|
||
| typedef struct | ||
| { | ||
| X509_ALGOR *x509Alg; | ||
| ASN1_BIT_STRING *subjectPublicKey; | ||
| } SUBJECT_PUBKEY_INFO; | ||
|
|
||
| SCOSSL_DECODE_CTX *p_scossl_decode_newctx(_In_ SCOSSL_PROVCTX *provctx, _In_ const SCOSSL_DECODE_KEYTYPE_DESC *desc); | ||
| void p_scossl_decode_freectx(_Inout_ SCOSSL_DECODE_CTX *ctx); | ||
|
|
||
| SCOSSL_STATUS p_scossl_decode_set_ctx_params(ossl_unused void *ctx, ossl_unused const OSSL_PARAM params[]); | ||
| const OSSL_PARAM *p_scossl_decode_settable_ctx_params(ossl_unused void *ctx); | ||
|
|
||
| BOOL p_scossl_decode_does_selection(_In_ const SCOSSL_DECODE_KEYTYPE_DESC *desc, int selection); | ||
|
|
||
| SCOSSL_STATUS p_scossl_decode(_In_ SCOSSL_DECODE_CTX *ctx, _In_ OSSL_CORE_BIO *in, | ||
| int selection, | ||
| _In_ OSSL_CALLBACK *dataCb, _In_ void *dataCbArg, | ||
| ossl_unused OSSL_PASSPHRASE_CALLBACK *passphraseCb, ossl_unused void *passphraseCbArg); | ||
|
|
||
| const ASN1_ITEM *p_scossl_decode_subject_pubkey_asn1_item(); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.