[openssl-commits] [openssl] master update

Andy Polyakov appro at openssl.org
Fri May 6 07:42:25 UTC 2016


The branch master has been updated
       via  9a2d2fb338d67d3001aebcb2aa8e11d0fd7d2f80 (commit)
      from  c0aa8c274843c5b8a70d70fc05d71fa3dfd510db (commit)


- Log -----------------------------------------------------------------
commit 9a2d2fb338d67d3001aebcb2aa8e11d0fd7d2f80
Author: Andy Polyakov <appro at openssl.org>
Date:   Sat Apr 23 19:14:21 2016 +0200

    test/evp_test.c: exercise different combinations of data misalignment.
    
    Reviewed-by: Emilia Käsper <emilia at openssl.org>

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

Summary of changes:
 test/evp_test.c | 79 +++++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 55 insertions(+), 24 deletions(-)

diff --git a/test/evp_test.c b/test/evp_test.c
index 56c821b..f8506d4 100644
--- a/test/evp_test.c
+++ b/test/evp_test.c
@@ -251,7 +251,7 @@ struct evp_test {
     /* start line of current test */
     unsigned int start_line;
     /* Error string for test */
-    const char *err;
+    const char *err, *aux_err;
     /* Expected error value of test */
     char *expected_err;
     /* Number of tests */
@@ -364,8 +364,13 @@ static int check_test_error(struct evp_test *t)
     if (!t->err && !t->expected_err)
         return 1;
     if (t->err && !t->expected_err) {
-        fprintf(stderr, "Test line %d: unexpected error %s\n",
-                t->start_line, t->err);
+        if (t->aux_err != NULL) {
+            fprintf(stderr, "Test line %d(%s): unexpected error %s\n",
+                    t->start_line, t->aux_err, t->err);
+        } else {
+            fprintf(stderr, "Test line %d: unexpected error %s\n",
+                    t->start_line, t->err);
+        }
         print_expected(t);
         return 0;
     }
@@ -830,7 +835,8 @@ static int cipher_test_parse(struct evp_test *t, const char *keyword,
     return 0;
 }
 
-static int cipher_test_enc(struct evp_test *t, int enc)
+static int cipher_test_enc(struct evp_test *t, int enc,
+                           size_t out_misalign, size_t inp_misalign)
 {
     struct cipher_data *cdat = t->data;
     unsigned char *in, *out, *tmp = NULL;
@@ -854,9 +860,21 @@ static int cipher_test_enc(struct evp_test *t, int enc)
         out = cdat->plaintext;
         out_len = cdat->plaintext_len;
     }
-    tmp = OPENSSL_malloc(in_len + 2 * EVP_MAX_BLOCK_LENGTH);
+    inp_misalign += 16 - ((out_misalign + in_len) & 15);
+    /*
+     * 'tmp' will store both output and copy of input. We make the copy
+     * of input to specifically aligned part of 'tmp'. So we just
+     * figured out how much padding would ensure the required alignment,
+     * now we allocate extended buffer and finally copy the input just
+     * past inp_misalign in expression below. Output will be written
+     * past out_misalign...
+     */
+    tmp = OPENSSL_malloc(out_misalign + in_len + 2 * EVP_MAX_BLOCK_LENGTH +
+                         inp_misalign + in_len);
     if (!tmp)
         goto err;
+    in = memcpy(tmp + out_misalign + in_len + 2 * EVP_MAX_BLOCK_LENGTH +
+                inp_misalign, in, in_len);
     err = "CIPHERINIT_ERROR";
     if (!EVP_CipherInit_ex(ctx, cdat->cipher, NULL, NULL, NULL, enc))
         goto err;
@@ -918,20 +936,20 @@ static int cipher_test_enc(struct evp_test *t, int enc)
     }
     EVP_CIPHER_CTX_set_padding(ctx, 0);
     err = "CIPHERUPDATE_ERROR";
-    if (!EVP_CipherUpdate(ctx, tmp, &tmplen, in, in_len))
+    if (!EVP_CipherUpdate(ctx, tmp + out_misalign, &tmplen, in, in_len))
         goto err;
     if (cdat->aead == EVP_CIPH_CCM_MODE)
         tmpflen = 0;
     else {
         err = "CIPHERFINAL_ERROR";
-        if (!EVP_CipherFinal_ex(ctx, tmp + tmplen, &tmpflen))
+        if (!EVP_CipherFinal_ex(ctx, tmp + out_misalign + tmplen, &tmpflen))
             goto err;
     }
     err = "LENGTH_MISMATCH";
     if (out_len != (size_t)(tmplen + tmpflen))
         goto err;
     err = "VALUE_MISMATCH";
-    if (check_output(t, out, tmp, out_len))
+    if (check_output(t, out, tmp + out_misalign, out_len))
         goto err;
     if (enc && cdat->aead) {
         unsigned char rtag[16];
@@ -961,6 +979,8 @@ static int cipher_test_run(struct evp_test *t)
 {
     struct cipher_data *cdat = t->data;
     int rv;
+    size_t out_misalign, inp_misalign;
+
     if (!cdat->key) {
         t->err = "NO_KEY";
         return 0;
@@ -976,24 +996,35 @@ static int cipher_test_run(struct evp_test *t)
         t->err = "NO_TAG";
         return 0;
     }
-    if (cdat->enc) {
-        rv = cipher_test_enc(t, 1);
-        /* Not fatal errors: return */
-        if (rv != 1) {
-            if (rv < 0)
-                return 0;
-            return 1;
-        }
-    }
-    if (cdat->enc != 1) {
-        rv = cipher_test_enc(t, 0);
-        /* Not fatal errors: return */
-        if (rv != 1) {
-            if (rv < 0)
-                return 0;
-            return 1;
+    for (out_misalign = 0; out_misalign <= 1; out_misalign++) {
+        static char aux_err[64];
+        t->aux_err = aux_err;
+        for (inp_misalign = 0; inp_misalign <= 1; inp_misalign++) {
+            BIO_snprintf(aux_err, sizeof(aux_err), "%s output and %s input",
+                         out_misalign ? "misaligned" : "aligned",
+                         inp_misalign ? "misaligned" : "aligned");
+            if (cdat->enc) {
+                rv = cipher_test_enc(t, 1, out_misalign, inp_misalign);
+                /* Not fatal errors: return */
+                if (rv != 1) {
+                    if (rv < 0)
+                        return 0;
+                    return 1;
+                }
+            }
+            if (cdat->enc != 1) {
+                rv = cipher_test_enc(t, 0, out_misalign, inp_misalign);
+                /* Not fatal errors: return */
+                if (rv != 1) {
+                    if (rv < 0)
+                        return 0;
+                    return 1;
+                }
+            }
         }
     }
+    t->aux_err = NULL;
+
     return 1;
 }
 


More information about the openssl-commits mailing list