Latest update.

This commit is contained in:
2020-02-17 23:45:59 +09:00
parent 9dfeec3942
commit f85de4da03
381 changed files with 7278 additions and 1826 deletions
@@ -1,4 +1,6 @@
LIBS=../../../libcrypto
SOURCE[../../../libcrypto]=rsa_enc.c
# We make separate GOAL variables for each algorithm, to make it easy to
# switch each to the Legacy provider when needed.
$RSA_GOAL=../../libimplementations.a
SOURCE[$RSA_GOAL]=rsa_enc.c
@@ -118,6 +118,12 @@ static int rsa_encrypt(void *vprsactx, unsigned char *out, size_t *outlen,
PROVerr(0, ERR_R_MALLOC_FAILURE);
return 0;
}
if (prsactx->oaep_md == NULL) {
OPENSSL_free(tbuf);
prsactx->oaep_md = EVP_MD_fetch(prsactx->libctx, "SHA-1", NULL);
PROVerr(0, ERR_R_INTERNAL_ERROR);
return 0;
}
ret = RSA_padding_add_PKCS1_OAEP_mgf1(tbuf, rsasize, in, inlen,
prsactx->oaep_label,
prsactx->oaep_labellen,
@@ -194,6 +200,13 @@ static int rsa_decrypt(void *vprsactx, unsigned char *out, size_t *outlen,
return 0;
}
if (prsactx->pad_mode == RSA_PKCS1_OAEP_PADDING) {
if (prsactx->oaep_md == NULL) {
prsactx->oaep_md = EVP_MD_fetch(prsactx->libctx, "SHA-1", NULL);
if (prsactx->oaep_md == NULL) {
PROVerr(0, ERR_R_INTERNAL_ERROR);
return 0;
}
}
ret = RSA_padding_check_PKCS1_OAEP_mgf1(out, outsize, tbuf,
len, len,
prsactx->oaep_label,
@@ -2,7 +2,23 @@
# switch each to the Legacy provider when needed.
$DH_GOAL=../../libimplementations.a
$ECX_GOAL=../../libimplementations.a
IF[{- !$disabled{dh} -}]
SOURCE[$DH_GOAL]=dh_exch.c
ENDIF
IF[{- !$disabled{asm} -}]
$ECDEF_s390x=S390X_EC_ASM
# Now that we have defined all the arch specific variables, use the
# appropriate one, and define the appropriate macros
IF[$ECASM_{- $target{asm_arch} -}]
$ECDEF=$ECDEF_{- $target{asm_arch} -}
ENDIF
ENDIF
IF[{- !$disabled{ec} -}]
SOURCE[$ECX_GOAL]=ecx_exch.c
DEFINE[$ECX_GOAL]=$ECDEF
ENDIF
+2 -2
View File
@@ -92,9 +92,9 @@ static int dh_derive(void *vpdhctx, unsigned char *secret, size_t *secretlen,
DH_get0_key(pdhctx->dhpeer, &pub_key, NULL);
if (pdhctx->pad)
ret = dh_compute_key_padded(pdhctx->libctx, secret, pub_key, pdhctx->dh);
ret = DH_compute_key_padded(secret, pub_key, pdhctx->dh);
else
ret = dh_compute_key(pdhctx->libctx, secret, pub_key, pdhctx->dh);
ret = DH_compute_key(secret, pub_key, pdhctx->dh);
if (ret <= 0)
return 0;
@@ -0,0 +1,223 @@
/*
* Copyright 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
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <openssl/crypto.h>
#include <openssl/core_numbers.h>
#include <openssl/core_names.h>
#include <openssl/params.h>
#include <openssl/err.h>
#include "internal/cryptlib.h"
#include "crypto/ecx.h"
#include "prov/implementations.h"
#include "prov/providercommonerr.h"
#ifdef S390X_EC_ASM
# include "s390x_arch.h"
#endif
static OSSL_OP_keyexch_newctx_fn x25519_newctx;
static OSSL_OP_keyexch_newctx_fn x448_newctx;
static OSSL_OP_keyexch_init_fn ecx_init;
static OSSL_OP_keyexch_set_peer_fn ecx_set_peer;
static OSSL_OP_keyexch_derive_fn ecx_derive;
static OSSL_OP_keyexch_freectx_fn ecx_freectx;
static OSSL_OP_keyexch_dupctx_fn ecx_dupctx;
/*
* What's passed as an actual key is defined by the KEYMGMT interface.
* We happen to know that our KEYMGMT simply passes ECX_KEY structures, so
* we use that here too.
*/
typedef struct {
size_t keylen;
ECX_KEY *key;
ECX_KEY *peerkey;
} PROV_ECX_CTX;
static void *ecx_newctx(void *provctx, size_t keylen)
{
PROV_ECX_CTX *ctx = OPENSSL_zalloc(sizeof(PROV_ECX_CTX));
if (ctx == NULL) {
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
return NULL;
}
ctx->keylen = keylen;
return ctx;
}
static void *x25519_newctx(void *provctx)
{
return ecx_newctx(provctx, X25519_KEYLEN);
}
static void *x448_newctx(void *provctx)
{
return ecx_newctx(provctx, X448_KEYLEN);
}
static int ecx_init(void *vecxctx, void *vkey)
{
PROV_ECX_CTX *ecxctx = (PROV_ECX_CTX *)vecxctx;
ECX_KEY *key = vkey;
if (ecxctx == NULL
|| key == NULL
|| key->keylen != ecxctx->keylen
|| !ecx_key_up_ref(key)) {
ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR);
return 0;
}
ecx_key_free(ecxctx->key);
ecxctx->key = key;
return 1;
}
static int ecx_set_peer(void *vecxctx, void *vkey)
{
PROV_ECX_CTX *ecxctx = (PROV_ECX_CTX *)vecxctx;
ECX_KEY *key = vkey;
if (ecxctx == NULL
|| key == NULL
|| key->keylen != ecxctx->keylen
|| !ecx_key_up_ref(key)) {
ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR);
return 0;
}
ecx_key_free(ecxctx->peerkey);
ecxctx->peerkey = key;
return 1;
}
static int ecx_derive(void *vecxctx, unsigned char *secret, size_t *secretlen,
size_t outlen)
{
PROV_ECX_CTX *ecxctx = (PROV_ECX_CTX *)vecxctx;
if (ecxctx->key == NULL
|| ecxctx->key->privkey == NULL
|| ecxctx->peerkey == NULL) {
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY);
return 0;
}
if (!ossl_assert(ecxctx->keylen == X25519_KEYLEN
|| ecxctx->keylen == X448_KEYLEN)) {
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);
return 0;
}
if (secret == NULL) {
*secretlen = ecxctx->keylen;
return 1;
}
if (outlen < ecxctx->keylen) {
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);
return 0;
}
if (ecxctx->keylen == X25519_KEYLEN) {
#ifdef S390X_EC_ASM
if (OPENSSL_s390xcap_P.pcc[1]
& S390X_CAPBIT(S390X_SCALAR_MULTIPLY_X25519)) {
if (s390x_x25519_mul(secret, ecxctx->peerkey->pubkey,
ecxctx->key->privkey) == 0) {
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_DURING_DERIVATION);
return 0;
}
} else
#endif
if (X25519(secret, ecxctx->key->privkey, ecxctx->peerkey->pubkey) == 0) {
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_DURING_DERIVATION);
return 0;
}
} else {
#ifdef S390X_EC_ASM
if (OPENSSL_s390xcap_P.pcc[1]
& S390X_CAPBIT(S390X_SCALAR_MULTIPLY_X448)) {
if (s390x_x448_mul(secret, ecxctx->peerkey->pubkey,
ecxctx->key->privkey) == 0) {
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_DURING_DERIVATION);
return 0;
}
} else
#endif
if (X448(secret, ecxctx->key->privkey, ecxctx->peerkey->pubkey) == 0) {
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_DURING_DERIVATION);
return 0;
}
}
*secretlen = ecxctx->keylen;
return 1;
}
static void ecx_freectx(void *vecxctx)
{
PROV_ECX_CTX *ecxctx = (PROV_ECX_CTX *)vecxctx;
ecx_key_free(ecxctx->key);
ecx_key_free(ecxctx->peerkey);
OPENSSL_free(ecxctx);
}
static void *ecx_dupctx(void *vecxctx)
{
PROV_ECX_CTX *srcctx = (PROV_ECX_CTX *)vecxctx;
PROV_ECX_CTX *dstctx;
dstctx = OPENSSL_zalloc(sizeof(*srcctx));
if (dstctx == NULL) {
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
return NULL;
}
*dstctx = *srcctx;
if (dstctx->key != NULL && !ecx_key_up_ref(dstctx->key)) {
ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR);
OPENSSL_free(dstctx);
return NULL;
}
if (dstctx->peerkey != NULL && !ecx_key_up_ref(dstctx->peerkey)) {
ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR);
ecx_key_free(dstctx->key);
OPENSSL_free(dstctx);
return NULL;
}
return dstctx;
}
const OSSL_DISPATCH x25519_keyexch_functions[] = {
{ OSSL_FUNC_KEYEXCH_NEWCTX, (void (*)(void))x25519_newctx },
{ OSSL_FUNC_KEYEXCH_INIT, (void (*)(void))ecx_init },
{ OSSL_FUNC_KEYEXCH_DERIVE, (void (*)(void))ecx_derive },
{ OSSL_FUNC_KEYEXCH_SET_PEER, (void (*)(void))ecx_set_peer },
{ OSSL_FUNC_KEYEXCH_FREECTX, (void (*)(void))ecx_freectx },
{ OSSL_FUNC_KEYEXCH_DUPCTX, (void (*)(void))ecx_dupctx },
{ 0, NULL }
};
const OSSL_DISPATCH x448_keyexch_functions[] = {
{ OSSL_FUNC_KEYEXCH_NEWCTX, (void (*)(void))x448_newctx },
{ OSSL_FUNC_KEYEXCH_INIT, (void (*)(void))ecx_init },
{ OSSL_FUNC_KEYEXCH_DERIVE, (void (*)(void))ecx_derive },
{ OSSL_FUNC_KEYEXCH_SET_PEER, (void (*)(void))ecx_set_peer },
{ OSSL_FUNC_KEYEXCH_FREECTX, (void (*)(void))ecx_freectx },
{ OSSL_FUNC_KEYEXCH_DUPCTX, (void (*)(void))ecx_dupctx },
{ 0, NULL }
};
@@ -257,9 +257,13 @@ 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 x25519_keymgmt_functions[];
extern const OSSL_DISPATCH x448_keymgmt_functions[];
/* Key Exchange */
extern const OSSL_DISPATCH dh_keyexch_functions[];
extern const OSSL_DISPATCH x25519_keyexch_functions[];
extern const OSSL_DISPATCH x448_keyexch_functions[];
/* Signature */
extern const OSSL_DISPATCH dsa_signature_functions[];
@@ -4,6 +4,7 @@
$DH_GOAL=../../libimplementations.a
$DSA_GOAL=../../libimplementations.a
$RSA_GOAL=../../libimplementations.a
$ECX_GOAL=../../libimplementations.a
IF[{- !$disabled{dh} -}]
SOURCE[$DH_GOAL]=dh_kmgmt.c
@@ -12,3 +13,6 @@ IF[{- !$disabled{dsa} -}]
SOURCE[$DSA_GOAL]=dsa_kmgmt.c
ENDIF
SOURCE[$RSA_GOAL]=rsa_kmgmt.c
IF[{- !$disabled{ec} -}]
SOURCE[$ECX_GOAL]=ecx_kmgmt.c
ENDIF
+9 -8
View File
@@ -10,12 +10,13 @@
#include <openssl/core_numbers.h>
#include <openssl/core_names.h>
#include <openssl/bn.h>
#include <openssl/dh.h>
#include <openssl/params.h>
#include "internal/param_build.h"
#include "crypto/dh.h"
#include "prov/implementations.h"
#include "prov/providercommon.h"
#include "prov/provider_ctx.h"
#include "crypto/dh.h"
static OSSL_OP_keymgmt_new_fn dh_newdata;
static OSSL_OP_keymgmt_free_fn dh_freedata;
@@ -86,9 +87,9 @@ static int params_to_key(DH *dh, const OSSL_PARAM params[])
return 0;
param_priv_key =
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_DH_PRIV_KEY);
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY);
param_pub_key =
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_DH_PUB_KEY);
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PUB_KEY);
/*
* DH documentation says that a public key must be present if a
@@ -126,10 +127,10 @@ static int key_to_params(DH *dh, OSSL_PARAM_BLD *tmpl)
DH_get0_key(dh, &pub_key, &priv_key);
if (priv_key != NULL
&& !ossl_param_bld_push_BN(tmpl, OSSL_PKEY_PARAM_DH_PRIV_KEY, priv_key))
&& !ossl_param_bld_push_BN(tmpl, OSSL_PKEY_PARAM_PRIV_KEY, priv_key))
return 0;
if (pub_key != NULL
&& !ossl_param_bld_push_BN(tmpl, OSSL_PKEY_PARAM_DH_PUB_KEY, pub_key))
&& !ossl_param_bld_push_BN(tmpl, OSSL_PKEY_PARAM_PUB_KEY, pub_key))
return 0;
return 1;
@@ -137,7 +138,7 @@ static int key_to_params(DH *dh, OSSL_PARAM_BLD *tmpl)
static void *dh_newdata(void *provctx)
{
return DH_new();
return dh_new_with_ctx(PROV_LIBRARY_CONTEXT_OF(provctx));
}
static void dh_freedata(void *keydata)
@@ -214,9 +215,9 @@ static int dh_export(void *keydata, int selection, OSSL_CALLBACK *param_cb,
OSSL_PARAM_BN(OSSL_PKEY_PARAM_FFC_P, NULL, 0), \
OSSL_PARAM_BN(OSSL_PKEY_PARAM_FFC_G, NULL, 0)
# define DH_IMEXPORTABLE_PUBLIC_KEY \
OSSL_PARAM_BN(OSSL_PKEY_PARAM_DH_PUB_KEY, NULL, 0)
OSSL_PARAM_BN(OSSL_PKEY_PARAM_PUB_KEY, NULL, 0)
# define DH_IMEXPORTABLE_PRIVATE_KEY \
OSSL_PARAM_BN(OSSL_PKEY_PARAM_DH_PRIV_KEY, NULL, 0)
OSSL_PARAM_BN(OSSL_PKEY_PARAM_PRIV_KEY, NULL, 0)
static const OSSL_PARAM dh_all_types[] = {
DH_IMEXPORTABLE_PARAMETERS,
DH_IMEXPORTABLE_PUBLIC_KEY,
+13 -7
View File
@@ -7,6 +7,12 @@
* https://www.openssl.org/source/license.html
*/
/*
* DSA low level APIs are deprecated for public use, but still ok for
* internal use.
*/
#include "internal/deprecated.h"
#include <openssl/core_numbers.h>
#include <openssl/core_names.h>
#include <openssl/bn.h>
@@ -94,9 +100,9 @@ static int params_to_key(DSA *dsa, const OSSL_PARAM params[])
return 0;
param_priv_key =
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_DSA_PRIV_KEY);
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY);
param_pub_key =
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_DSA_PUB_KEY);
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PUB_KEY);
/*
* DSA documentation says that a public key must be present if a private key
@@ -133,10 +139,10 @@ static int key_to_params(DSA *dsa, OSSL_PARAM_BLD *tmpl)
DSA_get0_key(dsa, &pub_key, &priv_key);
if (priv_key != NULL
&& !ossl_param_bld_push_BN(tmpl, OSSL_PKEY_PARAM_DSA_PRIV_KEY, priv_key))
&& !ossl_param_bld_push_BN(tmpl, OSSL_PKEY_PARAM_PRIV_KEY, priv_key))
return 0;
if (pub_key != NULL
&& !ossl_param_bld_push_BN(tmpl, OSSL_PKEY_PARAM_DSA_PUB_KEY, pub_key))
&& !ossl_param_bld_push_BN(tmpl, OSSL_PKEY_PARAM_PUB_KEY, pub_key))
return 0;
return 1;
@@ -144,7 +150,7 @@ static int key_to_params(DSA *dsa, OSSL_PARAM_BLD *tmpl)
static void *dsa_newdata(void *provctx)
{
return DSA_new();
return dsa_new_with_ctx(PROV_LIBRARY_CONTEXT_OF(provctx));
}
static void dsa_freedata(void *keydata)
@@ -222,9 +228,9 @@ static int dsa_export(void *keydata, int selection, OSSL_CALLBACK *param_cb,
OSSL_PARAM_BN(OSSL_PKEY_PARAM_FFC_Q, NULL, 0), \
OSSL_PARAM_BN(OSSL_PKEY_PARAM_FFC_G, NULL, 0)
# define DSA_IMEXPORTABLE_PUBLIC_KEY \
OSSL_PARAM_BN(OSSL_PKEY_PARAM_DSA_PUB_KEY, NULL, 0)
OSSL_PARAM_BN(OSSL_PKEY_PARAM_PUB_KEY, NULL, 0)
# define DSA_IMEXPORTABLE_PRIVATE_KEY \
OSSL_PARAM_BN(OSSL_PKEY_PARAM_DSA_PRIV_KEY, NULL, 0)
OSSL_PARAM_BN(OSSL_PKEY_PARAM_PRIV_KEY, NULL, 0)
static const OSSL_PARAM dsa_all_types[] = {
DSA_IMEXPORTABLE_PARAMETERS,
DSA_IMEXPORTABLE_PUBLIC_KEY,
@@ -0,0 +1,231 @@
/*
* Copyright 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
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <assert.h>
#include <openssl/core_numbers.h>
#include <openssl/core_names.h>
#include <openssl/params.h>
#include "internal/param_build.h"
#include "crypto/ecx.h"
#include "prov/implementations.h"
#include "prov/providercommon.h"
static OSSL_OP_keymgmt_new_fn x25519_new_key;
static OSSL_OP_keymgmt_new_fn x448_new_key;
static OSSL_OP_keymgmt_get_params_fn x25519_get_params;
static OSSL_OP_keymgmt_get_params_fn x448_get_params;
static OSSL_OP_keymgmt_gettable_params_fn ecx_gettable_params;
static OSSL_OP_keymgmt_has_fn ecx_has;
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;
static OSSL_OP_keymgmt_export_types_fn ecx_imexport_types;
static void *x25519_new_key(void *provctx)
{
return ecx_key_new(X25519_KEYLEN, 0);
}
static void *x448_new_key(void *provctx)
{
return ecx_key_new(X448_KEYLEN, 0);
}
static int ecx_has(void *keydata, int selection)
{
ECX_KEY *key = keydata;
const int ecx_selections = OSSL_KEYMGMT_SELECT_PUBLIC_KEY
| OSSL_KEYMGMT_SELECT_PRIVATE_KEY;
int ok = 1;
if ((selection & ~ecx_selections) != 0
|| (selection & ecx_selections) == 0)
return 0;
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
ok = ok && key->haspubkey;
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
ok = ok && key->privkey != NULL;
return ok;
}
static int ecx_import(void *keydata, int selection, const OSSL_PARAM params[])
{
ECX_KEY *key = keydata;
size_t privkeylen = 0, pubkeylen;
const OSSL_PARAM *param_priv_key = NULL, *param_pub_key;
unsigned char *pubkey;
const int ecx_selections = OSSL_KEYMGMT_SELECT_PUBLIC_KEY
| OSSL_KEYMGMT_SELECT_PRIVATE_KEY;
if (key == NULL)
return 0;
if ((selection & ~ecx_selections) != 0
|| (selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) == 0)
return 0;
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
param_priv_key =
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY);
param_pub_key =
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PUB_KEY);
/*
* If a private key is present then a public key must also be present.
* Alternatively we've just got a public key.
*/
if (param_pub_key == NULL
|| (param_priv_key == NULL
&& (selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0))
return 0;
if (param_priv_key != NULL
&& !OSSL_PARAM_get_octet_string(param_priv_key,
(void **)&key->privkey, key->keylen,
&privkeylen))
return 0;
pubkey = key->pubkey;
if (!OSSL_PARAM_get_octet_string(param_pub_key,
(void **)&pubkey,
sizeof(key->pubkey), &pubkeylen))
return 0;
if (pubkeylen != key->keylen
|| (param_priv_key != NULL && privkeylen != key->keylen))
return 0;
key->haspubkey = 1;
return 1;
}
static int key_to_params(ECX_KEY *key, OSSL_PARAM_BLD *tmpl)
{
if (key == NULL)
return 0;
if (!ossl_param_bld_push_octet_string(tmpl, OSSL_PKEY_PARAM_PUB_KEY,
key->pubkey, key->keylen))
return 0;
if (key->privkey != NULL
&& !ossl_param_bld_push_octet_string(tmpl, OSSL_PKEY_PARAM_PRIV_KEY,
key->privkey, key->keylen))
return 0;
return 1;
}
static int ecx_export(void *keydata, int selection, OSSL_CALLBACK *param_cb,
void *cbarg)
{
ECX_KEY *key = keydata;
OSSL_PARAM_BLD tmpl;
OSSL_PARAM *params = NULL;
int ret;
if (key == NULL)
return 0;
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0
&& !key_to_params(key, &tmpl))
return 0;
ossl_param_bld_init(&tmpl);
params = ossl_param_bld_to_param(&tmpl);
if (params == NULL) {
ossl_param_bld_free(params);
return 0;
}
ret = param_cb(params, cbarg);
ossl_param_bld_free(params);
return ret;
}
static const OSSL_PARAM ecx_key_types[] = {
OSSL_PARAM_BN(OSSL_PKEY_PARAM_PUB_KEY, NULL, 0),
OSSL_PARAM_BN(OSSL_PKEY_PARAM_PRIV_KEY, NULL, 0),
OSSL_PARAM_END
};
static const OSSL_PARAM *ecx_imexport_types(int selection)
{
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
return ecx_key_types;
return NULL;
}
static int ecx_get_params(OSSL_PARAM params[], int bits, int secbits,
int size)
{
OSSL_PARAM *p;
if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_BITS)) != NULL
&& !OSSL_PARAM_set_int(p, bits))
return 0;
if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_SECURITY_BITS)) != NULL
&& !OSSL_PARAM_set_int(p, secbits))
return 0;
if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_MAX_SIZE)) != NULL
&& !OSSL_PARAM_set_int(p, size))
return 0;
return 1;
}
static int x25519_get_params(void *key, OSSL_PARAM params[])
{
return ecx_get_params(params, X25519_BITS, X25519_SECURITY_BITS, X25519_KEYLEN);
}
static int x448_get_params(void *key, OSSL_PARAM params[])
{
return ecx_get_params(params, X448_BITS, X448_SECURITY_BITS, X448_KEYLEN);
}
static const OSSL_PARAM ecx_params[] = {
OSSL_PARAM_int(OSSL_PKEY_PARAM_BITS, NULL),
OSSL_PARAM_int(OSSL_PKEY_PARAM_SECURITY_BITS, NULL),
OSSL_PARAM_int(OSSL_PKEY_PARAM_MAX_SIZE, NULL),
OSSL_PARAM_END
};
static const OSSL_PARAM *ecx_gettable_params(void)
{
return ecx_params;
}
const OSSL_DISPATCH x25519_keymgmt_functions[] = {
{ OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))x25519_new_key },
{ OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))ecx_key_free },
{ OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*) (void))x25519_get_params },
{ OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*) (void))ecx_gettable_params },
{ OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))ecx_has },
{ 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 },
{ OSSL_FUNC_KEYMGMT_EXPORT_TYPES, (void (*)(void))ecx_imexport_types },
{ 0, NULL }
};
const OSSL_DISPATCH x448_keymgmt_functions[] = {
{ OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))x448_new_key },
{ OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))ecx_key_free },
{ OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*) (void))x448_get_params },
{ OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*) (void))ecx_gettable_params },
{ OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))ecx_has },
{ 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 },
{ OSSL_FUNC_KEYMGMT_EXPORT_TYPES, (void (*)(void))ecx_imexport_types },
{ 0, NULL }
};
+11 -3
View File
@@ -18,6 +18,7 @@
#include "internal/param_build.h"
#include "prov/implementations.h"
#include "prov/providercommon.h"
#include "prov/provider_ctx.h"
#include "crypto/rsa.h"
static OSSL_OP_keymgmt_new_fn rsa_newdata;
@@ -170,7 +171,9 @@ static int key_to_params(RSA *rsa, OSSL_PARAM_BLD *tmpl)
static void *rsa_newdata(void *provctx)
{
return RSA_new();
OPENSSL_CTX *libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
return rsa_new_with_ctx(libctx);
}
static void rsa_freedata(void *keydata)
@@ -321,7 +324,7 @@ static int rsa_get_params(void *key, OSSL_PARAM params[])
&& !OSSL_PARAM_set_int(p, RSA_size(rsa)))
return 0;
# if 0 /* PSS support pending */
# 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) {
@@ -338,9 +341,14 @@ static int rsa_get_params(void *key, OSSL_PARAM params[])
}
#endif
if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_DEFAULT_DIGEST)) != NULL
&& RSA_get0_pss_params(rsa) == NULL)
/* TODO(3.0): PSS support pending */
#if 0
&& RSA_get0_pss_params(rsa) == NULL
#endif
) {
if (!OSSL_PARAM_set_utf8_string(p, RSA_DEFAULT_MD))
return 0;
}
return 1;
}
@@ -7,6 +7,12 @@
* https://www.openssl.org/source/license.html
*/
/*
* DSA low level APIs are deprecated for public use, but still ok for
* internal use.
*/
#include "internal/deprecated.h"
#include <openssl/dsa.h>
#include <openssl/err.h>
#include "prov/bio.h" /* ossl_prov_bio_printf() */
@@ -7,6 +7,12 @@
* https://www.openssl.org/source/license.html
*/
/*
* DSA low level APIs are deprecated for public use, but still ok for
* internal use.
*/
#include "internal/deprecated.h"
#include <openssl/core_numbers.h>
#include <openssl/pem.h>
#include <openssl/dsa.h>
@@ -7,6 +7,12 @@
* https://www.openssl.org/source/license.html
*/
/*
* DSA low level APIs are deprecated for public use, but still ok for
* internal use.
*/
#include "internal/deprecated.h"
#include <openssl/core_numbers.h>
#include <openssl/core_names.h>
#include <openssl/err.h>
@@ -7,6 +7,12 @@
* https://www.openssl.org/source/license.html
*/
/*
* DSA low level APIs are deprecated for public use, but still ok for
* internal use.
*/
#include "internal/deprecated.h"
#include <openssl/core_numbers.h>
#include <openssl/err.h>
#include <openssl/pem.h>
+7 -2
View File
@@ -7,6 +7,12 @@
* https://www.openssl.org/source/license.html
*/
/*
* DSA low level APIs are deprecated for public use, but still ok for
* internal use.
*/
#include "internal/deprecated.h"
#include <string.h>
#include <openssl/crypto.h>
@@ -194,8 +200,7 @@ static int dsa_sign(void *vpdsactx, unsigned char *sig, size_t *siglen,
if (mdsize != 0 && tbslen != mdsize)
return 0;
ret = dsa_sign_int(pdsactx->libctx, 0, tbs, tbslen, sig, &sltmp,
pdsactx->dsa);
ret = dsa_sign_int(0, tbs, tbslen, sig, &sltmp, pdsactx->dsa);
if (ret <= 0)
return 0;