aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Polyakov <appro@openssl.org>2016-05-09 14:18:14 +0200
committerAndy Polyakov <appro@openssl.org>2016-05-16 22:26:37 +0200
commitff715da492fb82b4ea681aae64d73a6c6264218b (patch)
tree387bbee81c1f920e8ab377f08ed46d7cc1f553be
parent6133b4edbd12266ef9ccc3cbbfc0d5bb56e0d481 (diff)
downloadopenssl-ff715da492fb82b4ea681aae64d73a6c6264218b.zip
openssl-ff715da492fb82b4ea681aae64d73a6c6264218b.tar.gz
openssl-ff715da492fb82b4ea681aae64d73a6c6264218b.tar.bz2
test/evp_test.c: exercise in-place encryption.
Reviewed-by: Emilia Käsper <emilia@openssl.org>
-rw-r--r--test/evp_test.c54
1 files changed, 35 insertions, 19 deletions
diff --git a/test/evp_test.c b/test/evp_test.c
index f8506d4..629f23c 100644
--- a/test/evp_test.c
+++ b/test/evp_test.c
@@ -860,21 +860,31 @@ static int cipher_test_enc(struct evp_test *t, int enc,
out = cdat->plaintext;
out_len = cdat->plaintext_len;
}
- 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);
+ if (inp_misalign == (size_t)-1) {
+ /*
+ * Exercise in-place encryption
+ */
+ tmp = OPENSSL_malloc(out_misalign + in_len + 2 * EVP_MAX_BLOCK_LENGTH);
+ if (!tmp)
+ goto err;
+ in = memcpy(tmp + out_misalign, in, in_len);
+ } else {
+ 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;
@@ -999,10 +1009,16 @@ static int cipher_test_run(struct evp_test *t)
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");
+ for (inp_misalign = (size_t)-1; inp_misalign != 2; inp_misalign++) {
+ if (inp_misalign == (size_t)-1) {
+ /* kludge: inp_misalign == -1 means "exercise in-place" */
+ BIO_snprintf(aux_err, sizeof(aux_err), "%s in-place",
+ out_misalign ? "misaligned" : "aligned");
+ } else {
+ 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 */