]> git.proxmox.com Git - ceph.git/blame - ceph/src/crypto/isa-l/isa-l_crypto/aes/xts_128_enc_perf.c
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / crypto / isa-l / isa-l_crypto / aes / xts_128_enc_perf.c
CommitLineData
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
53void mk_rand_data(unsigned char *k1, unsigned char *k2, unsigned char *k3, unsigned char *p,
54 int n)
55{
56 int i;
57 for (i = 0; i < 16; i++) {
58 *k1++ = rand();
59 *k2++ = rand();
60 *k3++ = rand();
61 }
62 for (i = 0; i < n; i++)
63 *p++ = rand();
64
65}
66
67int main(void)
68{
69 int i;
70
71 unsigned char key1[16], key2[16], tinit[16];
72 unsigned char *pt, *ct;
1e59de90
TL
73 uint8_t expkey1_enc[16 * 11], expkey2_enc[16 * 11];
74 uint8_t expkey1_dec[16 * 11], null_key[16 * 11];
7c673cae
FG
75
76 printf("aes_xts_128_enc_perf:\n");
77
78 pt = malloc(TEST_LEN);
79 ct = malloc(TEST_LEN);
80
81 if (NULL == pt || NULL == ct) {
82 printf("malloc of testsize failed\n");
83 return -1;
84 }
85
1e59de90
TL
86 /* Encode perf test */
87
7c673cae
FG
88 mk_rand_data(key1, key2, tinit, pt, TEST_LEN);
89 XTS_AES_128_enc(key2, key1, tinit, TEST_LEN, pt, ct);
90
91 struct perf start, stop;
92
93 perf_start(&start);
94
95 for (i = 0; i < TEST_LOOPS; i++) {
96 XTS_AES_128_enc(key2, key1, tinit, TEST_LEN, pt, ct);
97 }
98
99 perf_stop(&stop);
100
1e59de90
TL
101 printf("aes_xts_128_enc" TEST_TYPE_STR ": ");
102 perf_print(stop, start, (long long)TEST_LEN * i);
103
104 /* Expanded keys perf test */
105
106 aes_keyexp_128(key1, expkey1_enc, expkey1_dec);
107 aes_keyexp_128(key2, expkey2_enc, null_key);
108 XTS_AES_128_enc_expanded_key(expkey2_enc, expkey1_enc, tinit, TEST_LEN, pt, ct);
109
110 perf_start(&start);
111
112 for (i = 0; i < TEST_LOOPS; i++) {
113 XTS_AES_128_enc_expanded_key(expkey2_enc, expkey1_enc, tinit, TEST_LEN, pt,
114 ct);
115 }
116
117 perf_stop(&stop);
118
119 printf("aes_xts_128_enc_expanded_key" TEST_TYPE_STR ": ");
7c673cae
FG
120 perf_print(stop, start, (long long)TEST_LEN * i);
121
122 return 0;
123}