]>
git.proxmox.com Git - ceph.git/blob - ceph/src/crypto/isa-l/isa-l_crypto/aes/xts_128_enc_ossl_perf.c
1 /**********************************************************************
2 Copyright(c) 2011-2016 Intel Corporation All rights reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
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
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.
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 **********************************************************************/
31 #include <stdlib.h> // for rand
32 #include <string.h> // for memcmp
36 #include <openssl/evp.h>
40 // Cached test, loop many times over small dataset
41 # define TEST_LEN 8*1024
42 # define TEST_LOOPS 400000
43 # define TEST_TYPE_STR "_warm"
45 // Uncached test. Pull from large mem base.
46 # define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */
47 # define TEST_LEN (2 * GT_L3_CACHE)
48 # define TEST_LOOPS 50
49 # define TEST_TYPE_STR "_cold"
52 #define TEST_MEM TEST_LEN
54 void xts128_mk_rand_data(unsigned char *k1
, unsigned char *k2
, unsigned char *k3
,
55 unsigned char *p
, int n
)
58 for (i
= 0; i
< 16; i
++) {
63 for (i
= 0; i
< n
; i
++)
69 int openssl_aes_128_xts_enc(EVP_CIPHER_CTX
* ctx
, unsigned char *key
, unsigned char *iv
,
70 int len
, unsigned char *pt
, unsigned char *ct
)
73 if (!EVP_EncryptInit_ex(ctx
, EVP_aes_128_xts(), NULL
, key
, iv
))
74 printf("\n ERROR!! \n");
75 if (!EVP_EncryptUpdate(ctx
, ct
, &outlen
, (const unsigned char *)pt
, len
))
76 printf("\n ERROR!! \n");
77 if (!EVP_EncryptFinal_ex(ctx
, ct
+ outlen
, &tmplen
))
78 printf("\n ERROR!! \n");
87 unsigned char key1
[16], key2
[16], tinit
[16];
88 unsigned char *pt
, *ct
, *refct
;
89 struct perf start
, stop
;
90 unsigned char keyssl
[32]; /* SSL takes both keys together */
92 /* Initialise our cipher context, which can use same input vectors */
94 EVP_CIPHER_CTX_init(&ctx
);
96 printf("aes_xts_128_enc_perf:\n");
98 pt
= malloc(TEST_LEN
);
99 ct
= malloc(TEST_LEN
);
100 refct
= malloc(TEST_LEN
);
102 if (NULL
== pt
|| NULL
== ct
|| NULL
== refct
) {
103 printf("malloc of testsize failed\n");
107 xts128_mk_rand_data(key1
, key2
, tinit
, pt
, TEST_LEN
);
109 /* Set up key for the SSL engine */
110 for (i
= 0; i
< 16; i
++) {
112 keyssl
[i
+ 16] = key2
[i
];
115 /* Encrypt and compare output */
116 XTS_AES_128_enc(key2
, key1
, tinit
, TEST_LEN
, pt
, ct
);
117 openssl_aes_128_xts_enc(&ctx
, keyssl
, tinit
, TEST_LEN
, pt
, refct
);
118 if (memcmp(ct
, refct
, TEST_LEN
)) {
119 printf("ISA-L and OpenSSL results don't match\n");
123 /* Time ISA-L encryption */
125 for (i
= 0; i
< TEST_LOOPS
; i
++)
126 XTS_AES_128_enc(key2
, key1
, tinit
, TEST_LEN
, pt
, ct
);
129 printf("aes_xts_128_enc" TEST_TYPE_STR
": ");
130 perf_print(stop
, start
, (long long)TEST_LEN
* i
);
132 /* Time OpenSSL encryption */
134 for (i
= 0; i
< TEST_LOOPS
; i
++)
135 openssl_aes_128_xts_enc(&ctx
, keyssl
, tinit
, TEST_LEN
, pt
, refct
);
138 printf("aes_xts_128_openssl_enc" TEST_TYPE_STR
": ");
139 perf_print(stop
, start
, (long long)TEST_LEN
* i
);