]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /********************************************************************** |
2 | Copyright(c) 2011-2016 Intel Corporation All rights reserved. | |
3 | ||
4 | Redistribution and use in source and binary forms, with or without | |
1e59de90 | 5 | modification, are permitted provided that the following conditions |
7c673cae FG |
6 | are met: |
7 | * Redistributions of source code must retain the above copyright | |
8 | notice, this list of conditions and the following disclaimer. | |
9 | * Redistributions in binary form must reproduce the above copyright | |
10 | notice, this list of conditions and the following disclaimer in | |
11 | the documentation and/or other materials provided with the | |
12 | distribution. | |
13 | * Neither the name of Intel Corporation nor the names of its | |
14 | contributors may be used to endorse or promote products derived | |
15 | from this software without specific prior written permission. | |
16 | ||
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28 | **********************************************************************/ | |
29 | ||
30 | #include <stdio.h> | |
31 | #include <stdlib.h> // for rand | |
32 | #include <string.h> // for memcmp | |
33 | #include "aes_xts.h" | |
1e59de90 | 34 | #include "aes_keyexp.h" |
7c673cae FG |
35 | #include "test.h" |
36 | ||
37 | //#define CACHED_TEST | |
38 | #ifdef CACHED_TEST | |
39 | // Cached test, loop many times over small dataset | |
40 | # define TEST_LEN 8*1024 | |
1e59de90 | 41 | # define TEST_LOOPS 3000000 |
7c673cae FG |
42 | # define TEST_TYPE_STR "_warm" |
43 | #else | |
44 | // Uncached test. Pull from large mem base. | |
45 | # define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */ | |
46 | # define TEST_LEN (2 * GT_L3_CACHE) | |
1e59de90 | 47 | # define TEST_LOOPS 400 |
7c673cae FG |
48 | # define TEST_TYPE_STR "_cold" |
49 | #endif | |
50 | ||
51 | #define TEST_MEM TEST_LEN | |
52 | ||
53 | void xts256_mk_rand_data(unsigned char *k1, unsigned char *k2, unsigned char *t, | |
54 | unsigned char *p, int n) | |
55 | { | |
56 | int i; | |
57 | for (i = 0; i < 32; i++) { | |
58 | *k1++ = rand(); | |
59 | *k2++ = rand(); | |
60 | } | |
61 | for (i = 0; i < 16; i++) | |
62 | *t++ = rand(); | |
63 | ||
64 | for (i = 0; i < n; i++) | |
65 | *p++ = rand(); | |
66 | ||
67 | } | |
68 | ||
69 | int main(void) | |
70 | { | |
71 | int i; | |
72 | ||
73 | unsigned char key1[16 * 2], key2[16 * 2], tinit[16]; | |
74 | unsigned char *pt, *ct; | |
1e59de90 TL |
75 | uint8_t expkey1_enc[16 * 15], expkey2_enc[16 * 15]; |
76 | uint8_t expkey1_dec[16 * 15], null_key[16 * 15]; | |
7c673cae FG |
77 | |
78 | printf("aes_xts_256_enc_perf:\n"); | |
79 | pt = malloc(TEST_LEN); | |
80 | ct = malloc(TEST_LEN); | |
81 | ||
82 | if (NULL == pt || NULL == ct) { | |
83 | printf("malloc of testsize failed\n"); | |
84 | return -1; | |
85 | } | |
86 | ||
1e59de90 TL |
87 | /* Encode perf test */ |
88 | ||
7c673cae FG |
89 | xts256_mk_rand_data(key1, key2, tinit, pt, TEST_LEN); |
90 | XTS_AES_256_enc(key2, key1, tinit, TEST_LEN, pt, ct); | |
91 | ||
92 | struct perf start, stop; | |
93 | ||
94 | perf_start(&start); | |
95 | ||
96 | for (i = 0; i < TEST_LOOPS; i++) { | |
97 | XTS_AES_256_enc(key2, key1, tinit, TEST_LEN, pt, ct); | |
98 | } | |
99 | ||
100 | perf_stop(&stop); | |
101 | ||
1e59de90 TL |
102 | printf("aes_xts_256_enc" TEST_TYPE_STR ": "); |
103 | perf_print(stop, start, (long long)TEST_LEN * i); | |
104 | ||
105 | /* Expanded keys perf test */ | |
106 | ||
107 | aes_keyexp_256(key1, expkey1_enc, expkey1_dec); | |
108 | aes_keyexp_256(key2, expkey2_enc, null_key); | |
109 | XTS_AES_256_enc_expanded_key(expkey2_enc, expkey1_enc, tinit, TEST_LEN, pt, ct); | |
110 | ||
111 | perf_start(&start); | |
112 | ||
113 | for (i = 0; i < TEST_LOOPS; i++) { | |
114 | XTS_AES_256_enc_expanded_key(expkey2_enc, expkey1_enc, tinit, TEST_LEN, pt, | |
115 | ct); | |
116 | } | |
117 | ||
118 | perf_stop(&stop); | |
119 | ||
120 | printf("aes_xts_256_enc_expanded_key" TEST_TYPE_STR ": "); | |
7c673cae FG |
121 | perf_print(stop, start, (long long)TEST_LEN * i); |
122 | ||
123 | return 0; | |
124 | } |