Latest update.
This commit is contained in:
+3
-6
@@ -9,11 +9,8 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/evp.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "evp_locl.h"
|
||||
#include "internal/bio.h"
|
||||
|
||||
/*
|
||||
@@ -148,7 +145,7 @@ static long md_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
switch (cmd) {
|
||||
case BIO_CTRL_RESET:
|
||||
if (BIO_get_init(b))
|
||||
ret = EVP_DigestInit_ex(ctx, ctx->digest, NULL);
|
||||
ret = EVP_DigestInit_ex(ctx, EVP_MD_CTX_md(ctx), NULL);
|
||||
else
|
||||
ret = 0;
|
||||
if (ret > 0)
|
||||
@@ -157,7 +154,7 @@ static long md_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
case BIO_C_GET_MD:
|
||||
if (BIO_get_init(b)) {
|
||||
ppmd = ptr;
|
||||
*ppmd = ctx->digest;
|
||||
*ppmd = EVP_MD_CTX_md(ctx);
|
||||
} else
|
||||
ret = 0;
|
||||
break;
|
||||
@@ -223,7 +220,7 @@ static int md_gets(BIO *bp, char *buf, int size)
|
||||
|
||||
ctx = BIO_get_data(bp);
|
||||
|
||||
if (size < ctx->digest->md_size)
|
||||
if (size < EVP_MD_CTX_size(ctx))
|
||||
return 0;
|
||||
|
||||
if (EVP_DigestFinal_ex(ctx, (unsigned char *)buf, &ret) <= 0)
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@
|
||||
#include "internal/bio.h"
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/rand.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/evp.h"
|
||||
|
||||
static int ok_write(BIO *h, const char *buf, int num);
|
||||
static int ok_read(BIO *h, char *buf, int size);
|
||||
|
||||
+21
-7
@@ -1,23 +1,38 @@
|
||||
LIBS=../../libcrypto
|
||||
$COMMON=digest.c evp_enc.c evp_lib.c evp_fetch.c cmeth_lib.c evp_utils.c \
|
||||
mac_lib.c mac_meth.c keymgmt_meth.c keymgmt_lib.c kdf_lib.c kdf_meth.c
|
||||
mac_lib.c mac_meth.c keymgmt_meth.c keymgmt_lib.c kdf_lib.c kdf_meth.c \
|
||||
m_sigver.c
|
||||
SOURCE[../../libcrypto]=$COMMON\
|
||||
encode.c evp_key.c evp_cnf.c \
|
||||
e_des.c e_bf.c e_idea.c e_des3.c e_camellia.c\
|
||||
e_rc4.c e_aes.c names.c e_seed.c e_aria.c e_sm4.c \
|
||||
e_xcbc_d.c e_rc2.c e_cast.c e_rc5.c \
|
||||
m_null.c m_md2.c m_md4.c m_md5.c m_sha1.c m_wp.c \
|
||||
m_md5_sha1.c m_mdc2.c m_ripemd.c m_sha3.c \
|
||||
m_null.c m_wp.c m_ripemd.c \
|
||||
p_open.c p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c p_dec.c \
|
||||
bio_md.c bio_b64.c bio_enc.c evp_err.c e_null.c \
|
||||
c_allc.c c_alld.c bio_ok.c \
|
||||
evp_pkey.c evp_pbe.c p5_crpt.c p5_crpt2.c pbe_scrypt.c \
|
||||
pkey_kdf.c \
|
||||
e_old.c pmeth_lib.c pmeth_fn.c pmeth_gn.c m_sigver.c \
|
||||
e_old.c pmeth_lib.c pmeth_fn.c pmeth_gn.c \
|
||||
e_aes_cbc_hmac_sha1.c e_aes_cbc_hmac_sha256.c e_rc4_hmac_md5.c \
|
||||
e_chacha20_poly1305.c \
|
||||
pkey_mac.c exchange.c
|
||||
SOURCE[../../providers/fips]=$COMMON
|
||||
pkey_mac.c exchange.c \
|
||||
legacy_sha.c legacy_md5_sha1.c
|
||||
|
||||
IF[{- !$disabled{md2} -}]
|
||||
SOURCE[../../libcrypto]=legacy_md2.c
|
||||
ENDIF
|
||||
IF[{- !$disabled{md4} -}]
|
||||
SOURCE[../../libcrypto]=legacy_md4.c
|
||||
ENDIF
|
||||
IF[{- !$disabled{md5} -}]
|
||||
SOURCE[../../libcrypto]=legacy_md5.c
|
||||
ENDIF
|
||||
IF[{- !$disabled{mdc2} -}]
|
||||
SOURCE[../../libcrypto]=legacy_mdc2.c
|
||||
ENDIF
|
||||
|
||||
SOURCE[../../providers/libfips.a]=$COMMON
|
||||
|
||||
INCLUDE[e_aes.o]=.. ../modes
|
||||
INCLUDE[e_aes_cbc_hmac_sha1.o]=../modes
|
||||
@@ -27,4 +42,3 @@ INCLUDE[e_camellia.o]=.. ../modes
|
||||
INCLUDE[e_sm4.o]=.. ../modes
|
||||
INCLUDE[e_des.o]=..
|
||||
INCLUDE[e_des3.o]=..
|
||||
INCLUDE[m_sha3.o]=..
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
#include <stdio.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/evp.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/evp.h"
|
||||
#include <openssl/pkcs12.h>
|
||||
#include <openssl/objects.h>
|
||||
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
#include <stdio.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/evp.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/evp.h"
|
||||
#include <openssl/pkcs12.h>
|
||||
#include <openssl/objects.h>
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/evp.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "internal/provider.h"
|
||||
#include "evp_locl.h"
|
||||
#include "evp_local.h"
|
||||
|
||||
EVP_CIPHER *EVP_CIPHER_meth_new(int cipher_type, int block_size, int key_len)
|
||||
{
|
||||
|
||||
+135
-52
@@ -14,9 +14,9 @@
|
||||
#include <openssl/params.h>
|
||||
#include <openssl/core_names.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "internal/provider.h"
|
||||
#include "evp_locl.h"
|
||||
#include "evp_local.h"
|
||||
|
||||
/* This call frees resources associated with the context */
|
||||
int EVP_MD_CTX_reset(EVP_MD_CTX *ctx)
|
||||
@@ -24,8 +24,19 @@ int EVP_MD_CTX_reset(EVP_MD_CTX *ctx)
|
||||
if (ctx == NULL)
|
||||
return 1;
|
||||
|
||||
if (ctx->digest == NULL || ctx->digest->prov == NULL)
|
||||
goto legacy;
|
||||
#ifndef FIPS_MODE
|
||||
/* TODO(3.0): Temporarily no support for EVP_DigestSign* in FIPS module */
|
||||
/*
|
||||
* pctx should be freed by the user of EVP_MD_CTX
|
||||
* if EVP_MD_CTX_FLAG_KEEP_PKEY_CTX is set
|
||||
*/
|
||||
if (!EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX))
|
||||
EVP_PKEY_CTX_free(ctx->pctx);
|
||||
#endif
|
||||
|
||||
EVP_MD_free(ctx->fetched_digest);
|
||||
ctx->fetched_digest = NULL;
|
||||
ctx->reqdigest = NULL;
|
||||
|
||||
if (ctx->provctx != NULL) {
|
||||
if (ctx->digest->freectx != NULL)
|
||||
@@ -34,13 +45,7 @@ int EVP_MD_CTX_reset(EVP_MD_CTX *ctx)
|
||||
EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_CLEANED);
|
||||
}
|
||||
|
||||
if (ctx->pctx != NULL)
|
||||
goto legacy;
|
||||
|
||||
return 1;
|
||||
|
||||
/* TODO(3.0): Remove legacy code below */
|
||||
legacy:
|
||||
|
||||
/*
|
||||
* Don't assume ctx->md_data was cleaned in EVP_Digest_Final, because
|
||||
@@ -53,19 +58,13 @@ int EVP_MD_CTX_reset(EVP_MD_CTX *ctx)
|
||||
&& !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE)) {
|
||||
OPENSSL_clear_free(ctx->md_data, ctx->digest->ctx_size);
|
||||
}
|
||||
/*
|
||||
* pctx should be freed by the user of EVP_MD_CTX
|
||||
* if EVP_MD_CTX_FLAG_KEEP_PKEY_CTX is set
|
||||
*/
|
||||
#ifndef FIPS_MODE
|
||||
/* TODO(3.0): Temporarily no support for EVP_DigestSign* in FIPS module */
|
||||
if (!EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX))
|
||||
EVP_PKEY_CTX_free(ctx->pctx);
|
||||
|
||||
# ifndef OPENSSL_NO_ENGINE
|
||||
#if !defined(FIPS_MODE) && !defined(OPENSSL_NO_ENGINE)
|
||||
ENGINE_finish(ctx->engine);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* TODO(3.0): End of legacy code */
|
||||
|
||||
OPENSSL_cleanse(ctx, sizeof(*ctx));
|
||||
|
||||
return 1;
|
||||
@@ -81,23 +80,10 @@ void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
|
||||
if (ctx == NULL)
|
||||
return;
|
||||
|
||||
if (ctx->digest == NULL || ctx->digest->prov == NULL)
|
||||
goto legacy;
|
||||
|
||||
EVP_MD_CTX_reset(ctx);
|
||||
|
||||
EVP_MD_free(ctx->fetched_digest);
|
||||
ctx->fetched_digest = NULL;
|
||||
ctx->digest = NULL;
|
||||
ctx->reqdigest = NULL;
|
||||
|
||||
OPENSSL_free(ctx);
|
||||
return;
|
||||
|
||||
/* TODO(3.0): Remove legacy code below */
|
||||
legacy:
|
||||
EVP_MD_CTX_reset(ctx);
|
||||
OPENSSL_free(ctx);
|
||||
}
|
||||
|
||||
int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)
|
||||
@@ -114,6 +100,16 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
|
||||
|
||||
EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_CLEANED);
|
||||
|
||||
if (ctx->provctx != NULL) {
|
||||
if (!ossl_assert(ctx->digest != NULL)) {
|
||||
EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_INITIALIZATION_ERROR);
|
||||
return 0;
|
||||
}
|
||||
if (ctx->digest->freectx != NULL)
|
||||
ctx->digest->freectx(ctx->provctx);
|
||||
ctx->provctx = NULL;
|
||||
}
|
||||
|
||||
if (type != NULL)
|
||||
ctx->reqdigest = type;
|
||||
|
||||
@@ -144,15 +140,14 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If there are engines involved or if we're being used as part of
|
||||
* EVP_DigestSignInit then we should use legacy handling for now.
|
||||
* If there are engines involved or EVP_MD_CTX_FLAG_NO_INIT is set then we
|
||||
* should use legacy handling for now.
|
||||
*/
|
||||
if (ctx->engine != NULL
|
||||
|| impl != NULL
|
||||
#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)
|
||||
|| tmpimpl != NULL
|
||||
#endif
|
||||
|| ctx->pctx != NULL
|
||||
|| (ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) != 0) {
|
||||
if (ctx->digest == ctx->fetched_digest)
|
||||
ctx->digest = NULL;
|
||||
@@ -290,6 +285,24 @@ int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t count)
|
||||
if (count == 0)
|
||||
return 1;
|
||||
|
||||
if (ctx->pctx != NULL
|
||||
&& EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx->pctx)
|
||||
&& ctx->pctx->op.sig.sigprovctx != NULL) {
|
||||
/*
|
||||
* Prior to OpenSSL 3.0 EVP_DigestSignUpdate() and
|
||||
* EVP_DigestVerifyUpdate() were just macros for EVP_DigestUpdate().
|
||||
* Some code calls EVP_DigestUpdate() directly even when initialised
|
||||
* with EVP_DigestSignInit_ex() or EVP_DigestVerifyInit_ex(), so we
|
||||
* detect that and redirect to the correct EVP_Digest*Update() function
|
||||
*/
|
||||
if (ctx->pctx->operation == EVP_PKEY_OP_SIGNCTX)
|
||||
return EVP_DigestSignUpdate(ctx, data, count);
|
||||
if (ctx->pctx->operation == EVP_PKEY_OP_VERIFYCTX)
|
||||
return EVP_DigestVerifyUpdate(ctx, data, count);
|
||||
EVPerr(EVP_F_EVP_DIGESTUPDATE, EVP_R_UPDATE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ctx->digest == NULL || ctx->digest->prov == NULL)
|
||||
goto legacy;
|
||||
|
||||
@@ -339,7 +352,6 @@ int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *isize)
|
||||
}
|
||||
}
|
||||
|
||||
EVP_MD_CTX_reset(ctx);
|
||||
return ret;
|
||||
|
||||
/* TODO(3.0): Remove legacy code below */
|
||||
@@ -545,29 +557,92 @@ const OSSL_PARAM *EVP_MD_gettable_params(const EVP_MD *digest)
|
||||
|
||||
int EVP_MD_CTX_set_params(EVP_MD_CTX *ctx, const OSSL_PARAM params[])
|
||||
{
|
||||
EVP_PKEY_CTX *pctx = ctx->pctx;
|
||||
|
||||
if (ctx->digest != NULL && ctx->digest->set_ctx_params != NULL)
|
||||
return ctx->digest->set_ctx_params(ctx->provctx, params);
|
||||
|
||||
if (pctx != NULL
|
||||
&& (pctx->operation == EVP_PKEY_OP_VERIFYCTX
|
||||
|| pctx->operation == EVP_PKEY_OP_SIGNCTX)
|
||||
&& pctx->op.sig.sigprovctx != NULL
|
||||
&& pctx->op.sig.signature->set_ctx_md_params != NULL)
|
||||
return pctx->op.sig.signature->set_ctx_md_params(pctx->op.sig.sigprovctx,
|
||||
params);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const OSSL_PARAM *EVP_MD_CTX_settable_params(const EVP_MD *digest)
|
||||
const OSSL_PARAM *EVP_MD_settable_ctx_params(const EVP_MD *md)
|
||||
{
|
||||
if (digest != NULL && digest->settable_ctx_params != NULL)
|
||||
return digest->settable_ctx_params();
|
||||
if (md != NULL && md->settable_ctx_params != NULL)
|
||||
return md->settable_ctx_params();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const OSSL_PARAM *EVP_MD_CTX_settable_params(EVP_MD_CTX *ctx)
|
||||
{
|
||||
EVP_PKEY_CTX *pctx;
|
||||
|
||||
if (ctx != NULL
|
||||
&& ctx->digest != NULL
|
||||
&& ctx->digest->settable_ctx_params != NULL)
|
||||
return ctx->digest->settable_ctx_params();
|
||||
|
||||
pctx = ctx->pctx;
|
||||
if (pctx != NULL
|
||||
&& (pctx->operation == EVP_PKEY_OP_VERIFYCTX
|
||||
|| pctx->operation == EVP_PKEY_OP_SIGNCTX)
|
||||
&& pctx->op.sig.sigprovctx != NULL
|
||||
&& pctx->op.sig.signature->settable_ctx_md_params != NULL)
|
||||
return pctx->op.sig.signature->settable_ctx_md_params(
|
||||
pctx->op.sig.sigprovctx);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int EVP_MD_CTX_get_params(EVP_MD_CTX *ctx, OSSL_PARAM params[])
|
||||
{
|
||||
EVP_PKEY_CTX *pctx = ctx->pctx;
|
||||
|
||||
if (ctx->digest != NULL && ctx->digest->get_params != NULL)
|
||||
return ctx->digest->get_ctx_params(ctx->provctx, params);
|
||||
|
||||
if (pctx != NULL
|
||||
&& (pctx->operation == EVP_PKEY_OP_VERIFYCTX
|
||||
|| pctx->operation == EVP_PKEY_OP_SIGNCTX)
|
||||
&& pctx->op.sig.sigprovctx != NULL
|
||||
&& pctx->op.sig.signature->get_ctx_md_params != NULL)
|
||||
return pctx->op.sig.signature->get_ctx_md_params(pctx->op.sig.sigprovctx,
|
||||
params);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const OSSL_PARAM *EVP_MD_CTX_gettable_params(const EVP_MD *digest)
|
||||
const OSSL_PARAM *EVP_MD_gettable_ctx_params(const EVP_MD *md)
|
||||
{
|
||||
if (digest != NULL && digest->gettable_ctx_params != NULL)
|
||||
return digest->gettable_ctx_params();
|
||||
if (md != NULL && md->gettable_ctx_params != NULL)
|
||||
return md->gettable_ctx_params();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const OSSL_PARAM *EVP_MD_CTX_gettable_params(EVP_MD_CTX *ctx)
|
||||
{
|
||||
EVP_PKEY_CTX *pctx;
|
||||
|
||||
if (ctx != NULL
|
||||
&& ctx->digest != NULL
|
||||
&& ctx->digest->gettable_ctx_params != NULL)
|
||||
return ctx->digest->gettable_ctx_params();
|
||||
|
||||
pctx = ctx->pctx;
|
||||
if (pctx != NULL
|
||||
&& (pctx->operation == EVP_PKEY_OP_VERIFYCTX
|
||||
|| pctx->operation == EVP_PKEY_OP_SIGNCTX)
|
||||
&& pctx->op.sig.sigprovctx != NULL
|
||||
&& pctx->op.sig.signature->gettable_ctx_md_params != NULL)
|
||||
return pctx->op.sig.signature->gettable_ctx_md_params(
|
||||
pctx->op.sig.sigprovctx);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -584,7 +659,10 @@ int EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ctx->digest->prov == NULL)
|
||||
if (ctx->digest->prov == NULL
|
||||
&& (ctx->pctx == NULL
|
||||
|| (ctx->pctx->operation != EVP_PKEY_OP_VERIFYCTX
|
||||
&& ctx->pctx->operation != EVP_PKEY_OP_SIGNCTX)))
|
||||
goto legacy;
|
||||
|
||||
switch (cmd) {
|
||||
@@ -597,15 +675,19 @@ int EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2)
|
||||
params[0] = OSSL_PARAM_construct_utf8_string(OSSL_DIGEST_PARAM_MICALG,
|
||||
p2, p1 ? p1 : 9999);
|
||||
break;
|
||||
case EVP_CTRL_SSL3_MASTER_SECRET:
|
||||
params[0] = OSSL_PARAM_construct_octet_string(OSSL_DIGEST_PARAM_SSL3_MS,
|
||||
p2, p1);
|
||||
break;
|
||||
default:
|
||||
return EVP_CTRL_RET_UNSUPPORTED;
|
||||
goto conclude;
|
||||
}
|
||||
|
||||
if (set_params)
|
||||
ret = evp_do_md_ctx_setparams(ctx->digest, ctx->provctx, params);
|
||||
ret = EVP_MD_CTX_set_params(ctx, params);
|
||||
else
|
||||
ret = evp_do_md_ctx_getparams(ctx->digest, ctx->provctx, params);
|
||||
return ret;
|
||||
ret = EVP_MD_CTX_get_params(ctx, params);
|
||||
goto conclude;
|
||||
|
||||
|
||||
/* TODO(3.0): Remove legacy code below */
|
||||
@@ -616,6 +698,7 @@ int EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2)
|
||||
}
|
||||
|
||||
ret = ctx->digest->md_ctrl(ctx, cmd, p1, p2);
|
||||
conclude:
|
||||
if (ret <= 0)
|
||||
return 0;
|
||||
return ret;
|
||||
@@ -677,7 +760,7 @@ static void *evp_md_from_dispatch(int name_id,
|
||||
#ifndef FIPS_MODE
|
||||
/* TODO(3.x) get rid of the need for legacy NIDs */
|
||||
md->type = NID_undef;
|
||||
evp_doall_names(prov, name_id, set_legacy_nid, &md->type);
|
||||
evp_names_do_all(prov, name_id, set_legacy_nid, &md->type);
|
||||
if (md->type == -1) {
|
||||
ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
|
||||
EVP_MD_free(md);
|
||||
@@ -819,9 +902,9 @@ void EVP_MD_free(EVP_MD *md)
|
||||
OPENSSL_free(md);
|
||||
}
|
||||
|
||||
void EVP_MD_do_all_ex(OPENSSL_CTX *libctx,
|
||||
void (*fn)(EVP_MD *mac, void *arg),
|
||||
void *arg)
|
||||
void EVP_MD_do_all_provided(OPENSSL_CTX *libctx,
|
||||
void (*fn)(EVP_MD *mac, void *arg),
|
||||
void *arg)
|
||||
{
|
||||
evp_generic_do_all(libctx, OSSL_OP_DIGEST,
|
||||
(void (*)(void *, void *))fn, arg,
|
||||
|
||||
+6
-6
@@ -16,12 +16,12 @@
|
||||
#include <openssl/aes.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/cmac.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/modes_int.h"
|
||||
#include "internal/siv_int.h"
|
||||
#include "internal/ciphermode_platform.h"
|
||||
#include "evp_locl.h"
|
||||
#include "crypto/modes.h"
|
||||
#include "crypto/siv.h"
|
||||
#include "crypto/ciphermode_platform.h"
|
||||
#include "evp_local.h"
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
@@ -3744,7 +3744,7 @@ static int aes_ocb_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
|
||||
return 1;
|
||||
|
||||
case EVP_CTRL_AEAD_SET_TAG:
|
||||
if (!ptr) {
|
||||
if (ptr == NULL) {
|
||||
/* Tag len must be 0 to 16 */
|
||||
if (arg < 0 || arg > 16)
|
||||
return 0;
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/rand.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/modes_int.h"
|
||||
#include "internal/evp_int.h"
|
||||
#include "internal/constant_time_locl.h"
|
||||
#include "crypto/modes.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "internal/constant_time.h"
|
||||
|
||||
typedef struct {
|
||||
AES_KEY ks;
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/rand.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/modes_int.h"
|
||||
#include "internal/constant_time_locl.h"
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/modes.h"
|
||||
#include "internal/constant_time.h"
|
||||
#include "crypto/evp.h"
|
||||
|
||||
typedef struct {
|
||||
AES_KEY ks;
|
||||
|
||||
+4
-4
@@ -14,10 +14,10 @@
|
||||
# include <openssl/modes.h>
|
||||
# include <openssl/rand.h>
|
||||
# include <openssl/rand_drbg.h>
|
||||
# include "internal/aria.h"
|
||||
# include "internal/evp_int.h"
|
||||
# include "internal/modes_int.h"
|
||||
# include "evp_locl.h"
|
||||
# include "crypto/aria.h"
|
||||
# include "crypto/evp.h"
|
||||
# include "crypto/modes.h"
|
||||
# include "evp_local.h"
|
||||
|
||||
/* ARIA subkey Structure */
|
||||
typedef struct {
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
#include "internal/cryptlib.h"
|
||||
#ifndef OPENSSL_NO_BF
|
||||
# include <openssl/evp.h>
|
||||
# include "internal/evp_int.h"
|
||||
# include "crypto/evp.h"
|
||||
# include <openssl/objects.h>
|
||||
# include <openssl/blowfish.h>
|
||||
|
||||
|
||||
@@ -17,9 +17,9 @@ NON_EMPTY_TRANSLATION_UNIT
|
||||
# include <string.h>
|
||||
# include <assert.h>
|
||||
# include <openssl/camellia.h>
|
||||
# include "internal/evp_int.h"
|
||||
# include "internal/modes_int.h"
|
||||
# include "internal/ciphermode_platform.h"
|
||||
# include "crypto/evp.h"
|
||||
# include "crypto/modes.h"
|
||||
# include "crypto/ciphermode_platform.h"
|
||||
|
||||
static int camellia_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
const unsigned char *iv, int enc);
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
#ifndef OPENSSL_NO_CAST
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/objects.h>
|
||||
# include "internal/evp_int.h"
|
||||
# include "crypto/evp.h"
|
||||
# include <openssl/cast.h>
|
||||
|
||||
static int cast_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/objects.h>
|
||||
# include "internal/evp_int.h"
|
||||
# include "evp_locl.h"
|
||||
# include "internal/chacha.h"
|
||||
# include "crypto/evp.h"
|
||||
# include "evp_local.h"
|
||||
# include "crypto/chacha.h"
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
@@ -146,7 +146,7 @@ const EVP_CIPHER *EVP_chacha20(void)
|
||||
}
|
||||
|
||||
# ifndef OPENSSL_NO_POLY1305
|
||||
# include "internal/poly1305.h"
|
||||
# include "crypto/poly1305.h"
|
||||
|
||||
typedef struct {
|
||||
EVP_CHACHA_KEY key;
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
#ifndef OPENSSL_NO_DES
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/objects.h>
|
||||
# include "internal/evp_int.h"
|
||||
# include "crypto/evp.h"
|
||||
# include <openssl/des.h>
|
||||
# include <openssl/rand.h>
|
||||
|
||||
|
||||
+2
-2
@@ -12,10 +12,10 @@
|
||||
#ifndef OPENSSL_NO_DES
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/objects.h>
|
||||
# include "internal/evp_int.h"
|
||||
# include "crypto/evp.h"
|
||||
# include <openssl/des.h>
|
||||
# include <openssl/rand.h>
|
||||
# include "evp_locl.h"
|
||||
# include "evp_local.h"
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
#ifndef OPENSSL_NO_IDEA
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/objects.h>
|
||||
# include "internal/evp_int.h"
|
||||
# include "crypto/evp.h"
|
||||
# include <openssl/idea.h>
|
||||
|
||||
/* Can't use IMPLEMENT_BLOCK_CIPHER because IDEA_ecb_encrypt is different */
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/objects.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/evp.h"
|
||||
|
||||
static int null_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
const unsigned char *iv, int enc);
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/objects.h>
|
||||
# include "internal/evp_int.h"
|
||||
# include "crypto/evp.h"
|
||||
# include <openssl/rc2.h>
|
||||
|
||||
static int rc2_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
# include <openssl/objects.h>
|
||||
# include <openssl/rc4.h>
|
||||
|
||||
# include "internal/evp_int.h"
|
||||
# include "crypto/evp.h"
|
||||
|
||||
typedef struct {
|
||||
RC4_KEY ks; /* working key */
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
# include <openssl/objects.h>
|
||||
# include <openssl/rc4.h>
|
||||
# include <openssl/md5.h>
|
||||
# include "internal/evp_int.h"
|
||||
# include "crypto/evp.h"
|
||||
|
||||
typedef struct {
|
||||
RC4_KEY ks;
|
||||
|
||||
+2
-2
@@ -13,9 +13,9 @@
|
||||
#ifndef OPENSSL_NO_RC5
|
||||
|
||||
# include <openssl/evp.h>
|
||||
# include "internal/evp_int.h"
|
||||
# include "crypto/evp.h"
|
||||
# include <openssl/objects.h>
|
||||
# include "evp_locl.h"
|
||||
# include "evp_local.h"
|
||||
# include <openssl/rc5.h>
|
||||
|
||||
static int r_32_12_16_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ NON_EMPTY_TRANSLATION_UNIT
|
||||
# include <string.h>
|
||||
# include <assert.h>
|
||||
# include <openssl/seed.h>
|
||||
# include "internal/evp_int.h"
|
||||
# include "crypto/evp.h"
|
||||
|
||||
static int seed_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
const unsigned char *iv, int enc);
|
||||
|
||||
+2
-2
@@ -13,8 +13,8 @@
|
||||
#ifndef OPENSSL_NO_SM4
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/modes.h>
|
||||
# include "internal/sm4.h"
|
||||
# include "internal/evp_int.h"
|
||||
# include "crypto/sm4.h"
|
||||
# include "crypto/evp.h"
|
||||
|
||||
typedef struct {
|
||||
SM4_KEY ks;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/objects.h>
|
||||
# include "internal/evp_int.h"
|
||||
# include "crypto/evp.h"
|
||||
# include <openssl/des.h>
|
||||
|
||||
static int desx_cbc_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
|
||||
+2
-2
@@ -11,8 +11,8 @@
|
||||
#include <limits.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/evp.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "evp_locl.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "evp_local.h"
|
||||
|
||||
static unsigned char conv_ascii2bin(unsigned char a,
|
||||
const unsigned char *table);
|
||||
|
||||
+57
-26
@@ -17,9 +17,9 @@
|
||||
#include <openssl/engine.h>
|
||||
#include <openssl/params.h>
|
||||
#include <openssl/core_names.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "internal/provider.h"
|
||||
#include "evp_locl.h"
|
||||
#include "evp_local.h"
|
||||
|
||||
int EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *ctx)
|
||||
{
|
||||
@@ -267,6 +267,19 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
|
||||
case NID_sm4_ctr:
|
||||
case NID_sm4_cfb128:
|
||||
case NID_sm4_ofb128:
|
||||
case NID_rc4:
|
||||
case NID_rc4_40:
|
||||
case NID_rc5_cbc:
|
||||
case NID_rc5_ecb:
|
||||
case NID_rc5_cfb64:
|
||||
case NID_rc5_ofb64:
|
||||
case NID_rc2_cbc:
|
||||
case NID_rc2_40_cbc:
|
||||
case NID_rc2_64_cbc:
|
||||
case NID_rc2_cfb64:
|
||||
case NID_rc2_ofb64:
|
||||
case NID_chacha20:
|
||||
case NID_chacha20_poly1305:
|
||||
break;
|
||||
default:
|
||||
goto legacy;
|
||||
@@ -335,19 +348,6 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (EVP_CIPHER_mode(ctx->cipher)) {
|
||||
case EVP_CIPH_CFB_MODE:
|
||||
case EVP_CIPH_OFB_MODE:
|
||||
case EVP_CIPH_CBC_MODE:
|
||||
/* For these modes we remember the original IV for later use */
|
||||
if (!ossl_assert(EVP_CIPHER_CTX_iv_length(ctx) <= (int)sizeof(ctx->oiv))) {
|
||||
EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_INITIALIZATION_ERROR);
|
||||
return 0;
|
||||
}
|
||||
if (iv != NULL)
|
||||
memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx));
|
||||
}
|
||||
|
||||
if (enc) {
|
||||
if (ctx->cipher->einit == NULL) {
|
||||
EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_INITIALIZATION_ERROR);
|
||||
@@ -1067,6 +1067,7 @@ int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
|
||||
int ret = EVP_CTRL_RET_UNSUPPORTED;
|
||||
int set_params = 1;
|
||||
size_t sz = arg;
|
||||
unsigned int i;
|
||||
OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
|
||||
|
||||
if (ctx == NULL || ctx->cipher == NULL) {
|
||||
@@ -1088,10 +1089,18 @@ int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
|
||||
ptr, sz);
|
||||
break;
|
||||
|
||||
case EVP_CTRL_INIT:
|
||||
/*
|
||||
* TODO(3.0) EVP_CTRL_INIT is purely legacy, no provider counterpart
|
||||
* As a matter of fact, this should be dead code, but some caller
|
||||
* might still do a direct control call with this command, so...
|
||||
* Legacy methods return 1 except for exceptional circumstances, so
|
||||
* we do the same here to not be disruptive.
|
||||
*/
|
||||
return 1;
|
||||
case EVP_CTRL_SET_PIPELINE_OUTPUT_BUFS: /* Used by DASYNC */
|
||||
case EVP_CTRL_INIT: /* TODO(3.0) Purely legacy, no provider counterpart */
|
||||
default:
|
||||
return EVP_CTRL_RET_UNSUPPORTED;
|
||||
goto end;
|
||||
case EVP_CTRL_GET_IV:
|
||||
set_params = 0;
|
||||
params[0] = OSSL_PARAM_construct_octet_string(OSSL_CIPHER_PARAM_IV,
|
||||
@@ -1107,12 +1116,25 @@ int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
|
||||
OSSL_PARAM_construct_octet_string(OSSL_CIPHER_PARAM_AEAD_TLS1_IV_FIXED,
|
||||
ptr, sz);
|
||||
break;
|
||||
case EVP_CTRL_GET_RC5_ROUNDS:
|
||||
set_params = 0; /* Fall thru */
|
||||
case EVP_CTRL_SET_RC5_ROUNDS:
|
||||
if (arg < 0)
|
||||
return 0;
|
||||
i = (unsigned int)arg;
|
||||
params[0] = OSSL_PARAM_construct_uint(OSSL_CIPHER_PARAM_ROUNDS, &i);
|
||||
break;
|
||||
case EVP_CTRL_AEAD_GET_TAG:
|
||||
set_params = 0; /* Fall thru */
|
||||
case EVP_CTRL_AEAD_SET_TAG:
|
||||
params[0] = OSSL_PARAM_construct_octet_string(OSSL_CIPHER_PARAM_AEAD_TAG,
|
||||
ptr, sz);
|
||||
break;
|
||||
case EVP_CTRL_AEAD_SET_MAC_KEY:
|
||||
params[0] =
|
||||
OSSL_PARAM_construct_octet_string(OSSL_CIPHER_PARAM_AEAD_MAC_KEY,
|
||||
ptr, sz);
|
||||
break;
|
||||
case EVP_CTRL_AEAD_TLS1_AAD:
|
||||
/* This one does a set and a get - since it returns a padding size */
|
||||
params[0] =
|
||||
@@ -1120,20 +1142,27 @@ int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
|
||||
ptr, sz);
|
||||
ret = evp_do_ciph_ctx_setparams(ctx->cipher, ctx->provctx, params);
|
||||
if (ret <= 0)
|
||||
return ret;
|
||||
goto end;
|
||||
params[0] =
|
||||
OSSL_PARAM_construct_size_t(OSSL_CIPHER_PARAM_AEAD_TLS1_AAD_PAD, &sz);
|
||||
ret = evp_do_ciph_ctx_getparams(ctx->cipher, ctx->provctx, params);
|
||||
if (ret <= 0)
|
||||
return 0;
|
||||
goto end;
|
||||
return sz;
|
||||
#ifndef OPENSSL_NO_RC2
|
||||
case EVP_CTRL_GET_RC2_KEY_BITS:
|
||||
set_params = 0; /* Fall thru */
|
||||
case EVP_CTRL_SET_RC2_KEY_BITS:
|
||||
params[0] = OSSL_PARAM_construct_size_t(OSSL_CIPHER_PARAM_RC2_KEYBITS, &sz);
|
||||
break;
|
||||
#endif /* OPENSSL_NO_RC2 */
|
||||
}
|
||||
|
||||
if (set_params)
|
||||
ret = evp_do_ciph_ctx_setparams(ctx->cipher, ctx->provctx, params);
|
||||
else
|
||||
ret = evp_do_ciph_ctx_getparams(ctx->cipher, ctx->provctx, params);
|
||||
return ret;
|
||||
goto end;
|
||||
|
||||
/* TODO(3.0): Remove legacy code below */
|
||||
legacy:
|
||||
@@ -1143,6 +1172,8 @@ legacy:
|
||||
}
|
||||
|
||||
ret = ctx->cipher->ctrl(ctx, type, arg, ptr);
|
||||
|
||||
end:
|
||||
if (ret == EVP_CTRL_RET_UNSUPPORTED) {
|
||||
EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL,
|
||||
EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED);
|
||||
@@ -1179,14 +1210,14 @@ const OSSL_PARAM *EVP_CIPHER_gettable_params(const EVP_CIPHER *cipher)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const OSSL_PARAM *EVP_CIPHER_CTX_settable_params(const EVP_CIPHER *cipher)
|
||||
const OSSL_PARAM *EVP_CIPHER_settable_ctx_params(const EVP_CIPHER *cipher)
|
||||
{
|
||||
if (cipher != NULL && cipher->settable_ctx_params != NULL)
|
||||
return cipher->settable_ctx_params();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const OSSL_PARAM *EVP_CIPHER_CTX_gettable_params(const EVP_CIPHER *cipher)
|
||||
const OSSL_PARAM *EVP_CIPHER_gettable_ctx_params(const EVP_CIPHER *cipher)
|
||||
{
|
||||
if (cipher != NULL && cipher->gettable_ctx_params != NULL)
|
||||
return cipher->gettable_ctx_params();
|
||||
@@ -1334,7 +1365,7 @@ static void *evp_cipher_from_dispatch(const int name_id,
|
||||
#ifndef FIPS_MODE
|
||||
/* TODO(3.x) get rid of the need for legacy NIDs */
|
||||
cipher->nid = NID_undef;
|
||||
evp_doall_names(prov, name_id, set_legacy_nid, &cipher->nid);
|
||||
evp_names_do_all(prov, name_id, set_legacy_nid, &cipher->nid);
|
||||
if (cipher->nid == -1) {
|
||||
ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
|
||||
EVP_CIPHER_free(cipher);
|
||||
@@ -1490,9 +1521,9 @@ void EVP_CIPHER_free(EVP_CIPHER *cipher)
|
||||
OPENSSL_free(cipher);
|
||||
}
|
||||
|
||||
void EVP_CIPHER_do_all_ex(OPENSSL_CTX *libctx,
|
||||
void (*fn)(EVP_CIPHER *mac, void *arg),
|
||||
void *arg)
|
||||
void EVP_CIPHER_do_all_provided(OPENSSL_CTX *libctx,
|
||||
void (*fn)(EVP_CIPHER *mac, void *arg),
|
||||
void *arg)
|
||||
{
|
||||
evp_generic_do_all(libctx, OSSL_OP_CIPHER,
|
||||
(void (*)(void *, void *))fn, arg,
|
||||
|
||||
@@ -18,6 +18,7 @@ static const ERR_STRING_DATA EVP_str_reasons[] = {
|
||||
"aes key setup failed"},
|
||||
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_ARIA_KEY_SETUP_FAILED),
|
||||
"aria key setup failed"},
|
||||
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_BAD_ALGORITHM_NAME), "bad algorithm name"},
|
||||
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_BAD_DECRYPT), "bad decrypt"},
|
||||
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_BAD_KEY_LENGTH), "bad key length"},
|
||||
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_BUFFER_TOO_SMALL), "buffer too small"},
|
||||
@@ -33,6 +34,8 @@ static const ERR_STRING_DATA EVP_str_reasons[] = {
|
||||
"cipher parameter error"},
|
||||
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_COMMAND_NOT_SUPPORTED),
|
||||
"command not supported"},
|
||||
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_CONFLICTING_ALGORITHM_NAME),
|
||||
"conflicting algorithm name"},
|
||||
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_COPY_ERROR), "copy error"},
|
||||
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_CTRL_NOT_IMPLEMENTED),
|
||||
"ctrl not implemented"},
|
||||
|
||||
+98
-22
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <openssl/ossl_typ.h>
|
||||
#include <openssl/types.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/core.h>
|
||||
#include "internal/cryptlib.h"
|
||||
@@ -17,8 +17,10 @@
|
||||
#include "internal/core.h"
|
||||
#include "internal/provider.h"
|
||||
#include "internal/namemap.h"
|
||||
#include "internal/evp_int.h" /* evp_locl.h needs it */
|
||||
#include "evp_locl.h"
|
||||
#include "crypto/evp.h" /* evp_local.h needs it */
|
||||
#include "evp_local.h"
|
||||
|
||||
#define NAME_SEPARATOR ':'
|
||||
|
||||
static void default_method_store_free(void *vstore)
|
||||
{
|
||||
@@ -42,7 +44,7 @@ struct method_data_st {
|
||||
OSSL_METHOD_CONSTRUCT_METHOD *mcm;
|
||||
int operation_id; /* For get_method_from_store() */
|
||||
int name_id; /* For get_method_from_store() */
|
||||
const char *name; /* For get_method_from_store() */
|
||||
const char *names; /* For get_method_from_store() */
|
||||
const char *propquery; /* For get_method_from_store() */
|
||||
void *(*method_from_dispatch)(int name_id, const OSSL_DISPATCH *,
|
||||
OSSL_PROVIDER *, void *);
|
||||
@@ -51,6 +53,69 @@ struct method_data_st {
|
||||
void (*destruct_method)(void *method);
|
||||
};
|
||||
|
||||
static int add_names_to_namemap(OSSL_NAMEMAP *namemap,
|
||||
const char *names)
|
||||
{
|
||||
const char *p, *q;
|
||||
size_t l;
|
||||
int id = 0;
|
||||
|
||||
/* Check that we have a namemap and that there is at least one name */
|
||||
if (namemap == NULL) {
|
||||
ERR_raise(ERR_LIB_EVP, ERR_R_PASSED_NULL_PARAMETER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check that no name is an empty string, and that all names have at
|
||||
* most one numeric identity together.
|
||||
*/
|
||||
for (p = names; *p != '\0'; p = (q == NULL ? p + l : q + 1)) {
|
||||
int this_id;
|
||||
|
||||
if ((q = strchr(p, NAME_SEPARATOR)) == NULL)
|
||||
l = strlen(p); /* offset to \0 */
|
||||
else
|
||||
l = q - p; /* offset to the next separator */
|
||||
|
||||
this_id = ossl_namemap_name2num_n(namemap, p, l);
|
||||
|
||||
if (*p == '\0' || *p == NAME_SEPARATOR) {
|
||||
ERR_raise(ERR_LIB_EVP, EVP_R_BAD_ALGORITHM_NAME);
|
||||
return 0;
|
||||
}
|
||||
if (id == 0)
|
||||
id = this_id;
|
||||
else if (this_id != 0 && this_id != id) {
|
||||
ERR_raise_data(ERR_LIB_EVP, EVP_R_CONFLICTING_ALGORITHM_NAME,
|
||||
"\"%.*s\" has an existing different identity %d (from \"%s\")",
|
||||
l, p, this_id, names);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Now that we have checked, register all names */
|
||||
for (p = names; *p != '\0'; p = (q == NULL ? p + l : q + 1)) {
|
||||
int this_id;
|
||||
|
||||
if ((q = strchr(p, NAME_SEPARATOR)) == NULL)
|
||||
l = strlen(p); /* offset to \0 */
|
||||
else
|
||||
l = q - p; /* offset to the next separator */
|
||||
|
||||
this_id = ossl_namemap_add_n(namemap, id, p, l);
|
||||
if (id == 0)
|
||||
id = this_id;
|
||||
else if (this_id != id) {
|
||||
ERR_raise_data(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR,
|
||||
"Got id %d when expecting %d", this_id, id);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
/*
|
||||
* Generic routines to fetch / create EVP methods with ossl_method_construct()
|
||||
*/
|
||||
@@ -105,10 +170,13 @@ static void *get_method_from_store(OPENSSL_CTX *libctx, void *store,
|
||||
*/
|
||||
if ((name_id = methdata->name_id) == 0) {
|
||||
OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx);
|
||||
const char *names = methdata->names;
|
||||
const char *q = strchr(names, NAME_SEPARATOR);
|
||||
size_t l = (q == NULL ? strlen(names) : (size_t)(q - names));
|
||||
|
||||
if (namemap == 0)
|
||||
return NULL;
|
||||
name_id = ossl_namemap_name2num(namemap, methdata->name);
|
||||
name_id = ossl_namemap_name2num_n(namemap, names, l);
|
||||
}
|
||||
|
||||
if (name_id == 0
|
||||
@@ -131,21 +199,30 @@ static void *get_method_from_store(OPENSSL_CTX *libctx, void *store,
|
||||
|
||||
static int put_method_in_store(OPENSSL_CTX *libctx, void *store,
|
||||
void *method, const OSSL_PROVIDER *prov,
|
||||
int operation_id, const char *name,
|
||||
int operation_id, const char *names,
|
||||
const char *propdef, void *data)
|
||||
{
|
||||
struct method_data_st *methdata = data;
|
||||
OSSL_NAMEMAP *namemap;
|
||||
int name_id;
|
||||
uint32_t meth_id;
|
||||
size_t l = 0;
|
||||
|
||||
/*
|
||||
* put_method_in_store() is only called with a method that was
|
||||
* successfully created by construct_method() below, which means
|
||||
* the name should already be stored in the namemap, so just use it.
|
||||
* that all the names should already be stored in the namemap with
|
||||
* the same numeric identity, so just use the first to get that
|
||||
* identity.
|
||||
*/
|
||||
if (names != NULL) {
|
||||
const char *q = strchr(names, NAME_SEPARATOR);
|
||||
|
||||
l = (q == NULL ? strlen(names) : (size_t)(q - names));
|
||||
}
|
||||
|
||||
if ((namemap = ossl_namemap_stored(libctx)) == NULL
|
||||
|| (name_id = ossl_namemap_name2num(namemap, name)) == 0
|
||||
|| (name_id = ossl_namemap_name2num_n(namemap, names, l)) == 0
|
||||
|| (meth_id = method_id(operation_id, name_id)) == 0)
|
||||
return 0;
|
||||
|
||||
@@ -162,7 +239,7 @@ static int put_method_in_store(OPENSSL_CTX *libctx, void *store,
|
||||
* The core fetching functionality passes the name of the implementation.
|
||||
* This function is responsible to getting an identity number for it.
|
||||
*/
|
||||
static void *construct_method(const char *name, const OSSL_DISPATCH *fns,
|
||||
static void *construct_method(const char *names, const OSSL_DISPATCH *fns,
|
||||
OSSL_PROVIDER *prov, void *data)
|
||||
{
|
||||
/*
|
||||
@@ -170,17 +247,14 @@ static void *construct_method(const char *name, const OSSL_DISPATCH *fns,
|
||||
* NULL, so it's safe to say that of all the spots to create a new
|
||||
* namemap entry, this is it. Should the name already exist there, we
|
||||
* know that ossl_namemap_add() will return its corresponding number.
|
||||
*
|
||||
* TODO(3.0): If this function gets an array of names instead of just
|
||||
* one, we need to check through all the names to see if at least one
|
||||
* of them has an associated number, and use that. If several names
|
||||
* have associated numbers that differ from each other, it's an error.
|
||||
*/
|
||||
struct method_data_st *methdata = data;
|
||||
OPENSSL_CTX *libctx = ossl_provider_library_context(prov);
|
||||
OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx);
|
||||
int name_id = ossl_namemap_add(namemap, 0, name);
|
||||
int name_id = add_names_to_namemap(namemap, names);
|
||||
|
||||
if (name_id == 0)
|
||||
return NULL;
|
||||
return methdata->method_from_dispatch(name_id, fns, prov,
|
||||
methdata->method_data);
|
||||
}
|
||||
@@ -255,7 +329,7 @@ static void *inner_generic_fetch(OPENSSL_CTX *libctx, int operation_id,
|
||||
mcmdata.libctx = libctx;
|
||||
mcmdata.operation_id = operation_id;
|
||||
mcmdata.name_id = name_id;
|
||||
mcmdata.name = name;
|
||||
mcmdata.names = name;
|
||||
mcmdata.propquery = properties;
|
||||
mcmdata.method_from_dispatch = new_method;
|
||||
mcmdata.destruct_method = free_method;
|
||||
@@ -337,6 +411,7 @@ struct do_all_data_st {
|
||||
void *user_arg;
|
||||
void *(*new_method)(const int name_id, const OSSL_DISPATCH *fns,
|
||||
OSSL_PROVIDER *prov, void *method_data);
|
||||
void *method_data;
|
||||
void (*free_method)(void *);
|
||||
};
|
||||
|
||||
@@ -346,12 +421,12 @@ static void do_one(OSSL_PROVIDER *provider, const OSSL_ALGORITHM *algo,
|
||||
struct do_all_data_st *data = vdata;
|
||||
OPENSSL_CTX *libctx = ossl_provider_library_context(provider);
|
||||
OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx);
|
||||
int name_id = ossl_namemap_add(namemap, 0, algo->algorithm_name);
|
||||
int name_id = add_names_to_namemap(namemap, algo->algorithm_names);
|
||||
void *method = NULL;
|
||||
|
||||
if (name_id != 0)
|
||||
method = data->new_method(name_id, algo->implementation, provider,
|
||||
NULL);
|
||||
data->method_data);
|
||||
|
||||
if (method != NULL) {
|
||||
data->user_fn(method, data->user_arg);
|
||||
@@ -372,10 +447,11 @@ void evp_generic_do_all(OPENSSL_CTX *libctx, int operation_id,
|
||||
struct do_all_data_st data;
|
||||
|
||||
data.new_method = new_method;
|
||||
data.method_data = method_data;
|
||||
data.free_method = free_method;
|
||||
data.user_fn = user_fn;
|
||||
data.user_arg = user_arg;
|
||||
ossl_algorithm_do_all(libctx, operation_id, method_data, do_one, &data);
|
||||
ossl_algorithm_do_all(libctx, operation_id, NULL, do_one, &data);
|
||||
}
|
||||
|
||||
const char *evp_first_name(OSSL_PROVIDER *prov, int name_id)
|
||||
@@ -394,9 +470,9 @@ int evp_is_a(OSSL_PROVIDER *prov, int number, const char *name)
|
||||
return ossl_namemap_name2num(namemap, name) == number;
|
||||
}
|
||||
|
||||
void evp_doall_names(OSSL_PROVIDER *prov, int number,
|
||||
void (*fn)(const char *name, void *data),
|
||||
void *data)
|
||||
void evp_names_do_all(OSSL_PROVIDER *prov, int number,
|
||||
void (*fn)(const char *name, void *data),
|
||||
void *data)
|
||||
{
|
||||
OPENSSL_CTX *libctx = ossl_provider_library_context(prov);
|
||||
OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx);
|
||||
|
||||
+171
-48
@@ -14,36 +14,38 @@
|
||||
#include <openssl/params.h>
|
||||
#include <openssl/core_names.h>
|
||||
#include <openssl/dh.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "internal/provider.h"
|
||||
#include "evp_locl.h"
|
||||
#include "evp_local.h"
|
||||
|
||||
#if !defined(FIPS_MODE)
|
||||
int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
|
||||
{
|
||||
int ret;
|
||||
int ret = -1; /* Assume the worst */
|
||||
const EVP_CIPHER *cipher = c->cipher;
|
||||
|
||||
if (cipher->prov != NULL) {
|
||||
/*
|
||||
* The cipher has come from a provider and won't have the default flags.
|
||||
* Find the implicit form so we can check the flags.
|
||||
* TODO(3.0): This won't work for 3rd party ciphers we know nothing about
|
||||
* We'll need to think of something else for those.
|
||||
*/
|
||||
cipher = EVP_get_cipherbynid(cipher->nid);
|
||||
if (cipher == NULL) {
|
||||
EVPerr(EVP_F_EVP_CIPHER_PARAM_TO_ASN1, ASN1_R_UNSUPPORTED_CIPHER);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (cipher->set_asn1_parameters != NULL)
|
||||
/*
|
||||
* For legacy implementations, we detect custom AlgorithmIdentifier
|
||||
* parameter handling by checking if the function pointer
|
||||
* cipher->set_asn1_parameters is set. We know that this pointer
|
||||
* is NULL for provided implementations.
|
||||
*
|
||||
* Otherwise, for any implementation, we check the flag
|
||||
* EVP_CIPH_FLAG_CUSTOM_ASN1. If it isn't set, we apply
|
||||
* default AI parameter extraction.
|
||||
*
|
||||
* Otherwise, for provided implementations, we convert |type| to
|
||||
* a DER encoded blob and pass to the implementation in OSSL_PARAM
|
||||
* form.
|
||||
*
|
||||
* If none of the above applies, this operation is unsupported.
|
||||
*/
|
||||
if (cipher->set_asn1_parameters != NULL) {
|
||||
ret = cipher->set_asn1_parameters(c, type);
|
||||
else if (cipher->flags & EVP_CIPH_FLAG_DEFAULT_ASN1) {
|
||||
} else if ((EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_CUSTOM_ASN1) == 0) {
|
||||
switch (EVP_CIPHER_mode(cipher)) {
|
||||
case EVP_CIPH_WRAP_MODE:
|
||||
if (EVP_CIPHER_nid(cipher) == NID_id_smime_alg_CMS3DESwrap)
|
||||
if (EVP_CIPHER_is_a(cipher, SN_id_smime_alg_CMS3DESwrap))
|
||||
ASN1_TYPE_set(type, V_ASN1_NULL, NULL);
|
||||
ret = 1;
|
||||
break;
|
||||
@@ -58,8 +60,40 @@ int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
|
||||
default:
|
||||
ret = EVP_CIPHER_set_asn1_iv(c, type);
|
||||
}
|
||||
} else
|
||||
ret = -1;
|
||||
} else if (cipher->prov != NULL) {
|
||||
OSSL_PARAM params[3], *p = params;
|
||||
unsigned char *der = NULL, *derp;
|
||||
|
||||
/*
|
||||
* We make two passes, the first to get the appropriate buffer size,
|
||||
* and the second to get the actual value.
|
||||
*/
|
||||
*p++ = OSSL_PARAM_construct_octet_string(OSSL_CIPHER_PARAM_ALG_ID,
|
||||
NULL, 0);
|
||||
*p = OSSL_PARAM_construct_end();
|
||||
|
||||
if (!EVP_CIPHER_CTX_get_params(c, params))
|
||||
goto err;
|
||||
|
||||
/* ... but, we should get a return size too! */
|
||||
if (params[0].return_size != 0
|
||||
&& (der = OPENSSL_malloc(params[0].return_size)) != NULL) {
|
||||
params[0].data = der;
|
||||
params[0].data_size = params[0].return_size;
|
||||
params[0].return_size = 0;
|
||||
derp = der;
|
||||
if (EVP_CIPHER_CTX_get_params(c, params)
|
||||
&& d2i_ASN1_TYPE(&type, (const unsigned char **)&derp,
|
||||
params[0].return_size) != NULL) {
|
||||
ret = 1;
|
||||
}
|
||||
OPENSSL_free(der);
|
||||
}
|
||||
} else {
|
||||
ret = -2;
|
||||
}
|
||||
|
||||
err:
|
||||
if (ret == -2)
|
||||
EVPerr(EVP_F_EVP_CIPHER_PARAM_TO_ASN1, ASN1_R_UNSUPPORTED_CIPHER);
|
||||
else if (ret <= 0)
|
||||
@@ -71,24 +105,29 @@ int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
|
||||
|
||||
int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
|
||||
{
|
||||
int ret;
|
||||
int ret = -1; /* Assume the worst */
|
||||
const EVP_CIPHER *cipher = c->cipher;
|
||||
|
||||
if (cipher->prov != NULL) {
|
||||
/*
|
||||
* The cipher has come from a provider and won't have the default flags.
|
||||
* Find the implicit form so we can check the flags.
|
||||
*/
|
||||
cipher = EVP_get_cipherbynid(cipher->nid);
|
||||
if (cipher == NULL)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cipher->get_asn1_parameters != NULL)
|
||||
/*
|
||||
* For legacy implementations, we detect custom AlgorithmIdentifier
|
||||
* parameter handling by checking if there the function pointer
|
||||
* cipher->get_asn1_parameters is set. We know that this pointer
|
||||
* is NULL for provided implementations.
|
||||
*
|
||||
* Otherwise, for any implementation, we check the flag
|
||||
* EVP_CIPH_FLAG_CUSTOM_ASN1. If it isn't set, we apply
|
||||
* default AI parameter creation.
|
||||
*
|
||||
* Otherwise, for provided implementations, we get the AI parameter
|
||||
* in DER encoded form from the implementation by requesting the
|
||||
* appropriate OSSL_PARAM and converting the result to a ASN1_TYPE.
|
||||
*
|
||||
* If none of the above applies, this operation is unsupported.
|
||||
*/
|
||||
if (cipher->get_asn1_parameters != NULL) {
|
||||
ret = cipher->get_asn1_parameters(c, type);
|
||||
else if (cipher->flags & EVP_CIPH_FLAG_DEFAULT_ASN1) {
|
||||
} else if ((EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_CUSTOM_ASN1) == 0) {
|
||||
switch (EVP_CIPHER_mode(cipher)) {
|
||||
|
||||
case EVP_CIPH_WRAP_MODE:
|
||||
ret = 1;
|
||||
break;
|
||||
@@ -102,10 +141,25 @@ int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
|
||||
|
||||
default:
|
||||
ret = EVP_CIPHER_get_asn1_iv(c, type);
|
||||
break;
|
||||
}
|
||||
} else
|
||||
ret = -1;
|
||||
} else if (cipher->prov != NULL) {
|
||||
OSSL_PARAM params[3], *p = params;
|
||||
unsigned char *der = NULL;
|
||||
int derl = -1;
|
||||
|
||||
if ((derl = i2d_ASN1_TYPE(type, &der)) >= 0) {
|
||||
*p++ =
|
||||
OSSL_PARAM_construct_octet_string(OSSL_CIPHER_PARAM_ALG_ID,
|
||||
der, (size_t)derl);
|
||||
*p = OSSL_PARAM_construct_end();
|
||||
if (EVP_CIPHER_CTX_set_params(c, params))
|
||||
ret = 1;
|
||||
OPENSSL_free(der);
|
||||
}
|
||||
} else {
|
||||
ret = -2;
|
||||
}
|
||||
|
||||
if (ret == -2)
|
||||
EVPerr(EVP_F_EVP_CIPHER_ASN1_TO_PARAM, EVP_R_UNSUPPORTED_CIPHER);
|
||||
else if (ret <= 0)
|
||||
@@ -140,11 +194,13 @@ int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
|
||||
{
|
||||
int i = 0;
|
||||
unsigned int j;
|
||||
unsigned char *oiv = NULL;
|
||||
|
||||
if (type != NULL) {
|
||||
oiv = (unsigned char *)EVP_CIPHER_CTX_original_iv(c);
|
||||
j = EVP_CIPHER_CTX_iv_length(c);
|
||||
OPENSSL_assert(j <= sizeof(c->iv));
|
||||
i = ASN1_TYPE_set_octetstring(type, c->oiv, j);
|
||||
i = ASN1_TYPE_set_octetstring(type, oiv, j);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
@@ -242,15 +298,31 @@ int EVP_Cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
const unsigned char *in, unsigned int inl)
|
||||
{
|
||||
if (ctx->cipher->prov != NULL) {
|
||||
size_t outl = 0; /* ignored */
|
||||
int blocksize = EVP_CIPHER_CTX_block_size(ctx);
|
||||
/*
|
||||
* If the provided implementation has a ccipher function, we use it,
|
||||
* and translate its return value like this: 0 => -1, 1 => outlen
|
||||
*
|
||||
* Otherwise, we call the cupdate function if in != NULL, or cfinal
|
||||
* if in == NULL. Regardless of which, we return what we got.
|
||||
*/
|
||||
int ret = -1;
|
||||
size_t outl = 0;
|
||||
size_t blocksize = EVP_CIPHER_CTX_block_size(ctx);
|
||||
|
||||
if (ctx->cipher->ccipher != NULL)
|
||||
return
|
||||
ctx->cipher->ccipher(ctx->provctx, out, &outl,
|
||||
inl + (blocksize == 1 ? 0 : blocksize),
|
||||
in, (size_t)inl);
|
||||
return 0;
|
||||
ret = ctx->cipher->ccipher(ctx->provctx, out, &outl,
|
||||
inl + (blocksize == 1 ? 0 : blocksize),
|
||||
in, (size_t)inl)
|
||||
? (int)outl : -1;
|
||||
else if (in != NULL)
|
||||
ret = ctx->cipher->cupdate(ctx->provctx, out, &outl,
|
||||
inl + (blocksize == 1 ? 0 : blocksize),
|
||||
in, (size_t)inl);
|
||||
else
|
||||
ret = ctx->cipher->cfinal(ctx->provctx, out, &outl,
|
||||
blocksize == 1 ? 0 : blocksize);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ctx->cipher->do_cipher(ctx, out, in, inl);
|
||||
@@ -275,6 +347,10 @@ unsigned long EVP_CIPHER_flags(const EVP_CIPHER *cipher)
|
||||
params[0] = OSSL_PARAM_construct_ulong(OSSL_CIPHER_PARAM_FLAGS, &v);
|
||||
ok = evp_do_ciph_getparams(cipher, params);
|
||||
|
||||
/* Provided implementations may have a custom cipher_cipher */
|
||||
if (cipher->prov != NULL && cipher->ccipher != NULL)
|
||||
v |= EVP_CIPH_FLAG_CUSTOM_CIPHER;
|
||||
|
||||
return ok != 0 ? v : 0;
|
||||
}
|
||||
|
||||
@@ -349,7 +425,16 @@ int EVP_CIPHER_CTX_tag_length(const EVP_CIPHER_CTX *ctx)
|
||||
|
||||
const unsigned char *EVP_CIPHER_CTX_original_iv(const EVP_CIPHER_CTX *ctx)
|
||||
{
|
||||
return ctx->oiv;
|
||||
int ok;
|
||||
const unsigned char *v = ctx->oiv;
|
||||
OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
|
||||
|
||||
params[0] =
|
||||
OSSL_PARAM_construct_octet_ptr(OSSL_CIPHER_PARAM_IV,
|
||||
(void **)&v, sizeof(ctx->oiv));
|
||||
ok = evp_do_ciph_ctx_getparams(ctx->cipher, ctx->provctx, params);
|
||||
|
||||
return ok != 0 ? v : NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -450,9 +535,21 @@ int EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx)
|
||||
|
||||
int EVP_CIPHER_is_a(const EVP_CIPHER *cipher, const char *name)
|
||||
{
|
||||
#ifndef FIPS_MODE
|
||||
if (cipher->prov == NULL) {
|
||||
int nid = EVP_CIPHER_nid(cipher);
|
||||
|
||||
return nid == OBJ_sn2nid(name) || nid == OBJ_ln2nid(name);
|
||||
}
|
||||
#endif
|
||||
return evp_is_a(cipher->prov, cipher->name_id, name);
|
||||
}
|
||||
|
||||
int EVP_CIPHER_number(const EVP_CIPHER *cipher)
|
||||
{
|
||||
return cipher->name_id;
|
||||
}
|
||||
|
||||
const char *EVP_CIPHER_name(const EVP_CIPHER *cipher)
|
||||
{
|
||||
if (cipher->prov != NULL)
|
||||
@@ -464,6 +561,14 @@ const char *EVP_CIPHER_name(const EVP_CIPHER *cipher)
|
||||
#endif
|
||||
}
|
||||
|
||||
void EVP_CIPHER_names_do_all(const EVP_CIPHER *cipher,
|
||||
void (*fn)(const char *name, void *data),
|
||||
void *data)
|
||||
{
|
||||
if (cipher->prov != NULL)
|
||||
evp_names_do_all(cipher->prov, cipher->name_id, fn, data);
|
||||
}
|
||||
|
||||
const OSSL_PROVIDER *EVP_CIPHER_provider(const EVP_CIPHER *cipher)
|
||||
{
|
||||
return cipher->prov;
|
||||
@@ -481,6 +586,16 @@ int EVP_CIPHER_mode(const EVP_CIPHER *cipher)
|
||||
return ok != 0 ? (int)v : 0;
|
||||
}
|
||||
|
||||
int EVP_MD_is_a(const EVP_MD *md, const char *name)
|
||||
{
|
||||
return evp_is_a(md->prov, md->name_id, name);
|
||||
}
|
||||
|
||||
int EVP_MD_number(const EVP_MD *md)
|
||||
{
|
||||
return md->name_id;
|
||||
}
|
||||
|
||||
const char *EVP_MD_name(const EVP_MD *md)
|
||||
{
|
||||
if (md->prov != NULL)
|
||||
@@ -492,6 +607,14 @@ const char *EVP_MD_name(const EVP_MD *md)
|
||||
#endif
|
||||
}
|
||||
|
||||
void EVP_MD_names_do_all(const EVP_MD *md,
|
||||
void (*fn)(const char *name, void *data),
|
||||
void *data)
|
||||
{
|
||||
if (md->prov != NULL)
|
||||
evp_names_do_all(md->prov, md->name_id, fn, data);
|
||||
}
|
||||
|
||||
const OSSL_PROVIDER *EVP_MD_provider(const EVP_MD *md)
|
||||
{
|
||||
return md->prov;
|
||||
|
||||
@@ -129,12 +129,22 @@ struct evp_signature_st {
|
||||
OSSL_OP_signature_verify_fn *verify;
|
||||
OSSL_OP_signature_verify_recover_init_fn *verify_recover_init;
|
||||
OSSL_OP_signature_verify_recover_fn *verify_recover;
|
||||
OSSL_OP_signature_digest_sign_init_fn *digest_sign_init;
|
||||
OSSL_OP_signature_digest_sign_update_fn *digest_sign_update;
|
||||
OSSL_OP_signature_digest_sign_final_fn *digest_sign_final;
|
||||
OSSL_OP_signature_digest_verify_init_fn *digest_verify_init;
|
||||
OSSL_OP_signature_digest_verify_update_fn *digest_verify_update;
|
||||
OSSL_OP_signature_digest_verify_final_fn *digest_verify_final;
|
||||
OSSL_OP_signature_freectx_fn *freectx;
|
||||
OSSL_OP_signature_dupctx_fn *dupctx;
|
||||
OSSL_OP_signature_get_ctx_params_fn *get_ctx_params;
|
||||
OSSL_OP_signature_gettable_ctx_params_fn *gettable_ctx_params;
|
||||
OSSL_OP_signature_set_ctx_params_fn *set_ctx_params;
|
||||
OSSL_OP_signature_settable_ctx_params_fn *settable_ctx_params;
|
||||
OSSL_OP_signature_get_ctx_md_params_fn *get_ctx_md_params;
|
||||
OSSL_OP_signature_gettable_ctx_md_params_fn *gettable_ctx_md_params;
|
||||
OSSL_OP_signature_set_ctx_md_params_fn *set_ctx_md_params;
|
||||
OSSL_OP_signature_settable_ctx_md_params_fn *settable_ctx_md_params;
|
||||
} /* EVP_SIGNATURE */;
|
||||
|
||||
int PKCS5_v2_PBKDF2_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass,
|
||||
@@ -163,7 +173,7 @@ DEFINE_STACK_OF(EVP_PBE_CTL)
|
||||
|
||||
int is_partially_overlapping(const void *ptr1, const void *ptr2, int len);
|
||||
|
||||
#include <openssl/ossl_typ.h>
|
||||
#include <openssl/types.h>
|
||||
#include <openssl/core.h>
|
||||
|
||||
void *evp_generic_fetch(OPENSSL_CTX *ctx, int operation_id,
|
||||
@@ -251,6 +261,6 @@ void evp_pkey_ctx_free_old_ops(EVP_PKEY_CTX *ctx);
|
||||
/* OSSL_PROVIDER * is only used to get the library context */
|
||||
const char *evp_first_name(OSSL_PROVIDER *prov, int name_id);
|
||||
int evp_is_a(OSSL_PROVIDER *prov, int number, const char *name);
|
||||
void evp_doall_names(OSSL_PROVIDER *prov, int number,
|
||||
void (*fn)(const char *name, void *data),
|
||||
void *data);
|
||||
void evp_names_do_all(OSSL_PROVIDER *prov, int number,
|
||||
void (*fn)(const char *name, void *data),
|
||||
void *data);
|
||||
@@ -12,8 +12,8 @@
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/pkcs12.h>
|
||||
#include <openssl/x509.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "evp_locl.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "evp_local.h"
|
||||
|
||||
/* Password based encryption (PBE) functions */
|
||||
|
||||
@@ -93,8 +93,9 @@ int EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
|
||||
if (!EVP_PBE_find(EVP_PBE_TYPE_OUTER, OBJ_obj2nid(pbe_obj),
|
||||
&cipher_nid, &md_nid, &keygen)) {
|
||||
char obj_tmp[80];
|
||||
|
||||
EVPerr(EVP_F_EVP_PBE_CIPHERINIT, EVP_R_UNKNOWN_PBE_ALGORITHM);
|
||||
if (!pbe_obj)
|
||||
if (pbe_obj == NULL)
|
||||
OPENSSL_strlcpy(obj_tmp, "NULL", sizeof(obj_tmp));
|
||||
else
|
||||
i2t_ASN1_OBJECT(obj_tmp, sizeof(obj_tmp), pbe_obj);
|
||||
@@ -102,7 +103,7 @@ int EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!pass)
|
||||
if (pass == NULL)
|
||||
passlen = 0;
|
||||
else if (passlen == -1)
|
||||
passlen = strlen(pass);
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/rand.h>
|
||||
#include "internal/asn1_int.h"
|
||||
#include "internal/evp_int.h"
|
||||
#include "internal/x509_int.h"
|
||||
#include "crypto/asn1.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "crypto/x509.h"
|
||||
|
||||
/* Extract a private key from a PKCS8 structure */
|
||||
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
#include <openssl/core.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/asn1.h> /* evp_locl.h needs it */
|
||||
#include <openssl/safestack.h> /* evp_locl.h needs it */
|
||||
#include "internal/evp_int.h" /* evp_locl.h needs it */
|
||||
#include "evp_locl.h"
|
||||
#include <openssl/asn1.h> /* evp_local.h needs it */
|
||||
#include <openssl/safestack.h> /* evp_local.h needs it */
|
||||
#include "crypto/evp.h" /* evp_local.h needs it */
|
||||
#include "evp_local.h"
|
||||
|
||||
/*
|
||||
* EVP_CTRL_RET_UNSUPPORTED = -1 is the returned value from any ctrl function
|
||||
|
||||
+38
-5
@@ -11,10 +11,10 @@
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/err.h>
|
||||
#include "internal/refcount.h"
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "internal/provider.h"
|
||||
#include "internal/numbers.h" /* includes SIZE_MAX */
|
||||
#include "evp_locl.h"
|
||||
#include "evp_local.h"
|
||||
|
||||
static EVP_KEYEXCH *evp_keyexch_new(OSSL_PROVIDER *prov)
|
||||
{
|
||||
@@ -224,7 +224,8 @@ int EVP_PKEY_derive_init_ex(EVP_PKEY_CTX *ctx, EVP_KEYEXCH *exchange)
|
||||
|
||||
ctx->op.kex.exchange = exchange;
|
||||
if (ctx->pkey != NULL) {
|
||||
provkey = evp_keymgmt_export_to_provider(ctx->pkey, exchange->keymgmt);
|
||||
provkey =
|
||||
evp_keymgmt_export_to_provider(ctx->pkey, exchange->keymgmt, 0);
|
||||
if (provkey == NULL) {
|
||||
EVPerr(EVP_F_EVP_PKEY_DERIVE_INIT_EX, EVP_R_INITIALIZATION_ERROR);
|
||||
goto err;
|
||||
@@ -283,8 +284,8 @@ int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer)
|
||||
return -2;
|
||||
}
|
||||
|
||||
provkey = evp_keymgmt_export_to_provider(peer,
|
||||
ctx->op.kex.exchange->keymgmt);
|
||||
provkey =
|
||||
evp_keymgmt_export_to_provider(peer, ctx->op.kex.exchange->keymgmt, 0);
|
||||
if (provkey == NULL) {
|
||||
EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER, ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
@@ -386,3 +387,35 @@ int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *pkeylen)
|
||||
M_check_autoarg(ctx, key, pkeylen, EVP_F_EVP_PKEY_DERIVE)
|
||||
return ctx->pmeth->derive(ctx, key, pkeylen);
|
||||
}
|
||||
|
||||
int EVP_KEYEXCH_number(const EVP_KEYEXCH *keyexch)
|
||||
{
|
||||
return keyexch->name_id;
|
||||
}
|
||||
|
||||
int EVP_KEYEXCH_is_a(const EVP_KEYEXCH *keyexch, const char *name)
|
||||
{
|
||||
return evp_is_a(keyexch->prov, keyexch->name_id, name);
|
||||
}
|
||||
|
||||
void EVP_KEYEXCH_do_all_provided(OPENSSL_CTX *libctx,
|
||||
void (*fn)(EVP_KEYEXCH *keyexch, void *arg),
|
||||
void *arg)
|
||||
{
|
||||
struct keymgmt_data_st keymgmt_data;
|
||||
|
||||
keymgmt_data.ctx = libctx;
|
||||
keymgmt_data.properties = NULL;
|
||||
evp_generic_do_all(libctx, OSSL_OP_KEYEXCH,
|
||||
(void (*)(void *, void *))fn, arg,
|
||||
evp_keyexch_from_dispatch, &keymgmt_data,
|
||||
(void (*)(void *))EVP_KEYEXCH_free);
|
||||
}
|
||||
|
||||
void EVP_KEYEXCH_names_do_all(const EVP_KEYEXCH *keyexch,
|
||||
void (*fn)(const char *name, void *data),
|
||||
void *data)
|
||||
{
|
||||
if (keyexch->prov != NULL)
|
||||
evp_names_do_all(keyexch->prov, keyexch->name_id, fn, data);
|
||||
}
|
||||
+18
-5
@@ -17,11 +17,11 @@
|
||||
#include <openssl/kdf.h>
|
||||
#include <openssl/core.h>
|
||||
#include <openssl/core_names.h>
|
||||
#include "internal/asn1_int.h"
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/asn1.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "internal/numbers.h"
|
||||
#include "internal/provider.h"
|
||||
#include "evp_locl.h"
|
||||
#include "evp_local.h"
|
||||
|
||||
EVP_KDF_CTX *EVP_KDF_CTX_new(EVP_KDF *kdf)
|
||||
{
|
||||
@@ -83,9 +83,14 @@ EVP_KDF_CTX *EVP_KDF_CTX_dup(const EVP_KDF_CTX *src)
|
||||
return dst;
|
||||
}
|
||||
|
||||
const char *EVP_KDF_name(const EVP_KDF *kdf)
|
||||
int EVP_KDF_number(const EVP_KDF *kdf)
|
||||
{
|
||||
return evp_first_name(kdf->prov, kdf->name_id);
|
||||
return kdf->name_id;
|
||||
}
|
||||
|
||||
int EVP_KDF_is_a(const EVP_KDF *kdf, const char *name)
|
||||
{
|
||||
return evp_is_a(kdf->prov, kdf->name_id, name);
|
||||
}
|
||||
|
||||
const OSSL_PROVIDER *EVP_KDF_provider(const EVP_KDF *kdf)
|
||||
@@ -159,3 +164,11 @@ int EVP_KDF_CTX_set_params(EVP_KDF_CTX *ctx, const OSSL_PARAM params[])
|
||||
return ctx->meth->set_ctx_params(ctx->data, params);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void EVP_KDF_names_do_all(const EVP_KDF *kdf,
|
||||
void (*fn)(const char *name, void *data),
|
||||
void *data)
|
||||
{
|
||||
if (kdf->prov != NULL)
|
||||
evp_names_do_all(kdf->prov, kdf->name_id, fn, data);
|
||||
}
|
||||
@@ -12,9 +12,9 @@
|
||||
#include <openssl/core.h>
|
||||
#include <openssl/core_numbers.h>
|
||||
#include <openssl/kdf.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "internal/provider.h"
|
||||
#include "evp_locl.h"
|
||||
#include "evp_local.h"
|
||||
|
||||
static int evp_kdf_up_ref(void *vkdf)
|
||||
{
|
||||
@@ -173,23 +173,23 @@ const OSSL_PARAM *EVP_KDF_gettable_params(const EVP_KDF *kdf)
|
||||
return kdf->gettable_params();
|
||||
}
|
||||
|
||||
const OSSL_PARAM *EVP_KDF_CTX_gettable_params(const EVP_KDF *kdf)
|
||||
const OSSL_PARAM *EVP_KDF_gettable_ctx_params(const EVP_KDF *kdf)
|
||||
{
|
||||
if (kdf->gettable_ctx_params == NULL)
|
||||
return NULL;
|
||||
return kdf->gettable_ctx_params();
|
||||
}
|
||||
|
||||
const OSSL_PARAM *EVP_KDF_CTX_settable_params(const EVP_KDF *kdf)
|
||||
const OSSL_PARAM *EVP_KDF_settable_ctx_params(const EVP_KDF *kdf)
|
||||
{
|
||||
if (kdf->settable_ctx_params == NULL)
|
||||
return NULL;
|
||||
return kdf->settable_ctx_params();
|
||||
}
|
||||
|
||||
void EVP_KDF_do_all_ex(OPENSSL_CTX *libctx,
|
||||
void (*fn)(EVP_KDF *kdf, void *arg),
|
||||
void *arg)
|
||||
void EVP_KDF_do_all_provided(OPENSSL_CTX *libctx,
|
||||
void (*fn)(EVP_KDF *kdf, void *arg),
|
||||
void *arg)
|
||||
{
|
||||
evp_generic_do_all(libctx, OSSL_OP_KDF,
|
||||
(void (*)(void *, void *))fn, arg,
|
||||
|
||||
+51
-24
@@ -9,10 +9,10 @@
|
||||
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/nelem.h"
|
||||
#include "internal/evp_int.h"
|
||||
#include "internal/asn1_int.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "crypto/asn1.h"
|
||||
#include "internal/provider.h"
|
||||
#include "evp_locl.h"
|
||||
#include "evp_local.h"
|
||||
|
||||
static OSSL_PARAM *paramdefs_to_params(const OSSL_PARAM *paramdefs)
|
||||
{
|
||||
@@ -52,6 +52,9 @@ static void *allocate_params_space(OSSL_PARAM *params)
|
||||
for (space = 0, p = params; p->key != NULL; p++)
|
||||
space += ((p->return_size + ALIGN_SIZE - 1) / ALIGN_SIZE) * ALIGN_SIZE;
|
||||
|
||||
if (space == 0)
|
||||
return NULL;
|
||||
|
||||
data = OPENSSL_zalloc(space);
|
||||
|
||||
for (space = 0, p = params; p->key != NULL; p++) {
|
||||
@@ -62,9 +65,10 @@ static void *allocate_params_space(OSSL_PARAM *params)
|
||||
return data;
|
||||
}
|
||||
|
||||
void *evp_keymgmt_export_to_provider(EVP_PKEY *pk, EVP_KEYMGMT *keymgmt)
|
||||
void *evp_keymgmt_export_to_provider(EVP_PKEY *pk, EVP_KEYMGMT *keymgmt,
|
||||
int want_domainparams)
|
||||
{
|
||||
void *provkey = NULL;
|
||||
void *provdata = NULL;
|
||||
size_t i, j;
|
||||
|
||||
/*
|
||||
@@ -90,8 +94,9 @@ void *evp_keymgmt_export_to_provider(EVP_PKEY *pk, EVP_KEYMGMT *keymgmt)
|
||||
for (i = 0;
|
||||
i < OSSL_NELEM(pk->pkeys) && pk->pkeys[i].keymgmt != NULL;
|
||||
i++) {
|
||||
if (keymgmt == pk->pkeys[i].keymgmt)
|
||||
return pk->pkeys[i].provkey;
|
||||
if (keymgmt == pk->pkeys[i].keymgmt
|
||||
&& want_domainparams == pk->pkeys[i].domainparams)
|
||||
return pk->pkeys[i].provdata;
|
||||
}
|
||||
|
||||
if (pk->pkey.ptr != NULL) {
|
||||
@@ -101,11 +106,11 @@ void *evp_keymgmt_export_to_provider(EVP_PKEY *pk, EVP_KEYMGMT *keymgmt)
|
||||
if (pk->ameth->export_to == NULL)
|
||||
return NULL;
|
||||
|
||||
/* Otherwise, simply use it */
|
||||
provkey = pk->ameth->export_to(pk, keymgmt);
|
||||
/* Otherwise, simply use it. */
|
||||
provdata = pk->ameth->export_to(pk, keymgmt, want_domainparams);
|
||||
|
||||
/* Synchronize the dirty count, but only if we exported successfully */
|
||||
if (provkey != NULL)
|
||||
if (provdata != NULL)
|
||||
pk->dirty_cnt_copy = pk->ameth->dirty_cnt(pk);
|
||||
|
||||
} else {
|
||||
@@ -116,10 +121,13 @@ void *evp_keymgmt_export_to_provider(EVP_PKEY *pk, EVP_KEYMGMT *keymgmt)
|
||||
* the new provider.
|
||||
*/
|
||||
|
||||
void *(*importfn)(void *provctx, const OSSL_PARAM params[]) =
|
||||
want_domainparams ? keymgmt->importdomparams : keymgmt->importkey;
|
||||
|
||||
/*
|
||||
* If the given keymgmt doesn't have an import function, give up
|
||||
*/
|
||||
if (keymgmt->importkey == NULL)
|
||||
if (importfn == NULL)
|
||||
return NULL;
|
||||
|
||||
for (j = 0; j < i && pk->pkeys[j].keymgmt != NULL; j++) {
|
||||
@@ -129,6 +137,14 @@ void *evp_keymgmt_export_to_provider(EVP_PKEY *pk, EVP_KEYMGMT *keymgmt)
|
||||
void *data = NULL;
|
||||
void *provctx =
|
||||
ossl_provider_ctx(EVP_KEYMGMT_provider(keymgmt));
|
||||
int (*exportfn)(void *provctx, OSSL_PARAM params[]) = NULL;
|
||||
|
||||
if (pk->pkeys[j].domainparams != want_domainparams)
|
||||
continue;
|
||||
|
||||
exportfn = want_domainparams
|
||||
? pk->pkeys[j].keymgmt->exportdomparams
|
||||
: pk->pkeys[j].keymgmt->exportkey;
|
||||
|
||||
paramdefs = pk->pkeys[j].keymgmt->exportkey_types();
|
||||
/*
|
||||
@@ -138,29 +154,35 @@ void *evp_keymgmt_export_to_provider(EVP_PKEY *pk, EVP_KEYMGMT *keymgmt)
|
||||
*/
|
||||
params = paramdefs_to_params(paramdefs);
|
||||
/* Get 'return_size' filled */
|
||||
pk->pkeys[j].keymgmt->exportkey(pk->pkeys[j].provkey, params);
|
||||
exportfn(pk->pkeys[j].provdata, params);
|
||||
|
||||
/*
|
||||
* Allocate space and assign 'data' to point into the
|
||||
* data block
|
||||
* data block.
|
||||
* If something goes wrong, go to the next cached key.
|
||||
*/
|
||||
data = allocate_params_space(params);
|
||||
if ((data = allocate_params_space(params)) == NULL)
|
||||
goto cont;
|
||||
|
||||
/*
|
||||
* Call the exportkey function a second time, to get
|
||||
* the data filled
|
||||
* the data filled.
|
||||
* If something goes wrong, go to the next cached key.
|
||||
*/
|
||||
pk->pkeys[j].keymgmt->exportkey(pk->pkeys[j].provkey, params);
|
||||
if (!exportfn(pk->pkeys[j].provdata, params))
|
||||
goto cont;
|
||||
|
||||
/*
|
||||
* We should have all the data at this point, so import
|
||||
* into the new provider and hope to get a key back.
|
||||
*/
|
||||
provkey = keymgmt->importkey(provctx, params);
|
||||
provdata = importfn(provctx, params);
|
||||
|
||||
cont:
|
||||
OPENSSL_free(params);
|
||||
OPENSSL_free(data);
|
||||
|
||||
if (provkey != NULL)
|
||||
if (provdata != NULL)
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -173,12 +195,14 @@ void *evp_keymgmt_export_to_provider(EVP_PKEY *pk, EVP_KEYMGMT *keymgmt)
|
||||
*/
|
||||
j = ossl_assert(i < OSSL_NELEM(pk->pkeys));
|
||||
|
||||
if (provkey != NULL) {
|
||||
if (provdata != NULL) {
|
||||
EVP_KEYMGMT_up_ref(keymgmt);
|
||||
pk->pkeys[i].keymgmt = keymgmt;
|
||||
pk->pkeys[i].provkey = provkey;
|
||||
pk->pkeys[i].provdata = provdata;
|
||||
pk->pkeys[i].domainparams = want_domainparams;
|
||||
}
|
||||
return provkey;
|
||||
|
||||
return provdata;
|
||||
}
|
||||
|
||||
void evp_keymgmt_clear_pkey_cache(EVP_PKEY *pk)
|
||||
@@ -190,11 +214,14 @@ void evp_keymgmt_clear_pkey_cache(EVP_PKEY *pk)
|
||||
i < OSSL_NELEM(pk->pkeys) && pk->pkeys[i].keymgmt != NULL;
|
||||
i++) {
|
||||
EVP_KEYMGMT *keymgmt = pk->pkeys[i].keymgmt;
|
||||
void *provkey = pk->pkeys[i].provkey;
|
||||
void *provdata = pk->pkeys[i].provdata;
|
||||
|
||||
pk->pkeys[i].keymgmt = NULL;
|
||||
pk->pkeys[i].provkey = NULL;
|
||||
keymgmt->freekey(provkey);
|
||||
pk->pkeys[i].provdata = NULL;
|
||||
if (pk->pkeys[i].domainparams)
|
||||
keymgmt->freedomparams(provdata);
|
||||
else
|
||||
keymgmt->freekey(provdata);
|
||||
EVP_KEYMGMT_free(keymgmt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
#include <openssl/err.h>
|
||||
#include "internal/provider.h"
|
||||
#include "internal/refcount.h"
|
||||
#include "internal/evp_int.h"
|
||||
#include "evp_locl.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "evp_local.h"
|
||||
|
||||
|
||||
static void *keymgmt_new(void)
|
||||
@@ -200,3 +200,30 @@ const OSSL_PROVIDER *EVP_KEYMGMT_provider(const EVP_KEYMGMT *keymgmt)
|
||||
return keymgmt->prov;
|
||||
}
|
||||
|
||||
int EVP_KEYMGMT_number(const EVP_KEYMGMT *keymgmt)
|
||||
{
|
||||
return keymgmt->name_id;
|
||||
}
|
||||
|
||||
int EVP_KEYMGMT_is_a(const EVP_KEYMGMT *keymgmt, const char *name)
|
||||
{
|
||||
return evp_is_a(keymgmt->prov, keymgmt->name_id, name);
|
||||
}
|
||||
|
||||
void EVP_KEYMGMT_do_all_provided(OPENSSL_CTX *libctx,
|
||||
void (*fn)(EVP_KEYMGMT *keymgmt, void *arg),
|
||||
void *arg)
|
||||
{
|
||||
evp_generic_do_all(libctx, OSSL_OP_KEYMGMT,
|
||||
(void (*)(void *, void *))fn, arg,
|
||||
keymgmt_from_dispatch, NULL,
|
||||
(void (*)(void *))EVP_KEYMGMT_free);
|
||||
}
|
||||
|
||||
void EVP_KEYMGMT_names_do_all(const EVP_KEYMGMT *keymgmt,
|
||||
void (*fn)(const char *name, void *data),
|
||||
void *data)
|
||||
{
|
||||
if (keymgmt->prov != NULL)
|
||||
evp_names_do_all(keymgmt->prov, keymgmt->name_id, fn, data);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2015-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
|
||||
#ifndef OPENSSL_NO_MD2
|
||||
|
||||
# include <openssl/md2.h>
|
||||
# include "crypto/evp.h"
|
||||
|
||||
static const EVP_MD md2_md = {
|
||||
NID_md2,
|
||||
NID_md2WithRSAEncryption,
|
||||
MD2_DIGEST_LENGTH,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
MD2_BLOCK,
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_md2(void)
|
||||
{
|
||||
return &md2_md;
|
||||
}
|
||||
|
||||
#endif /* OPENSSL_NO_MD2 */
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2015-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
|
||||
#ifndef OPENSSL_NO_MD4
|
||||
|
||||
# include <openssl/md4.h>
|
||||
# include "crypto/evp.h"
|
||||
|
||||
static const EVP_MD md4_md = {
|
||||
NID_md4,
|
||||
NID_md4WithRSAEncryption,
|
||||
MD4_DIGEST_LENGTH,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
MD4_CBLOCK,
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_md4(void)
|
||||
{
|
||||
return &md4_md;
|
||||
}
|
||||
|
||||
#endif /* OPENSSL_NO_MD4 */
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2015-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
|
||||
#ifndef OPENSSL_NO_MD5
|
||||
|
||||
# include <openssl/md5.h>
|
||||
# include "crypto/evp.h"
|
||||
|
||||
static const EVP_MD md5_md = {
|
||||
NID_md5,
|
||||
NID_md5WithRSAEncryption,
|
||||
MD5_DIGEST_LENGTH,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
MD5_CBLOCK,
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_md5(void)
|
||||
{
|
||||
return &md5_md;
|
||||
}
|
||||
|
||||
#endif /* OPENSSL_NO_MD5 */
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2015-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
|
||||
#include "prov/md5_sha1.h" /* diverse MD5_SHA1 macros */
|
||||
|
||||
#ifndef OPENSSL_NO_MD5
|
||||
|
||||
# include <openssl/obj_mac.h>
|
||||
# include "crypto/evp.h"
|
||||
|
||||
static const EVP_MD md5_sha1_md = {
|
||||
NID_md5_sha1,
|
||||
NID_md5_sha1,
|
||||
MD5_SHA1_DIGEST_LENGTH,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
MD5_SHA1_CBLOCK,
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_md5_sha1(void)
|
||||
{
|
||||
return &md5_sha1_md;
|
||||
}
|
||||
|
||||
#endif /* OPENSSL_NO_MD5 */
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2015-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
|
||||
#ifndef OPENSSL_NO_MDC2
|
||||
|
||||
# include <openssl/mdc2.h>
|
||||
# include "crypto/evp.h"
|
||||
|
||||
static const EVP_MD mdc2_md = {
|
||||
NID_mdc2,
|
||||
NID_mdc2WithRSA,
|
||||
MDC2_DIGEST_LENGTH,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
MDC2_BLOCK,
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_mdc2(void)
|
||||
{
|
||||
return &mdc2_md;
|
||||
}
|
||||
|
||||
#endif /* OPENSSL_NO_MDC2 */
|
||||
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
|
||||
#include <openssl/obj_mac.h>
|
||||
#include <openssl/sha.h> /* diverse SHA macros */
|
||||
#include "internal/sha3.h" /* KECCAK1600_WIDTH */
|
||||
#include "crypto/evp.h"
|
||||
|
||||
static const EVP_MD sha1_md = {
|
||||
NID_sha1,
|
||||
NID_sha1WithRSAEncryption,
|
||||
SHA_DIGEST_LENGTH,
|
||||
EVP_MD_FLAG_DIGALGID_ABSENT,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
SHA_CBLOCK,
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_sha1(void)
|
||||
{
|
||||
return &sha1_md;
|
||||
}
|
||||
|
||||
static const EVP_MD sha224_md = {
|
||||
NID_sha224,
|
||||
NID_sha224WithRSAEncryption,
|
||||
SHA224_DIGEST_LENGTH,
|
||||
EVP_MD_FLAG_DIGALGID_ABSENT,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
SHA256_CBLOCK,
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_sha224(void)
|
||||
{
|
||||
return &sha224_md;
|
||||
}
|
||||
|
||||
static const EVP_MD sha256_md = {
|
||||
NID_sha256,
|
||||
NID_sha256WithRSAEncryption,
|
||||
SHA256_DIGEST_LENGTH,
|
||||
EVP_MD_FLAG_DIGALGID_ABSENT,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
SHA256_CBLOCK,
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_sha256(void)
|
||||
{
|
||||
return &sha256_md;
|
||||
}
|
||||
|
||||
static const EVP_MD sha512_224_md = {
|
||||
NID_sha512_224,
|
||||
NID_sha512_224WithRSAEncryption,
|
||||
SHA224_DIGEST_LENGTH,
|
||||
EVP_MD_FLAG_DIGALGID_ABSENT,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
SHA512_CBLOCK,
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_sha512_224(void)
|
||||
{
|
||||
return &sha512_224_md;
|
||||
}
|
||||
|
||||
static const EVP_MD sha512_256_md = {
|
||||
NID_sha512_256,
|
||||
NID_sha512_256WithRSAEncryption,
|
||||
SHA256_DIGEST_LENGTH,
|
||||
EVP_MD_FLAG_DIGALGID_ABSENT,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
SHA512_CBLOCK,
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_sha512_256(void)
|
||||
{
|
||||
return &sha512_256_md;
|
||||
}
|
||||
|
||||
static const EVP_MD sha384_md = {
|
||||
NID_sha384,
|
||||
NID_sha384WithRSAEncryption,
|
||||
SHA384_DIGEST_LENGTH,
|
||||
EVP_MD_FLAG_DIGALGID_ABSENT,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
SHA512_CBLOCK,
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_sha384(void)
|
||||
{
|
||||
return &sha384_md;
|
||||
}
|
||||
|
||||
static const EVP_MD sha512_md = {
|
||||
NID_sha512,
|
||||
NID_sha512WithRSAEncryption,
|
||||
SHA512_DIGEST_LENGTH,
|
||||
EVP_MD_FLAG_DIGALGID_ABSENT,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
SHA512_CBLOCK,
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_sha512(void)
|
||||
{
|
||||
return &sha512_md;
|
||||
}
|
||||
|
||||
# define EVP_MD_SHA3(bitlen) \
|
||||
const EVP_MD *EVP_sha3_##bitlen(void) \
|
||||
{ \
|
||||
static const EVP_MD sha3_##bitlen##_md = { \
|
||||
NID_sha3_##bitlen, \
|
||||
NID_RSA_SHA3_##bitlen, \
|
||||
bitlen / 8, \
|
||||
EVP_MD_FLAG_DIGALGID_ABSENT, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
(KECCAK1600_WIDTH - bitlen * 2) / 8, \
|
||||
}; \
|
||||
return &sha3_##bitlen##_md; \
|
||||
}
|
||||
# define EVP_MD_SHAKE(bitlen) \
|
||||
const EVP_MD *EVP_shake##bitlen(void) \
|
||||
{ \
|
||||
static const EVP_MD shake##bitlen##_md = { \
|
||||
NID_shake##bitlen, \
|
||||
0, \
|
||||
bitlen / 8, \
|
||||
EVP_MD_FLAG_XOF, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
(KECCAK1600_WIDTH - bitlen * 2) / 8, \
|
||||
}; \
|
||||
return &shake##bitlen##_md; \
|
||||
}
|
||||
|
||||
EVP_MD_SHA3(224)
|
||||
EVP_MD_SHA3(256)
|
||||
EVP_MD_SHA3(384)
|
||||
EVP_MD_SHA3(512)
|
||||
|
||||
EVP_MD_SHAKE(128)
|
||||
EVP_MD_SHAKE(256)
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "internal/cryptlib.h"
|
||||
|
||||
#ifndef OPENSSL_NO_MD2
|
||||
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/objects.h>
|
||||
# include <openssl/x509.h>
|
||||
# include <openssl/md2.h>
|
||||
# include <openssl/rsa.h>
|
||||
|
||||
#include "internal/evp_int.h"
|
||||
|
||||
static int init(EVP_MD_CTX *ctx)
|
||||
{
|
||||
return MD2_Init(EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int update(EVP_MD_CTX *ctx, const void *data, size_t count)
|
||||
{
|
||||
return MD2_Update(EVP_MD_CTX_md_data(ctx), data, count);
|
||||
}
|
||||
|
||||
static int final(EVP_MD_CTX *ctx, unsigned char *md)
|
||||
{
|
||||
return MD2_Final(md, EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static const EVP_MD md2_md = {
|
||||
NID_md2,
|
||||
NID_md2WithRSAEncryption,
|
||||
MD2_DIGEST_LENGTH,
|
||||
0,
|
||||
init,
|
||||
update,
|
||||
final,
|
||||
NULL,
|
||||
NULL,
|
||||
MD2_BLOCK,
|
||||
sizeof(EVP_MD *) + sizeof(MD2_CTX),
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_md2(void)
|
||||
{
|
||||
return &md2_md;
|
||||
}
|
||||
#endif
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "internal/cryptlib.h"
|
||||
|
||||
#ifndef OPENSSL_NO_MD4
|
||||
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/objects.h>
|
||||
# include <openssl/x509.h>
|
||||
# include <openssl/md4.h>
|
||||
# include <openssl/rsa.h>
|
||||
# include "internal/evp_int.h"
|
||||
|
||||
static int init(EVP_MD_CTX *ctx)
|
||||
{
|
||||
return MD4_Init(EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int update(EVP_MD_CTX *ctx, const void *data, size_t count)
|
||||
{
|
||||
return MD4_Update(EVP_MD_CTX_md_data(ctx), data, count);
|
||||
}
|
||||
|
||||
static int final(EVP_MD_CTX *ctx, unsigned char *md)
|
||||
{
|
||||
return MD4_Final(md, EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static const EVP_MD md4_md = {
|
||||
NID_md4,
|
||||
NID_md4WithRSAEncryption,
|
||||
MD4_DIGEST_LENGTH,
|
||||
0,
|
||||
init,
|
||||
update,
|
||||
final,
|
||||
NULL,
|
||||
NULL,
|
||||
MD4_CBLOCK,
|
||||
sizeof(EVP_MD *) + sizeof(MD4_CTX),
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_md4(void)
|
||||
{
|
||||
return &md4_md;
|
||||
}
|
||||
#endif
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "internal/cryptlib.h"
|
||||
|
||||
#ifndef OPENSSL_NO_MD5
|
||||
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/objects.h>
|
||||
# include <openssl/x509.h>
|
||||
# include <openssl/md5.h>
|
||||
# include <openssl/rsa.h>
|
||||
# include "internal/evp_int.h"
|
||||
|
||||
static int init(EVP_MD_CTX *ctx)
|
||||
{
|
||||
return MD5_Init(EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int update(EVP_MD_CTX *ctx, const void *data, size_t count)
|
||||
{
|
||||
return MD5_Update(EVP_MD_CTX_md_data(ctx), data, count);
|
||||
}
|
||||
|
||||
static int final(EVP_MD_CTX *ctx, unsigned char *md)
|
||||
{
|
||||
return MD5_Final(md, EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static const EVP_MD md5_md = {
|
||||
NID_md5,
|
||||
NID_md5WithRSAEncryption,
|
||||
MD5_DIGEST_LENGTH,
|
||||
0,
|
||||
init,
|
||||
update,
|
||||
final,
|
||||
NULL,
|
||||
NULL,
|
||||
MD5_CBLOCK,
|
||||
sizeof(EVP_MD *) + sizeof(MD5_CTX),
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_md5(void)
|
||||
{
|
||||
return &md5_md;
|
||||
}
|
||||
#endif
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef OPENSSL_NO_MD5
|
||||
|
||||
# include <string.h>
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/obj_mac.h>
|
||||
# include "internal/evp_int.h"
|
||||
# include "internal/md5_sha1.h"
|
||||
|
||||
static int init(EVP_MD_CTX *ctx)
|
||||
{
|
||||
return md5_sha1_init(EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int update(EVP_MD_CTX *ctx, const void *data, size_t count)
|
||||
{
|
||||
return md5_sha1_update(EVP_MD_CTX_md_data(ctx), data, count);
|
||||
}
|
||||
|
||||
static int final(EVP_MD_CTX *ctx, unsigned char *md)
|
||||
{
|
||||
return md5_sha1_final(md, EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int ctrl(EVP_MD_CTX *ctx, int cmd, int mslen, void *ms)
|
||||
{
|
||||
return md5_sha1_ctrl(EVP_MD_CTX_md_data(ctx), cmd, mslen, ms);
|
||||
}
|
||||
|
||||
static const EVP_MD md5_sha1_md = {
|
||||
NID_md5_sha1,
|
||||
NID_md5_sha1,
|
||||
MD5_SHA1_DIGEST_LENGTH,
|
||||
0,
|
||||
init,
|
||||
update,
|
||||
final,
|
||||
NULL,
|
||||
NULL,
|
||||
MD5_SHA1_CBLOCK,
|
||||
sizeof(EVP_MD *) + sizeof(MD5_SHA1_CTX),
|
||||
ctrl
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_md5_sha1(void)
|
||||
{
|
||||
return &md5_sha1_md;
|
||||
}
|
||||
|
||||
#endif /* OPENSSL_NO_MD5 */
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "internal/cryptlib.h"
|
||||
|
||||
#ifndef OPENSSL_NO_MDC2
|
||||
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/objects.h>
|
||||
# include <openssl/x509.h>
|
||||
# include <openssl/mdc2.h>
|
||||
# include <openssl/rsa.h>
|
||||
# include "internal/evp_int.h"
|
||||
|
||||
static int init(EVP_MD_CTX *ctx)
|
||||
{
|
||||
return MDC2_Init(EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int update(EVP_MD_CTX *ctx, const void *data, size_t count)
|
||||
{
|
||||
return MDC2_Update(EVP_MD_CTX_md_data(ctx), data, count);
|
||||
}
|
||||
|
||||
static int final(EVP_MD_CTX *ctx, unsigned char *md)
|
||||
{
|
||||
return MDC2_Final(md, EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static const EVP_MD mdc2_md = {
|
||||
NID_mdc2,
|
||||
NID_mdc2WithRSA,
|
||||
MDC2_DIGEST_LENGTH,
|
||||
0,
|
||||
init,
|
||||
update,
|
||||
final,
|
||||
NULL,
|
||||
NULL,
|
||||
MDC2_BLOCK,
|
||||
sizeof(EVP_MD *) + sizeof(MDC2_CTX),
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_mdc2(void)
|
||||
{
|
||||
return &mdc2_md;
|
||||
}
|
||||
#endif
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/x509.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/evp.h"
|
||||
|
||||
static int init(EVP_MD_CTX *ctx)
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
# include <openssl/objects.h>
|
||||
# include <openssl/x509.h>
|
||||
# include <openssl/rsa.h>
|
||||
# include "internal/evp_int.h"
|
||||
# include "crypto/evp.h"
|
||||
|
||||
static int init(EVP_MD_CTX *ctx)
|
||||
{
|
||||
|
||||
@@ -1,243 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "internal/cryptlib.h"
|
||||
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "internal/sha.h"
|
||||
|
||||
static int init(EVP_MD_CTX *ctx)
|
||||
{
|
||||
return SHA1_Init(EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int update(EVP_MD_CTX *ctx, const void *data, size_t count)
|
||||
{
|
||||
return SHA1_Update(EVP_MD_CTX_md_data(ctx), data, count);
|
||||
}
|
||||
|
||||
static int final(EVP_MD_CTX *ctx, unsigned char *md)
|
||||
{
|
||||
return SHA1_Final(md, EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2)
|
||||
{
|
||||
return sha1_ctrl(ctx != NULL ? EVP_MD_CTX_md_data(ctx) : NULL, cmd, p1, p2);
|
||||
}
|
||||
|
||||
static const EVP_MD sha1_md = {
|
||||
NID_sha1,
|
||||
NID_sha1WithRSAEncryption,
|
||||
SHA_DIGEST_LENGTH,
|
||||
EVP_MD_FLAG_DIGALGID_ABSENT,
|
||||
init,
|
||||
update,
|
||||
final,
|
||||
NULL,
|
||||
NULL,
|
||||
SHA_CBLOCK,
|
||||
sizeof(EVP_MD *) + sizeof(SHA_CTX),
|
||||
ctrl
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_sha1(void)
|
||||
{
|
||||
return &sha1_md;
|
||||
}
|
||||
|
||||
static int init224(EVP_MD_CTX *ctx)
|
||||
{
|
||||
return SHA224_Init(EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int update224(EVP_MD_CTX *ctx, const void *data, size_t count)
|
||||
{
|
||||
return SHA224_Update(EVP_MD_CTX_md_data(ctx), data, count);
|
||||
}
|
||||
|
||||
static int final224(EVP_MD_CTX *ctx, unsigned char *md)
|
||||
{
|
||||
return SHA224_Final(md, EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int init256(EVP_MD_CTX *ctx)
|
||||
{
|
||||
return SHA256_Init(EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int update256(EVP_MD_CTX *ctx, const void *data, size_t count)
|
||||
{
|
||||
return SHA256_Update(EVP_MD_CTX_md_data(ctx), data, count);
|
||||
}
|
||||
|
||||
static int final256(EVP_MD_CTX *ctx, unsigned char *md)
|
||||
{
|
||||
return SHA256_Final(md, EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static const EVP_MD sha224_md = {
|
||||
NID_sha224,
|
||||
NID_sha224WithRSAEncryption,
|
||||
SHA224_DIGEST_LENGTH,
|
||||
EVP_MD_FLAG_DIGALGID_ABSENT,
|
||||
init224,
|
||||
update224,
|
||||
final224,
|
||||
NULL,
|
||||
NULL,
|
||||
SHA256_CBLOCK,
|
||||
sizeof(EVP_MD *) + sizeof(SHA256_CTX),
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_sha224(void)
|
||||
{
|
||||
return &sha224_md;
|
||||
}
|
||||
|
||||
static const EVP_MD sha256_md = {
|
||||
NID_sha256,
|
||||
NID_sha256WithRSAEncryption,
|
||||
SHA256_DIGEST_LENGTH,
|
||||
EVP_MD_FLAG_DIGALGID_ABSENT,
|
||||
init256,
|
||||
update256,
|
||||
final256,
|
||||
NULL,
|
||||
NULL,
|
||||
SHA256_CBLOCK,
|
||||
sizeof(EVP_MD *) + sizeof(SHA256_CTX),
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_sha256(void)
|
||||
{
|
||||
return &sha256_md;
|
||||
}
|
||||
|
||||
static int init512_224(EVP_MD_CTX *ctx)
|
||||
{
|
||||
return sha512_224_init(EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int init512_256(EVP_MD_CTX *ctx)
|
||||
{
|
||||
return sha512_256_init(EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int init384(EVP_MD_CTX *ctx)
|
||||
{
|
||||
return SHA384_Init(EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int update384(EVP_MD_CTX *ctx, const void *data, size_t count)
|
||||
{
|
||||
return SHA384_Update(EVP_MD_CTX_md_data(ctx), data, count);
|
||||
}
|
||||
|
||||
static int final384(EVP_MD_CTX *ctx, unsigned char *md)
|
||||
{
|
||||
return SHA384_Final(md, EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int init512(EVP_MD_CTX *ctx)
|
||||
{
|
||||
return SHA512_Init(EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
/* See comment in SHA224/256 section */
|
||||
static int update512(EVP_MD_CTX *ctx, const void *data, size_t count)
|
||||
{
|
||||
return SHA512_Update(EVP_MD_CTX_md_data(ctx), data, count);
|
||||
}
|
||||
|
||||
static int final512(EVP_MD_CTX *ctx, unsigned char *md)
|
||||
{
|
||||
return SHA512_Final(md, EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static const EVP_MD sha512_224_md = {
|
||||
NID_sha512_224,
|
||||
NID_sha512_224WithRSAEncryption,
|
||||
SHA224_DIGEST_LENGTH,
|
||||
EVP_MD_FLAG_DIGALGID_ABSENT,
|
||||
init512_224,
|
||||
update512,
|
||||
final512,
|
||||
NULL,
|
||||
NULL,
|
||||
SHA512_CBLOCK,
|
||||
sizeof(EVP_MD *) + sizeof(SHA512_CTX),
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_sha512_224(void)
|
||||
{
|
||||
return &sha512_224_md;
|
||||
}
|
||||
|
||||
static const EVP_MD sha512_256_md = {
|
||||
NID_sha512_256,
|
||||
NID_sha512_256WithRSAEncryption,
|
||||
SHA256_DIGEST_LENGTH,
|
||||
EVP_MD_FLAG_DIGALGID_ABSENT,
|
||||
init512_256,
|
||||
update512,
|
||||
final512,
|
||||
NULL,
|
||||
NULL,
|
||||
SHA512_CBLOCK,
|
||||
sizeof(EVP_MD *) + sizeof(SHA512_CTX),
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_sha512_256(void)
|
||||
{
|
||||
return &sha512_256_md;
|
||||
}
|
||||
|
||||
static const EVP_MD sha384_md = {
|
||||
NID_sha384,
|
||||
NID_sha384WithRSAEncryption,
|
||||
SHA384_DIGEST_LENGTH,
|
||||
EVP_MD_FLAG_DIGALGID_ABSENT,
|
||||
init384,
|
||||
update384,
|
||||
final384,
|
||||
NULL,
|
||||
NULL,
|
||||
SHA512_CBLOCK,
|
||||
sizeof(EVP_MD *) + sizeof(SHA512_CTX),
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_sha384(void)
|
||||
{
|
||||
return &sha384_md;
|
||||
}
|
||||
|
||||
static const EVP_MD sha512_md = {
|
||||
NID_sha512,
|
||||
NID_sha512WithRSAEncryption,
|
||||
SHA512_DIGEST_LENGTH,
|
||||
EVP_MD_FLAG_DIGALGID_ABSENT,
|
||||
init512,
|
||||
update512,
|
||||
final512,
|
||||
NULL,
|
||||
NULL,
|
||||
SHA512_CBLOCK,
|
||||
sizeof(EVP_MD *) + sizeof(SHA512_CTX),
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_sha512(void)
|
||||
{
|
||||
return &sha512_md;
|
||||
}
|
||||
@@ -1,319 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/objects.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "internal/sha3.h"
|
||||
#include "evp_locl.h"
|
||||
|
||||
static int init(EVP_MD_CTX *ctx)
|
||||
{
|
||||
return sha3_init(EVP_MD_CTX_md_data(ctx), '\x06', ctx->digest->md_size * 8);
|
||||
}
|
||||
|
||||
static int update(EVP_MD_CTX *ctx, const void *_inp, size_t len)
|
||||
{
|
||||
return sha3_update(EVP_MD_CTX_md_data(ctx), _inp, len);
|
||||
}
|
||||
|
||||
static int final(EVP_MD_CTX *ctx, unsigned char *md)
|
||||
{
|
||||
return sha3_final(md, EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int shake_init(EVP_MD_CTX *ctx)
|
||||
{
|
||||
return sha3_init(EVP_MD_CTX_md_data(ctx), '\x1f', ctx->digest->md_size * 8);
|
||||
}
|
||||
|
||||
static int shake_ctrl(EVP_MD_CTX *evp_ctx, int cmd, int p1, void *p2)
|
||||
{
|
||||
KECCAK1600_CTX *ctx = evp_ctx->md_data;
|
||||
|
||||
switch (cmd) {
|
||||
case EVP_MD_CTRL_XOF_LEN:
|
||||
ctx->md_size = p1;
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(OPENSSL_CPUID_OBJ) && defined(__s390__) && defined(KECCAK1600_ASM)
|
||||
/*
|
||||
* IBM S390X support
|
||||
*/
|
||||
# include "s390x_arch.h"
|
||||
|
||||
# define S390X_SHA3_FC(ctx) ((ctx)->pad)
|
||||
|
||||
# define S390X_sha3_224_CAPABLE ((OPENSSL_s390xcap_P.kimd[0] & \
|
||||
S390X_CAPBIT(S390X_SHA3_224)) && \
|
||||
(OPENSSL_s390xcap_P.klmd[0] & \
|
||||
S390X_CAPBIT(S390X_SHA3_224)))
|
||||
# define S390X_sha3_256_CAPABLE ((OPENSSL_s390xcap_P.kimd[0] & \
|
||||
S390X_CAPBIT(S390X_SHA3_256)) && \
|
||||
(OPENSSL_s390xcap_P.klmd[0] & \
|
||||
S390X_CAPBIT(S390X_SHA3_256)))
|
||||
# define S390X_sha3_384_CAPABLE ((OPENSSL_s390xcap_P.kimd[0] & \
|
||||
S390X_CAPBIT(S390X_SHA3_384)) && \
|
||||
(OPENSSL_s390xcap_P.klmd[0] & \
|
||||
S390X_CAPBIT(S390X_SHA3_384)))
|
||||
# define S390X_sha3_512_CAPABLE ((OPENSSL_s390xcap_P.kimd[0] & \
|
||||
S390X_CAPBIT(S390X_SHA3_512)) && \
|
||||
(OPENSSL_s390xcap_P.klmd[0] & \
|
||||
S390X_CAPBIT(S390X_SHA3_512)))
|
||||
# define S390X_shake128_CAPABLE ((OPENSSL_s390xcap_P.kimd[0] & \
|
||||
S390X_CAPBIT(S390X_SHAKE_128)) && \
|
||||
(OPENSSL_s390xcap_P.klmd[0] & \
|
||||
S390X_CAPBIT(S390X_SHAKE_128)))
|
||||
# define S390X_shake256_CAPABLE ((OPENSSL_s390xcap_P.kimd[0] & \
|
||||
S390X_CAPBIT(S390X_SHAKE_256)) && \
|
||||
(OPENSSL_s390xcap_P.klmd[0] & \
|
||||
S390X_CAPBIT(S390X_SHAKE_256)))
|
||||
|
||||
/* Convert md-size to block-size. */
|
||||
# define S390X_KECCAK1600_BSZ(n) ((KECCAK1600_WIDTH - ((n) << 1)) >> 3)
|
||||
|
||||
static int s390x_sha3_init(EVP_MD_CTX *evp_ctx)
|
||||
{
|
||||
KECCAK1600_CTX *ctx = evp_ctx->md_data;
|
||||
const size_t bsz = evp_ctx->digest->block_size;
|
||||
|
||||
/*-
|
||||
* KECCAK1600_CTX structure's pad field is used to store the KIMD/KLMD
|
||||
* function code.
|
||||
*/
|
||||
switch (bsz) {
|
||||
case S390X_KECCAK1600_BSZ(224):
|
||||
ctx->pad = S390X_SHA3_224;
|
||||
break;
|
||||
case S390X_KECCAK1600_BSZ(256):
|
||||
ctx->pad = S390X_SHA3_256;
|
||||
break;
|
||||
case S390X_KECCAK1600_BSZ(384):
|
||||
ctx->pad = S390X_SHA3_384;
|
||||
break;
|
||||
case S390X_KECCAK1600_BSZ(512):
|
||||
ctx->pad = S390X_SHA3_512;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(ctx->A, 0, sizeof(ctx->A));
|
||||
ctx->bufsz = 0;
|
||||
ctx->block_size = bsz;
|
||||
ctx->md_size = evp_ctx->digest->md_size;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int s390x_shake_init(EVP_MD_CTX *evp_ctx)
|
||||
{
|
||||
KECCAK1600_CTX *ctx = evp_ctx->md_data;
|
||||
const size_t bsz = evp_ctx->digest->block_size;
|
||||
|
||||
/*-
|
||||
* KECCAK1600_CTX structure's pad field is used to store the KIMD/KLMD
|
||||
* function code.
|
||||
*/
|
||||
switch (bsz) {
|
||||
case S390X_KECCAK1600_BSZ(128):
|
||||
ctx->pad = S390X_SHAKE_128;
|
||||
break;
|
||||
case S390X_KECCAK1600_BSZ(256):
|
||||
ctx->pad = S390X_SHAKE_256;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(ctx->A, 0, sizeof(ctx->A));
|
||||
ctx->bufsz = 0;
|
||||
ctx->block_size = bsz;
|
||||
ctx->md_size = evp_ctx->digest->md_size;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int s390x_sha3_update(EVP_MD_CTX *evp_ctx, const void *_inp, size_t len)
|
||||
{
|
||||
KECCAK1600_CTX *ctx = evp_ctx->md_data;
|
||||
const unsigned char *inp = _inp;
|
||||
const size_t bsz = ctx->block_size;
|
||||
size_t num, rem;
|
||||
|
||||
if (len == 0)
|
||||
return 1;
|
||||
|
||||
if ((num = ctx->bufsz) != 0) {
|
||||
rem = bsz - num;
|
||||
|
||||
if (len < rem) {
|
||||
memcpy(ctx->buf + num, inp, len);
|
||||
ctx->bufsz += len;
|
||||
return 1;
|
||||
}
|
||||
memcpy(ctx->buf + num, inp, rem);
|
||||
inp += rem;
|
||||
len -= rem;
|
||||
s390x_kimd(ctx->buf, bsz, ctx->pad, ctx->A);
|
||||
ctx->bufsz = 0;
|
||||
}
|
||||
rem = len % bsz;
|
||||
|
||||
s390x_kimd(inp, len - rem, ctx->pad, ctx->A);
|
||||
|
||||
if (rem) {
|
||||
memcpy(ctx->buf, inp + len - rem, rem);
|
||||
ctx->bufsz = rem;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int s390x_sha3_final(EVP_MD_CTX *evp_ctx, unsigned char *md)
|
||||
{
|
||||
KECCAK1600_CTX *ctx = evp_ctx->md_data;
|
||||
|
||||
s390x_klmd(ctx->buf, ctx->bufsz, NULL, 0, ctx->pad, ctx->A);
|
||||
memcpy(md, ctx->A, ctx->md_size);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int s390x_shake_final(EVP_MD_CTX *evp_ctx, unsigned char *md)
|
||||
{
|
||||
KECCAK1600_CTX *ctx = evp_ctx->md_data;
|
||||
|
||||
s390x_klmd(ctx->buf, ctx->bufsz, md, ctx->md_size, ctx->pad, ctx->A);
|
||||
return 1;
|
||||
}
|
||||
|
||||
# define EVP_MD_SHA3(bitlen) \
|
||||
const EVP_MD *EVP_sha3_##bitlen(void) \
|
||||
{ \
|
||||
static const EVP_MD s390x_sha3_##bitlen##_md = { \
|
||||
NID_sha3_##bitlen, \
|
||||
NID_RSA_SHA3_##bitlen, \
|
||||
bitlen / 8, \
|
||||
EVP_MD_FLAG_DIGALGID_ABSENT, \
|
||||
s390x_sha3_init, \
|
||||
s390x_sha3_update, \
|
||||
s390x_sha3_final, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
(KECCAK1600_WIDTH - bitlen * 2) / 8, \
|
||||
sizeof(KECCAK1600_CTX), \
|
||||
}; \
|
||||
static const EVP_MD sha3_##bitlen##_md = { \
|
||||
NID_sha3_##bitlen, \
|
||||
NID_RSA_SHA3_##bitlen, \
|
||||
bitlen / 8, \
|
||||
EVP_MD_FLAG_DIGALGID_ABSENT, \
|
||||
init, \
|
||||
update, \
|
||||
final, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
(KECCAK1600_WIDTH - bitlen * 2) / 8, \
|
||||
sizeof(KECCAK1600_CTX), \
|
||||
}; \
|
||||
return S390X_sha3_##bitlen##_CAPABLE ? \
|
||||
&s390x_sha3_##bitlen##_md : \
|
||||
&sha3_##bitlen##_md; \
|
||||
}
|
||||
|
||||
# define EVP_MD_SHAKE(bitlen) \
|
||||
const EVP_MD *EVP_shake##bitlen(void) \
|
||||
{ \
|
||||
static const EVP_MD s390x_shake##bitlen##_md = { \
|
||||
NID_shake##bitlen, \
|
||||
0, \
|
||||
bitlen / 8, \
|
||||
EVP_MD_FLAG_XOF, \
|
||||
s390x_shake_init, \
|
||||
s390x_sha3_update, \
|
||||
s390x_shake_final, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
(KECCAK1600_WIDTH - bitlen * 2) / 8, \
|
||||
sizeof(KECCAK1600_CTX), \
|
||||
shake_ctrl \
|
||||
}; \
|
||||
static const EVP_MD shake##bitlen##_md = { \
|
||||
NID_shake##bitlen, \
|
||||
0, \
|
||||
bitlen / 8, \
|
||||
EVP_MD_FLAG_XOF, \
|
||||
shake_init, \
|
||||
update, \
|
||||
final, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
(KECCAK1600_WIDTH - bitlen * 2) / 8, \
|
||||
sizeof(KECCAK1600_CTX), \
|
||||
shake_ctrl \
|
||||
}; \
|
||||
return S390X_shake##bitlen##_CAPABLE ? \
|
||||
&s390x_shake##bitlen##_md : \
|
||||
&shake##bitlen##_md; \
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
# define EVP_MD_SHA3(bitlen) \
|
||||
const EVP_MD *EVP_sha3_##bitlen(void) \
|
||||
{ \
|
||||
static const EVP_MD sha3_##bitlen##_md = { \
|
||||
NID_sha3_##bitlen, \
|
||||
NID_RSA_SHA3_##bitlen, \
|
||||
bitlen / 8, \
|
||||
EVP_MD_FLAG_DIGALGID_ABSENT, \
|
||||
init, \
|
||||
update, \
|
||||
final, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
(KECCAK1600_WIDTH - bitlen * 2) / 8, \
|
||||
sizeof(KECCAK1600_CTX), \
|
||||
}; \
|
||||
return &sha3_##bitlen##_md; \
|
||||
}
|
||||
|
||||
# define EVP_MD_SHAKE(bitlen) \
|
||||
const EVP_MD *EVP_shake##bitlen(void) \
|
||||
{ \
|
||||
static const EVP_MD shake##bitlen##_md = { \
|
||||
NID_shake##bitlen, \
|
||||
0, \
|
||||
bitlen / 8, \
|
||||
EVP_MD_FLAG_XOF, \
|
||||
shake_init, \
|
||||
update, \
|
||||
final, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
(KECCAK1600_WIDTH - bitlen * 2) / 8, \
|
||||
sizeof(KECCAK1600_CTX), \
|
||||
shake_ctrl \
|
||||
}; \
|
||||
return &shake##bitlen##_md; \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
EVP_MD_SHA3(224)
|
||||
EVP_MD_SHA3(256)
|
||||
EVP_MD_SHA3(384)
|
||||
EVP_MD_SHA3(512)
|
||||
|
||||
EVP_MD_SHAKE(128)
|
||||
EVP_MD_SHAKE(256)
|
||||
+196
-10
@@ -12,8 +12,11 @@
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/x509.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "evp_locl.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "internal/provider.h"
|
||||
#include "evp_local.h"
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
|
||||
static int update(EVP_MD_CTX *ctx, const void *data, size_t datalen)
|
||||
{
|
||||
@@ -22,14 +25,122 @@ static int update(EVP_MD_CTX *ctx, const void *data, size_t datalen)
|
||||
}
|
||||
|
||||
static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
|
||||
const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey,
|
||||
int ver)
|
||||
const EVP_MD *type, const char *mdname,
|
||||
const char *props, ENGINE *e, EVP_PKEY *pkey,
|
||||
EVP_SIGNATURE *signature, int ver)
|
||||
{
|
||||
if (ctx->pctx == NULL)
|
||||
ctx->pctx = EVP_PKEY_CTX_new(pkey, e);
|
||||
if (ctx->pctx == NULL)
|
||||
return 0;
|
||||
EVP_PKEY_CTX *locpctx = NULL;
|
||||
void *provkey = NULL;
|
||||
int ret;
|
||||
|
||||
if (ctx->provctx != NULL) {
|
||||
if (!ossl_assert(ctx->digest != NULL)) {
|
||||
ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
|
||||
return 0;
|
||||
}
|
||||
if (ctx->digest->freectx != NULL)
|
||||
ctx->digest->freectx(ctx->provctx);
|
||||
ctx->provctx = NULL;
|
||||
}
|
||||
|
||||
if (ctx->pctx == NULL) {
|
||||
ctx->pctx = EVP_PKEY_CTX_new(pkey, e);
|
||||
if (ctx->pctx == NULL)
|
||||
return 0;
|
||||
} else if (pkey != NULL) {
|
||||
if (!EVP_PKEY_up_ref(pkey))
|
||||
return 0;
|
||||
EVP_PKEY_free(ctx->pctx->pkey);
|
||||
ctx->pctx->pkey = pkey;
|
||||
}
|
||||
locpctx = ctx->pctx;
|
||||
evp_pkey_ctx_free_old_ops(locpctx);
|
||||
if (locpctx->pkey == NULL)
|
||||
goto legacy;
|
||||
|
||||
if (e != NULL || locpctx->engine != NULL)
|
||||
goto legacy;
|
||||
|
||||
if (signature != NULL) {
|
||||
if (!EVP_SIGNATURE_up_ref(signature))
|
||||
goto err;
|
||||
} else {
|
||||
/*
|
||||
* TODO(3.0): Check for legacy handling. Remove this once all all
|
||||
* algorithms are moved to providers.
|
||||
*/
|
||||
switch (locpctx->pkey->type) {
|
||||
case NID_dsa:
|
||||
break;
|
||||
default:
|
||||
goto legacy;
|
||||
}
|
||||
signature
|
||||
= EVP_SIGNATURE_fetch(NULL, OBJ_nid2sn(locpctx->pkey->type), NULL);
|
||||
|
||||
if (signature == NULL) {
|
||||
ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
locpctx->operation = ver ? EVP_PKEY_OP_VERIFYCTX
|
||||
: EVP_PKEY_OP_SIGNCTX;
|
||||
|
||||
locpctx->op.sig.signature = signature;
|
||||
|
||||
locpctx->op.sig.sigprovctx
|
||||
= signature->newctx(ossl_provider_ctx(signature->prov));
|
||||
if (locpctx->op.sig.sigprovctx == NULL) {
|
||||
ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
|
||||
goto err;
|
||||
}
|
||||
provkey =
|
||||
evp_keymgmt_export_to_provider(locpctx->pkey, signature->keymgmt, 0);
|
||||
if (provkey == NULL) {
|
||||
ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (mdname == NULL) {
|
||||
mdname = EVP_MD_name(type);
|
||||
ctx->reqdigest = type;
|
||||
} else {
|
||||
/*
|
||||
* This might be requested by a later call to EVP_MD_CTX_md(). In that
|
||||
* case the "explicit fetch" rules apply for that function (as per
|
||||
* man pages), i.e. the ref count is not updated so the EVP_MD should
|
||||
* not be used beyound the lifetime of the EVP_MD_CTX.
|
||||
*/
|
||||
ctx->reqdigest
|
||||
= ctx->fetched_digest
|
||||
= EVP_MD_fetch(
|
||||
ossl_provider_library_context(EVP_SIGNATURE_provider(signature)),
|
||||
mdname, props);
|
||||
}
|
||||
|
||||
if (ver) {
|
||||
if (signature->digest_verify_init == NULL) {
|
||||
ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
|
||||
goto err;
|
||||
}
|
||||
ret = signature->digest_verify_init(locpctx->op.sig.sigprovctx, mdname,
|
||||
props, provkey);
|
||||
} else {
|
||||
if (signature->digest_sign_init == NULL) {
|
||||
ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
|
||||
goto err;
|
||||
}
|
||||
ret = signature->digest_sign_init(locpctx->op.sig.sigprovctx, mdname,
|
||||
props, provkey);
|
||||
}
|
||||
|
||||
return ret ? 1 : 0;
|
||||
err:
|
||||
evp_pkey_ctx_free_old_ops(locpctx);
|
||||
locpctx->operation = EVP_PKEY_OP_UNDEFINED;
|
||||
return 0;
|
||||
|
||||
legacy:
|
||||
if (!(ctx->pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM)) {
|
||||
|
||||
if (type == NULL) {
|
||||
@@ -85,23 +196,86 @@ static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int EVP_DigestSignInit_ex(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
|
||||
const char *mdname, const char *props, EVP_PKEY *pkey,
|
||||
EVP_SIGNATURE *signature)
|
||||
{
|
||||
return do_sigver_init(ctx, pctx, NULL, mdname, props, NULL, pkey, signature,
|
||||
0);
|
||||
}
|
||||
|
||||
int EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
|
||||
const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey)
|
||||
{
|
||||
return do_sigver_init(ctx, pctx, type, e, pkey, 0);
|
||||
return do_sigver_init(ctx, pctx, type, NULL, NULL, e, pkey, NULL, 0);
|
||||
}
|
||||
|
||||
int EVP_DigestVerifyInit_ex(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
|
||||
const char *mdname, const char *props,
|
||||
EVP_PKEY *pkey, EVP_SIGNATURE *signature)
|
||||
{
|
||||
return do_sigver_init(ctx, pctx, NULL, mdname, props, NULL, pkey, signature,
|
||||
1);
|
||||
}
|
||||
|
||||
int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
|
||||
const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey)
|
||||
{
|
||||
return do_sigver_init(ctx, pctx, type, e, pkey, 1);
|
||||
return do_sigver_init(ctx, pctx, type, NULL, NULL, e, pkey, NULL, 1);
|
||||
}
|
||||
#endif /* FIPS_MDOE */
|
||||
|
||||
int EVP_DigestSignUpdate(EVP_MD_CTX *ctx, const void *data, size_t dsize)
|
||||
{
|
||||
EVP_PKEY_CTX *pctx = ctx->pctx;
|
||||
|
||||
if (pctx == NULL
|
||||
|| pctx->operation != EVP_PKEY_OP_SIGNCTX
|
||||
|| pctx->op.sig.sigprovctx == NULL
|
||||
|| pctx->op.sig.signature == NULL)
|
||||
goto legacy;
|
||||
|
||||
return pctx->op.sig.signature->digest_sign_update(pctx->op.sig.sigprovctx,
|
||||
data, dsize);
|
||||
|
||||
legacy:
|
||||
return EVP_DigestUpdate(ctx, data, dsize);
|
||||
}
|
||||
|
||||
int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *data, size_t dsize)
|
||||
{
|
||||
EVP_PKEY_CTX *pctx = ctx->pctx;
|
||||
|
||||
if (pctx == NULL
|
||||
|| pctx->operation != EVP_PKEY_OP_VERIFYCTX
|
||||
|| pctx->op.sig.sigprovctx == NULL
|
||||
|| pctx->op.sig.signature == NULL)
|
||||
goto legacy;
|
||||
|
||||
return pctx->op.sig.signature->digest_verify_update(pctx->op.sig.sigprovctx,
|
||||
data, dsize);
|
||||
|
||||
legacy:
|
||||
return EVP_DigestUpdate(ctx, data, dsize);
|
||||
}
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
|
||||
size_t *siglen)
|
||||
{
|
||||
int sctx = 0, r = 0;
|
||||
EVP_PKEY_CTX *pctx = ctx->pctx;
|
||||
|
||||
if (pctx == NULL
|
||||
|| pctx->operation != EVP_PKEY_OP_SIGNCTX
|
||||
|| pctx->op.sig.sigprovctx == NULL
|
||||
|| pctx->op.sig.signature == NULL)
|
||||
goto legacy;
|
||||
|
||||
return pctx->op.sig.signature->digest_sign_final(pctx->op.sig.sigprovctx,
|
||||
sigret, siglen, SIZE_MAX);
|
||||
|
||||
legacy:
|
||||
if (pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM) {
|
||||
if (!sigret)
|
||||
return pctx->pmeth->signctx(pctx, sigret, siglen, ctx);
|
||||
@@ -177,7 +351,18 @@ int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig,
|
||||
int r = 0;
|
||||
unsigned int mdlen = 0;
|
||||
int vctx = 0;
|
||||
EVP_PKEY_CTX *pctx = ctx->pctx;
|
||||
|
||||
if (pctx == NULL
|
||||
|| pctx->operation != EVP_PKEY_OP_VERIFYCTX
|
||||
|| pctx->op.sig.sigprovctx == NULL
|
||||
|| pctx->op.sig.signature == NULL)
|
||||
goto legacy;
|
||||
|
||||
return pctx->op.sig.signature->digest_verify_final(pctx->op.sig.sigprovctx,
|
||||
sig, siglen);
|
||||
|
||||
legacy:
|
||||
if (ctx->pctx->pmeth->verifyctx)
|
||||
vctx = 1;
|
||||
else
|
||||
@@ -216,3 +401,4 @@ int EVP_DigestVerify(EVP_MD_CTX *ctx, const unsigned char *sigret,
|
||||
return -1;
|
||||
return EVP_DigestVerifyFinal(ctx, sigret, siglen);
|
||||
}
|
||||
#endif /* FIPS_MODE */
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
# include <openssl/objects.h>
|
||||
# include <openssl/x509.h>
|
||||
# include <openssl/whrlpool.h>
|
||||
# include "internal/evp_int.h"
|
||||
# include "crypto/evp.h"
|
||||
|
||||
static int init(EVP_MD_CTX *ctx)
|
||||
{
|
||||
|
||||
+21
-3
@@ -13,11 +13,11 @@
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/core.h>
|
||||
#include <openssl/core_names.h>
|
||||
#include <openssl/ossl_typ.h>
|
||||
#include <openssl/types.h>
|
||||
#include "internal/nelem.h"
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "internal/provider.h"
|
||||
#include "evp_locl.h"
|
||||
#include "evp_local.h"
|
||||
|
||||
EVP_MAC_CTX *EVP_MAC_CTX_new(EVP_MAC *mac)
|
||||
{
|
||||
@@ -157,3 +157,21 @@ int EVP_MAC_CTX_set_params(EVP_MAC_CTX *ctx, const OSSL_PARAM params[])
|
||||
return ctx->meth->set_ctx_params(ctx->data, params);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int EVP_MAC_number(const EVP_MAC *mac)
|
||||
{
|
||||
return mac->name_id;
|
||||
}
|
||||
|
||||
int EVP_MAC_is_a(const EVP_MAC *mac, const char *name)
|
||||
{
|
||||
return evp_is_a(mac->prov, mac->name_id, name);
|
||||
}
|
||||
|
||||
void EVP_MAC_names_do_all(const EVP_MAC *mac,
|
||||
void (*fn)(const char *name, void *data),
|
||||
void *data)
|
||||
{
|
||||
if (mac->prov != NULL)
|
||||
evp_names_do_all(mac->prov, mac->name_id, fn, data);
|
||||
}
|
||||
+7
-17
@@ -2,9 +2,9 @@
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/core.h>
|
||||
#include <openssl/core_numbers.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "internal/provider.h"
|
||||
#include "evp_locl.h"
|
||||
#include "evp_local.h"
|
||||
|
||||
static int evp_mac_up_ref(void *vmac)
|
||||
{
|
||||
@@ -168,16 +168,6 @@ void EVP_MAC_free(EVP_MAC *mac)
|
||||
evp_mac_free(mac);
|
||||
}
|
||||
|
||||
int EVP_MAC_is_a(const EVP_MAC *mac, const char *name)
|
||||
{
|
||||
return evp_is_a(mac->prov, mac->name_id, name);
|
||||
}
|
||||
|
||||
const char *EVP_MAC_name(const EVP_MAC *mac)
|
||||
{
|
||||
return evp_first_name(mac->prov, mac->name_id);
|
||||
}
|
||||
|
||||
const OSSL_PROVIDER *EVP_MAC_provider(const EVP_MAC *mac)
|
||||
{
|
||||
return mac->prov;
|
||||
@@ -190,23 +180,23 @@ const OSSL_PARAM *EVP_MAC_gettable_params(const EVP_MAC *mac)
|
||||
return mac->gettable_params();
|
||||
}
|
||||
|
||||
const OSSL_PARAM *EVP_MAC_CTX_gettable_params(const EVP_MAC *mac)
|
||||
const OSSL_PARAM *EVP_MAC_gettable_ctx_params(const EVP_MAC *mac)
|
||||
{
|
||||
if (mac->gettable_ctx_params == NULL)
|
||||
return NULL;
|
||||
return mac->gettable_ctx_params();
|
||||
}
|
||||
|
||||
const OSSL_PARAM *EVP_MAC_CTX_settable_params(const EVP_MAC *mac)
|
||||
const OSSL_PARAM *EVP_MAC_settable_ctx_params(const EVP_MAC *mac)
|
||||
{
|
||||
if (mac->settable_ctx_params == NULL)
|
||||
return NULL;
|
||||
return mac->settable_ctx_params();
|
||||
}
|
||||
|
||||
void EVP_MAC_do_all_ex(OPENSSL_CTX *libctx,
|
||||
void (*fn)(EVP_MAC *mac, void *arg),
|
||||
void *arg)
|
||||
void EVP_MAC_do_all_provided(OPENSSL_CTX *libctx,
|
||||
void (*fn)(EVP_MAC *mac, void *arg),
|
||||
void *arg)
|
||||
{
|
||||
evp_generic_do_all(libctx, OSSL_OP_MAC,
|
||||
(void (*)(void *, void *))fn, arg,
|
||||
|
||||
+2
-2
@@ -11,9 +11,9 @@
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/kdf.h>
|
||||
#include "internal/objects.h"
|
||||
#include "crypto/objects.h"
|
||||
#include <openssl/x509.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/evp.h"
|
||||
|
||||
int EVP_add_cipher(const EVP_CIPHER *c)
|
||||
{
|
||||
|
||||
@@ -59,14 +59,14 @@ int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!pbe->iter)
|
||||
if (pbe->iter == NULL)
|
||||
iter = 1;
|
||||
else
|
||||
iter = ASN1_INTEGER_get(pbe->iter);
|
||||
salt = pbe->salt->data;
|
||||
saltlen = pbe->salt->length;
|
||||
|
||||
if (!pass)
|
||||
if (pass == NULL)
|
||||
passlen = 0;
|
||||
else if (passlen == -1)
|
||||
passlen = strlen(pass);
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
#include <openssl/hmac.h>
|
||||
#include <openssl/trace.h>
|
||||
#include <openssl/core_names.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "evp_locl.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "evp_local.h"
|
||||
|
||||
int PKCS5_PBKDF2_HMAC(const char *pass, int passlen,
|
||||
const unsigned char *salt, int saltlen, int iter,
|
||||
|
||||
+4
-5
@@ -23,8 +23,8 @@
|
||||
#include <openssl/params.h>
|
||||
#include <openssl/core_names.h>
|
||||
|
||||
#include "internal/asn1_int.h"
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/asn1.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "internal/provider.h"
|
||||
|
||||
static void EVP_PKEY_free_it(EVP_PKEY *x);
|
||||
@@ -40,7 +40,7 @@ int EVP_PKEY_security_bits(const EVP_PKEY *pkey)
|
||||
{
|
||||
if (pkey == NULL)
|
||||
return 0;
|
||||
if (!pkey->ameth || !pkey->ameth->pkey_security_bits)
|
||||
if (pkey->ameth == NULL || pkey->ameth->pkey_security_bits == NULL)
|
||||
return -2;
|
||||
return pkey->ameth->pkey_security_bits(pkey);
|
||||
}
|
||||
@@ -344,8 +344,7 @@ EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv,
|
||||
# ifndef OPENSSL_NO_ENGINE
|
||||
if (engine_id != NULL)
|
||||
params[paramsn++] =
|
||||
OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_ENGINE,
|
||||
(char *)engine_id, 0);
|
||||
OSSL_PARAM_construct_utf8_string("engine", (char *)engine_id, 0);
|
||||
# endif
|
||||
|
||||
params[paramsn++] =
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ int EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!priv)
|
||||
if (priv == NULL)
|
||||
return 1;
|
||||
|
||||
if (EVP_PKEY_id(priv) != EVP_PKEY_RSA) {
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/x509.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/evp.h"
|
||||
|
||||
int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
|
||||
unsigned int *siglen, EVP_PKEY *pkey)
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/x509.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/evp.h"
|
||||
|
||||
int EVP_VerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sigbuf,
|
||||
unsigned int siglen, EVP_PKEY *pkey)
|
||||
|
||||
+19
-5
@@ -17,7 +17,7 @@
|
||||
#include <openssl/core_names.h>
|
||||
#include <openssl/params.h>
|
||||
#include "internal/numbers.h"
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/evp.h"
|
||||
|
||||
#define MAX_PARAM 20
|
||||
|
||||
@@ -213,7 +213,7 @@ static int pkey_kdf_ctrl_str(EVP_PKEY_CTX *ctx, const char *type,
|
||||
EVP_KDF_CTX *kctx = pkctx->kctx;
|
||||
const EVP_KDF *kdf = EVP_KDF_CTX_kdf(kctx);
|
||||
BUF_MEM **collector = NULL;
|
||||
const OSSL_PARAM *defs = EVP_KDF_CTX_settable_params(kdf);
|
||||
const OSSL_PARAM *defs = EVP_KDF_settable_ctx_params(kdf);
|
||||
OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
|
||||
int ok = 0;
|
||||
|
||||
@@ -307,7 +307,7 @@ static int pkey_kdf_derive(EVP_PKEY_CTX *ctx, unsigned char *key,
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_SCRYPT
|
||||
const EVP_PKEY_METHOD scrypt_pkey_meth = {
|
||||
static const EVP_PKEY_METHOD scrypt_pkey_meth = {
|
||||
EVP_PKEY_SCRYPT,
|
||||
0,
|
||||
pkey_kdf_init,
|
||||
@@ -336,9 +336,14 @@ const EVP_PKEY_METHOD scrypt_pkey_meth = {
|
||||
pkey_kdf_ctrl,
|
||||
pkey_kdf_ctrl_str
|
||||
};
|
||||
|
||||
const EVP_PKEY_METHOD *scrypt_pkey_method(void)
|
||||
{
|
||||
return &scrypt_pkey_meth;
|
||||
}
|
||||
#endif
|
||||
|
||||
const EVP_PKEY_METHOD tls1_prf_pkey_meth = {
|
||||
static const EVP_PKEY_METHOD tls1_prf_pkey_meth = {
|
||||
EVP_PKEY_TLS1_PRF,
|
||||
0,
|
||||
pkey_kdf_init,
|
||||
@@ -368,7 +373,12 @@ const EVP_PKEY_METHOD tls1_prf_pkey_meth = {
|
||||
pkey_kdf_ctrl_str
|
||||
};
|
||||
|
||||
const EVP_PKEY_METHOD hkdf_pkey_meth = {
|
||||
const EVP_PKEY_METHOD *tls1_prf_pkey_method(void)
|
||||
{
|
||||
return &tls1_prf_pkey_meth;
|
||||
}
|
||||
|
||||
static const EVP_PKEY_METHOD hkdf_pkey_meth = {
|
||||
EVP_PKEY_HKDF,
|
||||
0,
|
||||
pkey_kdf_init,
|
||||
@@ -398,3 +408,7 @@ const EVP_PKEY_METHOD hkdf_pkey_meth = {
|
||||
pkey_kdf_ctrl_str
|
||||
};
|
||||
|
||||
const EVP_PKEY_METHOD *hkdf_pkey_method(void)
|
||||
{
|
||||
return &hkdf_pkey_meth;
|
||||
}
|
||||
+30
-13
@@ -13,8 +13,8 @@
|
||||
#include <openssl/engine.h>
|
||||
#include <openssl/params.h>
|
||||
#include <openssl/core_names.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "evp_locl.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "evp_local.h"
|
||||
|
||||
/* MAC PKEY context structure */
|
||||
|
||||
@@ -278,8 +278,7 @@ static int pkey_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
|
||||
char *engineid = (char *)ENGINE_get_id(ctx->engine);
|
||||
|
||||
params[params_n++] =
|
||||
OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_ENGINE,
|
||||
engineid, 0);
|
||||
OSSL_PARAM_construct_utf8_string("engine", engineid, 0);
|
||||
#endif
|
||||
params[params_n++] =
|
||||
OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_CIPHER,
|
||||
@@ -400,11 +399,9 @@ static int pkey_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
|
||||
char *engineid = ctx->engine == NULL
|
||||
? NULL : (char *)ENGINE_get_id(ctx->engine);
|
||||
|
||||
if (engineid != NULL) {
|
||||
if (engineid != NULL)
|
||||
params[params_n++] =
|
||||
OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_ENGINE,
|
||||
engineid, 0);
|
||||
}
|
||||
OSSL_PARAM_construct_utf8_string("engine", engineid, 0);
|
||||
#endif
|
||||
params[params_n++] =
|
||||
OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_DIGEST,
|
||||
@@ -455,7 +452,7 @@ static int pkey_mac_ctrl_str(EVP_PKEY_CTX *ctx,
|
||||
type = OSSL_MAC_PARAM_SIZE;
|
||||
|
||||
if (!OSSL_PARAM_allocate_from_text(¶ms[0],
|
||||
EVP_MAC_CTX_settable_params(mac),
|
||||
EVP_MAC_settable_ctx_params(mac),
|
||||
type, value, strlen(value) + 1))
|
||||
return 0;
|
||||
params[1] = OSSL_PARAM_construct_end();
|
||||
@@ -464,7 +461,7 @@ static int pkey_mac_ctrl_str(EVP_PKEY_CTX *ctx,
|
||||
return ok;
|
||||
}
|
||||
|
||||
const EVP_PKEY_METHOD cmac_pkey_meth = {
|
||||
static const EVP_PKEY_METHOD cmac_pkey_meth = {
|
||||
EVP_PKEY_CMAC,
|
||||
EVP_PKEY_FLAG_SIGCTX_CUSTOM,
|
||||
pkey_mac_init,
|
||||
@@ -497,7 +494,12 @@ const EVP_PKEY_METHOD cmac_pkey_meth = {
|
||||
pkey_mac_ctrl_str
|
||||
};
|
||||
|
||||
const EVP_PKEY_METHOD hmac_pkey_meth = {
|
||||
const EVP_PKEY_METHOD *cmac_pkey_method(void)
|
||||
{
|
||||
return &cmac_pkey_meth;
|
||||
}
|
||||
|
||||
static const EVP_PKEY_METHOD hmac_pkey_meth = {
|
||||
EVP_PKEY_HMAC,
|
||||
0,
|
||||
pkey_mac_init,
|
||||
@@ -530,7 +532,12 @@ const EVP_PKEY_METHOD hmac_pkey_meth = {
|
||||
pkey_mac_ctrl_str
|
||||
};
|
||||
|
||||
const EVP_PKEY_METHOD siphash_pkey_meth = {
|
||||
const EVP_PKEY_METHOD *hmac_pkey_method(void)
|
||||
{
|
||||
return &hmac_pkey_meth;
|
||||
}
|
||||
|
||||
static const EVP_PKEY_METHOD siphash_pkey_meth = {
|
||||
EVP_PKEY_SIPHASH,
|
||||
EVP_PKEY_FLAG_SIGCTX_CUSTOM,
|
||||
pkey_mac_init,
|
||||
@@ -563,7 +570,12 @@ const EVP_PKEY_METHOD siphash_pkey_meth = {
|
||||
pkey_mac_ctrl_str
|
||||
};
|
||||
|
||||
const EVP_PKEY_METHOD poly1305_pkey_meth = {
|
||||
const EVP_PKEY_METHOD *siphash_pkey_method(void)
|
||||
{
|
||||
return &siphash_pkey_meth;
|
||||
}
|
||||
|
||||
static const EVP_PKEY_METHOD poly1305_pkey_meth = {
|
||||
EVP_PKEY_POLY1305,
|
||||
EVP_PKEY_FLAG_SIGCTX_CUSTOM,
|
||||
pkey_mac_init,
|
||||
@@ -595,3 +607,8 @@ const EVP_PKEY_METHOD poly1305_pkey_meth = {
|
||||
pkey_mac_ctrl,
|
||||
pkey_mac_ctrl_str
|
||||
};
|
||||
|
||||
const EVP_PKEY_METHOD *poly1305_pkey_method(void)
|
||||
{
|
||||
return &poly1305_pkey_meth;
|
||||
}
|
||||
+135
-13
@@ -12,9 +12,9 @@
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/evp.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "internal/provider.h"
|
||||
#include "evp_locl.h"
|
||||
#include "evp_local.h"
|
||||
|
||||
static EVP_SIGNATURE *evp_signature_new(OSSL_PROVIDER *prov)
|
||||
{
|
||||
@@ -52,7 +52,8 @@ static void *evp_signature_from_dispatch(int name_id,
|
||||
keymgmt_data->properties);
|
||||
EVP_SIGNATURE *signature = NULL;
|
||||
int ctxfncnt = 0, signfncnt = 0, verifyfncnt = 0, verifyrecfncnt = 0;
|
||||
int gparamfncnt = 0, sparamfncnt = 0;
|
||||
int digsignfncnt = 0, digverifyfncnt = 0;
|
||||
int gparamfncnt = 0, sparamfncnt = 0, gmdparamfncnt = 0, smdparamfncnt = 0;
|
||||
|
||||
if (keymgmt == NULL || EVP_KEYMGMT_provider(keymgmt) != prov) {
|
||||
ERR_raise(ERR_LIB_EVP, EVP_R_NO_KEYMGMT_AVAILABLE);
|
||||
@@ -114,6 +115,48 @@ static void *evp_signature_from_dispatch(int name_id,
|
||||
= OSSL_get_OP_signature_verify_recover(fns);
|
||||
verifyrecfncnt++;
|
||||
break;
|
||||
case OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT:
|
||||
if (signature->digest_sign_init != NULL)
|
||||
break;
|
||||
signature->digest_sign_init
|
||||
= OSSL_get_OP_signature_digest_sign_init(fns);
|
||||
digsignfncnt++;
|
||||
break;
|
||||
case OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE:
|
||||
if (signature->digest_sign_update != NULL)
|
||||
break;
|
||||
signature->digest_sign_update
|
||||
= OSSL_get_OP_signature_digest_sign_update(fns);
|
||||
digsignfncnt++;
|
||||
break;
|
||||
case OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL:
|
||||
if (signature->digest_sign_final != NULL)
|
||||
break;
|
||||
signature->digest_sign_final
|
||||
= OSSL_get_OP_signature_digest_sign_final(fns);
|
||||
digsignfncnt++;
|
||||
break;
|
||||
case OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT:
|
||||
if (signature->digest_verify_init != NULL)
|
||||
break;
|
||||
signature->digest_verify_init
|
||||
= OSSL_get_OP_signature_digest_verify_init(fns);
|
||||
digverifyfncnt++;
|
||||
break;
|
||||
case OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE:
|
||||
if (signature->digest_verify_update != NULL)
|
||||
break;
|
||||
signature->digest_verify_update
|
||||
= OSSL_get_OP_signature_digest_verify_update(fns);
|
||||
digverifyfncnt++;
|
||||
break;
|
||||
case OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL:
|
||||
if (signature->digest_verify_final != NULL)
|
||||
break;
|
||||
signature->digest_verify_final
|
||||
= OSSL_get_OP_signature_digest_verify_final(fns);
|
||||
digverifyfncnt++;
|
||||
break;
|
||||
case OSSL_FUNC_SIGNATURE_FREECTX:
|
||||
if (signature->freectx != NULL)
|
||||
break;
|
||||
@@ -153,21 +196,65 @@ static void *evp_signature_from_dispatch(int name_id,
|
||||
= OSSL_get_OP_signature_settable_ctx_params(fns);
|
||||
sparamfncnt++;
|
||||
break;
|
||||
case OSSL_FUNC_SIGNATURE_GET_CTX_MD_PARAMS:
|
||||
if (signature->get_ctx_md_params != NULL)
|
||||
break;
|
||||
signature->get_ctx_md_params
|
||||
= OSSL_get_OP_signature_get_ctx_md_params(fns);
|
||||
gmdparamfncnt++;
|
||||
break;
|
||||
case OSSL_FUNC_SIGNATURE_GETTABLE_CTX_MD_PARAMS:
|
||||
if (signature->gettable_ctx_md_params != NULL)
|
||||
break;
|
||||
signature->gettable_ctx_md_params
|
||||
= OSSL_get_OP_signature_gettable_ctx_md_params(fns);
|
||||
gmdparamfncnt++;
|
||||
break;
|
||||
case OSSL_FUNC_SIGNATURE_SET_CTX_MD_PARAMS:
|
||||
if (signature->set_ctx_md_params != NULL)
|
||||
break;
|
||||
signature->set_ctx_md_params
|
||||
= OSSL_get_OP_signature_set_ctx_md_params(fns);
|
||||
smdparamfncnt++;
|
||||
break;
|
||||
case OSSL_FUNC_SIGNATURE_SETTABLE_CTX_MD_PARAMS:
|
||||
if (signature->settable_ctx_md_params != NULL)
|
||||
break;
|
||||
signature->settable_ctx_md_params
|
||||
= OSSL_get_OP_signature_settable_ctx_md_params(fns);
|
||||
smdparamfncnt++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ctxfncnt != 2
|
||||
|| (signfncnt != 2 && verifyfncnt != 2 && verifyrecfncnt != 2)
|
||||
|| (signfncnt == 0
|
||||
&& verifyfncnt == 0
|
||||
&& verifyrecfncnt == 0
|
||||
&& digsignfncnt == 0
|
||||
&& digverifyfncnt == 0)
|
||||
|| (signfncnt != 0 && signfncnt != 2)
|
||||
|| (verifyfncnt != 0 && verifyfncnt != 2)
|
||||
|| (verifyrecfncnt != 0 && verifyrecfncnt != 2)
|
||||
|| (digsignfncnt != 0 && digsignfncnt != 3)
|
||||
|| (digverifyfncnt != 0 && digverifyfncnt != 3)
|
||||
|| (gparamfncnt != 0 && gparamfncnt != 2)
|
||||
|| (sparamfncnt != 0 && sparamfncnt != 2)) {
|
||||
|| (sparamfncnt != 0 && sparamfncnt != 2)
|
||||
|| (gmdparamfncnt != 0 && gmdparamfncnt != 2)
|
||||
|| (smdparamfncnt != 0 && smdparamfncnt != 2)) {
|
||||
/*
|
||||
* In order to be a consistent set of functions we must have at least
|
||||
* a set of context functions (newctx and freectx) as well as a pair of
|
||||
* "signature" functions: (sign_init, sign) or (verify_init verify) or
|
||||
* (verify_recover_init, verify_recover). set_ctx_params and
|
||||
* settable_ctx_params are optional, but if one of them is present then
|
||||
* the other one must also be present. The same applies to
|
||||
* get_ctx_params and gettable_ctx_params. The dupctx function is
|
||||
* optional.
|
||||
* a set of context functions (newctx and freectx) as well as a set of
|
||||
* "signature" functions:
|
||||
* (sign_init, sign) or
|
||||
* (verify_init verify) or
|
||||
* (verify_recover_init, verify_recover) or
|
||||
* (digest_sign_init, digest_sign_update, digest_sign_final) or
|
||||
* (digest_verify_init, digest_verify_update, digest_verify_final).
|
||||
*
|
||||
* set_ctx_params and settable_ctx_params are optional, but if one of
|
||||
* them is present then the other one must also be present. The same
|
||||
* applies to get_ctx_params and gettable_ctx_params. The same rules
|
||||
* apply to the "md_params" functions. The dupctx function is optional.
|
||||
*/
|
||||
ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS);
|
||||
goto err;
|
||||
@@ -225,6 +312,40 @@ EVP_SIGNATURE *EVP_SIGNATURE_fetch(OPENSSL_CTX *ctx, const char *algorithm,
|
||||
(void (*)(void *))EVP_SIGNATURE_free);
|
||||
}
|
||||
|
||||
int EVP_SIGNATURE_is_a(const EVP_SIGNATURE *signature, const char *name)
|
||||
{
|
||||
return evp_is_a(signature->prov, signature->name_id, name);
|
||||
}
|
||||
|
||||
int EVP_SIGNATURE_number(const EVP_SIGNATURE *signature)
|
||||
{
|
||||
return signature->name_id;
|
||||
}
|
||||
|
||||
void EVP_SIGNATURE_do_all_provided(OPENSSL_CTX *libctx,
|
||||
void (*fn)(EVP_SIGNATURE *signature,
|
||||
void *arg),
|
||||
void *arg)
|
||||
{
|
||||
struct keymgmt_data_st keymgmt_data;
|
||||
|
||||
keymgmt_data.ctx = libctx;
|
||||
keymgmt_data.properties = NULL;
|
||||
evp_generic_do_all(libctx, OSSL_OP_SIGNATURE,
|
||||
(void (*)(void *, void *))fn, arg,
|
||||
evp_signature_from_dispatch, &keymgmt_data,
|
||||
(void (*)(void *))EVP_SIGNATURE_free);
|
||||
}
|
||||
|
||||
|
||||
void EVP_SIGNATURE_names_do_all(const EVP_SIGNATURE *signature,
|
||||
void (*fn)(const char *name, void *data),
|
||||
void *data)
|
||||
{
|
||||
if (signature->prov != NULL)
|
||||
evp_names_do_all(signature->prov, signature->name_id, fn, data);
|
||||
}
|
||||
|
||||
static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, EVP_SIGNATURE *signature,
|
||||
int operation)
|
||||
{
|
||||
@@ -272,7 +393,8 @@ static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, EVP_SIGNATURE *signature,
|
||||
|
||||
ctx->op.sig.signature = signature;
|
||||
if (ctx->pkey != NULL) {
|
||||
provkey = evp_keymgmt_export_to_provider(ctx->pkey, signature->keymgmt);
|
||||
provkey =
|
||||
evp_keymgmt_export_to_provider(ctx->pkey, signature->keymgmt, 0);
|
||||
if (provkey == NULL) {
|
||||
EVPerr(0, EVP_R_INITIALIZATION_ERROR);
|
||||
goto err;
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/evp.h>
|
||||
#include "internal/bn_int.h"
|
||||
#include "internal/asn1_int.h"
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/bn.h"
|
||||
#include "crypto/asn1.h"
|
||||
#include "crypto/evp.h"
|
||||
|
||||
int EVP_PKEY_paramgen_init(EVP_PKEY_CTX *ctx)
|
||||
{
|
||||
|
||||
+57
-37
@@ -16,66 +16,73 @@
|
||||
#include <openssl/core_names.h>
|
||||
#include <openssl/dh.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/asn1_int.h"
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/asn1.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "internal/numbers.h"
|
||||
#include "internal/provider.h"
|
||||
#include "evp_locl.h"
|
||||
#include "evp_local.h"
|
||||
|
||||
typedef const EVP_PKEY_METHOD *(*pmeth_fn)(void);
|
||||
typedef int sk_cmp_fn_type(const char *const *a, const char *const *b);
|
||||
|
||||
static STACK_OF(EVP_PKEY_METHOD) *app_pkey_methods = NULL;
|
||||
|
||||
/* This array needs to be in order of NIDs */
|
||||
static const EVP_PKEY_METHOD *standard_methods[] = {
|
||||
static pmeth_fn standard_methods[] = {
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
&rsa_pkey_meth,
|
||||
rsa_pkey_method,
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DH
|
||||
&dh_pkey_meth,
|
||||
dh_pkey_method,
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
&dsa_pkey_meth,
|
||||
dsa_pkey_method,
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_EC
|
||||
&ec_pkey_meth,
|
||||
ec_pkey_method,
|
||||
#endif
|
||||
&hmac_pkey_meth,
|
||||
hmac_pkey_method,
|
||||
#ifndef OPENSSL_NO_CMAC
|
||||
&cmac_pkey_meth,
|
||||
cmac_pkey_method,
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
&rsa_pss_pkey_meth,
|
||||
rsa_pss_pkey_method,
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DH
|
||||
&dhx_pkey_meth,
|
||||
dhx_pkey_method,
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_SCRYPT
|
||||
&scrypt_pkey_meth,
|
||||
scrypt_pkey_method,
|
||||
#endif
|
||||
&tls1_prf_pkey_meth,
|
||||
tls1_prf_pkey_method,
|
||||
#ifndef OPENSSL_NO_EC
|
||||
&ecx25519_pkey_meth,
|
||||
&ecx448_pkey_meth,
|
||||
ecx25519_pkey_method,
|
||||
ecx448_pkey_method,
|
||||
#endif
|
||||
&hkdf_pkey_meth,
|
||||
hkdf_pkey_method,
|
||||
#ifndef OPENSSL_NO_POLY1305
|
||||
&poly1305_pkey_meth,
|
||||
poly1305_pkey_method,
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_SIPHASH
|
||||
&siphash_pkey_meth,
|
||||
siphash_pkey_method,
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_EC
|
||||
&ed25519_pkey_meth,
|
||||
&ed448_pkey_meth,
|
||||
ed25519_pkey_method,
|
||||
ed448_pkey_method,
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
&sm2_pkey_meth,
|
||||
sm2_pkey_method,
|
||||
#endif
|
||||
};
|
||||
|
||||
DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *,
|
||||
pmeth);
|
||||
DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, pmeth_fn, pmeth_func);
|
||||
|
||||
static int pmeth_func_cmp(const EVP_PKEY_METHOD *const *a, pmeth_fn const *b)
|
||||
{
|
||||
return ((*a)->pkey_id - ((**b)())->pkey_id);
|
||||
}
|
||||
|
||||
IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, pmeth_fn, pmeth_func);
|
||||
|
||||
static int pmeth_cmp(const EVP_PKEY_METHOD *const *a,
|
||||
const EVP_PKEY_METHOD *const *b)
|
||||
@@ -83,13 +90,12 @@ static int pmeth_cmp(const EVP_PKEY_METHOD *const *a,
|
||||
return ((*a)->pkey_id - (*b)->pkey_id);
|
||||
}
|
||||
|
||||
IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *,
|
||||
pmeth);
|
||||
|
||||
const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type)
|
||||
{
|
||||
pmeth_fn *ret;
|
||||
EVP_PKEY_METHOD tmp;
|
||||
const EVP_PKEY_METHOD *t = &tmp, **ret;
|
||||
const EVP_PKEY_METHOD *t = &tmp;
|
||||
|
||||
tmp.pkey_id = type;
|
||||
if (app_pkey_methods) {
|
||||
int idx;
|
||||
@@ -97,15 +103,17 @@ const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type)
|
||||
if (idx >= 0)
|
||||
return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx);
|
||||
}
|
||||
ret = OBJ_bsearch_pmeth(&t, standard_methods,
|
||||
sizeof(standard_methods) /
|
||||
sizeof(EVP_PKEY_METHOD *));
|
||||
if (!ret || !*ret)
|
||||
ret = OBJ_bsearch_pmeth_func(&t, standard_methods,
|
||||
sizeof(standard_methods) /
|
||||
sizeof(pmeth_fn));
|
||||
if (ret == NULL || *ret == NULL)
|
||||
return NULL;
|
||||
return *ret;
|
||||
return (**ret)();
|
||||
}
|
||||
|
||||
static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
|
||||
static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e,
|
||||
const char *name, const char *propquery,
|
||||
int id)
|
||||
{
|
||||
EVP_PKEY_CTX *ret;
|
||||
const EVP_PKEY_METHOD *pmeth = NULL;
|
||||
@@ -124,6 +132,8 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
|
||||
return 0;
|
||||
id = pkey->type;
|
||||
}
|
||||
name = OBJ_nid2sn(id);
|
||||
propquery = NULL;
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
if (e == NULL && pkey != NULL)
|
||||
e = pkey->pmeth_engine != NULL ? pkey->pmeth_engine : pkey->engine;
|
||||
@@ -165,6 +175,8 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
|
||||
EVPerr(EVP_F_INT_CTX_NEW, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
ret->algorithm = name;
|
||||
ret->propquery = propquery;
|
||||
ret->engine = e;
|
||||
ret->pmeth = pmeth;
|
||||
ret->operation = EVP_PKEY_OP_UNDEFINED;
|
||||
@@ -271,12 +283,18 @@ void EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth)
|
||||
|
||||
EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e)
|
||||
{
|
||||
return int_ctx_new(pkey, e, -1);
|
||||
return int_ctx_new(pkey, e, NULL, NULL, -1);
|
||||
}
|
||||
|
||||
EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e)
|
||||
{
|
||||
return int_ctx_new(NULL, e, id);
|
||||
return int_ctx_new(NULL, e, NULL, NULL, id);
|
||||
}
|
||||
|
||||
EVP_PKEY_CTX *EVP_PKEY_CTX_new_provided(const char *name,
|
||||
const char *propquery)
|
||||
{
|
||||
return int_ctx_new(NULL, NULL, name, propquery, -1);
|
||||
}
|
||||
|
||||
EVP_PKEY_CTX *EVP_PKEY_CTX_dup(const EVP_PKEY_CTX *pctx)
|
||||
@@ -306,6 +324,8 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_dup(const EVP_PKEY_CTX *pctx)
|
||||
EVP_PKEY_up_ref(pctx->pkey);
|
||||
rctx->pkey = pctx->pkey;
|
||||
rctx->operation = pctx->operation;
|
||||
rctx->algorithm = pctx->algorithm;
|
||||
rctx->propquery = pctx->propquery;
|
||||
|
||||
if (EVP_PKEY_CTX_IS_DERIVE_OP(pctx)) {
|
||||
if (pctx->op.kex.exchange != NULL) {
|
||||
@@ -411,7 +431,7 @@ size_t EVP_PKEY_meth_get_count(void)
|
||||
const EVP_PKEY_METHOD *EVP_PKEY_meth_get0(size_t idx)
|
||||
{
|
||||
if (idx < OSSL_NELEM(standard_methods))
|
||||
return standard_methods[idx];
|
||||
return (standard_methods[idx])();
|
||||
if (app_pkey_methods == NULL)
|
||||
return NULL;
|
||||
idx -= OSSL_NELEM(standard_methods);
|
||||
|
||||
Reference in New Issue
Block a user