]>
git.proxmox.com Git - ceph.git/blob - ceph/src/crypto/isa-l/isa-l_crypto/aes/xts_256_expanded_key_test.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 **********************************************************************/
32 #include <aes_keyexp.h>
33 #include "xts_256_vect.h"
38 // Temporary array for the calculated vectors
41 // Arrays for expanded keys, null_key is a dummy vector (decrypt key not
42 // needed for the tweak part of the decryption)
43 uint8_t expkey1_enc
[16 * 15], expkey2_enc
[16 * 15];
44 uint8_t expkey1_dec
[16 * 15], null_key
[16 * 15];
48 // --- Encryption test ---
50 // Loop over the vectors
51 for (i
= 0; i
< NVEC
; i
++) {
53 // Allocate space for the calculated ciphertext
54 ct_test
= malloc(vlist
[i
].ptlen
);
55 if (ct_test
== NULL
) {
56 printf("Can't allocate ciphertext memory\n");
59 // Pre-expand our keys (will only use the encryption ones here)
60 aes_keyexp_256(vlist
[i
].key1
, expkey1_enc
, expkey1_dec
);
61 aes_keyexp_256(vlist
[i
].key2
, expkey2_enc
, null_key
);
63 XTS_AES_256_enc_expanded_key(expkey2_enc
, expkey1_enc
, vlist
[i
].TW
,
64 vlist
[i
].ptlen
, vlist
[i
].PTX
, ct_test
);
66 // Carry out comparison of the calculated ciphertext with
68 for (j
= 0; j
< vlist
[i
].ptlen
; j
++) {
70 if (ct_test
[j
] != vlist
[i
].CTX
[j
]) {
71 printf("\nXTS_AES_256_enc: Vector %d: ", i
+ 10);
72 printf("failed at byte %d! \n", j
);
79 // --- Decryption test ---
81 // Loop over the vectors
82 for (i
= 0; i
< NVEC
; i
++) {
84 // Allocate space for the calculated plaintext
85 pt_test
= malloc(vlist
[i
].ptlen
);
86 if (pt_test
== NULL
) {
87 printf("Can't allocate plaintext memory\n");
90 // Pre-expand keys for the decryption
91 aes_keyexp_256(vlist
[i
].key1
, expkey1_enc
, expkey1_dec
);
92 aes_keyexp_256(vlist
[i
].key2
, expkey2_enc
, null_key
);
94 // Note, encryption key is re-used for the tweak decryption step
95 XTS_AES_256_dec_expanded_key(expkey2_enc
, expkey1_dec
, vlist
[i
].TW
,
96 vlist
[i
].ptlen
, vlist
[i
].CTX
, pt_test
);
98 // Carry out comparison of the calculated ciphertext with
100 for (j
= 0; j
< vlist
[i
].ptlen
; j
++) {
102 if (pt_test
[j
] != vlist
[i
].PTX
[j
]) {
103 printf("\nXTS_AES_256_dec: Vector %d: ", i
+ 10);
104 printf("failed at byte %d! \n", j
);