1 From d2cb6745bb166818b6bd9e9011990453fedbccef Mon Sep 17 00:00:00 2001
2 From: Alexe Radu <radu.alexe@nxp.com>
3 Date: Fri, 9 Dec 2016 15:25:20 +0200
4 Subject: [PATCH 099/104] add support for authenc(hmac(sha1), cbc(aes)) speed
7 Signed-off-by: Alexe Radu <radu.alexe@nxp.com>
9 crypto/cryptodev.h | 1 +
11 tests/speed.c | 155 +++++++++++++++++++++++++++++++++++++++++++++++------
12 3 files changed, 146 insertions(+), 15 deletions(-)
14 diff --git a/crypto/cryptodev.h b/crypto/cryptodev.h
15 index 05221a4..05dc57b 100644
16 --- a/crypto/cryptodev.h
17 +++ b/crypto/cryptodev.h
18 @@ -62,6 +62,7 @@ enum cryptodev_crypto_op_t {
19 CRYPTO_TLS12_3DES_CBC_HMAC_SHA1,
20 CRYPTO_TLS12_AES_CBC_HMAC_SHA1,
21 CRYPTO_TLS12_AES_CBC_HMAC_SHA256,
22 + CRYPTO_AUTHENC_HMAC_SHA1_CBC_AES,
23 CRYPTO_ALGORITHM_ALL, /* Keep updated - see below */
26 diff --git a/ioctl.c b/ioctl.c
27 index e3b8af1..7288ffc 100644
30 @@ -222,6 +222,11 @@ crypto_create_session(struct fcrypt *fcr, struct session_op *sop)
34 + case CRYPTO_AUTHENC_HMAC_SHA1_CBC_AES:
35 + alg_name = "authenc(hmac(sha1),cbc(aes))";
40 alg_name = "ecb(cipher_null)";
42 diff --git a/tests/speed.c b/tests/speed.c
43 index fc38a63..61259b9 100644
62 @@ -59,8 +62,9 @@ int run_aes_256_xts(int fdc, struct test_params tp);
63 int run_crc32c(int fdc, struct test_params tp);
64 int run_sha1(int fdc, struct test_params tp);
65 int run_sha256(int fdc, struct test_params tp);
66 +int run_authenc(int fdc, struct test_params tp);
72 int (*func)(int, struct test_params);
73 @@ -71,6 +75,7 @@ struct {
74 {"crc32c", run_crc32c},
76 {"sha256", run_sha256},
77 + {"authenc", run_authenc},
80 static double udifftimeval(struct timeval start, struct timeval end)
81 @@ -269,7 +274,7 @@ static int encrypt_sync(int fdc, struct test_params tp, struct session_op *sess)
83 memset(buffer, val++, tp.nvalue);
89 gettimeofday(&start, NULL);
90 @@ -305,6 +310,84 @@ static int encrypt_sync(int fdc, struct test_params tp, struct session_op *sess)
94 +static int encrypt_auth(int fdc, struct test_params tp, struct session_op *sess)
96 + struct crypt_auth_op cao;
97 + char *buffer, iv[32];
98 + uint8_t auth[AUTH_SIZE];
99 + static int val = 23;
100 + struct timeval start, end;
101 + uint64_t total = 0;
102 + double secs, ddata, dspeed;
105 + int min_alignmask = sizeof(void*) - 1;
108 + memset(iv, 0x23, 32);
109 + memset(auth, 0xf1, sizeof(auth));
112 + printf("\tBuffer size %d bytes: ", tp.nvalue);
116 + alloc_size = tp.nvalue + TAG_LEN;
117 + alignmask = get_alignmask(fdc, sess);
119 + alignmask = ((alignmask < min_alignmask) ? min_alignmask : alignmask);
120 + if (posix_memalign((void **)(&buffer), alignmask + 1, alloc_size)) {
121 + printf("posix_memalign() failed!\n");
125 + if (!(buffer = malloc(alloc_size))) {
126 + perror("malloc()");
130 + memset(buffer, val++, tp.nvalue);
135 + gettimeofday(&start, NULL);
137 + memset(&cao, 0, sizeof(cao));
138 + cao.ses = sess->ses;
139 + cao.auth_src = auth;
140 + cao.auth_len = sizeof(auth);
141 + cao.len = tp.nvalue;
142 + cao.iv = (unsigned char *)iv;
143 + cao.op = COP_ENCRYPT;
144 + cao.src = (unsigned char *)buffer;
146 + cao.tag_len = TAG_LEN;
147 + cao.flags = COP_FLAG_AEAD_TLS_TYPE;
149 + if (ioctl(fdc, CIOCAUTHCRYPT, &cao)) {
150 + perror("ioctl(CIOCAUTHCRYPT)");
154 + } while(!must_finish);
155 + gettimeofday(&end, NULL);
157 + secs = udifftimeval(start, end)/ 1000000.0;
160 + value2machine(total, secs, &dspeed);
161 + printf("%" PRIu64 "\t%.2f\t%.2f\n", total, secs, dspeed);
163 + value2human(total, secs, &ddata, &dspeed, metric);
164 + printf ("done. %.2f %s in %.2f secs: ", ddata, metric, secs);
165 + printf ("%.2f %s/sec\n", dspeed, metric);
172 void usage(char *cmd_name)
174 printf(usage_str, cmd_name);
175 @@ -326,11 +409,19 @@ int run_test(int id, struct test_params tp)
179 + if (strcmp("authenc", ciphers[id].name) == 0) {
180 + tp.authflag = true;
185 - type = tp.aflag ? "async" : "sync";
187 + fprintf(stderr, "Testing %s:\n", ciphers[id].name);
190 + type = tp.aflag ? "async" : "sync";
192 - fprintf(stderr, "Testing %s %s:\n", type, ciphers[id].name);
193 + fprintf(stderr, "Testing %s %s:\n", type, ciphers[id].name);
196 err = ciphers[id].func(fdc, tp);
198 @@ -340,17 +431,30 @@ int run_test(int id, struct test_params tp)
202 -void do_test_vectors(int fdc, struct test_params tp, struct session_op *sess)
203 +static int start_test (int fdc, struct test_params tp, struct session_op *sess)
210 + err = encrypt_auth(fdc, tp, sess);
213 - encrypt_async(fdc, tp, sess);
214 + err = encrypt_async(fdc, tp, sess);
216 - encrypt_sync(fdc, tp, sess);
217 + err = encrypt_sync(fdc, tp, sess);
224 +void do_test_vectors(int fdc, struct test_params tp, struct session_op *sess)
230 + err = start_test(fdc, tp, sess);
232 for (i = 256; i <= (64 * 1024); i *= 2) {
234 @@ -358,11 +462,7 @@ void do_test_vectors(int fdc, struct test_params tp, struct session_op *sess)
239 - err = encrypt_async(fdc, tp, sess);
241 - err = encrypt_sync(fdc, tp, sess);
243 + err = start_test(fdc, tp, sess);
247 @@ -474,6 +574,30 @@ int run_sha256(int fdc, struct test_params tp)
251 +int run_authenc(int fdc, struct test_params tp)
253 + struct session_op sess;
254 + char *mkeybuf = "\x00\x00\x00\x00\x00\x00\x00\x00"
255 + "\x00\x00\x00\x00\x00\x00\x00\x00"
256 + "\x00\x00\x00\x00";
257 + char *ckeybuf = "\x06\xa9\x21\x40\x36\xb8\xa1\x5b"
258 + "\x51\x2e\x03\xd5\x34\x12\x00\x06";
260 + memset(&sess, 0, sizeof(sess));
261 + sess.cipher = CRYPTO_AUTHENC_HMAC_SHA1_CBC_AES;
263 + sess.key = (unsigned char *)ckeybuf;
264 + sess.mackeylen = 20;
265 + sess.mackey = (unsigned char *)mkeybuf;
266 + if (ioctl(fdc, CIOCGSESSION, &sess)) {
267 + perror("ioctl(CIOCGSESSION)");
271 + do_test_vectors(fdc, tp, &sess);
275 int main(int argc, char **argv)
278 @@ -487,6 +611,7 @@ int main(int argc, char **argv)
282 + tp.authflag = false;
285 while ((c = getopt(argc, argv, "ahn:t:m")) != -1) {