diff options
Diffstat (limited to 'crypto/evp')
-rw-r--r-- | crypto/evp/asymcipher.c | 21 | ||||
-rw-r--r-- | crypto/evp/digest.c | 28 | ||||
-rw-r--r-- | crypto/evp/evp_enc.c | 58 | ||||
-rw-r--r-- | crypto/evp/exchange.c | 7 | ||||
-rw-r--r-- | crypto/evp/kem.c | 15 | ||||
-rw-r--r-- | crypto/evp/m_sigver.c | 25 | ||||
-rw-r--r-- | crypto/evp/signature.c | 32 |
7 files changed, 136 insertions, 50 deletions
diff --git a/crypto/evp/asymcipher.c b/crypto/evp/asymcipher.c index b30b05bfa9..e74aafcb13 100644 --- a/crypto/evp/asymcipher.c +++ b/crypto/evp/asymcipher.c @@ -16,7 +16,8 @@ #include "internal/provider.h" #include "evp_local.h" -static int evp_pkey_asym_cipher_init(EVP_PKEY_CTX *ctx, int operation) +static int evp_pkey_asym_cipher_init(EVP_PKEY_CTX *ctx, int operation, + const OSSL_PARAM params[]) { int ret = 0; void *provkey = NULL; @@ -111,7 +112,7 @@ static int evp_pkey_asym_cipher_init(EVP_PKEY_CTX *ctx, int operation) ret = -2; goto err; } - ret = cipher->encrypt_init(ctx->op.ciph.ciphprovctx, provkey); + ret = cipher->encrypt_init(ctx->op.ciph.ciphprovctx, provkey, params); break; case EVP_PKEY_OP_DECRYPT: if (cipher->decrypt_init == NULL) { @@ -119,7 +120,7 @@ static int evp_pkey_asym_cipher_init(EVP_PKEY_CTX *ctx, int operation) ret = -2; goto err; } - ret = cipher->decrypt_init(ctx->op.ciph.ciphprovctx, provkey); + ret = cipher->decrypt_init(ctx->op.ciph.ciphprovctx, provkey, params); break; default: ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); @@ -168,7 +169,12 @@ static int evp_pkey_asym_cipher_init(EVP_PKEY_CTX *ctx, int operation) int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx) { - return evp_pkey_asym_cipher_init(ctx, EVP_PKEY_OP_ENCRYPT); + return evp_pkey_asym_cipher_init(ctx, EVP_PKEY_OP_ENCRYPT, NULL); +} + +int EVP_PKEY_encrypt_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]) +{ + return evp_pkey_asym_cipher_init(ctx, EVP_PKEY_OP_ENCRYPT, params); } int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx, @@ -205,7 +211,12 @@ int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx, int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx) { - return evp_pkey_asym_cipher_init(ctx, EVP_PKEY_OP_DECRYPT); + return evp_pkey_asym_cipher_init(ctx, EVP_PKEY_OP_DECRYPT, NULL); +} + +int EVP_PKEY_decrypt_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]) +{ + return evp_pkey_asym_cipher_init(ctx, EVP_PKEY_OP_DECRYPT, params); } int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c index 069eb192c1..dbbc44f046 100644 --- a/crypto/evp/digest.c +++ b/crypto/evp/digest.c @@ -124,13 +124,8 @@ void EVP_MD_CTX_free(EVP_MD_CTX *ctx) return; } -int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type) -{ - EVP_MD_CTX_reset(ctx); - return EVP_DigestInit_ex(ctx, type, NULL); -} - -int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) +static int evp_md_init_internal(EVP_MD_CTX *ctx, const EVP_MD *type, + const OSSL_PARAM params[], ENGINE *impl) { #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) ENGINE *tmpimpl = NULL; @@ -272,7 +267,7 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) return 0; } - return ctx->digest->dinit(ctx->provctx); + return ctx->digest->dinit(ctx->provctx, params); /* Code below to be removed when legacy support is dropped. */ legacy: @@ -346,6 +341,23 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) return ctx->digest->init(ctx); } +int EVP_DigestInit_ex2(EVP_MD_CTX *ctx, const EVP_MD *type, + const OSSL_PARAM params[]) +{ + return evp_md_init_internal(ctx, type, params, NULL); +} + +int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type) +{ + EVP_MD_CTX_reset(ctx); + return evp_md_init_internal(ctx, type, NULL, NULL); +} + +int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) +{ + return evp_md_init_internal(ctx, type, NULL, impl); +} + int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t count) { if (count == 0) diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c index 40e9f0b6c3..eb174c2d9f 100644 --- a/crypto/evp/evp_enc.c +++ b/crypto/evp/evp_enc.c @@ -72,17 +72,11 @@ void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx) OPENSSL_free(ctx); } -int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, - const unsigned char *key, const unsigned char *iv, int enc) -{ - if (cipher != NULL) - EVP_CIPHER_CTX_reset(ctx); - return EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, enc); -} - -int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, - ENGINE *impl, const unsigned char *key, - const unsigned char *iv, int enc) +static int evp_cipher_init_internal(EVP_CIPHER_CTX *ctx, + const EVP_CIPHER *cipher, + ENGINE *impl, const unsigned char *key, + const unsigned char *iv, int enc, + const OSSL_PARAM params[]) { #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) ENGINE *tmpimpl = NULL; @@ -221,7 +215,8 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, : EVP_CIPHER_CTX_key_length(ctx), iv, iv == NULL ? 0 - : EVP_CIPHER_CTX_iv_length(ctx)); + : EVP_CIPHER_CTX_iv_length(ctx), + params); } if (ctx->cipher->dinit == NULL) { @@ -235,7 +230,8 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, : EVP_CIPHER_CTX_key_length(ctx), iv, iv == NULL ? 0 - : EVP_CIPHER_CTX_iv_length(ctx)); + : EVP_CIPHER_CTX_iv_length(ctx), + params); /* Code below to be removed when legacy support is dropped. */ legacy: @@ -370,6 +366,28 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, return 1; } +int EVP_CipherInit_ex2(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, + const unsigned char *key, const unsigned char *iv, + int enc, const OSSL_PARAM params[]) +{ + return evp_cipher_init_internal(ctx, cipher, NULL, key, iv, enc, params); +} + +int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, + const unsigned char *key, const unsigned char *iv, int enc) +{ + if (cipher != NULL) + EVP_CIPHER_CTX_reset(ctx); + return evp_cipher_init_internal(ctx, cipher, NULL, key, iv, enc, NULL); +} + +int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, + ENGINE *impl, const unsigned char *key, + const unsigned char *iv, int enc) +{ + return evp_cipher_init_internal(ctx, cipher, impl, key, iv, enc, NULL); +} + int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl) { @@ -408,6 +426,13 @@ int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 1); } +int EVP_EncryptInit_ex2(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, + const unsigned char *key, const unsigned char *iv, + const OSSL_PARAM params[]) +{ + return EVP_CipherInit_ex2(ctx, cipher, key, iv, 1, params); +} + int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, const unsigned char *key, const unsigned char *iv) { @@ -421,6 +446,13 @@ int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 0); } +int EVP_DecryptInit_ex2(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, + const unsigned char *key, const unsigned char *iv, + const OSSL_PARAM params[]) +{ + return EVP_CipherInit_ex2(ctx, cipher, key, iv, 0, params); +} + /* * According to the letter of standard difference between pointers * is specified to be valid only within same object. This makes diff --git a/crypto/evp/exchange.c b/crypto/evp/exchange.c index 1a512c4283..e0e0597b3b 100644 --- a/crypto/evp/exchange.c +++ b/crypto/evp/exchange.c @@ -176,6 +176,11 @@ EVP_KEYEXCH *EVP_KEYEXCH_fetch(OSSL_LIB_CTX *ctx, const char *algorithm, int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx) { + return EVP_PKEY_derive_init_ex(ctx, NULL); +} + +int EVP_PKEY_derive_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]) +{ int ret; void *provkey = NULL; EVP_KEYEXCH *exchange = NULL; @@ -279,7 +284,7 @@ int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx) ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); goto err; } - ret = exchange->init(ctx->op.kex.exchprovctx, provkey); + ret = exchange->init(ctx->op.kex.exchprovctx, provkey, params); return ret ? 1 : 0; err: diff --git a/crypto/evp/kem.c b/crypto/evp/kem.c index 353c51a3ff..a4183e8311 100644 --- a/crypto/evp/kem.c +++ b/crypto/evp/kem.c @@ -16,7 +16,8 @@ #include "internal/provider.h" #include "evp_local.h" -static int evp_kem_init(EVP_PKEY_CTX *ctx, int operation) +static int evp_kem_init(EVP_PKEY_CTX *ctx, int operation, + const OSSL_PARAM params[]) { int ret = 0; EVP_KEM *kem = NULL; @@ -79,7 +80,7 @@ static int evp_kem_init(EVP_PKEY_CTX *ctx, int operation) ret = -2; goto err; } - ret = kem->encapsulate_init(ctx->op.encap.kemprovctx, provkey); + ret = kem->encapsulate_init(ctx->op.encap.kemprovctx, provkey, params); break; case EVP_PKEY_OP_DECAPSULATE: if (kem->decapsulate_init == NULL) { @@ -87,7 +88,7 @@ static int evp_kem_init(EVP_PKEY_CTX *ctx, int operation) ret = -2; goto err; } - ret = kem->decapsulate_init(ctx->op.encap.kemprovctx, provkey); + ret = kem->decapsulate_init(ctx->op.encap.kemprovctx, provkey, params); break; default: ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); @@ -104,9 +105,9 @@ static int evp_kem_init(EVP_PKEY_CTX *ctx, int operation) return ret; } -int EVP_PKEY_encapsulate_init(EVP_PKEY_CTX *ctx) +int EVP_PKEY_encapsulate_init(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]) { - return evp_kem_init(ctx, EVP_PKEY_OP_ENCAPSULATE); + return evp_kem_init(ctx, EVP_PKEY_OP_ENCAPSULATE, params); } int EVP_PKEY_encapsulate(EVP_PKEY_CTX *ctx, @@ -133,9 +134,9 @@ int EVP_PKEY_encapsulate(EVP_PKEY_CTX *ctx, out, outlen, secret, secretlen); } -int EVP_PKEY_decapsulate_init(EVP_PKEY_CTX *ctx) +int EVP_PKEY_decapsulate_init(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]) { - return evp_kem_init(ctx, EVP_PKEY_OP_DECAPSULATE); + return evp_kem_init(ctx, EVP_PKEY_OP_DECAPSULATE, params); } int EVP_PKEY_decapsulate(EVP_PKEY_CTX *ctx, diff --git a/crypto/evp/m_sigver.c b/crypto/evp/m_sigver.c index 7650512d2a..3fca9bc529 100644 --- a/crypto/evp/m_sigver.c +++ b/crypto/evp/m_sigver.c @@ -39,7 +39,8 @@ static const char *canon_mdname(const char *mdname) static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type, const char *mdname, OSSL_LIB_CTX *libctx, const char *props, - ENGINE *e, EVP_PKEY *pkey, int ver) + ENGINE *e, EVP_PKEY *pkey, int ver, + OSSL_PARAM params[]) { EVP_PKEY_CTX *locpctx = NULL; EVP_SIGNATURE *signature = NULL; @@ -202,14 +203,14 @@ static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, goto err; } ret = signature->digest_verify_init(locpctx->op.sig.sigprovctx, - mdname, provkey); + mdname, provkey, params); } 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, provkey); + mdname, provkey, params); } goto end; @@ -301,28 +302,34 @@ static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, int EVP_DigestSignInit_ex(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const char *mdname, OSSL_LIB_CTX *libctx, - const char *props, EVP_PKEY *pkey) + const char *props, EVP_PKEY *pkey, + OSSL_PARAM params[]) { - return do_sigver_init(ctx, pctx, NULL, mdname, libctx, props, NULL, pkey, 0); + return do_sigver_init(ctx, pctx, NULL, mdname, libctx, props, NULL, pkey, 0, + params); } 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, NULL, NULL, NULL, e, pkey, 0); + return do_sigver_init(ctx, pctx, type, NULL, NULL, NULL, e, pkey, 0, + NULL); } int EVP_DigestVerifyInit_ex(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const char *mdname, OSSL_LIB_CTX *libctx, - const char *props, EVP_PKEY *pkey) + const char *props, EVP_PKEY *pkey, + OSSL_PARAM params[]) { - return do_sigver_init(ctx, pctx, NULL, mdname, libctx, props, NULL, pkey, 1); + return do_sigver_init(ctx, pctx, NULL, mdname, libctx, props, NULL, pkey, 1, + params); } 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, NULL, NULL, NULL, e, pkey, 1); + return do_sigver_init(ctx, pctx, type, NULL, NULL, NULL, e, pkey, 1, + NULL); } #endif /* FIPS_MDOE */ diff --git a/crypto/evp/signature.c b/crypto/evp/signature.c index bb99ff3095..09cf4539d9 100644 --- a/crypto/evp/signature.c +++ b/crypto/evp/signature.c @@ -361,7 +361,8 @@ const OSSL_PARAM *EVP_SIGNATURE_settable_ctx_params(const EVP_SIGNATURE *sig) return sig->settable_ctx_params(NULL, provctx); } -static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, int operation) +static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, int operation, + const OSSL_PARAM params[]) { int ret = 0; void *provkey = NULL; @@ -456,7 +457,7 @@ static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, int operation) ret = -2; goto err; } - ret = signature->sign_init(ctx->op.sig.sigprovctx, provkey); + ret = signature->sign_init(ctx->op.sig.sigprovctx, provkey, params); break; case EVP_PKEY_OP_VERIFY: if (signature->verify_init == NULL) { @@ -464,7 +465,7 @@ static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, int operation) ret = -2; goto err; } - ret = signature->verify_init(ctx->op.sig.sigprovctx, provkey); + ret = signature->verify_init(ctx->op.sig.sigprovctx, provkey, params); break; case EVP_PKEY_OP_VERIFYRECOVER: if (signature->verify_recover_init == NULL) { @@ -472,7 +473,8 @@ static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, int operation) ret = -2; goto err; } - ret = signature->verify_recover_init(ctx->op.sig.sigprovctx, provkey); + ret = signature->verify_recover_init(ctx->op.sig.sigprovctx, provkey, + params); break; default: ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); @@ -540,7 +542,12 @@ static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, int operation) int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx) { - return evp_pkey_signature_init(ctx, EVP_PKEY_OP_SIGN); + return evp_pkey_signature_init(ctx, EVP_PKEY_OP_SIGN, NULL); +} + +int EVP_PKEY_sign_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]) +{ + return evp_pkey_signature_init(ctx, EVP_PKEY_OP_SIGN, params); } int EVP_PKEY_sign(EVP_PKEY_CTX *ctx, @@ -579,7 +586,12 @@ int EVP_PKEY_sign(EVP_PKEY_CTX *ctx, int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx) { - return evp_pkey_signature_init(ctx, EVP_PKEY_OP_VERIFY); + return evp_pkey_signature_init(ctx, EVP_PKEY_OP_VERIFY, NULL); +} + +int EVP_PKEY_verify_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]) +{ + return evp_pkey_signature_init(ctx, EVP_PKEY_OP_VERIFY, params); } int EVP_PKEY_verify(EVP_PKEY_CTX *ctx, @@ -616,7 +628,13 @@ int EVP_PKEY_verify(EVP_PKEY_CTX *ctx, int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx) { - return evp_pkey_signature_init(ctx, EVP_PKEY_OP_VERIFYRECOVER); + return evp_pkey_signature_init(ctx, EVP_PKEY_OP_VERIFYRECOVER, NULL); +} + +int EVP_PKEY_verify_recover_init_ex(EVP_PKEY_CTX *ctx, + const OSSL_PARAM params[]) +{ + return evp_pkey_signature_init(ctx, EVP_PKEY_OP_VERIFYRECOVER, params); } int EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx, |