diff options
author | Cristian Stoica <cristian.stoica@nxp.com> | 2016-01-25 11:19:43 +0200 |
---|---|---|
committer | Zhenhua Luo <zhenhua.luo@nxp.com> | 2016-06-23 10:58:51 +0800 |
commit | 41d1478e1294d06f0cce58fe847c0b0f1706b808 (patch) | |
tree | 8c6c5e2887cc30435ee40e764bb2ede58278d0ac /recipes-kernel/cryptodev/sdk_patches/0037-rewrite-sha_speed.c-to-reduce-code-duplication.patch | |
parent | e3956ffbc217e468e26c9ce2e8932d3720fabca4 (diff) | |
download | meta-fsl-ppc-41d1478e1294d06f0cce58fe847c0b0f1706b808.tar.gz |
cryptodev-qoriq: upgrade to 1.8 plus fsl patches
upstream commit: 87b56e04b24c6d4be145483477eff7d3153290e9
Also:
- move all fsl patches on top of cryptodev-1.8
- add CIOCHASH ioctl
- fix incorrect tests initializations
- modify yocto patches to match updated Makefiles
Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com>
Diffstat (limited to 'recipes-kernel/cryptodev/sdk_patches/0037-rewrite-sha_speed.c-to-reduce-code-duplication.patch')
-rw-r--r-- | recipes-kernel/cryptodev/sdk_patches/0037-rewrite-sha_speed.c-to-reduce-code-duplication.patch | 190 |
1 files changed, 190 insertions, 0 deletions
diff --git a/recipes-kernel/cryptodev/sdk_patches/0037-rewrite-sha_speed.c-to-reduce-code-duplication.patch b/recipes-kernel/cryptodev/sdk_patches/0037-rewrite-sha_speed.c-to-reduce-code-duplication.patch new file mode 100644 index 0000000..eff6ed9 --- /dev/null +++ b/recipes-kernel/cryptodev/sdk_patches/0037-rewrite-sha_speed.c-to-reduce-code-duplication.patch | |||
@@ -0,0 +1,190 @@ | |||
1 | From 344a0243e31f8fc467253404a548eedbb72b35d0 Mon Sep 17 00:00:00 2001 | ||
2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
3 | Date: Wed, 20 Jan 2016 17:11:49 +0200 | ||
4 | Subject: [PATCH 37/38] rewrite sha_speed.c to reduce code duplication | ||
5 | |||
6 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
7 | --- | ||
8 | tests/sha_speed.c | 131 ++++++++++++++++++++++++++++++++++-------------------- | ||
9 | 1 file changed, 84 insertions(+), 47 deletions(-) | ||
10 | |||
11 | diff --git a/tests/sha_speed.c b/tests/sha_speed.c | ||
12 | index e1dc54b..5f694bd 100644 | ||
13 | --- a/tests/sha_speed.c | ||
14 | +++ b/tests/sha_speed.c | ||
15 | @@ -28,6 +28,13 @@ | ||
16 | |||
17 | #include <crypto/cryptodev.h> | ||
18 | |||
19 | +/* Sizes of buffers to be hashed */ | ||
20 | +int buffer_lengths[] = {256, 512, 1024, 2048, 4096, 8192, 65536, 0}; | ||
21 | + | ||
22 | +/* Time in seconds allocated for each tested buffer lengths */ | ||
23 | +#define BUFFER_TEST_TIME 10 | ||
24 | + | ||
25 | + | ||
26 | static double udifftimeval(struct timeval start, struct timeval end) | ||
27 | { | ||
28 | return (double)(end.tv_usec - start.tv_usec) + | ||
29 | @@ -97,7 +104,7 @@ int hash_data(struct session_op *sess, int fdc, int chunksize, int alignmask) | ||
30 | memset(buffer, val++, chunksize); | ||
31 | |||
32 | must_finish = 0; | ||
33 | - alarm(5); | ||
34 | + alarm(BUFFER_TEST_TIME); | ||
35 | |||
36 | gettimeofday(&start, NULL); | ||
37 | do { | ||
38 | @@ -126,73 +133,103 @@ int hash_data(struct session_op *sess, int fdc, int chunksize, int alignmask) | ||
39 | return 0; | ||
40 | } | ||
41 | |||
42 | -int main(void) | ||
43 | -{ | ||
44 | - int fd, i, fdc = -1, alignmask = 0; | ||
45 | - struct session_op sess; | ||
46 | - char keybuf[32]; | ||
47 | + | ||
48 | #ifdef CIOCGSESSINFO | ||
49 | +int get_alignmask(struct session_op *sess, int fdc) | ||
50 | +{ | ||
51 | struct session_info_op siop; | ||
52 | + | ||
53 | + siop.ses = sess->ses; | ||
54 | + if (ioctl(fdc, CIOCGSESSINFO, &siop) < 0) { | ||
55 | + perror("ioctl(CIOCGSESSINFO)"); | ||
56 | + /* continue test ignoring CIOCGSESSINFO error */ | ||
57 | + return 0; | ||
58 | + } | ||
59 | + | ||
60 | + printf("using algorithm %s with driver %s\n", | ||
61 | + siop.hash_info.cra_name, siop.hash_info.cra_driver_name); | ||
62 | + | ||
63 | + return siop.alignmask; | ||
64 | +} | ||
65 | #endif | ||
66 | |||
67 | - signal(SIGALRM, alarm_handler); | ||
68 | |||
69 | - if ((fd = open("/dev/crypto", O_RDWR, 0)) < 0) { | ||
70 | - perror("open()"); | ||
71 | - return 1; | ||
72 | - } | ||
73 | - if (ioctl(fd, CRIOGET, &fdc)) { | ||
74 | - perror("ioctl(CRIOGET)"); | ||
75 | - return 1; | ||
76 | - } | ||
77 | +int hash_session(struct session_op *sess, int fdc) | ||
78 | +{ | ||
79 | + int i; | ||
80 | + int err; | ||
81 | + int alignmask; | ||
82 | |||
83 | - fprintf(stderr, "Testing SHA1 Hash: \n"); | ||
84 | - memset(&sess, 0, sizeof(sess)); | ||
85 | - sess.mac = CRYPTO_SHA1; | ||
86 | - if (ioctl(fdc, CIOCGSESSION, &sess)) { | ||
87 | + if (ioctl(fdc, CIOCGSESSION, sess)) { | ||
88 | perror("ioctl(CIOCGSESSION)"); | ||
89 | return 1; | ||
90 | } | ||
91 | + | ||
92 | #ifdef CIOCGSESSINFO | ||
93 | - siop.ses = sess.ses; | ||
94 | - if (ioctl(fdc, CIOCGSESSINFO, &siop)) { | ||
95 | - perror("ioctl(CIOCGSESSINFO)"); | ||
96 | - return 1; | ||
97 | - } | ||
98 | - printf("requested hash CRYPTO_SHA1, got %s with driver %s\n", | ||
99 | - siop.hash_info.cra_name, siop.hash_info.cra_driver_name); | ||
100 | - alignmask = siop.alignmask; | ||
101 | + alignmask = get_alignmask(sess, fdc); | ||
102 | +#else | ||
103 | + alignmask = 0; | ||
104 | #endif | ||
105 | |||
106 | - for (i = 256; i <= (64 * 1024); i *= 4) { | ||
107 | - if (hash_data(&sess, fdc, i, alignmask)) | ||
108 | - break; | ||
109 | + err = 0; | ||
110 | + for(i = 0; (err == 0) && (buffer_lengths[i] != 0); i++) { | ||
111 | + err = hash_data(sess, fdc, buffer_lengths[i], alignmask); | ||
112 | } | ||
113 | |||
114 | - fprintf(stderr, "\nTesting SHA256 Hash: \n"); | ||
115 | - memset(&sess, 0, sizeof(sess)); | ||
116 | - sess.mac = CRYPTO_SHA2_256; | ||
117 | - if (ioctl(fdc, CIOCGSESSION, &sess)) { | ||
118 | - perror("ioctl(CIOCGSESSION)"); | ||
119 | + if (ioctl(fdc, CIOCFSESSION, sess)) { | ||
120 | + perror("ioctl(CIOCFSESSION)"); | ||
121 | return 1; | ||
122 | } | ||
123 | -#ifdef CIOCGSESSINFO | ||
124 | - siop.ses = sess.ses; | ||
125 | - if (ioctl(fdc, CIOCGSESSINFO, &siop)) { | ||
126 | - perror("ioctl(CIOCGSESSINFO)"); | ||
127 | + | ||
128 | + return err; | ||
129 | +} | ||
130 | + | ||
131 | +int test_sha1(struct session_op *sess, int fdc) | ||
132 | +{ | ||
133 | + fprintf(stderr, "Testing SHA1 Hash: \n"); | ||
134 | + memset(sess, 0, sizeof(sess)); | ||
135 | + sess->mac = CRYPTO_SHA1; | ||
136 | + return hash_session(sess, fdc); | ||
137 | +} | ||
138 | + | ||
139 | + | ||
140 | +int test_sha256(struct session_op *sess, int fdc) | ||
141 | +{ | ||
142 | + fprintf(stderr, "Testing SHA256 Hash: \n"); | ||
143 | + memset(sess, 0, sizeof(sess)); | ||
144 | + sess->mac = CRYPTO_SHA2_256; | ||
145 | + return hash_session(sess, fdc); | ||
146 | +} | ||
147 | + | ||
148 | + | ||
149 | +int main(void) | ||
150 | +{ | ||
151 | + int fd; | ||
152 | + int fdc; | ||
153 | + int err; | ||
154 | + int i; | ||
155 | + struct session_op sess; | ||
156 | + | ||
157 | + signal(SIGALRM, alarm_handler); | ||
158 | + | ||
159 | + fd = open("/dev/crypto", O_RDWR, 0); | ||
160 | + if (fd < 0) { | ||
161 | + perror("open()"); | ||
162 | return 1; | ||
163 | } | ||
164 | - printf("requested hash CRYPTO_SHA2_256, got %s with driver %s\n", | ||
165 | - siop.hash_info.cra_name, siop.hash_info.cra_driver_name); | ||
166 | - alignmask = siop.alignmask; | ||
167 | -#endif | ||
168 | |||
169 | - for (i = 256; i <= (64 * 1024); i *= 4) { | ||
170 | - if (hash_data(&sess, fdc, i, alignmask)) | ||
171 | - break; | ||
172 | + err = ioctl(fd, CRIOGET, &fdc); | ||
173 | + if (err != 0) { | ||
174 | + perror("ioctl(CRIOGET)"); | ||
175 | + close(fd); | ||
176 | + return 1; | ||
177 | } | ||
178 | |||
179 | + /* run all tests but return an eventual error */ | ||
180 | + err |= test_sha1(&sess, fdc); | ||
181 | + err |= test_sha256(&sess, fdc); | ||
182 | + | ||
183 | close(fdc); | ||
184 | close(fd); | ||
185 | - return 0; | ||
186 | + return err; | ||
187 | } | ||
188 | -- | ||
189 | 2.7.0 | ||
190 | |||