summaryrefslogtreecommitdiffstats
path: root/recipes-kernel/cryptodev/sdk_patches/0099-add-support-for-authenc-hmac-sha1-cbc-aes-speed-test.patch
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-kernel/cryptodev/sdk_patches/0099-add-support-for-authenc-hmac-sha1-cbc-aes-speed-test.patch')
-rw-r--r--recipes-kernel/cryptodev/sdk_patches/0099-add-support-for-authenc-hmac-sha1-cbc-aes-speed-test.patch288
1 files changed, 0 insertions, 288 deletions
diff --git a/recipes-kernel/cryptodev/sdk_patches/0099-add-support-for-authenc-hmac-sha1-cbc-aes-speed-test.patch b/recipes-kernel/cryptodev/sdk_patches/0099-add-support-for-authenc-hmac-sha1-cbc-aes-speed-test.patch
deleted file mode 100644
index f65979af..00000000
--- a/recipes-kernel/cryptodev/sdk_patches/0099-add-support-for-authenc-hmac-sha1-cbc-aes-speed-test.patch
+++ /dev/null
@@ -1,288 +0,0 @@
1From d2cb6745bb166818b6bd9e9011990453fedbccef Mon Sep 17 00:00:00 2001
2From: Alexe Radu <radu.alexe@nxp.com>
3Date: Fri, 9 Dec 2016 15:25:20 +0200
4Subject: [PATCH 099/104] add support for authenc(hmac(sha1), cbc(aes)) speed
5 tests
6
7Signed-off-by: Alexe Radu <radu.alexe@nxp.com>
8---
9 crypto/cryptodev.h | 1 +
10 ioctl.c | 5 ++
11 tests/speed.c | 155 +++++++++++++++++++++++++++++++++++++++++++++++------
12 3 files changed, 146 insertions(+), 15 deletions(-)
13
14diff --git a/crypto/cryptodev.h b/crypto/cryptodev.h
15index 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 */
24 };
25
26diff --git a/ioctl.c b/ioctl.c
27index e3b8af1..7288ffc 100644
28--- a/ioctl.c
29+++ b/ioctl.c
30@@ -222,6 +222,11 @@ crypto_create_session(struct fcrypt *fcr, struct session_op *sop)
31 stream = 0;
32 aead = 1;
33 break;
34+ case CRYPTO_AUTHENC_HMAC_SHA1_CBC_AES:
35+ alg_name = "authenc(hmac(sha1),cbc(aes))";
36+ stream = 0;
37+ aead = 1;
38+ break;
39 case CRYPTO_NULL:
40 alg_name = "ecb(cipher_null)";
41 stream = 1;
42diff --git a/tests/speed.c b/tests/speed.c
43index fc38a63..61259b9 100644
44--- a/tests/speed.c
45+++ b/tests/speed.c
46@@ -33,12 +33,15 @@
47 #include <stdint.h>
48 #include <inttypes.h>
49
50+#define AUTH_SIZE 31
51+#define TAG_LEN 20
52
53 struct test_params {
54 bool tflag;
55 bool nflag;
56 bool mflag;
57 bool aflag;
58+ bool authflag;
59 int tvalue;
60 int nvalue;
61 };
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);
67
68-#define ALG_COUNT 6
69+#define ALG_COUNT 7
70 struct {
71 char *name;
72 int (*func)(int, struct test_params);
73@@ -71,6 +75,7 @@ struct {
74 {"crc32c", run_crc32c},
75 {"sha1", run_sha1},
76 {"sha256", run_sha256},
77+ {"authenc", run_authenc},
78 };
79
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)
82 }
83 memset(buffer, val++, tp.nvalue);
84
85- must_finish = 0;
86+ must_finish = 1;
87 alarm(tp.tvalue);
88
89 gettimeofday(&start, NULL);
90@@ -305,6 +310,84 @@ static int encrypt_sync(int fdc, struct test_params tp, struct session_op *sess)
91 return 0;
92 }
93
94+static int encrypt_auth(int fdc, struct test_params tp, struct session_op *sess)
95+{
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;
103+ char metric[16];
104+ int alignmask;
105+ int min_alignmask = sizeof(void*) - 1;
106+ int alloc_size;
107+
108+ memset(iv, 0x23, 32);
109+ memset(auth, 0xf1, sizeof(auth));
110+
111+ if (!tp.mflag) {
112+ printf("\tBuffer size %d bytes: ", tp.nvalue);
113+ fflush(stdout);
114+ }
115+
116+ alloc_size = tp.nvalue + TAG_LEN;
117+ alignmask = get_alignmask(fdc, sess);
118+ if (alignmask) {
119+ alignmask = ((alignmask < min_alignmask) ? min_alignmask : alignmask);
120+ if (posix_memalign((void **)(&buffer), alignmask + 1, alloc_size)) {
121+ printf("posix_memalign() failed!\n");
122+ return 1;
123+ }
124+ } else {
125+ if (!(buffer = malloc(alloc_size))) {
126+ perror("malloc()");
127+ return 1;
128+ }
129+ }
130+ memset(buffer, val++, tp.nvalue);
131+
132+ must_finish = 0;
133+ alarm(tp.tvalue);
134+
135+ gettimeofday(&start, NULL);
136+ do {
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;
145+ cao.dst = cao.src;
146+ cao.tag_len = TAG_LEN;
147+ cao.flags = COP_FLAG_AEAD_TLS_TYPE;
148+
149+ if (ioctl(fdc, CIOCAUTHCRYPT, &cao)) {
150+ perror("ioctl(CIOCAUTHCRYPT)");
151+ return 1;
152+ }
153+ total += cao.len;
154+ } while(!must_finish);
155+ gettimeofday(&end, NULL);
156+
157+ secs = udifftimeval(start, end)/ 1000000.0;
158+
159+ if (tp.mflag) {
160+ value2machine(total, secs, &dspeed);
161+ printf("%" PRIu64 "\t%.2f\t%.2f\n", total, secs, dspeed);
162+ } else {
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);
166+ }
167+
168+ free(buffer);
169+ return 0;
170+}
171+
172 void usage(char *cmd_name)
173 {
174 printf(usage_str, cmd_name);
175@@ -326,11 +409,19 @@ int run_test(int id, struct test_params tp)
176 return -EINVAL;
177 }
178
179+ if (strcmp("authenc", ciphers[id].name) == 0) {
180+ tp.authflag = true;
181+ }
182+
183 if (!tp.mflag) {
184- char *type;
185- type = tp.aflag ? "async" : "sync";
186+ if (tp.authflag) {
187+ fprintf(stderr, "Testing %s:\n", ciphers[id].name);
188+ } else {
189+ char *type;
190+ type = tp.aflag ? "async" : "sync";
191
192- fprintf(stderr, "Testing %s %s:\n", type, ciphers[id].name);
193+ fprintf(stderr, "Testing %s %s:\n", type, ciphers[id].name);
194+ }
195 }
196 err = ciphers[id].func(fdc, tp);
197
198@@ -340,17 +431,30 @@ int run_test(int id, struct test_params tp)
199 return err;
200 }
201
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)
204 {
205- int i;
206 int err;
207
208- if (tp.nflag) {
209+ if (tp.authflag) {
210+ err = encrypt_auth(fdc, tp, sess);
211+ } else {
212 if (tp.aflag) {
213- encrypt_async(fdc, tp, sess);
214+ err = encrypt_async(fdc, tp, sess);
215 } else {
216- encrypt_sync(fdc, tp, sess);
217+ err = encrypt_sync(fdc, tp, sess);
218 }
219+ }
220+
221+ return err;
222+}
223+
224+void do_test_vectors(int fdc, struct test_params tp, struct session_op *sess)
225+{
226+ int i;
227+ int err;
228+
229+ if (tp.nflag) {
230+ err = start_test(fdc, tp, sess);
231 } else {
232 for (i = 256; i <= (64 * 1024); i *= 2) {
233 if (must_exit) {
234@@ -358,11 +462,7 @@ void do_test_vectors(int fdc, struct test_params tp, struct session_op *sess)
235 }
236
237 tp.nvalue = i;
238- if (tp.aflag) {
239- err = encrypt_async(fdc, tp, sess);
240- } else {
241- err = encrypt_sync(fdc, tp, sess);
242- }
243+ err = start_test(fdc, tp, sess);
244
245 if (err != 0) {
246 break;
247@@ -474,6 +574,30 @@ int run_sha256(int fdc, struct test_params tp)
248 return 0;
249 }
250
251+int run_authenc(int fdc, struct test_params tp)
252+{
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";
259+
260+ memset(&sess, 0, sizeof(sess));
261+ sess.cipher = CRYPTO_AUTHENC_HMAC_SHA1_CBC_AES;
262+ sess.keylen = 16;
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)");
268+ return -EINVAL;
269+ }
270+
271+ do_test_vectors(fdc, tp, &sess);
272+ return 0;
273+}
274+
275 int main(int argc, char **argv)
276 {
277 int err = 0;
278@@ -487,6 +611,7 @@ int main(int argc, char **argv)
279 tp.nflag = false;
280 tp.mflag = false;
281 tp.aflag = false;
282+ tp.authflag = false;
283 alg_flag = false;
284 opterr = 0;
285 while ((c = getopt(argc, argv, "ahn:t:m")) != -1) {
286--
2872.10.2
288