diff options
Diffstat (limited to 'recipes-kernel/cryptodev/sdk_patches/0096-use-buf_align-macro-to-reduce-code-duplication.patch')
| -rw-r--r-- | recipes-kernel/cryptodev/sdk_patches/0096-use-buf_align-macro-to-reduce-code-duplication.patch | 248 |
1 files changed, 248 insertions, 0 deletions
diff --git a/recipes-kernel/cryptodev/sdk_patches/0096-use-buf_align-macro-to-reduce-code-duplication.patch b/recipes-kernel/cryptodev/sdk_patches/0096-use-buf_align-macro-to-reduce-code-duplication.patch new file mode 100644 index 000000000..83d0be12a --- /dev/null +++ b/recipes-kernel/cryptodev/sdk_patches/0096-use-buf_align-macro-to-reduce-code-duplication.patch | |||
| @@ -0,0 +1,248 @@ | |||
| 1 | From 6f4589ae57d141ea6257ae16df1709781d0fb8e4 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Tue, 29 Nov 2016 13:37:22 +0200 | ||
| 4 | Subject: [PATCH 096/104] use buf_align macro to reduce code duplication | ||
| 5 | |||
| 6 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 7 | --- | ||
| 8 | tests/async_cipher.c | 9 +++++---- | ||
| 9 | tests/cipher-aead-srtp.c | 13 +++++++------ | ||
| 10 | tests/cipher-aead.c | 13 +++++++------ | ||
| 11 | tests/cipher-gcm.c | 17 +++++------------ | ||
| 12 | tests/cipher.c | 9 +++++---- | ||
| 13 | tests/testhelper.h | 9 +++++++++ | ||
| 14 | 6 files changed, 38 insertions(+), 32 deletions(-) | ||
| 15 | create mode 100644 tests/testhelper.h | ||
| 16 | |||
| 17 | diff --git a/tests/async_cipher.c b/tests/async_cipher.c | ||
| 18 | index db6fb06..7a184e5 100644 | ||
| 19 | --- a/tests/async_cipher.c | ||
| 20 | +++ b/tests/async_cipher.c | ||
| 21 | @@ -14,6 +14,7 @@ | ||
| 22 | #include <crypto/cryptodev.h> | ||
| 23 | |||
| 24 | #include "asynchelper.h" | ||
| 25 | +#include "testhelper.h" | ||
| 26 | |||
| 27 | #ifdef ENABLE_ASYNC | ||
| 28 | |||
| 29 | @@ -62,8 +63,8 @@ test_crypto(int cfd) | ||
| 30 | perror("ioctl(CIOCGSESSINFO)"); | ||
| 31 | return 1; | ||
| 32 | } | ||
| 33 | - plaintext = (uint8_t *)(((unsigned long)plaintext_raw + siop.alignmask) & ~siop.alignmask); | ||
| 34 | - ciphertext = (uint8_t *)(((unsigned long)ciphertext_raw + siop.alignmask) & ~siop.alignmask); | ||
| 35 | + plaintext = buf_align(plaintext_raw, siop.alignmask); | ||
| 36 | + ciphertext = buf_align(ciphertext_raw, siop.alignmask); | ||
| 37 | #else | ||
| 38 | plaintext = plaintext_raw; | ||
| 39 | ciphertext = ciphertext_raw; | ||
| 40 | @@ -162,7 +163,7 @@ static int test_aes(int cfd) | ||
| 41 | perror("ioctl(CIOCGSESSINFO)"); | ||
| 42 | return 1; | ||
| 43 | } | ||
| 44 | - plaintext1 = (uint8_t *)(((unsigned long)plaintext1_raw + siop1.alignmask) & ~siop1.alignmask); | ||
| 45 | + plaintext1 = buf_align(plaintext1_raw, siop1.alignmask); | ||
| 46 | #else | ||
| 47 | plaintext1 = plaintext1_raw; | ||
| 48 | #endif | ||
| 49 | @@ -185,7 +186,7 @@ static int test_aes(int cfd) | ||
| 50 | perror("ioctl(CIOCGSESSINFO)"); | ||
| 51 | return 1; | ||
| 52 | } | ||
| 53 | - plaintext2 = (uint8_t *)(((unsigned long)plaintext2_raw + siop2.alignmask) & ~siop2.alignmask); | ||
| 54 | + plaintext2 = buf_align(plaintext2_raw, siop2.alignmask); | ||
| 55 | #else | ||
| 56 | plaintext2 = plaintext2_raw; | ||
| 57 | #endif | ||
| 58 | diff --git a/tests/cipher-aead-srtp.c b/tests/cipher-aead-srtp.c | ||
| 59 | index c44877d..578d2f7 100644 | ||
| 60 | --- a/tests/cipher-aead-srtp.c | ||
| 61 | +++ b/tests/cipher-aead-srtp.c | ||
| 62 | @@ -12,6 +12,7 @@ | ||
| 63 | |||
| 64 | #include <sys/ioctl.h> | ||
| 65 | #include <crypto/cryptodev.h> | ||
| 66 | +#include "testhelper.h" | ||
| 67 | |||
| 68 | #define DATA_SIZE (8*1024) | ||
| 69 | #define HEADER_SIZE 193 | ||
| 70 | @@ -122,8 +123,8 @@ test_crypto(int cfd) | ||
| 71 | printf("requested cipher CRYPTO_AES_CBC/HMAC-SHA1, got %s with driver %s\n", | ||
| 72 | siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name); | ||
| 73 | |||
| 74 | - plaintext = (uint8_t *)(((unsigned long)plaintext_raw + siop.alignmask) & ~siop.alignmask); | ||
| 75 | - ciphertext = (uint8_t *)(((unsigned long)ciphertext_raw + siop.alignmask) & ~siop.alignmask); | ||
| 76 | + plaintext = buf_align(plaintext_raw, siop.alignmask); | ||
| 77 | + ciphertext = buf_align(ciphertext_raw, siop.alignmask); | ||
| 78 | |||
| 79 | memset(plaintext, 0x15, HEADER_SIZE); /* header */ | ||
| 80 | memset(&plaintext[HEADER_SIZE], 0x17, PLAINTEXT_SIZE); /* payload */ | ||
| 81 | @@ -265,8 +266,8 @@ test_encrypt_decrypt(int cfd) | ||
| 82 | // printf("requested cipher CRYPTO_AES_CBC/HMAC-SHA1, got %s with driver %s\n", | ||
| 83 | // siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name); | ||
| 84 | |||
| 85 | - plaintext = (uint8_t *)(((unsigned long)plaintext_raw + siop.alignmask) & ~siop.alignmask); | ||
| 86 | - ciphertext = (uint8_t *)(((unsigned long)ciphertext_raw + siop.alignmask) & ~siop.alignmask); | ||
| 87 | + plaintext = buf_align(plaintext_raw, siop.alignmask); | ||
| 88 | + ciphertext = buf_align(ciphertext_raw, siop.alignmask); | ||
| 89 | |||
| 90 | memset(plaintext, 0x15, HEADER_SIZE); /* header */ | ||
| 91 | memset(&plaintext[HEADER_SIZE], 0x17, PLAINTEXT_SIZE); /* payload */ | ||
| 92 | @@ -407,8 +408,8 @@ test_encrypt_decrypt_error(int cfd, int err) | ||
| 93 | // printf("requested cipher CRYPTO_AES_CBC/HMAC-SHA1, got %s with driver %s\n", | ||
| 94 | // siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name); | ||
| 95 | |||
| 96 | - plaintext = (uint8_t *)(((unsigned long)plaintext_raw + siop.alignmask) & ~siop.alignmask); | ||
| 97 | - ciphertext = (uint8_t *)(((unsigned long)ciphertext_raw + siop.alignmask) & ~siop.alignmask); | ||
| 98 | + plaintext = buf_align(plaintext_raw, siop.alignmask); | ||
| 99 | + ciphertext = buf_align(ciphertext_raw, siop.alignmask); | ||
| 100 | |||
| 101 | memset(plaintext, 0x15, HEADER_SIZE); /* header */ | ||
| 102 | memset(&plaintext[HEADER_SIZE], 0x17, PLAINTEXT_SIZE); /* payload */ | ||
| 103 | diff --git a/tests/cipher-aead.c b/tests/cipher-aead.c | ||
| 104 | index da43aa6..b329d12 100644 | ||
| 105 | --- a/tests/cipher-aead.c | ||
| 106 | +++ b/tests/cipher-aead.c | ||
| 107 | @@ -12,6 +12,7 @@ | ||
| 108 | |||
| 109 | #include <sys/ioctl.h> | ||
| 110 | #include <crypto/cryptodev.h> | ||
| 111 | +#include "testhelper.h" | ||
| 112 | |||
| 113 | #define DATA_SIZE (8*1024) | ||
| 114 | #define AUTH_SIZE 31 | ||
| 115 | @@ -133,8 +134,8 @@ test_crypto(int cfd) | ||
| 116 | printf("requested cipher CRYPTO_AES_CBC/HMAC-SHA1, got %s with driver %s\n", | ||
| 117 | siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name); | ||
| 118 | |||
| 119 | - plaintext = (uint8_t *)(((unsigned long)plaintext_raw + siop.alignmask) & ~siop.alignmask); | ||
| 120 | - ciphertext = (uint8_t *)(((unsigned long)ciphertext_raw + siop.alignmask) & ~siop.alignmask); | ||
| 121 | + plaintext = buf_align(plaintext_raw, siop.alignmask); | ||
| 122 | + ciphertext = buf_align(ciphertext_raw, siop.alignmask); | ||
| 123 | memset(plaintext, 0x15, DATA_SIZE); | ||
| 124 | |||
| 125 | if (get_sha1_hmac(cfd, sess.mackey, sess.mackeylen, auth, sizeof(auth), plaintext, DATA_SIZE, sha1mac) != 0) { | ||
| 126 | @@ -285,8 +286,8 @@ test_encrypt_decrypt(int cfd) | ||
| 127 | // printf("requested cipher CRYPTO_AES_CBC/HMAC-SHA1, got %s with driver %s\n", | ||
| 128 | // siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name); | ||
| 129 | |||
| 130 | - plaintext = (uint8_t *)(((unsigned long)plaintext_raw + siop.alignmask) & ~siop.alignmask); | ||
| 131 | - ciphertext = (uint8_t *)(((unsigned long)ciphertext_raw + siop.alignmask) & ~siop.alignmask); | ||
| 132 | + plaintext = buf_align(plaintext_raw, siop.alignmask); | ||
| 133 | + ciphertext = buf_align(ciphertext_raw, siop.alignmask); | ||
| 134 | |||
| 135 | memset(plaintext, 0x15, DATA_SIZE); | ||
| 136 | |||
| 137 | @@ -434,8 +435,8 @@ test_encrypt_decrypt_error(int cfd, int err) | ||
| 138 | // printf("requested cipher CRYPTO_AES_CBC/HMAC-SHA1, got %s with driver %s\n", | ||
| 139 | // siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name); | ||
| 140 | |||
| 141 | - plaintext = (uint8_t *)(((unsigned long)plaintext_raw + siop.alignmask) & ~siop.alignmask); | ||
| 142 | - ciphertext = (uint8_t *)(((unsigned long)ciphertext_raw + siop.alignmask) & ~siop.alignmask); | ||
| 143 | + plaintext = buf_align(plaintext_raw, siop.alignmask); | ||
| 144 | + ciphertext = buf_align(ciphertext_raw, siop.alignmask); | ||
| 145 | memset(plaintext, 0x15, DATA_SIZE); | ||
| 146 | |||
| 147 | if (get_sha1_hmac(cfd, sess.mackey, sess.mackeylen, auth, sizeof(auth), plaintext, DATA_SIZE, sha1mac) != 0) { | ||
| 148 | diff --git a/tests/cipher-gcm.c b/tests/cipher-gcm.c | ||
| 149 | index 3f6cc7b..d5f8486 100644 | ||
| 150 | --- a/tests/cipher-gcm.c | ||
| 151 | +++ b/tests/cipher-gcm.c | ||
| 152 | @@ -12,6 +12,7 @@ | ||
| 153 | |||
| 154 | #include <sys/ioctl.h> | ||
| 155 | #include <crypto/cryptodev.h> | ||
| 156 | +#include "testhelper.h" | ||
| 157 | |||
| 158 | #define DATA_SIZE (8*1024) | ||
| 159 | #define AUTH_SIZE 31 | ||
| 160 | @@ -232,12 +233,8 @@ static int test_encrypt_decrypt(int cfd) | ||
| 161 | // printf("requested cipher CRYPTO_AES_CBC/HMAC-SHA1, got %s with driver %s\n", | ||
| 162 | // siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name); | ||
| 163 | |||
| 164 | - plaintext = | ||
| 165 | - (uint8_t *) (((unsigned long) plaintext_raw + siop.alignmask) & | ||
| 166 | - ~siop.alignmask); | ||
| 167 | - ciphertext = | ||
| 168 | - (uint8_t *) (((unsigned long) ciphertext_raw + siop.alignmask) & | ||
| 169 | - ~siop.alignmask); | ||
| 170 | + plaintext = (__u8 *)buf_align(plaintext_raw, siop.alignmask); | ||
| 171 | + ciphertext = (__u8 *)buf_align(ciphertext_raw, siop.alignmask); | ||
| 172 | |||
| 173 | memset(plaintext, 0x15, DATA_SIZE); | ||
| 174 | |||
| 175 | @@ -385,12 +382,8 @@ static int test_encrypt_decrypt_error(int cfd, int err) | ||
| 176 | // printf("requested cipher CRYPTO_AES_CBC/HMAC-SHA1, got %s with driver %s\n", | ||
| 177 | // siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name); | ||
| 178 | |||
| 179 | - plaintext = | ||
| 180 | - (uint8_t *) (((unsigned long) plaintext_raw + siop.alignmask) & | ||
| 181 | - ~siop.alignmask); | ||
| 182 | - ciphertext = | ||
| 183 | - (uint8_t *) (((unsigned long) ciphertext_raw + siop.alignmask) & | ||
| 184 | - ~siop.alignmask); | ||
| 185 | + plaintext = (__u8 *)buf_align(plaintext_raw, siop.alignmask); | ||
| 186 | + ciphertext = (__u8 *)buf_align(ciphertext_raw, siop.alignmask); | ||
| 187 | |||
| 188 | memset(plaintext, 0x15, DATA_SIZE); | ||
| 189 | memcpy(ciphertext, plaintext, DATA_SIZE); | ||
| 190 | diff --git a/tests/cipher.c b/tests/cipher.c | ||
| 191 | index f3ca2f0..222f095 100644 | ||
| 192 | --- a/tests/cipher.c | ||
| 193 | +++ b/tests/cipher.c | ||
| 194 | @@ -12,6 +12,7 @@ | ||
| 195 | |||
| 196 | #include <sys/ioctl.h> | ||
| 197 | #include <crypto/cryptodev.h> | ||
| 198 | +#include "testhelper.h" | ||
| 199 | |||
| 200 | static int debug = 0; | ||
| 201 | |||
| 202 | @@ -58,8 +59,8 @@ test_crypto(int cfd) | ||
| 203 | printf("requested cipher CRYPTO_AES_CBC, got %s with driver %s\n", | ||
| 204 | siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name); | ||
| 205 | |||
| 206 | - plaintext = (uint8_t *)(((unsigned long)plaintext_raw + siop.alignmask) & ~siop.alignmask); | ||
| 207 | - ciphertext = (uint8_t *)(((unsigned long)ciphertext_raw + siop.alignmask) & ~siop.alignmask); | ||
| 208 | + plaintext = buf_align(plaintext_raw, siop.alignmask); | ||
| 209 | + ciphertext = buf_align(ciphertext_raw, siop.alignmask); | ||
| 210 | #else | ||
| 211 | plaintext = plaintext_raw; | ||
| 212 | ciphertext = ciphertext_raw; | ||
| 213 | @@ -177,7 +178,7 @@ static int test_aes(int cfd) | ||
| 214 | perror("ioctl(CIOCGSESSINFO)"); | ||
| 215 | return 1; | ||
| 216 | } | ||
| 217 | - plaintext1 = (uint8_t *)(((unsigned long)plaintext1_raw + siop.alignmask) & ~siop.alignmask); | ||
| 218 | + plaintext1 = buf_align(plaintext1_raw, siop.alignmask); | ||
| 219 | #else | ||
| 220 | plaintext1 = plaintext1_raw; | ||
| 221 | #endif | ||
| 222 | @@ -227,7 +228,7 @@ static int test_aes(int cfd) | ||
| 223 | printf("requested cipher CRYPTO_AES_CBC, got %s with driver %s\n", | ||
| 224 | siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name); | ||
| 225 | |||
| 226 | - plaintext2 = (uint8_t *)(((unsigned long)plaintext2_raw + siop.alignmask) & ~siop.alignmask); | ||
| 227 | + plaintext2 = buf_align(plaintext2_raw, siop.alignmask); | ||
| 228 | #else | ||
| 229 | plaintext2 = plaintext2_raw; | ||
| 230 | #endif | ||
| 231 | diff --git a/tests/testhelper.h b/tests/testhelper.h | ||
| 232 | new file mode 100644 | ||
| 233 | index 0000000..800d10d | ||
| 234 | --- /dev/null | ||
| 235 | +++ b/tests/testhelper.h | ||
| 236 | @@ -0,0 +1,9 @@ | ||
| 237 | +/* | ||
| 238 | + * Some helper stuff shared between the sample programs. | ||
| 239 | + */ | ||
| 240 | +#ifndef __TESTHELPER_H | ||
| 241 | +#define __TESTHELPER_H | ||
| 242 | + | ||
| 243 | +#define buf_align(buf, align) (void *)(((unsigned long)(buf) + (align)) & ~(align)) | ||
| 244 | + | ||
| 245 | +#endif /* __TESTHELPER_H */ | ||
| 246 | -- | ||
| 247 | 2.10.2 | ||
| 248 | |||
