aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-kernel/cryptodev/sdk_patches/0038-extend-sha_speed.c-to-test-CIOCHASH.patch
blob: eb8bf197c7a643b51361be620301ceb88e0175ed (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
From 65704ea24e80647e8c5f938300f51cb70af50c1c Mon Sep 17 00:00:00 2001
From: Cristian Stoica <cristian.stoica@nxp.com>
Date: Thu, 21 Jan 2016 17:30:59 +0200
Subject: [PATCH 38/38] extend sha_speed.c to test CIOCHASH

Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com>
---
 tests/sha_speed.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)

diff --git a/tests/sha_speed.c b/tests/sha_speed.c
index 5f694bd..d731c66 100644
--- a/tests/sha_speed.c
+++ b/tests/sha_speed.c
@@ -133,6 +133,62 @@ int hash_data(struct session_op *sess, int fdc, int chunksize, int alignmask)
 	return 0;
 }
 
+int digest_data(struct session_op *sess, int fdc, int chunksize, int alignmask)
+{
+	struct hash_op_data hash_op;
+	char *buffer;
+	static int val = 23;
+	struct timeval start, end;
+	double total = 0;
+	double secs, ddata, dspeed;
+	char metric[16];
+	uint8_t mac[AALG_MAX_RESULT_LEN];
+
+	if (alignmask) {
+		if (posix_memalign((void **)&buffer, alignmask + 1, chunksize)) {
+			printf("posix_memalign() failed!\n");
+			return 1;
+		}
+	} else {
+		if (!(buffer = malloc(chunksize))) {
+			perror("malloc()");
+			return 1;
+		}
+	}
+
+	printf("\tEncrypting in chunks of %d bytes: ", chunksize);
+	fflush(stdout);
+
+	memset(buffer, val++, chunksize);
+
+	must_finish = 0;
+	alarm(BUFFER_TEST_TIME);
+
+	gettimeofday(&start, NULL);
+	do {
+		memset(&hash_op, 0, sizeof(hash_op));
+		hash_op.mac_op = sess->mac;
+		hash_op.len = chunksize;
+		hash_op.src = (unsigned char *)buffer;
+		hash_op.mac_result = mac;
+
+		if (ioctl(fdc, CIOCHASH, hash_op) != 0) {
+			perror("ioctl(CIOCHASH)");
+			return 1;
+		}
+		total += chunksize;
+	} while(must_finish == 0);
+	gettimeofday(&end, NULL);
+
+	secs = udifftimeval(start, end)/ 1000000.0;
+
+	value2human(1, total, secs, &ddata, &dspeed, metric);
+	printf ("done. %.2f %s in %.2f secs: ", ddata, metric, secs);
+	printf ("%.2f %s/sec\n", dspeed, metric);
+
+	free(buffer);
+	return 0;
+}
 
 #ifdef CIOCGSESSINFO
 int get_alignmask(struct session_op *sess, int fdc)
@@ -154,6 +210,20 @@ int get_alignmask(struct session_op *sess, int fdc)
 #endif
 
 
+int ciochash_session(struct session_op *sess, int fdc)
+{
+	int i;
+	int err = 0;
+
+	err = 0;
+	for(i = 0; (err == 0) && (buffer_lengths[i] != 0); i++) {
+		err = digest_data(sess, fdc, buffer_lengths[i], 0);
+	}
+
+	return err;
+}
+
+
 int hash_session(struct session_op *sess, int fdc)
 {
 	int i;
@@ -193,6 +263,15 @@ int test_sha1(struct session_op *sess, int fdc)
 }
 
 
+int test_sha1_ciochash(struct session_op *sess, int fdc)
+{
+	fprintf(stderr, "Testing SHA1 CIOCHASH: \n");
+	memset(sess, 0, sizeof(sess));
+	sess->mac = CRYPTO_SHA1;
+	return ciochash_session(sess, fdc);
+}
+
+
 int test_sha256(struct session_op *sess, int fdc)
 {
 	fprintf(stderr, "Testing SHA256 Hash: \n");
@@ -202,6 +281,15 @@ int test_sha256(struct session_op *sess, int fdc)
 }
 
 
+int test_sha256_ciochash(struct session_op *sess, int fdc)
+{
+	fprintf(stderr, "Testing SHA256 CIOCHASH: \n");
+	memset(sess, 0, sizeof(sess));
+	sess->mac = CRYPTO_SHA2_256;
+	return ciochash_session(sess, fdc);
+}
+
+
 int main(void)
 {
 	int fd;
@@ -227,7 +315,9 @@ int main(void)
 
 	/* run all tests but return an eventual error */
 	err |= test_sha1(&sess, fdc);
+	err |= test_sha1_ciochash(&sess, fdc);
 	err |= test_sha256(&sess, fdc);
+	err |= test_sha256_ciochash(&sess, fdc);
 
 	close(fdc);
 	close(fd);
-- 
2.7.0