Latest update.
This commit is contained in:
@@ -89,7 +89,16 @@ static int rsa_init(void *vprsactx, void *vrsa)
|
||||
return 0;
|
||||
RSA_free(prsactx->rsa);
|
||||
prsactx->rsa = vrsa;
|
||||
prsactx->pad_mode = RSA_PKCS1_PADDING;
|
||||
|
||||
switch (RSA_test_flags(prsactx->rsa, RSA_FLAG_TYPE_MASK)) {
|
||||
case RSA_FLAG_TYPE_RSA:
|
||||
prsactx->pad_mode = RSA_PKCS1_PADDING;
|
||||
break;
|
||||
default:
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ static int aes_ocb_block_update_internal(PROV_AES_OCB_CTX *ctx,
|
||||
size_t nextblocks;
|
||||
size_t outlint = 0;
|
||||
|
||||
if (bufsz != 0)
|
||||
if (*bufsz != 0)
|
||||
nextblocks = fillblock(buf, bufsz, AES_BLOCK_SIZE, &in, &inl);
|
||||
else
|
||||
nextblocks = inl & ~(AES_BLOCK_SIZE-1);
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
#include "cipher_aes_xts.h"
|
||||
|
||||
#ifdef FIPS_MODE
|
||||
#ifdef FIPS_MODULE
|
||||
const int allow_insecure_decrypt = 0;
|
||||
#else
|
||||
const int allow_insecure_decrypt = 1;
|
||||
#endif /* FIPS_MODE */
|
||||
#endif /* FIPS_MODULE */
|
||||
@@ -49,7 +49,7 @@ static void *cast5_dupctx(void *ctx)
|
||||
IMPLEMENT_var_keylen_cipher(cast5, CAST, ecb, ECB, CAST5_FLAGS, 128, 64, 0, block)
|
||||
/* cast5128cbc_functions */
|
||||
IMPLEMENT_var_keylen_cipher(cast5, CAST, cbc, CBC, CAST5_FLAGS, 128, 64, 64, block)
|
||||
/* cast564ofb64_functions */
|
||||
IMPLEMENT_var_keylen_cipher(cast5, CAST, ofb64, OFB, CAST5_FLAGS, 64, 8, 64, stream)
|
||||
/* cast564cfb64_functions */
|
||||
IMPLEMENT_var_keylen_cipher(cast5, CAST, cfb64, CFB, CAST5_FLAGS, 64, 8, 64, stream)
|
||||
/* cast5128ofb64_functions */
|
||||
IMPLEMENT_var_keylen_cipher(cast5, CAST, ofb64, OFB, CAST5_FLAGS, 128, 8, 64, stream)
|
||||
/* cast5128cfb64_functions */
|
||||
IMPLEMENT_var_keylen_cipher(cast5, CAST, cfb64, CFB, CAST5_FLAGS, 128, 8, 64, stream)
|
||||
@@ -65,7 +65,13 @@ static int cipher_hw_des_ecb_cipher(PROV_CIPHER_CTX *ctx, unsigned char *out,
|
||||
static int cipher_hw_des_cbc_cipher(PROV_CIPHER_CTX *ctx, unsigned char *out,
|
||||
const unsigned char *in, size_t len)
|
||||
{
|
||||
DES_key_schedule *key = &(((PROV_DES_CTX *)ctx)->dks.ks);
|
||||
PROV_DES_CTX *dctx = (PROV_DES_CTX *)ctx;
|
||||
DES_key_schedule *key = &(dctx->dks.ks);
|
||||
|
||||
if (dctx->dstream.cbc != NULL) {
|
||||
(*dctx->dstream.cbc) (in, out, len, key, ctx->iv);
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (len >= MAXCHUNK) {
|
||||
DES_ncbc_encrypt(in, out, MAXCHUNK, key, (DES_cblock *)ctx->iv,
|
||||
|
||||
@@ -458,7 +458,7 @@ int ecdh_plain_derive(void *vpecdhctx, unsigned char *secret,
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
#ifndef FIPS_MODULE
|
||||
static ossl_inline
|
||||
int ecdh_X9_63_kdf_derive(void *vpecdhctx, unsigned char *secret,
|
||||
size_t *psecretlen, size_t outlen)
|
||||
@@ -498,7 +498,7 @@ int ecdh_X9_63_kdf_derive(void *vpecdhctx, unsigned char *secret,
|
||||
OPENSSL_secure_clear_free(stmp, stmplen);
|
||||
return ret;
|
||||
}
|
||||
#endif /* FIPS_MODE */
|
||||
#endif /* FIPS_MODULE */
|
||||
|
||||
static
|
||||
int ecdh_derive(void *vpecdhctx, unsigned char *secret,
|
||||
@@ -509,11 +509,11 @@ int ecdh_derive(void *vpecdhctx, unsigned char *secret,
|
||||
switch (pecdhctx->kdf_type) {
|
||||
case PROV_ECDH_KDF_NONE:
|
||||
return ecdh_plain_derive(vpecdhctx, secret, psecretlen, outlen);
|
||||
#ifndef FIPS_MODE
|
||||
#ifndef FIPS_MODULE
|
||||
case PROV_ECDH_KDF_X9_63:
|
||||
return ecdh_X9_63_kdf_derive(vpecdhctx, secret, psecretlen, outlen);
|
||||
|
||||
#endif /* FIPS_MODE */
|
||||
#endif /* FIPS_MODULE */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -148,8 +148,8 @@ extern const OSSL_DISPATCH idea128cfb64_functions[];
|
||||
#ifndef OPENSSL_NO_CAST
|
||||
extern const OSSL_DISPATCH cast5128ecb_functions[];
|
||||
extern const OSSL_DISPATCH cast5128cbc_functions[];
|
||||
extern const OSSL_DISPATCH cast564ofb64_functions[];
|
||||
extern const OSSL_DISPATCH cast564cfb64_functions[];
|
||||
extern const OSSL_DISPATCH cast5128ofb64_functions[];
|
||||
extern const OSSL_DISPATCH cast5128cfb64_functions[];
|
||||
#endif /* OPENSSL_NO_CAST */
|
||||
#ifndef OPENSSL_NO_SEED
|
||||
extern const OSSL_DISPATCH seed128ecb_functions[];
|
||||
@@ -181,7 +181,7 @@ extern const OSSL_DISPATCH rc2128ofb128_functions[];
|
||||
#ifndef OPENSSL_NO_DES
|
||||
extern const OSSL_DISPATCH tdes_ede3_ecb_functions[];
|
||||
extern const OSSL_DISPATCH tdes_ede3_cbc_functions[];
|
||||
# ifndef FIPS_MODE
|
||||
# ifndef FIPS_MODULE
|
||||
extern const OSSL_DISPATCH tdes_ede3_ofb_functions[];
|
||||
extern const OSSL_DISPATCH tdes_ede3_cfb_functions[];
|
||||
extern const OSSL_DISPATCH tdes_ede3_cfb8_functions[];
|
||||
@@ -201,7 +201,7 @@ extern const OSSL_DISPATCH des_ofb64_functions[];
|
||||
extern const OSSL_DISPATCH des_cfb64_functions[];
|
||||
extern const OSSL_DISPATCH des_cfb1_functions[];
|
||||
extern const OSSL_DISPATCH des_cfb8_functions[];
|
||||
# endif /* FIPS_MODE */
|
||||
# endif /* FIPS_MODULE */
|
||||
#endif /* OPENSSL_NO_DES */
|
||||
|
||||
#ifndef OPENSSL_NO_RC4
|
||||
@@ -257,6 +257,7 @@ extern const OSSL_DISPATCH kdf_krb5kdf_functions[];
|
||||
extern const OSSL_DISPATCH dh_keymgmt_functions[];
|
||||
extern const OSSL_DISPATCH dsa_keymgmt_functions[];
|
||||
extern const OSSL_DISPATCH rsa_keymgmt_functions[];
|
||||
extern const OSSL_DISPATCH rsapss_keymgmt_functions[];
|
||||
extern const OSSL_DISPATCH x25519_keymgmt_functions[];
|
||||
extern const OSSL_DISPATCH x448_keymgmt_functions[];
|
||||
extern const OSSL_DISPATCH ed25519_keymgmt_functions[];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -13,8 +13,8 @@
|
||||
* For backwards compatibility reasons,
|
||||
* Extra checks are done by default in fips mode only.
|
||||
*/
|
||||
#ifdef FIPS_MODE
|
||||
#ifdef FIPS_MODULE
|
||||
const int kdf_pbkdf2_default_checks = 1;
|
||||
#else
|
||||
const int kdf_pbkdf2_default_checks = 0;
|
||||
#endif /* FIPS_MODE */
|
||||
#endif /* FIPS_MODULE */
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright 2018-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
|
||||
@@ -322,6 +322,8 @@ static int dh_validate_public(DH *dh)
|
||||
const BIGNUM *pub_key = NULL;
|
||||
|
||||
DH_get0_key(dh, &pub_key, NULL);
|
||||
if (pub_key == NULL)
|
||||
return 0;
|
||||
return DH_check_pub_key_ex(dh, pub_key);
|
||||
}
|
||||
|
||||
@@ -331,6 +333,8 @@ static int dh_validate_private(DH *dh)
|
||||
const BIGNUM *priv_key = NULL;
|
||||
|
||||
DH_get0_key(dh, NULL, &priv_key);
|
||||
if (priv_key == NULL)
|
||||
return 0;
|
||||
return dh_check_priv_key(dh, priv_key, &status);;
|
||||
}
|
||||
|
||||
|
||||
@@ -312,6 +312,8 @@ static int dsa_validate_public(DSA *dsa)
|
||||
const BIGNUM *pub_key = NULL;
|
||||
|
||||
DSA_get0_key(dsa, &pub_key, NULL);
|
||||
if (pub_key == NULL)
|
||||
return 0;
|
||||
return dsa_check_pub_key(dsa, pub_key, &status);
|
||||
}
|
||||
|
||||
@@ -321,6 +323,8 @@ static int dsa_validate_private(DSA *dsa)
|
||||
const BIGNUM *priv_key = NULL;
|
||||
|
||||
DSA_get0_key(dsa, NULL, &priv_key);
|
||||
if (priv_key == NULL)
|
||||
return 0;
|
||||
return dsa_check_priv_key(dsa, priv_key, &status);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,6 @@ static OSSL_OP_keymgmt_gen_init_fn ec_gen_init;
|
||||
static OSSL_OP_keymgmt_gen_set_template_fn ec_gen_set_template;
|
||||
static OSSL_OP_keymgmt_gen_set_params_fn ec_gen_set_params;
|
||||
static OSSL_OP_keymgmt_gen_settable_params_fn ec_gen_settable_params;
|
||||
static OSSL_OP_keymgmt_gen_get_params_fn ec_gen_get_params;
|
||||
static OSSL_OP_keymgmt_gen_gettable_params_fn ec_gen_gettable_params;
|
||||
static OSSL_OP_keymgmt_gen_fn ec_gen;
|
||||
static OSSL_OP_keymgmt_gen_cleanup_fn ec_gen_cleanup;
|
||||
static OSSL_OP_keymgmt_free_fn ec_freedata;
|
||||
@@ -679,39 +677,6 @@ static const OSSL_PARAM *ec_gen_settable_params(void *provctx)
|
||||
return settable;
|
||||
}
|
||||
|
||||
static int ec_gen_get_params(void *genctx, OSSL_PARAM params[])
|
||||
{
|
||||
struct ec_gen_ctx *gctx = genctx;
|
||||
OSSL_PARAM *p;
|
||||
|
||||
if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_EC_NAME)) != NULL) {
|
||||
int nid = EC_GROUP_get_curve_name(gctx->gen_group);
|
||||
int ret = 0;
|
||||
const char *curve_name = ec_curve_nid2name(nid);
|
||||
|
||||
switch (p->data_type) {
|
||||
case OSSL_PARAM_UTF8_STRING:
|
||||
ret = OSSL_PARAM_set_utf8_string(p, curve_name);
|
||||
break;
|
||||
case OSSL_PARAM_UTF8_PTR:
|
||||
ret = OSSL_PARAM_set_utf8_ptr(p, curve_name);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const OSSL_PARAM *ec_gen_gettable_params(void *provctx)
|
||||
{
|
||||
static OSSL_PARAM gettable[] = {
|
||||
{ OSSL_PKEY_PARAM_EC_NAME, OSSL_PARAM_UTF8_PTR, NULL, 0, 0 },
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
|
||||
return gettable;
|
||||
}
|
||||
|
||||
static int ec_gen_assign_group(EC_KEY *ec, EC_GROUP *group)
|
||||
{
|
||||
if (group == NULL) {
|
||||
@@ -767,9 +732,6 @@ const OSSL_DISPATCH ec_keymgmt_functions[] = {
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS, (void (*)(void))ec_gen_set_params },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS,
|
||||
(void (*)(void))ec_gen_settable_params },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_GET_PARAMS, (void (*)(void))ec_gen_get_params },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_GETTABLE_PARAMS,
|
||||
(void (*)(void))ec_gen_gettable_params },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN, (void (*)(void))ec_gen },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_CLEANUP, (void (*)(void))ec_gen_cleanup },
|
||||
{ OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))ec_freedata },
|
||||
|
||||
@@ -47,6 +47,7 @@ static OSSL_OP_keymgmt_gettable_params_fn x448_gettable_params;
|
||||
static OSSL_OP_keymgmt_gettable_params_fn ed25519_gettable_params;
|
||||
static OSSL_OP_keymgmt_gettable_params_fn ed448_gettable_params;
|
||||
static OSSL_OP_keymgmt_has_fn ecx_has;
|
||||
static OSSL_OP_keymgmt_match_fn ecx_match;
|
||||
static OSSL_OP_keymgmt_import_fn ecx_import;
|
||||
static OSSL_OP_keymgmt_import_types_fn ecx_imexport_types;
|
||||
static OSSL_OP_keymgmt_export_fn ecx_export;
|
||||
@@ -68,22 +69,22 @@ static void *s390x_ecd_keygen448(struct ecx_gen_ctx *gctx);
|
||||
|
||||
static void *x25519_new_key(void *provctx)
|
||||
{
|
||||
return ecx_key_new(ECX_KEY_TYPE_X25519, 0);
|
||||
return ecx_key_new(PROV_LIBRARY_CONTEXT_OF(provctx), ECX_KEY_TYPE_X25519, 0);
|
||||
}
|
||||
|
||||
static void *x448_new_key(void *provctx)
|
||||
{
|
||||
return ecx_key_new(ECX_KEY_TYPE_X448, 0);
|
||||
return ecx_key_new(PROV_LIBRARY_CONTEXT_OF(provctx), ECX_KEY_TYPE_X448, 0);
|
||||
}
|
||||
|
||||
static void *ed25519_new_key(void *provctx)
|
||||
{
|
||||
return ecx_key_new(ECX_KEY_TYPE_ED25519, 0);
|
||||
return ecx_key_new(PROV_LIBRARY_CONTEXT_OF(provctx), ECX_KEY_TYPE_ED25519, 0);
|
||||
}
|
||||
|
||||
static void *ed448_new_key(void *provctx)
|
||||
{
|
||||
return ecx_key_new(ECX_KEY_TYPE_ED448, 0);
|
||||
return ecx_key_new(PROV_LIBRARY_CONTEXT_OF(provctx), ECX_KEY_TYPE_ED448, 0);
|
||||
}
|
||||
|
||||
static int ecx_has(void *keydata, int selection)
|
||||
@@ -104,6 +105,36 @@ static int ecx_has(void *keydata, int selection)
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ecx_match(const void *keydata1, const void *keydata2, int selection)
|
||||
{
|
||||
const ECX_KEY *key1 = keydata1;
|
||||
const ECX_KEY *key2 = keydata2;
|
||||
int ok = 1;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0)
|
||||
ok = ok && key1->type == key2->type;
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) {
|
||||
if ((key1->privkey == NULL && key2->privkey != NULL)
|
||||
|| (key1->privkey != NULL && key2->privkey == NULL)
|
||||
|| key1->type != key2->type)
|
||||
ok = 0;
|
||||
else
|
||||
ok = ok && (key1->privkey == NULL /* implies key2->privkey == NULL */
|
||||
|| CRYPTO_memcmp(key1->privkey, key2->privkey,
|
||||
key1->keylen) == 0);
|
||||
}
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) {
|
||||
if (key1->haspubkey != key2->haspubkey
|
||||
|| key1->type != key2->type)
|
||||
ok = 0;
|
||||
else
|
||||
ok = ok && (key1->haspubkey == 0 /* implies key2->haspubkey == 0 */
|
||||
|| CRYPTO_memcmp(key1->pubkey, key2->pubkey,
|
||||
key1->keylen) == 0);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ecx_import(void *keydata, int selection, const OSSL_PARAM params[])
|
||||
{
|
||||
ECX_KEY *key = keydata;
|
||||
@@ -113,12 +144,11 @@ static int ecx_import(void *keydata, int selection, const OSSL_PARAM params[])
|
||||
if (key == NULL)
|
||||
return 0;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) == 0)
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) == 0)
|
||||
return 0;
|
||||
|
||||
include_private = ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ok = ok && ecx_key_fromdata(key, params, include_private);
|
||||
ok = ok && ecx_key_fromdata(key, params, include_private);
|
||||
|
||||
return ok;
|
||||
}
|
||||
@@ -162,10 +192,6 @@ static int ecx_export(void *keydata, int selection, OSSL_CALLBACK *param_cb,
|
||||
&& !key_to_params(key, tmpl, NULL))
|
||||
goto err;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0
|
||||
&& !key_to_params(key, tmpl, NULL))
|
||||
goto err;
|
||||
|
||||
params = OSSL_PARAM_BLD_to_param(tmpl);
|
||||
if (params == NULL)
|
||||
goto err;
|
||||
@@ -326,7 +352,7 @@ static void *ecx_gen(struct ecx_gen_ctx *gctx)
|
||||
|
||||
if (gctx == NULL)
|
||||
return NULL;
|
||||
if ((key = ecx_key_new(gctx->type, 0)) == NULL) {
|
||||
if ((key = ecx_key_new(gctx->libctx, gctx->type, 0)) == NULL) {
|
||||
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
@@ -425,6 +451,7 @@ static void ecx_gen_cleanup(void *genctx)
|
||||
{ OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*) (void))alg##_get_params }, \
|
||||
{ OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*) (void))alg##_gettable_params }, \
|
||||
{ OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))ecx_has }, \
|
||||
{ OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))ecx_match }, \
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))ecx_import }, \
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))ecx_imexport_types }, \
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))ecx_export }, \
|
||||
@@ -450,7 +477,7 @@ static void *s390x_ecx_keygen25519(struct ecx_gen_ctx *gctx)
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
ECX_KEY *key = ecx_key_new(ECX_KEY_TYPE_X25519, 1);
|
||||
ECX_KEY *key = ecx_key_new(gctx->libctx, ECX_KEY_TYPE_X25519, 1);
|
||||
unsigned char *privkey = NULL, *pubkey;
|
||||
|
||||
if (key == NULL) {
|
||||
@@ -490,7 +517,7 @@ static void *s390x_ecx_keygen448(struct ecx_gen_ctx *gctx)
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
ECX_KEY *key = ecx_key_new(ECX_KEY_TYPE_X448, 1);
|
||||
ECX_KEY *key = ecx_key_new(gctx->libctx, ECX_KEY_TYPE_X448, 1);
|
||||
unsigned char *privkey = NULL, *pubkey;
|
||||
|
||||
if (key == NULL) {
|
||||
@@ -533,7 +560,7 @@ static void *s390x_ecd_keygen25519(struct ecx_gen_ctx *gctx)
|
||||
0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
|
||||
};
|
||||
unsigned char x_dst[32], buff[SHA512_DIGEST_LENGTH];
|
||||
ECX_KEY *key = ecx_key_new(ECX_KEY_TYPE_ED25519, 1);
|
||||
ECX_KEY *key = ecx_key_new(gctx->libctx, ECX_KEY_TYPE_ED25519, 1);
|
||||
unsigned char *privkey = NULL, *pubkey;
|
||||
unsigned int sz;
|
||||
EVP_MD *sha = NULL;
|
||||
@@ -595,7 +622,7 @@ static void *s390x_ecd_keygen448(struct ecx_gen_ctx *gctx)
|
||||
0x24, 0xbc, 0xb6, 0x6e, 0x71, 0x46, 0x3f, 0x69, 0x00
|
||||
};
|
||||
unsigned char x_dst[57], buff[114];
|
||||
ECX_KEY *key = ecx_key_new(ECX_KEY_TYPE_ED448, 1);
|
||||
ECX_KEY *key = ecx_key_new(gctx->libctx, ECX_KEY_TYPE_ED448, 1);
|
||||
unsigned char *privkey = NULL, *pubkey;
|
||||
EVP_MD_CTX *hashctx = NULL;
|
||||
EVP_MD *shake = NULL;
|
||||
|
||||
@@ -20,9 +20,12 @@
|
||||
#include "internal/param_build_set.h"
|
||||
|
||||
static OSSL_OP_keymgmt_new_fn rsa_newdata;
|
||||
static OSSL_OP_keymgmt_new_fn rsapss_newdata;
|
||||
static OSSL_OP_keymgmt_gen_init_fn rsa_gen_init;
|
||||
static OSSL_OP_keymgmt_gen_init_fn rsapss_gen_init;
|
||||
static OSSL_OP_keymgmt_gen_set_params_fn rsa_gen_set_params;
|
||||
static OSSL_OP_keymgmt_gen_settable_params_fn rsa_gen_settable_params;
|
||||
static OSSL_OP_keymgmt_gen_settable_params_fn rsapss_gen_settable_params;
|
||||
static OSSL_OP_keymgmt_gen_fn rsa_gen;
|
||||
static OSSL_OP_keymgmt_gen_cleanup_fn rsa_gen_cleanup;
|
||||
static OSSL_OP_keymgmt_free_fn rsa_freedata;
|
||||
@@ -35,51 +38,53 @@ static OSSL_OP_keymgmt_import_fn rsa_import;
|
||||
static OSSL_OP_keymgmt_import_types_fn rsa_import_types;
|
||||
static OSSL_OP_keymgmt_export_fn rsa_export;
|
||||
static OSSL_OP_keymgmt_export_types_fn rsa_export_types;
|
||||
static OSSL_OP_keymgmt_query_operation_name_fn rsapss_query_operation_name;
|
||||
|
||||
#define RSA_DEFAULT_MD "SHA256"
|
||||
#define RSA_POSSIBLE_SELECTIONS \
|
||||
#define RSA_PSS_DEFAULT_MD OSSL_DIGEST_NAME_SHA1
|
||||
#define RSA_POSSIBLE_SELECTIONS \
|
||||
(OSSL_KEYMGMT_SELECT_KEYPAIR | OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS)
|
||||
|
||||
DEFINE_STACK_OF(BIGNUM)
|
||||
DEFINE_SPECIAL_STACK_OF_CONST(BIGNUM_const, BIGNUM)
|
||||
|
||||
static int key_to_params(RSA *rsa, OSSL_PARAM_BLD *bld, OSSL_PARAM params[])
|
||||
static int pss_params_fromdata(RSA_PSS_PARAMS_30 *pss_params,
|
||||
const OSSL_PARAM params[], int rsa_type,
|
||||
OPENSSL_CTX *libctx)
|
||||
{
|
||||
int ret = 0;
|
||||
const BIGNUM *rsa_d = NULL, *rsa_n = NULL, *rsa_e = NULL;
|
||||
STACK_OF(BIGNUM_const) *factors = sk_BIGNUM_const_new_null();
|
||||
STACK_OF(BIGNUM_const) *exps = sk_BIGNUM_const_new_null();
|
||||
STACK_OF(BIGNUM_const) *coeffs = sk_BIGNUM_const_new_null();
|
||||
if (!rsa_pss_params_30_fromdata(pss_params, params, libctx))
|
||||
return 0;
|
||||
|
||||
if (rsa == NULL || factors == NULL || exps == NULL || coeffs == NULL)
|
||||
goto err;
|
||||
/* If not a PSS type RSA, sending us PSS parameters is wrong */
|
||||
if (rsa_type != RSA_FLAG_TYPE_RSASSAPSS
|
||||
&& !rsa_pss_params_30_is_unrestricted(pss_params))
|
||||
return 0;
|
||||
|
||||
RSA_get0_key(rsa, &rsa_n, &rsa_e, &rsa_d);
|
||||
rsa_get0_all_params(rsa, factors, exps, coeffs);
|
||||
|
||||
if (!ossl_param_build_set_bn(bld, params, OSSL_PKEY_PARAM_RSA_N, rsa_n)
|
||||
|| !ossl_param_build_set_bn(bld, params, OSSL_PKEY_PARAM_RSA_E, rsa_e)
|
||||
|| !ossl_param_build_set_bn(bld, params, OSSL_PKEY_PARAM_RSA_D, rsa_d)
|
||||
|| !ossl_param_build_set_multi_key_bn(bld, params, rsa_mp_factor_names,
|
||||
factors)
|
||||
|| !ossl_param_build_set_multi_key_bn(bld, params, rsa_mp_exp_names,
|
||||
exps)
|
||||
|| !ossl_param_build_set_multi_key_bn(bld, params, rsa_mp_coeff_names,
|
||||
coeffs))
|
||||
goto err;
|
||||
ret = 1;
|
||||
err:
|
||||
sk_BIGNUM_const_free(factors);
|
||||
sk_BIGNUM_const_free(exps);
|
||||
sk_BIGNUM_const_free(coeffs);
|
||||
return ret;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void *rsa_newdata(void *provctx)
|
||||
{
|
||||
OPENSSL_CTX *libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
|
||||
RSA *rsa = rsa_new_with_ctx(libctx);
|
||||
|
||||
return rsa_new_with_ctx(libctx);
|
||||
if (rsa != NULL) {
|
||||
RSA_clear_flags(rsa, RSA_FLAG_TYPE_MASK);
|
||||
RSA_set_flags(rsa, RSA_FLAG_TYPE_RSA);
|
||||
}
|
||||
return rsa;
|
||||
}
|
||||
|
||||
static void *rsapss_newdata(void *provctx)
|
||||
{
|
||||
OPENSSL_CTX *libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
|
||||
RSA *rsa = rsa_new_with_ctx(libctx);
|
||||
|
||||
if (rsa != NULL) {
|
||||
RSA_clear_flags(rsa, RSA_FLAG_TYPE_MASK);
|
||||
RSA_set_flags(rsa, RSA_FLAG_TYPE_RSASSAPSS);
|
||||
}
|
||||
return rsa;
|
||||
}
|
||||
|
||||
static void rsa_freedata(void *keydata)
|
||||
@@ -97,7 +102,8 @@ static int rsa_has(void *keydata, int selection)
|
||||
ok = 1;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS) != 0)
|
||||
ok = ok && 0; /* This will change with PSS and OAEP */
|
||||
/* This will change with OAEP */
|
||||
ok = ok && (RSA_test_flags(rsa, RSA_FLAG_TYPE_RSASSAPSS) != 0);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ok = ok && (RSA_get0_e(rsa) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
|
||||
@@ -126,13 +132,22 @@ static int rsa_match(const void *keydata1, const void *keydata2, int selection)
|
||||
static int rsa_import(void *keydata, int selection, const OSSL_PARAM params[])
|
||||
{
|
||||
RSA *rsa = keydata;
|
||||
int rsa_type;
|
||||
int ok = 1;
|
||||
|
||||
if (rsa == NULL)
|
||||
return 0;
|
||||
|
||||
/* TODO(3.0) PSS and OAEP should bring on parameters */
|
||||
if ((selection & RSA_POSSIBLE_SELECTIONS) == 0)
|
||||
return 0;
|
||||
|
||||
rsa_type = RSA_test_flags(rsa, RSA_FLAG_TYPE_MASK);
|
||||
|
||||
/* TODO(3.0) OAEP should bring on parameters as well */
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS) != 0)
|
||||
ok = ok && pss_params_fromdata(rsa_get0_pss_params_30(rsa), params,
|
||||
rsa_type, rsa_get0_libctx(rsa));
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ok = ok && rsa_fromdata(rsa, params);
|
||||
|
||||
@@ -143,6 +158,7 @@ static int rsa_export(void *keydata, int selection,
|
||||
OSSL_CALLBACK *param_callback, void *cbarg)
|
||||
{
|
||||
RSA *rsa = keydata;
|
||||
const RSA_PSS_PARAMS_30 *pss_params = rsa_get0_pss_params_30(rsa);
|
||||
OSSL_PARAM_BLD *tmpl;
|
||||
OSSL_PARAM *params = NULL;
|
||||
int ok = 1;
|
||||
@@ -150,14 +166,17 @@ static int rsa_export(void *keydata, int selection,
|
||||
if (rsa == NULL)
|
||||
return 0;
|
||||
|
||||
/* TODO(3.0) PSS and OAEP should bring on parameters */
|
||||
/* TODO(3.0) OAEP should bring on parameters */
|
||||
|
||||
tmpl = OSSL_PARAM_BLD_new();
|
||||
if (tmpl == NULL)
|
||||
return 0;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS) != 0)
|
||||
ok = ok && (rsa_pss_params_30_is_unrestricted(pss_params)
|
||||
|| rsa_pss_params_30_todata(pss_params, NULL, tmpl, NULL));
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ok = ok && key_to_params(rsa, tmpl, NULL);
|
||||
ok = ok && rsa_todata(rsa, tmpl, NULL);
|
||||
|
||||
if (!ok
|
||||
|| (params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL)
|
||||
@@ -170,7 +189,7 @@ err:
|
||||
return ok;
|
||||
}
|
||||
|
||||
#ifdef FIPS_MODE
|
||||
#ifdef FIPS_MODULE
|
||||
/* In fips mode there are no multi-primes. */
|
||||
# define RSA_KEY_MP_TYPES() \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR1, NULL, 0), \
|
||||
@@ -259,6 +278,8 @@ static const OSSL_PARAM *rsa_export_types(int selection)
|
||||
static int rsa_get_params(void *key, OSSL_PARAM params[])
|
||||
{
|
||||
RSA *rsa = key;
|
||||
const RSA_PSS_PARAMS_30 *pss_params = rsa_get0_pss_params_30(rsa);
|
||||
int rsa_type = RSA_test_flags(rsa, RSA_FLAG_TYPE_MASK);
|
||||
OSSL_PARAM *p;
|
||||
|
||||
if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_BITS)) != NULL
|
||||
@@ -271,32 +292,36 @@ static int rsa_get_params(void *key, OSSL_PARAM params[])
|
||||
&& !OSSL_PARAM_set_int(p, RSA_size(rsa)))
|
||||
return 0;
|
||||
|
||||
# if 0 /* TODO(3.0): PSS support pending */
|
||||
if ((p = OSSL_PARAM_locate(params,
|
||||
OSSL_PKEY_PARAM_MANDATORY_DIGEST)) != NULL
|
||||
&& RSA_get0_pss_params(rsa) != NULL) {
|
||||
const EVP_MD *md, *mgf1md;
|
||||
int min_saltlen;
|
||||
|
||||
if (!rsa_pss_get_param(RSA_get0_pss_params(rsa),
|
||||
&md, &mgf1md, &min_saltlen)) {
|
||||
ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
}
|
||||
if (!OSSL_PARAM_set_utf8_string(p, EVP_MD_name(md)))
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* For RSA-PSS keys, we ignore the default digest request
|
||||
* TODO(3.0) with RSA-OAEP keys, this may need to be amended
|
||||
*/
|
||||
if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_DEFAULT_DIGEST)) != NULL
|
||||
/* TODO(3.0): PSS support pending */
|
||||
#if 0
|
||||
&& RSA_get0_pss_params(rsa) == NULL
|
||||
#endif
|
||||
) {
|
||||
&& rsa_type != RSA_FLAG_TYPE_RSASSAPSS) {
|
||||
if (!OSSL_PARAM_set_utf8_string(p, RSA_DEFAULT_MD))
|
||||
return 0;
|
||||
}
|
||||
return key_to_params(rsa, NULL, params);
|
||||
|
||||
/*
|
||||
* For non-RSA-PSS keys, we ignore the mandatory digest request
|
||||
* TODO(3.0) with RSA-OAEP keys, this may need to be amended
|
||||
*/
|
||||
if ((p = OSSL_PARAM_locate(params,
|
||||
OSSL_PKEY_PARAM_MANDATORY_DIGEST)) != NULL
|
||||
&& rsa_type == RSA_FLAG_TYPE_RSASSAPSS) {
|
||||
const char *mdname = RSA_PSS_DEFAULT_MD;
|
||||
|
||||
if (!rsa_pss_params_30_is_unrestricted(pss_params)) {
|
||||
mdname =
|
||||
rsa_oaeppss_nid2name(rsa_pss_params_30_hashalg(pss_params));
|
||||
|
||||
if (mdname == NULL || !OSSL_PARAM_set_utf8_string(p, mdname))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return (rsa_type != RSA_FLAG_TYPE_RSASSAPSS
|
||||
|| rsa_pss_params_30_todata(pss_params, NULL, NULL, params))
|
||||
&& rsa_todata(rsa, NULL, params);
|
||||
}
|
||||
|
||||
static const OSSL_PARAM rsa_params[] = {
|
||||
@@ -337,10 +362,15 @@ static int rsa_validate(void *keydata, int selection)
|
||||
struct rsa_gen_ctx {
|
||||
OPENSSL_CTX *libctx;
|
||||
|
||||
int rsa_type;
|
||||
|
||||
size_t nbits;
|
||||
BIGNUM *pub_exp;
|
||||
size_t primes;
|
||||
|
||||
/* For PSS */
|
||||
RSA_PSS_PARAMS_30 pss_params;
|
||||
|
||||
/* For generation callback */
|
||||
OSSL_CALLBACK *cb;
|
||||
void *cbarg;
|
||||
@@ -357,7 +387,7 @@ static int rsa_gencb(int p, int n, BN_GENCB *cb)
|
||||
return gctx->cb(params, gctx->cbarg);
|
||||
}
|
||||
|
||||
static void *rsa_gen_init(void *provctx, int selection)
|
||||
static void *gen_init(void *provctx, int selection, int rsa_type)
|
||||
{
|
||||
OPENSSL_CTX *libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
|
||||
struct rsa_gen_ctx *gctx = NULL;
|
||||
@@ -370,15 +400,32 @@ static void *rsa_gen_init(void *provctx, int selection)
|
||||
if ((gctx->pub_exp = BN_new()) == NULL
|
||||
|| !BN_set_word(gctx->pub_exp, RSA_F4)) {
|
||||
BN_free(gctx->pub_exp);
|
||||
OPENSSL_free(gctx);
|
||||
gctx = NULL;
|
||||
} else {
|
||||
gctx->nbits = 2048;
|
||||
gctx->primes = RSA_DEFAULT_PRIME_NUM;
|
||||
}
|
||||
gctx->rsa_type = rsa_type;
|
||||
}
|
||||
return gctx;
|
||||
}
|
||||
|
||||
static void *rsa_gen_init(void *provctx, int selection)
|
||||
{
|
||||
return gen_init(provctx, selection, RSA_FLAG_TYPE_RSA);
|
||||
}
|
||||
|
||||
static void *rsapss_gen_init(void *provctx, int selection)
|
||||
{
|
||||
return gen_init(provctx, selection, RSA_FLAG_TYPE_RSASSAPSS);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function is common for all RSA sub-types, to detect possible
|
||||
* misuse, such as PSS parameters being passed when a plain RSA key
|
||||
* is generated.
|
||||
*/
|
||||
static int rsa_gen_set_params(void *genctx, const OSSL_PARAM params[])
|
||||
{
|
||||
struct rsa_gen_ctx *gctx = genctx;
|
||||
@@ -393,15 +440,44 @@ static int rsa_gen_set_params(void *genctx, const OSSL_PARAM params[])
|
||||
if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_E)) != NULL
|
||||
&& !OSSL_PARAM_get_BN(p, &gctx->pub_exp))
|
||||
return 0;
|
||||
/* Only attempt to get PSS parameters when generating an RSA-PSS key */
|
||||
if (gctx->rsa_type == RSA_FLAG_TYPE_RSASSAPSS
|
||||
&& !pss_params_fromdata(&gctx->pss_params, params, gctx->rsa_type,
|
||||
gctx->libctx))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define rsa_gen_basic \
|
||||
OSSL_PARAM_size_t(OSSL_PKEY_PARAM_RSA_BITS, NULL), \
|
||||
OSSL_PARAM_size_t(OSSL_PKEY_PARAM_RSA_PRIMES, NULL), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_E, NULL, 0)
|
||||
|
||||
/*
|
||||
* The following must be kept in sync with rsa_pss_params_30_fromdata()
|
||||
* in crypto/rsa/rsa_backend.c
|
||||
*/
|
||||
#define rsa_gen_pss \
|
||||
OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_RSA_DIGEST, NULL, 0), \
|
||||
OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_RSA_MASKGENFUNC, NULL, 0), \
|
||||
OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_RSA_MGF1_DIGEST, NULL, 0), \
|
||||
OSSL_PARAM_int(OSSL_PKEY_PARAM_RSA_PSS_SALTLEN, NULL)
|
||||
|
||||
static const OSSL_PARAM *rsa_gen_settable_params(void *provctx)
|
||||
{
|
||||
static OSSL_PARAM settable[] = {
|
||||
OSSL_PARAM_size_t(OSSL_PKEY_PARAM_RSA_BITS, NULL),
|
||||
OSSL_PARAM_size_t(OSSL_PKEY_PARAM_RSA_PRIMES, NULL),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_E, NULL, 0),
|
||||
rsa_gen_basic,
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
|
||||
return settable;
|
||||
}
|
||||
|
||||
static const OSSL_PARAM *rsapss_gen_settable_params(void *provctx)
|
||||
{
|
||||
static OSSL_PARAM settable[] = {
|
||||
rsa_gen_basic,
|
||||
rsa_gen_pss,
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
|
||||
@@ -411,11 +487,28 @@ static const OSSL_PARAM *rsa_gen_settable_params(void *provctx)
|
||||
static void *rsa_gen(void *genctx, OSSL_CALLBACK *osslcb, void *cbarg)
|
||||
{
|
||||
struct rsa_gen_ctx *gctx = genctx;
|
||||
RSA *rsa = NULL;
|
||||
RSA *rsa = NULL, *rsa_tmp = NULL;
|
||||
BN_GENCB *gencb = NULL;
|
||||
|
||||
switch (gctx->rsa_type) {
|
||||
case RSA_FLAG_TYPE_RSA:
|
||||
/* For plain RSA keys, PSS parameters must not be set */
|
||||
if (!rsa_pss_params_30_is_unrestricted(&gctx->pss_params))
|
||||
goto err;
|
||||
break;
|
||||
case RSA_FLAG_TYPE_RSASSAPSS:
|
||||
/*
|
||||
* For plain RSA-PSS keys, PSS parameters may be set but don't have
|
||||
* to, so not check.
|
||||
*/
|
||||
break;
|
||||
default:
|
||||
/* Unsupported RSA key sub-type... */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (gctx == NULL
|
||||
|| (rsa = rsa_new_with_ctx(gctx->libctx)) == NULL)
|
||||
|| (rsa_tmp = rsa_new_with_ctx(gctx->libctx)) == NULL)
|
||||
return NULL;
|
||||
|
||||
gctx->cb = osslcb;
|
||||
@@ -424,14 +517,23 @@ static void *rsa_gen(void *genctx, OSSL_CALLBACK *osslcb, void *cbarg)
|
||||
if (gencb != NULL)
|
||||
BN_GENCB_set(gencb, rsa_gencb, genctx);
|
||||
|
||||
if (!RSA_generate_multi_prime_key(rsa, (int)gctx->nbits, (int)gctx->primes,
|
||||
gctx->pub_exp, gencb)) {
|
||||
RSA_free(rsa);
|
||||
rsa = NULL;
|
||||
}
|
||||
if (!RSA_generate_multi_prime_key(rsa_tmp,
|
||||
(int)gctx->nbits, (int)gctx->primes,
|
||||
gctx->pub_exp, gencb))
|
||||
goto err;
|
||||
|
||||
if (!rsa_pss_params_30_copy(rsa_get0_pss_params_30(rsa_tmp),
|
||||
&gctx->pss_params))
|
||||
goto err;
|
||||
|
||||
RSA_clear_flags(rsa_tmp, RSA_FLAG_TYPE_MASK);
|
||||
RSA_set_flags(rsa_tmp, gctx->rsa_type);
|
||||
|
||||
rsa = rsa_tmp;
|
||||
rsa_tmp = NULL;
|
||||
err:
|
||||
BN_GENCB_free(gencb);
|
||||
|
||||
RSA_free(rsa_tmp);
|
||||
return rsa;
|
||||
}
|
||||
|
||||
@@ -446,6 +548,12 @@ static void rsa_gen_cleanup(void *genctx)
|
||||
OPENSSL_free(gctx);
|
||||
}
|
||||
|
||||
/* For any RSA key, we use the "RSA" algorithms regardless of sub-type. */
|
||||
static const char *rsapss_query_operation_name(int operation_id)
|
||||
{
|
||||
return "RSA";
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH rsa_keymgmt_functions[] = {
|
||||
{ OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))rsa_newdata },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_INIT, (void (*)(void))rsa_gen_init },
|
||||
@@ -467,3 +575,25 @@ const OSSL_DISPATCH rsa_keymgmt_functions[] = {
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORT_TYPES, (void (*)(void))rsa_export_types },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
const OSSL_DISPATCH rsapss_keymgmt_functions[] = {
|
||||
{ OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))rsapss_newdata },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_INIT, (void (*)(void))rsapss_gen_init },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS, (void (*)(void))rsa_gen_set_params },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS,
|
||||
(void (*)(void))rsapss_gen_settable_params },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN, (void (*)(void))rsa_gen },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_CLEANUP, (void (*)(void))rsa_gen_cleanup },
|
||||
{ OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))rsa_freedata },
|
||||
{ OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*) (void))rsa_get_params },
|
||||
{ OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*) (void))rsa_gettable_params },
|
||||
{ OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))rsa_has },
|
||||
{ OSSL_FUNC_KEYMGMT_VALIDATE, (void (*)(void))rsa_validate },
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))rsa_import },
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))rsa_import_types },
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))rsa_export },
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORT_TYPES, (void (*)(void))rsa_export_types },
|
||||
{ OSSL_FUNC_KEYMGMT_QUERY_OPERATION_NAME,
|
||||
(void (*)(void))rsapss_query_operation_name },
|
||||
{ 0, NULL }
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -250,6 +250,8 @@ static int kmac_init(void *vmacctx)
|
||||
return 0;
|
||||
|
||||
block_len = EVP_MD_block_size(ossl_prov_digest_md(&kctx->digest));
|
||||
if (block_len < 0)
|
||||
return 0;
|
||||
|
||||
/* Set default custom string if it is not already set */
|
||||
if (kctx->custom_len == 0) {
|
||||
|
||||
@@ -10,7 +10,10 @@ $ECX_GOAL=../../libimplementations.a
|
||||
$EC_GOAL=../../libimplementations.a
|
||||
|
||||
SOURCE[$SERIALIZER_GOAL]=serializer_common.c
|
||||
|
||||
SOURCE[$RSA_GOAL]=serializer_rsa.c serializer_rsa_priv.c serializer_rsa_pub.c
|
||||
DEPEND[serializer_rsa.o]=../../common/include/prov/der_rsa.h
|
||||
|
||||
IF[{- !$disabled{"dh"} || !$disabled{"dsa"} -}]
|
||||
SOURCE[$FFC_GOAL]=serializer_ffc_params.c
|
||||
ENDIF
|
||||
|
||||
@@ -178,7 +178,7 @@ int ossl_prov_print_labeled_bignum(BIO *out, const char *label,
|
||||
}
|
||||
|
||||
if (BN_is_zero(bn))
|
||||
return ossl_prov_bio_printf(out, "%s%s0\n", label, post_label_spc);
|
||||
return BIO_printf(out, "%s%s0\n", label, post_label_spc);
|
||||
|
||||
if (BN_num_bytes(bn) <= BN_BYTES) {
|
||||
BN_ULONG *words = bn_get_words(bn);
|
||||
@@ -186,10 +186,8 @@ int ossl_prov_print_labeled_bignum(BIO *out, const char *label,
|
||||
if (BN_is_negative(bn))
|
||||
neg = "-";
|
||||
|
||||
return ossl_prov_bio_printf(out,
|
||||
"%s%s%s" BN_FMTu " (%s0x" BN_FMTx ")\n",
|
||||
label, post_label_spc, neg, words[0],
|
||||
neg, words[0]);
|
||||
return BIO_printf(out, "%s%s%s" BN_FMTu " (%s0x" BN_FMTx ")\n",
|
||||
label, post_label_spc, neg, words[0], neg, words[0]);
|
||||
}
|
||||
|
||||
hex_str = BN_bn2hex(bn);
|
||||
@@ -198,18 +196,18 @@ int ossl_prov_print_labeled_bignum(BIO *out, const char *label,
|
||||
++p;
|
||||
neg = " (Negative)";
|
||||
}
|
||||
if (ossl_prov_bio_printf(out, "%s%s\n", label, neg) <= 0)
|
||||
if (BIO_printf(out, "%s%s\n", label, neg) <= 0)
|
||||
goto err;
|
||||
|
||||
/* Keep track of how many bytes we have printed out so far */
|
||||
bytes = 0;
|
||||
|
||||
if (ossl_prov_bio_printf(out, "%s", spaces) <= 0)
|
||||
if (BIO_printf(out, "%s", spaces) <= 0)
|
||||
goto err;
|
||||
|
||||
/* Add a leading 00 if the top bit is set */
|
||||
if (*p >= '8') {
|
||||
if (ossl_prov_bio_printf(out, "%02x", 0) <= 0)
|
||||
if (BIO_printf(out, "%02x", 0) <= 0)
|
||||
goto err;
|
||||
++bytes;
|
||||
use_sep = 1;
|
||||
@@ -217,18 +215,18 @@ int ossl_prov_print_labeled_bignum(BIO *out, const char *label,
|
||||
while (*p != '\0') {
|
||||
/* Do a newline after every 15 hex bytes + add the space indent */
|
||||
if ((bytes % 15) == 0 && bytes > 0) {
|
||||
if (ossl_prov_bio_printf(out, ":\n%s", spaces) <= 0)
|
||||
if (BIO_printf(out, ":\n%s", spaces) <= 0)
|
||||
goto err;
|
||||
use_sep = 0; /* The first byte on the next line doesnt have a : */
|
||||
}
|
||||
if (ossl_prov_bio_printf(out, "%s%c%c", use_sep ? ":" : "",
|
||||
ossl_tolower(p[0]), ossl_tolower(p[1])) <= 0)
|
||||
if (BIO_printf(out, "%s%c%c", use_sep ? ":" : "",
|
||||
ossl_tolower(p[0]), ossl_tolower(p[1])) <= 0)
|
||||
goto err;
|
||||
++bytes;
|
||||
p += 2;
|
||||
use_sep = 1;
|
||||
}
|
||||
if (ossl_prov_bio_printf(out, "\n") <= 0)
|
||||
if (BIO_printf(out, "\n") <= 0)
|
||||
goto err;
|
||||
ret = 1;
|
||||
err:
|
||||
@@ -244,22 +242,22 @@ int ossl_prov_print_labeled_buf(BIO *out, const char *label,
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (ossl_prov_bio_printf(out, "%s\n", label) <= 0)
|
||||
if (BIO_printf(out, "%s\n", label) <= 0)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < buflen; i++) {
|
||||
if ((i % LABELED_BUF_PRINT_WIDTH) == 0) {
|
||||
if (i > 0 && ossl_prov_bio_printf(out, "\n") <= 0)
|
||||
if (i > 0 && BIO_printf(out, "\n") <= 0)
|
||||
return 0;
|
||||
if (ossl_prov_bio_printf(out, " ") <= 0)
|
||||
if (BIO_printf(out, " ") <= 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ossl_prov_bio_printf(out, "%02x%s", buf[i],
|
||||
if (BIO_printf(out, "%02x%s", buf[i],
|
||||
(i == buflen - 1) ? "" : ":") <= 0)
|
||||
return 0;
|
||||
}
|
||||
if (ossl_prov_bio_printf(out, "\n") <= 0)
|
||||
if (BIO_printf(out, "\n") <= 0)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
|
||||
@@ -70,7 +70,7 @@ int ossl_prov_print_dh(BIO *out, DH *dh, enum dh_print_type type)
|
||||
if (p == NULL)
|
||||
goto null_err;
|
||||
|
||||
if (ossl_prov_bio_printf(out, "%s: (%d bit)\n", type_label, BN_num_bits(p))
|
||||
if (BIO_printf(out, "%s: (%d bit)\n", type_label, BN_num_bits(p))
|
||||
<= 0)
|
||||
goto err;
|
||||
if (priv_key != NULL
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/providercommonerr.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn dh_param_newctx;
|
||||
@@ -48,7 +49,8 @@ static void dh_param_freectx(void *ctx)
|
||||
}
|
||||
|
||||
/* Public key : DER */
|
||||
static int dh_param_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dh_param_der_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new();
|
||||
@@ -69,14 +71,23 @@ static int dh_param_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dh_param_der(void *ctx, void *dh, BIO *out,
|
||||
static int dh_param_der(void *ctx, void *dh, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return i2d_DHparams_bio(out, dh);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
ret = i2d_DHparams_bio(out, dh);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Public key : PEM */
|
||||
static int dh_param_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dh_param_pem_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new();
|
||||
@@ -97,13 +108,23 @@ static int dh_param_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dh_param_pem(void *ctx, void *dh, BIO *out,
|
||||
static int dh_param_pem(void *ctx, void *dh, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return PEM_write_bio_DHparams(out, dh);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = PEM_write_bio_DHparams(out, dh);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int dh_param_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dh_param_print_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new();
|
||||
@@ -124,10 +145,19 @@ static int dh_param_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dh_param_print(void *ctx, void *dh, BIO *out,
|
||||
static int dh_param_print(void *ctx, void *dh, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_dh(out, dh, dh_print_params);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_dh(out, dh, dh_print_params);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH dh_param_der_serializer_functions[] = {
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <openssl/params.h>
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn dh_priv_newctx;
|
||||
@@ -117,7 +118,8 @@ static int dh_priv_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
||||
}
|
||||
|
||||
/* Private key : DER */
|
||||
static int dh_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dh_priv_der_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dh_priv_ctx_st *ctx = vctx;
|
||||
@@ -138,11 +140,15 @@ static int dh_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dh_priv_der(void *vctx, void *dh, BIO *out,
|
||||
static int dh_priv_der(void *vctx, void *dh, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dh_priv_ctx_st *ctx = vctx;
|
||||
int ret;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
@@ -151,12 +157,14 @@ static int dh_priv_der(void *vctx, void *dh, BIO *out,
|
||||
ossl_prov_prepare_dh_params,
|
||||
ossl_prov_dh_priv_to_der,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Private key : PEM */
|
||||
static int dh_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dh_pem_priv_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dh_priv_ctx_st *ctx = vctx;
|
||||
@@ -177,11 +185,15 @@ static int dh_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dh_pem_priv(void *vctx, void *dh, BIO *out,
|
||||
static int dh_pem_priv(void *vctx, void *dh, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dh_priv_ctx_st *ctx = vctx;
|
||||
int ret;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
@@ -190,6 +202,7 @@ static int dh_pem_priv(void *vctx, void *dh, BIO *out,
|
||||
ossl_prov_prepare_dh_params,
|
||||
ossl_prov_dh_priv_to_der,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -206,7 +219,8 @@ static void dh_print_freectx(void *ctx)
|
||||
{
|
||||
}
|
||||
|
||||
static int dh_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dh_priv_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dh_priv_ctx_st *ctx = vctx;
|
||||
@@ -227,10 +241,19 @@ static int dh_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dh_priv_print(void *ctx, void *dh, BIO *out,
|
||||
static int dh_priv_print(void *ctx, void *dh, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_dh(out, dh, dh_print_priv);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_dh(out, dh, dh_print_priv);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH dh_priv_der_serializer_functions[] = {
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <openssl/params.h>
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn dh_pub_newctx;
|
||||
@@ -48,7 +49,8 @@ static void dh_pub_freectx(void *ctx)
|
||||
}
|
||||
|
||||
/* Public key : DER */
|
||||
static int dh_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dh_pub_der_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new();
|
||||
@@ -69,17 +71,27 @@ static int dh_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dh_pub_der(void *ctx, void *dh, BIO *out,
|
||||
static int dh_pub_der(void *ctx, void *dh, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_write_pub_der_from_obj(out, dh, EVP_PKEY_DH,
|
||||
ossl_prov_prepare_dh_params,
|
||||
ossl_prov_dh_pub_to_der);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_write_pub_der_from_obj(out, dh, EVP_PKEY_DH,
|
||||
ossl_prov_prepare_dh_params,
|
||||
ossl_prov_dh_pub_to_der);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Public key : PEM */
|
||||
static int dh_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
static int dh_pub_pem_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new();
|
||||
OSSL_OP_keymgmt_free_fn *dh_free = ossl_prov_get_keymgmt_dh_free();
|
||||
@@ -99,17 +111,26 @@ static int dh_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dh_pub_pem(void *ctx, void *dh, BIO *out,
|
||||
static int dh_pub_pem(void *ctx, void *dh, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_write_pub_pem_from_obj(out, dh, EVP_PKEY_DH,
|
||||
ossl_prov_prepare_dh_params,
|
||||
ossl_prov_dh_pub_to_der);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_write_pub_pem_from_obj(out, dh, EVP_PKEY_DH,
|
||||
ossl_prov_prepare_dh_params,
|
||||
ossl_prov_dh_pub_to_der);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int dh_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
static int dh_pub_print_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new();
|
||||
OSSL_OP_keymgmt_free_fn *dh_free = ossl_prov_get_keymgmt_dh_free();
|
||||
@@ -129,10 +150,19 @@ static int dh_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dh_pub_print(void *ctx, void *dh, BIO *out,
|
||||
static int dh_pub_print(void *ctx, void *dh, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_dh(out, dh, dh_print_pub);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_dh(out, dh, dh_print_pub);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH dh_pub_der_serializer_functions[] = {
|
||||
|
||||
@@ -73,8 +73,7 @@ int ossl_prov_print_dsa(BIO *out, DSA *dsa, enum dsa_print_type type)
|
||||
if (p == NULL)
|
||||
goto null_err;
|
||||
|
||||
if (ossl_prov_bio_printf(out, "%s: (%d bit)\n", type_label,
|
||||
BN_num_bits(p)) <= 0)
|
||||
if (BIO_printf(out, "%s: (%d bit)\n", type_label, BN_num_bits(p)) <= 0)
|
||||
goto err;
|
||||
if (priv_key != NULL
|
||||
&& !ossl_prov_print_labeled_bignum(out, "priv:", priv_key))
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/providercommonerr.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn dsa_param_newctx;
|
||||
@@ -48,7 +49,8 @@ static void dsa_param_freectx(void *ctx)
|
||||
}
|
||||
|
||||
/* Public key : DER */
|
||||
static int dsa_param_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dsa_param_der_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
|
||||
@@ -69,14 +71,24 @@ static int dsa_param_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_param_der(void *ctx, void *dsa, BIO *out,
|
||||
static int dsa_param_der(void *ctx, void *dsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return i2d_DSAparams_bio(out, dsa);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = i2d_DSAparams_bio(out, dsa);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Public key : PEM */
|
||||
static int dsa_param_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dsa_param_pem_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
|
||||
@@ -97,13 +109,23 @@ static int dsa_param_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_param_pem(void *ctx, void *dsa, BIO *out,
|
||||
static int dsa_param_pem(void *ctx, void *dsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return PEM_write_bio_DSAparams(out, dsa);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = PEM_write_bio_DSAparams(out, dsa);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int dsa_param_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dsa_param_print_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
|
||||
@@ -124,10 +146,19 @@ static int dsa_param_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_param_print(void *ctx, void *dsa, BIO *out,
|
||||
static int dsa_param_print(void *ctx, void *dsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_dsa(out, dsa, dsa_print_params);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_dsa(out, dsa, dsa_print_params);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH dsa_param_der_serializer_functions[] = {
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <openssl/params.h>
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn dsa_priv_newctx;
|
||||
@@ -117,7 +118,8 @@ static int dsa_priv_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
||||
}
|
||||
|
||||
/* Private key : DER */
|
||||
static int dsa_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dsa_priv_der_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dsa_priv_ctx_st *ctx = vctx;
|
||||
@@ -138,22 +140,31 @@ static int dsa_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_priv_der(void *vctx, void *dsa, BIO *out,
|
||||
static int dsa_priv_der(void *vctx, void *dsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dsa_priv_ctx_st *ctx = vctx;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
|
||||
return ossl_prov_write_priv_der_from_obj(out, dsa, EVP_PKEY_DSA,
|
||||
ossl_prov_prepare_dsa_params,
|
||||
ossl_prov_dsa_priv_to_der,
|
||||
&ctx->sc);
|
||||
ret = ossl_prov_write_priv_der_from_obj(out, dsa, EVP_PKEY_DSA,
|
||||
ossl_prov_prepare_dsa_params,
|
||||
ossl_prov_dsa_priv_to_der,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Private key : PEM */
|
||||
static int dsa_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dsa_pem_priv_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dsa_priv_ctx_st *ctx = vctx;
|
||||
@@ -174,18 +185,26 @@ static int dsa_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_pem_priv(void *vctx, void *dsa, BIO *out,
|
||||
static int dsa_pem_priv(void *vctx, void *dsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dsa_priv_ctx_st *ctx = vctx;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
|
||||
return ossl_prov_write_priv_pem_from_obj(out, dsa, EVP_PKEY_DSA,
|
||||
ossl_prov_prepare_dsa_params,
|
||||
ossl_prov_dsa_priv_to_der,
|
||||
&ctx->sc);
|
||||
ret = ossl_prov_write_priv_pem_from_obj(out, dsa, EVP_PKEY_DSA,
|
||||
ossl_prov_prepare_dsa_params,
|
||||
ossl_prov_dsa_priv_to_der,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -201,7 +220,7 @@ static void dsa_print_freectx(void *ctx)
|
||||
}
|
||||
|
||||
static int dsa_priv_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
BIO *out,
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dsa_priv_ctx_st *ctx = vctx;
|
||||
@@ -222,10 +241,19 @@ static int dsa_priv_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_priv_print(void *ctx, void *dsa, BIO *out,
|
||||
static int dsa_priv_print(void *ctx, void *dsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_dsa(out, dsa, dsa_print_priv);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_dsa(out, dsa, dsa_print_priv);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH dsa_priv_der_serializer_functions[] = {
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <openssl/params.h>
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn dsa_pub_newctx;
|
||||
@@ -48,7 +49,8 @@ static void dsa_pub_freectx(void *ctx)
|
||||
}
|
||||
|
||||
/* Public key : DER */
|
||||
static int dsa_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dsa_pub_der_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
|
||||
@@ -69,7 +71,7 @@ static int dsa_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_pub_der(void *ctx, void *dsa, BIO *out,
|
||||
static int dsa_pub_der(void *ctx, void *dsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
/*
|
||||
@@ -77,8 +79,13 @@ static int dsa_pub_der(void *ctx, void *dsa, BIO *out,
|
||||
* in crypto/dsa/dsa_ameth.c
|
||||
*/
|
||||
int save_parameters = 1;
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
return
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret =
|
||||
save_parameters
|
||||
? ossl_prov_write_pub_der_from_obj(out, dsa, EVP_PKEY_DSA,
|
||||
ossl_prov_prepare_all_dsa_params,
|
||||
@@ -87,10 +94,14 @@ static int dsa_pub_der(void *ctx, void *dsa, BIO *out,
|
||||
ossl_prov_prepare_dsa_params,
|
||||
ossl_prov_dsa_pub_to_der);
|
||||
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Public key : PEM */
|
||||
static int dsa_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dsa_pub_pem_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
|
||||
@@ -111,15 +122,26 @@ static int dsa_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_pub_pem(void *ctx, void *dsa, BIO *out,
|
||||
static int dsa_pub_pem(void *ctx, void *dsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_write_pub_pem_from_obj(out, dsa, EVP_PKEY_DSA,
|
||||
ossl_prov_prepare_dsa_params,
|
||||
ossl_prov_dsa_pub_to_der);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_write_pub_pem_from_obj(out, dsa, EVP_PKEY_DSA,
|
||||
ossl_prov_prepare_dsa_params,
|
||||
ossl_prov_dsa_pub_to_der);
|
||||
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int dsa_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dsa_pub_print_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
|
||||
@@ -140,10 +162,19 @@ static int dsa_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_pub_print(void *ctx, void *dsa, BIO *out,
|
||||
static int dsa_pub_print(void *ctx, void *dsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_dsa(out, dsa, 0);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_dsa(out, dsa, 0);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH dsa_pub_der_serializer_functions[] = {
|
||||
|
||||
@@ -31,15 +31,13 @@ static int ossl_prov_print_ec_param(BIO *out, const EC_GROUP *group)
|
||||
if (curve_nid == NID_undef)
|
||||
return 0;
|
||||
|
||||
if (ossl_prov_bio_printf(out, "%s: %s\n", "ASN1 OID",
|
||||
OBJ_nid2sn(curve_nid)) <= 0)
|
||||
if (BIO_printf(out, "%s: %s\n", "ASN1 OID", OBJ_nid2sn(curve_nid)) <= 0)
|
||||
return 0;
|
||||
|
||||
/* TODO(3.0): Only named curves are currently supported */
|
||||
curve_name = EC_curve_nid2nist(curve_nid);
|
||||
return (curve_name == NULL
|
||||
|| ossl_prov_bio_printf(out, "%s: %s\n", "NIST CURVE",
|
||||
curve_name) > 0);
|
||||
|| BIO_printf(out, "%s: %s\n", "NIST CURVE", curve_name) > 0);
|
||||
}
|
||||
|
||||
int ossl_prov_print_eckey(BIO *out, EC_KEY *eckey, enum ec_print_type type)
|
||||
@@ -86,8 +84,8 @@ int ossl_prov_print_eckey(BIO *out, EC_KEY *eckey, enum ec_print_type type)
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (ossl_prov_bio_printf(out, "%s: (%d bit)\n", type_label,
|
||||
EC_GROUP_order_bits(group)) <= 0)
|
||||
if (BIO_printf(out, "%s: (%d bit)\n", type_label,
|
||||
EC_GROUP_order_bits(group)) <= 0)
|
||||
goto err;
|
||||
if (priv != NULL
|
||||
&& !ossl_prov_print_labeled_buf(out, "priv:", priv, priv_len))
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/providercommonerr.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn ec_param_newctx;
|
||||
@@ -39,8 +40,9 @@ static void ec_param_freectx(void *vctx)
|
||||
}
|
||||
|
||||
/* Public key : DER */
|
||||
static int ec_param_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
static int ec_param_der_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
OSSL_OP_keymgmt_free_fn *ec_free;
|
||||
@@ -62,15 +64,25 @@ static int ec_param_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_param_der(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_param_der(void *vctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return i2d_ECPKParameters_bio(out, EC_KEY_get0_group(eckey));
|
||||
BIO *out = bio_new_from_core_bio(vctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = i2d_ECPKParameters_bio(out, EC_KEY_get0_group(eckey));
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Public key : PEM */
|
||||
static int ec_param_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
static int ec_param_pem_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
OSSL_OP_keymgmt_free_fn *ec_free;
|
||||
@@ -92,14 +104,24 @@ static int ec_param_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_param_pem(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_param_pem(void *vctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return PEM_write_bio_ECPKParameters(out, EC_KEY_get0_group(eckey));
|
||||
BIO *out = bio_new_from_core_bio(vctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = PEM_write_bio_ECPKParameters(out, EC_KEY_get0_group(eckey));
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ec_param_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
static int ec_param_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
OSSL_OP_keymgmt_free_fn *ec_free;
|
||||
@@ -121,10 +143,19 @@ static int ec_param_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_param_print(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_param_print(void *vctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_eckey(out, eckey, ec_print_params);
|
||||
BIO *out = bio_new_from_core_bio(vctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_eckey(out, eckey, ec_print_params);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH ec_param_der_serializer_functions[] = {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <openssl/params.h>
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn ec_priv_newctx;
|
||||
@@ -111,8 +112,9 @@ static int ec_priv_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
||||
}
|
||||
|
||||
/* Private key : DER */
|
||||
static int ec_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
static int ec_priv_der_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ec_priv_ctx_st *ctx = vctx;
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
@@ -134,23 +136,32 @@ static int ec_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_priv_der(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_priv_der(void *vctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ec_priv_ctx_st *ctx = vctx;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
|
||||
return ossl_prov_write_priv_der_from_obj(out, eckey, EVP_PKEY_EC,
|
||||
ossl_prov_prepare_ec_params,
|
||||
ossl_prov_ec_priv_to_der,
|
||||
&ctx->sc);
|
||||
ret = ossl_prov_write_priv_der_from_obj(out, eckey, EVP_PKEY_EC,
|
||||
ossl_prov_prepare_ec_params,
|
||||
ossl_prov_ec_priv_to_der,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Private key : PEM */
|
||||
static int ec_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
static int ec_pem_priv_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ec_priv_ctx_st *ctx = vctx;
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
@@ -172,18 +183,26 @@ static int ec_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_pem_priv(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_pem_priv(void *vctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ec_priv_ctx_st *ctx = vctx;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
|
||||
return ossl_prov_write_priv_pem_from_obj(out, eckey, EVP_PKEY_EC,
|
||||
ossl_prov_prepare_ec_params,
|
||||
ossl_prov_ec_priv_to_der,
|
||||
&ctx->sc);
|
||||
ret = ossl_prov_write_priv_pem_from_obj(out, eckey, EVP_PKEY_EC,
|
||||
ossl_prov_prepare_ec_params,
|
||||
ossl_prov_ec_priv_to_der,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -198,7 +217,8 @@ static void ec_print_freectx(void *ctx)
|
||||
{
|
||||
}
|
||||
|
||||
static int ec_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ec_priv_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ec_priv_ctx_st *ctx = vctx;
|
||||
@@ -221,10 +241,19 @@ static int ec_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_priv_print(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_priv_print(void *ctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_eckey(out, eckey, ec_print_priv);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_eckey(out, eckey, ec_print_priv);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH ec_priv_der_serializer_functions[] = {
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <openssl/params.h>
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn ec_pub_newctx;
|
||||
@@ -41,7 +42,8 @@ static void ec_pub_freectx(void *ctx)
|
||||
}
|
||||
|
||||
/* Public key : DER */
|
||||
static int ec_pub_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ec_pub_der_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
@@ -64,16 +66,26 @@ static int ec_pub_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_pub_der(void *ctx, void *eckey, BIO *out,
|
||||
static int ec_pub_der(void *ctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_write_pub_der_from_obj(out, eckey, EVP_PKEY_EC,
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_write_pub_der_from_obj(out, eckey, EVP_PKEY_EC,
|
||||
ossl_prov_prepare_ec_params,
|
||||
ossl_prov_ec_pub_to_der);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Public key : PEM */
|
||||
static int ec_pub_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ec_pub_pem_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
@@ -96,15 +108,25 @@ static int ec_pub_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_pub_pem(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_pub_pem(void *vctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_write_pub_pem_from_obj(out, eckey, EVP_PKEY_EC,
|
||||
ossl_prov_prepare_ec_params,
|
||||
ossl_prov_ec_pub_to_der);
|
||||
BIO *out = bio_new_from_core_bio(vctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_write_pub_pem_from_obj(out, eckey, EVP_PKEY_EC,
|
||||
ossl_prov_prepare_ec_params,
|
||||
ossl_prov_ec_pub_to_der);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ec_pub_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ec_pub_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
@@ -127,10 +149,19 @@ static int ec_pub_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_pub_print(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_pub_print(void *vctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_eckey(out, eckey, ec_print_pub);
|
||||
BIO *out = bio_new_from_core_bio(vctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_eckey(out, eckey, ec_print_pub);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH ec_pub_der_serializer_functions[] = {
|
||||
|
||||
@@ -86,7 +86,7 @@ int ossl_prov_print_ecx(BIO *out, ECX_KEY *ecxkey, enum ecx_print_type type)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ossl_prov_bio_printf(out, "%s:\n", type_label) <= 0)
|
||||
if (BIO_printf(out, "%s:\n", type_label) <= 0)
|
||||
return 0;
|
||||
if (type == ecx_print_priv
|
||||
&& !ossl_prov_print_labeled_buf(out, "priv:", ecxkey->privkey,
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "crypto/ecx.h"
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn x25519_priv_newctx;
|
||||
@@ -134,7 +135,8 @@ static int ecx_priv_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
||||
}
|
||||
|
||||
/* Private key : DER */
|
||||
static int ecx_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ecx_priv_der_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_priv_ctx_st *ctx = vctx;
|
||||
@@ -157,13 +159,17 @@ static int ecx_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ecx_priv_der(void *vctx, void *vecxkey, BIO *out,
|
||||
static int ecx_priv_der(void *vctx, void *vecxkey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_priv_ctx_st *ctx = vctx;
|
||||
ECX_KEY *ecxkey = vecxkey;
|
||||
int ret;
|
||||
int nid = KEYTYPE2NID(ctx->type);
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
@@ -173,12 +179,14 @@ static int ecx_priv_der(void *vctx, void *vecxkey, BIO *out,
|
||||
NULL,
|
||||
ossl_prov_ecx_priv_to_der,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Private key : PEM */
|
||||
static int ecx_priv_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ecx_priv_pem_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_priv_ctx_st *ctx = vctx;
|
||||
@@ -201,12 +209,16 @@ static int ecx_priv_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ecx_priv_pem(void *vctx, void *ecxkey, BIO *out,
|
||||
static int ecx_priv_pem(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_priv_ctx_st *ctx = vctx;
|
||||
int ret;
|
||||
int nid = KEYTYPE2NID(ctx->type);
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
@@ -216,11 +228,13 @@ static int ecx_priv_pem(void *vctx, void *ecxkey, BIO *out,
|
||||
NULL,
|
||||
ossl_prov_ecx_priv_to_der,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ecx_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ecx_priv_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_priv_ctx_st *ctx = vctx;
|
||||
@@ -243,10 +257,20 @@ static int ecx_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ecx_priv_print(void *ctx, void *ecxkey, BIO *out,
|
||||
static int ecx_priv_print(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_ecx(out, ecxkey, ecx_print_priv);
|
||||
struct ecx_priv_ctx_st *ctx = vctx;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_ecx(out, ecxkey, ecx_print_priv);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define MAKE_SERIALIZER_FUNCTIONS(alg, type) \
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "crypto/ecx.h"
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn x25519_pub_newctx;
|
||||
@@ -76,7 +77,8 @@ static void ecx_pub_freectx(void *ctx)
|
||||
}
|
||||
|
||||
/* Public key : DER */
|
||||
static int ecx_pub_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ecx_pub_der_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_pub_ctx_st *ctx = vctx;
|
||||
@@ -99,19 +101,28 @@ static int ecx_pub_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ecx_pub_der(void *vctx, void *ecxkey, BIO *out,
|
||||
static int ecx_pub_der(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_pub_ctx_st *ctx = vctx;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
int ret;
|
||||
|
||||
return ossl_prov_write_pub_der_from_obj(out, ecxkey,
|
||||
KEYTYPE2NID(ctx->type),
|
||||
NULL,
|
||||
ossl_prov_ecx_pub_to_der);
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_write_pub_der_from_obj(out, ecxkey,
|
||||
KEYTYPE2NID(ctx->type),
|
||||
NULL,
|
||||
ossl_prov_ecx_pub_to_der);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Public key : PEM */
|
||||
static int ecx_pub_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ecx_pub_pem_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_pub_ctx_st *ctx = vctx;
|
||||
@@ -134,19 +145,27 @@ static int ecx_pub_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ecx_pub_pem(void *vctx, void *ecxkey, BIO *out,
|
||||
static int ecx_pub_pem(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_pub_ctx_st *ctx = vctx;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
int ret;
|
||||
|
||||
return ossl_prov_write_pub_pem_from_obj(out, ecxkey,
|
||||
KEYTYPE2NID(ctx->type),
|
||||
NULL,
|
||||
ossl_prov_ecx_pub_to_der);
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_write_pub_pem_from_obj(out, ecxkey,
|
||||
KEYTYPE2NID(ctx->type),
|
||||
NULL,
|
||||
ossl_prov_ecx_pub_to_der);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ecx_pub_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ecx_pub_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_pub_ctx_st *ctx = vctx;
|
||||
@@ -169,10 +188,20 @@ static int ecx_pub_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ecx_pub_print(void *ctx, void *ecxkey, BIO *out,
|
||||
static int ecx_pub_print(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_ecx(out, ecxkey, ecx_print_pub);
|
||||
struct ecx_pub_ctx_st *ctx = vctx;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_ecx(out, ecxkey, ecx_print_pub);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define MAKE_SERIALIZER_FUNCTIONS(alg, type) \
|
||||
|
||||
@@ -20,7 +20,7 @@ int ffc_params_prov_print(BIO *out, const FFC_PARAMS *ffc)
|
||||
|
||||
if (name == NULL)
|
||||
goto err;
|
||||
if (ossl_prov_bio_printf(out, "GROUP: %s\n", name) <= 0)
|
||||
if (BIO_printf(out, "GROUP: %s\n", name) <= 0)
|
||||
goto err;
|
||||
return 1;
|
||||
#else
|
||||
@@ -46,15 +46,15 @@ int ffc_params_prov_print(BIO *out, const FFC_PARAMS *ffc)
|
||||
goto err;
|
||||
}
|
||||
if (ffc->gindex != -1) {
|
||||
if (ossl_prov_bio_printf(out, "gindex: %d\n", ffc->gindex) <= 0)
|
||||
if (BIO_printf(out, "gindex: %d\n", ffc->gindex) <= 0)
|
||||
goto err;
|
||||
}
|
||||
if (ffc->pcounter != -1) {
|
||||
if (ossl_prov_bio_printf(out, "pcounter: %d\n", ffc->pcounter) <= 0)
|
||||
if (BIO_printf(out, "pcounter: %d\n", ffc->pcounter) <= 0)
|
||||
goto err;
|
||||
}
|
||||
if (ffc->h != 0) {
|
||||
if (ossl_prov_bio_printf(out, "h: %d\n", ffc->h) <= 0)
|
||||
if (BIO_printf(out, "h: %d\n", ffc->h) <= 0)
|
||||
goto err;
|
||||
}
|
||||
return 1;
|
||||
|
||||
@@ -82,6 +82,14 @@ int ossl_prov_prepare_all_dsa_params(const void *dsa, int nid,
|
||||
int ossl_prov_dsa_pub_to_der(const void *dsa, unsigned char **pder);
|
||||
int ossl_prov_dsa_priv_to_der(const void *dsa, unsigned char **pder);
|
||||
|
||||
/*
|
||||
* ossl_prov_prepare_rsa_params() is designed to work with the ossl_prov_write_
|
||||
* functions, hence 'void *rsa' rather than 'RSA *rsa'.
|
||||
*/
|
||||
int ossl_prov_prepare_rsa_params(const void *rsa, int nid,
|
||||
void **pstr, int *pstrtype);
|
||||
int ossl_prov_rsa_type_to_evp(const RSA *rsa);
|
||||
|
||||
int ossl_prov_print_labeled_bignum(BIO *out, const char *label,
|
||||
const BIGNUM *bn);
|
||||
int ossl_prov_print_labeled_buf(BIO *out, const char *label,
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include "internal/packet.h"
|
||||
#include "crypto/rsa.h" /* rsa_get0_all_params() */
|
||||
#include "prov/bio.h" /* ossl_prov_bio_printf() */
|
||||
#include "prov/der_rsa.h" /* DER_w_RSASSA_PSS_params() */
|
||||
#include "prov/implementations.h" /* rsa_keymgmt_functions */
|
||||
#include "serializer_local.h"
|
||||
|
||||
@@ -37,6 +39,7 @@ int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv)
|
||||
STACK_OF(BIGNUM_const) *factors = sk_BIGNUM_const_new_null();
|
||||
STACK_OF(BIGNUM_const) *exps = sk_BIGNUM_const_new_null();
|
||||
STACK_OF(BIGNUM_const) *coeffs = sk_BIGNUM_const_new_null();
|
||||
RSA_PSS_PARAMS_30 *pss_params = rsa_get0_pss_params_30(rsa);
|
||||
int ret = 0;
|
||||
|
||||
if (rsa == NULL || factors == NULL || exps == NULL || coeffs == NULL)
|
||||
@@ -46,15 +49,14 @@ int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv)
|
||||
rsa_get0_all_params(rsa, factors, exps, coeffs);
|
||||
|
||||
if (priv && rsa_d != NULL) {
|
||||
if (ossl_prov_bio_printf(out, "Private-Key: (%d bit, %d primes)\n",
|
||||
BN_num_bits(rsa_n),
|
||||
sk_BIGNUM_const_num(factors)) <= 0)
|
||||
if (BIO_printf(out, "Private-Key: (%d bit, %d primes)\n",
|
||||
BN_num_bits(rsa_n),
|
||||
sk_BIGNUM_const_num(factors)) <= 0)
|
||||
goto err;
|
||||
modulus_label = "modulus:";
|
||||
exponent_label = "publicExponent:";
|
||||
} else {
|
||||
if (ossl_prov_bio_printf(out, "Public-Key: (%d bit)\n",
|
||||
BN_num_bits(rsa_n)) <= 0)
|
||||
if (BIO_printf(out, "Public-Key: (%d bit)\n", BN_num_bits(rsa_n)) <= 0)
|
||||
goto err;
|
||||
modulus_label = "Modulus:";
|
||||
exponent_label = "Exponent:";
|
||||
@@ -84,18 +86,18 @@ int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv)
|
||||
sk_BIGNUM_const_value(coeffs, 0)))
|
||||
goto err;
|
||||
for (i = 2; i < sk_BIGNUM_const_num(factors); i++) {
|
||||
if (ossl_prov_bio_printf(out, "prime%d:", i + 1) <= 0)
|
||||
if (BIO_printf(out, "prime%d:", i + 1) <= 0)
|
||||
goto err;
|
||||
if (!ossl_prov_print_labeled_bignum(out, NULL,
|
||||
sk_BIGNUM_const_value(factors,
|
||||
i)))
|
||||
goto err;
|
||||
if (ossl_prov_bio_printf(out, "exponent%d:", i + 1) <= 0)
|
||||
if (BIO_printf(out, "exponent%d:", i + 1) <= 0)
|
||||
goto err;
|
||||
if (!ossl_prov_print_labeled_bignum(out, NULL,
|
||||
sk_BIGNUM_const_value(exps, i)))
|
||||
goto err;
|
||||
if (ossl_prov_bio_printf(out, "coefficient%d:", i + 1) <= 0)
|
||||
if (BIO_printf(out, "coefficient%d:", i + 1) <= 0)
|
||||
goto err;
|
||||
if (!ossl_prov_print_labeled_bignum(out, NULL,
|
||||
sk_BIGNUM_const_value(coeffs,
|
||||
@@ -103,6 +105,60 @@ int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv)
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
switch (RSA_test_flags(rsa, RSA_FLAG_TYPE_MASK)) {
|
||||
case RSA_FLAG_TYPE_RSA:
|
||||
if (!rsa_pss_params_30_is_unrestricted(pss_params)) {
|
||||
if (BIO_printf(out, "(INVALID PSS PARAMETERS)\n") <= 0)
|
||||
goto err;
|
||||
}
|
||||
break;
|
||||
case RSA_FLAG_TYPE_RSASSAPSS:
|
||||
if (rsa_pss_params_30_is_unrestricted(pss_params)) {
|
||||
if (BIO_printf(out, "No PSS parameter restrictions\n") <= 0)
|
||||
goto err;
|
||||
} else {
|
||||
int hashalg_nid = rsa_pss_params_30_hashalg(pss_params);
|
||||
int maskgenalg_nid = rsa_pss_params_30_maskgenalg(pss_params);
|
||||
int maskgenhashalg_nid =
|
||||
rsa_pss_params_30_maskgenhashalg(pss_params);
|
||||
int saltlen = rsa_pss_params_30_saltlen(pss_params);
|
||||
int trailerfield = rsa_pss_params_30_trailerfield(pss_params);
|
||||
|
||||
if (BIO_printf(out, "PSS parameter restrictions:\n") <= 0)
|
||||
goto err;
|
||||
if (BIO_printf(out, " Hash Algorithm: %s%s\n",
|
||||
rsa_oaeppss_nid2name(hashalg_nid),
|
||||
(hashalg_nid == NID_sha1
|
||||
? " (default)" : "")) <= 0)
|
||||
goto err;
|
||||
if (BIO_printf(out, " Mask Algorithm: %s with %s%s\n",
|
||||
rsa_mgf_nid2name(maskgenalg_nid),
|
||||
rsa_oaeppss_nid2name(maskgenhashalg_nid),
|
||||
(maskgenalg_nid == NID_mgf1
|
||||
&& maskgenhashalg_nid == NID_sha1
|
||||
? " (default)" : "")) <= 0)
|
||||
goto err;
|
||||
if (BIO_printf(out, " Minimum Salt Length: %d%s\n",
|
||||
saltlen,
|
||||
(saltlen == 20 ? " (default)" : "")) <= 0)
|
||||
goto err;
|
||||
/*
|
||||
* TODO(3.0) Should we show the ASN.1 trailerField value, or
|
||||
* the actual trailerfield byte (i.e. 0xBC for 1)?
|
||||
* crypto/rsa/rsa_ameth.c isn't very clear on that, as it
|
||||
* does display 0xBC when the default applies, but the ASN.1
|
||||
* trailerField value otherwise...
|
||||
*/
|
||||
if (BIO_printf(out, " Trailer Field: 0x%x%s\n",
|
||||
trailerfield,
|
||||
(trailerfield == 1 ? " (default)" : ""))
|
||||
<= 0)
|
||||
goto err;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
err:
|
||||
sk_BIGNUM_const_free(factors);
|
||||
@@ -110,3 +166,90 @@ int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv)
|
||||
sk_BIGNUM_const_free(coeffs);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper functions to prepare RSA-PSS params for serialization. We would
|
||||
* have simply written the whole AlgorithmIdentifier, but existing libcrypto
|
||||
* functionality doesn't allow that.
|
||||
*/
|
||||
|
||||
int ossl_prov_prepare_rsa_params(const void *rsa, int nid,
|
||||
void **pstr, int *pstrtype)
|
||||
{
|
||||
const RSA_PSS_PARAMS_30 *pss = rsa_get0_pss_params_30((RSA *)rsa);
|
||||
|
||||
*pstr = NULL;
|
||||
|
||||
switch (RSA_test_flags(rsa, RSA_FLAG_TYPE_MASK)) {
|
||||
case RSA_FLAG_TYPE_RSA:
|
||||
/* If plain RSA, the parameters shall be NULL */
|
||||
*pstrtype = V_ASN1_NULL;
|
||||
return 1;
|
||||
case RSA_FLAG_TYPE_RSASSAPSS:
|
||||
if (rsa_pss_params_30_is_unrestricted(pss)) {
|
||||
*pstrtype = V_ASN1_UNDEF;
|
||||
} else {
|
||||
ASN1_STRING *astr = NULL;
|
||||
WPACKET pkt;
|
||||
unsigned char *str = NULL;
|
||||
size_t str_sz = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
if (!WPACKET_init_null_der(&pkt))
|
||||
goto err;
|
||||
break;
|
||||
case 1:
|
||||
if ((str = OPENSSL_malloc(str_sz)) == NULL
|
||||
|| !WPACKET_init_der(&pkt, str, str_sz)) {
|
||||
goto err;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!DER_w_RSASSA_PSS_params(&pkt, -1, pss)
|
||||
|| !WPACKET_finish(&pkt))
|
||||
goto err;
|
||||
WPACKET_get_total_written(&pkt, &str_sz);
|
||||
WPACKET_cleanup(&pkt);
|
||||
|
||||
/*
|
||||
* If no PSS parameters are going to be written, there's no
|
||||
* point going for another iteration.
|
||||
* This saves us from getting |str| allocated just to have it
|
||||
* immediately de-allocated.
|
||||
*/
|
||||
if (str_sz == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if ((astr = ASN1_STRING_new()) == NULL)
|
||||
goto err;
|
||||
*pstrtype = V_ASN1_SEQUENCE;
|
||||
ASN1_STRING_set0(astr, str, (int)str_sz);
|
||||
*pstr = astr;
|
||||
|
||||
return 1;
|
||||
err:
|
||||
OPENSSL_free(str);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Currently unsupported RSA key type */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ossl_prov_rsa_type_to_evp(const RSA *rsa)
|
||||
{
|
||||
switch (RSA_test_flags(rsa, RSA_FLAG_TYPE_MASK)) {
|
||||
case RSA_FLAG_TYPE_RSA:
|
||||
return EVP_PKEY_RSA;
|
||||
case RSA_FLAG_TYPE_RSASSAPSS:
|
||||
return EVP_PKEY_RSA_PSS;
|
||||
}
|
||||
|
||||
/* Currently unsupported RSA key type */
|
||||
return EVP_PKEY_NONE;
|
||||
}
|
||||
@@ -15,9 +15,11 @@
|
||||
#include <openssl/types.h>
|
||||
#include <openssl/params.h>
|
||||
#include <openssl/safestack.h>
|
||||
#include "crypto/rsa.h"
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/providercommonerr.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn rsa_priv_newctx;
|
||||
@@ -43,34 +45,6 @@ struct rsa_priv_ctx_st {
|
||||
struct pkcs8_encrypt_ctx_st sc;
|
||||
};
|
||||
|
||||
/* Helper functions to prepare RSA-PSS params for serialization */
|
||||
|
||||
static int prepare_rsa_params(const void *rsa, int nid,
|
||||
void **pstr, int *pstrtype)
|
||||
{
|
||||
const RSA_PSS_PARAMS *pss = RSA_get0_pss_params(rsa);
|
||||
*pstr = NULL;
|
||||
|
||||
/* If RSA it's just NULL type */
|
||||
if (nid != EVP_PKEY_RSA_PSS) {
|
||||
*pstrtype = V_ASN1_NULL;
|
||||
return 1;
|
||||
}
|
||||
/* If no PSS parameters we omit parameters entirely */
|
||||
if (pss == NULL) {
|
||||
*pstrtype = V_ASN1_UNDEF;
|
||||
return 1;
|
||||
}
|
||||
/* Encode PSS parameters */
|
||||
if (ASN1_item_pack((void *)pss, ASN1_ITEM_rptr(RSA_PSS_PARAMS),
|
||||
(ASN1_STRING **)pstr)
|
||||
== NULL)
|
||||
return 0;
|
||||
|
||||
*pstrtype = V_ASN1_SEQUENCE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Private key : context */
|
||||
static void *rsa_priv_newctx(void *provctx)
|
||||
{
|
||||
@@ -140,7 +114,8 @@ static int rsa_priv_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
||||
}
|
||||
|
||||
/* Private key : DER */
|
||||
static int rsa_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int rsa_priv_der_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct rsa_priv_ctx_st *ctx = vctx;
|
||||
@@ -161,25 +136,32 @@ static int rsa_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int rsa_priv_der(void *vctx, void *rsa, BIO *out,
|
||||
static int rsa_priv_der(void *vctx, void *rsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct rsa_priv_ctx_st *ctx = vctx;
|
||||
int ret;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
|
||||
ret = ossl_prov_write_priv_der_from_obj(out, rsa, EVP_PKEY_RSA,
|
||||
prepare_rsa_params,
|
||||
ret = ossl_prov_write_priv_der_from_obj(out, rsa,
|
||||
ossl_prov_rsa_type_to_evp(rsa),
|
||||
ossl_prov_prepare_rsa_params,
|
||||
(i2d_of_void *)i2d_RSAPrivateKey,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Private key : PEM */
|
||||
static int rsa_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int rsa_pem_priv_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct rsa_priv_ctx_st *ctx = vctx;
|
||||
@@ -200,19 +182,25 @@ static int rsa_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int rsa_pem_priv(void *vctx, void *rsa, BIO *out,
|
||||
static int rsa_pem_priv(void *vctx, void *rsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct rsa_priv_ctx_st *ctx = vctx;
|
||||
int ret;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
|
||||
ret = ossl_prov_write_priv_pem_from_obj(out, rsa, EVP_PKEY_RSA,
|
||||
prepare_rsa_params,
|
||||
ret = ossl_prov_write_priv_pem_from_obj(out, rsa,
|
||||
ossl_prov_rsa_type_to_evp(rsa),
|
||||
ossl_prov_prepare_rsa_params,
|
||||
(i2d_of_void *)i2d_RSAPrivateKey,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -230,7 +218,7 @@ static void rsa_print_freectx(void *ctx)
|
||||
}
|
||||
|
||||
static int rsa_priv_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
BIO *out,
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct rsa_priv_ctx_st *ctx = vctx;
|
||||
@@ -251,10 +239,19 @@ static int rsa_priv_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int rsa_priv_print(void *ctx, void *rsa, BIO *out,
|
||||
static int rsa_priv_print(void *ctx, void *rsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_rsa(out, rsa, 1);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_rsa(out, rsa, 1);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH rsa_priv_der_serializer_functions[] = {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/providercommonerr.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn rsa_pub_newctx;
|
||||
@@ -42,7 +43,8 @@ static void rsa_pub_freectx(void *ctx)
|
||||
}
|
||||
|
||||
/* Public key : DER */
|
||||
static int rsa_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int rsa_pub_der_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *rsa_new = ossl_prov_get_keymgmt_rsa_new();
|
||||
@@ -63,14 +65,27 @@ static int rsa_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int rsa_pub_der(void *ctx, void *rsa, BIO *out,
|
||||
static int rsa_pub_der(void *ctx, void *rsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return i2d_RSA_PUBKEY_bio(out, rsa);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_write_pub_der_from_obj(out, rsa,
|
||||
ossl_prov_rsa_type_to_evp(rsa),
|
||||
ossl_prov_prepare_rsa_params,
|
||||
(i2d_of_void *)i2d_RSAPublicKey);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Public key : PEM */
|
||||
static int rsa_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int rsa_pub_pem_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *rsa_new = ossl_prov_get_keymgmt_rsa_new();
|
||||
@@ -91,13 +106,26 @@ static int rsa_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int rsa_pub_pem(void *ctx, void *rsa, BIO *out,
|
||||
static int rsa_pub_pem(void *ctx, void *rsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return PEM_write_bio_RSA_PUBKEY(out, rsa);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_write_pub_pem_from_obj(out, rsa,
|
||||
ossl_prov_rsa_type_to_evp(rsa),
|
||||
ossl_prov_prepare_rsa_params,
|
||||
(i2d_of_void *)i2d_RSAPublicKey);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rsa_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int rsa_pub_print_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *rsa_new = ossl_prov_get_keymgmt_rsa_new();
|
||||
@@ -118,10 +146,19 @@ static int rsa_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int rsa_pub_print(void *ctx, void *rsa, BIO *out,
|
||||
static int rsa_pub_print(void *ctx, void *rsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_rsa(out, rsa, 0);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_rsa(out, rsa, 0);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH rsa_pub_der_serializer_functions[] = {
|
||||
|
||||
@@ -63,6 +63,7 @@ static OSSL_OP_signature_settable_ctx_md_params_fn dsa_settable_ctx_md_params;
|
||||
|
||||
typedef struct {
|
||||
OPENSSL_CTX *libctx;
|
||||
char *propq;
|
||||
DSA *dsa;
|
||||
|
||||
/*
|
||||
@@ -131,7 +132,7 @@ static int dsa_get_md_nid(const EVP_MD *md)
|
||||
return mdnid;
|
||||
}
|
||||
|
||||
static void *dsa_newctx(void *provctx)
|
||||
static void *dsa_newctx(void *provctx, const char *propq)
|
||||
{
|
||||
PROV_DSA_CTX *pdsactx = OPENSSL_zalloc(sizeof(PROV_DSA_CTX));
|
||||
|
||||
@@ -140,12 +141,20 @@ static void *dsa_newctx(void *provctx)
|
||||
|
||||
pdsactx->libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
|
||||
pdsactx->flag_allow_md = 1;
|
||||
if (propq != NULL && (pdsactx->propq = OPENSSL_strdup(propq)) == NULL) {
|
||||
OPENSSL_free(pdsactx);
|
||||
pdsactx = NULL;
|
||||
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
|
||||
}
|
||||
return pdsactx;
|
||||
}
|
||||
|
||||
static int dsa_setup_md(PROV_DSA_CTX *ctx,
|
||||
const char *mdname, const char *mdprops)
|
||||
{
|
||||
if (mdprops == NULL)
|
||||
mdprops = ctx->propq;
|
||||
|
||||
if (mdname != NULL) {
|
||||
EVP_MD *md = EVP_MD_fetch(ctx->libctx, mdname, mdprops);
|
||||
int md_nid = dsa_get_md_nid(md);
|
||||
@@ -234,7 +243,7 @@ static int dsa_verify(void *vpdsactx, const unsigned char *sig, size_t siglen,
|
||||
}
|
||||
|
||||
static int dsa_digest_signverify_init(void *vpdsactx, const char *mdname,
|
||||
const char *props, void *vdsa)
|
||||
void *vdsa)
|
||||
{
|
||||
PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
|
||||
|
||||
@@ -242,7 +251,7 @@ static int dsa_digest_signverify_init(void *vpdsactx, const char *mdname,
|
||||
if (!dsa_signature_init(vpdsactx, vdsa))
|
||||
return 0;
|
||||
|
||||
if (!dsa_setup_md(pdsactx, mdname, props))
|
||||
if (!dsa_setup_md(pdsactx, mdname, NULL))
|
||||
return 0;
|
||||
|
||||
pdsactx->mdctx = EVP_MD_CTX_new();
|
||||
|
||||
@@ -60,6 +60,7 @@ static OSSL_OP_signature_settable_ctx_md_params_fn ecdsa_settable_ctx_md_params;
|
||||
|
||||
typedef struct {
|
||||
OPENSSL_CTX *libctx;
|
||||
char *propq;
|
||||
EC_KEY *ec;
|
||||
char mdname[OSSL_MAX_NAME_SIZE];
|
||||
|
||||
@@ -90,7 +91,7 @@ typedef struct {
|
||||
BIGNUM *r;
|
||||
} PROV_ECDSA_CTX;
|
||||
|
||||
static void *ecdsa_newctx(void *provctx)
|
||||
static void *ecdsa_newctx(void *provctx, const char *propq)
|
||||
{
|
||||
PROV_ECDSA_CTX *ctx = OPENSSL_zalloc(sizeof(PROV_ECDSA_CTX));
|
||||
|
||||
@@ -98,6 +99,11 @@ static void *ecdsa_newctx(void *provctx)
|
||||
return NULL;
|
||||
|
||||
ctx->libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
|
||||
if (propq != NULL && (ctx->propq = OPENSSL_strdup(propq)) == NULL) {
|
||||
OPENSSL_free(ctx);
|
||||
ctx = NULL;
|
||||
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
@@ -203,7 +209,7 @@ static void free_md(PROV_ECDSA_CTX *ctx)
|
||||
}
|
||||
|
||||
static int ecdsa_digest_signverify_init(void *vctx, const char *mdname,
|
||||
const char *props, void *ec)
|
||||
void *ec)
|
||||
{
|
||||
PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
|
||||
int md_nid = NID_undef;
|
||||
@@ -214,7 +220,7 @@ static int ecdsa_digest_signverify_init(void *vctx, const char *mdname,
|
||||
if (!ecdsa_signature_init(vctx, ec))
|
||||
return 0;
|
||||
|
||||
ctx->md = EVP_MD_fetch(ctx->libctx, mdname, props);
|
||||
ctx->md = EVP_MD_fetch(ctx->libctx, mdname, ctx->propq);
|
||||
if ((md_nid = get_md_nid(ctx->md)) == NID_undef)
|
||||
goto error;
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ typedef struct {
|
||||
ECX_KEY *key;
|
||||
} PROV_EDDSA_CTX;
|
||||
|
||||
static void *eddsa_newctx(void *provctx)
|
||||
static void *eddsa_newctx(void *provctx, const char *propq_unused)
|
||||
{
|
||||
PROV_EDDSA_CTX *peddsactx = OPENSSL_zalloc(sizeof(PROV_EDDSA_CTX));
|
||||
|
||||
@@ -51,7 +51,7 @@ static void *eddsa_newctx(void *provctx)
|
||||
}
|
||||
|
||||
static int eddsa_digest_signverify_init(void *vpeddsactx, const char *mdname,
|
||||
const char *props, void *vedkey)
|
||||
void *vedkey)
|
||||
{
|
||||
PROV_EDDSA_CTX *peddsactx = (PROV_EDDSA_CTX *)vpeddsactx;
|
||||
ECX_KEY *edkey = (ECX_KEY *)vedkey;
|
||||
|
||||
@@ -31,16 +31,16 @@
|
||||
#include "prov/der_rsa.h"
|
||||
|
||||
static OSSL_OP_signature_newctx_fn rsa_newctx;
|
||||
static OSSL_OP_signature_sign_init_fn rsa_signature_init;
|
||||
static OSSL_OP_signature_verify_init_fn rsa_signature_init;
|
||||
static OSSL_OP_signature_verify_recover_init_fn rsa_signature_init;
|
||||
static OSSL_OP_signature_sign_init_fn rsa_sign_init;
|
||||
static OSSL_OP_signature_verify_init_fn rsa_verify_init;
|
||||
static OSSL_OP_signature_verify_recover_init_fn rsa_verify_recover_init;
|
||||
static OSSL_OP_signature_sign_fn rsa_sign;
|
||||
static OSSL_OP_signature_verify_fn rsa_verify;
|
||||
static OSSL_OP_signature_verify_recover_fn rsa_verify_recover;
|
||||
static OSSL_OP_signature_digest_sign_init_fn rsa_digest_signverify_init;
|
||||
static OSSL_OP_signature_digest_sign_init_fn rsa_digest_sign_init;
|
||||
static OSSL_OP_signature_digest_sign_update_fn rsa_digest_signverify_update;
|
||||
static OSSL_OP_signature_digest_sign_final_fn rsa_digest_sign_final;
|
||||
static OSSL_OP_signature_digest_verify_init_fn rsa_digest_signverify_init;
|
||||
static OSSL_OP_signature_digest_verify_init_fn rsa_digest_verify_init;
|
||||
static OSSL_OP_signature_digest_verify_update_fn rsa_digest_signverify_update;
|
||||
static OSSL_OP_signature_digest_verify_final_fn rsa_digest_verify_final;
|
||||
static OSSL_OP_signature_freectx_fn rsa_freectx;
|
||||
@@ -73,7 +73,9 @@ static OSSL_ITEM padding_item[] = {
|
||||
|
||||
typedef struct {
|
||||
OPENSSL_CTX *libctx;
|
||||
char *propq;
|
||||
RSA *rsa;
|
||||
int operation;
|
||||
|
||||
/*
|
||||
* Flag to determine if the hash function can be changed (1) or not (0)
|
||||
@@ -129,6 +131,8 @@ static int rsa_get_md_nid(const EVP_MD *md)
|
||||
{ NID_sha256, OSSL_DIGEST_NAME_SHA2_256 },
|
||||
{ NID_sha384, OSSL_DIGEST_NAME_SHA2_384 },
|
||||
{ NID_sha512, OSSL_DIGEST_NAME_SHA2_512 },
|
||||
{ NID_sha512_224, OSSL_DIGEST_NAME_SHA2_512_224 },
|
||||
{ NID_sha512_256, OSSL_DIGEST_NAME_SHA2_512_256 },
|
||||
{ NID_md5, OSSL_DIGEST_NAME_MD5 },
|
||||
{ NID_md5_sha1, OSSL_DIGEST_NAME_MD5_SHA1 },
|
||||
{ NID_md2, OSSL_DIGEST_NAME_MD2 },
|
||||
@@ -153,9 +157,6 @@ static int rsa_get_md_nid(const EVP_MD *md)
|
||||
}
|
||||
}
|
||||
|
||||
if (mdnid == NID_undef)
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST);
|
||||
|
||||
end:
|
||||
return mdnid;
|
||||
}
|
||||
@@ -177,44 +178,51 @@ static int rsa_check_padding(int mdnid, int padding)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void *rsa_newctx(void *provctx)
|
||||
static int rsa_check_parameters(EVP_MD *md, PROV_RSA_CTX *prsactx)
|
||||
{
|
||||
PROV_RSA_CTX *prsactx = OPENSSL_zalloc(sizeof(PROV_RSA_CTX));
|
||||
if (prsactx->pad_mode == RSA_PKCS1_PSS_PADDING) {
|
||||
int max_saltlen;
|
||||
|
||||
if (prsactx == NULL)
|
||||
/* See if minimum salt length exceeds maximum possible */
|
||||
max_saltlen = RSA_size(prsactx->rsa) - EVP_MD_size(md);
|
||||
if ((RSA_bits(prsactx->rsa) & 0x7) == 1)
|
||||
max_saltlen--;
|
||||
if (prsactx->min_saltlen > max_saltlen) {
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_SALT_LENGTH);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void *rsa_newctx(void *provctx, const char *propq)
|
||||
{
|
||||
PROV_RSA_CTX *prsactx = NULL;
|
||||
char *propq_copy = NULL;
|
||||
|
||||
if ((prsactx = OPENSSL_zalloc(sizeof(PROV_RSA_CTX))) == NULL
|
||||
|| (propq != NULL
|
||||
&& (propq_copy = OPENSSL_strdup(propq)) == NULL)) {
|
||||
OPENSSL_free(prsactx);
|
||||
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
prsactx->libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
|
||||
prsactx->flag_allow_md = 1;
|
||||
prsactx->propq = propq_copy;
|
||||
return prsactx;
|
||||
}
|
||||
|
||||
/* True if PSS parameters are restricted */
|
||||
#define rsa_pss_restricted(prsactx) (prsactx->min_saltlen != -1)
|
||||
|
||||
static int rsa_signature_init(void *vprsactx, void *vrsa)
|
||||
{
|
||||
PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
|
||||
|
||||
if (prsactx == NULL || vrsa == NULL || !RSA_up_ref(vrsa))
|
||||
return 0;
|
||||
|
||||
RSA_free(prsactx->rsa);
|
||||
prsactx->rsa = vrsa;
|
||||
if (RSA_get0_pss_params(prsactx->rsa) != NULL)
|
||||
prsactx->pad_mode = RSA_PKCS1_PSS_PADDING;
|
||||
else
|
||||
prsactx->pad_mode = RSA_PKCS1_PADDING;
|
||||
/* Maximum for sign, auto for verify */
|
||||
prsactx->saltlen = RSA_PSS_SALTLEN_AUTO;
|
||||
prsactx->min_saltlen = -1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int rsa_setup_md(PROV_RSA_CTX *ctx, const char *mdname,
|
||||
const char *mdprops)
|
||||
{
|
||||
if (mdprops == NULL)
|
||||
mdprops = ctx->propq;
|
||||
|
||||
if (mdname != NULL) {
|
||||
EVP_MD *md = EVP_MD_fetch(ctx->libctx, mdname, mdprops);
|
||||
int md_nid = rsa_get_md_nid(md);
|
||||
@@ -222,7 +230,14 @@ static int rsa_setup_md(PROV_RSA_CTX *ctx, const char *mdname,
|
||||
|
||||
if (md == NULL
|
||||
|| md_nid == NID_undef
|
||||
|| !rsa_check_padding(md_nid, ctx->pad_mode)) {
|
||||
|| !rsa_check_padding(md_nid, ctx->pad_mode)
|
||||
|| !rsa_check_parameters(md, ctx)) {
|
||||
if (md == NULL)
|
||||
ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST,
|
||||
"%s could not be fetched", mdname);
|
||||
if (md_nid == NID_undef)
|
||||
ERR_raise_data(ERR_LIB_PROV, PROV_R_DIGEST_NOT_ALLOWED,
|
||||
"digest=%s", mdname);
|
||||
EVP_MD_free(md);
|
||||
return 0;
|
||||
}
|
||||
@@ -256,18 +271,90 @@ static int rsa_setup_md(PROV_RSA_CTX *ctx, const char *mdname,
|
||||
}
|
||||
|
||||
static int rsa_setup_mgf1_md(PROV_RSA_CTX *ctx, const char *mdname,
|
||||
const char *props)
|
||||
const char *mdprops)
|
||||
{
|
||||
if (mdprops == NULL)
|
||||
mdprops = ctx->propq;
|
||||
|
||||
if (ctx->mgf1_mdname[0] != '\0')
|
||||
EVP_MD_free(ctx->mgf1_md);
|
||||
|
||||
if ((ctx->mgf1_md = EVP_MD_fetch(ctx->libctx, mdname, props)) == NULL)
|
||||
if ((ctx->mgf1_md = EVP_MD_fetch(ctx->libctx, mdname, mdprops)) == NULL) {
|
||||
ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST,
|
||||
"%s could not be fetched", mdname);
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_strlcpy(ctx->mgf1_mdname, mdname, sizeof(ctx->mgf1_mdname));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int rsa_signature_init(void *vprsactx, void *vrsa, int operation)
|
||||
{
|
||||
PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
|
||||
|
||||
if (prsactx == NULL || vrsa == NULL || !RSA_up_ref(vrsa))
|
||||
return 0;
|
||||
|
||||
RSA_free(prsactx->rsa);
|
||||
prsactx->rsa = vrsa;
|
||||
prsactx->operation = operation;
|
||||
|
||||
/* Maximum for sign, auto for verify */
|
||||
prsactx->saltlen = RSA_PSS_SALTLEN_AUTO;
|
||||
prsactx->min_saltlen = -1;
|
||||
|
||||
switch (RSA_test_flags(prsactx->rsa, RSA_FLAG_TYPE_MASK)) {
|
||||
case RSA_FLAG_TYPE_RSA:
|
||||
prsactx->pad_mode = RSA_PKCS1_PADDING;
|
||||
break;
|
||||
case RSA_FLAG_TYPE_RSASSAPSS:
|
||||
prsactx->pad_mode = RSA_PKCS1_PSS_PADDING;
|
||||
|
||||
{
|
||||
const RSA_PSS_PARAMS_30 *pss =
|
||||
rsa_get0_pss_params_30(prsactx->rsa);
|
||||
|
||||
if (!rsa_pss_params_30_is_unrestricted(pss)) {
|
||||
int md_nid = rsa_pss_params_30_hashalg(pss);
|
||||
int mgf1md_nid = rsa_pss_params_30_maskgenhashalg(pss);
|
||||
int min_saltlen = rsa_pss_params_30_saltlen(pss);
|
||||
const char *mdname, *mgf1mdname;
|
||||
|
||||
mdname = rsa_oaeppss_nid2name(md_nid);
|
||||
mgf1mdname = rsa_oaeppss_nid2name(mgf1md_nid);
|
||||
prsactx->min_saltlen = min_saltlen;
|
||||
|
||||
if (mdname == NULL) {
|
||||
ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST,
|
||||
"PSS restrictions lack hash algorithm");
|
||||
return 0;
|
||||
}
|
||||
if (mgf1mdname == NULL) {
|
||||
ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST,
|
||||
"PSS restrictions lack MGF1 hash algorithm");
|
||||
return 0;
|
||||
}
|
||||
|
||||
strncpy(prsactx->mdname, mdname, sizeof(prsactx->mdname));
|
||||
strncpy(prsactx->mgf1_mdname, mgf1mdname,
|
||||
sizeof(prsactx->mgf1_mdname));
|
||||
prsactx->saltlen = min_saltlen;
|
||||
|
||||
return rsa_setup_md(prsactx, mdname, prsactx->propq)
|
||||
&& rsa_setup_mgf1_md(prsactx, mgf1mdname, prsactx->propq);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
ERR_raise(ERR_LIB_RSA, PROV_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int setup_tbuf(PROV_RSA_CTX *ctx)
|
||||
{
|
||||
if (ctx->tbuf != NULL)
|
||||
@@ -287,10 +374,16 @@ static void clean_tbuf(PROV_RSA_CTX *ctx)
|
||||
|
||||
static void free_tbuf(PROV_RSA_CTX *ctx)
|
||||
{
|
||||
OPENSSL_clear_free(ctx->tbuf, RSA_size(ctx->rsa));
|
||||
clean_tbuf(ctx);
|
||||
OPENSSL_free(ctx->tbuf);
|
||||
ctx->tbuf = NULL;
|
||||
}
|
||||
|
||||
static int rsa_sign_init(void *vprsactx, void *vrsa)
|
||||
{
|
||||
return rsa_signature_init(vprsactx, vrsa, EVP_PKEY_OP_SIGN);
|
||||
}
|
||||
|
||||
static int rsa_sign(void *vprsactx, unsigned char *sig, size_t *siglen,
|
||||
size_t sigsize, const unsigned char *tbs, size_t tbslen)
|
||||
{
|
||||
@@ -304,8 +397,11 @@ static int rsa_sign(void *vprsactx, unsigned char *sig, size_t *siglen,
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (sigsize < (size_t)rsasize)
|
||||
if (sigsize < rsasize) {
|
||||
ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_SIGNATURE_SIZE,
|
||||
"is %zu, should be at least %zu", sigsize, rsasize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (mdsize != 0) {
|
||||
if (tbslen != mdsize) {
|
||||
@@ -313,7 +409,7 @@ static int rsa_sign(void *vprsactx, unsigned char *sig, size_t *siglen,
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
#ifndef FIPS_MODULE
|
||||
if (EVP_MD_is_a(prsactx->md, OSSL_DIGEST_NAME_MDC2)) {
|
||||
unsigned int sltmp;
|
||||
|
||||
@@ -336,7 +432,9 @@ static int rsa_sign(void *vprsactx, unsigned char *sig, size_t *siglen,
|
||||
switch (prsactx->pad_mode) {
|
||||
case RSA_X931_PADDING:
|
||||
if ((size_t)RSA_size(prsactx->rsa) < tbslen + 1) {
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_KEY_SIZE_TOO_SMALL);
|
||||
ERR_raise_data(ERR_LIB_PROV, PROV_R_KEY_SIZE_TOO_SMALL,
|
||||
"RSA key size = %d, expected minimum = %d",
|
||||
RSA_size(prsactx->rsa), tbslen + 1);
|
||||
return 0;
|
||||
}
|
||||
if (!setup_tbuf(prsactx)) {
|
||||
@@ -370,14 +468,24 @@ static int rsa_sign(void *vprsactx, unsigned char *sig, size_t *siglen,
|
||||
switch (prsactx->saltlen) {
|
||||
case RSA_PSS_SALTLEN_DIGEST:
|
||||
if (prsactx->min_saltlen > EVP_MD_size(prsactx->md)) {
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_PSS_SALTLEN_TOO_SMALL);
|
||||
ERR_raise_data(ERR_LIB_PROV,
|
||||
PROV_R_PSS_SALTLEN_TOO_SMALL,
|
||||
"minimum salt length set to %d, "
|
||||
"but the digest only gives %d",
|
||||
prsactx->min_saltlen,
|
||||
EVP_MD_size(prsactx->md));
|
||||
return 0;
|
||||
}
|
||||
/* FALLTHRU */
|
||||
default:
|
||||
if (prsactx->saltlen >= 0
|
||||
&& prsactx->saltlen < prsactx->min_saltlen) {
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_PSS_SALTLEN_TOO_SMALL);
|
||||
ERR_raise_data(ERR_LIB_PROV,
|
||||
PROV_R_PSS_SALTLEN_TOO_SMALL,
|
||||
"minimum salt length set to %d, but the"
|
||||
"actual salt length is only set to %d",
|
||||
prsactx->min_saltlen,
|
||||
prsactx->saltlen);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
@@ -407,7 +515,7 @@ static int rsa_sign(void *vprsactx, unsigned char *sig, size_t *siglen,
|
||||
prsactx->pad_mode);
|
||||
}
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
#ifndef FIPS_MODULE
|
||||
end:
|
||||
#endif
|
||||
if (ret <= 0) {
|
||||
@@ -419,6 +527,11 @@ static int rsa_sign(void *vprsactx, unsigned char *sig, size_t *siglen,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int rsa_verify_recover_init(void *vprsactx, void *vrsa)
|
||||
{
|
||||
return rsa_signature_init(vprsactx, vrsa, EVP_PKEY_OP_VERIFYRECOVER);
|
||||
}
|
||||
|
||||
static int rsa_verify_recover(void *vprsactx,
|
||||
unsigned char *rout,
|
||||
size_t *routlen,
|
||||
@@ -459,7 +572,9 @@ static int rsa_verify_recover(void *vprsactx,
|
||||
|
||||
*routlen = ret;
|
||||
if (routsize < (size_t)ret) {
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
|
||||
ERR_raise_data(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL,
|
||||
"buffer size is %d, should be %d",
|
||||
routsize, ret);
|
||||
return 0;
|
||||
}
|
||||
memcpy(rout, prsactx->tbuf, ret);
|
||||
@@ -496,6 +611,11 @@ static int rsa_verify_recover(void *vprsactx,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int rsa_verify_init(void *vprsactx, void *vrsa)
|
||||
{
|
||||
return rsa_signature_init(vprsactx, vrsa, EVP_PKEY_OP_VERIFY);
|
||||
}
|
||||
|
||||
static int rsa_verify(void *vprsactx, const unsigned char *sig, size_t siglen,
|
||||
const unsigned char *tbs, size_t tbslen)
|
||||
{
|
||||
@@ -520,29 +640,6 @@ static int rsa_verify(void *vprsactx, const unsigned char *sig, size_t siglen,
|
||||
int ret;
|
||||
size_t mdsize;
|
||||
|
||||
/* Check PSS restrictions */
|
||||
if (rsa_pss_restricted(prsactx)) {
|
||||
switch (prsactx->saltlen) {
|
||||
case RSA_PSS_SALTLEN_AUTO:
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_PSS_SALTLEN);
|
||||
return 0;
|
||||
case RSA_PSS_SALTLEN_DIGEST:
|
||||
if (prsactx->min_saltlen > EVP_MD_size(prsactx->md)) {
|
||||
ERR_raise(ERR_LIB_PROV,
|
||||
PROV_R_PSS_SALTLEN_TOO_SMALL);
|
||||
return 0;
|
||||
}
|
||||
/* FALLTHRU */
|
||||
default:
|
||||
if (prsactx->saltlen >= 0
|
||||
&& prsactx->saltlen < prsactx->min_saltlen) {
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_PSS_SALTLEN_TOO_SMALL);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* We need to check this for the RSA_verify_PKCS1_PSS_mgf1()
|
||||
* call
|
||||
@@ -596,18 +693,20 @@ static int rsa_verify(void *vprsactx, const unsigned char *sig, size_t siglen,
|
||||
}
|
||||
|
||||
static int rsa_digest_signverify_init(void *vprsactx, const char *mdname,
|
||||
const char *props, void *vrsa)
|
||||
void *vrsa, int operation)
|
||||
{
|
||||
PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
|
||||
|
||||
prsactx->flag_allow_md = 0;
|
||||
if (!rsa_signature_init(vprsactx, vrsa)
|
||||
|| !rsa_setup_md(prsactx, mdname, props))
|
||||
if (!rsa_signature_init(vprsactx, vrsa, operation)
|
||||
|| !rsa_setup_md(prsactx, mdname, NULL)) /* TODO RL */
|
||||
return 0;
|
||||
|
||||
prsactx->mdctx = EVP_MD_CTX_new();
|
||||
if (prsactx->mdctx == NULL)
|
||||
if (prsactx->mdctx == NULL) {
|
||||
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!EVP_DigestInit_ex(prsactx->mdctx, prsactx->md, NULL))
|
||||
goto error;
|
||||
@@ -622,8 +721,9 @@ static int rsa_digest_signverify_init(void *vprsactx, const char *mdname,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rsa_digest_signverify_update(void *vprsactx, const unsigned char *data,
|
||||
size_t datalen)
|
||||
static int rsa_digest_signverify_update(void *vprsactx,
|
||||
const unsigned char *data,
|
||||
size_t datalen)
|
||||
{
|
||||
PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
|
||||
|
||||
@@ -633,8 +733,15 @@ int rsa_digest_signverify_update(void *vprsactx, const unsigned char *data,
|
||||
return EVP_DigestUpdate(prsactx->mdctx, data, datalen);
|
||||
}
|
||||
|
||||
int rsa_digest_sign_final(void *vprsactx, unsigned char *sig, size_t *siglen,
|
||||
size_t sigsize)
|
||||
static int rsa_digest_sign_init(void *vprsactx, const char *mdname,
|
||||
void *vrsa)
|
||||
{
|
||||
return rsa_digest_signverify_init(vprsactx, mdname, vrsa,
|
||||
EVP_PKEY_OP_SIGN);
|
||||
}
|
||||
|
||||
static int rsa_digest_sign_final(void *vprsactx, unsigned char *sig,
|
||||
size_t *siglen, size_t sigsize)
|
||||
{
|
||||
PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
|
||||
unsigned char digest[EVP_MAX_MD_SIZE];
|
||||
@@ -661,6 +768,12 @@ int rsa_digest_sign_final(void *vprsactx, unsigned char *sig, size_t *siglen,
|
||||
return rsa_sign(vprsactx, sig, siglen, sigsize, digest, (size_t)dlen);
|
||||
}
|
||||
|
||||
static int rsa_digest_verify_init(void *vprsactx, const char *mdname,
|
||||
void *vrsa)
|
||||
{
|
||||
return rsa_digest_signverify_init(vprsactx, mdname, vrsa,
|
||||
EVP_PKEY_OP_VERIFY);
|
||||
}
|
||||
|
||||
int rsa_digest_verify_final(void *vprsactx, const unsigned char *sig,
|
||||
size_t siglen)
|
||||
@@ -695,6 +808,7 @@ static void rsa_freectx(void *vprsactx)
|
||||
EVP_MD_CTX_free(prsactx->mdctx);
|
||||
EVP_MD_free(prsactx->md);
|
||||
EVP_MD_free(prsactx->mgf1_md);
|
||||
OPENSSL_free(prsactx->propq);
|
||||
free_tbuf(prsactx);
|
||||
|
||||
OPENSSL_clear_free(prsactx, sizeof(prsactx));
|
||||
@@ -706,8 +820,10 @@ static void *rsa_dupctx(void *vprsactx)
|
||||
PROV_RSA_CTX *dstctx;
|
||||
|
||||
dstctx = OPENSSL_zalloc(sizeof(*srcctx));
|
||||
if (dstctx == NULL)
|
||||
if (dstctx == NULL) {
|
||||
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*dstctx = *srcctx;
|
||||
dstctx->rsa = NULL;
|
||||
@@ -858,11 +974,13 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[])
|
||||
|
||||
if (!OSSL_PARAM_get_utf8_string(p, &pmdname, sizeof(mdname)))
|
||||
return 0;
|
||||
if (propsp != NULL
|
||||
&& !OSSL_PARAM_get_utf8_string(propsp, &pmdprops, sizeof(mdprops)))
|
||||
|
||||
if (propsp == NULL)
|
||||
pmdprops = NULL;
|
||||
else if (!OSSL_PARAM_get_utf8_string(propsp,
|
||||
&pmdprops, sizeof(mdprops)))
|
||||
return 0;
|
||||
|
||||
/* TODO(3.0) PSS check needs more work */
|
||||
if (rsa_pss_restricted(prsactx)) {
|
||||
/* TODO(3.0) figure out what to do for prsactx->md == NULL */
|
||||
if (prsactx->md == NULL || EVP_MD_is_a(prsactx->md, mdname))
|
||||
@@ -872,13 +990,14 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[])
|
||||
}
|
||||
|
||||
/* non-PSS code follows */
|
||||
if (!rsa_setup_md(prsactx, mdname, mdprops))
|
||||
if (!rsa_setup_md(prsactx, mdname, pmdprops))
|
||||
return 0;
|
||||
}
|
||||
|
||||
p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_PAD_MODE);
|
||||
if (p != NULL) {
|
||||
int pad_mode = 0;
|
||||
const char *err_extra_text = NULL;
|
||||
|
||||
switch (p->data_type) {
|
||||
case OSSL_PARAM_INTEGER: /* Support for legacy pad mode number */
|
||||
@@ -910,31 +1029,49 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[])
|
||||
* OAEP padding is for asymmetric cipher only so is not compatible
|
||||
* with signature use.
|
||||
*/
|
||||
ERR_raise_data(ERR_LIB_PROV,
|
||||
PROV_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE,
|
||||
"OAEP padding not allowed for signing / verifying");
|
||||
return 0;
|
||||
err_extra_text = "OAEP padding not allowed for signing / verifying";
|
||||
goto bad_pad;
|
||||
case RSA_PKCS1_PSS_PADDING:
|
||||
if (prsactx->mdname[0] == '\0')
|
||||
rsa_setup_md(prsactx, "SHA1", "");
|
||||
goto cont;
|
||||
case RSA_PKCS1_PADDING:
|
||||
case RSA_SSLV23_PADDING:
|
||||
case RSA_NO_PADDING:
|
||||
case RSA_X931_PADDING:
|
||||
if (RSA_get0_pss_params(prsactx->rsa) != NULL) {
|
||||
ERR_raise_data(ERR_LIB_PROV,
|
||||
PROV_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE,
|
||||
"X.931 padding not allowed with RSA-PSS");
|
||||
if ((prsactx->operation
|
||||
& (EVP_PKEY_OP_SIGN | EVP_PKEY_OP_VERIFY)) == 0) {
|
||||
err_extra_text =
|
||||
"PSS padding only allowed for sign and verify operations";
|
||||
goto bad_pad;
|
||||
}
|
||||
if (prsactx->md == NULL
|
||||
&& !rsa_setup_md(prsactx, OSSL_DIGEST_NAME_SHA1, NULL)) {
|
||||
return 0;
|
||||
}
|
||||
cont:
|
||||
if (!rsa_check_padding(prsactx->mdnid, pad_mode))
|
||||
return 0;
|
||||
break;
|
||||
case RSA_PKCS1_PADDING:
|
||||
err_extra_text = "PKCS#1 padding not allowed with RSA-PSS";
|
||||
goto cont;
|
||||
case RSA_SSLV23_PADDING:
|
||||
err_extra_text = "SSLv3 padding not allowed with RSA-PSS";
|
||||
goto cont;
|
||||
case RSA_NO_PADDING:
|
||||
err_extra_text = "No padding not allowed with RSA-PSS";
|
||||
goto cont;
|
||||
case RSA_X931_PADDING:
|
||||
err_extra_text = "X.931 padding not allowed with RSA-PSS";
|
||||
cont:
|
||||
if (RSA_test_flags(prsactx->rsa,
|
||||
RSA_FLAG_TYPE_MASK) == RSA_FLAG_TYPE_RSA)
|
||||
break;
|
||||
/* FALLTHRU */
|
||||
default:
|
||||
bad_pad:
|
||||
if (err_extra_text == NULL)
|
||||
ERR_raise(ERR_LIB_PROV,
|
||||
PROV_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE);
|
||||
else
|
||||
ERR_raise_data(ERR_LIB_PROV,
|
||||
PROV_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE,
|
||||
err_extra_text);
|
||||
return 0;
|
||||
}
|
||||
if (!rsa_check_padding(prsactx->mdnid, pad_mode))
|
||||
return 0;
|
||||
prsactx->pad_mode = pad_mode;
|
||||
}
|
||||
|
||||
@@ -978,6 +1115,37 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (rsa_pss_restricted(prsactx)) {
|
||||
switch (prsactx->saltlen) {
|
||||
case RSA_PSS_SALTLEN_AUTO:
|
||||
if (prsactx->operation == EVP_PKEY_OP_VERIFY) {
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_PSS_SALTLEN);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case RSA_PSS_SALTLEN_DIGEST:
|
||||
if (prsactx->min_saltlen > EVP_MD_size(prsactx->md)) {
|
||||
ERR_raise_data(ERR_LIB_PROV,
|
||||
PROV_R_PSS_SALTLEN_TOO_SMALL,
|
||||
"Should be more than %d, but would be "
|
||||
"set to match digest size (%d)",
|
||||
prsactx->min_saltlen,
|
||||
EVP_MD_size(prsactx->md));
|
||||
return 0;
|
||||
}
|
||||
/* FALLTHRU */
|
||||
default:
|
||||
if (saltlen >= 0 && saltlen < prsactx->min_saltlen) {
|
||||
ERR_raise_data(ERR_LIB_PROV,
|
||||
PROV_R_PSS_SALTLEN_TOO_SMALL,
|
||||
"Should be more than %d, "
|
||||
"but would be set to %d",
|
||||
prsactx->min_saltlen, saltlen);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
prsactx->saltlen = saltlen;
|
||||
}
|
||||
|
||||
@@ -991,8 +1159,11 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[])
|
||||
|
||||
if (!OSSL_PARAM_get_utf8_string(p, &pmdname, sizeof(mdname)))
|
||||
return 0;
|
||||
if (propsp != NULL
|
||||
&& !OSSL_PARAM_get_utf8_string(propsp, &pmdprops, sizeof(mdprops)))
|
||||
|
||||
if (propsp == NULL)
|
||||
pmdprops = NULL;
|
||||
else if (!OSSL_PARAM_get_utf8_string(propsp,
|
||||
&pmdprops, sizeof(mdprops)))
|
||||
return 0;
|
||||
|
||||
if (prsactx->pad_mode != RSA_PKCS1_PSS_PADDING) {
|
||||
@@ -1000,9 +1171,8 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* TODO(3.0) PSS check needs more work */
|
||||
if (rsa_pss_restricted(prsactx)) {
|
||||
/* TODO(3.0) figure out what to do for prsactx->md == NULL */
|
||||
/* TODO(3.0) figure out what to do for prsactx->mgf1_md == NULL */
|
||||
if (prsactx->mgf1_md == NULL
|
||||
|| EVP_MD_is_a(prsactx->mgf1_md, mdname))
|
||||
return 1;
|
||||
@@ -1011,7 +1181,7 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[])
|
||||
}
|
||||
|
||||
/* non-PSS code follows */
|
||||
if (!rsa_setup_mgf1_md(prsactx, mdname, mdprops))
|
||||
if (!rsa_setup_mgf1_md(prsactx, mdname, pmdprops))
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1081,20 +1251,22 @@ static const OSSL_PARAM *rsa_settable_ctx_md_params(void *vprsactx)
|
||||
|
||||
const OSSL_DISPATCH rsa_signature_functions[] = {
|
||||
{ OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))rsa_newctx },
|
||||
{ OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))rsa_signature_init },
|
||||
{ OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))rsa_sign_init },
|
||||
{ OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))rsa_sign },
|
||||
{ OSSL_FUNC_SIGNATURE_VERIFY_INIT, (void (*)(void))rsa_signature_init },
|
||||
{ OSSL_FUNC_SIGNATURE_VERIFY_INIT, (void (*)(void))rsa_verify_init },
|
||||
{ OSSL_FUNC_SIGNATURE_VERIFY, (void (*)(void))rsa_verify },
|
||||
{ OSSL_FUNC_SIGNATURE_VERIFY_RECOVER_INIT, (void (*)(void))rsa_signature_init },
|
||||
{ OSSL_FUNC_SIGNATURE_VERIFY_RECOVER, (void (*)(void))rsa_verify_recover },
|
||||
{ OSSL_FUNC_SIGNATURE_VERIFY_RECOVER_INIT,
|
||||
(void (*)(void))rsa_verify_recover_init },
|
||||
{ OSSL_FUNC_SIGNATURE_VERIFY_RECOVER,
|
||||
(void (*)(void))rsa_verify_recover },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT,
|
||||
(void (*)(void))rsa_digest_signverify_init },
|
||||
(void (*)(void))rsa_digest_sign_init },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE,
|
||||
(void (*)(void))rsa_digest_signverify_update },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL,
|
||||
(void (*)(void))rsa_digest_sign_final },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT,
|
||||
(void (*)(void))rsa_digest_signverify_init },
|
||||
(void (*)(void))rsa_digest_verify_init },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE,
|
||||
(void (*)(void))rsa_digest_signverify_update },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL,
|
||||
|
||||
Reference in New Issue
Block a user