Signed-off-by: Cristian Stoica <[email protected]>
---
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 ebddc85..273a471 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 = (char *)(((unsigned long)plaintext_raw + siop.alignmask) &
~siop.alignmask);
- ciphertext = (char *)(((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 = (char *)(((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 = (char *)(((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 fae04e7..75fb825 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 = (char *)(((unsigned long)plaintext_raw + siop.alignmask) &
~siop.alignmask);
- ciphertext = (char *)(((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 = (char *)(((unsigned long)plaintext_raw + siop.alignmask) &
~siop.alignmask);
- ciphertext = (char *)(((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 = (char *)(((unsigned long)plaintext_raw + siop.alignmask) &
~siop.alignmask);
- ciphertext = (char *)(((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 164327f..837b521 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 = (char *)(((unsigned long)plaintext_raw + siop.alignmask) &
~siop.alignmask);
- ciphertext = (char *)(((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 = (char *)(((unsigned long)plaintext_raw + siop.alignmask) &
~siop.alignmask);
- ciphertext = (char *)(((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 = (char *)(((unsigned long)plaintext_raw + siop.alignmask) &
~siop.alignmask);
- ciphertext = (char *)(((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 dfc3d84..e444afa 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 =
- (char *) (((unsigned long) plaintext_raw + siop.alignmask) &
- ~siop.alignmask);
- ciphertext =
- (char *) (((unsigned long) ciphertext_raw + siop.alignmask) &
- ~siop.alignmask);
+ plaintext = (char *)buf_align(plaintext_raw, siop.alignmask);
+ ciphertext = (char *)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 =
- (char *) (((unsigned long) plaintext_raw + siop.alignmask) &
- ~siop.alignmask);
- ciphertext =
- (char *) (((unsigned long) ciphertext_raw + siop.alignmask) &
- ~siop.alignmask);
+ plaintext = (char *)buf_align(plaintext_raw, siop.alignmask);
+ ciphertext = (char *)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 07144f2..7248404 100644
--- a/tests/cipher.c
+++ b/tests/cipher.c
@@ -11,6 +11,7 @@
#include <sys/ioctl.h>
#include <crypto/cryptodev.h>
+#include "testhelper.h"
static int debug = 0;
@@ -57,8 +58,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 = (char *)(((unsigned long)plaintext_raw + siop.alignmask) &
~siop.alignmask);
- ciphertext = (char *)(((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;
@@ -176,7 +177,7 @@ static int test_aes(int cfd)
perror("ioctl(CIOCGSESSINFO)");
return 1;
}
- plaintext1 = (char *)(((unsigned long)plaintext1_raw + siop.alignmask)
& ~siop.alignmask);
+ plaintext1 = buf_align(plaintext1_raw, siop.alignmask);
#else
plaintext1 = plaintext1_raw;
#endif
@@ -226,7 +227,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 = (char *)(((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.7.3
_______________________________________________
Cryptodev-linux-devel mailing list
[email protected]
https://mail.gna.org/listinfo/cryptodev-linux-devel