Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

crypto: tcrypt - randomize speed test memory

Running speed tests on uniform memory can give better performance results than on random/real-world data. Therefore randomize memory
to be used by speed tests.

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
  • Loading branch information...
commit 1df1a3c0a24f7adaca228d192189480a3d517f2c 1 parent 8c7207b
@jkivilin authored
Showing with 29 additions and 8 deletions.
  1. +29 −8 crypto/tcrypt.c
View
37 crypto/tcrypt.c
@@ -27,6 +27,7 @@
#include <linux/init.h>
#include <linux/gfp.h>
#include <linux/module.h>
+#include <linux/random.h>
#include <linux/scatterlist.h>
#include <linux/string.h>
#include <linux/moduleparam.h>
@@ -67,6 +68,26 @@ static char *check[] = {
"lzo", "cts", "zlib", NULL
};
+static void memset_rnd(void *buf, unsigned int nbytes)
+{
+ u8 *p = buf;
+ u32 rnd;
+
+ while (nbytes >= sizeof(rnd)) {
+ rnd = random32();
+
+ memcpy(p, &rnd, sizeof(rnd));
+ p += sizeof(rnd);
+ nbytes -= sizeof(rnd);
+ }
+
+ if (nbytes == 0)
+ return;
+
+ rnd = random32();
+ memcpy(p, &rnd, nbytes);
+}
+
static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
struct scatterlist *sg, int blen, int sec)
{
@@ -185,7 +206,7 @@ static void test_cipher_speed(const char *algo, int enc, unsigned int sec,
printk("test %u (%d bit key, %d byte blocks): ", i,
*keysize * 8, *b_size);
- memset(tvmem[0], 0xff, PAGE_SIZE);
+ memset_rnd(tvmem[0], PAGE_SIZE);
/* set key, plain text and IV */
key = tvmem[0];
@@ -208,12 +229,12 @@ static void test_cipher_speed(const char *algo, int enc, unsigned int sec,
PAGE_SIZE - *keysize);
for (j = 1; j < TVMEMSIZE; j++) {
sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
- memset (tvmem[j], 0xff, PAGE_SIZE);
+ memset_rnd(tvmem[j], PAGE_SIZE);
}
iv_len = crypto_blkcipher_ivsize(tfm);
if (iv_len) {
- memset(&iv, 0xff, iv_len);
+ memset_rnd(&iv, iv_len);
crypto_blkcipher_set_iv(tfm, iv, iv_len);
}
@@ -403,7 +424,7 @@ static void test_hash_sg_init(struct scatterlist *sg)
sg_init_table(sg, TVMEMSIZE);
for (i = 0; i < TVMEMSIZE; i++) {
sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
- memset(tvmem[i], 0xff, PAGE_SIZE);
+ memset_rnd(tvmem[i], PAGE_SIZE);
}
}
@@ -856,7 +877,7 @@ static void test_acipher_speed(const char *algo, int enc, unsigned int sec,
pr_info("test %u (%d bit key, %d byte blocks): ", i,
*keysize * 8, *b_size);
- memset(tvmem[0], 0xff, PAGE_SIZE);
+ memset_rnd(tvmem[0], PAGE_SIZE);
/* set key, plain text and IV */
key = tvmem[0];
@@ -886,19 +907,19 @@ static void test_acipher_speed(const char *algo, int enc, unsigned int sec,
j = 1;
while (k > PAGE_SIZE) {
sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
- memset(tvmem[j], 0xff, PAGE_SIZE);
+ memset_rnd(tvmem[j], PAGE_SIZE);
j++;
k -= PAGE_SIZE;
}
sg_set_buf(sg + j, tvmem[j], k);
- memset(tvmem[j], 0xff, k);
+ memset_rnd(tvmem[j], k);
} else {
sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
}
iv_len = crypto_ablkcipher_ivsize(tfm);
if (iv_len)
- memset(&iv, 0xff, iv_len);
+ memset_rnd(&iv, iv_len);
ablkcipher_request_set_crypt(req, sg, sg, *b_size, iv);
Please sign in to comment.
Something went wrong with that request. Please try again.