VirtualBox

source: vbox/trunk/src/libs/openssl-3.1.3/include/crypto/aes_platform.h@ 102210

Last change on this file since 102210 was 101211, checked in by vboxsync, 16 months ago

openssl-3.1.3: Applied and adjusted our OpenSSL changes to 3.1.2. bugref:10527

File size: 26.2 KB
Line 
1/*
2 * Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10#ifndef OSSL_AES_PLATFORM_H
11# define OSSL_AES_PLATFORM_H
12# ifndef RT_WITHOUT_PRAGMA_ONCE /* VBOX */
13# pragma once
14# endif /* VBOX */
15
16# include <openssl/aes.h>
17
18# ifdef VPAES_ASM
19int vpaes_set_encrypt_key(const unsigned char *userKey, int bits,
20 AES_KEY *key);
21int vpaes_set_decrypt_key(const unsigned char *userKey, int bits,
22 AES_KEY *key);
23void vpaes_encrypt(const unsigned char *in, unsigned char *out,
24 const AES_KEY *key);
25void vpaes_decrypt(const unsigned char *in, unsigned char *out,
26 const AES_KEY *key);
27void vpaes_cbc_encrypt(const unsigned char *in,
28 unsigned char *out,
29 size_t length,
30 const AES_KEY *key, unsigned char *ivec, int enc);
31# endif /* VPAES_ASM */
32
33# ifdef BSAES_ASM
34void ossl_bsaes_cbc_encrypt(const unsigned char *in, unsigned char *out,
35 size_t length, const AES_KEY *key,
36 unsigned char ivec[16], int enc);
37void ossl_bsaes_ctr32_encrypt_blocks(const unsigned char *in,
38 unsigned char *out, size_t len,
39 const AES_KEY *key,
40 const unsigned char ivec[16]);
41void ossl_bsaes_xts_encrypt(const unsigned char *inp, unsigned char *out,
42 size_t len, const AES_KEY *key1,
43 const AES_KEY *key2, const unsigned char iv[16]);
44void ossl_bsaes_xts_decrypt(const unsigned char *inp, unsigned char *out,
45 size_t len, const AES_KEY *key1,
46 const AES_KEY *key2, const unsigned char iv[16]);
47# endif /* BSAES_ASM */
48
49# ifdef AES_CTR_ASM
50void AES_ctr32_encrypt(const unsigned char *in, unsigned char *out,
51 size_t blocks, const AES_KEY *key,
52 const unsigned char ivec[AES_BLOCK_SIZE]);
53# endif /* AES_CTR_ASM */
54
55# ifdef AES_XTS_ASM
56void AES_xts_encrypt(const unsigned char *inp, unsigned char *out, size_t len,
57 const AES_KEY *key1, const AES_KEY *key2,
58 const unsigned char iv[16]);
59void AES_xts_decrypt(const unsigned char *inp, unsigned char *out, size_t len,
60 const AES_KEY *key1, const AES_KEY *key2,
61 const unsigned char iv[16]);
62# endif /* AES_XTS_ASM */
63
64# if defined(OPENSSL_CPUID_OBJ)
65# if (defined(__powerpc__) || defined(__ppc__) || defined(_ARCH_PPC))
66# include "crypto/ppc_arch.h"
67# ifdef VPAES_ASM
68# define VPAES_CAPABLE (OPENSSL_ppccap_P & PPC_ALTIVEC)
69# endif
70# define HWAES_CAPABLE (OPENSSL_ppccap_P & PPC_CRYPTO207)
71# define HWAES_set_encrypt_key aes_p8_set_encrypt_key
72# define HWAES_set_decrypt_key aes_p8_set_decrypt_key
73# define HWAES_encrypt aes_p8_encrypt
74# define HWAES_decrypt aes_p8_decrypt
75# define HWAES_cbc_encrypt aes_p8_cbc_encrypt
76# define HWAES_ctr32_encrypt_blocks aes_p8_ctr32_encrypt_blocks
77# define HWAES_xts_encrypt aes_p8_xts_encrypt
78# define HWAES_xts_decrypt aes_p8_xts_decrypt
79# if !defined(OPENSSL_SYS_AIX) && !defined(OPENSSL_SYS_MACOSX)
80# define PPC_AES_GCM_CAPABLE (OPENSSL_ppccap_P & PPC_MADD300)
81# define AES_GCM_ENC_BYTES 128
82# define AES_GCM_DEC_BYTES 128
83size_t ppc_aes_gcm_encrypt(const unsigned char *in, unsigned char *out,
84 size_t len, const void *key, unsigned char ivec[16],
85 u64 *Xi);
86size_t ppc_aes_gcm_decrypt(const unsigned char *in, unsigned char *out,
87 size_t len, const void *key, unsigned char ivec[16],
88 u64 *Xi);
89# define AES_GCM_ASM_PPC(gctx) ((gctx)->ctr==aes_p8_ctr32_encrypt_blocks && \
90 (gctx)->gcm.funcs.ghash==gcm_ghash_p8)
91void gcm_ghash_p8(u64 Xi[2],const u128 Htable[16],const u8 *inp, size_t len);
92# endif /* OPENSSL_SYS_AIX || OPENSSL_SYS_MACOSX */
93# endif /* PPC */
94
95# if (defined(__arm__) || defined(__arm) || defined(__aarch64__))
96# include "arm_arch.h"
97# if __ARM_MAX_ARCH__>=7
98# if defined(BSAES_ASM)
99# define BSAES_CAPABLE (OPENSSL_armcap_P & ARMV7_NEON)
100# endif
101# if defined(VPAES_ASM)
102# define VPAES_CAPABLE (OPENSSL_armcap_P & ARMV7_NEON)
103# endif
104# define HWAES_CAPABLE (OPENSSL_armcap_P & ARMV8_AES)
105# define HWAES_set_encrypt_key aes_v8_set_encrypt_key
106# define HWAES_set_decrypt_key aes_v8_set_decrypt_key
107# define HWAES_encrypt aes_v8_encrypt
108# define HWAES_decrypt aes_v8_decrypt
109# define HWAES_cbc_encrypt aes_v8_cbc_encrypt
110# define HWAES_ecb_encrypt aes_v8_ecb_encrypt
111# if __ARM_MAX_ARCH__>=8 && defined(__aarch64__)
112# define HWAES_xts_encrypt aes_v8_xts_encrypt
113# define HWAES_xts_decrypt aes_v8_xts_decrypt
114# endif
115# define HWAES_ctr32_encrypt_blocks aes_v8_ctr32_encrypt_blocks
116# define AES_PMULL_CAPABLE ((OPENSSL_armcap_P & ARMV8_PMULL) && (OPENSSL_armcap_P & ARMV8_AES))
117# define AES_GCM_ENC_BYTES 512
118# define AES_GCM_DEC_BYTES 512
119# if __ARM_MAX_ARCH__>=8 && defined(__aarch64__)
120# define AES_gcm_encrypt armv8_aes_gcm_encrypt
121# define AES_gcm_decrypt armv8_aes_gcm_decrypt
122# define AES_GCM_ASM(gctx) ((gctx)->ctr==aes_v8_ctr32_encrypt_blocks && \
123 (gctx)->gcm.funcs.ghash==gcm_ghash_v8)
124/* The [unroll8_eor3_]aes_gcm_(enc|dec)_(128|192|256)_kernel() functions
125 * take input length in BITS and return number of BYTES processed */
126size_t aes_gcm_enc_128_kernel(const uint8_t * plaintext, uint64_t plaintext_length, uint8_t * ciphertext,
127 uint64_t *Xi, unsigned char ivec[16], const void *key);
128size_t aes_gcm_enc_192_kernel(const uint8_t * plaintext, uint64_t plaintext_length, uint8_t * ciphertext,
129 uint64_t *Xi, unsigned char ivec[16], const void *key);
130size_t aes_gcm_enc_256_kernel(const uint8_t * plaintext, uint64_t plaintext_length, uint8_t * ciphertext,
131 uint64_t *Xi, unsigned char ivec[16], const void *key);
132size_t aes_gcm_dec_128_kernel(const uint8_t * ciphertext, uint64_t plaintext_length, uint8_t * plaintext,
133 uint64_t *Xi, unsigned char ivec[16], const void *key);
134size_t aes_gcm_dec_192_kernel(const uint8_t * ciphertext, uint64_t plaintext_length, uint8_t * plaintext,
135 uint64_t *Xi, unsigned char ivec[16], const void *key);
136size_t aes_gcm_dec_256_kernel(const uint8_t * ciphertext, uint64_t plaintext_length, uint8_t * plaintext,
137 uint64_t *Xi, unsigned char ivec[16], const void *key);
138size_t unroll8_eor3_aes_gcm_enc_128_kernel(const uint8_t * plaintext, uint64_t plaintext_length, uint8_t * ciphertext,
139 uint64_t *Xi, unsigned char ivec[16], const void *key);
140size_t unroll8_eor3_aes_gcm_enc_192_kernel(const uint8_t * plaintext, uint64_t plaintext_length, uint8_t * ciphertext,
141 uint64_t *Xi, unsigned char ivec[16], const void *key);
142size_t unroll8_eor3_aes_gcm_enc_256_kernel(const uint8_t * plaintext, uint64_t plaintext_length, uint8_t * ciphertext,
143 uint64_t *Xi, unsigned char ivec[16], const void *key);
144size_t unroll8_eor3_aes_gcm_dec_128_kernel(const uint8_t * ciphertext, uint64_t plaintext_length, uint8_t * plaintext,
145 uint64_t *Xi, unsigned char ivec[16], const void *key);
146size_t unroll8_eor3_aes_gcm_dec_192_kernel(const uint8_t * ciphertext, uint64_t plaintext_length, uint8_t * plaintext,
147 uint64_t *Xi, unsigned char ivec[16], const void *key);
148size_t unroll8_eor3_aes_gcm_dec_256_kernel(const uint8_t * ciphertext, uint64_t plaintext_length, uint8_t * plaintext,
149 uint64_t *Xi, unsigned char ivec[16], const void *key);
150size_t armv8_aes_gcm_encrypt(const unsigned char *in, unsigned char *out, size_t len, const void *key,
151 unsigned char ivec[16], u64 *Xi);
152size_t armv8_aes_gcm_decrypt(const unsigned char *in, unsigned char *out, size_t len, const void *key,
153 unsigned char ivec[16], u64 *Xi);
154void gcm_ghash_v8(u64 Xi[2],const u128 Htable[16],const u8 *inp, size_t len);
155# endif
156# endif
157# endif
158# endif /* OPENSSL_CPUID_OBJ */
159
160# if defined(AES_ASM) && ( \
161 defined(__x86_64) || defined(__x86_64__) || \
162 defined(_M_AMD64) || defined(_M_X64) )
163# define AES_CBC_HMAC_SHA_CAPABLE 1
164# define AESNI_CBC_HMAC_SHA_CAPABLE (OPENSSL_ia32cap_P[1]&(1<<(57-32)))
165# endif
166
167# if defined(__loongarch__) || defined(__loongarch64)
168# include "loongarch_arch.h"
169# if defined(VPAES_ASM)
170# define VPAES_CAPABLE (OPENSSL_loongarch_hwcap_P & LOONGARCH_HWCAP_LSX)
171# endif
172# endif
173
174# if defined(AES_ASM) && !defined(I386_ONLY) && ( \
175 ((defined(__i386) || defined(__i386__) || \
176 defined(_M_IX86)) && defined(OPENSSL_IA32_SSE2))|| \
177 defined(__x86_64) || defined(__x86_64__) || \
178 defined(_M_AMD64) || defined(_M_X64) )
179
180/* AES-NI section */
181
182# define AESNI_CAPABLE (OPENSSL_ia32cap_P[1]&(1<<(57-32)))
183# ifdef VPAES_ASM
184# define VPAES_CAPABLE (OPENSSL_ia32cap_P[1]&(1<<(41-32)))
185# endif
186# ifdef BSAES_ASM
187# define BSAES_CAPABLE (OPENSSL_ia32cap_P[1]&(1<<(41-32)))
188# endif
189
190# define AES_GCM_ENC_BYTES 32
191# define AES_GCM_DEC_BYTES 16
192
193int aesni_set_encrypt_key(const unsigned char *userKey, int bits,
194 AES_KEY *key);
195int aesni_set_decrypt_key(const unsigned char *userKey, int bits,
196 AES_KEY *key);
197
198void aesni_encrypt(const unsigned char *in, unsigned char *out,
199 const AES_KEY *key);
200void aesni_decrypt(const unsigned char *in, unsigned char *out,
201 const AES_KEY *key);
202
203void aesni_ecb_encrypt(const unsigned char *in,
204 unsigned char *out,
205 size_t length, const AES_KEY *key, int enc);
206void aesni_cbc_encrypt(const unsigned char *in,
207 unsigned char *out,
208 size_t length,
209 const AES_KEY *key, unsigned char *ivec, int enc);
210# ifndef OPENSSL_NO_OCB
211void aesni_ocb_encrypt(const unsigned char *in, unsigned char *out,
212 size_t blocks, const void *key,
213 size_t start_block_num,
214 unsigned char offset_i[16],
215 const unsigned char L_[][16],
216 unsigned char checksum[16]);
217void aesni_ocb_decrypt(const unsigned char *in, unsigned char *out,
218 size_t blocks, const void *key,
219 size_t start_block_num,
220 unsigned char offset_i[16],
221 const unsigned char L_[][16],
222 unsigned char checksum[16]);
223# endif /* OPENSSL_NO_OCB */
224
225void aesni_ctr32_encrypt_blocks(const unsigned char *in,
226 unsigned char *out,
227 size_t blocks,
228 const void *key, const unsigned char *ivec);
229
230void aesni_xts_encrypt(const unsigned char *in,
231 unsigned char *out,
232 size_t length,
233 const AES_KEY *key1, const AES_KEY *key2,
234 const unsigned char iv[16]);
235
236void aesni_xts_decrypt(const unsigned char *in,
237 unsigned char *out,
238 size_t length,
239 const AES_KEY *key1, const AES_KEY *key2,
240 const unsigned char iv[16]);
241
242void aesni_ccm64_encrypt_blocks(const unsigned char *in,
243 unsigned char *out,
244 size_t blocks,
245 const void *key,
246 const unsigned char ivec[16],
247 unsigned char cmac[16]);
248
249void aesni_ccm64_decrypt_blocks(const unsigned char *in,
250 unsigned char *out,
251 size_t blocks,
252 const void *key,
253 const unsigned char ivec[16],
254 unsigned char cmac[16]);
255
256# if defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64)
257size_t aesni_gcm_encrypt(const unsigned char *in, unsigned char *out, size_t len,
258 const void *key, unsigned char ivec[16], u64 *Xi);
259size_t aesni_gcm_decrypt(const unsigned char *in, unsigned char *out, size_t len,
260 const void *key, unsigned char ivec[16], u64 *Xi);
261void gcm_ghash_avx(u64 Xi[2], const u128 Htable[16], const u8 *in, size_t len);
262
263# define AES_gcm_encrypt aesni_gcm_encrypt
264# define AES_gcm_decrypt aesni_gcm_decrypt
265# define AES_GCM_ASM(ctx) (ctx->ctr == aesni_ctr32_encrypt_blocks && \
266 ctx->gcm.funcs.ghash == gcm_ghash_avx)
267# endif
268
269
270# elif defined(AES_ASM) && (defined(__sparc) || defined(__sparc__))
271
272/* Fujitsu SPARC64 X support */
273# include "crypto/sparc_arch.h"
274
275# define SPARC_AES_CAPABLE (OPENSSL_sparcv9cap_P[1] & CFR_AES)
276# define HWAES_CAPABLE (OPENSSL_sparcv9cap_P[0] & SPARCV9_FJAESX)
277# define HWAES_set_encrypt_key aes_fx_set_encrypt_key
278# define HWAES_set_decrypt_key aes_fx_set_decrypt_key
279# define HWAES_encrypt aes_fx_encrypt
280# define HWAES_decrypt aes_fx_decrypt
281# define HWAES_cbc_encrypt aes_fx_cbc_encrypt
282# define HWAES_ctr32_encrypt_blocks aes_fx_ctr32_encrypt_blocks
283
284void aes_t4_set_encrypt_key(const unsigned char *key, int bits, AES_KEY *ks);
285void aes_t4_set_decrypt_key(const unsigned char *key, int bits, AES_KEY *ks);
286void aes_t4_encrypt(const unsigned char *in, unsigned char *out,
287 const AES_KEY *key);
288void aes_t4_decrypt(const unsigned char *in, unsigned char *out,
289 const AES_KEY *key);
290/*
291 * Key-length specific subroutines were chosen for following reason.
292 * Each SPARC T4 core can execute up to 8 threads which share core's
293 * resources. Loading as much key material to registers allows to
294 * minimize references to shared memory interface, as well as amount
295 * of instructions in inner loops [much needed on T4]. But then having
296 * non-key-length specific routines would require conditional branches
297 * either in inner loops or on subroutines' entries. Former is hardly
298 * acceptable, while latter means code size increase to size occupied
299 * by multiple key-length specific subroutines, so why fight?
300 */
301void aes128_t4_cbc_encrypt(const unsigned char *in, unsigned char *out,
302 size_t len, const AES_KEY *key,
303 unsigned char *ivec, int /*unused*/);
304void aes128_t4_cbc_decrypt(const unsigned char *in, unsigned char *out,
305 size_t len, const AES_KEY *key,
306 unsigned char *ivec, int /*unused*/);
307void aes192_t4_cbc_encrypt(const unsigned char *in, unsigned char *out,
308 size_t len, const AES_KEY *key,
309 unsigned char *ivec, int /*unused*/);
310void aes192_t4_cbc_decrypt(const unsigned char *in, unsigned char *out,
311 size_t len, const AES_KEY *key,
312 unsigned char *ivec, int /*unused*/);
313void aes256_t4_cbc_encrypt(const unsigned char *in, unsigned char *out,
314 size_t len, const AES_KEY *key,
315 unsigned char *ivec, int /*unused*/);
316void aes256_t4_cbc_decrypt(const unsigned char *in, unsigned char *out,
317 size_t len, const AES_KEY *key,
318 unsigned char *ivec, int /*unused*/);
319void aes128_t4_ctr32_encrypt(const unsigned char *in, unsigned char *out,
320 size_t blocks, const AES_KEY *key,
321 unsigned char *ivec);
322void aes192_t4_ctr32_encrypt(const unsigned char *in, unsigned char *out,
323 size_t blocks, const AES_KEY *key,
324 unsigned char *ivec);
325void aes256_t4_ctr32_encrypt(const unsigned char *in, unsigned char *out,
326 size_t blocks, const AES_KEY *key,
327 unsigned char *ivec);
328void aes128_t4_xts_encrypt(const unsigned char *in, unsigned char *out,
329 size_t blocks, const AES_KEY *key1,
330 const AES_KEY *key2, const unsigned char *ivec);
331void aes128_t4_xts_decrypt(const unsigned char *in, unsigned char *out,
332 size_t blocks, const AES_KEY *key1,
333 const AES_KEY *key2, const unsigned char *ivec);
334void aes256_t4_xts_encrypt(const unsigned char *in, unsigned char *out,
335 size_t blocks, const AES_KEY *key1,
336 const AES_KEY *key2, const unsigned char *ivec);
337void aes256_t4_xts_decrypt(const unsigned char *in, unsigned char *out,
338 size_t blocks, const AES_KEY *key1,
339 const AES_KEY *key2, const unsigned char *ivec);
340
341# elif defined(OPENSSL_CPUID_OBJ) && defined(__s390__)
342/* IBM S390X support */
343# include "s390x_arch.h"
344
345
346/* Convert key size to function code: [16,24,32] -> [18,19,20]. */
347# define S390X_AES_FC(keylen) (S390X_AES_128 + ((((keylen) << 3) - 128) >> 6))
348
349/* Most modes of operation need km for partial block processing. */
350# define S390X_aes_128_CAPABLE (OPENSSL_s390xcap_P.km[0] & \
351 S390X_CAPBIT(S390X_AES_128))
352# define S390X_aes_192_CAPABLE (OPENSSL_s390xcap_P.km[0] & \
353 S390X_CAPBIT(S390X_AES_192))
354# define S390X_aes_256_CAPABLE (OPENSSL_s390xcap_P.km[0] & \
355 S390X_CAPBIT(S390X_AES_256))
356
357# define S390X_aes_128_cbc_CAPABLE 1 /* checked by callee */
358# define S390X_aes_192_cbc_CAPABLE 1
359# define S390X_aes_256_cbc_CAPABLE 1
360
361# define S390X_aes_128_ecb_CAPABLE S390X_aes_128_CAPABLE
362# define S390X_aes_192_ecb_CAPABLE S390X_aes_192_CAPABLE
363# define S390X_aes_256_ecb_CAPABLE S390X_aes_256_CAPABLE
364
365# define S390X_aes_128_ofb_CAPABLE (S390X_aes_128_CAPABLE && \
366 (OPENSSL_s390xcap_P.kmo[0] & \
367 S390X_CAPBIT(S390X_AES_128)))
368# define S390X_aes_192_ofb_CAPABLE (S390X_aes_192_CAPABLE && \
369 (OPENSSL_s390xcap_P.kmo[0] & \
370 S390X_CAPBIT(S390X_AES_192)))
371# define S390X_aes_256_ofb_CAPABLE (S390X_aes_256_CAPABLE && \
372 (OPENSSL_s390xcap_P.kmo[0] & \
373 S390X_CAPBIT(S390X_AES_256)))
374
375# define S390X_aes_128_cfb_CAPABLE (S390X_aes_128_CAPABLE && \
376 (OPENSSL_s390xcap_P.kmf[0] & \
377 S390X_CAPBIT(S390X_AES_128)))
378# define S390X_aes_192_cfb_CAPABLE (S390X_aes_192_CAPABLE && \
379 (OPENSSL_s390xcap_P.kmf[0] & \
380 S390X_CAPBIT(S390X_AES_192)))
381# define S390X_aes_256_cfb_CAPABLE (S390X_aes_256_CAPABLE && \
382 (OPENSSL_s390xcap_P.kmf[0] & \
383 S390X_CAPBIT(S390X_AES_256)))
384# define S390X_aes_128_cfb8_CAPABLE (OPENSSL_s390xcap_P.kmf[0] & \
385 S390X_CAPBIT(S390X_AES_128))
386# define S390X_aes_192_cfb8_CAPABLE (OPENSSL_s390xcap_P.kmf[0] & \
387 S390X_CAPBIT(S390X_AES_192))
388# define S390X_aes_256_cfb8_CAPABLE (OPENSSL_s390xcap_P.kmf[0] & \
389 S390X_CAPBIT(S390X_AES_256))
390# define S390X_aes_128_cfb1_CAPABLE 0
391# define S390X_aes_192_cfb1_CAPABLE 0
392# define S390X_aes_256_cfb1_CAPABLE 0
393
394# define S390X_aes_128_ctr_CAPABLE 1 /* checked by callee */
395# define S390X_aes_192_ctr_CAPABLE 1
396# define S390X_aes_256_ctr_CAPABLE 1
397
398# define S390X_aes_128_xts_CAPABLE 1 /* checked by callee */
399# define S390X_aes_256_xts_CAPABLE 1
400
401# define S390X_aes_128_gcm_CAPABLE (S390X_aes_128_CAPABLE && \
402 (OPENSSL_s390xcap_P.kma[0] & \
403 S390X_CAPBIT(S390X_AES_128)))
404# define S390X_aes_192_gcm_CAPABLE (S390X_aes_192_CAPABLE && \
405 (OPENSSL_s390xcap_P.kma[0] & \
406 S390X_CAPBIT(S390X_AES_192)))
407# define S390X_aes_256_gcm_CAPABLE (S390X_aes_256_CAPABLE && \
408 (OPENSSL_s390xcap_P.kma[0] & \
409 S390X_CAPBIT(S390X_AES_256)))
410
411# define S390X_aes_128_ccm_CAPABLE (S390X_aes_128_CAPABLE && \
412 (OPENSSL_s390xcap_P.kmac[0] & \
413 S390X_CAPBIT(S390X_AES_128)))
414# define S390X_aes_192_ccm_CAPABLE (S390X_aes_192_CAPABLE && \
415 (OPENSSL_s390xcap_P.kmac[0] & \
416 S390X_CAPBIT(S390X_AES_192)))
417# define S390X_aes_256_ccm_CAPABLE (S390X_aes_256_CAPABLE && \
418 (OPENSSL_s390xcap_P.kmac[0] & \
419 S390X_CAPBIT(S390X_AES_256)))
420# define S390X_CCM_AAD_FLAG 0x40
421
422# ifndef OPENSSL_NO_OCB
423# define S390X_aes_128_ocb_CAPABLE 0
424# define S390X_aes_192_ocb_CAPABLE 0
425# define S390X_aes_256_ocb_CAPABLE 0
426# endif /* OPENSSL_NO_OCB */
427
428# ifndef OPENSSL_NO_SIV
429# define S390X_aes_128_siv_CAPABLE 0
430# define S390X_aes_192_siv_CAPABLE 0
431# define S390X_aes_256_siv_CAPABLE 0
432# endif /* OPENSSL_NO_SIV */
433
434/* Convert key size to function code: [16,24,32] -> [18,19,20]. */
435# define S390X_AES_FC(keylen) (S390X_AES_128 + ((((keylen) << 3) - 128) >> 6))
436# elif defined(OPENSSL_CPUID_OBJ) && defined(__riscv) && __riscv_xlen == 64
437/* RISC-V 64 support */
438# include "riscv_arch.h"
439# define RV64I_ZKND_ZKNE_CAPABLE (RISCV_HAS_ZKND() && RISCV_HAS_ZKNE())
440
441int rv64i_zkne_set_encrypt_key(const unsigned char *userKey, const int bits,
442 AES_KEY *key);
443int rv64i_zknd_set_decrypt_key(const unsigned char *userKey, const int bits,
444 AES_KEY *key);
445void rv64i_zkne_encrypt(const unsigned char *in, unsigned char *out,
446 const AES_KEY *key);
447void rv64i_zknd_decrypt(const unsigned char *in, unsigned char *out,
448 const AES_KEY *key);
449# elif defined(OPENSSL_CPUID_OBJ) && defined(__riscv) && __riscv_xlen == 32
450/* RISC-V 32 support */
451# include "riscv_arch.h"
452# define RV32I_ZKND_ZKNE_CAPABLE (RISCV_HAS_ZKND() && RISCV_HAS_ZKNE())
453# define RV32I_ZBKB_ZKND_ZKNE_CAPABLE (RV32I_ZKND_ZKNE_CAPABLE && RISCV_HAS_ZBKB())
454
455int rv32i_zkne_set_encrypt_key(const unsigned char *userKey, const int bits,
456 AES_KEY *key);
457/* set_decrypt_key needs both zknd and zkne */
458int rv32i_zknd_zkne_set_decrypt_key(const unsigned char *userKey, const int bits,
459 AES_KEY *key);
460int rv32i_zbkb_zkne_set_encrypt_key(const unsigned char *userKey, const int bits,
461 AES_KEY *key);
462int rv32i_zbkb_zknd_zkne_set_decrypt_key(const unsigned char *userKey, const int bits,
463 AES_KEY *key);
464void rv32i_zkne_encrypt(const unsigned char *in, unsigned char *out,
465 const AES_KEY *key);
466void rv32i_zknd_decrypt(const unsigned char *in, unsigned char *out,
467 const AES_KEY *key);
468# endif
469
470# if defined(HWAES_CAPABLE)
471int HWAES_set_encrypt_key(const unsigned char *userKey, const int bits,
472 AES_KEY *key);
473int HWAES_set_decrypt_key(const unsigned char *userKey, const int bits,
474 AES_KEY *key);
475void HWAES_encrypt(const unsigned char *in, unsigned char *out,
476 const AES_KEY *key);
477void HWAES_decrypt(const unsigned char *in, unsigned char *out,
478 const AES_KEY *key);
479void HWAES_cbc_encrypt(const unsigned char *in, unsigned char *out,
480 size_t length, const AES_KEY *key,
481 unsigned char *ivec, const int enc);
482void HWAES_ecb_encrypt(const unsigned char *in, unsigned char *out,
483 size_t length, const AES_KEY *key,
484 const int enc);
485void HWAES_ctr32_encrypt_blocks(const unsigned char *in, unsigned char *out,
486 size_t len, const void *key,
487 const unsigned char ivec[16]);
488void HWAES_xts_encrypt(const unsigned char *inp, unsigned char *out,
489 size_t len, const AES_KEY *key1,
490 const AES_KEY *key2, const unsigned char iv[16]);
491void HWAES_xts_decrypt(const unsigned char *inp, unsigned char *out,
492 size_t len, const AES_KEY *key1,
493 const AES_KEY *key2, const unsigned char iv[16]);
494# ifndef OPENSSL_NO_OCB
495# ifdef HWAES_ocb_encrypt
496void HWAES_ocb_encrypt(const unsigned char *in, unsigned char *out,
497 size_t blocks, const void *key,
498 size_t start_block_num,
499 unsigned char offset_i[16],
500 const unsigned char L_[][16],
501 unsigned char checksum[16]);
502# else
503# define HWAES_ocb_encrypt ((ocb128_f)NULL)
504# endif
505# ifdef HWAES_ocb_decrypt
506void HWAES_ocb_decrypt(const unsigned char *in, unsigned char *out,
507 size_t blocks, const void *key,
508 size_t start_block_num,
509 unsigned char offset_i[16],
510 const unsigned char L_[][16],
511 unsigned char checksum[16]);
512# else
513# define HWAES_ocb_decrypt ((ocb128_f)NULL)
514# endif
515# endif /* OPENSSL_NO_OCB */
516
517# endif /* HWAES_CAPABLE */
518
519#endif /* OSSL_AES_PLATFORM_H */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette