Latest update.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Generated by util/mkerr.pl DO NOT EDIT
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -103,6 +103,7 @@ int ERR_load_PROV_strings(void);
|
||||
# define PROV_R_TAG_NOT_NEEDED 120
|
||||
# define PROV_R_UNABLE_TO_LOAD_SHA1 143
|
||||
# define PROV_R_UNABLE_TO_LOAD_SHA256 147
|
||||
# define PROV_R_UNKNOWN_PADDING_TYPE 163
|
||||
# define PROV_R_UNSUPPORTED_CEK_ALG 145
|
||||
# define PROV_R_UNSUPPORTED_KEY_SIZE 153
|
||||
# define PROV_R_UNSUPPORTED_MAC_TYPE 137
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Generated by util/mkerr.pl DO NOT EDIT
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -88,6 +88,8 @@ static const ERR_STRING_DATA PROV_str_reasons[] = {
|
||||
"unable to load sha1"},
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_UNABLE_TO_LOAD_SHA256),
|
||||
"unable to load sha256"},
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_UNKNOWN_PADDING_TYPE),
|
||||
"unknown padding type"},
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_UNSUPPORTED_CEK_ALG),
|
||||
"unsupported cek alg"},
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_UNSUPPORTED_KEY_SIZE),
|
||||
|
||||
@@ -417,19 +417,19 @@ static const OSSL_ALGORITHM deflt_serializer[] = {
|
||||
dh_priv_text_serializer_functions },
|
||||
{ "DH", "default=yes,format=text,type=public",
|
||||
dh_pub_text_serializer_functions },
|
||||
{ "DH", "default=yes,format=text,type=domainparams",
|
||||
{ "DH", "default=yes,format=text,type=parameters",
|
||||
dh_param_text_serializer_functions },
|
||||
{ "DH", "default=yes,format=der,type=private",
|
||||
dh_priv_der_serializer_functions },
|
||||
{ "DH", "default=yes,format=der,type=public",
|
||||
dh_pub_der_serializer_functions },
|
||||
{ "DH", "default=yes,format=der,type=domainparams",
|
||||
{ "DH", "default=yes,format=der,type=parameters",
|
||||
dh_param_der_serializer_functions },
|
||||
{ "DH", "default=yes,format=pem,type=private",
|
||||
dh_priv_pem_serializer_functions },
|
||||
{ "DH", "default=yes,format=pem,type=public",
|
||||
dh_pub_pem_serializer_functions },
|
||||
{ "DH", "default=yes,format=pem,type=domainparams",
|
||||
{ "DH", "default=yes,format=pem,type=parameters",
|
||||
dh_param_pem_serializer_functions },
|
||||
#endif
|
||||
|
||||
@@ -438,19 +438,19 @@ static const OSSL_ALGORITHM deflt_serializer[] = {
|
||||
dsa_priv_text_serializer_functions },
|
||||
{ "DSA", "default=yes,format=text,type=public",
|
||||
dsa_pub_text_serializer_functions },
|
||||
{ "DSA", "default=yes,format=text,type=domainparams",
|
||||
{ "DSA", "default=yes,format=text,type=parameters",
|
||||
dsa_param_text_serializer_functions },
|
||||
{ "DSA", "default=yes,format=der,type=private",
|
||||
dsa_priv_der_serializer_functions },
|
||||
{ "DSA", "default=yes,format=der,type=public",
|
||||
dsa_pub_der_serializer_functions },
|
||||
{ "DSA", "default=yes,format=der,type=domainparams",
|
||||
{ "DSA", "default=yes,format=der,type=parameters",
|
||||
dsa_param_der_serializer_functions },
|
||||
{ "DSA", "default=yes,format=pem,type=private",
|
||||
dsa_priv_pem_serializer_functions },
|
||||
{ "DSA", "default=yes,format=pem,type=public",
|
||||
dsa_pub_pem_serializer_functions },
|
||||
{ "DSA", "default=yes,format=pem,type=domainparams",
|
||||
{ "DSA", "default=yes,format=pem,type=parameters",
|
||||
dsa_param_pem_serializer_functions },
|
||||
#endif
|
||||
|
||||
|
||||
+307
-92
@@ -26,6 +26,7 @@
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/property.h"
|
||||
#include "internal/nelem.h"
|
||||
#include "internal/param_build.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
@@ -125,65 +126,84 @@ static OSSL_PARAM core_params[] =
|
||||
};
|
||||
|
||||
/*
|
||||
* This routine is currently necessary as bn params are currently processed
|
||||
* using BN_native2bn when raw data is received. This means we need to do
|
||||
* magic to reverse the order of the bytes to match native format.
|
||||
* The array of hexdata is to get around compilers that dont like
|
||||
* Convert a string into a bignumber.
|
||||
* The array of hex_data is used to get around compilers that dont like
|
||||
* strings longer than 509 bytes,
|
||||
*/
|
||||
static int rawnative_fromhex(const char *hex_data[],
|
||||
unsigned char **native, size_t *nativelen)
|
||||
#if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_DSA)
|
||||
static int hextobn(const char *hex_data[], BIGNUM **bn)
|
||||
{
|
||||
int ret = 0;
|
||||
unsigned char *data = NULL;
|
||||
BIGNUM *bn = NULL;
|
||||
int i, slen, datalen, sz;
|
||||
int i, slen;
|
||||
char *str = NULL;
|
||||
|
||||
/* Get the total length of the strings */
|
||||
for (slen = 0, i = 0; hex_data[i] != NULL; ++i)
|
||||
slen += strlen(hex_data[i]);
|
||||
|
||||
/* Add 1 for the string terminator */
|
||||
str = OPENSSL_zalloc(slen + 1);
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
/* join the strings together into 1 buffer */
|
||||
for (i = 0; hex_data[i] != NULL; ++i)
|
||||
strcat(str, hex_data[i]);
|
||||
|
||||
if (BN_hex2bn(&bn, str) <= 0)
|
||||
return 0;
|
||||
|
||||
datalen = slen / 2;
|
||||
data = (unsigned char *)str; /* reuse the str buffer */
|
||||
|
||||
sz = BN_bn2nativepad(bn, data, datalen);
|
||||
if (sz <= 0)
|
||||
if (BN_hex2bn(bn, str) <= 0)
|
||||
goto err;
|
||||
ret = 1;
|
||||
*native = data;
|
||||
*nativelen = datalen;
|
||||
data = NULL; /* so it does not get freed */
|
||||
err:
|
||||
BN_free(bn);
|
||||
OPENSSL_free(data);
|
||||
OPENSSL_free(str);
|
||||
return ret;
|
||||
}
|
||||
#endif /* !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_DSA) */
|
||||
|
||||
/* TODO(3.0): To be removed */
|
||||
static int dummy_evp_call(void *provctx)
|
||||
#ifndef OPENSSL_NO_DH
|
||||
static int hextobin(const char *hex_data[], unsigned char **out, size_t *len)
|
||||
{
|
||||
OPENSSL_CTX *libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
|
||||
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
|
||||
EVP_MD *sha256 = EVP_MD_fetch(libctx, "SHA256", NULL);
|
||||
EVP_KDF *kdf = EVP_KDF_fetch(libctx, OSSL_KDF_NAME_PBKDF2, NULL);
|
||||
int ret = 0, sz;
|
||||
BIGNUM *bn = NULL;
|
||||
unsigned char *buf = NULL;
|
||||
|
||||
if (!hextobn(hex_data, &bn))
|
||||
return 0;
|
||||
sz = BN_num_bytes(bn);
|
||||
buf = OPENSSL_zalloc(sz);
|
||||
if (buf == NULL)
|
||||
goto err;
|
||||
if (BN_bn2binpad(bn, buf, sz) <= 0)
|
||||
goto err;
|
||||
|
||||
*out = buf;
|
||||
*len = sz;
|
||||
buf = NULL; /* Set to NULL so it is not freed */
|
||||
ret = 1;
|
||||
err:
|
||||
OPENSSL_free(buf);
|
||||
BN_free(bn);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
static int dsa_key_signature_test(OPENSSL_CTX *libctx)
|
||||
{
|
||||
int ret = 0;
|
||||
BIGNUM *p = NULL, *q = NULL, *g = NULL;
|
||||
BIGNUM *pub = NULL, *priv = NULL;
|
||||
OSSL_PARAM *params = NULL, *params_sig = NULL;
|
||||
OSSL_PARAM_BLD bld;
|
||||
EVP_PKEY_CTX *sctx = NULL, *kctx = NULL;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
OSSL_PARAM *p;
|
||||
OSSL_PARAM params[16];
|
||||
unsigned char sig[64];
|
||||
size_t siglen, sigdgstlen;
|
||||
unsigned char *dsa_p = NULL, *dsa_q = NULL, *dsa_g = NULL;
|
||||
unsigned char *dsa_pub = NULL, *dsa_priv = NULL;
|
||||
size_t dsa_p_len, dsa_q_len, dsa_g_len, dsa_pub_len, dsa_priv_len;
|
||||
size_t siglen;
|
||||
|
||||
static const unsigned char dgst[SHA256_DIGEST_LENGTH] = {
|
||||
0x7f, 0x83, 0xb1, 0x65, 0x7f, 0xf1, 0xfc, 0x53, 0xb9, 0x2d, 0xc1, 0x81,
|
||||
0x48, 0xa1, 0xd6, 0x5d, 0xfc, 0x2d, 0x4b, 0x1f, 0xa3, 0xd6, 0x77, 0x28,
|
||||
0x4a, 0xdd, 0xd2, 0x00, 0x12, 0x6d, 0x90, 0x69
|
||||
};
|
||||
/* dsa 2048 */
|
||||
static const char *dsa_p_hex[] = {
|
||||
"a29b8872ce8b8423b7d5d21d4b02f57e03e9e6b8a258dc16611ba098ab543415"
|
||||
@@ -226,14 +246,235 @@ static int dummy_evp_call(void *provctx)
|
||||
"6ccaeef6d73b4e80f11c17b8e9627c036635bac39423505e407e5cb7",
|
||||
NULL
|
||||
};
|
||||
char msg[] = "Hello World!";
|
||||
const unsigned char exptd[] = {
|
||||
0x7f, 0x83, 0xb1, 0x65, 0x7f, 0xf1, 0xfc, 0x53, 0xb9, 0x2d, 0xc1, 0x81,
|
||||
0x48, 0xa1, 0xd6, 0x5d, 0xfc, 0x2d, 0x4b, 0x1f, 0xa3, 0xd6, 0x77, 0x28,
|
||||
0x4a, 0xdd, 0xd2, 0x00, 0x12, 0x6d, 0x90, 0x69
|
||||
|
||||
if (!hextobn(dsa_p_hex, &p)
|
||||
|| !hextobn(dsa_q_hex, &q)
|
||||
|| !hextobn(dsa_g_hex, &g)
|
||||
|| !hextobn(dsa_pub_hex, &pub)
|
||||
|| !hextobn(dsa_priv_hex, &priv))
|
||||
goto err;
|
||||
|
||||
ossl_param_bld_init(&bld);
|
||||
if (!ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_FFC_P, p)
|
||||
|| !ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_FFC_Q, q)
|
||||
|| !ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_FFC_G, g)
|
||||
|| !ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_DSA_PUB_KEY, pub)
|
||||
|| !ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_DSA_PRIV_KEY, priv))
|
||||
goto err;
|
||||
params = ossl_param_bld_to_param(&bld);
|
||||
|
||||
/* Create a EVP_PKEY_CTX to load the DSA key into */
|
||||
kctx = EVP_PKEY_CTX_new_from_name(libctx, SN_dsa, "");
|
||||
if (kctx == NULL || params == NULL)
|
||||
goto err;
|
||||
if (EVP_PKEY_key_fromdata_init(kctx) <= 0
|
||||
|| EVP_PKEY_fromdata(kctx, &pkey, params) <= 0)
|
||||
goto err;
|
||||
|
||||
/* Create a EVP_PKEY_CTX to use for the signing operation */
|
||||
sctx = EVP_PKEY_CTX_new_from_pkey(libctx, pkey, NULL);
|
||||
if (sctx == NULL
|
||||
|| EVP_PKEY_sign_init(sctx) <= 0)
|
||||
goto err;
|
||||
|
||||
/* set signature parameters */
|
||||
ossl_param_bld_init(&bld);
|
||||
if (!ossl_param_bld_push_utf8_string(&bld, OSSL_SIGNATURE_PARAM_DIGEST,
|
||||
SN_sha256,strlen(SN_sha256) + 1))
|
||||
goto err;
|
||||
params_sig = ossl_param_bld_to_param(&bld);
|
||||
if (EVP_PKEY_CTX_set_params(sctx, params_sig) <= 0)
|
||||
goto err;
|
||||
|
||||
if (EVP_PKEY_sign(sctx, sig, &siglen, dgst, sizeof(dgst)) <= 0
|
||||
|| EVP_PKEY_verify_init(sctx) <= 0
|
||||
|| EVP_PKEY_verify(sctx, sig, siglen, dgst, sizeof(dgst)) <= 0)
|
||||
goto err;
|
||||
ret = 1;
|
||||
err:
|
||||
ossl_param_bld_free(params);
|
||||
ossl_param_bld_free(params_sig);
|
||||
BN_free(p);
|
||||
BN_free(q);
|
||||
BN_free(g);
|
||||
BN_free(pub);
|
||||
BN_free(priv);
|
||||
EVP_PKEY_free(pkey);
|
||||
EVP_PKEY_CTX_free(kctx);
|
||||
EVP_PKEY_CTX_free(sctx);
|
||||
return ret;
|
||||
}
|
||||
#endif /* OPENSSL_NO_DSA */
|
||||
|
||||
#ifndef OPENSSL_NO_DH
|
||||
static int dh_key_exchange_test(OPENSSL_CTX *libctx)
|
||||
{
|
||||
int ret = 0;
|
||||
BIGNUM *p = NULL, *q = NULL, *g = NULL;
|
||||
BIGNUM *pub = NULL, *priv = NULL, *pub_peer = NULL;
|
||||
unsigned char *kat_secret = NULL;
|
||||
EVP_PKEY_CTX *kactx = NULL, *dctx = NULL;
|
||||
EVP_PKEY *pkey = NULL, *peerkey = NULL;
|
||||
OSSL_PARAM *params = NULL;
|
||||
OSSL_PARAM *params_peer = NULL;
|
||||
unsigned char secret[256];
|
||||
size_t secret_len, kat_secret_len = 0;
|
||||
OSSL_PARAM_BLD bld;
|
||||
|
||||
/* DH KAT */
|
||||
static const char *dh_p_hex[] = {
|
||||
"dcca1511b2313225f52116e1542789e001f0425bccc7f366f7406407f1c9fa8b"
|
||||
"e610f1778bb170be39dbb76f85bf24ce6880adb7629f7c6d015e61d43fa3ee4d"
|
||||
"e185f2cfd041ffde9d418407e15138bb021daeb35f762d1782acc658d32bd4b0"
|
||||
"232c927dd38fa097b3d1859fa8acafb98f066608fc644ec7ddb6f08599f92ac1",
|
||||
"b59825da8432077def695646063c20823c9507ab6f0176d4730d990dbbe6361c"
|
||||
"d8b2b94d3d2f329b82099bd661f42950f403df3ede62a33188b02798ba823f44"
|
||||
"b946fe9df677a0c5a1238eaa97b70f80da8cac88e092b1127060ffbf45579994"
|
||||
"011dc2faa5e7f6c76245e1cc312231c17d1ca6b19007ef0db99f9cb60e1d5f69",
|
||||
NULL
|
||||
};
|
||||
unsigned int dgstlen = 0;
|
||||
static const char *dh_q_hex[] = {
|
||||
"898b226717ef039e603e82e5c7afe48374ac5f625c54f1ea11acb57d",
|
||||
NULL
|
||||
};
|
||||
static const char *dh_g_hex[] = {
|
||||
"5ef7b88f2df60139351dfbfe1266805fdf356cdfd13a4da0050c7ede"
|
||||
"246df59f6abf96ade5f2b28ffe88d6bce7f7894a3d535fc82126ddd4"
|
||||
"24872e16b838df8c51e9016f889c7c203e98a8b631f9c72563d38a49"
|
||||
"589a0753d358e783318cefd9677c7b2dbb77d6dce2a1963795ca64b9",
|
||||
"2d1c9aac6d0e8d431de5e50060dff78689c9eca1c1248c16ed09c7ad",
|
||||
"412a17406d2b525aa1cabb237b9734ec7b8ce3fae02f29c5efed30d6"
|
||||
"9187da109c2c9fe2aadbb0c22af54c616655000c431c6b4a379763b0"
|
||||
"a91658efc84e8b06358c8b4f213710fd10172cf39b830c2dd84a0c8a"
|
||||
"b82516ecab995fa4215e023e4ecf8074c39d6c88b70d1ee4e96fdc20",
|
||||
"ea115c32",
|
||||
NULL
|
||||
};
|
||||
static const char *dh_priv_hex[] = {
|
||||
"1433e0b5a917b60a3023f2f8aa2c2d70d2968aba9aeac81540b8fce6",
|
||||
NULL
|
||||
};
|
||||
static const char *dh_pub_hex[] = {
|
||||
"95dd338d29e5710492b918317b72a36936e1951a2ee5a5591699c048"
|
||||
"6d0d4f9bdd6d5a3f6b98890c62b37652d36e712111e68a7355372506"
|
||||
"99efe330537391fbc2c548bc5ac3e5b23386c3eef5eb43c099d70a52"
|
||||
"02687e83964248fca91f40908e8fb3319315f6d2606d7f7cd52cc6e7",
|
||||
"c5843afb22519cf0f0f9d3a0a4e8c88899efede7364351fb6a363ee7"
|
||||
"17e5445adab4c931a6483997b87dad83677e4d1d3a7775e0f6d00fdf"
|
||||
"73c7ad801e665a0e5a796d0a0380a19fa182efc8a04f5e4db90d1a86"
|
||||
"37f95db16436bdc8f3fc096c4ff7f234be8fef479ac4b0dc4b77263e",
|
||||
"07d9959de0f1bf3f0ae3d9d50e4b89c99e3ea1217343dd8c6581acc4"
|
||||
"959c91d3",
|
||||
NULL
|
||||
};
|
||||
static const char *dh_peer_pub_hex[] = {
|
||||
"1fc1da341d1a846a96b7be24340f877dd010aa0356d5ad58aae9c7b0"
|
||||
"8f749a32235110b5d88eb5dbfa978d27ecc530f02d3114005b64b1c0"
|
||||
"e024cb8ae21698bca9e60d42808622f181c56e1de7a96e6efee9d665"
|
||||
"67e91b977042c7e3d0448f05fb77f522b9bfc8d33cc3c31ed3b31f0f",
|
||||
"ecb6db4f6ea311e77afdbcd47aee1bb150f216873578fb96468e8f9f"
|
||||
"3de8efbfce75624b1df05322a34f1463e839e8984c4ad0a96e1ac842"
|
||||
"e5318cc23c062a8ca171b8d575980dde7fc56f1536523820d43192bf"
|
||||
"d51e8e228978aca5b94472f339caeb9931b42be301268bc99789c9b2",
|
||||
"5571c3c0e4cb3f007f1a511cbb53c8519cdd1302abca6c0f34f96739"
|
||||
"f17ff48b",
|
||||
NULL
|
||||
};
|
||||
static const char *dh_secret_exptd_hex[] = {
|
||||
"08ff33bb2ecff49a7d4a7912aeb1bb6ab511641b4a76770c8cc1bcc2"
|
||||
"33343dfe700d11813d2c9ed23b211ca9e8786921edca283c68b16153"
|
||||
"fa01e91ab82c90ddab4a95816770a98710e14c92ab83b6e46e1e426e"
|
||||
"e852430d6187daa3720a6bcd73235c6b0f941f3364f50420551a4bfe",
|
||||
"afe2bc438505a59a4a40daca7a895a73db575c74c13a23ad8832957d"
|
||||
"582d38f0a6165fb0d7e9b8799e42fd3220e332e98185a0c9429757b2"
|
||||
"d0d02c17dbaa1ff6ed93d7e73e241eaed90caf394d2bc6570f18c81f"
|
||||
"2be5d01a2ca99ff142b5d963f9f500325e7556f95849b3ffc7479486",
|
||||
"be1d4596a3106bd5cb4f61c57ec5f100fb7a0c82a10b82526a97d1d9"
|
||||
"7d98eaf6",
|
||||
NULL
|
||||
};
|
||||
|
||||
if (!hextobn(dh_p_hex, &p)
|
||||
|| !hextobn(dh_q_hex, &q)
|
||||
|| !hextobn(dh_g_hex, &g)
|
||||
|| !hextobn(dh_pub_hex, &pub)
|
||||
|| !hextobn(dh_priv_hex, &priv)
|
||||
|| !hextobn(dh_peer_pub_hex, &pub_peer)
|
||||
|| !hextobin(dh_secret_exptd_hex, &kat_secret, &kat_secret_len))
|
||||
goto err;
|
||||
|
||||
ossl_param_bld_init(&bld);
|
||||
if (!ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_FFC_P, p)
|
||||
|| !ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_FFC_Q, q)
|
||||
|| !ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_FFC_G, g)
|
||||
|| !ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_DH_PUB_KEY, pub)
|
||||
|| !ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_DH_PRIV_KEY, priv))
|
||||
goto err;
|
||||
params = ossl_param_bld_to_param(&bld);
|
||||
|
||||
ossl_param_bld_init(&bld);
|
||||
if (!ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_FFC_P, p)
|
||||
|| !ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_FFC_Q, q)
|
||||
|| !ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_FFC_G, g)
|
||||
|| !ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_DH_PUB_KEY, pub_peer))
|
||||
goto err;
|
||||
|
||||
params_peer = ossl_param_bld_to_param(&bld);
|
||||
if (params == NULL || params_peer == NULL)
|
||||
goto err;
|
||||
|
||||
/* Create a EVP_PKEY_CTX to load the DH keys into */
|
||||
kactx = EVP_PKEY_CTX_new_from_name(libctx, "DH", "");
|
||||
if (kactx == NULL)
|
||||
goto err;
|
||||
if (EVP_PKEY_key_fromdata_init(kactx) <= 0
|
||||
|| EVP_PKEY_fromdata(kactx, &pkey, params) <= 0)
|
||||
goto err;
|
||||
if (EVP_PKEY_key_fromdata_init(kactx) <= 0
|
||||
|| EVP_PKEY_fromdata(kactx, &peerkey, params_peer) <= 0)
|
||||
goto err;
|
||||
|
||||
/* Create a EVP_PKEY_CTX to perform key derivation */
|
||||
dctx = EVP_PKEY_CTX_new_from_pkey(libctx, pkey, NULL);
|
||||
if (dctx == NULL)
|
||||
goto err;
|
||||
|
||||
if (EVP_PKEY_derive_init(dctx) <= 0
|
||||
|| EVP_PKEY_derive_set_peer(dctx, peerkey) <= 0
|
||||
|| EVP_PKEY_derive(dctx, secret, &secret_len) <= 0)
|
||||
goto err;
|
||||
|
||||
if (secret_len != kat_secret_len
|
||||
|| memcmp(secret, kat_secret, secret_len) != 0)
|
||||
goto err;
|
||||
ret = 1;
|
||||
err:
|
||||
ossl_param_bld_free(params_peer);
|
||||
ossl_param_bld_free(params);
|
||||
BN_free(p);
|
||||
BN_free(q);
|
||||
BN_free(g);
|
||||
BN_free(pub);
|
||||
BN_free(priv);
|
||||
BN_free(pub_peer);
|
||||
OPENSSL_free(kat_secret);
|
||||
EVP_PKEY_free(pkey);
|
||||
EVP_PKEY_free(peerkey);
|
||||
EVP_PKEY_CTX_free(kactx);
|
||||
EVP_PKEY_CTX_free(dctx);
|
||||
return ret;
|
||||
}
|
||||
#endif /* OPENSSL_NO_DH */
|
||||
|
||||
/* TODO(3.0): To be removed */
|
||||
static int dummy_evp_call(void *provctx)
|
||||
{
|
||||
OPENSSL_CTX *libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
|
||||
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
|
||||
EVP_MD *sha256 = EVP_MD_fetch(libctx, "SHA256", NULL);
|
||||
EVP_KDF *kdf = EVP_KDF_fetch(libctx, OSSL_KDF_NAME_PBKDF2, NULL);
|
||||
unsigned char dgst[SHA256_DIGEST_LENGTH];
|
||||
unsigned int dgstlen;
|
||||
int ret = 0;
|
||||
BN_CTX *bnctx = NULL;
|
||||
BIGNUM *a = NULL, *b = NULL;
|
||||
@@ -243,6 +484,13 @@ static int dummy_evp_call(void *provctx)
|
||||
EC_KEY *key = NULL;
|
||||
#endif
|
||||
|
||||
static const char msg[] = "Hello World!";
|
||||
static const unsigned char exptd[] = {
|
||||
0x7f, 0x83, 0xb1, 0x65, 0x7f, 0xf1, 0xfc, 0x53, 0xb9, 0x2d, 0xc1, 0x81,
|
||||
0x48, 0xa1, 0xd6, 0x5d, 0xfc, 0x2d, 0x4b, 0x1f, 0xa3, 0xd6, 0x77, 0x28,
|
||||
0x4a, 0xdd, 0xd2, 0x00, 0x12, 0x6d, 0x90, 0x69
|
||||
};
|
||||
|
||||
if (ctx == NULL || sha256 == NULL || drbg == NULL || kdf == NULL)
|
||||
goto err;
|
||||
|
||||
@@ -284,54 +532,17 @@ static int dummy_evp_call(void *provctx)
|
||||
if (!EC_KEY_generate_key(key))
|
||||
goto err;
|
||||
#endif
|
||||
if (!rawnative_fromhex(dsa_p_hex, &dsa_p, &dsa_p_len)
|
||||
|| !rawnative_fromhex(dsa_q_hex, &dsa_q, &dsa_q_len)
|
||||
|| !rawnative_fromhex(dsa_g_hex, &dsa_g, &dsa_g_len)
|
||||
|| !rawnative_fromhex(dsa_pub_hex, &dsa_pub, &dsa_pub_len)
|
||||
|| !rawnative_fromhex(dsa_priv_hex, &dsa_priv, &dsa_priv_len))
|
||||
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
if (!dsa_key_signature_test(libctx))
|
||||
goto err;
|
||||
#endif
|
||||
|
||||
p = params;
|
||||
*p++ = OSSL_PARAM_construct_BN(OSSL_PKEY_PARAM_FFC_P, dsa_p, dsa_p_len);
|
||||
*p++ = OSSL_PARAM_construct_BN(OSSL_PKEY_PARAM_FFC_Q, dsa_q, dsa_q_len);
|
||||
*p++ = OSSL_PARAM_construct_BN(OSSL_PKEY_PARAM_FFC_G, dsa_g, dsa_g_len);
|
||||
*p++ = OSSL_PARAM_construct_BN(OSSL_PKEY_PARAM_DSA_PUB_KEY,
|
||||
dsa_pub, dsa_pub_len);
|
||||
*p++ = OSSL_PARAM_construct_BN(OSSL_PKEY_PARAM_DSA_PRIV_KEY,
|
||||
dsa_priv, dsa_priv_len);
|
||||
*p = OSSL_PARAM_construct_end();
|
||||
|
||||
kctx = EVP_PKEY_CTX_new_from_name(libctx, SN_dsa, "");
|
||||
if (kctx == NULL)
|
||||
goto err;
|
||||
if (EVP_PKEY_key_fromdata_init(kctx) <= 0
|
||||
|| EVP_PKEY_fromdata(kctx, &pkey, params) <= 0)
|
||||
#ifndef OPENSSL_NO_DH
|
||||
if (!dh_key_exchange_test(libctx))
|
||||
goto err;
|
||||
#endif /* OPENSSL_NO_DH */
|
||||
|
||||
sctx = EVP_PKEY_CTX_new_from_pkey(libctx, pkey);
|
||||
if (sctx == NULL)
|
||||
goto err;;
|
||||
|
||||
if (EVP_PKEY_sign_init(sctx) <= 0)
|
||||
goto err;
|
||||
|
||||
/* set signature parameters */
|
||||
sigdgstlen = SHA256_DIGEST_LENGTH;
|
||||
p = params;
|
||||
*p++ = OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST,
|
||||
SN_sha256,
|
||||
strlen(SN_sha256) + 1);
|
||||
|
||||
*p++ = OSSL_PARAM_construct_size_t(OSSL_SIGNATURE_PARAM_DIGEST_SIZE,
|
||||
&sigdgstlen);
|
||||
*p = OSSL_PARAM_construct_end();
|
||||
if (EVP_PKEY_CTX_set_params(sctx, params) <= 0)
|
||||
goto err;
|
||||
|
||||
if (EVP_PKEY_sign(sctx, sig, &siglen, dgst, sizeof(dgst)) <= 0
|
||||
|| EVP_PKEY_verify_init(sctx) <= 0
|
||||
|| EVP_PKEY_verify(sctx, sig, siglen, dgst, sizeof(dgst)) <= 0)
|
||||
goto err;
|
||||
ret = 1;
|
||||
err:
|
||||
BN_CTX_end(bnctx);
|
||||
@@ -344,14 +555,6 @@ static int dummy_evp_call(void *provctx)
|
||||
#ifndef OPENSSL_NO_EC
|
||||
EC_KEY_free(key);
|
||||
#endif
|
||||
OPENSSL_free(dsa_p);
|
||||
OPENSSL_free(dsa_q);
|
||||
OPENSSL_free(dsa_g);
|
||||
OPENSSL_free(dsa_pub);
|
||||
OPENSSL_free(dsa_priv);
|
||||
EVP_PKEY_free(pkey);
|
||||
EVP_PKEY_CTX_free(kctx);
|
||||
EVP_PKEY_CTX_free(sctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -588,6 +791,13 @@ static const OSSL_ALGORITHM fips_kdfs[] = {
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
static const OSSL_ALGORITHM fips_keyexch[] = {
|
||||
#ifndef OPENSSL_NO_DH
|
||||
{ "DH:dhKeyAgreement", "fips=yes", dh_keyexch_functions },
|
||||
#endif
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
static const OSSL_ALGORITHM fips_signature[] = {
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
{ "DSA:dsaEncryption", "fips=yes", dsa_signature_functions },
|
||||
@@ -596,6 +806,9 @@ static const OSSL_ALGORITHM fips_signature[] = {
|
||||
};
|
||||
|
||||
static const OSSL_ALGORITHM fips_keymgmt[] = {
|
||||
#ifndef OPENSSL_NO_DH
|
||||
{ "DH:dhKeyAgreement", "fips=yes", dh_keymgmt_functions },
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
{ "DSA", "fips=yes", dsa_keymgmt_functions },
|
||||
#endif
|
||||
@@ -619,6 +832,8 @@ static const OSSL_ALGORITHM *fips_query(OSSL_PROVIDER *prov,
|
||||
return fips_kdfs;
|
||||
case OSSL_OP_KEYMGMT:
|
||||
return fips_keymgmt;
|
||||
case OSSL_OP_KEYEXCH:
|
||||
return fips_keyexch;
|
||||
case OSSL_OP_SIGNATURE:
|
||||
return fips_signature;
|
||||
}
|
||||
|
||||
@@ -141,6 +141,7 @@ static const unsigned char aes_256_gcm_tag[] = {
|
||||
};
|
||||
|
||||
static const ST_KAT_CIPHER st_kat_cipher_tests[] = {
|
||||
#ifndef OPENSSL_NO_DES
|
||||
{
|
||||
{
|
||||
OSSL_SELF_TEST_DESC_CIPHER_TDES,
|
||||
@@ -151,6 +152,7 @@ static const ST_KAT_CIPHER st_kat_cipher_tests[] = {
|
||||
ITM(des_ede3_cbc_key),
|
||||
ITM(des_ede3_cbc_iv),
|
||||
},
|
||||
#endif
|
||||
{
|
||||
{
|
||||
OSSL_SELF_TEST_DESC_CIPHER_AES_GCM,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <string.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/kdf.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/nelem.h"
|
||||
#include "self_test.h"
|
||||
#include "self_test_data.inc"
|
||||
@@ -140,15 +141,20 @@ static int self_test_kdf(const ST_KAT_KDF *t, OSSL_ST_EVENT *event,
|
||||
OPENSSL_CTX *libctx)
|
||||
{
|
||||
int ret = 0;
|
||||
int i;
|
||||
int i, numparams;
|
||||
unsigned char out[64];
|
||||
EVP_KDF *kdf = NULL;
|
||||
EVP_KDF_CTX *ctx = NULL;
|
||||
OSSL_PARAM params[16];
|
||||
const OSSL_PARAM *settables = NULL;
|
||||
|
||||
numparams = OSSL_NELEM(params);
|
||||
SELF_TEST_EVENT_onbegin(event, OSSL_SELF_TEST_TYPE_KAT_KDF, t->desc);
|
||||
|
||||
/* Zeroize the params array to avoid mem leaks on error */
|
||||
for (i = 0; i < numparams; ++i)
|
||||
params[i] = OSSL_PARAM_construct_end();
|
||||
|
||||
kdf = EVP_KDF_fetch(libctx, t->algorithm, "");
|
||||
ctx = EVP_KDF_CTX_new(kdf);
|
||||
if (ctx == NULL)
|
||||
@@ -156,13 +162,14 @@ static int self_test_kdf(const ST_KAT_KDF *t, OSSL_ST_EVENT *event,
|
||||
|
||||
settables = EVP_KDF_settable_ctx_params(kdf);
|
||||
for (i = 0; t->ctrls[i].name != NULL; ++i) {
|
||||
if (!ossl_assert(i < (numparams - 1)))
|
||||
goto end;
|
||||
if (!OSSL_PARAM_allocate_from_text(¶ms[i], settables,
|
||||
t->ctrls[i].name,
|
||||
t->ctrls[i].value,
|
||||
strlen(t->ctrls[i].value)))
|
||||
goto end;
|
||||
}
|
||||
params[i] = OSSL_PARAM_construct_end();
|
||||
if (!EVP_KDF_CTX_set_params(ctx, params))
|
||||
goto end;
|
||||
|
||||
|
||||
@@ -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