summaryrefslogtreecommitdiffstats
path: root/providers
diff options
context:
space:
mode:
Diffstat (limited to 'providers')
-rw-r--r--providers/defltprov.c9
-rw-r--r--providers/fips/fipsprov.c9
-rw-r--r--providers/implementations/ciphers/cipher_aes_wrp.c31
-rw-r--r--providers/implementations/include/prov/implementations.h6
4 files changed, 52 insertions, 3 deletions
diff --git a/providers/defltprov.c b/providers/defltprov.c
index 959c48d1db..123f03e726 100644
--- a/providers/defltprov.c
+++ b/providers/defltprov.c
@@ -204,6 +204,15 @@ static const OSSL_ALGORITHM_CAPABLE deflt_ciphers[] = {
ossl_aes192wrappad_functions),
ALG("AES-128-WRAP-PAD:id-aes128-wrap-pad:AES128-WRAP-PAD",
ossl_aes128wrappad_functions),
+ ALG("AES-256-WRAP-INV:AES256-WRAP-INV", ossl_aes256wrapinv_functions),
+ ALG("AES-192-WRAP-INV:AES192-WRAP-INV", ossl_aes192wrapinv_functions),
+ ALG("AES-128-WRAP-INV:AES128-WRAP-INV", ossl_aes128wrapinv_functions),
+ ALG("AES-256-WRAP-PAD-INV:AES256-WRAP-PAD-INV",
+ ossl_aes256wrappadinv_functions),
+ ALG("AES-192-WRAP-PAD-INV:AES192-WRAP-PAD-INV",
+ ossl_aes192wrappadinv_functions),
+ ALG("AES-128-WRAP-PAD-INV:AES128-WRAP-PAD-INV",
+ ossl_aes128wrappadinv_functions),
ALGC("AES-128-CBC-HMAC-SHA1", ossl_aes128cbc_hmac_sha1_functions,
ossl_cipher_capable_aes_cbc_hmac_sha1),
ALGC("AES-256-CBC-HMAC-SHA1", ossl_aes256cbc_hmac_sha1_functions,
diff --git a/providers/fips/fipsprov.c b/providers/fips/fipsprov.c
index a4e6601071..33b2f0213e 100644
--- a/providers/fips/fipsprov.c
+++ b/providers/fips/fipsprov.c
@@ -286,6 +286,15 @@ static const OSSL_ALGORITHM_CAPABLE fips_ciphers[] = {
ossl_aes192wrappad_functions),
ALG("AES-128-WRAP-PAD:id-aes128-wrap-pad:AES128-WRAP-PAD",
ossl_aes128wrappad_functions),
+ ALG("AES-256-WRAP-INV:AES256-WRAP-INV", ossl_aes256wrapinv_functions),
+ ALG("AES-192-WRAP-INV:AES192-WRAP-INV", ossl_aes192wrapinv_functions),
+ ALG("AES-128-WRAP-INV:AES128-WRAP-INV", ossl_aes128wrapinv_functions),
+ ALG("AES-256-WRAP-PAD-INV:AES256-WRAP-PAD-INV",
+ ossl_aes256wrappadinv_functions),
+ ALG("AES-192-WRAP-PAD-INV:AES192-WRAP-PAD-INV",
+ ossl_aes192wrappadinv_functions),
+ ALG("AES-128-WRAP-PAD-INV:AES128-WRAP-PAD-INV",
+ ossl_aes128wrappadinv_functions),
ALGC("AES-128-CBC-HMAC-SHA1", ossl_aes128cbc_hmac_sha1_functions,
ossl_cipher_capable_aes_cbc_hmac_sha1),
ALGC("AES-256-CBC-HMAC-SHA1", ossl_aes256cbc_hmac_sha1_functions,
diff --git a/providers/implementations/ciphers/cipher_aes_wrp.c b/providers/implementations/ciphers/cipher_aes_wrp.c
index 3918161b46..ca57666e7a 100644
--- a/providers/implementations/ciphers/cipher_aes_wrp.c
+++ b/providers/implementations/ciphers/cipher_aes_wrp.c
@@ -25,6 +25,7 @@
/* 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)
typedef size_t (*aeswrap_fn)(void *key, const unsigned char *iv,
unsigned char *out, const unsigned char *in,
@@ -85,7 +86,6 @@ static int aes_wrap_init(void *vctx, const unsigned char *key,
return 0;
ctx->enc = enc;
- ctx->block = enc ? (block128_f)AES_encrypt : (block128_f)AES_decrypt;
if (ctx->pad)
wctx->wrapfn = enc ? CRYPTO_128_wrap_pad : CRYPTO_128_unwrap_pad;
else
@@ -96,14 +96,32 @@ static int aes_wrap_init(void *vctx, const unsigned char *key,
return 0;
}
if (key != NULL) {
+ int use_forward_transform;
+
if (keylen != ctx->keylen) {
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);
return 0;
}
- if (ctx->enc)
- AES_set_encrypt_key(key, keylen * 8, &wctx->ks.ks);
+ /*
+ * See SP800-38F : Section 5.1
+ * The forward and inverse transformations for the AES block
+ * cipher—called “cipher” and “inverse cipher” are informally known as
+ * the AES encryption and AES decryption functions, respectively.
+ * If the designated cipher function for a key-wrap algorithm is chosen
+ * to be the AES decryption function, then CIPH-1K will be the AES
+ * encryption function.
+ */
+ if ((ctx->flags & EVP_CIPH_FLAG_INVERSE_CIPHER) == 0)
+ use_forward_transform = ctx->enc;
else
+ use_forward_transform = !ctx->enc;
+ if (use_forward_transform) {
+ AES_set_encrypt_key(key, keylen * 8, &wctx->ks.ks);
+ ctx->block = (block128_f)AES_encrypt;
+ } else {
AES_set_decrypt_key(key, keylen * 8, &wctx->ks.ks);
+ ctx->block = (block128_f)AES_decrypt;
+ }
}
return 1;
}
@@ -266,3 +284,10 @@ IMPLEMENT_cipher(wrap, wrap, WRAP, WRAP_FLAGS, 128, 64, AES_WRAP_NOPAD_IVLEN * 8
IMPLEMENT_cipher(wrap, wrappad, WRAP, WRAP_FLAGS, 256, 64, AES_WRAP_PAD_IVLEN * 8);
IMPLEMENT_cipher(wrap, wrappad, WRAP, WRAP_FLAGS, 192, 64, AES_WRAP_PAD_IVLEN * 8);
IMPLEMENT_cipher(wrap, wrappad, WRAP, WRAP_FLAGS, 128, 64, AES_WRAP_PAD_IVLEN * 8);
+
+IMPLEMENT_cipher(wrap, wrapinv, WRAP, WRAP_FLAGS_INV, 256, 64, AES_WRAP_NOPAD_IVLEN * 8);
+IMPLEMENT_cipher(wrap, wrapinv, WRAP, WRAP_FLAGS_INV, 192, 64, AES_WRAP_NOPAD_IVLEN * 8);
+IMPLEMENT_cipher(wrap, wrapinv, WRAP, WRAP_FLAGS_INV, 128, 64, AES_WRAP_NOPAD_IVLEN * 8);
+IMPLEMENT_cipher(wrap, wrappadinv, WRAP, WRAP_FLAGS_INV, 256, 64, AES_WRAP_PAD_IVLEN * 8);
+IMPLEMENT_cipher(wrap, wrappadinv, WRAP, WRAP_FLAGS_INV, 192, 64, AES_WRAP_PAD_IVLEN * 8);
+IMPLEMENT_cipher(wrap, wrappadinv, WRAP, WRAP_FLAGS_INV, 128, 64, AES_WRAP_PAD_IVLEN * 8);
diff --git a/providers/implementations/include/prov/implementations.h b/providers/implementations/include/prov/implementations.h
index 1db344b946..fd6b721364 100644
--- a/providers/implementations/include/prov/implementations.h
+++ b/providers/implementations/include/prov/implementations.h
@@ -82,6 +82,12 @@ extern const OSSL_DISPATCH ossl_aes128wrap_functions[];
extern const OSSL_DISPATCH ossl_aes256wrappad_functions[];
extern const OSSL_DISPATCH ossl_aes192wrappad_functions[];
extern const OSSL_DISPATCH ossl_aes128wrappad_functions[];
+extern const OSSL_DISPATCH ossl_aes256wrapinv_functions[];
+extern const OSSL_DISPATCH ossl_aes192wrapinv_functions[];
+extern const OSSL_DISPATCH ossl_aes128wrapinv_functions[];
+extern const OSSL_DISPATCH ossl_aes256wrappadinv_functions[];
+extern const OSSL_DISPATCH ossl_aes192wrappadinv_functions[];
+extern const OSSL_DISPATCH ossl_aes128wrappadinv_functions[];
extern const OSSL_DISPATCH ossl_aes256cbc_hmac_sha1_functions[];
extern const OSSL_DISPATCH ossl_aes128cbc_hmac_sha1_functions[];
extern const OSSL_DISPATCH ossl_aes256cbc_hmac_sha256_functions[];