aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-kernel/cryptodev/sdk_patches/0096-use-buf_align-macro-to-reduce-code-duplication.patch
diff options
context:
space:
mode:
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.patch248
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 00000000..83d0be12
--- /dev/null
+++ b/recipes-kernel/cryptodev/sdk_patches/0096-use-buf_align-macro-to-reduce-code-duplication.patch
@@ -0,0 +1,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
+