aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-kernel/cryptodev/sdk_patches/0096-use-buf_align-macro-to-reduce-code-duplication.patch
blob: 83d0be12a8ee5bad14529b237c4080bd37447d5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
From 6f4589ae57d141ea6257ae16df1709781d0fb8e4 Mon Sep 17 00:00:00 2001
From: Cristian Stoica <cristian.stoica@nxp.com>
Date: Tue, 29 Nov 2016 13:37:22 +0200
Subject: [PATCH 096/104] use buf_align macro to reduce code duplication

Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com>
---
 tests/async_cipher.c     |  9 +++++----
 tests/cipher-aead-srtp.c | 13 +++++++------
 tests/cipher-aead.c      | 13 +++++++------
 tests/cipher-gcm.c       | 17 +++++------------
 tests/cipher.c           |  9 +++++----
 tests/testhelper.h       |  9 +++++++++
 6 files changed, 38 insertions(+), 32 deletions(-)
 create mode 100644 tests/testhelper.h

diff --git a/tests/async_cipher.c b/tests/async_cipher.c
index db6fb06..7a184e5 100644
--- a/tests/async_cipher.c
+++ b/tests/async_cipher.c
@@ -14,6 +14,7 @@
 #include <crypto/cryptodev.h>
 
 #include "asynchelper.h"
+#include "testhelper.h"
 
 #ifdef ENABLE_ASYNC
 
@@ -62,8 +63,8 @@ test_crypto(int cfd)
 		perror("ioctl(CIOCGSESSINFO)");
 		return 1;
 	}
-	plaintext = (uint8_t *)(((unsigned long)plaintext_raw + siop.alignmask) & ~siop.alignmask);
-	ciphertext = (uint8_t *)(((unsigned long)ciphertext_raw + siop.alignmask) & ~siop.alignmask);
+	plaintext = buf_align(plaintext_raw, siop.alignmask);
+	ciphertext = buf_align(ciphertext_raw, siop.alignmask);
 #else
 	plaintext = plaintext_raw;
 	ciphertext = ciphertext_raw;
@@ -162,7 +163,7 @@ static int test_aes(int cfd)
 		perror("ioctl(CIOCGSESSINFO)");
 		return 1;
 	}
-	plaintext1 = (uint8_t *)(((unsigned long)plaintext1_raw + siop1.alignmask) & ~siop1.alignmask);
+	plaintext1 = buf_align(plaintext1_raw, siop1.alignmask);
 #else
 	plaintext1 = plaintext1_raw;
 #endif
@@ -185,7 +186,7 @@ static int test_aes(int cfd)
 		perror("ioctl(CIOCGSESSINFO)");
 		return 1;
 	}
-	plaintext2 = (uint8_t *)(((unsigned long)plaintext2_raw + siop2.alignmask) & ~siop2.alignmask);
+	plaintext2 = buf_align(plaintext2_raw, siop2.alignmask);
 #else
 	plaintext2 = plaintext2_raw;
 #endif
diff --git a/tests/cipher-aead-srtp.c b/tests/cipher-aead-srtp.c
index c44877d..578d2f7 100644
--- a/tests/cipher-aead-srtp.c
+++ b/tests/cipher-aead-srtp.c
@@ -12,6 +12,7 @@
 
 #include <sys/ioctl.h>
 #include <crypto/cryptodev.h>
+#include "testhelper.h"
 
 #define	DATA_SIZE	(8*1024)
 #define HEADER_SIZE 193
@@ -122,8 +123,8 @@ test_crypto(int cfd)
 		printf("requested cipher CRYPTO_AES_CBC/HMAC-SHA1, got %s with driver %s\n",
 			siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name);
 
-	plaintext = (uint8_t *)(((unsigned long)plaintext_raw + siop.alignmask) & ~siop.alignmask);
-	ciphertext = (uint8_t *)(((unsigned long)ciphertext_raw + siop.alignmask) & ~siop.alignmask);
+	plaintext = buf_align(plaintext_raw, siop.alignmask);
+	ciphertext = buf_align(ciphertext_raw, siop.alignmask);
 
 	memset(plaintext, 0x15, HEADER_SIZE); /* header */
 	memset(&plaintext[HEADER_SIZE], 0x17, PLAINTEXT_SIZE); /* payload */
@@ -265,8 +266,8 @@ test_encrypt_decrypt(int cfd)
 //	printf("requested cipher CRYPTO_AES_CBC/HMAC-SHA1, got %s with driver %s\n",
 //			siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name);
 
-	plaintext = (uint8_t *)(((unsigned long)plaintext_raw + siop.alignmask) & ~siop.alignmask);
-	ciphertext = (uint8_t *)(((unsigned long)ciphertext_raw + siop.alignmask) & ~siop.alignmask);
+	plaintext = buf_align(plaintext_raw, siop.alignmask);
+	ciphertext = buf_align(ciphertext_raw, siop.alignmask);
 
 	memset(plaintext, 0x15, HEADER_SIZE); /* header */
 	memset(&plaintext[HEADER_SIZE], 0x17, PLAINTEXT_SIZE); /* payload */
@@ -407,8 +408,8 @@ test_encrypt_decrypt_error(int cfd, int err)
 //	printf("requested cipher CRYPTO_AES_CBC/HMAC-SHA1, got %s with driver %s\n",
 //			siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name);
 
-	plaintext = (uint8_t *)(((unsigned long)plaintext_raw + siop.alignmask) & ~siop.alignmask);
-	ciphertext = (uint8_t *)(((unsigned long)ciphertext_raw + siop.alignmask) & ~siop.alignmask);
+	plaintext = buf_align(plaintext_raw, siop.alignmask);
+	ciphertext = buf_align(ciphertext_raw, siop.alignmask);
 
 	memset(plaintext, 0x15, HEADER_SIZE); /* header */
 	memset(&plaintext[HEADER_SIZE], 0x17, PLAINTEXT_SIZE); /* payload */
diff --git a/tests/cipher-aead.c b/tests/cipher-aead.c
index da43aa6..b329d12 100644
--- a/tests/cipher-aead.c
+++ b/tests/cipher-aead.c
@@ -12,6 +12,7 @@
 
 #include <sys/ioctl.h>
 #include <crypto/cryptodev.h>
+#include "testhelper.h"
 
 #define	DATA_SIZE	(8*1024)
 #define AUTH_SIZE       31
@@ -133,8 +134,8 @@ test_crypto(int cfd)
 		printf("requested cipher CRYPTO_AES_CBC/HMAC-SHA1, got %s with driver %s\n",
 			siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name);
 
-	plaintext = (uint8_t *)(((unsigned long)plaintext_raw + siop.alignmask) & ~siop.alignmask);
-	ciphertext = (uint8_t *)(((unsigned long)ciphertext_raw + siop.alignmask) & ~siop.alignmask);
+	plaintext = buf_align(plaintext_raw, siop.alignmask);
+	ciphertext = buf_align(ciphertext_raw, siop.alignmask);
 	memset(plaintext, 0x15, DATA_SIZE);
 
 	if (get_sha1_hmac(cfd, sess.mackey, sess.mackeylen, auth, sizeof(auth), plaintext, DATA_SIZE, sha1mac) != 0) {
@@ -285,8 +286,8 @@ test_encrypt_decrypt(int cfd)
 //	printf("requested cipher CRYPTO_AES_CBC/HMAC-SHA1, got %s with driver %s\n",
 //			siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name);
 
-	plaintext = (uint8_t *)(((unsigned long)plaintext_raw + siop.alignmask) & ~siop.alignmask);
-	ciphertext = (uint8_t *)(((unsigned long)ciphertext_raw + siop.alignmask) & ~siop.alignmask);
+	plaintext = buf_align(plaintext_raw, siop.alignmask);
+	ciphertext = buf_align(ciphertext_raw, siop.alignmask);
 
 	memset(plaintext, 0x15, DATA_SIZE);
 
@@ -434,8 +435,8 @@ test_encrypt_decrypt_error(int cfd, int err)
 //	printf("requested cipher CRYPTO_AES_CBC/HMAC-SHA1, got %s with driver %s\n",
 //			siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name);
 
-	plaintext = (uint8_t *)(((unsigned long)plaintext_raw + siop.alignmask) & ~siop.alignmask);
-	ciphertext = (uint8_t *)(((unsigned long)ciphertext_raw + siop.alignmask) & ~siop.alignmask);
+	plaintext = buf_align(plaintext_raw, siop.alignmask);
+	ciphertext = buf_align(ciphertext_raw, siop.alignmask);
 	memset(plaintext, 0x15, DATA_SIZE);
 
 	if (get_sha1_hmac(cfd, sess.mackey, sess.mackeylen, auth, sizeof(auth), plaintext, DATA_SIZE, sha1mac) != 0) {
diff --git a/tests/cipher-gcm.c b/tests/cipher-gcm.c
index 3f6cc7b..d5f8486 100644
--- a/tests/cipher-gcm.c
+++ b/tests/cipher-gcm.c
@@ -12,6 +12,7 @@
 
 #include <sys/ioctl.h>
 #include <crypto/cryptodev.h>
+#include "testhelper.h"
 
 #define	DATA_SIZE	(8*1024)
 #define AUTH_SIZE       31
@@ -232,12 +233,8 @@ static int test_encrypt_decrypt(int cfd)
 //      printf("requested cipher CRYPTO_AES_CBC/HMAC-SHA1, got %s with driver %s\n",
 //                      siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name);
 
-	plaintext =
-	    (uint8_t *) (((unsigned long) plaintext_raw + siop.alignmask) &
-		      ~siop.alignmask);
-	ciphertext =
-	    (uint8_t *) (((unsigned long) ciphertext_raw + siop.alignmask) &
-		      ~siop.alignmask);
+	plaintext = (__u8 *)buf_align(plaintext_raw, siop.alignmask);
+	ciphertext = (__u8 *)buf_align(ciphertext_raw, siop.alignmask);
 
 	memset(plaintext, 0x15, DATA_SIZE);
 
@@ -385,12 +382,8 @@ static int test_encrypt_decrypt_error(int cfd, int err)
 //      printf("requested cipher CRYPTO_AES_CBC/HMAC-SHA1, got %s with driver %s\n",
 //                      siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name);
 
-	plaintext =
-	    (uint8_t *) (((unsigned long) plaintext_raw + siop.alignmask) &
-		      ~siop.alignmask);
-	ciphertext =
-	    (uint8_t *) (((unsigned long) ciphertext_raw + siop.alignmask) &
-		      ~siop.alignmask);
+	plaintext = (__u8 *)buf_align(plaintext_raw, siop.alignmask);
+	ciphertext = (__u8 *)buf_align(ciphertext_raw, siop.alignmask);
 
 	memset(plaintext, 0x15, DATA_SIZE);
 	memcpy(ciphertext, plaintext, DATA_SIZE);
diff --git a/tests/cipher.c b/tests/cipher.c
index f3ca2f0..222f095 100644
--- a/tests/cipher.c
+++ b/tests/cipher.c
@@ -12,6 +12,7 @@
 
 #include <sys/ioctl.h>
 #include <crypto/cryptodev.h>
+#include "testhelper.h"
 
 static int debug = 0;
 
@@ -58,8 +59,8 @@ test_crypto(int cfd)
 		printf("requested cipher CRYPTO_AES_CBC, got %s with driver %s\n",
 			siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name);
 
-	plaintext = (uint8_t *)(((unsigned long)plaintext_raw + siop.alignmask) & ~siop.alignmask);
-	ciphertext = (uint8_t *)(((unsigned long)ciphertext_raw + siop.alignmask) & ~siop.alignmask);
+	plaintext = buf_align(plaintext_raw, siop.alignmask);
+	ciphertext = buf_align(ciphertext_raw, siop.alignmask);
 #else
 	plaintext = plaintext_raw;
 	ciphertext = ciphertext_raw;
@@ -177,7 +178,7 @@ static int test_aes(int cfd)
 		perror("ioctl(CIOCGSESSINFO)");
 		return 1;
 	}
-	plaintext1 = (uint8_t *)(((unsigned long)plaintext1_raw + siop.alignmask) & ~siop.alignmask);
+	plaintext1 = buf_align(plaintext1_raw, siop.alignmask);
 #else
 	plaintext1 = plaintext1_raw;
 #endif
@@ -227,7 +228,7 @@ static int test_aes(int cfd)
 		printf("requested cipher CRYPTO_AES_CBC, got %s with driver %s\n",
 			siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name);
 
-	plaintext2 = (uint8_t *)(((unsigned long)plaintext2_raw + siop.alignmask) & ~siop.alignmask);
+	plaintext2 = buf_align(plaintext2_raw, siop.alignmask);
 #else
 	plaintext2 = plaintext2_raw;
 #endif
diff --git a/tests/testhelper.h b/tests/testhelper.h
new file mode 100644
index 0000000..800d10d
--- /dev/null
+++ b/tests/testhelper.h
@@ -0,0 +1,9 @@
+/*
+ * Some helper stuff shared between the sample programs.
+ */
+#ifndef __TESTHELPER_H
+#define __TESTHELPER_H
+
+#define buf_align(buf, align) (void *)(((unsigned long)(buf) + (align)) & ~(align))
+
+#endif /* __TESTHELPER_H */
-- 
2.10.2