aboutsummaryrefslogtreecommitdiff
path: root/crypto/evp/evp_enc.c
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2013-07-17 14:05:19 +0100
committerDr. Stephen Henson <steve@openssl.org>2013-07-17 21:45:00 +0100
commit97cf1f6c2854a3a955fd7dd3a1f113deba00c9ef (patch)
tree900ee64624393d5d9721059b2b62c22c2792190b /crypto/evp/evp_enc.c
parent415ece73015a0e24ea934ecfb857d022952bb65b (diff)
downloadopenssl-97cf1f6c2854a3a955fd7dd3a1f113deba00c9ef.zip
openssl-97cf1f6c2854a3a955fd7dd3a1f113deba00c9ef.tar.gz
openssl-97cf1f6c2854a3a955fd7dd3a1f113deba00c9ef.tar.bz2
EVP support for wrapping algorithms.
Add support for key wrap algorithms via EVP interface. Generalise AES wrap algorithm and add to modes, making existing AES wrap algorithm a special case. Move test code to evptests.txt
Diffstat (limited to 'crypto/evp/evp_enc.c')
-rw-r--r--crypto/evp/evp_enc.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c
index 5b3bf3b..f705967 100644
--- a/crypto/evp/evp_enc.c
+++ b/crypto/evp/evp_enc.c
@@ -174,7 +174,8 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp
ctx->cipher_data = NULL;
}
ctx->key_len = cipher->key_len;
- ctx->flags = 0;
+ /* Preserve wrap enable flag, zero everything else */
+ ctx->flags &= EVP_CIPHER_CTX_FLAG_WRAP_ALLOW;
if(ctx->cipher->flags & EVP_CIPH_CTRL_INIT)
{
if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_INIT, 0, NULL))
@@ -197,6 +198,13 @@ skip_to_init:
|| ctx->cipher->block_size == 8
|| ctx->cipher->block_size == 16);
+ if(!(ctx->flags & EVP_CIPHER_CTX_FLAG_WRAP_ALLOW)
+ && EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_WRAP_MODE)
+ {
+ EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_WRAP_MODE_NOT_ALLOWED);
+ return 0;
+ }
+
if(!(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_CUSTOM_IV)) {
switch(EVP_CIPHER_CTX_mode(ctx)) {
@@ -230,6 +238,7 @@ skip_to_init:
break;
}
}
+
if(key || (ctx->cipher->flags & EVP_CIPH_ALWAYS_CALL_INIT)) {
if(!ctx->cipher->init(ctx,key,iv,enc)) return 0;