[openssl-commits] [openssl] master update

Matt Caswell matt at openssl.org
Fri Sep 25 14:16:21 UTC 2015


The branch master has been updated
       via  51a6081719373d5dabda0d628d1637c501dd2068 (commit)
      from  a2c1dedc5de3312fd4d6506923f2a61eecc67985 (commit)


- Log -----------------------------------------------------------------
commit 51a6081719373d5dabda0d628d1637c501dd2068
Author: Matt Caswell <matt at openssl.org>
Date:   Tue Sep 22 08:54:43 2015 +0100

    Change ossltest engine to manually allocate cipher_data
    
    The ossltest engine wraps the built-in implementation of aes128-cbc.
    Normally in an engine the cipher_data structure is automatically allocated
    by the EVP layer. However this relies on the engine specifying up front
    the size of that cipher_data structure. In the case of ossltest this value
    isn't available at compile time. This change makes the ossltest engine
    allocate its own cipher_data structure instead of leaving it to the EVP
    layer.
    
    Reviewed-by: Andy Polyakov <appro at openssl.org>

-----------------------------------------------------------------------

Summary of changes:
 engines/e_ossltest.c     | 32 ++++++++++++++------------------
 engines/e_ossltest_err.c |  2 ++
 engines/e_ossltest_err.h |  1 +
 3 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/engines/e_ossltest.c b/engines/e_ossltest.c
index 6e50a5f..c339026 100644
--- a/engines/e_ossltest.c
+++ b/engines/e_ossltest.c
@@ -207,23 +207,6 @@ int ossltest_aes128_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
 int ossltest_aes128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
                                const unsigned char *in, size_t inl);
 
-/*
- * Copy of the definition in crypto/evp/e_aes.c. Only used for the "sizeof"
- * below
- */
-typedef struct {
-    union {
-        double align;
-        AES_KEY ks;
-    } ks;
-    block128_f block;
-    union {
-        cbc128_f cbc;
-        ctr128_f ctr;
-    } stream;
-} EVP_AES_KEY;
-
-
 static const EVP_CIPHER ossltest_aes_128_cbc = { \
     NID_aes_128_cbc,
     16, /* block size */
@@ -233,7 +216,7 @@ static const EVP_CIPHER ossltest_aes_128_cbc = { \
     ossltest_aes128_init_key,
     ossltest_aes128_cbc_cipher,
     NULL,
-    sizeof(EVP_AES_KEY),
+    0, /* We don't know the size of cipher_data at compile time */
     NULL,NULL,NULL,NULL
 };
 
@@ -515,6 +498,19 @@ static int digest_sha512_final(EVP_MD_CTX *ctx, unsigned char *md)
 int ossltest_aes128_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
                              const unsigned char *iv, int enc)
 {
+    if (ctx->cipher_data == NULL) {
+        /*
+         * Normally cipher_data is allocated automatically for an engine but
+         * we don't know the ctx_size as compile time so we have to do it at
+         * run time
+         */
+        ctx->cipher_data = OPENSSL_zalloc(EVP_aes_128_cbc()->ctx_size);
+        if (!ctx->cipher_data) {
+            OSSLTESTerr(OSSLTEST_F_OSSLTEST_AES128_INIT_KEY,
+                        ERR_R_MALLOC_FAILURE);
+            return 0;
+        }
+    }
     return EVP_aes_128_cbc()->init(ctx, key, iv, enc);
 }
 
diff --git a/engines/e_ossltest_err.c b/engines/e_ossltest_err.c
index c1b0063..4abb395 100644
--- a/engines/e_ossltest_err.c
+++ b/engines/e_ossltest_err.c
@@ -71,6 +71,8 @@
 
 static ERR_STRING_DATA OSSLTEST_str_functs[] = {
     {ERR_FUNC(OSSLTEST_F_BIND_OSSLTEST), "BIND_OSSLTEST"},
+    {ERR_FUNC(OSSLTEST_F_OSSLTEST_AES128_INIT_KEY),
+     "OSSLTEST_AES128_INIT_KEY"},
     {0, NULL}
 };
 
diff --git a/engines/e_ossltest_err.h b/engines/e_ossltest_err.h
index 8f874e0..b46eb05 100644
--- a/engines/e_ossltest_err.h
+++ b/engines/e_ossltest_err.h
@@ -73,6 +73,7 @@ static void ERR_OSSLTEST_error(int function, int reason, char *file, int line);
 
 /* Function codes. */
 # define OSSLTEST_F_BIND_OSSLTEST                         100
+# define OSSLTEST_F_OSSLTEST_AES128_INIT_KEY              101
 
 /* Reason codes. */
 # define OSSLTEST_R_INIT_FAILED                           100


More information about the openssl-commits mailing list