diff options
| author | jsing <> | 2025-07-13 06:01:33 +0000 |
|---|---|---|
| committer | jsing <> | 2025-07-13 06:01:33 +0000 |
| commit | f0234f5a33ecf3b2784f3e73bdf1e937abe56599 (patch) | |
| tree | a43688f8969e5bd862faf101152f51b1560e7731 /src/lib/libcrypto/aes/aes.c | |
| parent | 417b1213b262bbe6d34c708537dff4b062920bfa (diff) | |
| download | openbsd-f0234f5a33ecf3b2784f3e73bdf1e937abe56599.tar.gz openbsd-f0234f5a33ecf3b2784f3e73bdf1e937abe56599.tar.bz2 openbsd-f0234f5a33ecf3b2784f3e73bdf1e937abe56599.zip | |
Simplify AES-XTS implementation and remove AES-NI specific code from EVP.
Provide aes_xts_encrypt_internal() and call that from aes_xts_cipher().
Have amd64 and i386 provide their own versions that dispatch to
aesni_xts_encrypt()/aesni_xts_decrypt() as appropriate. The
AESNI_CAPABLE code and methods can then be removed.
ok tb@
Diffstat (limited to 'src/lib/libcrypto/aes/aes.c')
| -rw-r--r-- | src/lib/libcrypto/aes/aes.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/lib/libcrypto/aes/aes.c b/src/lib/libcrypto/aes/aes.c index e9dbe975e3..45b7a3b109 100644 --- a/src/lib/libcrypto/aes/aes.c +++ b/src/lib/libcrypto/aes/aes.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: aes.c,v 1.10 2025/06/27 17:10:45 jsing Exp $ */ | 1 | /* $OpenBSD: aes.c,v 1.11 2025/07/13 06:01:33 jsing Exp $ */ |
| 2 | /* ==================================================================== | 2 | /* ==================================================================== |
| 3 | * Copyright (c) 2002-2006 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 2002-2006 The OpenSSL Project. All rights reserved. |
| 4 | * | 4 | * |
| @@ -57,6 +57,7 @@ | |||
| 57 | 57 | ||
| 58 | #include "crypto_arch.h" | 58 | #include "crypto_arch.h" |
| 59 | #include "crypto_internal.h" | 59 | #include "crypto_internal.h" |
| 60 | #include "modes_local.h" | ||
| 60 | 61 | ||
| 61 | static const unsigned char aes_wrap_default_iv[] = { | 62 | static const unsigned char aes_wrap_default_iv[] = { |
| 62 | 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, | 63 | 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, |
| @@ -322,6 +323,35 @@ AES_ofb128_encrypt(const unsigned char *in, unsigned char *out, size_t length, | |||
| 322 | } | 323 | } |
| 323 | LCRYPTO_ALIAS(AES_ofb128_encrypt); | 324 | LCRYPTO_ALIAS(AES_ofb128_encrypt); |
| 324 | 325 | ||
| 326 | void | ||
| 327 | aes_xts_encrypt_generic(const unsigned char *in, unsigned char *out, size_t len, | ||
| 328 | const AES_KEY *key1, const AES_KEY *key2, const unsigned char iv[16], | ||
| 329 | int encrypt) | ||
| 330 | { | ||
| 331 | XTS128_CONTEXT xctx; | ||
| 332 | |||
| 333 | if (encrypt) | ||
| 334 | xctx.block1 = aes_encrypt_block128; | ||
| 335 | else | ||
| 336 | xctx.block1 = aes_decrypt_block128; | ||
| 337 | |||
| 338 | xctx.block2 = aes_encrypt_block128; | ||
| 339 | xctx.key1 = key1; | ||
| 340 | xctx.key2 = key2; | ||
| 341 | |||
| 342 | CRYPTO_xts128_encrypt(&xctx, iv, in, out, len, encrypt); | ||
| 343 | } | ||
| 344 | |||
| 345 | #ifndef HAVE_AES_XTS_ENCRYPT_INTERNAL | ||
| 346 | void | ||
| 347 | aes_xts_encrypt_internal(const unsigned char *in, unsigned char *out, size_t len, | ||
| 348 | const AES_KEY *key1, const AES_KEY *key2, const unsigned char iv[16], | ||
| 349 | int encrypt) | ||
| 350 | { | ||
| 351 | aes_xts_encrypt_generic(in, out, len, key1, key2, iv, encrypt); | ||
| 352 | } | ||
| 353 | #endif | ||
| 354 | |||
| 325 | int | 355 | int |
| 326 | AES_wrap_key(AES_KEY *key, const unsigned char *iv, unsigned char *out, | 356 | AES_wrap_key(AES_KEY *key, const unsigned char *iv, unsigned char *out, |
| 327 | const unsigned char *in, unsigned int inlen) | 357 | const unsigned char *in, unsigned int inlen) |
