[openssl] master update
Dr. Paul Dale
pauli at openssl.org
Wed Feb 10 02:32:12 UTC 2021
The branch master has been updated
via af53092c2b67a8a0b76ae73385414cb1815ea7cc (commit)
via a054d15c22c501d33e1382bb09ba80bac08c2738 (commit)
via 36978c19a9a5bfd514b1c6f9db66fda4b39ed2c3 (commit)
from 8a686bdb3ac7d61b6d5f02b9132c4878ae80a7e5 (commit)
- Log -----------------------------------------------------------------
commit af53092c2b67a8a0b76ae73385414cb1815ea7cc
Author: Shane Lontis <shane.lontis at oracle.com>
Date: Thu Dec 17 16:42:05 2020 +1000
Replace provider digest flags with separate param fields
Reviewed-by: Paul Dale <pauli at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13830)
commit a054d15c22c501d33e1382bb09ba80bac08c2738
Author: Shane Lontis <shane.lontis at oracle.com>
Date: Thu Dec 17 16:39:57 2020 +1000
Replace provider cipher flags with separate param fields
Reviewed-by: Paul Dale <pauli at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13830)
commit 36978c19a9a5bfd514b1c6f9db66fda4b39ed2c3
Author: Shane Lontis <shane.lontis at oracle.com>
Date: Mon Dec 14 14:36:48 2020 +1000
Replace MAC flags OSSL_MAC_PARAM_FLAGS with separate param fields.
Fixes #12992
Reviewed-by: Paul Dale <pauli at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13830)
-----------------------------------------------------------------------
Summary of changes:
crypto/evp/digest.c | 16 +++++---
crypto/evp/evp_lib.c | 44 +++++++++++++++-------
doc/man3/EVP_DigestInit.pod | 4 +-
doc/man3/EVP_MAC.pod | 15 ++++++--
doc/man7/EVP_MAC-HMAC.pod | 6 ++-
doc/man7/EVP_MD-MDC2.pod | 2 +-
doc/man7/provider-cipher.pod | 28 ++++++++++----
doc/man7/provider-mac.pod | 11 +++++-
include/openssl/core_names.h | 34 ++++++++++-------
.../ciphers/cipher_aes_cbc_hmac_sha.c | 7 +---
.../implementations/ciphers/cipher_aes_cts.inc | 8 ++--
providers/implementations/ciphers/cipher_aes_siv.c | 3 +-
providers/implementations/ciphers/cipher_aes_siv.h | 1 -
providers/implementations/ciphers/cipher_aes_wrp.c | 8 ++--
providers/implementations/ciphers/cipher_aes_xts.c | 11 +-----
.../implementations/ciphers/cipher_blowfish.c | 2 +-
providers/implementations/ciphers/cipher_cast5.c | 2 +-
.../implementations/ciphers/cipher_chacha20.c | 3 +-
.../ciphers/cipher_chacha20_poly1305.c | 10 +----
providers/implementations/ciphers/cipher_des.c | 3 +-
providers/implementations/ciphers/cipher_des.h | 3 +-
providers/implementations/ciphers/cipher_rc2.c | 13 ++++---
providers/implementations/ciphers/cipher_rc4.c | 7 ++--
.../implementations/ciphers/cipher_rc4_hmac_md5.c | 13 +++----
providers/implementations/ciphers/cipher_rc5.c | 10 +++--
providers/implementations/ciphers/cipher_tdes.c | 2 +-
providers/implementations/ciphers/cipher_tdes.h | 4 +-
.../ciphers/cipher_tdes_default_hw.c | 2 +-
.../implementations/ciphers/cipher_tdes_wrap.c | 4 +-
providers/implementations/ciphers/ciphercommon.c | 39 +++++++++++++++----
.../implementations/ciphers/ciphercommon_ccm.c | 5 +--
.../implementations/ciphers/ciphercommon_hw.c | 2 +-
providers/implementations/digests/digestcommon.c | 14 +++++--
providers/implementations/digests/sha2_prov.c | 22 +++++------
providers/implementations/digests/sha3_prov.c | 10 +++--
.../implementations/include/prov/ciphercommon.h | 23 ++++++++---
.../include/prov/ciphercommon_aead.h | 19 ++++------
.../implementations/include/prov/digestcommon.h | 4 ++
providers/implementations/macs/hmac_prov.c | 38 ++++++++++++++-----
39 files changed, 272 insertions(+), 180 deletions(-)
diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c
index e89b591978..40aedae47b 100644
--- a/crypto/evp/digest.c
+++ b/crypto/evp/digest.c
@@ -830,23 +830,27 @@ static void set_legacy_nid(const char *name, void *vlegacy_nid)
static int evp_md_cache_constants(EVP_MD *md)
{
- int ok;
+ int ok, xof = 0, algid_absent = 0;
size_t blksz = 0;
size_t mdsize = 0;
- unsigned long flags = 0;
- OSSL_PARAM params[4];
+ OSSL_PARAM params[5];
params[0] = OSSL_PARAM_construct_size_t(OSSL_DIGEST_PARAM_BLOCK_SIZE, &blksz);
params[1] = OSSL_PARAM_construct_size_t(OSSL_DIGEST_PARAM_SIZE, &mdsize);
- params[2] = OSSL_PARAM_construct_ulong(OSSL_DIGEST_PARAM_FLAGS, &flags);
- params[3] = OSSL_PARAM_construct_end();
+ params[2] = OSSL_PARAM_construct_int(OSSL_DIGEST_PARAM_XOF, &xof);
+ params[3] = OSSL_PARAM_construct_int(OSSL_DIGEST_PARAM_ALGID_ABSENT,
+ &algid_absent);
+ params[4] = OSSL_PARAM_construct_end();
ok = evp_do_md_getparams(md, params);
if (mdsize > INT_MAX || blksz > INT_MAX)
ok = 0;
if (ok) {
md->block_size = (int)blksz;
md->md_size = (int)mdsize;
- md->flags = flags;
+ if (xof)
+ md->flags |= EVP_MD_FLAG_XOF;
+ if (algid_absent)
+ md->flags |= EVP_MD_FLAG_DIGALGID_ABSENT;
}
return ok;
}
diff --git a/crypto/evp/evp_lib.c b/crypto/evp/evp_lib.c
index 2febcfc2d5..427ffc813a 100644
--- a/crypto/evp/evp_lib.c
+++ b/crypto/evp/evp_lib.c
@@ -333,29 +333,41 @@ int EVP_CIPHER_type(const EVP_CIPHER *ctx)
int evp_cipher_cache_constants(EVP_CIPHER *cipher)
{
- int ok;
+ int ok, aead = 0, custom_iv = 0, cts = 0, multiblock = 0;
size_t ivlen = 0;
size_t blksz = 0;
size_t keylen = 0;
unsigned int mode = 0;
- unsigned long flags = 0;
- OSSL_PARAM params[6];
+ OSSL_PARAM params[9];
params[0] = OSSL_PARAM_construct_size_t(OSSL_CIPHER_PARAM_BLOCK_SIZE, &blksz);
params[1] = OSSL_PARAM_construct_size_t(OSSL_CIPHER_PARAM_IVLEN, &ivlen);
params[2] = OSSL_PARAM_construct_size_t(OSSL_CIPHER_PARAM_KEYLEN, &keylen);
params[3] = OSSL_PARAM_construct_uint(OSSL_CIPHER_PARAM_MODE, &mode);
- params[4] = OSSL_PARAM_construct_ulong(OSSL_CIPHER_PARAM_FLAGS, &flags);
- params[5] = OSSL_PARAM_construct_end();
+ params[4] = OSSL_PARAM_construct_int(OSSL_CIPHER_PARAM_AEAD, &aead);
+ params[5] = OSSL_PARAM_construct_int(OSSL_CIPHER_PARAM_CUSTOM_IV,
+ &custom_iv);
+ params[6] = OSSL_PARAM_construct_int(OSSL_CIPHER_PARAM_CTS, &cts);
+ params[7] = OSSL_PARAM_construct_int(OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK,
+ &multiblock);
+ params[8] = OSSL_PARAM_construct_end();
ok = evp_do_ciph_getparams(cipher, params);
if (ok) {
- /* Provided implementations may have a custom cipher_cipher */
- if (cipher->prov != NULL && cipher->ccipher != NULL)
- flags |= EVP_CIPH_FLAG_CUSTOM_CIPHER;
cipher->block_size = blksz;
cipher->iv_len = ivlen;
cipher->key_len = keylen;
- cipher->flags = flags | mode;
+ cipher->flags = mode;
+ if (aead)
+ cipher->flags |= EVP_CIPH_FLAG_AEAD_CIPHER;
+ if (custom_iv)
+ cipher->flags |= EVP_CIPH_CUSTOM_IV;
+ if (cts)
+ cipher->flags |= EVP_CIPH_FLAG_CTS;
+ if (multiblock)
+ cipher->flags |= EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK;
+ /* Provided implementations may have a custom cipher_cipher */
+ if (cipher->prov != NULL && cipher->ccipher != NULL)
+ cipher->flags |= EVP_CIPH_FLAG_CUSTOM_CIPHER;
}
return ok;
}
@@ -686,11 +698,6 @@ const OSSL_PROVIDER *EVP_MD_provider(const EVP_MD *md)
return md->prov;
}
-int EVP_MD_block_size(const EVP_MD *md)
-{
- return md->block_size;
-}
-
int EVP_MD_type(const EVP_MD *md)
{
return md->type;
@@ -701,6 +708,15 @@ int EVP_MD_pkey_type(const EVP_MD *md)
return md->pkey_type;
}
+int EVP_MD_block_size(const EVP_MD *md)
+{
+ if (md == NULL) {
+ ERR_raise(ERR_LIB_EVP, EVP_R_MESSAGE_DIGEST_IS_NULL);
+ return -1;
+ }
+ return md->block_size;
+}
+
int EVP_MD_size(const EVP_MD *md)
{
if (md == NULL) {
diff --git a/doc/man3/EVP_DigestInit.pod b/doc/man3/EVP_DigestInit.pod
index 3a17243976..28572f23b3 100644
--- a/doc/man3/EVP_DigestInit.pod
+++ b/doc/man3/EVP_DigestInit.pod
@@ -393,13 +393,13 @@ EVP_MD_CTX_set_params() can be used with the following OSSL_PARAM keys:
=over 4
-=item "xoflen" (B<OSSL_PARAM_DIGEST_KEY_XOFLEN>) <unsigned integer>
+=item "xoflen" (B<OSSL_DIGEST_PARAM_XOFLEN>) <unsigned integer>
Sets the digest length for extendable output functions.
It is used by the SHAKE algorithm and should not exceed what can be given
using a B<size_t>.
-=item "pad_type" (B<OSSL_PARAM_DIGEST_KEY_PAD_TYPE>) <integer>
+=item "pad-type" (B<OSSL_DIGEST_PARAM_PAD_TYPE>) <unsigned integer>
Sets the padding type.
It is used by the MDC2 algorithm.
diff --git a/doc/man3/EVP_MAC.pod b/doc/man3/EVP_MAC.pod
index 455d154cee..926c1fbd06 100644
--- a/doc/man3/EVP_MAC.pod
+++ b/doc/man3/EVP_MAC.pod
@@ -225,10 +225,19 @@ It's a simple flag, the value 0 or 1 are expected.
This option is used by KMAC.
-=item "flags" (B<OSSL_MAC_PARAM_FLAGS>) <integer>
+=item "digest-noinit" (B<OSSL_MAC_PARAM_DIGEST_NOINIT>) <integer>
-These will set the MAC flags to the given numbers.
-Some MACs do not support this option.
+A simple flag to set the MAC digest to not initialise the
+implementation specific data. The value 0 or 1 is expected.
+
+This option is used by HMAC.
+
+=item "digest-oneshot" (B<OSSL_MAC_PARAM_DIGEST_ONESHOT>) <integer>
+
+A simple flag to set the MAC digest to be a oneshot operation.
+The value 0 or 1 is expected.
+
+This option is used by HMAC.
=item "properties" (B<OSSL_MAC_PARAM_PROPERTIES>) <UTF8 string>
diff --git a/doc/man7/EVP_MAC-HMAC.pod b/doc/man7/EVP_MAC-HMAC.pod
index 94bac8dbcf..8136bed000 100644
--- a/doc/man7/EVP_MAC-HMAC.pod
+++ b/doc/man7/EVP_MAC-HMAC.pod
@@ -30,10 +30,12 @@ The following parameter can be set with EVP_MAC_CTX_set_params():
=item "key" (B<OSSL_MAC_PARAM_KEY>) <octet string>
-=item "flags" (B<OSSL_MAC_PARAM_FLAGS>) <octet string>
-
=item "digest" (B<OSSL_MAC_PARAM_DIGEST>) <UTF8 string>
+=item "digest-noinit" (B<OSSL_MAC_PARAM_DIGEST_NOINIT>) <integer>
+
+=item "digest-oneshot" (B<OSSL_MAC_PARAM_DIGEST_ONESHOT>) <integer>
+
=item "properties" (B<OSSL_MAC_PARAM_PROPERTIES>) <UTF8 string>
=item "tls-data-size" (B<OSSL_MAC_PARAM_TLS_DATA_SIZE>) <unsigned integer>
diff --git a/doc/man7/EVP_MD-MDC2.pod b/doc/man7/EVP_MD-MDC2.pod
index 516e19da19..53069557ea 100644
--- a/doc/man7/EVP_MD-MDC2.pod
+++ b/doc/man7/EVP_MD-MDC2.pod
@@ -25,7 +25,7 @@ settable for an B<EVP_MD_CTX> with L<EVP_MD_CTX_set_params(3)>:
=over 4
-=item "pad_type" (B<OSSL_DIGEST_PARAM_PAD_TYPE>) <unsigned integer>
+=item "pad-type" (B<OSSL_DIGEST_PARAM_PAD_TYPE>) <unsigned integer>
Sets the padding type to be used.
Normally the final MDC2 block is padded with zeros.
diff --git a/doc/man7/provider-cipher.pod b/doc/man7/provider-cipher.pod
index 3ab277ecf9..34a5ec0a7f 100644
--- a/doc/man7/provider-cipher.pod
+++ b/doc/man7/provider-cipher.pod
@@ -218,13 +218,27 @@ For example AES in CTR mode has a block size of 1 (because it operates like a
stream cipher), even though AES has a block size of 16.
The length of the "blocksize" parameter should not exceed that of a B<size_t>.
-=item "flags" (B<OSSL_CIPHER_PARAM_FLAGS>) <unsigned integer>
+=item "aead" (B<OSSL_CIPHER_PARAM_AEAD>) <integer>
-Gets any flags for the associated cipher algorithm.
-See L<EVP_CIPHER_meth_set_flags(3)> for a list of currently defined cipher
-flags.
-The length of the "flags" parameter should equal that of an
-B<unsigned long int>.
+Gets 1 if this is an AEAD cipher algorithm, otherwise it gets 0.
+
+=item "custom-iv" (B<OSSL_CIPHER_PARAM_CUSTOM_IV>) <integer>
+
+Gets 1 if the cipher algorithm has a custom IV, otherwise it gets 0.
+Storing and initializing the IV is left entirely to the implementation, if a
+custom IV is used.
+
+=item "cts" (B<OSSL_CIPHER_PARAM_CTS>) <integer>
+
+Gets 1 if the cipher algorithm uses ciphertext stealing, otherwise it gets 0.
+This is currently used to indicate that the cipher is a one shot that only
+allows a single call to EVP_CipherUpdate().
+
+=item "tls-multi" (B<OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK>) <integer>
+
+Gets 1 if the cipher algorithm supports interleaving of crypto blocks, otherwise
+it gets 0. The interleaving is an optimization only applicable to certain
+TLS ciphers.
=item "keylen" (B<OSSL_CIPHER_PARAM_KEYLEN>) <unsigned integer>
@@ -263,7 +277,7 @@ See L<EVP_EncryptInit(3)/AEAD Interface>.
=item "taglen" (B<OSSL_CIPHER_PARAM_AEAD_TAGLEN>) <unsigned integer>
Gets the tag length to be used for an AEAD cipher for the associated cipher ctx.
-It returns a default value if it has not been set.
+It gets a default value if it has not been set.
The length of the "taglen" parameter should not exceed that of a B<size_t>.
=item "tlsaad" (B<OSSL_CIPHER_PARAM_AEAD_TLS1_AAD>) <octet string>
diff --git a/doc/man7/provider-mac.pod b/doc/man7/provider-mac.pod
index f89b1fe0e2..f18a8c7fde 100644
--- a/doc/man7/provider-mac.pod
+++ b/doc/man7/provider-mac.pod
@@ -172,9 +172,16 @@ Sets the salt of the underlying cipher, when applicable.
Sets XOF mode in the associated MAC ctx.
0 means no XOF mode, 1 means XOF mode.
-=item "flags" (B<OSSL_MAC_PARAM_FLAGS>) <integer>
+=item "digest-noinit" (B<OSSL_MAC_PARAM_DIGEST_NOINIT>) <integer>
+
+A simple flag to set the MAC digest to not initialise the
+implementation specific data. The value 0 or 1 is expected.
+
+=item "digest-oneshot" (B<OSSL_MAC_PARAM_DIGEST_ONESHOT>) <integer>
+
+A simple flag to set the MAC digest to be a oneshot operation.
+The value 0 or 1 is expected.
-Gets flags associated with the MAC.
=for comment We need to investigate if this is the right approach
diff --git a/include/openssl/core_names.h b/include/openssl/core_names.h
index 221d67b823..ff2d1a03f9 100644
--- a/include/openssl/core_names.h
+++ b/include/openssl/core_names.h
@@ -69,7 +69,10 @@ extern "C" {
#define OSSL_CIPHER_PARAM_TLS_MAC_SIZE "tls-mac-size" /* size_t */
#define OSSL_CIPHER_PARAM_MODE "mode" /* uint */
#define OSSL_CIPHER_PARAM_BLOCK_SIZE "blocksize" /* size_t */
-#define OSSL_CIPHER_PARAM_FLAGS "flags" /* ulong */
+#define OSSL_CIPHER_PARAM_AEAD "aead" /* int, 0 or 1 */
+#define OSSL_CIPHER_PARAM_CUSTOM_IV "custom-iv" /* int, 0 or 1 */
+#define OSSL_CIPHER_PARAM_CTS "cts" /* int, 0 or 1 */
+#define OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK "tls-multi" /* int, 0 or 1 */
#define OSSL_CIPHER_PARAM_KEYLEN "keylen" /* size_t */
#define OSSL_CIPHER_PARAM_IVLEN "ivlen" /* size_t */
#define OSSL_CIPHER_PARAM_IV "iv" /* octet_string OR octet_ptr */
@@ -115,13 +118,14 @@ extern "C" {
#define OSSL_CIPHER_CTS_MODE_CS3 "CS3"
/* digest parameters */
-#define OSSL_DIGEST_PARAM_XOFLEN "xoflen" /* size_t */
-#define OSSL_DIGEST_PARAM_SSL3_MS "ssl3-ms" /* octet string */
-#define OSSL_DIGEST_PARAM_PAD_TYPE "pad_type" /* uint */
-#define OSSL_DIGEST_PARAM_MICALG "micalg" /* utf8 string */
-#define OSSL_DIGEST_PARAM_BLOCK_SIZE "blocksize" /* size_t */
-#define OSSL_DIGEST_PARAM_SIZE "size" /* size_t */
-#define OSSL_DIGEST_PARAM_FLAGS "flags" /* ulong */
+#define OSSL_DIGEST_PARAM_XOFLEN "xoflen" /* size_t */
+#define OSSL_DIGEST_PARAM_SSL3_MS "ssl3-ms" /* octet string */
+#define OSSL_DIGEST_PARAM_PAD_TYPE "pad-type" /* uint */
+#define OSSL_DIGEST_PARAM_MICALG "micalg" /* utf8 string */
+#define OSSL_DIGEST_PARAM_BLOCK_SIZE "blocksize" /* size_t */
+#define OSSL_DIGEST_PARAM_SIZE "size" /* size_t */
+#define OSSL_DIGEST_PARAM_XOF "xof" /* int, 0 or 1 */
+#define OSSL_DIGEST_PARAM_ALGID_ABSENT "algid-absent" /* int, 0 or 1 */
/* Known DIGEST names (not a complete list) */
#define OSSL_DIGEST_NAME_MD5 "MD5"
@@ -146,12 +150,14 @@ extern "C" {
#define OSSL_DIGEST_NAME_SM3 "SM3"
/* MAC parameters */
-#define OSSL_MAC_PARAM_KEY "key" /* octet string */
-#define OSSL_MAC_PARAM_IV "iv" /* octet string */
-#define OSSL_MAC_PARAM_CUSTOM "custom" /* utf8 string */
-#define OSSL_MAC_PARAM_SALT "salt" /* octet string */
-#define OSSL_MAC_PARAM_XOF "xof" /* int, 0 or 1 */
-#define OSSL_MAC_PARAM_FLAGS "flags" /* int */
+#define OSSL_MAC_PARAM_KEY "key" /* octet string */
+#define OSSL_MAC_PARAM_IV "iv" /* octet string */
+#define OSSL_MAC_PARAM_CUSTOM "custom" /* utf8 string */
+#define OSSL_MAC_PARAM_SALT "salt" /* octet string */
+#define OSSL_MAC_PARAM_XOF "xof" /* int, 0 or 1 */
+#define OSSL_MAC_PARAM_DIGEST_NOINIT "digest-noinit" /* int, 0 or 1 */
+#define OSSL_MAC_PARAM_DIGEST_ONESHOT "digest-oneshot" /* int, 0 or 1 */
+
/*
* If "engine" or "properties" are specified, they should always be paired
* with "cipher" or "digest".
diff --git a/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.c b/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.c
index 53bef600a5..03f216d22e 100644
--- a/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.c
+++ b/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.c
@@ -30,11 +30,8 @@ const OSSL_DISPATCH ossl_##nm##kbits##sub##_functions[] = { \
#else
# include "prov/providercommonerr.h"
-/* TODO(3.0) Figure out what flags are required */
-# define AES_CBC_HMAC_SHA_FLAGS (EVP_CIPH_CBC_MODE \
- | EVP_CIPH_FLAG_DEFAULT_ASN1 \
- | EVP_CIPH_FLAG_AEAD_CIPHER \
- | EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)
+# define AES_CBC_HMAC_SHA_FLAGS (PROV_CIPHER_FLAG_AEAD \
+ | PROV_CIPHER_FLAG_TLS1_MULTIBLOCK)
static OSSL_FUNC_cipher_freectx_fn aes_cbc_hmac_sha1_freectx;
static OSSL_FUNC_cipher_freectx_fn aes_cbc_hmac_sha256_freectx;
diff --git a/providers/implementations/ciphers/cipher_aes_cts.inc b/providers/implementations/ciphers/cipher_aes_cts.inc
index 6eb85a083f..dae112febf 100644
--- a/providers/implementations/ciphers/cipher_aes_cts.inc
+++ b/providers/implementations/ciphers/cipher_aes_cts.inc
@@ -12,6 +12,8 @@
#include "cipher_aes_cts.h"
#include "prov/providercommonerr.h"
+#define AES_CTS_FLAGS PROV_CIPHER_FLAG_CTS
+
static OSSL_FUNC_cipher_get_ctx_params_fn aes_cbc_cts_get_ctx_params;
static OSSL_FUNC_cipher_set_ctx_params_fn aes_cbc_cts_set_ctx_params;
static OSSL_FUNC_cipher_gettable_ctx_params_fn aes_cbc_cts_gettable_ctx_params;
@@ -101,8 +103,8 @@ const OSSL_DISPATCH ossl_##alg##kbits##lcmode##_cts_functions[] = { \
};
/* ossl_aes256cbc_cts_functions */
-IMPLEMENT_cts_cipher(aes, AES, cbc, CBC, EVP_CIPH_FLAG_CTS, 256, 128, 128, block)
+IMPLEMENT_cts_cipher(aes, AES, cbc, CBC, AES_CTS_FLAGS, 256, 128, 128, block)
/* ossl_aes192cbc_cts_functions */
-IMPLEMENT_cts_cipher(aes, AES, cbc, CBC, EVP_CIPH_FLAG_CTS, 192, 128, 128, block)
+IMPLEMENT_cts_cipher(aes, AES, cbc, CBC, AES_CTS_FLAGS, 192, 128, 128, block)
/* ossl_aes128cbc_cts_functions */
-IMPLEMENT_cts_cipher(aes, AES, cbc, CBC, EVP_CIPH_FLAG_CTS, 128, 128, 128, block)
+IMPLEMENT_cts_cipher(aes, AES, cbc, CBC, AES_CTS_FLAGS, 128, 128, 128, block)
diff --git a/providers/implementations/ciphers/cipher_aes_siv.c b/providers/implementations/ciphers/cipher_aes_siv.c
index 7a83506c24..469515bb8c 100644
--- a/providers/implementations/ciphers/cipher_aes_siv.c
+++ b/providers/implementations/ciphers/cipher_aes_siv.c
@@ -37,7 +37,6 @@ static void *aes_siv_newctx(void *provctx, size_t keybits, unsigned int mode,
if (ctx != NULL) {
ctx->taglen = SIV_LEN;
ctx->mode = mode;
- ctx->flags = flags;
ctx->keylen = keybits / 8;
ctx->hw = ossl_prov_cipher_hw_aes_siv(keybits);
ctx->libctx = PROV_LIBCTX_OF(provctx);
@@ -259,7 +258,7 @@ static OSSL_FUNC_cipher_settable_ctx_params_fn \
static int alg##_##kbits##_##lc##_get_params(OSSL_PARAM params[]) \
{ \
return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE, \
- flags, 2*kbits, blkbits, ivbits); \
+ flags, 2*kbits, blkbits, ivbits); \
} \
static void * alg##kbits##lc##_newctx(void *provctx) \
{ \
diff --git a/providers/implementations/ciphers/cipher_aes_siv.h b/providers/implementations/ciphers/cipher_aes_siv.h
index 6d2649f049..c0b2a903bc 100644
--- a/providers/implementations/ciphers/cipher_aes_siv.h
+++ b/providers/implementations/ciphers/cipher_aes_siv.h
@@ -24,7 +24,6 @@ typedef struct prov_cipher_hw_aes_siv_st {
typedef struct prov_siv_ctx_st {
unsigned int mode; /* The mode that we are using */
unsigned int enc : 1; /* Set to 1 if we are encrypting or 0 otherwise */
- uint64_t flags;
size_t keylen; /* The input keylength (twice the alg key length) */
size_t taglen; /* the taglen is the same as the sivlen */
SIV128_CONTEXT siv;
diff --git a/providers/implementations/ciphers/cipher_aes_wrp.c b/providers/implementations/ciphers/cipher_aes_wrp.c
index ca57666e7a..dc625216ca 100644
--- a/providers/implementations/ciphers/cipher_aes_wrp.c
+++ b/providers/implementations/ciphers/cipher_aes_wrp.c
@@ -22,10 +22,8 @@
#define AES_WRAP_PAD_IVLEN 4
#define AES_WRAP_NOPAD_IVLEN 8
-/* TODO(3.0) Figure out what flags need to be passed */
-#define WRAP_FLAGS (EVP_CIPH_WRAP_MODE | EVP_CIPH_CUSTOM_IV \
- | EVP_CIPH_ALWAYS_CALL_INIT)
-#define WRAP_FLAGS_INV (WRAP_FLAGS | EVP_CIPH_FLAG_INVERSE_CIPHER)
+#define WRAP_FLAGS (PROV_CIPHER_FLAG_CUSTOM_IV)
+#define WRAP_FLAGS_INV (WRAP_FLAGS | PROV_CIPHER_FLAG_INVERSE_CIPHER)
typedef size_t (*aeswrap_fn)(void *key, const unsigned char *iv,
unsigned char *out, const unsigned char *in,
@@ -111,7 +109,7 @@ static int aes_wrap_init(void *vctx, const unsigned char *key,
* to be the AES decryption function, then CIPH-1K will be the AES
* encryption function.
*/
- if ((ctx->flags & EVP_CIPH_FLAG_INVERSE_CIPHER) == 0)
+ if (ctx->inverse_cipher == 0)
use_forward_transform = ctx->enc;
else
use_forward_transform = !ctx->enc;
diff --git a/providers/implementations/ciphers/cipher_aes_xts.c b/providers/implementations/ciphers/cipher_aes_xts.c
index 7ccad56198..cf768d27d4 100644
--- a/providers/implementations/ciphers/cipher_aes_xts.c
+++ b/providers/implementations/ciphers/cipher_aes_xts.c
@@ -20,12 +20,7 @@
#include "prov/providercommon.h"
#include "prov/providercommonerr.h"
-/* TODO (3.0) Figure out what flags need to be set */
-#define AES_XTS_FLAGS (EVP_CIPH_CUSTOM_IV \
- | EVP_CIPH_ALWAYS_CALL_INIT \
- | EVP_CIPH_CTRL_INIT \
- | EVP_CIPH_CUSTOM_COPY)
-
+#define AES_XTS_FLAGS PROV_CIPHER_FLAG_CUSTOM_IV
#define AES_XTS_IV_BITS 128
#define AES_XTS_BLOCK_BITS 8
@@ -233,10 +228,6 @@ static int aes_xts_set_ctx_params(void *vctx, const OSSL_PARAM params[])
PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;
const OSSL_PARAM *p;
- /*
- * TODO(3.0) We need a general solution for handling missing parameters
- * inside set_params and get_params methods.
- */
p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_KEYLEN);
if (p != NULL) {
size_t keylen;
diff --git a/providers/implementations/ciphers/cipher_blowfish.c b/providers/implementations/ciphers/cipher_blowfish.c
index 6320f560a0..cf303bb863 100644
--- a/providers/implementations/ciphers/cipher_blowfish.c
+++ b/providers/implementations/ciphers/cipher_blowfish.c
@@ -19,7 +19,7 @@
#include "prov/implementations.h"
#include "prov/providercommon.h"
-#define BF_FLAGS (EVP_CIPH_VARIABLE_LENGTH)
+#define BF_FLAGS PROV_CIPHER_FLAG_VARIABLE_LENGTH
static OSSL_FUNC_cipher_freectx_fn blowfish_freectx;
static OSSL_FUNC_cipher_dupctx_fn blowfish_dupctx;
diff --git a/providers/implementations/ciphers/cipher_cast5.c b/providers/implementations/ciphers/cipher_cast5.c
index 7c686013d8..1d525343b4 100644
--- a/providers/implementations/ciphers/cipher_cast5.c
+++ b/providers/implementations/ciphers/cipher_cast5.c
@@ -20,7 +20,7 @@
#include "prov/providercommon.h"
#include "prov/providercommonerr.h"
-#define CAST5_FLAGS (EVP_CIPH_VARIABLE_LENGTH)
+#define CAST5_FLAGS PROV_CIPHER_FLAG_VARIABLE_LENGTH
static OSSL_FUNC_cipher_freectx_fn cast5_freectx;
static OSSL_FUNC_cipher_dupctx_fn cast5_dupctx;
diff --git a/providers/implementations/ciphers/cipher_chacha20.c b/providers/implementations/ciphers/cipher_chacha20.c
index 8e0727ae47..b2fe1b1957 100644
--- a/providers/implementations/ciphers/cipher_chacha20.c
+++ b/providers/implementations/ciphers/cipher_chacha20.c
@@ -17,8 +17,7 @@
#define CHACHA20_KEYLEN (CHACHA_KEY_SIZE)
#define CHACHA20_BLKLEN (1)
#define CHACHA20_IVLEN (CHACHA_CTR_SIZE)
-/* TODO(3.0) Figure out what flags are required */
-#define CHACHA20_FLAGS (EVP_CIPH_CUSTOM_IV | EVP_CIPH_ALWAYS_CALL_INIT)
+#define CHACHA20_FLAGS (PROV_CIPHER_FLAG_CUSTOM_IV)
static OSSL_FUNC_cipher_newctx_fn chacha20_newctx;
static OSSL_FUNC_cipher_freectx_fn chacha20_freectx;
diff --git a/providers/implementations/ciphers/cipher_chacha20_poly1305.c b/providers/implementations/ciphers/cipher_chacha20_poly1305.c
index 7a9cc5c20f..919d4fba94 100644
--- a/providers/implementations/ciphers/cipher_chacha20_poly1305.c
+++ b/providers/implementations/ciphers/cipher_chacha20_poly1305.c
@@ -19,14 +19,8 @@
#define CHACHA20_POLY1305_BLKLEN 1
#define CHACHA20_POLY1305_MAX_IVLEN 12
#define CHACHA20_POLY1305_MODE 0
-/* TODO(3.0) Figure out what flags are required */
-#define CHACHA20_POLY1305_FLAGS (EVP_CIPH_FLAG_AEAD_CIPHER \
- | EVP_CIPH_ALWAYS_CALL_INIT \
- | EVP_CIPH_CTRL_INIT \
- | EVP_CIPH_CUSTOM_COPY \
- | EVP_CIPH_FLAG_CUSTOM_CIPHER \
- | EVP_CIPH_CUSTOM_IV \
- | EVP_CIPH_CUSTOM_IV_LENGTH)
+#define CHACHA20_POLY1305_FLAGS (PROV_CIPHER_FLAG_AEAD \
+ | PROV_CIPHER_FLAG_CUSTOM_IV)
static OSSL_FUNC_cipher_newctx_fn chacha20_poly1305_newctx;
static OSSL_FUNC_cipher_freectx_fn chacha20_poly1305_freectx;
diff --git a/providers/implementations/ciphers/cipher_des.c b/providers/implementations/ciphers/cipher_des.c
index 345adfab60..ec186445c8 100644
--- a/providers/implementations/ciphers/cipher_des.c
+++ b/providers/implementations/ciphers/cipher_des.c
@@ -20,8 +20,7 @@
#include "prov/providercommon.h"
#include "prov/providercommonerr.h"
-/* TODO(3.0) Figure out what flags need to be here */
-#define DES_FLAGS (EVP_CIPH_RAND_KEY)
+#define DES_FLAGS 0
static OSSL_FUNC_cipher_freectx_fn des_freectx;
static OSSL_FUNC_cipher_encrypt_init_fn des_einit;
diff --git a/providers/implementations/ciphers/cipher_des.h b/providers/implementations/ciphers/cipher_des.h
index aedb38177e..78ca686bad 100644
--- a/providers/implementations/ciphers/cipher_des.h
+++ b/providers/implementations/ciphers/cipher_des.h
@@ -10,8 +10,7 @@
#include <openssl/des.h>
#include "crypto/des_platform.h"
-/* TODO(3.0) Figure out what flags need to be here */
-#define TDES_FLAGS (EVP_CIPH_RAND_KEY)
+#define TDES_FLAGS 0
typedef struct prov_des_ctx_st {
PROV_CIPHER_CTX base; /* Must be first */
diff --git a/providers/implementations/ciphers/cipher_rc2.c b/providers/implementations/ciphers/cipher_rc2.c
index b7c244f245..09d66b2cdd 100644
--- a/providers/implementations/ciphers/cipher_rc2.c
+++ b/providers/implementations/ciphers/cipher_rc2.c
@@ -23,6 +23,7 @@
#define RC2_40_MAGIC 0xa0
#define RC2_64_MAGIC 0x78
#define RC2_128_MAGIC 0x3a
+#define RC2_FLAGS PROV_CIPHER_FLAG_VARIABLE_LENGTH
static OSSL_FUNC_cipher_freectx_fn rc2_freectx;
static OSSL_FUNC_cipher_dupctx_fn rc2_dupctx;
@@ -242,15 +243,15 @@ const OSSL_DISPATCH ossl_##alg##kbits##lcmode##_functions[] = { \
};
/* ossl_rc2128ecb_functions */
-IMPLEMENT_cipher(rc2, RC2, ecb, ECB, EVP_CIPH_VARIABLE_LENGTH, 128, 64, 0, block)
+IMPLEMENT_cipher(rc2, RC2, ecb, ECB, RC2_FLAGS, 128, 64, 0, block)
/* ossl_rc2128cbc_functions */
-IMPLEMENT_cipher(rc2, RC2, cbc, CBC, EVP_CIPH_VARIABLE_LENGTH, 128, 64, 64, block)
+IMPLEMENT_cipher(rc2, RC2, cbc, CBC, RC2_FLAGS, 128, 64, 64, block)
/* ossl_rc240cbc_functions */
-IMPLEMENT_cipher(rc2, RC2, cbc, CBC, EVP_CIPH_VARIABLE_LENGTH, 40, 64, 64, block)
+IMPLEMENT_cipher(rc2, RC2, cbc, CBC, RC2_FLAGS, 40, 64, 64, block)
/* ossl_rc264cbc_functions */
-IMPLEMENT_cipher(rc2, RC2, cbc, CBC, EVP_CIPH_VARIABLE_LENGTH, 64, 64, 64, block)
+IMPLEMENT_cipher(rc2, RC2, cbc, CBC, RC2_FLAGS, 64, 64, 64, block)
/* ossl_rc2128ofb128_functions */
-IMPLEMENT_cipher(rc2, RC2, ofb128, OFB, EVP_CIPH_VARIABLE_LENGTH, 128, 8, 64, stream)
+IMPLEMENT_cipher(rc2, RC2, ofb128, OFB, RC2_FLAGS, 128, 8, 64, stream)
/* ossl_rc2128cfb128_functions */
-IMPLEMENT_cipher(rc2, RC2, cfb128, CFB, EVP_CIPH_VARIABLE_LENGTH, 128, 8, 64, stream)
+IMPLEMENT_cipher(rc2, RC2, cfb128, CFB, RC2_FLAGS, 128, 8, 64, stream)
diff --git a/providers/implementations/ciphers/cipher_rc4.c b/providers/implementations/ciphers/cipher_rc4.c
index 91644fca59..18233bbac1 100644
--- a/providers/implementations/ciphers/cipher_rc4.c
+++ b/providers/implementations/ciphers/cipher_rc4.c
@@ -19,8 +19,7 @@
#include "prov/implementations.h"
#include "prov/providercommon.h"
-/* TODO (3.0) Figure out what flags are required */
-#define RC4_FLAGS EVP_CIPH_FLAG_DEFAULT_ASN1
+#define RC4_FLAGS PROV_CIPHER_FLAG_VARIABLE_LENGTH
static OSSL_FUNC_cipher_freectx_fn rc4_freectx;
static OSSL_FUNC_cipher_dupctx_fn rc4_dupctx;
@@ -97,6 +96,6 @@ const OSSL_DISPATCH ossl_##alg##kbits##_functions[] = { \
};
/* ossl_rc440_functions */
-IMPLEMENT_cipher(rc4, RC4, EVP_CIPH_VARIABLE_LENGTH, 40, 8, 0, stream)
+IMPLEMENT_cipher(rc4, RC4, RC4_FLAGS, 40, 8, 0, stream)
/* ossl_rc4128_functions */
-IMPLEMENT_cipher(rc4, RC4, EVP_CIPH_VARIABLE_LENGTH, 128, 8, 0, stream)
+IMPLEMENT_cipher(rc4, RC4, RC4_FLAGS, 128, 8, 0, stream)
diff --git a/providers/implementations/ciphers/cipher_rc4_hmac_md5.c b/providers/implementations/ciphers/cipher_rc4_hmac_md5.c
index 9dc9615c04..b757197110 100644
--- a/providers/implementations/ciphers/cipher_rc4_hmac_md5.c
+++ b/providers/implementations/ciphers/cipher_rc4_hmac_md5.c
@@ -20,9 +20,8 @@
#include "prov/providercommon.h"
#include "prov/providercommonerr.h"
-/* TODO(3.0) Figure out what flags are required */
-#define RC4_HMAC_MD5_FLAGS (EVP_CIPH_STREAM_CIPHER | EVP_CIPH_VARIABLE_LENGTH \
- | EVP_CIPH_FLAG_AEAD_CIPHER)
+#define RC4_HMAC_MD5_FLAGS (PROV_CIPHER_FLAG_VARIABLE_LENGTH \
+ | PROV_CIPHER_FLAG_AEAD)
#define RC4_HMAC_MD5_KEY_BITS (16 * 8)
#define RC4_HMAC_MD5_BLOCK_BITS (1 * 8)
@@ -183,10 +182,10 @@ static int rc4_hmac_md5_set_ctx_params(void *vctx, const OSSL_PARAM params[])
static int rc4_hmac_md5_get_params(OSSL_PARAM params[])
{
return ossl_cipher_generic_get_params(params, RC4_HMAC_MD5_MODE,
- RC4_HMAC_MD5_FLAGS,
- RC4_HMAC_MD5_KEY_BITS,
- RC4_HMAC_MD5_BLOCK_BITS,
- RC4_HMAC_MD5_IV_BITS);
+ RC4_HMAC_MD5_FLAGS,
+ RC4_HMAC_MD5_KEY_BITS,
+ RC4_HMAC_MD5_BLOCK_BITS,
+ RC4_HMAC_MD5_IV_BITS);
}
const OSSL_DISPATCH ossl_rc4_hmac_ossl_md5_functions[] = {
diff --git a/providers/implementations/ciphers/cipher_rc5.c b/providers/implementations/ciphers/cipher_rc5.c
index 80de5f4bdd..ec408ed885 100644
--- a/providers/implementations/ciphers/cipher_rc5.c
+++ b/providers/implementations/ciphers/cipher_rc5.c
@@ -20,6 +20,8 @@
#include "prov/providercommon.h"
#include "prov/providercommonerr.h"
+#define RC5_FLAGS PROV_CIPHER_FLAG_VARIABLE_LENGTH
+
static OSSL_FUNC_cipher_freectx_fn rc5_freectx;
static OSSL_FUNC_cipher_dupctx_fn rc5_dupctx;
OSSL_FUNC_cipher_gettable_ctx_params_fn rc5_gettable_ctx_params;
@@ -153,10 +155,10 @@ const OSSL_DISPATCH ossl_##alg##kbits##lcmode##_functions[] = { \
};
/* ossl_rc5128ecb_functions */
-IMPLEMENT_cipher(rc5, RC5, ecb, ECB, EVP_CIPH_VARIABLE_LENGTH, 128, 64, 0, block)
+IMPLEMENT_cipher(rc5, RC5, ecb, ECB, RC5_FLAGS, 128, 64, 0, block)
/* ossl_rc5128cbc_functions */
-IMPLEMENT_cipher(rc5, RC5, cbc, CBC, EVP_CIPH_VARIABLE_LENGTH, 128, 64, 64, block)
+IMPLEMENT_cipher(rc5, RC5, cbc, CBC, RC5_FLAGS, 128, 64, 64, block)
/* ossl_rc5128ofb64_functions */
-IMPLEMENT_cipher(rc5, RC5, ofb64, OFB, EVP_CIPH_VARIABLE_LENGTH, 128, 8, 64, stream)
+IMPLEMENT_cipher(rc5, RC5, ofb64, OFB, RC5_FLAGS, 128, 8, 64, stream)
/* ossl_rc5128cfb64_functions */
-IMPLEMENT_cipher(rc5, RC5, cfb64, CFB, EVP_CIPH_VARIABLE_LENGTH, 128, 8, 64, stream)
+IMPLEMENT_cipher(rc5, RC5, cfb64, CFB, RC5_FLAGS, 128, 8, 64, stream)
diff --git a/providers/implementations/ciphers/cipher_tdes.c b/providers/implementations/ciphers/cipher_tdes.c
index c9fb1ceda7..a2855af481 100644
--- a/providers/implementations/ciphers/cipher_tdes.c
+++ b/providers/implementations/ciphers/cipher_tdes.c
@@ -20,7 +20,7 @@
#include "prov/providercommonerr.h"
/*
- * TODO(3.0) - ECB mode does not use an IV - but existing test code is setting
+ * NOTE: ECB mode does not use an IV - but existing test code is setting
* an IV. Fixing this could potentially make applications break.
*/
/* ossl_tdes_ede3_ecb_functions */
diff --git a/providers/implementations/ciphers/cipher_tdes.h b/providers/implementations/ciphers/cipher_tdes.h
index 081a00fffa..9bef908cc3 100644
--- a/providers/implementations/ciphers/cipher_tdes.h
+++ b/providers/implementations/ciphers/cipher_tdes.h
@@ -13,9 +13,7 @@
#define DES_BLOCK_SIZE 8
#define TDES_IVLEN 8
-
-/* TODO(3.0) Figure out what flags need to be here */
-#define TDES_FLAGS (EVP_CIPH_RAND_KEY)
+#define TDES_FLAGS 0
typedef struct prov_tdes_ctx_st {
PROV_CIPHER_CTX base; /* Must be first */
diff --git a/providers/implementations/ciphers/cipher_tdes_default_hw.c b/providers/implementations/ciphers/cipher_tdes_default_hw.c
index b7c7ea11f7..77b08ebbe1 100644
--- a/providers/implementations/ciphers/cipher_tdes_default_hw.c
+++ b/providers/implementations/ciphers/cipher_tdes_default_hw.c
@@ -101,7 +101,7 @@ static int ossl_cipher_hw_tdes_cfb1(PROV_CIPHER_CTX *ctx, unsigned char *out,
size_t n;
unsigned char c[1], d[1];
- if ((ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS) == 0)
+ if (ctx->use_bits == 0)
inl *= 8;
for (n = 0; n < inl; ++n) {
c[0] = (in[n / 8] & (1 << (7 - n % 8))) ? 0x80 : 0;
diff --git a/providers/implementations/ciphers/cipher_tdes_wrap.c b/providers/implementations/ciphers/cipher_tdes_wrap.c
index acb8c97e33..b78a77c254 100644
--- a/providers/implementations/ciphers/cipher_tdes_wrap.c
+++ b/providers/implementations/ciphers/cipher_tdes_wrap.c
@@ -21,9 +21,7 @@
#include "prov/providercommon.h"
#include "prov/providercommonerr.h"
-/* TODO (3.0) Figure out what flags are required */
-#define TDES_WRAP_FLAGS (EVP_CIPH_WRAP_MODE | EVP_CIPH_CUSTOM_IV)
-
+#define TDES_WRAP_FLAGS PROV_CIPHER_FLAG_CUSTOM_IV
static OSSL_FUNC_cipher_update_fn tdes_wrap_update;
static OSSL_FUNC_cipher_cipher_fn tdes_wrap_cipher;
diff --git a/providers/implementations/ciphers/ciphercommon.c b/providers/implementations/ciphers/ciphercommon.c
index d1e8c461b5..fa73edb473 100644
--- a/providers/implementations/ciphers/ciphercommon.c
+++ b/providers/implementations/ciphers/ciphercommon.c
@@ -26,7 +26,10 @@ static const OSSL_PARAM cipher_known_gettable_params[] = {
OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_KEYLEN, NULL),
OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_IVLEN, NULL),
OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_BLOCK_SIZE, NULL),
- OSSL_PARAM_ulong(OSSL_CIPHER_PARAM_FLAGS, NULL),
+ OSSL_PARAM_int(OSSL_CIPHER_PARAM_AEAD, NULL),
+ OSSL_PARAM_int(OSSL_CIPHER_PARAM_CUSTOM_IV, NULL),
+ OSSL_PARAM_int(OSSL_CIPHER_PARAM_CTS, NULL),
+ OSSL_PARAM_int(OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK, NULL),
{ OSSL_CIPHER_PARAM_TLS_MAC, OSSL_PARAM_OCTET_PTR, NULL, 0, OSSL_PARAM_UNMODIFIED },
OSSL_PARAM_END
};
@@ -36,7 +39,7 @@ const OSSL_PARAM *ossl_cipher_generic_gettable_params(void *provctx)
}
int ossl_cipher_generic_get_params(OSSL_PARAM params[], unsigned int md,
- unsigned long flags,
+ uint64_t flags,
size_t kbits, size_t blkbits, size_t ivbits)
{
OSSL_PARAM *p;
@@ -46,8 +49,27 @@ int ossl_cipher_generic_get_params(OSSL_PARAM params[], unsigned int md,
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
return 0;
}
- p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_FLAGS);
- if (p != NULL && !OSSL_PARAM_set_ulong(p, flags)) {
+ p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_AEAD);
+ if (p != NULL
+ && !OSSL_PARAM_set_int(p, (flags & PROV_CIPHER_FLAG_AEAD) != 0)) {
+ ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
+ return 0;
+ }
+ p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_CUSTOM_IV);
+ if (p != NULL
+ && !OSSL_PARAM_set_int(p, (flags & PROV_CIPHER_FLAG_CUSTOM_IV) != 0)) {
+ ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
+ return 0;
+ }
+ p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_CTS);
+ if (p != NULL
+ && !OSSL_PARAM_set_int(p, (flags & PROV_CIPHER_FLAG_CTS) != 0)) {
+ ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
+ return 0;
+ }
+ p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK);
+ if (p != NULL
+ && !OSSL_PARAM_set_int(p, (flags & PROV_CIPHER_FLAG_TLS1_MULTIBLOCK) != 0)) {
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
return 0;
}
@@ -80,7 +102,6 @@ CIPHER_DEFAULT_SETTABLE_CTX_PARAMS_END(ossl_cipher_generic)
/*
* Variable key length cipher functions for OSSL_PARAM settables
*/
-
int ossl_cipher_var_keylen_set_ctx_params(void *vctx, const OSSL_PARAM params[])
{
PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;
@@ -168,7 +189,7 @@ static int cipher_generic_init_internal(PROV_CIPHER_CTX *ctx,
return 0;
}
if (key != NULL) {
- if ((ctx->flags & EVP_CIPH_VARIABLE_LENGTH) == 0) {
+ if (ctx->variable_keylength == 0) {
if (keylen != ctx->keylen) {
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEYLEN);
return 0;
@@ -608,7 +629,11 @@ void ossl_cipher_generic_initkey(void *vctx, size_t kbits, size_t blkbits,
{
PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;
- ctx->flags = flags;
+ if ((flags & PROV_CIPHER_FLAG_INVERSE_CIPHER) != 0)
+ ctx->inverse_cipher = 1;
+ if ((flags & PROV_CIPHER_FLAG_VARIABLE_LENGTH) != 0)
+ ctx->variable_keylength = 1;
+
ctx->pad = 1;
ctx->keylen = ((kbits) / 8);
ctx->ivlen = ((ivbits) / 8);
diff --git a/providers/implementations/ciphers/ciphercommon_ccm.c b/providers/implementations/ciphers/ciphercommon_ccm.c
index cb529f5f31..0009e9876c 100644
--- a/providers/implementations/ciphers/ciphercommon_ccm.c
+++ b/providers/implementations/ciphers/ciphercommon_ccm.c
@@ -291,9 +291,8 @@ int ccm_stream_final(void *vctx, unsigned char *out, size_t *outl,
return 1;
}
-int ccm_cipher(void *vctx,
- unsigned char *out, size_t *outl, size_t outsize,
- const unsigned char *in, size_t inl)
+int ccm_cipher(void *vctx, unsigned char *out, size_t *outl, size_t outsize,
+ const unsigned char *in, size_t inl)
{
PROV_CCM_CTX *ctx = (PROV_CCM_CTX *)vctx;
diff --git a/providers/implementations/ciphers/ciphercommon_hw.c b/providers/implementations/ciphers/ciphercommon_hw.c
index 7063593011..8673e7b744 100644
--- a/providers/implementations/ciphers/ciphercommon_hw.c
+++ b/providers/implementations/ciphers/ciphercommon_hw.c
@@ -85,7 +85,7 @@ int ossl_cipher_hw_generic_cfb1(PROV_CIPHER_CTX *dat, unsigned char *out,
{
int num = dat->num;
- if ((dat->flags & EVP_CIPH_FLAG_LENGTH_BITS) != 0) {
+ if (dat->use_bits) {
CRYPTO_cfb128_1_encrypt(in, out, len, dat->ks, dat->iv, &num,
dat->enc, dat->block);
dat->num = num;
diff --git a/providers/implementations/digests/digestcommon.c b/providers/implementations/digests/digestcommon.c
index 6d926713c8..b8e7efde60 100644
--- a/providers/implementations/digests/digestcommon.c
+++ b/providers/implementations/digests/digestcommon.c
@@ -26,8 +26,15 @@ int digest_default_get_params(OSSL_PARAM params[], size_t blksz, size_t paramsz,
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
return 0;
}
- p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_FLAGS);
- if (p != NULL && !OSSL_PARAM_set_ulong(p, flags)) {
+ p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_XOF);
+ if (p != NULL
+ && !OSSL_PARAM_set_int(p, (flags & PROV_DIGEST_FLAG_XOF) != 0)) {
+ ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
+ return 0;
+ }
+ p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_ALGID_ABSENT);
+ if (p != NULL
+ && !OSSL_PARAM_set_int(p, (flags & PROV_DIGEST_FLAG_ALGID_ABSENT) != 0)) {
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
return 0;
}
@@ -37,7 +44,8 @@ int digest_default_get_params(OSSL_PARAM params[], size_t blksz, size_t paramsz,
static const OSSL_PARAM digest_default_known_gettable_params[] = {
OSSL_PARAM_size_t(OSSL_DIGEST_PARAM_BLOCK_SIZE, NULL),
OSSL_PARAM_size_t(OSSL_DIGEST_PARAM_SIZE, NULL),
- OSSL_PARAM_ulong(OSSL_DIGEST_PARAM_FLAGS, NULL),
+ OSSL_PARAM_int(OSSL_DIGEST_PARAM_XOF, NULL),
+ OSSL_PARAM_int(OSSL_DIGEST_PARAM_ALGID_ABSENT, NULL),
OSSL_PARAM_END
};
const OSSL_PARAM *digest_default_gettable_params(void *provctx)
diff --git a/providers/implementations/digests/sha2_prov.c b/providers/implementations/digests/sha2_prov.c
index 2f01149ad9..4cff62131c 100644
--- a/providers/implementations/digests/sha2_prov.c
+++ b/providers/implementations/digests/sha2_prov.c
@@ -24,6 +24,8 @@
#include "prov/implementations.h"
#include "crypto/sha.h"
+#define SHA2_FLAGS PROV_DIGEST_FLAG_ALGID_ABSENT
+
static OSSL_FUNC_digest_set_ctx_params_fn sha1_set_ctx_params;
static OSSL_FUNC_digest_settable_ctx_params_fn sha1_settable_ctx_params;
@@ -53,43 +55,37 @@ static int sha1_set_ctx_params(void *vctx, const OSSL_PARAM params[])
/* ossl_sha1_functions */
IMPLEMENT_digest_functions_with_settable_ctx(
- sha1, SHA_CTX, SHA_CBLOCK, SHA_DIGEST_LENGTH, EVP_MD_FLAG_DIGALGID_ABSENT,
+ sha1, SHA_CTX, SHA_CBLOCK, SHA_DIGEST_LENGTH, SHA2_FLAGS,
SHA1_Init, SHA1_Update, SHA1_Final,
sha1_settable_ctx_params, sha1_set_ctx_params)
/* ossl_sha224_functions */
IMPLEMENT_digest_functions(sha224, SHA256_CTX,
- SHA256_CBLOCK, SHA224_DIGEST_LENGTH,
- EVP_MD_FLAG_DIGALGID_ABSENT,
+ SHA256_CBLOCK, SHA224_DIGEST_LENGTH, SHA2_FLAGS,
SHA224_Init, SHA224_Update, SHA224_Final)
/* ossl_sha256_functions */
IMPLEMENT_digest_functions(sha256, SHA256_CTX,
- SHA256_CBLOCK, SHA256_DIGEST_LENGTH,
- EVP_MD_FLAG_DIGALGID_ABSENT,
+ SHA256_CBLOCK, SHA256_DIGEST_LENGTH, SHA2_FLAGS,
SHA256_Init, SHA256_Update, SHA256_Final)
/* ossl_sha384_functions */
IMPLEMENT_digest_functions(sha384, SHA512_CTX,
- SHA512_CBLOCK, SHA384_DIGEST_LENGTH,
- EVP_MD_FLAG_DIGALGID_ABSENT,
+ SHA512_CBLOCK, SHA384_DIGEST_LENGTH, SHA2_FLAGS,
SHA384_Init, SHA384_Update, SHA384_Final)
/* ossl_sha512_functions */
IMPLEMENT_digest_functions(sha512, SHA512_CTX,
- SHA512_CBLOCK, SHA512_DIGEST_LENGTH,
- EVP_MD_FLAG_DIGALGID_ABSENT,
+ SHA512_CBLOCK, SHA512_DIGEST_LENGTH, SHA2_FLAGS,
SHA512_Init, SHA512_Update, SHA512_Final)
/* ossl_sha512_224_functions */
IMPLEMENT_digest_functions(sha512_224, SHA512_CTX,
- SHA512_CBLOCK, SHA224_DIGEST_LENGTH,
- EVP_MD_FLAG_DIGALGID_ABSENT,
+ SHA512_CBLOCK, SHA224_DIGEST_LENGTH, SHA2_FLAGS,
sha512_224_init, SHA512_Update, SHA512_Final)
/* ossl_sha512_256_functions */
IMPLEMENT_digest_functions(sha512_256, SHA512_CTX,
- SHA512_CBLOCK, SHA256_DIGEST_LENGTH,
- EVP_MD_FLAG_DIGALGID_ABSENT,
+ SHA512_CBLOCK, SHA256_DIGEST_LENGTH, SHA2_FLAGS,
sha512_256_init, SHA512_Update, SHA512_Final)
diff --git a/providers/implementations/digests/sha3_prov.c b/providers/implementations/digests/sha3_prov.c
index 6b44792529..6e731fd842 100644
--- a/providers/implementations/digests/sha3_prov.c
+++ b/providers/implementations/digests/sha3_prov.c
@@ -18,6 +18,10 @@
#include "prov/implementations.h"
#include "prov/providercommonerr.h"
+#define SHA3_FLAGS PROV_DIGEST_FLAG_ALGID_ABSENT
+#define SHAKE_FLAGS PROV_DIGEST_FLAG_XOF
+#define KMAC_FLAGS PROV_DIGEST_FLAG_XOF
+
/*
* Forward declaration of any unique methods implemented here. This is not strictly
* necessary for the compiler, but provides an assurance that the signatures
@@ -286,18 +290,18 @@ static int shake_set_ctx_params(void *vctx, const OSSL_PARAM params[])
SHA3_newctx(sha3, SHA3_##bitlen, sha3_##bitlen, bitlen, '\x06') \
PROV_FUNC_SHA3_DIGEST(sha3_##bitlen, bitlen, \
SHA3_BLOCKSIZE(bitlen), SHA3_MDSIZE(bitlen), \
- EVP_MD_FLAG_DIGALGID_ABSENT)
+ SHA3_FLAGS)
#define IMPLEMENT_SHAKE_functions(bitlen) \
SHA3_newctx(shake, SHAKE_##bitlen, shake_##bitlen, bitlen, '\x1f') \
PROV_FUNC_SHAKE_DIGEST(shake_##bitlen, bitlen, \
SHA3_BLOCKSIZE(bitlen), SHA3_MDSIZE(bitlen), \
- EVP_MD_FLAG_XOF)
+ SHAKE_FLAGS)
#define IMPLEMENT_KMAC_functions(bitlen) \
KMAC_newctx(keccak_kmac_##bitlen, bitlen, '\x04') \
PROV_FUNC_SHAKE_DIGEST(keccak_kmac_##bitlen, bitlen, \
SHA3_BLOCKSIZE(bitlen), KMAC_MDSIZE(bitlen), \
- EVP_MD_FLAG_XOF)
+ KMAC_FLAGS)
/* ossl_sha3_224_functions */
IMPLEMENT_SHA3_functions(224)
diff --git a/providers/implementations/include/prov/ciphercommon.h b/providers/implementations/include/prov/ciphercommon.h
index efc7eb9223..ee35400936 100644
--- a/providers/implementations/include/prov/ciphercommon.h
+++ b/providers/implementations/include/prov/ciphercommon.h
@@ -34,6 +34,15 @@ typedef int (PROV_CIPHER_HW_FN)(PROV_CIPHER_CTX *dat, unsigned char *out,
/* TODO(3.0): VERIFY ME */
#define MAX_TLS_MAC_SIZE 48
+/* Internal flags that can be queried */
+#define PROV_CIPHER_FLAG_AEAD 0x0001
+#define PROV_CIPHER_FLAG_CUSTOM_IV 0x0002
+#define PROV_CIPHER_FLAG_CTS 0x0004
+#define PROV_CIPHER_FLAG_TLS1_MULTIBLOCK 0x0008
+/* Internal flags that are only used within the provider */
+#define PROV_CIPHER_FLAG_VARIABLE_LENGTH 0x0010
+#define PROV_CIPHER_FLAG_INVERSE_CIPHER 0x0020
+
struct prov_cipher_ctx_st {
block128_f block;
union {
@@ -52,7 +61,9 @@ struct prov_cipher_ctx_st {
unsigned int enc : 1; /* Set to 1 for encrypt, or 0 otherwise */
unsigned int iv_set : 1; /* Set when the iv is copied to the iv/oiv buffers */
unsigned int updated : 1; /* Set to 1 during update for one shot ciphers */
-
+ unsigned int variable_keylength : 1;
+ unsigned int inverse_cipher : 1; /* set to 1 to use inverse cipher */
+ unsigned int use_bits : 1; /* Set to 0 for cfb1 to use bits instead of bytes */
unsigned int tlsversion; /* If TLS padding is in use the TLS version number */
unsigned char *tlsmac; /* tls MAC extracted from the last record */
@@ -73,7 +84,6 @@ struct prov_cipher_ctx_st {
* manage partial blocks themselves.
*/
unsigned int num;
- uint64_t flags;
/* The original value of the iv */
unsigned char oiv[GENERIC_BLOCK_SIZE];
@@ -110,11 +120,12 @@ OSSL_FUNC_cipher_gettable_ctx_params_fn ossl_cipher_aead_gettable_ctx_params;
OSSL_FUNC_cipher_settable_ctx_params_fn ossl_cipher_aead_settable_ctx_params;
int ossl_cipher_generic_get_params(OSSL_PARAM params[], unsigned int md,
- unsigned long flags,
- size_t kbits, size_t blkbits, size_t ivbits);
+ uint64_t flags,
+ size_t kbits, size_t blkbits, size_t ivbits);
void ossl_cipher_generic_initkey(void *vctx, size_t kbits, size_t blkbits,
- size_t ivbits, unsigned int mode, uint64_t flags,
- const PROV_CIPHER_HW *hw, void *provctx);
+ size_t ivbits, unsigned int mode,
+ uint64_t flags,
+ const PROV_CIPHER_HW *hw, void *provctx);
#define IMPLEMENT_generic_cipher_func(alg, UCALG, lcmode, UCMODE, flags, kbits,\
blkbits, ivbits, typ) \
diff --git a/providers/implementations/include/prov/ciphercommon_aead.h b/providers/implementations/include/prov/ciphercommon_aead.h
index 47175f7247..63fdb54151 100644
--- a/providers/implementations/include/prov/ciphercommon_aead.h
+++ b/providers/implementations/include/prov/ciphercommon_aead.h
@@ -9,21 +9,16 @@
#define UNINITIALISED_SIZET ((size_t)-1)
-/* TODO(3.0) Figure out what flags are really needed */
-#define AEAD_FLAGS (EVP_CIPH_FLAG_AEAD_CIPHER \
- | EVP_CIPH_CUSTOM_IV \
- | EVP_CIPH_ALWAYS_CALL_INIT \
- | EVP_CIPH_CTRL_INIT \
- | EVP_CIPH_CUSTOM_COPY)
+#define AEAD_FLAGS (PROV_CIPHER_FLAG_AEAD | PROV_CIPHER_FLAG_CUSTOM_IV)
#define IMPLEMENT_aead_cipher(alg, lc, UCMODE, flags, kbits, blkbits, ivbits) \
-static OSSL_FUNC_cipher_get_params_fn alg##_##kbits##_##lc##_get_params; \
+static OSSL_FUNC_cipher_get_params_fn alg##_##kbits##_##lc##_get_params; \
static int alg##_##kbits##_##lc##_get_params(OSSL_PARAM params[]) \
{ \
- return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE, \
+ return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE, \
flags, kbits, blkbits, ivbits); \
} \
-static OSSL_FUNC_cipher_newctx_fn alg##kbits##lc##_newctx; \
+static OSSL_FUNC_cipher_newctx_fn alg##kbits##lc##_newctx; \
static void * alg##kbits##lc##_newctx(void *provctx) \
{ \
return alg##_##lc##_newctx(provctx, kbits); \
@@ -43,10 +38,10 @@ const OSSL_DISPATCH ossl_##alg##kbits##lc##_functions[] = { \
{ OSSL_FUNC_CIPHER_SET_CTX_PARAMS, \
(void (*)(void)) lc##_set_ctx_params }, \
{ OSSL_FUNC_CIPHER_GETTABLE_PARAMS, \
- (void (*)(void))ossl_cipher_generic_gettable_params }, \
+ (void (*)(void))ossl_cipher_generic_gettable_params }, \
{ OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS, \
- (void (*)(void))ossl_cipher_aead_gettable_ctx_params }, \
+ (void (*)(void))ossl_cipher_aead_gettable_ctx_params }, \
{ OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS, \
- (void (*)(void))ossl_cipher_aead_settable_ctx_params }, \
+ (void (*)(void))ossl_cipher_aead_settable_ctx_params }, \
{ 0, NULL } \
}
diff --git a/providers/implementations/include/prov/digestcommon.h b/providers/implementations/include/prov/digestcommon.h
index 99004731fa..f1164c5a1a 100644
--- a/providers/implementations/include/prov/digestcommon.h
+++ b/providers/implementations/include/prov/digestcommon.h
@@ -15,6 +15,10 @@
# include <openssl/params.h>
# include "prov/providercommon.h"
+/* Internal flags that can be queried */
+#define PROV_DIGEST_FLAG_XOF 0x0001
+#define PROV_DIGEST_FLAG_ALGID_ABSENT 0x0002
+
# ifdef __cplusplus
extern "C" {
# endif
diff --git a/providers/implementations/macs/hmac_prov.c b/providers/implementations/macs/hmac_prov.c
index 993e36ae34..3f9a862458 100644
--- a/providers/implementations/macs/hmac_prov.c
+++ b/providers/implementations/macs/hmac_prov.c
@@ -83,7 +83,6 @@ static void *hmac_new(void *provctx)
OPENSSL_free(macctx);
return NULL;
}
- /* TODO(3.0) Should we do something more with that context? */
macctx->provctx = provctx;
return macctx;
@@ -239,7 +238,8 @@ static const OSSL_PARAM known_settable_ctx_params[] = {
OSSL_PARAM_utf8_string(OSSL_MAC_PARAM_DIGEST, NULL, 0),
OSSL_PARAM_utf8_string(OSSL_MAC_PARAM_PROPERTIES, NULL, 0),
OSSL_PARAM_octet_string(OSSL_MAC_PARAM_KEY, NULL, 0),
- OSSL_PARAM_int(OSSL_MAC_PARAM_FLAGS, NULL),
+ OSSL_PARAM_int(OSSL_MAC_PARAM_DIGEST_NOINIT, NULL),
+ OSSL_PARAM_int(OSSL_MAC_PARAM_DIGEST_ONESHOT, NULL),
OSSL_PARAM_size_t(OSSL_MAC_PARAM_TLS_DATA_SIZE, NULL),
OSSL_PARAM_END
};
@@ -248,6 +248,23 @@ static const OSSL_PARAM *hmac_settable_ctx_params(ossl_unused void *provctx)
return known_settable_ctx_params;
}
+static int set_flag(const OSSL_PARAM params[], const char *key, int mask,
+ int *flags)
+{
+ const OSSL_PARAM *p = OSSL_PARAM_locate_const(params, key);
+ int flag = 0;
+
+ if (p != NULL) {
+ if (!OSSL_PARAM_get_int(p, &flag))
+ return 0;
+ if (flag == 0)
+ *flags &= ~mask;
+ else
+ *flags |= mask;
+ }
+ return 1;
+}
+
/*
* ALL parameters should be set before init().
*/
@@ -256,19 +273,20 @@ static int hmac_set_ctx_params(void *vmacctx, const OSSL_PARAM params[])
struct hmac_data_st *macctx = vmacctx;
OSSL_LIB_CTX *ctx = PROV_LIBCTX_OF(macctx->provctx);
const OSSL_PARAM *p;
+ int flags = 0;
if (!ossl_prov_digest_load_from_params(&macctx->digest, params, ctx))
return 0;
- /* TODO(3.0) formalize the meaning of "flags", perhaps as other params */
- if ((p = OSSL_PARAM_locate_const(params,
- OSSL_MAC_PARAM_FLAGS)) != NULL) {
- int flags = 0;
-
- if (!OSSL_PARAM_get_int(p, &flags))
- return 0;
+ if (!set_flag(params, OSSL_MAC_PARAM_DIGEST_NOINIT, EVP_MD_CTX_FLAG_NO_INIT,
+ &flags))
+ return 0;
+ if (!set_flag(params, OSSL_MAC_PARAM_DIGEST_ONESHOT, EVP_MD_CTX_FLAG_ONESHOT,
+ &flags))
+ return 0;
+ if (flags)
HMAC_CTX_set_flags(macctx->ctx, flags);
- }
+
if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_KEY)) != NULL) {
if (p->data_type != OSSL_PARAM_OCTET_STRING)
return 0;
More information about the openssl-commits
mailing list