]>
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 | |
5 | modification, are permitted provided that the following conditions | |
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" | |
34 | #include "test.h" | |
35 | ||
36 | //#define CACHED_TEST | |
37 | #ifdef CACHED_TEST | |
38 | // Cached test, loop many times over small dataset | |
39 | # define TEST_LEN 8*1024 | |
40 | # define TEST_LOOPS 400000 | |
41 | # define TEST_TYPE_STR "_warm" | |
42 | #else | |
43 | // Uncached test. Pull from large mem base. | |
44 | # define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */ | |
45 | # define TEST_LEN (2 * GT_L3_CACHE) | |
46 | # define TEST_LOOPS 50 | |
47 | # define TEST_TYPE_STR "_cold" | |
48 | #endif | |
49 | ||
50 | #define TEST_MEM TEST_LEN | |
51 | ||
52 | void mk_rand_data(unsigned char *k1, unsigned char *k2, unsigned char *k3, unsigned char *p, | |
53 | int n) | |
54 | { | |
55 | int i; | |
56 | for (i = 0; i < 16; i++) { | |
57 | *k1++ = rand(); | |
58 | *k2++ = rand(); | |
59 | *k3++ = rand(); | |
60 | } | |
61 | for (i = 0; i < n; i++) | |
62 | *p++ = rand(); | |
63 | ||
64 | } | |
65 | ||
66 | int main(void) | |
67 | { | |
68 | int i; | |
69 | ||
70 | unsigned char key1[16], key2[16], tinit[16]; | |
71 | unsigned char *pt, *ct, *dt; | |
72 | ||
73 | printf("aes_xts_128_dec_perf:\n"); | |
74 | ||
75 | pt = malloc(TEST_LEN); | |
76 | ct = malloc(TEST_LEN); | |
77 | dt = malloc(TEST_LEN); | |
78 | ||
79 | if (NULL == pt || NULL == ct || NULL == dt) { | |
80 | printf("malloc of testsize failed\n"); | |
81 | return -1; | |
82 | } | |
83 | ||
84 | mk_rand_data(key1, key2, tinit, pt, TEST_LEN); | |
85 | XTS_AES_128_enc(key2, key1, tinit, TEST_LEN, pt, ct); | |
86 | XTS_AES_128_dec(key2, key1, tinit, TEST_LEN, ct, dt); | |
87 | ||
88 | struct perf start, stop; | |
89 | ||
90 | perf_start(&start); | |
91 | ||
92 | for (i = 0; i < TEST_LOOPS; i++) { | |
93 | XTS_AES_128_dec(key2, key1, tinit, TEST_LEN, ct, dt); | |
94 | } | |
95 | ||
96 | perf_stop(&stop); | |
97 | ||
98 | printf("aes_xts_128_dec" TEST_TYPE_STR ": "); | |
99 | perf_print(stop, start, (long long)TEST_LEN * i); | |
100 | ||
101 | return 0; | |
102 | } |