2 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 #include <openssl/evp.h>
12 #include <openssl/bio.h>
17 static const unsigned char key[16] = { 0 };
18 static unsigned char inp[1024] = { 0 };
19 unsigned char out[1024], ref[1024];
22 b = BIO_new(BIO_f_cipher());
23 if (!BIO_set_cipher(b, EVP_camellia_128_ctr(), key, NULL, 0))
25 BIO_push(b, BIO_new_mem_buf(inp, sizeof(inp)));
26 lref = BIO_read(b, inp, sizeof(inp));
33 /* reference output for single-chunk operation */
34 b = BIO_new(BIO_f_cipher());
35 if (!BIO_set_cipher(b, EVP_aes_128_cbc(), key, NULL, 0))
37 BIO_push(b, BIO_new_mem_buf(inp, sizeof(inp)));
38 lref = BIO_read(b, ref, sizeof(ref));
41 /* perform split operations and compare to reference */
42 for (i = 1; i < lref; i++) {
43 b = BIO_new(BIO_f_cipher());
44 if (!BIO_set_cipher(b, EVP_aes_128_cbc(), key, NULL, 0))
46 BIO_push(b, BIO_new_mem_buf(inp, sizeof(inp)));
47 memset(out, 0, sizeof(out));
49 len = BIO_read(b, out, i);
50 /* check for overstep */
51 if (out[i] != (unsigned char)~ref[i]) {
52 fprintf(stderr, "CBC output overstep@%d\n", i);
55 len += BIO_read(b, out + len, sizeof(out) - len);
58 if (len != lref || memcmp(out, ref, len)) {
59 fprintf(stderr, "CBC output mismatch@%d\n", i);
64 /* perform small-chunk operations and compare to reference */
65 for (i = 1; i < lref / 2; i++) {
68 b = BIO_new(BIO_f_cipher());
69 if (!BIO_set_cipher(b, EVP_aes_128_cbc(), key, NULL, 0))
71 BIO_push(b, BIO_new_mem_buf(inp, sizeof(inp)));
72 memset(out, 0, sizeof(out));
73 for (len = 0; (delta = BIO_read(b, out + len, i)); ) {
78 if (len != lref || memcmp(out, ref, len)) {
79 fprintf(stderr, "CBC output mismatch@%d\n", i);
88 /* reference output for single-chunk operation */
89 b = BIO_new(BIO_f_cipher());
90 if (!BIO_set_cipher(b, EVP_aes_128_cbc(), key, NULL, 0))
92 BIO_push(b, BIO_new_mem_buf(inp, sizeof(inp)));
93 lref = BIO_read(b, ref, sizeof(ref));
96 /* perform split operations and compare to reference */
97 for (i = 1; i < lref; i++) {
98 b = BIO_new(BIO_f_cipher());
99 if (!BIO_set_cipher(b, EVP_aes_128_cbc(), key, NULL, 0))
101 BIO_push(b, BIO_new_mem_buf(inp, sizeof(inp)));
102 memset(out, 0, sizeof(out));
104 len = BIO_read(b, out, i);
105 /* check for overstep */
106 if (out[i] != (unsigned char)~ref[i]) {
107 fprintf(stderr, "CTR output overstep@%d\n", i);
110 len += BIO_read(b, out + len, sizeof(out) - len);
113 if (len != lref || memcmp(out, ref, len)) {
114 fprintf(stderr, "CTR output mismatch@%d\n", i);
119 /* perform small-chunk operations and compare to reference */
120 for (i = 1; i < lref / 2; i++) {
123 b = BIO_new(BIO_f_cipher());
124 if (!BIO_set_cipher(b, EVP_aes_128_cbc(), key, NULL, 0))
126 BIO_push(b, BIO_new_mem_buf(inp, sizeof(inp)));
127 memset(out, 0, sizeof(out));
128 for (len = 0; (delta = BIO_read(b, out + len, i)); ) {
133 if (len != lref || memcmp(out, ref, len)) {
134 fprintf(stderr, "CTR output mismatch@%d\n", i);