Latest update.
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
/* Just for SSL_MAX_MASTER_KEY_LENGTH */
|
||||
#include <openssl/ssl.h>
|
||||
#include "internal/constant_time.h"
|
||||
#include "internal/sizes.h"
|
||||
#include "crypto/rsa.h"
|
||||
#include "prov/providercommonerr.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
@@ -36,6 +37,16 @@ static OSSL_OP_asym_cipher_gettable_ctx_params_fn rsa_gettable_ctx_params;
|
||||
static OSSL_OP_asym_cipher_set_ctx_params_fn rsa_set_ctx_params;
|
||||
static OSSL_OP_asym_cipher_settable_ctx_params_fn rsa_settable_ctx_params;
|
||||
|
||||
static OSSL_ITEM padding_item[] = {
|
||||
{ RSA_PKCS1_PADDING, "pkcs1" },
|
||||
{ RSA_SSLV23_PADDING, "sslv23" },
|
||||
{ RSA_NO_PADDING, "none" },
|
||||
{ RSA_PKCS1_OAEP_PADDING, "oaep" }, /* Correct spelling first */
|
||||
{ RSA_PKCS1_OAEP_PADDING, "oeap" },
|
||||
{ RSA_X931_PADDING, "x931" },
|
||||
{ RSA_PKCS1_PSS_PADDING, "pss" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
/*
|
||||
* What's passed as an actual key is defined by the KEYMGMT interface.
|
||||
@@ -262,8 +273,35 @@ static int rsa_get_ctx_params(void *vprsactx, OSSL_PARAM *params)
|
||||
return 0;
|
||||
|
||||
p = OSSL_PARAM_locate(params, OSSL_ASYM_CIPHER_PARAM_PAD_MODE);
|
||||
if (p != NULL && !OSSL_PARAM_set_int(p, prsactx->pad_mode))
|
||||
return 0;
|
||||
if (p != NULL)
|
||||
switch (p->data_type) {
|
||||
case OSSL_PARAM_INTEGER: /* Support for legacy pad mode number */
|
||||
if (!OSSL_PARAM_set_int(p, prsactx->pad_mode))
|
||||
return 0;
|
||||
break;
|
||||
case OSSL_PARAM_UTF8_STRING:
|
||||
{
|
||||
int i;
|
||||
const char *word = NULL;
|
||||
|
||||
for (i = 0; padding_item[i].id != 0; i++) {
|
||||
if (prsactx->pad_mode == (int)padding_item[i].id) {
|
||||
word = padding_item[i].ptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (word != NULL) {
|
||||
if (!OSSL_PARAM_set_utf8_string(p, word))
|
||||
return 0;
|
||||
} else {
|
||||
ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
p = OSSL_PARAM_locate(params, OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST);
|
||||
if (p != NULL && !OSSL_PARAM_set_utf8_string(p, prsactx->oaep_md == NULL
|
||||
@@ -303,7 +341,7 @@ static int rsa_get_ctx_params(void *vprsactx, OSSL_PARAM *params)
|
||||
|
||||
static const OSSL_PARAM known_gettable_ctx_params[] = {
|
||||
OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST, NULL, 0),
|
||||
OSSL_PARAM_int(OSSL_ASYM_CIPHER_PARAM_PAD_MODE, NULL),
|
||||
OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_PAD_MODE, NULL, 0),
|
||||
OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST, NULL, 0),
|
||||
OSSL_PARAM_DEFN(OSSL_ASYM_CIPHER_PARAM_OAEP_LABEL, OSSL_PARAM_OCTET_PTR,
|
||||
NULL, 0),
|
||||
@@ -322,10 +360,9 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[])
|
||||
{
|
||||
PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
|
||||
const OSSL_PARAM *p;
|
||||
/* Should be big enough */
|
||||
char mdname[80], mdprops[80] = { '\0' };
|
||||
char mdname[OSSL_MAX_NAME_SIZE];
|
||||
char mdprops[OSSL_MAX_PROPQUERY_SIZE] = { '\0' };
|
||||
char *str = mdname;
|
||||
int pad_mode;
|
||||
|
||||
if (prsactx == NULL || params == NULL)
|
||||
return 0;
|
||||
@@ -352,8 +389,32 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[])
|
||||
|
||||
p = OSSL_PARAM_locate_const(params, OSSL_ASYM_CIPHER_PARAM_PAD_MODE);
|
||||
if (p != NULL) {
|
||||
if (!OSSL_PARAM_get_int(p, &pad_mode))
|
||||
int pad_mode = 0;
|
||||
|
||||
switch (p->data_type) {
|
||||
case OSSL_PARAM_INTEGER: /* Support for legacy pad mode number */
|
||||
if (!OSSL_PARAM_get_int(p, &pad_mode))
|
||||
return 0;
|
||||
break;
|
||||
case OSSL_PARAM_UTF8_STRING:
|
||||
{
|
||||
int i;
|
||||
|
||||
if (p->data == NULL)
|
||||
return 0;
|
||||
|
||||
for (i = 0; padding_item[i].id != 0; i++) {
|
||||
if (strcmp(p->data, padding_item[i].ptr) == 0) {
|
||||
pad_mode = padding_item[i].id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* PSS padding is for signatures only so is not compatible with
|
||||
* asymmetric cipher use.
|
||||
@@ -425,7 +486,7 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[])
|
||||
|
||||
static const OSSL_PARAM known_settable_ctx_params[] = {
|
||||
OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST, NULL, 0),
|
||||
OSSL_PARAM_int(OSSL_ASYM_CIPHER_PARAM_PAD_MODE, NULL),
|
||||
OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_PAD_MODE, NULL, 0),
|
||||
OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST, NULL, 0),
|
||||
OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST_PROPS, NULL, 0),
|
||||
OSSL_PARAM_octet_string(OSSL_ASYM_CIPHER_PARAM_OAEP_LABEL, NULL, 0),
|
||||
|
||||
@@ -69,9 +69,11 @@ static int aes_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
||||
PROV_AES_HMAC_SHA_CTX *ctx = (PROV_AES_HMAC_SHA_CTX *)vctx;
|
||||
PROV_CIPHER_HW_AES_HMAC_SHA *hw =
|
||||
(PROV_CIPHER_HW_AES_HMAC_SHA *)ctx->hw;
|
||||
EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
|
||||
const OSSL_PARAM *p, *p1, *pin;
|
||||
const OSSL_PARAM *p;
|
||||
int ret = 1;
|
||||
# if !defined(OPENSSL_NO_MULTIBLOCK)
|
||||
EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
|
||||
# endif
|
||||
|
||||
p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_AEAD_MAC_KEY);
|
||||
if (p != NULL) {
|
||||
@@ -101,8 +103,8 @@ static int aes_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
||||
*/
|
||||
p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_AAD);
|
||||
if (p != NULL) {
|
||||
p1 = OSSL_PARAM_locate_const(params,
|
||||
OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_INTERLEAVE);
|
||||
const OSSL_PARAM *p1 = OSSL_PARAM_locate_const(params,
|
||||
OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_INTERLEAVE);
|
||||
if (p->data_type != OSSL_PARAM_OCTET_STRING
|
||||
|| p1 == NULL
|
||||
|| !OSSL_PARAM_get_uint(p1, &mb_param.interleave)) {
|
||||
@@ -126,10 +128,11 @@ static int aes_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
||||
*/
|
||||
p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_ENC);
|
||||
if (p != NULL) {
|
||||
p1 = OSSL_PARAM_locate_const(params,
|
||||
OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_INTERLEAVE);
|
||||
pin = OSSL_PARAM_locate_const(params,
|
||||
OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_ENC_IN);
|
||||
const OSSL_PARAM *p1 = OSSL_PARAM_locate_const(params,
|
||||
OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_INTERLEAVE);
|
||||
const OSSL_PARAM *pin = OSSL_PARAM_locate_const(params,
|
||||
OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_ENC_IN);
|
||||
|
||||
if (p->data_type != OSSL_PARAM_OCTET_STRING
|
||||
|| pin == NULL
|
||||
|| pin->data_type != OSSL_PARAM_OCTET_STRING
|
||||
@@ -175,13 +178,13 @@ static int aes_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
||||
static int aes_get_ctx_params(void *vctx, OSSL_PARAM params[])
|
||||
{
|
||||
PROV_AES_HMAC_SHA_CTX *ctx = (PROV_AES_HMAC_SHA_CTX *)vctx;
|
||||
PROV_CIPHER_HW_AES_HMAC_SHA *hw =
|
||||
(PROV_CIPHER_HW_AES_HMAC_SHA *)ctx->hw;
|
||||
OSSL_PARAM *p;
|
||||
|
||||
# if !defined(OPENSSL_NO_MULTIBLOCK)
|
||||
p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_MAX_BUFSIZE);
|
||||
if (p != NULL) {
|
||||
PROV_CIPHER_HW_AES_HMAC_SHA *hw =
|
||||
(PROV_CIPHER_HW_AES_HMAC_SHA *)ctx->hw;
|
||||
size_t len = hw->tls1_multiblock_max_bufsize(ctx);
|
||||
|
||||
if (!OSSL_PARAM_set_size_t(p, len)) {
|
||||
@@ -280,7 +283,7 @@ static void aes_cbc_hmac_sha1_freectx(void *vctx)
|
||||
PROV_AES_HMAC_SHA1_CTX *ctx = (PROV_AES_HMAC_SHA1_CTX *)vctx;
|
||||
|
||||
if (ctx != NULL)
|
||||
OPENSSL_clear_free(ctx, sizeof(ctx));
|
||||
OPENSSL_clear_free(ctx, sizeof(*ctx));
|
||||
}
|
||||
|
||||
static void *aes_cbc_hmac_sha256_newctx(void *provctx, size_t kbits,
|
||||
@@ -301,7 +304,7 @@ static void aes_cbc_hmac_sha256_freectx(void *vctx)
|
||||
PROV_AES_HMAC_SHA256_CTX *ctx = (PROV_AES_HMAC_SHA256_CTX *)vctx;
|
||||
|
||||
if (ctx != NULL)
|
||||
OPENSSL_clear_free(ctx, sizeof(ctx));
|
||||
OPENSSL_clear_free(ctx, sizeof(*ctx));
|
||||
}
|
||||
|
||||
# define IMPLEMENT_CIPHER(nm, sub, kbits, blkbits, ivbits, flags) \
|
||||
|
||||
@@ -13,10 +13,6 @@
|
||||
int cipher_capable_aes_cbc_hmac_sha1(void);
|
||||
int cipher_capable_aes_cbc_hmac_sha256(void);
|
||||
|
||||
#ifdef AES_CBC_HMAC_SHA_CAPABLE
|
||||
# include <openssl/aes.h>
|
||||
# include <openssl/sha.h>
|
||||
|
||||
typedef struct prov_cipher_hw_aes_hmac_sha_ctx_st {
|
||||
PROV_CIPHER_HW base; /* must be first */
|
||||
void (*init_mac_key)(void *ctx, const unsigned char *inkey, size_t inlen);
|
||||
@@ -30,6 +26,13 @@ typedef struct prov_cipher_hw_aes_hmac_sha_ctx_st {
|
||||
# endif /* OPENSSL_NO_MULTIBLOCK) */
|
||||
} PROV_CIPHER_HW_AES_HMAC_SHA;
|
||||
|
||||
const PROV_CIPHER_HW_AES_HMAC_SHA *PROV_CIPHER_HW_aes_cbc_hmac_sha1(void);
|
||||
const PROV_CIPHER_HW_AES_HMAC_SHA *PROV_CIPHER_HW_aes_cbc_hmac_sha256(void);
|
||||
|
||||
#ifdef AES_CBC_HMAC_SHA_CAPABLE
|
||||
# include <openssl/aes.h>
|
||||
# include <openssl/sha.h>
|
||||
|
||||
typedef struct prov_aes_hmac_sha_ctx_st {
|
||||
PROV_CIPHER_CTX base;
|
||||
AES_KEY ks;
|
||||
@@ -59,7 +62,4 @@ typedef struct prov_aes_hmac_sha256_ctx_st {
|
||||
|
||||
# define NO_PAYLOAD_LENGTH ((size_t)-1)
|
||||
|
||||
const PROV_CIPHER_HW_AES_HMAC_SHA *PROV_CIPHER_HW_aes_cbc_hmac_sha1(void);
|
||||
const PROV_CIPHER_HW_AES_HMAC_SHA *PROV_CIPHER_HW_aes_cbc_hmac_sha256(void);
|
||||
|
||||
#endif /* AES_CBC_HMAC_SHA_CAPABLE */
|
||||
@@ -16,11 +16,16 @@
|
||||
|
||||
#include "cipher_aes_cbc_hmac_sha.h"
|
||||
|
||||
#ifndef AES_CBC_HMAC_SHA_CAPABLE
|
||||
#if !defined(AES_CBC_HMAC_SHA_CAPABLE) || !defined(AESNI_CAPABLE)
|
||||
int cipher_capable_aes_cbc_hmac_sha1(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const PROV_CIPHER_HW_AES_HMAC_SHA *PROV_CIPHER_HW_aes_cbc_hmac_sha1(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
|
||||
# include <openssl/rand.h>
|
||||
@@ -765,7 +770,7 @@ static int aesni_cbc_hmac_sha1_tls1_multiblock_encrypt(
|
||||
param->interleave / 4);
|
||||
}
|
||||
|
||||
#endif /* OPENSSL_NO_MULTIBLOCK */
|
||||
# endif /* OPENSSL_NO_MULTIBLOCK */
|
||||
|
||||
static const PROV_CIPHER_HW_AES_HMAC_SHA cipher_hw_aes_hmac_sha1 = {
|
||||
{
|
||||
@@ -786,4 +791,4 @@ const PROV_CIPHER_HW_AES_HMAC_SHA *PROV_CIPHER_HW_aes_cbc_hmac_sha1(void)
|
||||
return &cipher_hw_aes_hmac_sha1;
|
||||
}
|
||||
|
||||
#endif /* AES_CBC_HMAC_SHA_CAPABLE */
|
||||
#endif /* !defined(AES_CBC_HMAC_SHA_CAPABLE) || !defined(AESNI_CAPABLE) */
|
||||
@@ -16,11 +16,16 @@
|
||||
|
||||
#include "cipher_aes_cbc_hmac_sha.h"
|
||||
|
||||
#ifndef AES_CBC_HMAC_SHA_CAPABLE
|
||||
#if !defined(AES_CBC_HMAC_SHA_CAPABLE) || !defined(AESNI_CAPABLE)
|
||||
int cipher_capable_aes_cbc_hmac_sha256(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const PROV_CIPHER_HW_AES_HMAC_SHA *PROV_CIPHER_HW_aes_cbc_hmac_sha256(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
|
||||
# include <openssl/rand.h>
|
||||
@@ -814,7 +819,7 @@ static int aesni_cbc_hmac_sha256_tls1_multiblock_encrypt(
|
||||
param->inp, param->len,
|
||||
param->interleave / 4);
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
|
||||
static const PROV_CIPHER_HW_AES_HMAC_SHA cipher_hw_aes_hmac_sha256 = {
|
||||
{
|
||||
@@ -835,4 +840,4 @@ const PROV_CIPHER_HW_AES_HMAC_SHA *PROV_CIPHER_HW_aes_cbc_hmac_sha256(void)
|
||||
return &cipher_hw_aes_hmac_sha256;
|
||||
}
|
||||
|
||||
#endif /* AES_CBC_HMAC_SHA_CAPABLE */
|
||||
#endif /* !defined(AES_CBC_HMAC_SHA_CAPABLE) || !defined(AESNI_CAPABLE) */
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* DES low level APIs are deprecated for public use, but still ok for internal
|
||||
* use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include "prov/ciphercommon.h"
|
||||
#include "cipher_des.h"
|
||||
#include <openssl/rand.h>
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* DES low level APIs are deprecated for public use, but still ok for internal
|
||||
* use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include "prov/ciphercommon.h"
|
||||
#include "cipher_des.h"
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* DES low level APIs are deprecated for public use, but still ok for internal
|
||||
* use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include "cipher_tdes_default.h"
|
||||
#include "prov/implementations.h"
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* DES low level APIs are deprecated for public use, but still ok for internal
|
||||
* use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <openssl/des.h>
|
||||
#include "cipher_tdes_default.h"
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* DES low level APIs are deprecated for public use, but still ok for internal
|
||||
* use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include "prov/ciphercommon.h"
|
||||
#include "cipher_tdes.h"
|
||||
#include <openssl/rand.h>
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* DES low level APIs are deprecated for public use, but still ok for internal
|
||||
* use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include "cipher_tdes_default.h"
|
||||
#include "prov/implementations.h"
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* DES low level APIs are deprecated for public use, but still ok for internal
|
||||
* use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include "cipher_tdes_default.h"
|
||||
|
||||
#define ks1 tks.ks[0]
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* DES low level APIs are deprecated for public use, but still ok for internal
|
||||
* use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include "prov/ciphercommon.h"
|
||||
#include "cipher_tdes.h"
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* SHA-1 low level APIs are deprecated for public use, but still ok for
|
||||
* DES and SHA-1 low level APIs are deprecated for public use, but still ok for
|
||||
* internal use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* DES low level APIs are deprecated for public use, but still ok for internal
|
||||
* use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include "cipher_tdes_default.h"
|
||||
|
||||
#define cipher_hw_tdes_wrap_initkey cipher_hw_tdes_ede3_initkey
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include <openssl/dh.h>
|
||||
#include <openssl/params.h>
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "crypto/dh.h"
|
||||
|
||||
static OSSL_OP_keyexch_newctx_fn dh_newctx;
|
||||
static OSSL_OP_keyexch_init_fn dh_init;
|
||||
@@ -30,6 +32,7 @@ static OSSL_OP_keyexch_settable_ctx_params_fn dh_settable_ctx_params;
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
OPENSSL_CTX *libctx;
|
||||
DH *dh;
|
||||
DH *dhpeer;
|
||||
unsigned int pad : 1;
|
||||
@@ -37,7 +40,12 @@ typedef struct {
|
||||
|
||||
static void *dh_newctx(void *provctx)
|
||||
{
|
||||
return OPENSSL_zalloc(sizeof(PROV_DH_CTX));
|
||||
PROV_DH_CTX *pdhctx = OPENSSL_zalloc(sizeof(PROV_DH_CTX));
|
||||
|
||||
if (pdhctx == NULL)
|
||||
return NULL;
|
||||
pdhctx->libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
|
||||
return pdhctx;
|
||||
}
|
||||
|
||||
static int dh_init(void *vpdhctx, void *vdh)
|
||||
@@ -83,8 +91,10 @@ static int dh_derive(void *vpdhctx, unsigned char *secret, size_t *secretlen,
|
||||
return 0;
|
||||
|
||||
DH_get0_key(pdhctx->dhpeer, &pub_key, NULL);
|
||||
ret = (pdhctx->pad) ? DH_compute_key_padded(secret, pub_key, pdhctx->dh)
|
||||
: DH_compute_key(secret, pub_key, pdhctx->dh);
|
||||
if (pdhctx->pad)
|
||||
ret = dh_compute_key_padded(pdhctx->libctx, secret, pub_key, pdhctx->dh);
|
||||
else
|
||||
ret = dh_compute_key(pdhctx->libctx, secret, pub_key, pdhctx->dh);
|
||||
if (ret <= 0)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* HMAC low level APIs are deprecated for public use, but still ok for internal
|
||||
* use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* DES low level APIs are deprecated for public use, but still ok for internal
|
||||
* use. We access the DES_set_odd_parity(3) function here.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* HMAC low level APIs are deprecated for public use, but still ok for internal
|
||||
* use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -75,7 +75,7 @@ static void kdf_scrypt_free(void *vctx)
|
||||
KDF_SCRYPT *ctx = (KDF_SCRYPT *)vctx;
|
||||
|
||||
if (ctx != NULL) {
|
||||
EVP_MD_meth_free(ctx->sha256);
|
||||
EVP_MD_free(ctx->sha256);
|
||||
kdf_scrypt_reset(ctx);
|
||||
OPENSSL_free(ctx);
|
||||
}
|
||||
|
||||
@@ -13,15 +13,22 @@
|
||||
#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"
|
||||
|
||||
static OSSL_OP_keymgmt_importdomparams_fn dh_importdomparams;
|
||||
static OSSL_OP_keymgmt_exportdomparams_fn dh_exportdomparams;
|
||||
static OSSL_OP_keymgmt_get_key_params_fn dh_get_domparam_params;
|
||||
static OSSL_OP_keymgmt_importkey_fn dh_importkey;
|
||||
static OSSL_OP_keymgmt_exportkey_fn dh_exportkey;
|
||||
static OSSL_OP_keymgmt_get_key_params_fn dh_get_key_params;
|
||||
static OSSL_OP_keymgmt_new_fn dh_newdata;
|
||||
static OSSL_OP_keymgmt_free_fn dh_freedata;
|
||||
static OSSL_OP_keymgmt_get_params_fn dh_get_params;
|
||||
static OSSL_OP_keymgmt_gettable_params_fn dh_gettable_params;
|
||||
static OSSL_OP_keymgmt_has_fn dh_has;
|
||||
static OSSL_OP_keymgmt_import_fn dh_import;
|
||||
static OSSL_OP_keymgmt_import_types_fn dh_import_types;
|
||||
static OSSL_OP_keymgmt_export_fn dh_export;
|
||||
static OSSL_OP_keymgmt_export_types_fn dh_export_types;
|
||||
|
||||
#define DH_POSSIBLE_SELECTIONS \
|
||||
(OSSL_KEYMGMT_SELECT_KEYPAIR | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS)
|
||||
|
||||
static int params_to_domparams(DH *dh, const OSSL_PARAM params[])
|
||||
{
|
||||
@@ -128,70 +135,132 @@ static int key_to_params(DH *dh, OSSL_PARAM_BLD *tmpl)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void *dh_importdomparams(void *provctx, const OSSL_PARAM params[])
|
||||
static void *dh_newdata(void *provctx)
|
||||
{
|
||||
DH *dh;
|
||||
|
||||
if ((dh = DH_new()) == NULL
|
||||
|| !params_to_domparams(dh, params)) {
|
||||
DH_free(dh);
|
||||
dh = NULL;
|
||||
}
|
||||
return dh;
|
||||
return DH_new();
|
||||
}
|
||||
|
||||
static int dh_exportdomparams(void *domparams, OSSL_CALLBACK *param_cb,
|
||||
void *cbarg)
|
||||
static void dh_freedata(void *keydata)
|
||||
{
|
||||
DH *dh = domparams;
|
||||
DH_free(keydata);
|
||||
}
|
||||
|
||||
static int dh_has(void *keydata, int selection)
|
||||
{
|
||||
DH *dh = keydata;
|
||||
int ok = 0;
|
||||
|
||||
if ((selection & DH_POSSIBLE_SELECTIONS) != 0)
|
||||
ok = 1;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
|
||||
ok = ok && (DH_get0_pub_key(dh) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
|
||||
ok = ok && (DH_get0_priv_key(dh) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0)
|
||||
ok = ok && (DH_get0_p(dh) != NULL && DH_get0_g(dh) != NULL);
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dh_import(void *keydata, int selection, const OSSL_PARAM params[])
|
||||
{
|
||||
DH *dh = keydata;
|
||||
int ok = 0;
|
||||
|
||||
if (dh == NULL)
|
||||
return 0;
|
||||
|
||||
if ((selection & DH_POSSIBLE_SELECTIONS) != 0)
|
||||
ok = 1;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0)
|
||||
ok = ok && params_to_domparams(dh, params);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ok = ok && params_to_key(dh, params);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dh_export(void *keydata, int selection, OSSL_CALLBACK *param_cb,
|
||||
void *cbarg)
|
||||
{
|
||||
DH *dh = keydata;
|
||||
OSSL_PARAM_BLD tmpl;
|
||||
OSSL_PARAM *params = NULL;
|
||||
int ret;
|
||||
int ok = 1;
|
||||
|
||||
if (dh == NULL)
|
||||
return 0;
|
||||
|
||||
ossl_param_bld_init(&tmpl);
|
||||
if (dh == NULL
|
||||
|| !domparams_to_params(dh, &tmpl)
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0)
|
||||
ok = ok && domparams_to_params(dh, &tmpl);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ok = ok && key_to_params(dh, &tmpl);
|
||||
|
||||
if (!ok
|
||||
|| (params = ossl_param_bld_to_param(&tmpl)) == NULL)
|
||||
return 0;
|
||||
ret = param_cb(params, cbarg);
|
||||
|
||||
ok = param_cb(params, cbarg);
|
||||
ossl_param_bld_free(params);
|
||||
return ret;
|
||||
return ok;
|
||||
}
|
||||
|
||||
static void *dh_importkey(void *provctx, const OSSL_PARAM params[])
|
||||
/* IMEXPORT = IMPORT + EXPORT */
|
||||
|
||||
# define DH_IMEXPORTABLE_PARAMETERS \
|
||||
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)
|
||||
# define DH_IMEXPORTABLE_PRIVATE_KEY \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_DH_PRIV_KEY, NULL, 0)
|
||||
static const OSSL_PARAM dh_all_types[] = {
|
||||
DH_IMEXPORTABLE_PARAMETERS,
|
||||
DH_IMEXPORTABLE_PUBLIC_KEY,
|
||||
DH_IMEXPORTABLE_PRIVATE_KEY,
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
static const OSSL_PARAM dh_parameter_types[] = {
|
||||
DH_IMEXPORTABLE_PARAMETERS,
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
static const OSSL_PARAM dh_key_types[] = {
|
||||
DH_IMEXPORTABLE_PUBLIC_KEY,
|
||||
DH_IMEXPORTABLE_PRIVATE_KEY,
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
static const OSSL_PARAM *dh_types[] = {
|
||||
NULL, /* Index 0 = none of them */
|
||||
dh_parameter_types, /* Index 1 = parameter types */
|
||||
dh_key_types, /* Index 2 = key types */
|
||||
dh_all_types /* Index 3 = 1 + 2 */
|
||||
};
|
||||
|
||||
static const OSSL_PARAM *dh_imexport_types(int selection)
|
||||
{
|
||||
DH *dh;
|
||||
int type_select = 0;
|
||||
|
||||
if ((dh = DH_new()) == NULL
|
||||
|| !params_to_key(dh, params)) {
|
||||
DH_free(dh);
|
||||
dh = NULL;
|
||||
}
|
||||
return dh;
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0)
|
||||
type_select += 1;
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
type_select += 2;
|
||||
return dh_types[type_select];
|
||||
}
|
||||
|
||||
static int dh_exportkey(void *key, OSSL_CALLBACK *param_cb, void *cbarg)
|
||||
static const OSSL_PARAM *dh_import_types(int selection)
|
||||
{
|
||||
DH *dh = key;
|
||||
OSSL_PARAM_BLD tmpl;
|
||||
OSSL_PARAM *params = NULL;
|
||||
int ret;
|
||||
|
||||
ossl_param_bld_init(&tmpl);
|
||||
if (dh == NULL
|
||||
|| !key_to_params(dh, &tmpl)
|
||||
|| (params = ossl_param_bld_to_param(&tmpl)) == NULL)
|
||||
return 0;
|
||||
ret = param_cb(params, cbarg);
|
||||
ossl_param_bld_free(params);
|
||||
return ret;
|
||||
return dh_imexport_types(selection);
|
||||
}
|
||||
|
||||
/*
|
||||
* Same function for domain parameters and for keys.
|
||||
* "dpk" = "domain parameters & keys"
|
||||
*/
|
||||
static ossl_inline int dh_get_dpk_params(void *key, OSSL_PARAM params[])
|
||||
static const OSSL_PARAM *dh_export_types(int selection)
|
||||
{
|
||||
return dh_imexport_types(selection);
|
||||
}
|
||||
|
||||
static ossl_inline int dh_get_params(void *key, OSSL_PARAM params[])
|
||||
{
|
||||
DH *dh = key;
|
||||
OSSL_PARAM *p;
|
||||
@@ -208,33 +277,27 @@ static ossl_inline int dh_get_dpk_params(void *key, OSSL_PARAM params[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* We have wrapper functions to make sure we get signatures right, see
|
||||
* the forward declarations at the beginning of this file.
|
||||
*/
|
||||
static int dh_get_domparam_params(void *domparams, OSSL_PARAM params[])
|
||||
{
|
||||
return dh_get_dpk_params(domparams, params);
|
||||
}
|
||||
static const OSSL_PARAM dh_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 int dh_get_key_params(void *key, OSSL_PARAM params[])
|
||||
static const OSSL_PARAM *dh_gettable_params(void)
|
||||
{
|
||||
return dh_get_dpk_params(key, params);
|
||||
return dh_params;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH dh_keymgmt_functions[] = {
|
||||
/*
|
||||
* TODO(3.0) When implementing OSSL_FUNC_KEYMGMT_GENKEY, remember to also
|
||||
* implement OSSL_FUNC_KEYMGMT_EXPORTKEY.
|
||||
*/
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORTDOMPARAMS, (void (*)(void))dh_importdomparams },
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORTDOMPARAMS, (void (*)(void))dh_exportdomparams },
|
||||
{ OSSL_FUNC_KEYMGMT_GET_DOMPARAM_PARAMS,
|
||||
(void (*) (void))dh_get_domparam_params },
|
||||
{ OSSL_FUNC_KEYMGMT_FREEDOMPARAMS, (void (*)(void))DH_free },
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORTKEY, (void (*)(void))dh_importkey },
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORTKEY, (void (*)(void))dh_exportkey },
|
||||
{ OSSL_FUNC_KEYMGMT_FREEKEY, (void (*)(void))DH_free },
|
||||
{ OSSL_FUNC_KEYMGMT_GET_KEY_PARAMS, (void (*) (void))dh_get_key_params },
|
||||
{ OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))dh_newdata },
|
||||
{ OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))dh_freedata },
|
||||
{ OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*) (void))dh_get_params },
|
||||
{ OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*) (void))dh_gettable_params },
|
||||
{ OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))dh_has },
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))dh_import },
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))dh_import_types },
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))dh_export },
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORT_TYPES, (void (*)(void))dh_export_types },
|
||||
{ 0, NULL }
|
||||
};
|
||||
@@ -12,17 +12,25 @@
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/params.h>
|
||||
#include "internal/param_build.h"
|
||||
#include "crypto/dsa.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/providercommon.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "crypto/dsa.h"
|
||||
|
||||
static OSSL_OP_keymgmt_importdomparams_fn dsa_importdomparams;
|
||||
static OSSL_OP_keymgmt_exportdomparams_fn dsa_exportdomparams;
|
||||
static OSSL_OP_keymgmt_get_domparam_params_fn dsa_get_domparam_params;
|
||||
static OSSL_OP_keymgmt_importkey_fn dsa_importkey;
|
||||
static OSSL_OP_keymgmt_exportkey_fn dsa_exportkey;
|
||||
static OSSL_OP_keymgmt_get_key_params_fn dsa_get_key_params;
|
||||
static OSSL_OP_keymgmt_new_fn dsa_newdata;
|
||||
static OSSL_OP_keymgmt_free_fn dsa_freedata;
|
||||
static OSSL_OP_keymgmt_get_params_fn dsa_get_params;
|
||||
static OSSL_OP_keymgmt_gettable_params_fn dsa_gettable_params;
|
||||
static OSSL_OP_keymgmt_has_fn dsa_has;
|
||||
static OSSL_OP_keymgmt_import_fn dsa_import;
|
||||
static OSSL_OP_keymgmt_import_types_fn dsa_import_types;
|
||||
static OSSL_OP_keymgmt_export_fn dsa_export;
|
||||
static OSSL_OP_keymgmt_export_types_fn dsa_export_types;
|
||||
|
||||
#define DSA_DEFAULT_MD "SHA256"
|
||||
#define DSA_POSSIBLE_SELECTIONS \
|
||||
(OSSL_KEYMGMT_SELECT_KEYPAIR | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS)
|
||||
|
||||
static int params_to_domparams(DSA *dsa, const OSSL_PARAM params[])
|
||||
{
|
||||
@@ -134,70 +142,133 @@ static int key_to_params(DSA *dsa, OSSL_PARAM_BLD *tmpl)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void *dsa_importdomparams(void *provctx, const OSSL_PARAM params[])
|
||||
static void *dsa_newdata(void *provctx)
|
||||
{
|
||||
DSA *dsa;
|
||||
|
||||
if ((dsa = DSA_new()) == NULL
|
||||
|| !params_to_domparams(dsa, params)) {
|
||||
DSA_free(dsa);
|
||||
dsa = NULL;
|
||||
}
|
||||
return dsa;
|
||||
return DSA_new();
|
||||
}
|
||||
|
||||
static int dsa_exportdomparams(void *domparams,
|
||||
OSSL_CALLBACK *param_cb, void *cbarg)
|
||||
static void dsa_freedata(void *keydata)
|
||||
{
|
||||
DSA *dsa = domparams;
|
||||
DSA_free(keydata);
|
||||
}
|
||||
|
||||
static int dsa_has(void *keydata, int selection)
|
||||
{
|
||||
DSA *dsa = keydata;
|
||||
int ok = 0;
|
||||
|
||||
if ((selection & DSA_POSSIBLE_SELECTIONS) != 0)
|
||||
ok = 1;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
|
||||
ok = ok && (DSA_get0_pub_key(dsa) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
|
||||
ok = ok && (DSA_get0_priv_key(dsa) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0)
|
||||
ok = ok && (DSA_get0_p(dsa) != NULL && DSA_get0_g(dsa) != NULL);
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_import(void *keydata, int selection, const OSSL_PARAM params[])
|
||||
{
|
||||
DSA *dsa = keydata;
|
||||
int ok = 0;
|
||||
|
||||
if (dsa == NULL)
|
||||
return 0;
|
||||
|
||||
if ((selection & DSA_POSSIBLE_SELECTIONS) != 0)
|
||||
ok = 1;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0)
|
||||
ok = ok && params_to_domparams(dsa, params);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ok = ok && params_to_key(dsa, params);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_export(void *keydata, int selection, OSSL_CALLBACK *param_cb,
|
||||
void *cbarg)
|
||||
{
|
||||
DSA *dsa = keydata;
|
||||
OSSL_PARAM_BLD tmpl;
|
||||
OSSL_PARAM *params = NULL;
|
||||
int ret;
|
||||
int ok = 1;
|
||||
|
||||
if (dsa == NULL)
|
||||
return 0;
|
||||
|
||||
ossl_param_bld_init(&tmpl);
|
||||
if (dsa == NULL
|
||||
|| !domparams_to_params(dsa, &tmpl)
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0)
|
||||
ok = ok && domparams_to_params(dsa, &tmpl);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ok = ok && key_to_params(dsa, &tmpl);
|
||||
|
||||
if (!ok
|
||||
|| (params = ossl_param_bld_to_param(&tmpl)) == NULL)
|
||||
return 0;
|
||||
ret = param_cb(params, cbarg);
|
||||
|
||||
ok = param_cb(params, cbarg);
|
||||
ossl_param_bld_free(params);
|
||||
return ret;
|
||||
return ok;
|
||||
}
|
||||
|
||||
static void *dsa_importkey(void *provctx, const OSSL_PARAM params[])
|
||||
/* IMEXPORT = IMPORT + EXPORT */
|
||||
|
||||
# define DSA_IMEXPORTABLE_PARAMETERS \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_FFC_P, NULL, 0), \
|
||||
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)
|
||||
# define DSA_IMEXPORTABLE_PRIVATE_KEY \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_DSA_PRIV_KEY, NULL, 0)
|
||||
static const OSSL_PARAM dsa_all_types[] = {
|
||||
DSA_IMEXPORTABLE_PARAMETERS,
|
||||
DSA_IMEXPORTABLE_PUBLIC_KEY,
|
||||
DSA_IMEXPORTABLE_PRIVATE_KEY,
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
static const OSSL_PARAM dsa_parameter_types[] = {
|
||||
DSA_IMEXPORTABLE_PARAMETERS,
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
static const OSSL_PARAM dsa_key_types[] = {
|
||||
DSA_IMEXPORTABLE_PUBLIC_KEY,
|
||||
DSA_IMEXPORTABLE_PRIVATE_KEY,
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
static const OSSL_PARAM *dsa_types[] = {
|
||||
NULL, /* Index 0 = none of them */
|
||||
dsa_parameter_types, /* Index 1 = parameter types */
|
||||
dsa_key_types, /* Index 2 = key types */
|
||||
dsa_all_types /* Index 3 = 1 + 2 */
|
||||
};
|
||||
|
||||
static const OSSL_PARAM *dsa_imexport_types(int selection)
|
||||
{
|
||||
DSA *dsa;
|
||||
int type_select = 0;
|
||||
|
||||
if ((dsa = DSA_new()) == NULL
|
||||
|| !params_to_key(dsa, params)) {
|
||||
DSA_free(dsa);
|
||||
dsa = NULL;
|
||||
}
|
||||
return dsa;
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0)
|
||||
type_select += 1;
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
type_select += 2;
|
||||
return dsa_types[type_select];
|
||||
}
|
||||
|
||||
static int dsa_exportkey(void *key, OSSL_CALLBACK *param_cb, void *cbarg)
|
||||
static const OSSL_PARAM *dsa_import_types(int selection)
|
||||
{
|
||||
DSA *dsa = key;
|
||||
OSSL_PARAM_BLD tmpl;
|
||||
OSSL_PARAM *params = NULL;
|
||||
int ret;
|
||||
|
||||
ossl_param_bld_init(&tmpl);
|
||||
if (dsa == NULL
|
||||
|| !key_to_params(dsa, &tmpl)
|
||||
|| (params = ossl_param_bld_to_param(&tmpl)) == NULL)
|
||||
return 0;
|
||||
ret = param_cb(params, cbarg);
|
||||
ossl_param_bld_free(params);
|
||||
return ret;
|
||||
return dsa_imexport_types(selection);
|
||||
}
|
||||
|
||||
/*
|
||||
* Same function for domain parameters and for keys.
|
||||
* "dpk" = "domain parameters & keys"
|
||||
*/
|
||||
static ossl_inline int dsa_get_dpk_params(void *key, OSSL_PARAM params[])
|
||||
static const OSSL_PARAM *dsa_export_types(int selection)
|
||||
{
|
||||
return dsa_imexport_types(selection);
|
||||
}
|
||||
|
||||
static ossl_inline int dsa_get_params(void *key, OSSL_PARAM params[])
|
||||
{
|
||||
DSA *dsa = key;
|
||||
OSSL_PARAM *p;
|
||||
@@ -211,32 +282,34 @@ static ossl_inline int dsa_get_dpk_params(void *key, OSSL_PARAM params[])
|
||||
if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_MAX_SIZE)) != NULL
|
||||
&& !OSSL_PARAM_set_int(p, DSA_size(dsa)))
|
||||
return 0;
|
||||
if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_DEFAULT_DIGEST)) != NULL
|
||||
&& !OSSL_PARAM_set_utf8_string(p, DSA_DEFAULT_MD))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* We have wrapper functions to make sure we get signatures right, see
|
||||
* the forward declarations at the beginning of this file.
|
||||
*/
|
||||
static int dsa_get_domparam_params(void *domparams, OSSL_PARAM params[])
|
||||
{
|
||||
return dsa_get_dpk_params(domparams, params);
|
||||
}
|
||||
static const OSSL_PARAM dsa_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_utf8_string(OSSL_PKEY_PARAM_DEFAULT_DIGEST, NULL, 0),
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
|
||||
static int dsa_get_key_params(void *key, OSSL_PARAM params[])
|
||||
static const OSSL_PARAM *dsa_gettable_params(void)
|
||||
{
|
||||
return dsa_get_dpk_params(key, params);
|
||||
return dsa_params;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH dsa_keymgmt_functions[] = {
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORTDOMPARAMS, (void (*)(void))dsa_importdomparams },
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORTDOMPARAMS, (void (*)(void))dsa_exportdomparams },
|
||||
{ OSSL_FUNC_KEYMGMT_FREEDOMPARAMS, (void (*)(void))DSA_free },
|
||||
{ OSSL_FUNC_KEYMGMT_GET_DOMPARAM_PARAMS,
|
||||
(void (*) (void))dsa_get_domparam_params },
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORTKEY, (void (*)(void))dsa_importkey },
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORTKEY, (void (*)(void))dsa_exportkey },
|
||||
{ OSSL_FUNC_KEYMGMT_FREEKEY, (void (*)(void))DSA_free },
|
||||
{ OSSL_FUNC_KEYMGMT_GET_KEY_PARAMS, (void (*) (void))dsa_get_key_params },
|
||||
{ OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))dsa_newdata },
|
||||
{ OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))dsa_freedata },
|
||||
{ OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*) (void))dsa_get_params },
|
||||
{ OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*) (void))dsa_gettable_params },
|
||||
{ OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))dsa_has },
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))dsa_import },
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))dsa_import_types },
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))dsa_export },
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORT_TYPES, (void (*)(void))dsa_export_types },
|
||||
{ 0, NULL }
|
||||
};
|
||||
@@ -10,7 +10,9 @@
|
||||
#include <openssl/core_numbers.h>
|
||||
#include <openssl/core_names.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/params.h>
|
||||
#include <openssl/types.h>
|
||||
#include "internal/param_build.h"
|
||||
@@ -18,9 +20,20 @@
|
||||
#include "prov/providercommon.h"
|
||||
#include "crypto/rsa.h"
|
||||
|
||||
static OSSL_OP_keymgmt_importkey_fn rsa_importkey;
|
||||
static OSSL_OP_keymgmt_exportkey_fn rsa_exportkey;
|
||||
static OSSL_OP_keymgmt_get_key_params_fn rsa_get_key_params;
|
||||
static OSSL_OP_keymgmt_new_fn rsa_newdata;
|
||||
static OSSL_OP_keymgmt_free_fn rsa_freedata;
|
||||
static OSSL_OP_keymgmt_get_params_fn rsa_get_params;
|
||||
static OSSL_OP_keymgmt_gettable_params_fn rsa_gettable_params;
|
||||
static OSSL_OP_keymgmt_has_fn rsa_has;
|
||||
static OSSL_OP_keymgmt_validate_fn rsa_validate;
|
||||
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;
|
||||
|
||||
#define RSA_DEFAULT_MD "SHA256"
|
||||
#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)
|
||||
@@ -155,33 +168,73 @@ static int key_to_params(RSA *rsa, OSSL_PARAM_BLD *tmpl)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void *rsa_importkey(void *provctx, const OSSL_PARAM params[])
|
||||
static void *rsa_newdata(void *provctx)
|
||||
{
|
||||
RSA *rsa;
|
||||
|
||||
if ((rsa = RSA_new()) == NULL
|
||||
|| !params_to_key(rsa, params)) {
|
||||
RSA_free(rsa);
|
||||
rsa = NULL;
|
||||
}
|
||||
return rsa;
|
||||
return RSA_new();
|
||||
}
|
||||
|
||||
static int rsa_exportkey(void *key, OSSL_CALLBACK *param_callback, void *cbarg)
|
||||
static void rsa_freedata(void *keydata)
|
||||
{
|
||||
RSA *rsa = key;
|
||||
RSA_free(keydata);
|
||||
}
|
||||
|
||||
static int rsa_has(void *keydata, int selection)
|
||||
{
|
||||
RSA *rsa = keydata;
|
||||
int ok = 0;
|
||||
|
||||
if ((selection & RSA_POSSIBLE_SELECTIONS) != 0)
|
||||
ok = 1;
|
||||
|
||||
ok = ok && (RSA_get0_e(rsa) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
|
||||
ok = ok && (RSA_get0_n(rsa) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
|
||||
ok = ok && (RSA_get0_d(rsa) != NULL);
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int rsa_import(void *keydata, int selection, const OSSL_PARAM params[])
|
||||
{
|
||||
RSA *rsa = keydata;
|
||||
int ok = 1;
|
||||
|
||||
if (rsa == NULL)
|
||||
return 0;
|
||||
|
||||
/* TODO(3.0) PSS and OAEP should bring on parameters */
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ok = ok && params_to_key(rsa, params);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int rsa_export(void *keydata, int selection,
|
||||
OSSL_CALLBACK *param_callback, void *cbarg)
|
||||
{
|
||||
RSA *rsa = keydata;
|
||||
OSSL_PARAM_BLD tmpl;
|
||||
OSSL_PARAM *params = NULL;
|
||||
int ret;
|
||||
int ok = 1;
|
||||
|
||||
if (rsa == NULL)
|
||||
return 0;
|
||||
|
||||
/* TODO(3.0) PSS and OAEP should bring on parameters */
|
||||
|
||||
ossl_param_bld_init(&tmpl);
|
||||
if (rsa == NULL
|
||||
|| !key_to_params(rsa, &tmpl)
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ok = ok && key_to_params(rsa, &tmpl);
|
||||
|
||||
if (!ok
|
||||
|| (params = ossl_param_bld_to_param(&tmpl)) == NULL)
|
||||
return 0;
|
||||
ret = param_callback(params, cbarg);
|
||||
|
||||
ok = param_callback(params, cbarg);
|
||||
ossl_param_bld_free(params);
|
||||
return ret;
|
||||
return ok;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -235,17 +288,25 @@ static const OSSL_PARAM rsa_key_types[] = {
|
||||
* so we at least pretend to have some limits.
|
||||
*/
|
||||
|
||||
static const OSSL_PARAM *rsa_exportkey_types(void)
|
||||
static const OSSL_PARAM *rsa_imexport_types(int selection)
|
||||
{
|
||||
return rsa_key_types;
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
return rsa_key_types;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const OSSL_PARAM *rsa_importkey_types(void)
|
||||
static const OSSL_PARAM *rsa_import_types(int selection)
|
||||
{
|
||||
return rsa_key_types;
|
||||
return rsa_imexport_types(selection);
|
||||
}
|
||||
|
||||
static int rsa_get_key_params(void *key, OSSL_PARAM params[])
|
||||
|
||||
static const OSSL_PARAM *rsa_export_types(int selection)
|
||||
{
|
||||
return rsa_imexport_types(selection);
|
||||
}
|
||||
|
||||
static int rsa_get_params(void *key, OSSL_PARAM params[])
|
||||
{
|
||||
RSA *rsa = key;
|
||||
OSSL_PARAM *p;
|
||||
@@ -259,15 +320,75 @@ static int rsa_get_key_params(void *key, OSSL_PARAM params[])
|
||||
if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_MAX_SIZE)) != NULL
|
||||
&& !OSSL_PARAM_set_int(p, RSA_size(rsa)))
|
||||
return 0;
|
||||
|
||||
# if 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
|
||||
if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_DEFAULT_DIGEST)) != NULL
|
||||
&& RSA_get0_pss_params(rsa) == NULL)
|
||||
if (!OSSL_PARAM_set_utf8_string(p, RSA_DEFAULT_MD))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const OSSL_PARAM rsa_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_utf8_string(OSSL_PKEY_PARAM_DEFAULT_DIGEST, NULL, 0),
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
|
||||
static const OSSL_PARAM *rsa_gettable_params(void)
|
||||
{
|
||||
return rsa_params;
|
||||
}
|
||||
|
||||
static int rsa_validate(void *keydata, int selection)
|
||||
{
|
||||
RSA *rsa = keydata;
|
||||
int ok = 0;
|
||||
|
||||
if ((selection & RSA_POSSIBLE_SELECTIONS) != 0)
|
||||
ok = 1;
|
||||
|
||||
/* If the whole key is selected, we do a pairwise validation */
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR)
|
||||
== OSSL_KEYMGMT_SELECT_KEYPAIR) {
|
||||
ok = ok && rsa_validate_pairwise(rsa);
|
||||
} else {
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
|
||||
ok = ok && rsa_validate_private(rsa);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
|
||||
ok = ok && rsa_validate_public(rsa);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH rsa_keymgmt_functions[] = {
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORTKEY, (void (*)(void))rsa_importkey },
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORTKEY_TYPES, (void (*)(void))rsa_importkey_types },
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORTKEY, (void (*)(void))rsa_exportkey },
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORTKEY_TYPES, (void (*)(void))rsa_exportkey_types },
|
||||
{ OSSL_FUNC_KEYMGMT_FREEKEY, (void (*)(void))RSA_free },
|
||||
{ OSSL_FUNC_KEYMGMT_GET_KEY_PARAMS, (void (*) (void))rsa_get_key_params },
|
||||
{ OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))rsa_newdata },
|
||||
{ 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 },
|
||||
{ 0, NULL }
|
||||
};
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* CMAC 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/params.h>
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* HMAC 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/params.h>
|
||||
|
||||
@@ -112,12 +112,32 @@ static X509_PUBKEY *ossl_prov_pubkey_from_obj(const void *obj, int obj_nid,
|
||||
return xpk;
|
||||
}
|
||||
|
||||
OSSL_OP_keymgmt_importkey_fn *ossl_prov_get_importkey(const OSSL_DISPATCH *fns)
|
||||
OSSL_OP_keymgmt_new_fn *ossl_prov_get_keymgmt_new(const OSSL_DISPATCH *fns)
|
||||
{
|
||||
/* Pilfer the keymgmt dispatch table */
|
||||
for (; fns->function_id != 0; fns++)
|
||||
if (fns->function_id == OSSL_FUNC_KEYMGMT_IMPORTKEY)
|
||||
return OSSL_get_OP_keymgmt_importkey(fns);
|
||||
if (fns->function_id == OSSL_FUNC_KEYMGMT_NEW)
|
||||
return OSSL_get_OP_keymgmt_new(fns);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OSSL_OP_keymgmt_free_fn *ossl_prov_get_keymgmt_free(const OSSL_DISPATCH *fns)
|
||||
{
|
||||
/* Pilfer the keymgmt dispatch table */
|
||||
for (; fns->function_id != 0; fns++)
|
||||
if (fns->function_id == OSSL_FUNC_KEYMGMT_FREE)
|
||||
return OSSL_get_OP_keymgmt_free(fns);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OSSL_OP_keymgmt_import_fn *ossl_prov_get_keymgmt_import(const OSSL_DISPATCH *fns)
|
||||
{
|
||||
/* Pilfer the keymgmt dispatch table */
|
||||
for (; fns->function_id != 0; fns++)
|
||||
if (fns->function_id == OSSL_FUNC_KEYMGMT_IMPORT)
|
||||
return OSSL_get_OP_keymgmt_import(fns);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -138,29 +158,29 @@ OSSL_OP_keymgmt_importkey_fn *ossl_prov_get_importkey(const OSSL_DISPATCH *fns)
|
||||
# endif
|
||||
|
||||
int ossl_prov_print_labeled_bignum(BIO *out, const char *label,
|
||||
const BIGNUM *n)
|
||||
const BIGNUM *bn)
|
||||
{
|
||||
const char *neg;
|
||||
const char *post_label_spc = " ";
|
||||
int bytes;
|
||||
BN_ULONG *words;
|
||||
int i, off;
|
||||
int n, i;
|
||||
|
||||
if (n == NULL)
|
||||
if (bn == NULL)
|
||||
return 0;
|
||||
if (label == NULL) {
|
||||
label = "";
|
||||
post_label_spc = "";
|
||||
}
|
||||
|
||||
bytes = BN_num_bytes(n);
|
||||
words = bn_get_words(n);
|
||||
neg = BN_is_negative(n) ? "-" : "";
|
||||
bytes = BN_num_bytes(bn);
|
||||
words = bn_get_words(bn);
|
||||
neg = BN_is_negative(bn) ? "-" : "";
|
||||
|
||||
if (BN_is_zero(n))
|
||||
if (BN_is_zero(bn))
|
||||
return ossl_prov_bio_printf(out, "%s%s0\n", label, post_label_spc);
|
||||
|
||||
if (BN_num_bytes(n) <= BN_BYTES)
|
||||
if (BN_num_bytes(bn) <= BN_BYTES)
|
||||
return ossl_prov_bio_printf(out,
|
||||
"%s%s%s" BN_FMTu " (%s0x" BN_FMTx ")\n",
|
||||
label, post_label_spc, neg, words[0],
|
||||
@@ -172,44 +192,53 @@ int ossl_prov_print_labeled_bignum(BIO *out, const char *label,
|
||||
if (ossl_prov_bio_printf(out, "%s%s\n", label, neg) <= 0)
|
||||
return 0;
|
||||
|
||||
/* Skip past the zero bytes in the first word */
|
||||
for (off = 0; off < BN_BYTES; off++) {
|
||||
BN_ULONG l = words[0];
|
||||
int o = 8 * (BN_BYTES - off - 1);
|
||||
int b = ((l & (0xffLU << o)) >> o) & 0xff;
|
||||
/* Keep track of how many bytes we have printed out so far */
|
||||
n = 0;
|
||||
|
||||
if (b != 0)
|
||||
break;
|
||||
}
|
||||
/* print 16 hex digits per line, indented with 4 spaces */
|
||||
for (i = 0; i < bytes; i += 16) {
|
||||
int j, step;
|
||||
/*
|
||||
* OpenSSL BIGNUMs are little endian limbs, so we print them last to
|
||||
* first limb.
|
||||
* i is used as limb index, j is used as the "byte index" in the limb
|
||||
*/
|
||||
for (i = bytes / BN_BYTES - 1; i >= 0; i--) {
|
||||
BN_ULONG l = words[i];
|
||||
int j;
|
||||
|
||||
if (ossl_prov_bio_printf(out, " ") <= 0)
|
||||
return 0;
|
||||
for (j = BN_BYTES - 1; j >= 0; j--) {
|
||||
int o = 8 * j;
|
||||
int b = ((l & (0xffLU << o)) >> o) & 0xff;
|
||||
|
||||
for (j = 0; i + j < bytes && j < 16; j += BN_BYTES - step) {
|
||||
int k;
|
||||
BN_ULONG l = words[(i + j + off) / BN_BYTES];
|
||||
/* Indent every new line with 4 spaces */
|
||||
if ((n % 15) == 0) {
|
||||
if (n > 0)
|
||||
if (ossl_prov_bio_printf(out, "\n") <= 0)
|
||||
return 0;
|
||||
if (ossl_prov_bio_printf(out, " ") <= 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
step = (i + j + off) % BN_BYTES;
|
||||
|
||||
for (k = step; k < BN_BYTES; k++) {
|
||||
int o = 8 * (BN_BYTES - k - 1);
|
||||
int b = ((l & (0xffLU << o)) >> o) & 0xff;
|
||||
|
||||
/* We may have reached the number of bytes prematurely */
|
||||
if (i + j + k - off >= bytes)
|
||||
break;
|
||||
/*
|
||||
* Upper bit set, then we print an extra zero and pretend the
|
||||
* BIGNUM was one byte longer
|
||||
*/
|
||||
if (n == 0 && b > 127) {
|
||||
if (ossl_prov_bio_printf(out, "%02x:", 0) <= 0)
|
||||
return 0;
|
||||
n++;
|
||||
bytes++;
|
||||
}
|
||||
|
||||
if (++n < bytes) {
|
||||
if (ossl_prov_bio_printf(out, "%02x:", b) <= 0)
|
||||
return 0;
|
||||
} else {
|
||||
if (ossl_prov_bio_printf(out, "%02x", b) <= 0)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (ossl_prov_bio_printf(out, "\n") <= 0)
|
||||
return 0;
|
||||
}
|
||||
if (ossl_prov_bio_printf(out, "\n") <= 0)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -14,9 +14,19 @@
|
||||
#include "prov/providercommonerr.h" /* PROV_R_BN_ERROR */
|
||||
#include "serializer_local.h"
|
||||
|
||||
OSSL_OP_keymgmt_importkey_fn *ossl_prov_get_dh_importkey(void)
|
||||
OSSL_OP_keymgmt_new_fn *ossl_prov_get_keymgmt_dh_new(void)
|
||||
{
|
||||
return ossl_prov_get_importkey(dh_keymgmt_functions);
|
||||
return ossl_prov_get_keymgmt_new(dh_keymgmt_functions);
|
||||
}
|
||||
|
||||
OSSL_OP_keymgmt_free_fn *ossl_prov_get_keymgmt_dh_free(void)
|
||||
{
|
||||
return ossl_prov_get_keymgmt_free(dh_keymgmt_functions);
|
||||
}
|
||||
|
||||
OSSL_OP_keymgmt_import_fn *ossl_prov_get_keymgmt_dh_import(void)
|
||||
{
|
||||
return ossl_prov_get_keymgmt_import(dh_keymgmt_functions);
|
||||
}
|
||||
|
||||
int ossl_prov_print_dh(BIO *out, DH *dh, enum dh_print_type type)
|
||||
@@ -51,7 +61,7 @@ int ossl_prov_print_dh(BIO *out, DH *dh, enum dh_print_type type)
|
||||
}
|
||||
|
||||
p = DH_get0_p(dh);
|
||||
g = DH_get0_p(dh);
|
||||
g = DH_get0_g(dh);
|
||||
if (p == NULL || g == NULL)
|
||||
goto null_err;
|
||||
|
||||
|
||||
@@ -45,15 +45,20 @@ static void dh_param_freectx(void *ctx)
|
||||
static int dh_param_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_importkey_fn *dh_importkey =
|
||||
ossl_prov_get_dh_importkey();
|
||||
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();
|
||||
OSSL_OP_keymgmt_import_fn *dh_import = ossl_prov_get_keymgmt_dh_import();
|
||||
int ok = 0;
|
||||
|
||||
if (dh_importkey != NULL) {
|
||||
DH *dh = dh_importkey(ctx, params); /* ctx == provctx */
|
||||
if (dh_import != NULL) {
|
||||
DH *dh;
|
||||
|
||||
ok = dh_param_der(ctx, dh, out, cb, cbarg);
|
||||
DH_free(dh);
|
||||
/* ctx == provctx */
|
||||
if ((dh = dh_new(ctx)) != NULL
|
||||
&& dh_import(dh, OSSL_KEYMGMT_SELECT_ALL_PARAMETERS, params)
|
||||
&& dh_param_der(ctx, dh, out, cb, cbarg))
|
||||
ok = 1;
|
||||
dh_free(dh);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -66,17 +71,22 @@ static int dh_param_der(void *ctx, void *dh, BIO *out,
|
||||
|
||||
/* Public key : PEM */
|
||||
static int dh_param_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_importkey_fn *dh_importkey =
|
||||
ossl_prov_get_dh_importkey();
|
||||
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();
|
||||
OSSL_OP_keymgmt_import_fn *dh_import = ossl_prov_get_keymgmt_dh_import();
|
||||
int ok = 0;
|
||||
|
||||
if (dh_importkey != NULL) {
|
||||
DH *dh = dh_importkey(ctx, params); /* ctx == provctx */
|
||||
if (dh_import != NULL) {
|
||||
DH *dh;
|
||||
|
||||
ok = dh_param_pem(ctx, dh, out, cb, cbarg);
|
||||
DH_free(dh);
|
||||
/* ctx == provctx */
|
||||
if ((dh = dh_new(ctx)) != NULL
|
||||
&& dh_import(dh, OSSL_KEYMGMT_SELECT_ALL_PARAMETERS, params)
|
||||
&& dh_param_pem(ctx, dh, out, cb, cbarg))
|
||||
ok = 1;
|
||||
dh_free(dh);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -88,17 +98,22 @@ static int dh_param_pem(void *ctx, void *dh, BIO *out,
|
||||
}
|
||||
|
||||
static int dh_param_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_importkey_fn *dh_importkey =
|
||||
ossl_prov_get_dh_importkey();
|
||||
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();
|
||||
OSSL_OP_keymgmt_import_fn *dh_import = ossl_prov_get_keymgmt_dh_import();
|
||||
int ok = 0;
|
||||
|
||||
if (dh_importkey != NULL) {
|
||||
DH *dh = dh_importkey(ctx, params); /* ctx == provctx */
|
||||
if (dh_import != NULL) {
|
||||
DH *dh;
|
||||
|
||||
ok = dh_param_print(ctx, dh, out, cb, cbarg);
|
||||
DH_free(dh);
|
||||
/* ctx == provctx */
|
||||
if ((dh = dh_new(ctx)) != NULL
|
||||
&& dh_import(dh, OSSL_KEYMGMT_SELECT_ALL_PARAMETERS, params)
|
||||
&& dh_param_print(ctx, dh, out, cb, cbarg))
|
||||
ok = 1;
|
||||
dh_free(dh);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -112,18 +112,22 @@ 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,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dh_priv_ctx_st *ctx = vctx;
|
||||
OSSL_OP_keymgmt_importkey_fn *dh_importkey =
|
||||
ossl_prov_get_dh_importkey();
|
||||
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();
|
||||
OSSL_OP_keymgmt_import_fn *dh_import = ossl_prov_get_keymgmt_dh_import();
|
||||
int ok = 0;
|
||||
|
||||
if (dh_importkey != NULL) {
|
||||
DH *dh = dh_importkey(ctx->provctx, params);
|
||||
if (dh_import != NULL) {
|
||||
DH *dh;
|
||||
|
||||
ok = dh_priv_der(ctx, dh, out, cb, cbarg);
|
||||
DH_free(dh);
|
||||
if ((dh = dh_new(ctx->provctx)) != NULL
|
||||
&& dh_import(dh, OSSL_KEYMGMT_SELECT_KEYPAIR, params)
|
||||
&& dh_priv_der(ctx, dh, out, cb, cbarg))
|
||||
ok = 1;
|
||||
dh_free(dh);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -147,24 +151,28 @@ static int dh_priv_der(void *vctx, void *dh, BIO *out,
|
||||
|
||||
/* Private key : PEM */
|
||||
static int dh_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dh_priv_ctx_st *ctx = vctx;
|
||||
OSSL_OP_keymgmt_importkey_fn *dh_importkey =
|
||||
ossl_prov_get_dh_importkey();
|
||||
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();
|
||||
OSSL_OP_keymgmt_import_fn *dh_import = ossl_prov_get_keymgmt_dh_import();
|
||||
int ok = 0;
|
||||
|
||||
if (dh_importkey != NULL) {
|
||||
DH *dh = dh_importkey(ctx, params);
|
||||
if (dh_import != NULL) {
|
||||
DH *dh;
|
||||
|
||||
ok = dh_pem_priv(ctx->provctx, dh, out, cb, cbarg);
|
||||
DH_free(dh);
|
||||
if ((dh = dh_new(ctx->provctx)) != NULL
|
||||
&& dh_import(dh, OSSL_KEYMGMT_SELECT_KEYPAIR, params)
|
||||
&& dh_pem_priv(ctx->provctx, dh, out, cb, cbarg))
|
||||
ok = 1;
|
||||
dh_free(dh);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dh_pem_priv(void *vctx, void *dh, BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dh_priv_ctx_st *ctx = vctx;
|
||||
int ret;
|
||||
@@ -192,25 +200,29 @@ static void dh_print_freectx(void *ctx)
|
||||
{
|
||||
}
|
||||
|
||||
static int dh_priv_print_data(void *provctx, const OSSL_PARAM params[],
|
||||
BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
static int dh_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_importkey_fn *dh_importkey =
|
||||
ossl_prov_get_dh_importkey();
|
||||
struct dh_priv_ctx_st *ctx = vctx;
|
||||
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();
|
||||
OSSL_OP_keymgmt_import_fn *dh_import = ossl_prov_get_keymgmt_dh_import();
|
||||
int ok = 0;
|
||||
|
||||
if (dh_importkey != NULL) {
|
||||
DH *dh = dh_importkey(provctx, params); /* ctx == provctx */
|
||||
if (dh_import != NULL) {
|
||||
DH *dh;
|
||||
|
||||
ok = dh_priv_print(provctx, dh, out, cb, cbarg);
|
||||
DH_free(dh);
|
||||
if ((dh = dh_new(ctx->provctx)) != NULL
|
||||
&& dh_import(dh, OSSL_KEYMGMT_SELECT_KEYPAIR, params)
|
||||
&& dh_priv_print(ctx, dh, out, cb, cbarg))
|
||||
ok = 1;
|
||||
dh_free(dh);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dh_priv_print(void *ctx, void *dh, BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_dh(out, dh, dh_print_priv);
|
||||
}
|
||||
|
||||
@@ -45,15 +45,20 @@ static void dh_pub_freectx(void *ctx)
|
||||
static int dh_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_importkey_fn *dh_importkey =
|
||||
ossl_prov_get_dh_importkey();
|
||||
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();
|
||||
OSSL_OP_keymgmt_import_fn *dh_import = ossl_prov_get_keymgmt_dh_import();
|
||||
int ok = 0;
|
||||
|
||||
if (dh_importkey != NULL) {
|
||||
DH *dh = dh_importkey(ctx, params); /* ctx == provctx */
|
||||
if (dh_import != NULL) {
|
||||
DH *dh;
|
||||
|
||||
ok = dh_pub_der(ctx, dh, out, cb, cbarg);
|
||||
DH_free(dh);
|
||||
/* ctx == provctx */
|
||||
if ((dh = dh_new(ctx)) != NULL
|
||||
&& dh_import(dh, OSSL_KEYMGMT_SELECT_KEYPAIR, params)
|
||||
&& dh_pub_der(ctx, dh, out, cb, cbarg))
|
||||
ok = 1;
|
||||
dh_free(dh);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -70,15 +75,20 @@ static int dh_pub_der(void *ctx, void *dh, BIO *out,
|
||||
static int dh_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_importkey_fn *dh_importkey =
|
||||
ossl_prov_get_dh_importkey();
|
||||
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();
|
||||
OSSL_OP_keymgmt_import_fn *dh_import = ossl_prov_get_keymgmt_dh_import();
|
||||
int ok = 0;
|
||||
|
||||
if (dh_importkey != NULL) {
|
||||
DH *dh = dh_importkey(ctx, params); /* ctx == provctx */
|
||||
if (dh_import != NULL) {
|
||||
DH *dh;
|
||||
|
||||
ok = dh_pub_pem(ctx, dh, out, cb, cbarg);
|
||||
DH_free(dh);
|
||||
/* ctx == provctx */
|
||||
if ((dh = dh_new(ctx)) != NULL
|
||||
&& dh_import(dh, OSSL_KEYMGMT_SELECT_KEYPAIR, params)
|
||||
&& dh_pub_pem(ctx, dh, out, cb, cbarg))
|
||||
ok = 1;
|
||||
dh_free(dh);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -95,15 +105,20 @@ static int dh_pub_pem(void *ctx, void *dh, BIO *out,
|
||||
static int dh_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_importkey_fn *dh_importkey =
|
||||
ossl_prov_get_dh_importkey();
|
||||
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();
|
||||
OSSL_OP_keymgmt_import_fn *dh_import = ossl_prov_get_keymgmt_dh_import();
|
||||
int ok = 0;
|
||||
|
||||
if (dh_importkey != NULL) {
|
||||
DH *dh = dh_importkey(ctx, params); /* ctx == provctx */
|
||||
if (dh_import != NULL) {
|
||||
DH *dh;
|
||||
|
||||
ok = dh_pub_print(ctx, dh, out, cb, cbarg);
|
||||
DH_free(dh);
|
||||
/* ctx == provctx */
|
||||
if ((dh = dh_new(ctx)) != NULL
|
||||
&& dh_import(dh, OSSL_KEYMGMT_SELECT_KEYPAIR, params)
|
||||
&& dh_pub_print(ctx, dh, out, cb, cbarg))
|
||||
ok = 1;
|
||||
dh_free(dh);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -14,9 +14,19 @@
|
||||
#include "prov/providercommonerr.h" /* PROV_R_BN_ERROR */
|
||||
#include "serializer_local.h"
|
||||
|
||||
OSSL_OP_keymgmt_importkey_fn *ossl_prov_get_dsa_importkey(void)
|
||||
OSSL_OP_keymgmt_new_fn *ossl_prov_get_keymgmt_dsa_new(void)
|
||||
{
|
||||
return ossl_prov_get_importkey(dsa_keymgmt_functions);
|
||||
return ossl_prov_get_keymgmt_new(dsa_keymgmt_functions);
|
||||
}
|
||||
|
||||
OSSL_OP_keymgmt_free_fn *ossl_prov_get_keymgmt_dsa_free(void)
|
||||
{
|
||||
return ossl_prov_get_keymgmt_free(dsa_keymgmt_functions);
|
||||
}
|
||||
|
||||
OSSL_OP_keymgmt_import_fn *ossl_prov_get_keymgmt_dsa_import(void)
|
||||
{
|
||||
return ossl_prov_get_keymgmt_import(dsa_keymgmt_functions);
|
||||
}
|
||||
|
||||
int ossl_prov_print_dsa(BIO *out, DSA *dsa, enum dsa_print_type type)
|
||||
|
||||
@@ -43,68 +43,83 @@ static void dsa_param_freectx(void *ctx)
|
||||
|
||||
/* Public key : DER */
|
||||
static int dsa_param_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_importkey_fn *dsa_importkey =
|
||||
ossl_prov_get_dsa_importkey();
|
||||
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
|
||||
OSSL_OP_keymgmt_free_fn *dsa_free = ossl_prov_get_keymgmt_dsa_free();
|
||||
OSSL_OP_keymgmt_import_fn *dsa_import = ossl_prov_get_keymgmt_dsa_import();
|
||||
int ok = 0;
|
||||
|
||||
if (dsa_importkey != NULL) {
|
||||
DSA *dsa = dsa_importkey(ctx, params); /* ctx == provctx */
|
||||
if (dsa_import != NULL) {
|
||||
DSA *dsa;
|
||||
|
||||
ok = dsa_param_der(ctx, dsa, out, cb, cbarg);
|
||||
DSA_free(dsa);
|
||||
/* ctx == provctx */
|
||||
if ((dsa = dsa_new(ctx)) != NULL
|
||||
&& dsa_import(dsa, OSSL_KEYMGMT_SELECT_ALL_PARAMETERS, params)
|
||||
&& dsa_param_der(ctx, dsa, out, cb, cbarg))
|
||||
ok = 1;
|
||||
dsa_free(dsa);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_param_der(void *ctx, void *dsa, BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return i2d_DSAparams_bio(out, dsa);
|
||||
}
|
||||
|
||||
/* Public key : PEM */
|
||||
static int dsa_param_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_importkey_fn *dsa_importkey =
|
||||
ossl_prov_get_dsa_importkey();
|
||||
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
|
||||
OSSL_OP_keymgmt_free_fn *dsa_free = ossl_prov_get_keymgmt_dsa_free();
|
||||
OSSL_OP_keymgmt_import_fn *dsa_import = ossl_prov_get_keymgmt_dsa_import();
|
||||
int ok = 0;
|
||||
|
||||
if (dsa_importkey != NULL) {
|
||||
DSA *dsa = dsa_importkey(ctx, params); /* ctx == provctx */
|
||||
if (dsa_import != NULL) {
|
||||
DSA *dsa;
|
||||
|
||||
ok = dsa_param_pem(ctx, dsa, out, cb, cbarg);
|
||||
DSA_free(dsa);
|
||||
/* ctx == provctx */
|
||||
if ((dsa = dsa_new(ctx)) != NULL
|
||||
&& dsa_import(dsa, OSSL_KEYMGMT_SELECT_ALL_PARAMETERS, params)
|
||||
&& dsa_param_pem(ctx, dsa, out, cb, cbarg))
|
||||
ok = 1;
|
||||
dsa_free(dsa);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_param_pem(void *ctx, void *dsa, BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return PEM_write_bio_DSAparams(out, dsa);
|
||||
}
|
||||
|
||||
static int dsa_param_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_importkey_fn *dsa_importkey =
|
||||
ossl_prov_get_dsa_importkey();
|
||||
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
|
||||
OSSL_OP_keymgmt_free_fn *dsa_free = ossl_prov_get_keymgmt_dsa_free();
|
||||
OSSL_OP_keymgmt_import_fn *dsa_import = ossl_prov_get_keymgmt_dsa_import();
|
||||
int ok = 0;
|
||||
|
||||
if (dsa_importkey != NULL) {
|
||||
DSA *dsa = dsa_importkey(ctx, params); /* ctx == provctx */
|
||||
if (dsa_import != NULL) {
|
||||
DSA *dsa;
|
||||
|
||||
ok = dsa_param_print(ctx, dsa, out, cb, cbarg);
|
||||
DSA_free(dsa);
|
||||
/* ctx == provctx */
|
||||
if ((dsa = dsa_new(ctx)) != NULL
|
||||
&& dsa_import(dsa, OSSL_KEYMGMT_SELECT_ALL_PARAMETERS, params)
|
||||
&& dsa_param_print(ctx, dsa, out, cb, cbarg))
|
||||
ok = 1;
|
||||
dsa_free(dsa);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_param_print(void *ctx, void *dsa, BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_dsa(out, dsa, dsa_print_params);
|
||||
}
|
||||
|
||||
@@ -115,15 +115,19 @@ static int dsa_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dsa_priv_ctx_st *ctx = vctx;
|
||||
OSSL_OP_keymgmt_importkey_fn *dsa_importkey =
|
||||
ossl_prov_get_dsa_importkey();
|
||||
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
|
||||
OSSL_OP_keymgmt_free_fn *dsa_free = ossl_prov_get_keymgmt_dsa_free();
|
||||
OSSL_OP_keymgmt_import_fn *dsa_import = ossl_prov_get_keymgmt_dsa_import();
|
||||
int ok = 0;
|
||||
|
||||
if (dsa_importkey != NULL) {
|
||||
DSA *dsa = dsa_importkey(ctx->provctx, params);
|
||||
if (dsa_import != NULL) {
|
||||
DSA *dsa;
|
||||
|
||||
ok = dsa_priv_der(ctx, dsa, out, cb, cbarg);
|
||||
DSA_free(dsa);
|
||||
if ((dsa = dsa_new(ctx->provctx)) != NULL
|
||||
&& dsa_import(dsa, OSSL_KEYMGMT_SELECT_KEYPAIR, params)
|
||||
&& dsa_priv_der(ctx, dsa, out, cb, cbarg))
|
||||
ok = 1;
|
||||
dsa_free(dsa);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -147,15 +151,19 @@ static int dsa_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dsa_priv_ctx_st *ctx = vctx;
|
||||
OSSL_OP_keymgmt_importkey_fn *dsa_importkey =
|
||||
ossl_prov_get_dsa_importkey();
|
||||
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
|
||||
OSSL_OP_keymgmt_free_fn *dsa_free = ossl_prov_get_keymgmt_dsa_free();
|
||||
OSSL_OP_keymgmt_import_fn *dsa_import = ossl_prov_get_keymgmt_dsa_import();
|
||||
int ok = 0;
|
||||
|
||||
if (dsa_importkey != NULL) {
|
||||
DSA *dsa = dsa_importkey(ctx, params);
|
||||
if (dsa_import != NULL) {
|
||||
DSA *dsa;
|
||||
|
||||
ok = dsa_pem_priv(ctx->provctx, dsa, out, cb, cbarg);
|
||||
DSA_free(dsa);
|
||||
if ((dsa = dsa_new(ctx->provctx)) != NULL
|
||||
&& dsa_import(dsa, OSSL_KEYMGMT_SELECT_KEYPAIR, params)
|
||||
&& dsa_pem_priv(ctx, dsa, out, cb, cbarg))
|
||||
ok = 1;
|
||||
dsa_free(dsa);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -186,19 +194,24 @@ static void dsa_print_freectx(void *ctx)
|
||||
{
|
||||
}
|
||||
|
||||
static int dsa_priv_print_data(void *provctx, const OSSL_PARAM params[],
|
||||
static int dsa_priv_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_importkey_fn *dsa_importkey =
|
||||
ossl_prov_get_dsa_importkey();
|
||||
struct dsa_priv_ctx_st *ctx = vctx;
|
||||
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
|
||||
OSSL_OP_keymgmt_free_fn *dsa_free = ossl_prov_get_keymgmt_dsa_free();
|
||||
OSSL_OP_keymgmt_import_fn *dsa_import = ossl_prov_get_keymgmt_dsa_import();
|
||||
int ok = 0;
|
||||
|
||||
if (dsa_importkey != NULL) {
|
||||
DSA *dsa = dsa_importkey(provctx, params); /* ctx == provctx */
|
||||
if (dsa_import != NULL) {
|
||||
DSA *dsa;
|
||||
|
||||
ok = dsa_priv_print(provctx, dsa, out, cb, cbarg);
|
||||
DSA_free(dsa);
|
||||
if ((dsa = dsa_new(ctx->provctx)) != NULL
|
||||
&& dsa_import(dsa, OSSL_KEYMGMT_SELECT_KEYPAIR, params)
|
||||
&& dsa_priv_print(ctx, dsa, out, cb, cbarg))
|
||||
ok = 1;
|
||||
dsa_free(dsa);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -45,15 +45,20 @@ static void dsa_pub_freectx(void *ctx)
|
||||
static int dsa_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_importkey_fn *dsa_importkey =
|
||||
ossl_prov_get_dsa_importkey();
|
||||
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
|
||||
OSSL_OP_keymgmt_free_fn *dsa_free = ossl_prov_get_keymgmt_dsa_free();
|
||||
OSSL_OP_keymgmt_import_fn *dsa_import = ossl_prov_get_keymgmt_dsa_import();
|
||||
int ok = 0;
|
||||
|
||||
if (dsa_importkey != NULL) {
|
||||
DSA *dsa = dsa_importkey(ctx, params); /* ctx == provctx */
|
||||
if (dsa_import != NULL) {
|
||||
DSA *dsa;
|
||||
|
||||
ok = dsa_pub_der(ctx, dsa, out, cb, cbarg);
|
||||
DSA_free(dsa);
|
||||
/* ctx == provctx */
|
||||
if ((dsa = dsa_new(ctx)) != NULL
|
||||
&& dsa_import(dsa, OSSL_KEYMGMT_SELECT_KEYPAIR, params)
|
||||
&& dsa_pub_der(ctx, dsa, out, cb, cbarg))
|
||||
ok = 1;
|
||||
dsa_free(dsa);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -82,15 +87,20 @@ static int dsa_pub_der(void *ctx, void *dsa, BIO *out,
|
||||
static int dsa_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_importkey_fn *dsa_importkey =
|
||||
ossl_prov_get_dsa_importkey();
|
||||
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
|
||||
OSSL_OP_keymgmt_free_fn *dsa_free = ossl_prov_get_keymgmt_dsa_free();
|
||||
OSSL_OP_keymgmt_import_fn *dsa_import = ossl_prov_get_keymgmt_dsa_import();
|
||||
int ok = 0;
|
||||
|
||||
if (dsa_importkey != NULL) {
|
||||
DSA *dsa = dsa_importkey(ctx, params); /* ctx == provctx */
|
||||
if (dsa_import != NULL) {
|
||||
DSA *dsa;
|
||||
|
||||
ok = dsa_pub_pem(ctx, dsa, out, cb, cbarg);
|
||||
DSA_free(dsa);
|
||||
/* ctx == provctx */
|
||||
if ((dsa = dsa_new(ctx)) != NULL
|
||||
&& dsa_import(dsa, OSSL_KEYMGMT_SELECT_KEYPAIR, params)
|
||||
&& dsa_pub_pem(ctx, dsa, out, cb, cbarg))
|
||||
ok = 1;
|
||||
dsa_free(dsa);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -106,15 +116,20 @@ static int dsa_pub_pem(void *ctx, void *dsa, BIO *out,
|
||||
static int dsa_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_importkey_fn *dsa_importkey =
|
||||
ossl_prov_get_dsa_importkey();
|
||||
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
|
||||
OSSL_OP_keymgmt_free_fn *dsa_free = ossl_prov_get_keymgmt_dsa_free();
|
||||
OSSL_OP_keymgmt_import_fn *dsa_import = ossl_prov_get_keymgmt_dsa_import();
|
||||
int ok = 0;
|
||||
|
||||
if (dsa_importkey != NULL) {
|
||||
DSA *dsa = dsa_importkey(ctx, params); /* ctx == provctx */
|
||||
if (dsa_import != NULL) {
|
||||
DSA *dsa;
|
||||
|
||||
ok = dsa_pub_print(ctx, dsa, out, cb, cbarg);
|
||||
DSA_free(dsa);
|
||||
/* ctx == provctx */
|
||||
if ((dsa = dsa_new(ctx)) != NULL
|
||||
&& dsa_import(dsa, OSSL_KEYMGMT_SELECT_KEYPAIR, params)
|
||||
&& dsa_pub_print(ctx, dsa, out, cb, cbarg))
|
||||
ok = 1;
|
||||
dsa_free(dsa);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -30,11 +30,19 @@ struct pkcs8_encrypt_ctx_st {
|
||||
void *cbarg;
|
||||
};
|
||||
|
||||
OSSL_OP_keymgmt_importkey_fn *ossl_prov_get_importkey(const OSSL_DISPATCH *fns);
|
||||
OSSL_OP_keymgmt_new_fn *ossl_prov_get_keymgmt_new(const OSSL_DISPATCH *fns);
|
||||
OSSL_OP_keymgmt_free_fn *ossl_prov_get_keymgmt_free(const OSSL_DISPATCH *fns);
|
||||
OSSL_OP_keymgmt_import_fn *ossl_prov_get_keymgmt_import(const OSSL_DISPATCH *fns);
|
||||
|
||||
OSSL_OP_keymgmt_importkey_fn *ossl_prov_get_rsa_importkey(void);
|
||||
OSSL_OP_keymgmt_importkey_fn *ossl_prov_get_dh_importkey(void);
|
||||
OSSL_OP_keymgmt_importkey_fn *ossl_prov_get_dsa_importkey(void);
|
||||
OSSL_OP_keymgmt_new_fn *ossl_prov_get_keymgmt_rsa_new(void);
|
||||
OSSL_OP_keymgmt_free_fn *ossl_prov_get_keymgmt_rsa_free(void);
|
||||
OSSL_OP_keymgmt_import_fn *ossl_prov_get_keymgmt_rsa_import(void);
|
||||
OSSL_OP_keymgmt_new_fn *ossl_prov_get_keymgmt_dh_new(void);
|
||||
OSSL_OP_keymgmt_free_fn *ossl_prov_get_keymgmt_dh_free(void);
|
||||
OSSL_OP_keymgmt_import_fn *ossl_prov_get_keymgmt_dh_import(void);
|
||||
OSSL_OP_keymgmt_new_fn *ossl_prov_get_keymgmt_dsa_new(void);
|
||||
OSSL_OP_keymgmt_free_fn *ossl_prov_get_keymgmt_dsa_free(void);
|
||||
OSSL_OP_keymgmt_import_fn *ossl_prov_get_keymgmt_dsa_import(void);
|
||||
|
||||
int ossl_prov_prepare_dh_params(const void *dh, int nid,
|
||||
ASN1_STRING **pstr, int *pstrtype);
|
||||
@@ -54,7 +62,7 @@ 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);
|
||||
|
||||
int ossl_prov_print_labeled_bignum(BIO *out, const char *label,
|
||||
const BIGNUM *n);
|
||||
const BIGNUM *bn);
|
||||
int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv);
|
||||
|
||||
enum dh_print_type {
|
||||
|
||||
@@ -14,9 +14,19 @@
|
||||
|
||||
DEFINE_SPECIAL_STACK_OF_CONST(BIGNUM_const, BIGNUM)
|
||||
|
||||
OSSL_OP_keymgmt_importkey_fn *ossl_prov_get_rsa_importkey(void)
|
||||
OSSL_OP_keymgmt_new_fn *ossl_prov_get_keymgmt_rsa_new(void)
|
||||
{
|
||||
return ossl_prov_get_importkey(rsa_keymgmt_functions);
|
||||
return ossl_prov_get_keymgmt_new(rsa_keymgmt_functions);
|
||||
}
|
||||
|
||||
OSSL_OP_keymgmt_free_fn *ossl_prov_get_keymgmt_rsa_free(void)
|
||||
{
|
||||
return ossl_prov_get_keymgmt_free(rsa_keymgmt_functions);
|
||||
}
|
||||
|
||||
OSSL_OP_keymgmt_import_fn *ossl_prov_get_keymgmt_rsa_import(void)
|
||||
{
|
||||
return ossl_prov_get_keymgmt_import(rsa_keymgmt_functions);
|
||||
}
|
||||
|
||||
int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv)
|
||||
|
||||
@@ -143,15 +143,19 @@ static int rsa_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct rsa_priv_ctx_st *ctx = vctx;
|
||||
OSSL_OP_keymgmt_importkey_fn *rsa_importkey =
|
||||
ossl_prov_get_rsa_importkey();
|
||||
OSSL_OP_keymgmt_new_fn *rsa_new = ossl_prov_get_keymgmt_rsa_new();
|
||||
OSSL_OP_keymgmt_free_fn *rsa_free = ossl_prov_get_keymgmt_rsa_free();
|
||||
OSSL_OP_keymgmt_import_fn *rsa_import = ossl_prov_get_keymgmt_rsa_import();
|
||||
int ok = 0;
|
||||
|
||||
if (rsa_importkey != NULL) {
|
||||
RSA *rsa = rsa_importkey(ctx->provctx, params);
|
||||
if (rsa_import != NULL) {
|
||||
RSA *rsa;
|
||||
|
||||
ok = rsa_priv_der(vctx, rsa, out, cb, cbarg);
|
||||
RSA_free(rsa);
|
||||
if ((rsa = rsa_new(ctx->provctx)) != NULL
|
||||
&& rsa_import(rsa, OSSL_KEYMGMT_SELECT_KEYPAIR, params)
|
||||
&& rsa_priv_der(ctx, rsa, out, cb, cbarg))
|
||||
ok = 1;
|
||||
rsa_free(rsa);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -178,15 +182,19 @@ static int rsa_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct rsa_priv_ctx_st *ctx = vctx;
|
||||
OSSL_OP_keymgmt_importkey_fn *rsa_importkey =
|
||||
ossl_prov_get_rsa_importkey();
|
||||
OSSL_OP_keymgmt_new_fn *rsa_new = ossl_prov_get_keymgmt_rsa_new();
|
||||
OSSL_OP_keymgmt_free_fn *rsa_free = ossl_prov_get_keymgmt_rsa_free();
|
||||
OSSL_OP_keymgmt_import_fn *rsa_import = ossl_prov_get_keymgmt_rsa_import();
|
||||
int ok = 0;
|
||||
|
||||
if (rsa_importkey != NULL) {
|
||||
RSA *rsa = rsa_importkey(ctx, params);
|
||||
if (rsa_import != NULL) {
|
||||
RSA *rsa;
|
||||
|
||||
ok = rsa_pem_priv(vctx, rsa, out, cb, cbarg);
|
||||
RSA_free(rsa);
|
||||
if ((rsa = rsa_new(ctx->provctx)) != NULL
|
||||
&& rsa_import(rsa, OSSL_KEYMGMT_SELECT_KEYPAIR, params)
|
||||
&& rsa_pem_priv(ctx, rsa, out, cb, cbarg))
|
||||
ok = 1;
|
||||
rsa_free(rsa);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -220,19 +228,24 @@ static void rsa_print_freectx(void *ctx)
|
||||
{
|
||||
}
|
||||
|
||||
static int rsa_priv_print_data(void *provctx, const OSSL_PARAM params[],
|
||||
static int rsa_priv_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_importkey_fn *rsa_importkey =
|
||||
ossl_prov_get_rsa_importkey();
|
||||
struct rsa_priv_ctx_st *ctx = vctx;
|
||||
OSSL_OP_keymgmt_new_fn *rsa_new = ossl_prov_get_keymgmt_rsa_new();
|
||||
OSSL_OP_keymgmt_free_fn *rsa_free = ossl_prov_get_keymgmt_rsa_free();
|
||||
OSSL_OP_keymgmt_import_fn *rsa_import = ossl_prov_get_keymgmt_rsa_import();
|
||||
int ok = 0;
|
||||
|
||||
if (rsa_importkey != NULL) {
|
||||
RSA *rsa = rsa_importkey(provctx, params); /* ctx == provctx */
|
||||
if (rsa_import != NULL) {
|
||||
RSA *rsa;
|
||||
|
||||
ok = rsa_priv_print(provctx, rsa, out, cb, cbarg);
|
||||
RSA_free(rsa);
|
||||
if ((rsa = rsa_new(ctx->provctx)) != NULL
|
||||
&& rsa_import(rsa, OSSL_KEYMGMT_SELECT_KEYPAIR, params)
|
||||
&& rsa_priv_print(ctx, rsa, out, cb, cbarg))
|
||||
ok = 1;
|
||||
rsa_free(rsa);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -45,15 +45,20 @@ static void rsa_pub_freectx(void *ctx)
|
||||
static int rsa_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_importkey_fn *rsa_importkey =
|
||||
ossl_prov_get_rsa_importkey();
|
||||
OSSL_OP_keymgmt_new_fn *rsa_new = ossl_prov_get_keymgmt_rsa_new();
|
||||
OSSL_OP_keymgmt_free_fn *rsa_free = ossl_prov_get_keymgmt_rsa_free();
|
||||
OSSL_OP_keymgmt_import_fn *rsa_import = ossl_prov_get_keymgmt_rsa_import();
|
||||
int ok = 0;
|
||||
|
||||
if (rsa_importkey != NULL) {
|
||||
RSA *rsa = rsa_importkey(ctx, params); /* ctx == provctx */
|
||||
if (rsa_import != NULL) {
|
||||
RSA *rsa;
|
||||
|
||||
ok = rsa_pub_der(ctx, rsa, out, cb, cbarg);
|
||||
RSA_free(rsa);
|
||||
/* ctx == provctx */
|
||||
if ((rsa = rsa_new(ctx)) != NULL
|
||||
&& rsa_import(rsa, OSSL_KEYMGMT_SELECT_KEYPAIR, params)
|
||||
&& rsa_pub_der(ctx, rsa, out, cb, cbarg))
|
||||
ok = 1;
|
||||
rsa_free(rsa);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -68,15 +73,20 @@ static int rsa_pub_der(void *ctx, void *rsa, BIO *out,
|
||||
static int rsa_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_importkey_fn *rsa_importkey =
|
||||
ossl_prov_get_rsa_importkey();
|
||||
OSSL_OP_keymgmt_new_fn *rsa_new = ossl_prov_get_keymgmt_rsa_new();
|
||||
OSSL_OP_keymgmt_free_fn *rsa_free = ossl_prov_get_keymgmt_rsa_free();
|
||||
OSSL_OP_keymgmt_import_fn *rsa_import = ossl_prov_get_keymgmt_rsa_import();
|
||||
int ok = 0;
|
||||
|
||||
if (rsa_importkey != NULL) {
|
||||
RSA *rsa = rsa_importkey(ctx, params); /* ctx == provctx */
|
||||
if (rsa_import != NULL) {
|
||||
RSA *rsa;
|
||||
|
||||
ok = rsa_pub_pem(ctx, rsa, out, cb, cbarg);
|
||||
RSA_free(rsa);
|
||||
/* ctx == provctx */
|
||||
if ((rsa = rsa_new(ctx)) != NULL
|
||||
&& rsa_import(rsa, OSSL_KEYMGMT_SELECT_KEYPAIR, params)
|
||||
&& rsa_pub_pem(ctx, rsa, out, cb, cbarg))
|
||||
ok = 1;
|
||||
rsa_free(rsa);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -90,15 +100,20 @@ static int rsa_pub_pem(void *ctx, void *rsa, BIO *out,
|
||||
static int rsa_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_importkey_fn *rsa_importkey =
|
||||
ossl_prov_get_rsa_importkey();
|
||||
OSSL_OP_keymgmt_new_fn *rsa_new = ossl_prov_get_keymgmt_rsa_new();
|
||||
OSSL_OP_keymgmt_free_fn *rsa_free = ossl_prov_get_keymgmt_rsa_free();
|
||||
OSSL_OP_keymgmt_import_fn *rsa_import = ossl_prov_get_keymgmt_rsa_import();
|
||||
int ok = 0;
|
||||
|
||||
if (rsa_importkey != NULL) {
|
||||
RSA *rsa = rsa_importkey(ctx, params); /* ctx == provctx */
|
||||
if (rsa_import != NULL) {
|
||||
RSA *rsa;
|
||||
|
||||
ok = rsa_pub_print(ctx, rsa, out, cb, cbarg);
|
||||
RSA_free(rsa);
|
||||
/* ctx == provctx */
|
||||
if ((rsa = rsa_new(ctx)) != NULL
|
||||
&& rsa_import(rsa, OSSL_KEYMGMT_SELECT_KEYPAIR, params)
|
||||
&& rsa_pub_print(ctx, rsa, out, cb, cbarg))
|
||||
ok = 1;
|
||||
rsa_free(rsa);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -7,13 +7,21 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/core_numbers.h>
|
||||
#include <openssl/core_names.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/dsa.h>
|
||||
#include <openssl/params.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/err.h>
|
||||
#include "internal/nelem.h"
|
||||
#include "internal/sizes.h"
|
||||
#include "prov/providercommonerr.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/providercommonerr.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "crypto/dsa.h"
|
||||
|
||||
@@ -48,13 +56,72 @@ static OSSL_OP_signature_settable_ctx_md_params_fn dsa_settable_ctx_md_params;
|
||||
typedef struct {
|
||||
OPENSSL_CTX *libctx;
|
||||
DSA *dsa;
|
||||
size_t mdsize;
|
||||
/* Should be big enough */
|
||||
char mdname[80];
|
||||
|
||||
/*
|
||||
* Flag to determine if the hash function can be changed (1) or not (0)
|
||||
* Because it's dangerous to change during a DigestSign or DigestVerify
|
||||
* operation, this flag is cleared by their Init function, and set again
|
||||
* by their Final function.
|
||||
*/
|
||||
unsigned int flag_allow_md : 1;
|
||||
|
||||
char mdname[OSSL_MAX_NAME_SIZE];
|
||||
|
||||
/* The Algorithm Identifier of the combined signature agorithm */
|
||||
unsigned char aid[OSSL_MAX_ALGORITHM_ID_SIZE];
|
||||
size_t aid_len;
|
||||
|
||||
/* main digest */
|
||||
EVP_MD *md;
|
||||
EVP_MD_CTX *mdctx;
|
||||
size_t mdsize;
|
||||
} PROV_DSA_CTX;
|
||||
|
||||
static size_t dsa_get_md_size(const PROV_DSA_CTX *pdsactx)
|
||||
{
|
||||
if (pdsactx->md != NULL)
|
||||
return EVP_MD_size(pdsactx->md);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dsa_get_md_nid(const EVP_MD *md)
|
||||
{
|
||||
/*
|
||||
* Because the DSA library deals with NIDs, we need to translate.
|
||||
* We do so using EVP_MD_is_a(), and therefore need a name to NID
|
||||
* map.
|
||||
*/
|
||||
static const OSSL_ITEM name_to_nid[] = {
|
||||
{ NID_sha1, OSSL_DIGEST_NAME_SHA1 },
|
||||
{ NID_sha224, OSSL_DIGEST_NAME_SHA2_224 },
|
||||
{ NID_sha256, OSSL_DIGEST_NAME_SHA2_256 },
|
||||
{ NID_sha384, OSSL_DIGEST_NAME_SHA2_384 },
|
||||
{ NID_sha512, OSSL_DIGEST_NAME_SHA2_512 },
|
||||
{ NID_sha3_224, OSSL_DIGEST_NAME_SHA3_224 },
|
||||
{ NID_sha3_256, OSSL_DIGEST_NAME_SHA3_256 },
|
||||
{ NID_sha3_384, OSSL_DIGEST_NAME_SHA3_384 },
|
||||
{ NID_sha3_512, OSSL_DIGEST_NAME_SHA3_512 },
|
||||
};
|
||||
size_t i;
|
||||
int mdnid = NID_undef;
|
||||
|
||||
if (md == NULL)
|
||||
goto end;
|
||||
|
||||
for (i = 0; i < OSSL_NELEM(name_to_nid); i++) {
|
||||
if (EVP_MD_is_a(md, name_to_nid[i].ptr)) {
|
||||
mdnid = (int)name_to_nid[i].id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (mdnid == NID_undef)
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST);
|
||||
|
||||
end:
|
||||
return mdnid;
|
||||
}
|
||||
|
||||
static void *dsa_newctx(void *provctx)
|
||||
{
|
||||
PROV_DSA_CTX *pdsactx = OPENSSL_zalloc(sizeof(PROV_DSA_CTX));
|
||||
@@ -63,9 +130,39 @@ static void *dsa_newctx(void *provctx)
|
||||
return NULL;
|
||||
|
||||
pdsactx->libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
|
||||
pdsactx->flag_allow_md = 1;
|
||||
return pdsactx;
|
||||
}
|
||||
|
||||
static int dsa_setup_md(PROV_DSA_CTX *ctx,
|
||||
const char *mdname, const char *mdprops)
|
||||
{
|
||||
if (mdname != NULL) {
|
||||
EVP_MD *md = EVP_MD_fetch(ctx->libctx, mdname, mdprops);
|
||||
int md_nid = dsa_get_md_nid(md);
|
||||
size_t algorithmidentifier_len = 0;
|
||||
const unsigned char *algorithmidentifier;
|
||||
|
||||
EVP_MD_free(ctx->md);
|
||||
ctx->md = NULL;
|
||||
ctx->mdname[0] = '\0';
|
||||
|
||||
algorithmidentifier =
|
||||
dsa_algorithmidentifier_encoding(md_nid, &algorithmidentifier_len);
|
||||
|
||||
if (algorithmidentifier == NULL) {
|
||||
EVP_MD_free(md);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ctx->md = md;
|
||||
OPENSSL_strlcpy(ctx->mdname, mdname, sizeof(ctx->mdname));
|
||||
memcpy(ctx->aid, algorithmidentifier, algorithmidentifier_len);
|
||||
ctx->aid_len = algorithmidentifier_len;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int dsa_signature_init(void *vpdsactx, void *vdsa)
|
||||
{
|
||||
PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
|
||||
@@ -84,6 +181,7 @@ static int dsa_sign(void *vpdsactx, unsigned char *sig, size_t *siglen,
|
||||
int ret;
|
||||
unsigned int sltmp;
|
||||
size_t dsasize = DSA_size(pdsactx->dsa);
|
||||
size_t mdsize = dsa_get_md_size(pdsactx);
|
||||
|
||||
if (sig == NULL) {
|
||||
*siglen = dsasize;
|
||||
@@ -93,7 +191,7 @@ static int dsa_sign(void *vpdsactx, unsigned char *sig, size_t *siglen,
|
||||
if (sigsize < (size_t)dsasize)
|
||||
return 0;
|
||||
|
||||
if (pdsactx->mdsize != 0 && tbslen != pdsactx->mdsize)
|
||||
if (mdsize != 0 && tbslen != mdsize)
|
||||
return 0;
|
||||
|
||||
ret = dsa_sign_int(pdsactx->libctx, 0, tbs, tbslen, sig, &sltmp,
|
||||
@@ -109,8 +207,9 @@ static int dsa_verify(void *vpdsactx, const unsigned char *sig, size_t siglen,
|
||||
const unsigned char *tbs, size_t tbslen)
|
||||
{
|
||||
PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
|
||||
size_t mdsize = dsa_get_md_size(pdsactx);
|
||||
|
||||
if (pdsactx->mdsize != 0 && tbslen != pdsactx->mdsize)
|
||||
if (mdsize != 0 && tbslen != mdsize)
|
||||
return 0;
|
||||
|
||||
return DSA_verify(0, tbs, tbslen, sig, siglen, pdsactx->dsa);
|
||||
@@ -120,24 +219,29 @@ static int dsa_digest_signverify_init(void *vpdsactx, const char *mdname,
|
||||
const char *props, void *vdsa)
|
||||
{
|
||||
PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
|
||||
EVP_MD *md;
|
||||
|
||||
pdsactx->flag_allow_md = 0;
|
||||
if (!dsa_signature_init(vpdsactx, vdsa))
|
||||
return 0;
|
||||
|
||||
md = EVP_MD_fetch(pdsactx->libctx, mdname, props);
|
||||
if (md == NULL)
|
||||
if (!dsa_setup_md(pdsactx, mdname, props))
|
||||
return 0;
|
||||
pdsactx->md = md;
|
||||
pdsactx->mdsize = EVP_MD_size(md);
|
||||
|
||||
pdsactx->mdctx = EVP_MD_CTX_new();
|
||||
if (pdsactx->mdctx == NULL)
|
||||
return 0;
|
||||
goto error;
|
||||
|
||||
if (!EVP_DigestInit_ex(pdsactx->mdctx, md, NULL))
|
||||
return 0;
|
||||
if (!EVP_DigestInit_ex(pdsactx->mdctx, pdsactx->md, NULL))
|
||||
goto error;
|
||||
|
||||
return 1;
|
||||
|
||||
error:
|
||||
EVP_MD_CTX_free(pdsactx->mdctx);
|
||||
EVP_MD_free(pdsactx->md);
|
||||
pdsactx->mdctx = NULL;
|
||||
pdsactx->md = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dsa_digest_signverify_update(void *vpdsactx, const unsigned char *data,
|
||||
@@ -175,6 +279,8 @@ int dsa_digest_sign_final(void *vpdsactx, unsigned char *sig, size_t *siglen,
|
||||
return 0;
|
||||
}
|
||||
|
||||
pdsactx->flag_allow_md = 1;
|
||||
|
||||
return dsa_sign(vpdsactx, sig, siglen, sigsize, digest, (size_t)dlen);
|
||||
}
|
||||
|
||||
@@ -197,6 +303,8 @@ int dsa_digest_verify_final(void *vpdsactx, const unsigned char *sig,
|
||||
if (!EVP_DigestFinal_ex(pdsactx->mdctx, digest, &dlen))
|
||||
return 0;
|
||||
|
||||
pdsactx->flag_allow_md = 1;
|
||||
|
||||
return dsa_verify(vpdsactx, sig, siglen, digest, (size_t)dlen);
|
||||
}
|
||||
|
||||
@@ -254,21 +362,20 @@ static int dsa_get_ctx_params(void *vpdsactx, OSSL_PARAM *params)
|
||||
if (pdsactx == NULL || params == NULL)
|
||||
return 0;
|
||||
|
||||
p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_DIGEST_SIZE);
|
||||
if (p != NULL && !OSSL_PARAM_set_size_t(p, pdsactx->mdsize))
|
||||
p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID);
|
||||
if (p != NULL
|
||||
&& !OSSL_PARAM_set_octet_string(p, pdsactx->aid, pdsactx->aid_len))
|
||||
return 0;
|
||||
|
||||
p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_DIGEST);
|
||||
if (p != NULL && !OSSL_PARAM_set_utf8_string(p, pdsactx->md == NULL
|
||||
? pdsactx->mdname
|
||||
: EVP_MD_name(pdsactx->md)))
|
||||
if (p != NULL && !OSSL_PARAM_set_utf8_string(p, pdsactx->mdname))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const OSSL_PARAM known_gettable_ctx_params[] = {
|
||||
OSSL_PARAM_size_t(OSSL_SIGNATURE_PARAM_DIGEST_SIZE, NULL),
|
||||
OSSL_PARAM_octet_string(OSSL_SIGNATURE_PARAM_ALGORITHM_ID, NULL, 0),
|
||||
OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0),
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
@@ -282,39 +389,34 @@ static int dsa_set_ctx_params(void *vpdsactx, const OSSL_PARAM params[])
|
||||
{
|
||||
PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
|
||||
const OSSL_PARAM *p;
|
||||
char *mdname;
|
||||
|
||||
if (pdsactx == NULL || params == NULL)
|
||||
return 0;
|
||||
|
||||
if (pdsactx->md != NULL) {
|
||||
/*
|
||||
* You cannot set the digest name/size when doing a DigestSign or
|
||||
* DigestVerify.
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
|
||||
p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_DIGEST_SIZE);
|
||||
if (p != NULL && !OSSL_PARAM_get_size_t(p, &pdsactx->mdsize))
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* We never actually use the mdname, but we do support getting it later.
|
||||
* This can be useful for applications that want to know the MD that they
|
||||
* previously set.
|
||||
*/
|
||||
p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_DIGEST);
|
||||
mdname = pdsactx->mdname;
|
||||
if (p != NULL
|
||||
&& !OSSL_PARAM_get_utf8_string(p, &mdname, sizeof(pdsactx->mdname)))
|
||||
/* Not allowed during certain operations */
|
||||
if (p != NULL && !pdsactx->flag_allow_md)
|
||||
return 0;
|
||||
if (p != NULL) {
|
||||
char mdname[OSSL_MAX_NAME_SIZE] = "", *pmdname = mdname;
|
||||
char mdprops[OSSL_MAX_PROPQUERY_SIZE] = "", *pmdprops = mdprops;
|
||||
const OSSL_PARAM *propsp =
|
||||
OSSL_PARAM_locate_const(params,
|
||||
OSSL_SIGNATURE_PARAM_PROPERTIES);
|
||||
|
||||
if (!OSSL_PARAM_get_utf8_string(p, &pmdname, sizeof(mdname)))
|
||||
return 0;
|
||||
if (propsp != NULL
|
||||
&& !OSSL_PARAM_get_utf8_string(propsp, &pmdprops, sizeof(mdprops)))
|
||||
return 0;
|
||||
if (!dsa_setup_md(pdsactx, mdname, mdprops))
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const OSSL_PARAM known_settable_ctx_params[] = {
|
||||
OSSL_PARAM_size_t(OSSL_SIGNATURE_PARAM_DIGEST_SIZE, NULL),
|
||||
OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0),
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user