-
Notifications
You must be signed in to change notification settings - Fork 13
Add generic and AES SKEY support #163
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
base: main
Are you sure you want to change the base?
Changes from all commits
005b4c8
62b4564
3849fb7
d8e64ce
0891064
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 |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
|
|
||
| #include "scossl_helpers.h" | ||
| #include "p_scossl_aes.h" | ||
| #include "p_scossl_skey.h" | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
|
|
@@ -120,6 +121,19 @@ static SCOSSL_STATUS p_scossl_aes_xts_decrypt_init(_Inout_ SCOSSL_AES_XTS_CTX *c | |
| return p_scossl_aes_xts_init_internal(ctx, 0, key, keylen, iv, ivlen, params); | ||
| } | ||
|
|
||
| static SCOSSL_STATUS p_scossl_aes_xts_skey_encrypt_init(_Inout_ SCOSSL_AES_XTS_CTX *ctx, _In_ SCOSSL_SKEY *skey, | ||
| _In_reads_bytes_opt_(ivlen) const unsigned char *iv, size_t ivlen, | ||
| _In_ const OSSL_PARAM params[]) | ||
| { | ||
| return p_scossl_aes_xts_init_internal((SCOSSL_AES_XTS_CTX *)ctx, 1, skey->pbKey, skey->cbKey, iv, ivlen, params); | ||
| } | ||
|
Contributor
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. Nit: Redundant cast — |
||
|
|
||
| static SCOSSL_STATUS p_scossl_aes_xts_skey_decrypt_init(_Inout_ SCOSSL_AES_XTS_CTX *ctx, _In_ SCOSSL_SKEY *skey, | ||
| _In_reads_bytes_opt_(ivlen) const unsigned char *iv, size_t ivlen, | ||
| _In_ const OSSL_PARAM params[]) | ||
| { | ||
| return p_scossl_aes_xts_init_internal((SCOSSL_AES_XTS_CTX *)ctx, 0, skey->pbKey, skey->cbKey, iv, ivlen, params); | ||
| } | ||
|
|
||
| static SCOSSL_STATUS p_scossl_aes_xts_cipher(SCOSSL_AES_XTS_CTX *ctx, | ||
| _Out_writes_bytes_(*outl) unsigned char *out, _Out_ size_t *outl, size_t outsize, | ||
|
|
@@ -274,6 +288,8 @@ static SCOSSL_STATUS p_scossl_aes_xts_set_ctx_params(_Inout_ SCOSSL_AES_XTS_CTX | |
| {OSSL_FUNC_CIPHER_GETTABLE_PARAMS, (void (*)(void))p_scossl_aes_generic_gettable_params}, \ | ||
| {OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS, (void (*)(void))p_scossl_aes_xts_gettable_ctx_params}, \ | ||
| {OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS, (void (*)(void))p_scossl_aes_xts_settable_ctx_params}, \ | ||
| {OSSL_FUNC_CIPHER_ENCRYPT_SKEY_INIT, (void (*)(void))p_scossl_aes_xts_skey_encrypt_init}, \ | ||
| {OSSL_FUNC_CIPHER_DECRYPT_SKEY_INIT, (void (*)(void))p_scossl_aes_xts_skey_decrypt_init}, \ | ||
| {0, NULL}}; | ||
mamckee marked this conversation as resolved.
Show resolved
Hide resolved
mamckee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| IMPLEMENT_SCOSSL_AES_XTS_CIPHER(128) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // | ||
| // Copyright (c) Microsoft Corporation. Licensed under the MIT license. | ||
| // | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "scossl_helpers.h" | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| #define SCOSSL_SKEY_TYPE_GENERIC 1 | ||
| #define SCOSSL_SKEY_TYPE_AES 2 | ||
|
|
||
| typedef struct | ||
| { | ||
| int type; | ||
|
|
||
| OSSL_LIB_CTX *libctx; | ||
|
|
||
| PBYTE pbKey; | ||
| SIZE_T cbKey; | ||
| } SCOSSL_SKEY; | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // | ||
| // Copyright (c) Microsoft Corporation. Licensed under the MIT license. | ||
| // | ||
|
|
||
| #include <openssl/proverr.h> | ||
|
|
||
| #include "p_scossl_generic_skeymgmt.h" | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| static const OSSL_PARAM p_scossl_aes_skeymgmt_settable_param_types[] = { | ||
| OSSL_PARAM_octet_string(OSSL_SKEY_PARAM_RAW_BYTES, NULL, 0), | ||
| OSSL_PARAM_END}; | ||
|
|
||
| static const OSSL_PARAM p_scossl_aes_skeygen_settable_param_types[] = { | ||
| OSSL_PARAM_size_t(OSSL_SKEY_PARAM_KEY_LENGTH, NULL), | ||
| OSSL_PARAM_END}; | ||
|
|
||
| static SCOSSL_SKEY *p_scossl_aes_skeymgmt_import(_In_ SCOSSL_PROVCTX *provctx, int selection, _In_ const OSSL_PARAM params[]) | ||
| { | ||
| SCOSSL_SKEY *skey = p_scossl_generic_skeymgmt_import(provctx, selection, params); | ||
|
|
||
| if (skey != NULL) | ||
| { | ||
| skey->type = SCOSSL_SKEY_TYPE_AES; | ||
|
|
||
| if (skey->cbKey != 16 && skey->cbKey != 24 && skey->cbKey != 32) | ||
| { | ||
|
Contributor
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. Nit: AES key length is validated after |
||
| ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH); | ||
| p_scossl_generic_skeymgmt_free(skey); | ||
| skey = NULL; | ||
| } | ||
| } | ||
|
|
||
| return skey; | ||
| } | ||
|
|
||
| static SCOSSL_STATUS p_scossl_aes_skeymgmt_export(_In_ SCOSSL_SKEY *skey, int selection, | ||
| _In_ OSSL_CALLBACK *param_cb, _In_ void *cbarg) | ||
| { | ||
| if (skey->type != SCOSSL_SKEY_TYPE_AES) | ||
| { | ||
| return SCOSSL_FAILURE; | ||
| } | ||
mamckee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return p_scossl_generic_skeymgmt_export(skey, selection, param_cb, cbarg); | ||
| } | ||
|
|
||
| static SCOSSL_SKEY *p_scossl_aes_skeygen_generate(_In_ SCOSSL_PROVCTX *provctx, _In_ const OSSL_PARAM params[]) | ||
| { | ||
| SCOSSL_SKEY *skey = p_scossl_generic_skeygen_generate(provctx, params); | ||
|
|
||
| if (skey != NULL) | ||
| { | ||
| skey->type = SCOSSL_SKEY_TYPE_AES; | ||
|
|
||
| if (skey->cbKey != 16 && skey->cbKey != 24 && skey->cbKey != 32) | ||
| { | ||
| ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH); | ||
| p_scossl_generic_skeymgmt_free(skey); | ||
| skey = NULL; | ||
| } | ||
| } | ||
|
|
||
| return skey; | ||
| } | ||
|
|
||
| static const OSSL_PARAM *p_scossl_aes_skeymgmt_imp_settable_params(ossl_unused void *provctx) | ||
| { | ||
| return p_scossl_aes_skeymgmt_settable_param_types; | ||
| } | ||
|
|
||
| static const OSSL_PARAM *p_scossl_aes_skeygen_settable_params(ossl_unused void *provctx) | ||
| { | ||
| return p_scossl_aes_skeygen_settable_param_types; | ||
| } | ||
|
|
||
| const OSSL_DISPATCH p_scossl_aes_skeymgmt_functions[] = { | ||
| {OSSL_FUNC_SKEYMGMT_FREE, (void (*)(void))p_scossl_generic_skeymgmt_free}, | ||
| {OSSL_FUNC_SKEYMGMT_IMPORT, (void (*)(void))p_scossl_aes_skeymgmt_import}, | ||
| {OSSL_FUNC_SKEYMGMT_EXPORT, (void (*)(void))p_scossl_aes_skeymgmt_export}, | ||
| {OSSL_FUNC_SKEYMGMT_GENERATE, (void (*)(void))p_scossl_aes_skeygen_generate}, | ||
| {OSSL_FUNC_SKEYMGMT_IMP_SETTABLE_PARAMS, (void (*)(void))p_scossl_aes_skeymgmt_imp_settable_params}, | ||
| {OSSL_FUNC_SKEYMGMT_GEN_SETTABLE_PARAMS, (void (*)(void))p_scossl_aes_skeygen_settable_params}, | ||
| {0, NULL}}; | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
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.
Question: This bumps the minimum OpenSSL requirement from any version to 3.5 globally, making the entire provider unbuildable with OpenSSL 3.0-3.4. The SKEYMGMT dispatch registration in
p_scossl_base.calready uses#ifdef OSSL_OP_SKEYMGMTguards — was making 3.5 the hard minimum intentional? If not, the new source files could be conditionally compiled and thefind_packageleft as-is.