2014-12-17 09:58:11 -07:00
|
|
|
/* aes.h
|
|
|
|
*
|
2022-12-30 17:12:11 -07:00
|
|
|
* Copyright (C) 2006-2023 wolfSSL Inc.
|
2014-12-17 09:58:11 -07:00
|
|
|
*
|
2016-03-17 16:02:13 -06:00
|
|
|
* This file is part of wolfSSL.
|
2014-12-17 09:58:11 -07:00
|
|
|
*
|
2014-12-18 11:44:48 -07:00
|
|
|
* wolfSSL is free software; you can redistribute it and/or modify
|
2014-12-17 09:58:11 -07:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2014-12-18 11:44:48 -07:00
|
|
|
* wolfSSL is distributed in the hope that it will be useful,
|
2014-12-17 09:58:11 -07:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2016-03-17 16:02:13 -06:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
2014-12-17 09:58:11 -07:00
|
|
|
*/
|
|
|
|
|
2017-12-29 10:45:37 -07:00
|
|
|
/*!
|
|
|
|
\file wolfssl/wolfcrypt/aes.h
|
|
|
|
*/
|
2020-07-09 15:13:01 -07:00
|
|
|
/*
|
2017-12-29 10:45:37 -07:00
|
|
|
|
2020-07-09 15:13:01 -07:00
|
|
|
DESCRIPTION
|
|
|
|
This library provides the interfaces to the Advanced Encryption Standard (AES)
|
|
|
|
for encrypting and decrypting data. AES is the standard known for a symmetric
|
|
|
|
block cipher mechanism that uses n-bit binary string parameter key with 128-bits,
|
|
|
|
192-bits, and 256-bits of key sizes.
|
2016-03-17 16:02:13 -06:00
|
|
|
|
2020-07-09 15:13:01 -07:00
|
|
|
*/
|
2014-12-17 09:58:11 -07:00
|
|
|
#ifndef WOLF_CRYPT_AES_H
|
|
|
|
#define WOLF_CRYPT_AES_H
|
|
|
|
|
2014-12-18 11:44:48 -07:00
|
|
|
#include <wolfssl/wolfcrypt/types.h>
|
|
|
|
|
2023-02-10 11:48:59 +10:00
|
|
|
#if !defined(NO_AES) || defined(WOLFSSL_SM4)
|
|
|
|
typedef struct Gcm {
|
|
|
|
ALIGN16 byte H[16];
|
|
|
|
#ifdef OPENSSL_EXTRA
|
|
|
|
word32 aadH[4]; /* additional authenticated data GHASH */
|
|
|
|
word32 aadLen; /* additional authenticated data len */
|
|
|
|
#endif
|
|
|
|
#ifdef GCM_TABLE
|
|
|
|
/* key-based fast multiplication table. */
|
|
|
|
ALIGN16 byte M0[256][16];
|
|
|
|
#elif defined(GCM_TABLE_4BIT)
|
|
|
|
#if defined(BIG_ENDIAN_ORDER) || defined(WC_16BIT_CPU)
|
|
|
|
ALIGN16 byte M0[16][16];
|
|
|
|
#else
|
|
|
|
ALIGN16 byte M0[32][16];
|
|
|
|
#endif
|
|
|
|
#endif /* GCM_TABLE */
|
|
|
|
} Gcm;
|
|
|
|
|
|
|
|
WOLFSSL_LOCAL void GenerateM0(Gcm* gcm);
|
|
|
|
#ifdef WOLFSSL_ARMASM
|
|
|
|
WOLFSSL_LOCAL void GMULT(byte* X, byte* Y);
|
|
|
|
#endif
|
|
|
|
WOLFSSL_LOCAL void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c,
|
|
|
|
word32 cSz, byte* s, word32 sSz);
|
|
|
|
#endif
|
|
|
|
|
2015-02-26 12:29:15 -08:00
|
|
|
#ifndef NO_AES
|
|
|
|
|
2018-02-01 11:02:35 -08:00
|
|
|
#if defined(HAVE_FIPS) && \
|
|
|
|
defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
|
|
|
|
#include <wolfssl/wolfcrypt/fips.h>
|
|
|
|
#endif /* HAVE_FIPS_VERSION >= 2 */
|
|
|
|
|
2018-07-30 13:58:19 -07:00
|
|
|
#ifndef WC_NO_RNG
|
|
|
|
#include <wolfssl/wolfcrypt/random.h>
|
|
|
|
#endif
|
|
|
|
#ifdef STM32_CRYPTO
|
|
|
|
#include <wolfssl/wolfcrypt/port/st/stm32.h>
|
|
|
|
#endif
|
2015-01-01 07:33:07 -07:00
|
|
|
|
2020-09-18 11:46:08 +02:00
|
|
|
#ifdef WOLFSSL_IMXRT_DCP
|
|
|
|
#include "fsl_dcp.h"
|
|
|
|
#endif
|
2018-02-05 13:50:30 -08:00
|
|
|
|
2017-06-07 11:37:21 -06:00
|
|
|
#ifdef WOLFSSL_XILINX_CRYPT
|
2022-05-20 14:28:39 +02:00
|
|
|
#ifdef WOLFSSL_XILINX_CRYPT_VERSAL
|
|
|
|
#include <wolfssl/wolfcrypt/port/xilinx/xil-versal-glue.h>
|
|
|
|
#include <xsecure_aesclient.h>
|
|
|
|
#define WOLFSSL_XILINX_AES_KEY_SRC XSECURE_AES_USER_KEY_0
|
|
|
|
#else /* versal */
|
|
|
|
#include <xsecure_aes.h>
|
2022-05-04 16:12:59 +02:00
|
|
|
#define WOLFSSL_XILINX_AES_KEY_SRC XSECURE_CSU_AES_KEY_SRC_KUP
|
2022-05-20 14:28:39 +02:00
|
|
|
#endif /* !versal */
|
2022-05-04 16:12:59 +02:00
|
|
|
#endif /* WOLFSSL_XILINX_CRYPT */
|
|
|
|
|
|
|
|
#if defined(WOLFSSL_XILINX_CRYPT) || defined(WOLFSSL_AFALG_XILINX_AES)
|
|
|
|
#if !defined(WOLFSSL_XILINX_AES_KEY_SRC)
|
|
|
|
#define WOLFSSL_XILINX_AES_KEY_SRC 0
|
|
|
|
#endif /* !defined(WOLFSSL_XILINX_AES_KEY_SRC) */
|
|
|
|
#endif /* all Xilinx crypto */
|
2017-06-07 11:37:21 -06:00
|
|
|
|
2021-08-20 12:59:41 -06:00
|
|
|
#ifdef WOLFSSL_SE050
|
|
|
|
#include <wolfssl/wolfcrypt/port/nxp/se050_port.h>
|
|
|
|
#endif
|
|
|
|
|
2018-08-24 10:24:53 -06:00
|
|
|
#if defined(WOLFSSL_AFALG) || defined(WOLFSSL_AFALG_XILINX_AES)
|
2018-07-18 17:26:25 -06:00
|
|
|
/* included for struct msghdr */
|
2018-08-24 10:24:53 -06:00
|
|
|
#include <wolfssl/wolfcrypt/port/af_alg/wc_afalg.h>
|
2018-07-18 17:26:25 -06:00
|
|
|
#endif
|
|
|
|
|
2021-08-19 11:25:59 +10:00
|
|
|
#if defined(WOLFSSL_KCAPI_AES)
|
|
|
|
#include <wolfssl/wolfcrypt/port/kcapi/wc_kcapi.h>
|
|
|
|
#endif
|
|
|
|
|
2018-08-17 09:46:16 -06:00
|
|
|
#if defined(WOLFSSL_DEVCRYPTO_AES) || defined(WOLFSSL_DEVCRYPTO_CBC)
|
|
|
|
#include <wolfssl/wolfcrypt/port/devcrypto/wc_devcrypto.h>
|
|
|
|
#endif
|
|
|
|
|
2020-11-06 12:20:03 -08:00
|
|
|
#ifdef WOLFSSL_SILABS_SE_ACCEL
|
|
|
|
#include <wolfssl/wolfcrypt/port/silabs/silabs_aes.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2018-03-06 16:45:44 -08:00
|
|
|
#if defined(HAVE_AESGCM) && !defined(WC_NO_RNG)
|
|
|
|
#include <wolfssl/wolfcrypt/random.h>
|
|
|
|
#endif
|
|
|
|
|
2021-12-22 17:41:01 +01:00
|
|
|
#if defined(WOLFSSL_HAVE_PSA) && !defined(WOLFSSL_PSA_NO_AES)
|
|
|
|
#include <psa/crypto.h>
|
|
|
|
#endif
|
|
|
|
|
2019-03-27 20:44:38 -07:00
|
|
|
#if defined(WOLFSSL_CRYPTOCELL)
|
|
|
|
#include <wolfssl/wolfcrypt/port/arm/cryptoCell.h>
|
|
|
|
#endif
|
2014-12-17 09:58:11 -07:00
|
|
|
|
2019-08-19 17:32:22 +09:00
|
|
|
#if defined(WOLFSSL_RENESAS_TSIP_TLS) && \
|
|
|
|
defined(WOLFSSL_RENESAS_TSIP_TLS_AES_CRYPT)
|
2022-05-27 13:53:25 +09:00
|
|
|
#include <wolfssl/wolfcrypt/port/Renesas/renesas_tsip_types.h>
|
2019-08-19 17:32:22 +09:00
|
|
|
#endif
|
|
|
|
|
2022-09-21 03:21:33 -04:00
|
|
|
#ifdef WOLFSSL_MAXQ10XX_CRYPTO
|
|
|
|
#include <wolfssl/wolfcrypt/port/maxim/maxq10xx.h>
|
|
|
|
#endif
|
|
|
|
|
2014-12-17 09:58:11 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2020-01-14 21:13:52 +01:00
|
|
|
#ifndef WOLFSSL_AES_KEY_SIZE_ENUM
|
|
|
|
#define WOLFSSL_AES_KEY_SIZE_ENUM
|
2018-04-10 19:59:11 -07:00
|
|
|
/* these are required for FIPS and non-FIPS */
|
2018-02-01 11:02:35 -08:00
|
|
|
enum {
|
2018-04-10 19:59:11 -07:00
|
|
|
AES_128_KEY_SIZE = 16, /* for 128 bit */
|
|
|
|
AES_192_KEY_SIZE = 24, /* for 192 bit */
|
|
|
|
AES_256_KEY_SIZE = 32, /* for 256 bit */
|
|
|
|
|
2023-04-14 13:48:03 -05:00
|
|
|
AES_IV_SIZE = 16 /* always block size */
|
2018-04-10 19:59:11 -07:00
|
|
|
};
|
2020-01-14 21:13:52 +01:00
|
|
|
#endif
|
2018-04-10 19:59:11 -07:00
|
|
|
|
2018-02-01 11:02:35 -08:00
|
|
|
/* avoid redefinition of structs */
|
|
|
|
#if !defined(HAVE_FIPS) || \
|
|
|
|
(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
|
2016-08-15 13:59:41 -06:00
|
|
|
|
|
|
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
|
|
|
#include <wolfssl/wolfcrypt/async.h>
|
|
|
|
#endif
|
2015-01-05 14:59:48 -07:00
|
|
|
|
|
|
|
enum {
|
2018-04-03 08:50:26 -07:00
|
|
|
AES_ENC_TYPE = WC_CIPHER_AES, /* cipher unique type */
|
2015-01-05 14:59:48 -07:00
|
|
|
AES_ENCRYPTION = 0,
|
|
|
|
AES_DECRYPTION = 1,
|
2018-03-30 10:30:45 -07:00
|
|
|
|
2018-04-03 08:50:26 -07:00
|
|
|
AES_BLOCK_SIZE = 16,
|
|
|
|
|
2018-04-10 19:59:11 -07:00
|
|
|
KEYWRAP_BLOCK_SIZE = 8,
|
2018-06-27 19:37:21 -07:00
|
|
|
|
|
|
|
GCM_NONCE_MAX_SZ = 16, /* wolfCrypt's maximum nonce size allowed. */
|
2021-03-04 09:09:08 -08:00
|
|
|
GCM_NONCE_MID_SZ = 12, /* The default nonce size for AES-GCM. */
|
2018-06-27 19:37:21 -07:00
|
|
|
GCM_NONCE_MIN_SZ = 8, /* wolfCrypt's minimum nonce size allowed. */
|
|
|
|
CCM_NONCE_MIN_SZ = 7,
|
|
|
|
CCM_NONCE_MAX_SZ = 13,
|
|
|
|
CTR_SZ = 4,
|
2018-09-12 08:56:59 +10:00
|
|
|
AES_IV_FIXED_SZ = 4,
|
2020-01-21 15:51:12 -08:00
|
|
|
#ifdef WOLFSSL_AES_CFB
|
|
|
|
AES_CFB_MODE = 1,
|
|
|
|
#endif
|
|
|
|
#ifdef WOLFSSL_AES_OFB
|
|
|
|
AES_OFB_MODE = 2,
|
|
|
|
#endif
|
2020-01-28 21:46:04 -06:00
|
|
|
#ifdef WOLFSSL_AES_XTS
|
|
|
|
AES_XTS_MODE = 3,
|
|
|
|
#endif
|
2018-09-12 08:56:59 +10:00
|
|
|
|
2022-03-17 14:12:13 -07:00
|
|
|
#ifdef WOLF_PRIVATE_KEY_ID
|
2020-10-23 13:57:46 +10:00
|
|
|
AES_MAX_ID_LEN = 32,
|
|
|
|
AES_MAX_LABEL_LEN = 32,
|
2018-09-12 08:56:59 +10:00
|
|
|
#endif
|
2023-04-14 13:48:03 -05:00
|
|
|
|
|
|
|
WOLF_ENUM_DUMMY_LAST_ELEMENT(AES)
|
2015-01-05 14:59:48 -07:00
|
|
|
};
|
|
|
|
|
2019-09-09 19:24:45 -06:00
|
|
|
struct Aes {
|
2015-01-05 14:59:48 -07:00
|
|
|
/* AESNI needs key first, rounds 2nd, not sure why yet */
|
|
|
|
ALIGN16 word32 key[60];
|
|
|
|
word32 rounds;
|
Intel QuickAssist (QAT) support and async enhancements/fixes:
* Adds ./configure "--with-intelqa=../QAT1.6”, port files, memory management and README.md (see wolfcrypt/src/port/intel/).
* Added Intel QAT support for RSA public/private (CRT/non-CRT), AES CBC/GCM, ECDH/ECDSA, DH, DES3, SHA, SHA224, SHA256, SHA384, SHA512, MD5 and HMAC.
* wolfSSL async enabled all client and server: PKI, Encrypt/Decrypt, Hashing/HMAC and Certificate Sign/Verify.
* wolfSSL async support in functions: Encrypt, Decrypt, VerifyMAC, BuildMessage, ConfirmSignature, DoCertificate, ParseCertRelative, and MakeSignature.
* wolfCrypt test and benchmark async support added for all HW acceleration.
* wolfCrypt benchmark multi-threading support.
* Added QuickAssist memory overrides for XMALLOC, XFREE and XREALLOC. XREALLOC determines if existing pointer needs reallocated for NUMA.
* Refactor to make sure “heap” is available for async dev init.
* Added async support for all examples for connect, accept, read and write.
* Added new WC_BIGINT (in wolfmath.c) for async hardware support.
* Added async simulator tests for DES3 CBC, AES CBC/GCM.
* Added QAT standalone build for unit testing.
* Added int return code to SHA and MD5 functions.
* Refactor of the async stack variable handling, so async operations have generic args buffer area and cleanup function pointer.
* Combined duplicate code for async push/pop handling.
* Refactor internal.c to add AllocKey / FreeKey.
* Refactor of hash init/free in TLS to use InitHashes and FreeHashes.
* Refactor of the async event->context to use WOLF_EVENT_TYPE_ASYNC_WOLFSSL for WOLFSSL* and WOLF_EVENT_TYPE_ASYNC_WOLFCRYPT for WC_ASYNC_DEV*.
* Suppress error message for WC_PENDING_E.
* Implemented "wolfSSL_EVP_MD_CTX_init" to do memset.
* Cleanup of the openssl compat CTX sizes when async is enabled.
* Cleanup of AES, DES3, DH, SHA, MD5, DES3, DH, HMAC, MD5 for consistency and readability.
* Cleanup of the OPAQUE_LEN.
* Cleanup to use ENCRYPT_LEN instead of sizeof(ssl->arrays.preMasterSecret).
* Changed ssl->arrays.preMasterSecret to use XMALLOC (accelerates HW operations)
* Reduce verbosity with debug enabled for "GetMyVersion", "wolfSSL Using RSA OAEP padding" and "wolfSSL Using RSA PKCSV15 padding".
* Updated RSA un-padding error message so its different than one above it for better debugging.
* Added QAT async enables for each algorithm.
* Refactor of the async init to use _ex.
* Added WC_ASYNC_THRESH_NONE to allow bypass of the async thresholds for testing.
* Reformatted the benchmark results:
PKI: "RSA 2048 private HW 18522 ops took 1.003 sec, avg 0.054 ms, 18467.763 ops/sec"
Crypto/Hashing: SHA-256 SW 350 megs took 1.009 seconds, 346.946 MB/s Cycles per byte = 9.87
* Added min execution time for all benchmarks.
* Moved wc_*GetHash and wc_*RestorePos to appropriate files so use of isCopy flag is local.
* Fix for ECC sign status sometimes being invalid due to uninitialized ECC digest in benchmark.
* Added new DECLARE_VAR/FREE_VAR and DECLARE_ARRAY/FREE_ARRAY macros for helping setup test/benchmark variables to accelerate async.
* Added NO_SW_BENCH option to only run HW bench.
* Added support for PRNG to use hardware SHA256 if _wc devId provided.
* Fix to prevent curve tests from running against wrong curve sizes. Changed wc_ecc_set_curve to match on exact size.
* Added the wc_*GetHash calls to the wolfCrypt tests.
* Added async hardware start/stop to wolfSSL init/cleanup.
* Refactor to add wc_*Copy for hashing context (for async), which replaces wc_*RestorePos.
* Fixes for building with TI hashing (including: SHA224, missing new API’s and building with dummy build for non hw testing). Note: We need to add build test for this `./configure CFLAGS="-DWOLFSSL_TI_HASH -DTI_DUMMY_BUILD”`.
* Added arg checks on wc_*GetHash and wc_*Copy.
* Cleanup of the BuildMD5, BuildSHA, BuildMD5_CertVerify and BuildSHA_CertVerify functions.
* Added new ./configure --enable-asyncthreads, to allow enable/disable of the async threading support. If --enable-asynccrypt set this will be enabled by default if pthread is supported. Allows multi-threaded benchmarks with async simulator.
* Added checks for all hashing to verify valid ->buffLen.
* Fix for SHA512 scan-build warning about un-initialized “W_X”.
* Fix for valgrind un-initialized use of buffer in AllocDer (der->buffer) and BuildTlsFinished handshake_hash.
* Refactor of the benchmarking to use common function for start, check and finish of the stats.
* Fixed issue with ECC cache loading in multi-threading.
* Fix bug with AESNI not aligned code that assumes XMALLOC is 16-byte aligned.
* Added new WC_ASYNC_NO_… options to allow disabling of individual async algorithms. New defines are: WC_ASYNC_NO_CRYPT, WC_ASYNC_NO_PKI and WC_ASYNC_NO_HASH. Additionally each algorithm has a WC_ASYNC_NO_[ALGO] define.
* Added “wolfSSL_GetAllocators” API and fixed the wolfCrypt memcb_test so it restores callback pointers after test is complete (fixes issue with using custom allocators and test breaking it).
2017-04-07 15:46:32 -07:00
|
|
|
int keylen;
|
2015-01-05 14:59:48 -07:00
|
|
|
|
|
|
|
ALIGN16 word32 reg[AES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
|
|
|
|
ALIGN16 word32 tmp[AES_BLOCK_SIZE / sizeof(word32)]; /* same */
|
|
|
|
|
2018-03-15 17:05:30 -07:00
|
|
|
#if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
|
|
|
|
word32 invokeCtr[2];
|
|
|
|
word32 nonceSz;
|
|
|
|
#endif
|
2015-01-05 14:59:48 -07:00
|
|
|
#ifdef HAVE_AESGCM
|
2023-02-10 11:48:59 +10:00
|
|
|
Gcm gcm;
|
2019-08-08 12:44:22 -07:00
|
|
|
|
2021-08-20 12:59:41 -06:00
|
|
|
#ifdef WOLFSSL_SE050
|
|
|
|
sss_symmetric_t aes_ctx; /* used as the function context */
|
|
|
|
int ctxInitDone;
|
2022-10-19 10:10:48 -06:00
|
|
|
word32 keyId;
|
|
|
|
byte keyIdSet;
|
|
|
|
byte useSWCrypt; /* Use SW crypt instead of SE050, before SCP03 auth */
|
2021-08-20 12:59:41 -06:00
|
|
|
#endif
|
2019-10-04 11:21:56 -07:00
|
|
|
#ifdef HAVE_CAVIUM_OCTEON_SYNC
|
|
|
|
word32 y0;
|
|
|
|
#endif
|
2015-01-05 14:59:48 -07:00
|
|
|
#endif /* HAVE_AESGCM */
|
2022-07-22 16:19:55 -07:00
|
|
|
#ifdef WOLFSSL_CAAM
|
|
|
|
int blackKey; /* black key / hsm key id */
|
|
|
|
#endif
|
2015-01-05 14:59:48 -07:00
|
|
|
#ifdef WOLFSSL_AESNI
|
|
|
|
byte use_aesni;
|
|
|
|
#endif /* WOLFSSL_AESNI */
|
2019-01-17 11:01:14 -08:00
|
|
|
#ifdef WOLF_CRYPTO_CB
|
2019-01-09 17:39:05 -08:00
|
|
|
int devId;
|
2019-02-06 13:32:10 -08:00
|
|
|
void* devCtx;
|
2018-09-12 08:56:59 +10:00
|
|
|
#endif
|
2022-03-17 14:12:13 -07:00
|
|
|
#ifdef WOLF_PRIVATE_KEY_ID
|
2018-09-12 08:56:59 +10:00
|
|
|
byte id[AES_MAX_ID_LEN];
|
|
|
|
int idLen;
|
2020-10-23 13:57:46 +10:00
|
|
|
char label[AES_MAX_LABEL_LEN];
|
|
|
|
int labelLen;
|
2018-09-12 08:56:59 +10:00
|
|
|
#endif
|
2019-10-22 09:35:26 -07:00
|
|
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
Intel QuickAssist (QAT) support and async enhancements/fixes:
* Adds ./configure "--with-intelqa=../QAT1.6”, port files, memory management and README.md (see wolfcrypt/src/port/intel/).
* Added Intel QAT support for RSA public/private (CRT/non-CRT), AES CBC/GCM, ECDH/ECDSA, DH, DES3, SHA, SHA224, SHA256, SHA384, SHA512, MD5 and HMAC.
* wolfSSL async enabled all client and server: PKI, Encrypt/Decrypt, Hashing/HMAC and Certificate Sign/Verify.
* wolfSSL async support in functions: Encrypt, Decrypt, VerifyMAC, BuildMessage, ConfirmSignature, DoCertificate, ParseCertRelative, and MakeSignature.
* wolfCrypt test and benchmark async support added for all HW acceleration.
* wolfCrypt benchmark multi-threading support.
* Added QuickAssist memory overrides for XMALLOC, XFREE and XREALLOC. XREALLOC determines if existing pointer needs reallocated for NUMA.
* Refactor to make sure “heap” is available for async dev init.
* Added async support for all examples for connect, accept, read and write.
* Added new WC_BIGINT (in wolfmath.c) for async hardware support.
* Added async simulator tests for DES3 CBC, AES CBC/GCM.
* Added QAT standalone build for unit testing.
* Added int return code to SHA and MD5 functions.
* Refactor of the async stack variable handling, so async operations have generic args buffer area and cleanup function pointer.
* Combined duplicate code for async push/pop handling.
* Refactor internal.c to add AllocKey / FreeKey.
* Refactor of hash init/free in TLS to use InitHashes and FreeHashes.
* Refactor of the async event->context to use WOLF_EVENT_TYPE_ASYNC_WOLFSSL for WOLFSSL* and WOLF_EVENT_TYPE_ASYNC_WOLFCRYPT for WC_ASYNC_DEV*.
* Suppress error message for WC_PENDING_E.
* Implemented "wolfSSL_EVP_MD_CTX_init" to do memset.
* Cleanup of the openssl compat CTX sizes when async is enabled.
* Cleanup of AES, DES3, DH, SHA, MD5, DES3, DH, HMAC, MD5 for consistency and readability.
* Cleanup of the OPAQUE_LEN.
* Cleanup to use ENCRYPT_LEN instead of sizeof(ssl->arrays.preMasterSecret).
* Changed ssl->arrays.preMasterSecret to use XMALLOC (accelerates HW operations)
* Reduce verbosity with debug enabled for "GetMyVersion", "wolfSSL Using RSA OAEP padding" and "wolfSSL Using RSA PKCSV15 padding".
* Updated RSA un-padding error message so its different than one above it for better debugging.
* Added QAT async enables for each algorithm.
* Refactor of the async init to use _ex.
* Added WC_ASYNC_THRESH_NONE to allow bypass of the async thresholds for testing.
* Reformatted the benchmark results:
PKI: "RSA 2048 private HW 18522 ops took 1.003 sec, avg 0.054 ms, 18467.763 ops/sec"
Crypto/Hashing: SHA-256 SW 350 megs took 1.009 seconds, 346.946 MB/s Cycles per byte = 9.87
* Added min execution time for all benchmarks.
* Moved wc_*GetHash and wc_*RestorePos to appropriate files so use of isCopy flag is local.
* Fix for ECC sign status sometimes being invalid due to uninitialized ECC digest in benchmark.
* Added new DECLARE_VAR/FREE_VAR and DECLARE_ARRAY/FREE_ARRAY macros for helping setup test/benchmark variables to accelerate async.
* Added NO_SW_BENCH option to only run HW bench.
* Added support for PRNG to use hardware SHA256 if _wc devId provided.
* Fix to prevent curve tests from running against wrong curve sizes. Changed wc_ecc_set_curve to match on exact size.
* Added the wc_*GetHash calls to the wolfCrypt tests.
* Added async hardware start/stop to wolfSSL init/cleanup.
* Refactor to add wc_*Copy for hashing context (for async), which replaces wc_*RestorePos.
* Fixes for building with TI hashing (including: SHA224, missing new API’s and building with dummy build for non hw testing). Note: We need to add build test for this `./configure CFLAGS="-DWOLFSSL_TI_HASH -DTI_DUMMY_BUILD”`.
* Added arg checks on wc_*GetHash and wc_*Copy.
* Cleanup of the BuildMD5, BuildSHA, BuildMD5_CertVerify and BuildSHA_CertVerify functions.
* Added new ./configure --enable-asyncthreads, to allow enable/disable of the async threading support. If --enable-asynccrypt set this will be enabled by default if pthread is supported. Allows multi-threaded benchmarks with async simulator.
* Added checks for all hashing to verify valid ->buffLen.
* Fix for SHA512 scan-build warning about un-initialized “W_X”.
* Fix for valgrind un-initialized use of buffer in AllocDer (der->buffer) and BuildTlsFinished handshake_hash.
* Refactor of the benchmarking to use common function for start, check and finish of the stats.
* Fixed issue with ECC cache loading in multi-threading.
* Fix bug with AESNI not aligned code that assumes XMALLOC is 16-byte aligned.
* Added new WC_ASYNC_NO_… options to allow disabling of individual async algorithms. New defines are: WC_ASYNC_NO_CRYPT, WC_ASYNC_NO_PKI and WC_ASYNC_NO_HASH. Additionally each algorithm has a WC_ASYNC_NO_[ALGO] define.
* Added “wolfSSL_GetAllocators” API and fixed the wolfCrypt memcb_test so it restores callback pointers after test is complete (fixes issue with using custom allocators and test breaking it).
2017-04-07 15:46:32 -07:00
|
|
|
WC_ASYNC_DEV asyncDev;
|
2016-08-15 13:59:41 -06:00
|
|
|
#endif /* WOLFSSL_ASYNC_CRYPT */
|
2020-01-21 15:51:12 -08:00
|
|
|
#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \
|
2020-01-28 21:46:04 -06:00
|
|
|
defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS)
|
2016-01-29 16:13:09 -08:00
|
|
|
word32 left; /* unused bytes left from last call */
|
2015-01-05 14:59:48 -07:00
|
|
|
#endif
|
2017-06-07 11:37:21 -06:00
|
|
|
#ifdef WOLFSSL_XILINX_CRYPT
|
2022-05-20 14:28:39 +02:00
|
|
|
#ifdef WOLFSSL_XILINX_CRYPT_VERSAL
|
|
|
|
wc_Xsecure xSec;
|
|
|
|
XSecure_AesKeySize xKeySize;
|
|
|
|
int aadStyle;
|
|
|
|
byte keyInit[WOLFSSL_XSECURE_AES_KEY_SIZE] ALIGN64;
|
|
|
|
#else
|
2017-06-07 11:37:21 -06:00
|
|
|
XSecure_Aes xilAes;
|
|
|
|
XCsuDma dma;
|
2022-05-20 14:28:39 +02:00
|
|
|
word32 keyInit[8];
|
|
|
|
#endif
|
2017-06-07 11:37:21 -06:00
|
|
|
word32 kup;
|
2018-07-18 17:26:25 -06:00
|
|
|
#endif
|
2018-08-24 10:24:53 -06:00
|
|
|
#if defined(WOLFSSL_AFALG) || defined(WOLFSSL_AFALG_XILINX_AES)
|
2018-07-18 17:26:25 -06:00
|
|
|
int alFd; /* server socket to bind to */
|
|
|
|
int rdFd; /* socket to read from */
|
|
|
|
struct msghdr msg;
|
|
|
|
int dir; /* flag for encrpyt or decrypt */
|
2018-08-24 10:24:53 -06:00
|
|
|
#ifdef WOLFSSL_AFALG_XILINX_AES
|
|
|
|
word32 msgBuf[CMSG_SPACE(4) + CMSG_SPACE(sizeof(struct af_alg_iv) +
|
|
|
|
GCM_NONCE_MID_SZ)];
|
|
|
|
#endif
|
2018-08-17 09:46:16 -06:00
|
|
|
#endif
|
2021-08-19 11:25:59 +10:00
|
|
|
#if defined(WOLFSSL_KCAPI_AES)
|
|
|
|
struct kcapi_handle* handle;
|
|
|
|
int init;
|
|
|
|
#endif
|
2019-02-06 13:32:10 -08:00
|
|
|
#if defined(WOLF_CRYPTO_CB) || (defined(WOLFSSL_DEVCRYPTO) && \
|
2019-10-14 15:39:46 -07:00
|
|
|
(defined(WOLFSSL_DEVCRYPTO_AES) || defined(WOLFSSL_DEVCRYPTO_CBC))) || \
|
2021-08-19 11:25:59 +10:00
|
|
|
(defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_AES)) || \
|
|
|
|
defined(WOLFSSL_KCAPI_AES)
|
2019-02-06 13:32:10 -08:00
|
|
|
word32 devKey[AES_MAX_KEY_SIZE/WOLFSSL_BIT_SIZE/sizeof(word32)]; /* raw key */
|
2019-10-14 16:55:24 -07:00
|
|
|
#ifdef HAVE_CAVIUM_OCTEON_SYNC
|
2019-10-07 17:33:51 -07:00
|
|
|
int keySet;
|
2019-02-06 13:32:10 -08:00
|
|
|
#endif
|
|
|
|
#endif
|
2018-09-20 15:59:29 -06:00
|
|
|
#if defined(WOLFSSL_DEVCRYPTO) && \
|
|
|
|
(defined(WOLFSSL_DEVCRYPTO_AES) || defined(WOLFSSL_DEVCRYPTO_CBC))
|
2018-08-17 09:46:16 -06:00
|
|
|
WC_CRYPTODEV ctx;
|
2019-03-27 20:44:38 -07:00
|
|
|
#endif
|
|
|
|
#if defined(WOLFSSL_CRYPTOCELL)
|
|
|
|
aes_context_t ctx;
|
2019-08-19 17:32:22 +09:00
|
|
|
#endif
|
|
|
|
#if defined(WOLFSSL_RENESAS_TSIP_TLS) && \
|
|
|
|
defined(WOLFSSL_RENESAS_TSIP_TLS_AES_CRYPT)
|
|
|
|
TSIP_AES_CTX ctx;
|
2020-09-18 11:46:08 +02:00
|
|
|
#endif
|
2023-04-14 06:10:35 +09:00
|
|
|
#if defined(WOLFSSL_RENESAS_SCEPROTECT) ||\
|
|
|
|
defined(WOLFSSL_RENESAS_SCEPROTECT_CRYPTONLY)
|
2021-10-30 20:21:21 +09:00
|
|
|
SCE_AES_CTX ctx;
|
|
|
|
#endif
|
2020-09-18 11:46:08 +02:00
|
|
|
#if defined(WOLFSSL_IMXRT_DCP)
|
|
|
|
dcp_handle_t handle;
|
2020-11-06 12:20:03 -08:00
|
|
|
#endif
|
|
|
|
#if defined(WOLFSSL_SILABS_SE_ACCEL)
|
|
|
|
silabs_aes_t ctx;
|
2021-12-22 17:41:01 +01:00
|
|
|
#endif
|
2022-09-21 03:21:33 -04:00
|
|
|
#ifdef WOLFSSL_MAXQ10XX_CRYPTO
|
|
|
|
maxq_aes_t maxq_ctx;
|
|
|
|
#endif
|
2021-12-22 17:41:01 +01:00
|
|
|
#if defined(WOLFSSL_HAVE_PSA) && !defined(WOLFSSL_PSA_NO_AES)
|
|
|
|
psa_key_id_t key_id;
|
|
|
|
psa_cipher_operation_t psa_ctx;
|
|
|
|
int ctx_initialized;
|
|
|
|
int key_need_importing;
|
2017-08-30 17:50:15 -06:00
|
|
|
#endif
|
2017-09-01 15:32:55 -06:00
|
|
|
void* heap; /* memory hint to use */
|
2021-03-04 16:01:45 +10:00
|
|
|
#ifdef WOLFSSL_AESGCM_STREAM
|
2021-03-17 11:31:03 +10:00
|
|
|
#if !defined(WOLFSSL_SMALL_STACK) || defined(WOLFSSL_AESNI)
|
|
|
|
ALIGN16 byte streamData[5 * AES_BLOCK_SIZE];
|
|
|
|
#else
|
|
|
|
byte* streamData;
|
|
|
|
#endif
|
2021-03-04 16:01:45 +10:00
|
|
|
word32 aSz;
|
|
|
|
word32 cSz;
|
|
|
|
byte over;
|
|
|
|
byte aOver;
|
|
|
|
byte cOver;
|
|
|
|
byte gcmKeySet:1;
|
|
|
|
byte nonceSet:1;
|
|
|
|
byte ctrSet:1;
|
|
|
|
#endif
|
2019-09-09 19:24:45 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef WC_AES_TYPE_DEFINED
|
|
|
|
typedef struct Aes Aes;
|
|
|
|
#define WC_AES_TYPE_DEFINED
|
|
|
|
#endif
|
2015-01-05 14:59:48 -07:00
|
|
|
|
2017-09-08 16:00:33 -06:00
|
|
|
#ifdef WOLFSSL_AES_XTS
|
|
|
|
typedef struct XtsAes {
|
|
|
|
Aes aes;
|
|
|
|
Aes tweak;
|
|
|
|
} XtsAes;
|
|
|
|
#endif
|
2015-01-05 14:59:48 -07:00
|
|
|
|
|
|
|
#ifdef HAVE_AESGCM
|
|
|
|
typedef struct Gmac {
|
|
|
|
Aes aes;
|
|
|
|
} Gmac;
|
|
|
|
#endif /* HAVE_AESGCM */
|
2015-01-01 07:33:07 -07:00
|
|
|
#endif /* HAVE_FIPS */
|
|
|
|
|
Intel QuickAssist (QAT) support and async enhancements/fixes:
* Adds ./configure "--with-intelqa=../QAT1.6”, port files, memory management and README.md (see wolfcrypt/src/port/intel/).
* Added Intel QAT support for RSA public/private (CRT/non-CRT), AES CBC/GCM, ECDH/ECDSA, DH, DES3, SHA, SHA224, SHA256, SHA384, SHA512, MD5 and HMAC.
* wolfSSL async enabled all client and server: PKI, Encrypt/Decrypt, Hashing/HMAC and Certificate Sign/Verify.
* wolfSSL async support in functions: Encrypt, Decrypt, VerifyMAC, BuildMessage, ConfirmSignature, DoCertificate, ParseCertRelative, and MakeSignature.
* wolfCrypt test and benchmark async support added for all HW acceleration.
* wolfCrypt benchmark multi-threading support.
* Added QuickAssist memory overrides for XMALLOC, XFREE and XREALLOC. XREALLOC determines if existing pointer needs reallocated for NUMA.
* Refactor to make sure “heap” is available for async dev init.
* Added async support for all examples for connect, accept, read and write.
* Added new WC_BIGINT (in wolfmath.c) for async hardware support.
* Added async simulator tests for DES3 CBC, AES CBC/GCM.
* Added QAT standalone build for unit testing.
* Added int return code to SHA and MD5 functions.
* Refactor of the async stack variable handling, so async operations have generic args buffer area and cleanup function pointer.
* Combined duplicate code for async push/pop handling.
* Refactor internal.c to add AllocKey / FreeKey.
* Refactor of hash init/free in TLS to use InitHashes and FreeHashes.
* Refactor of the async event->context to use WOLF_EVENT_TYPE_ASYNC_WOLFSSL for WOLFSSL* and WOLF_EVENT_TYPE_ASYNC_WOLFCRYPT for WC_ASYNC_DEV*.
* Suppress error message for WC_PENDING_E.
* Implemented "wolfSSL_EVP_MD_CTX_init" to do memset.
* Cleanup of the openssl compat CTX sizes when async is enabled.
* Cleanup of AES, DES3, DH, SHA, MD5, DES3, DH, HMAC, MD5 for consistency and readability.
* Cleanup of the OPAQUE_LEN.
* Cleanup to use ENCRYPT_LEN instead of sizeof(ssl->arrays.preMasterSecret).
* Changed ssl->arrays.preMasterSecret to use XMALLOC (accelerates HW operations)
* Reduce verbosity with debug enabled for "GetMyVersion", "wolfSSL Using RSA OAEP padding" and "wolfSSL Using RSA PKCSV15 padding".
* Updated RSA un-padding error message so its different than one above it for better debugging.
* Added QAT async enables for each algorithm.
* Refactor of the async init to use _ex.
* Added WC_ASYNC_THRESH_NONE to allow bypass of the async thresholds for testing.
* Reformatted the benchmark results:
PKI: "RSA 2048 private HW 18522 ops took 1.003 sec, avg 0.054 ms, 18467.763 ops/sec"
Crypto/Hashing: SHA-256 SW 350 megs took 1.009 seconds, 346.946 MB/s Cycles per byte = 9.87
* Added min execution time for all benchmarks.
* Moved wc_*GetHash and wc_*RestorePos to appropriate files so use of isCopy flag is local.
* Fix for ECC sign status sometimes being invalid due to uninitialized ECC digest in benchmark.
* Added new DECLARE_VAR/FREE_VAR and DECLARE_ARRAY/FREE_ARRAY macros for helping setup test/benchmark variables to accelerate async.
* Added NO_SW_BENCH option to only run HW bench.
* Added support for PRNG to use hardware SHA256 if _wc devId provided.
* Fix to prevent curve tests from running against wrong curve sizes. Changed wc_ecc_set_curve to match on exact size.
* Added the wc_*GetHash calls to the wolfCrypt tests.
* Added async hardware start/stop to wolfSSL init/cleanup.
* Refactor to add wc_*Copy for hashing context (for async), which replaces wc_*RestorePos.
* Fixes for building with TI hashing (including: SHA224, missing new API’s and building with dummy build for non hw testing). Note: We need to add build test for this `./configure CFLAGS="-DWOLFSSL_TI_HASH -DTI_DUMMY_BUILD”`.
* Added arg checks on wc_*GetHash and wc_*Copy.
* Cleanup of the BuildMD5, BuildSHA, BuildMD5_CertVerify and BuildSHA_CertVerify functions.
* Added new ./configure --enable-asyncthreads, to allow enable/disable of the async threading support. If --enable-asynccrypt set this will be enabled by default if pthread is supported. Allows multi-threaded benchmarks with async simulator.
* Added checks for all hashing to verify valid ->buffLen.
* Fix for SHA512 scan-build warning about un-initialized “W_X”.
* Fix for valgrind un-initialized use of buffer in AllocDer (der->buffer) and BuildTlsFinished handshake_hash.
* Refactor of the benchmarking to use common function for start, check and finish of the stats.
* Fixed issue with ECC cache loading in multi-threading.
* Fix bug with AESNI not aligned code that assumes XMALLOC is 16-byte aligned.
* Added new WC_ASYNC_NO_… options to allow disabling of individual async algorithms. New defines are: WC_ASYNC_NO_CRYPT, WC_ASYNC_NO_PKI and WC_ASYNC_NO_HASH. Additionally each algorithm has a WC_ASYNC_NO_[ALGO] define.
* Added “wolfSSL_GetAllocators” API and fixed the wolfCrypt memcb_test so it restores callback pointers after test is complete (fixes issue with using custom allocators and test breaking it).
2017-04-07 15:46:32 -07:00
|
|
|
|
|
|
|
/* Authenticate cipher function prototypes */
|
|
|
|
typedef int (*wc_AesAuthEncryptFunc)(Aes* aes, byte* out,
|
|
|
|
const byte* in, word32 sz,
|
|
|
|
const byte* iv, word32 ivSz,
|
|
|
|
byte* authTag, word32 authTagSz,
|
|
|
|
const byte* authIn, word32 authInSz);
|
|
|
|
typedef int (*wc_AesAuthDecryptFunc)(Aes* aes, byte* out,
|
|
|
|
const byte* in, word32 sz,
|
|
|
|
const byte* iv, word32 ivSz,
|
|
|
|
const byte* authTag, word32 authTagSz,
|
|
|
|
const byte* authIn, word32 authInSz);
|
|
|
|
|
|
|
|
/* AES-CBC */
|
2015-07-22 14:18:07 +02:00
|
|
|
WOLFSSL_API int wc_AesSetKey(Aes* aes, const byte* key, word32 len,
|
|
|
|
const byte* iv, int dir);
|
|
|
|
WOLFSSL_API int wc_AesSetIV(Aes* aes, const byte* iv);
|
2018-11-15 14:08:40 -07:00
|
|
|
|
|
|
|
#ifdef HAVE_AES_CBC
|
2015-07-22 14:18:07 +02:00
|
|
|
WOLFSSL_API int wc_AesCbcEncrypt(Aes* aes, byte* out,
|
|
|
|
const byte* in, word32 sz);
|
|
|
|
WOLFSSL_API int wc_AesCbcDecrypt(Aes* aes, byte* out,
|
|
|
|
const byte* in, word32 sz);
|
2018-11-15 14:08:40 -07:00
|
|
|
#endif
|
2016-10-13 22:10:50 +09:00
|
|
|
|
2018-01-12 11:05:43 -07:00
|
|
|
#ifdef WOLFSSL_AES_CFB
|
2017-03-03 13:20:46 -07:00
|
|
|
WOLFSSL_API int wc_AesCfbEncrypt(Aes* aes, byte* out,
|
|
|
|
const byte* in, word32 sz);
|
2020-01-29 09:59:51 -07:00
|
|
|
WOLFSSL_API int wc_AesCfb1Encrypt(Aes* aes, byte* out,
|
|
|
|
const byte* in, word32 sz);
|
|
|
|
WOLFSSL_API int wc_AesCfb8Encrypt(Aes* aes, byte* out,
|
|
|
|
const byte* in, word32 sz);
|
2017-03-03 13:20:46 -07:00
|
|
|
#ifdef HAVE_AES_DECRYPT
|
|
|
|
WOLFSSL_API int wc_AesCfbDecrypt(Aes* aes, byte* out,
|
|
|
|
const byte* in, word32 sz);
|
2020-01-29 09:59:51 -07:00
|
|
|
WOLFSSL_API int wc_AesCfb1Decrypt(Aes* aes, byte* out,
|
|
|
|
const byte* in, word32 sz);
|
|
|
|
WOLFSSL_API int wc_AesCfb8Decrypt(Aes* aes, byte* out,
|
|
|
|
const byte* in, word32 sz);
|
2017-03-03 13:20:46 -07:00
|
|
|
#endif /* HAVE_AES_DECRYPT */
|
2018-01-12 11:05:43 -07:00
|
|
|
#endif /* WOLFSSL_AES_CFB */
|
2017-03-03 13:20:46 -07:00
|
|
|
|
2020-01-21 15:51:12 -08:00
|
|
|
#ifdef WOLFSSL_AES_OFB
|
|
|
|
WOLFSSL_API int wc_AesOfbEncrypt(Aes* aes, byte* out,
|
|
|
|
const byte* in, word32 sz);
|
|
|
|
#ifdef HAVE_AES_DECRYPT
|
|
|
|
WOLFSSL_API int wc_AesOfbDecrypt(Aes* aes, byte* out,
|
|
|
|
const byte* in, word32 sz);
|
|
|
|
#endif /* HAVE_AES_DECRYPT */
|
|
|
|
#endif /* WOLFSSL_AES_OFB */
|
|
|
|
|
2016-10-13 22:10:50 +09:00
|
|
|
#ifdef HAVE_AES_ECB
|
|
|
|
WOLFSSL_API int wc_AesEcbEncrypt(Aes* aes, byte* out,
|
|
|
|
const byte* in, word32 sz);
|
|
|
|
WOLFSSL_API int wc_AesEcbDecrypt(Aes* aes, byte* out,
|
|
|
|
const byte* in, word32 sz);
|
|
|
|
#endif
|
2015-01-05 14:59:48 -07:00
|
|
|
|
2014-12-17 09:58:11 -07:00
|
|
|
/* AES-CTR */
|
2014-12-29 14:35:46 -07:00
|
|
|
#ifdef WOLFSSL_AES_COUNTER
|
2017-05-22 22:10:49 -06:00
|
|
|
WOLFSSL_API int wc_AesCtrEncrypt(Aes* aes, byte* out,
|
2015-07-22 14:18:07 +02:00
|
|
|
const byte* in, word32 sz);
|
2014-12-17 09:58:11 -07:00
|
|
|
#endif
|
|
|
|
/* AES-DIRECT */
|
2014-12-29 14:35:46 -07:00
|
|
|
#if defined(WOLFSSL_AES_DIRECT)
|
2022-01-21 14:48:12 -06:00
|
|
|
#if defined(HAVE_FIPS) && \
|
|
|
|
(!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
|
2014-12-18 11:44:48 -07:00
|
|
|
WOLFSSL_API void wc_AesEncryptDirect(Aes* aes, byte* out, const byte* in);
|
|
|
|
WOLFSSL_API void wc_AesDecryptDirect(Aes* aes, byte* out, const byte* in);
|
2022-01-21 14:48:12 -06:00
|
|
|
WOLFSSL_API int wc_AesSetKeyDirect(Aes* aes, const byte* key, word32 len,
|
2014-12-17 09:58:11 -07:00
|
|
|
const byte* iv, int dir);
|
2022-01-21 14:48:12 -06:00
|
|
|
#elif defined(BUILDING_WOLFSSL)
|
2022-01-24 12:32:25 -06:00
|
|
|
WOLFSSL_API WARN_UNUSED_RESULT int wc_AesEncryptDirect(Aes* aes, byte* out,
|
|
|
|
const byte* in);
|
|
|
|
WOLFSSL_API WARN_UNUSED_RESULT int wc_AesDecryptDirect(Aes* aes, byte* out,
|
|
|
|
const byte* in);
|
|
|
|
WOLFSSL_API WARN_UNUSED_RESULT int wc_AesSetKeyDirect(Aes* aes,
|
|
|
|
const byte* key,
|
|
|
|
word32 len,
|
2022-01-21 14:48:12 -06:00
|
|
|
const byte* iv, int dir);
|
|
|
|
#else
|
|
|
|
WOLFSSL_API int wc_AesEncryptDirect(Aes* aes, byte* out, const byte* in);
|
|
|
|
WOLFSSL_API int wc_AesDecryptDirect(Aes* aes, byte* out, const byte* in);
|
|
|
|
WOLFSSL_API int wc_AesSetKeyDirect(Aes* aes, const byte* key, word32 len,
|
|
|
|
const byte* iv, int dir);
|
|
|
|
#endif
|
2014-12-17 09:58:11 -07:00
|
|
|
#endif
|
2018-03-15 17:05:30 -07:00
|
|
|
|
2014-12-17 09:58:11 -07:00
|
|
|
#ifdef HAVE_AESGCM
|
2017-06-07 11:37:21 -06:00
|
|
|
#ifdef WOLFSSL_XILINX_CRYPT
|
|
|
|
WOLFSSL_API int wc_AesGcmSetKey_ex(Aes* aes, const byte* key, word32 len,
|
|
|
|
word32 kup);
|
2018-08-24 10:24:53 -06:00
|
|
|
#elif defined(WOLFSSL_AFALG_XILINX_AES)
|
|
|
|
WOLFSSL_LOCAL int wc_AesGcmSetKey_ex(Aes* aes, const byte* key, word32 len,
|
|
|
|
word32 kup);
|
2017-06-07 11:37:21 -06:00
|
|
|
#endif
|
2014-12-18 11:44:48 -07:00
|
|
|
WOLFSSL_API int wc_AesGcmSetKey(Aes* aes, const byte* key, word32 len);
|
2015-07-22 14:18:07 +02:00
|
|
|
WOLFSSL_API int wc_AesGcmEncrypt(Aes* aes, byte* out,
|
|
|
|
const byte* in, word32 sz,
|
|
|
|
const byte* iv, word32 ivSz,
|
|
|
|
byte* authTag, word32 authTagSz,
|
|
|
|
const byte* authIn, word32 authInSz);
|
|
|
|
WOLFSSL_API int wc_AesGcmDecrypt(Aes* aes, byte* out,
|
|
|
|
const byte* in, word32 sz,
|
|
|
|
const byte* iv, word32 ivSz,
|
|
|
|
const byte* authTag, word32 authTagSz,
|
|
|
|
const byte* authIn, word32 authInSz);
|
2021-03-04 16:01:45 +10:00
|
|
|
#ifdef WOLFSSL_AESGCM_STREAM
|
|
|
|
WOLFSSL_API int wc_AesGcmInit(Aes* aes, const byte* key, word32 len,
|
|
|
|
const byte* iv, word32 ivSz);
|
|
|
|
|
2021-03-17 11:31:03 +10:00
|
|
|
WOLFSSL_API int wc_AesGcmEncryptInit(Aes* aes, const byte* key, word32 len,
|
|
|
|
const byte* iv, word32 ivSz);
|
2021-03-04 16:01:45 +10:00
|
|
|
WOLFSSL_API int wc_AesGcmEncryptInit_ex(Aes* aes, const byte* key, word32 len,
|
|
|
|
byte* ivOut, word32 ivOutSz);
|
|
|
|
WOLFSSL_API int wc_AesGcmEncryptUpdate(Aes* aes, byte* out, const byte* in,
|
|
|
|
word32 sz, const byte* authIn, word32 authInSz);
|
|
|
|
WOLFSSL_API int wc_AesGcmEncryptFinal(Aes* aes, byte* authTag,
|
|
|
|
word32 authTagSz);
|
|
|
|
|
2021-03-17 11:31:03 +10:00
|
|
|
WOLFSSL_API int wc_AesGcmDecryptInit(Aes* aes, const byte* key, word32 len,
|
|
|
|
const byte* iv, word32 ivSz);
|
2021-03-04 16:01:45 +10:00
|
|
|
WOLFSSL_API int wc_AesGcmDecryptUpdate(Aes* aes, byte* out, const byte* in,
|
|
|
|
word32 sz, const byte* authIn, word32 authInSz);
|
|
|
|
WOLFSSL_API int wc_AesGcmDecryptFinal(Aes* aes, const byte* authTag,
|
|
|
|
word32 authTagSz);
|
|
|
|
#endif
|
2014-12-17 09:58:11 -07:00
|
|
|
|
2018-03-06 16:45:44 -08:00
|
|
|
#ifndef WC_NO_RNG
|
2018-03-20 13:40:44 -07:00
|
|
|
WOLFSSL_API int wc_AesGcmSetExtIV(Aes* aes, const byte* iv, word32 ivSz);
|
|
|
|
WOLFSSL_API int wc_AesGcmSetIV(Aes* aes, word32 ivSz,
|
2018-03-15 17:05:30 -07:00
|
|
|
const byte* ivFixed, word32 ivFixedSz,
|
|
|
|
WC_RNG* rng);
|
2018-02-05 13:50:30 -08:00
|
|
|
WOLFSSL_API int wc_AesGcmEncrypt_ex(Aes* aes, byte* out,
|
2018-03-15 17:05:30 -07:00
|
|
|
const byte* in, word32 sz,
|
|
|
|
byte* ivOut, word32 ivOutSz,
|
|
|
|
byte* authTag, word32 authTagSz,
|
|
|
|
const byte* authIn, word32 authInSz);
|
2018-03-06 16:45:44 -08:00
|
|
|
#endif /* WC_NO_RNG */
|
2018-02-05 13:50:30 -08:00
|
|
|
|
2014-12-18 11:44:48 -07:00
|
|
|
WOLFSSL_API int wc_GmacSetKey(Gmac* gmac, const byte* key, word32 len);
|
|
|
|
WOLFSSL_API int wc_GmacUpdate(Gmac* gmac, const byte* iv, word32 ivSz,
|
2015-07-22 14:18:07 +02:00
|
|
|
const byte* authIn, word32 authInSz,
|
|
|
|
byte* authTag, word32 authTagSz);
|
2018-03-15 17:05:30 -07:00
|
|
|
#ifndef WC_NO_RNG
|
|
|
|
WOLFSSL_API int wc_Gmac(const byte* key, word32 keySz, byte* iv, word32 ivSz,
|
|
|
|
const byte* authIn, word32 authInSz,
|
|
|
|
byte* authTag, word32 authTagSz, WC_RNG* rng);
|
|
|
|
WOLFSSL_API int wc_GmacVerify(const byte* key, word32 keySz,
|
|
|
|
const byte* iv, word32 ivSz,
|
|
|
|
const byte* authIn, word32 authInSz,
|
|
|
|
const byte* authTag, word32 authTagSz);
|
|
|
|
#endif /* WC_NO_RNG */
|
2014-12-17 09:58:11 -07:00
|
|
|
#endif /* HAVE_AESGCM */
|
|
|
|
#ifdef HAVE_AESCCM
|
2020-04-28 14:46:06 -06:00
|
|
|
WOLFSSL_LOCAL int wc_AesCcmCheckTagSize(int sz);
|
2016-10-12 10:02:53 -06:00
|
|
|
WOLFSSL_API int wc_AesCcmSetKey(Aes* aes, const byte* key, word32 keySz);
|
2015-10-02 11:40:47 -06:00
|
|
|
WOLFSSL_API int wc_AesCcmEncrypt(Aes* aes, byte* out,
|
2015-07-22 14:18:07 +02:00
|
|
|
const byte* in, word32 inSz,
|
|
|
|
const byte* nonce, word32 nonceSz,
|
|
|
|
byte* authTag, word32 authTagSz,
|
|
|
|
const byte* authIn, word32 authInSz);
|
|
|
|
WOLFSSL_API int wc_AesCcmDecrypt(Aes* aes, byte* out,
|
|
|
|
const byte* in, word32 inSz,
|
|
|
|
const byte* nonce, word32 nonceSz,
|
|
|
|
const byte* authTag, word32 authTagSz,
|
|
|
|
const byte* authIn, word32 authInSz);
|
2018-03-15 17:05:30 -07:00
|
|
|
WOLFSSL_API int wc_AesCcmSetNonce(Aes* aes,
|
|
|
|
const byte* nonce, word32 nonceSz);
|
|
|
|
WOLFSSL_API int wc_AesCcmEncrypt_ex(Aes* aes, byte* out,
|
|
|
|
const byte* in, word32 sz,
|
|
|
|
byte* ivOut, word32 ivOutSz,
|
|
|
|
byte* authTag, word32 authTagSz,
|
|
|
|
const byte* authIn, word32 authInSz);
|
2014-12-17 09:58:11 -07:00
|
|
|
#endif /* HAVE_AESCCM */
|
2016-12-05 15:38:42 -07:00
|
|
|
#ifdef HAVE_AES_KEYWRAP
|
|
|
|
WOLFSSL_API int wc_AesKeyWrap(const byte* key, word32 keySz,
|
|
|
|
const byte* in, word32 inSz,
|
|
|
|
byte* out, word32 outSz,
|
|
|
|
const byte* iv);
|
2021-02-25 20:01:51 +01:00
|
|
|
WOLFSSL_API int wc_AesKeyWrap_ex(Aes *aes,
|
|
|
|
const byte* in, word32 inSz,
|
|
|
|
byte* out, word32 outSz,
|
|
|
|
const byte* iv);
|
2016-12-05 15:38:42 -07:00
|
|
|
WOLFSSL_API int wc_AesKeyUnWrap(const byte* key, word32 keySz,
|
|
|
|
const byte* in, word32 inSz,
|
|
|
|
byte* out, word32 outSz,
|
|
|
|
const byte* iv);
|
2021-02-25 20:01:51 +01:00
|
|
|
WOLFSSL_API int wc_AesKeyUnWrap_ex(Aes *aes,
|
|
|
|
const byte* in, word32 inSz,
|
|
|
|
byte* out, word32 outSz,
|
|
|
|
const byte* iv);
|
2016-12-05 15:38:42 -07:00
|
|
|
#endif /* HAVE_AES_KEYWRAP */
|
2014-12-17 09:58:11 -07:00
|
|
|
|
2017-08-30 17:50:15 -06:00
|
|
|
#ifdef WOLFSSL_AES_XTS
|
2017-08-30 13:51:17 -06:00
|
|
|
|
2017-09-08 16:00:33 -06:00
|
|
|
WOLFSSL_API int wc_AesXtsSetKey(XtsAes* aes, const byte* key,
|
2017-08-30 13:51:17 -06:00
|
|
|
word32 len, int dir, void* heap, int devId);
|
|
|
|
|
2017-09-08 16:00:33 -06:00
|
|
|
WOLFSSL_API int wc_AesXtsEncryptSector(XtsAes* aes, byte* out,
|
2017-08-30 13:51:17 -06:00
|
|
|
const byte* in, word32 sz, word64 sector);
|
|
|
|
|
2017-09-08 16:00:33 -06:00
|
|
|
WOLFSSL_API int wc_AesXtsDecryptSector(XtsAes* aes, byte* out,
|
2017-08-30 13:51:17 -06:00
|
|
|
const byte* in, word32 sz, word64 sector);
|
|
|
|
|
2017-09-08 16:00:33 -06:00
|
|
|
WOLFSSL_API int wc_AesXtsEncrypt(XtsAes* aes, byte* out,
|
2017-08-30 13:51:17 -06:00
|
|
|
const byte* in, word32 sz, const byte* i, word32 iSz);
|
|
|
|
|
2017-09-08 16:00:33 -06:00
|
|
|
WOLFSSL_API int wc_AesXtsDecrypt(XtsAes* aes, byte* out,
|
2017-08-30 17:50:15 -06:00
|
|
|
const byte* in, word32 sz, const byte* i, word32 iSz);
|
2017-09-08 16:00:33 -06:00
|
|
|
|
|
|
|
WOLFSSL_API int wc_AesXtsFree(XtsAes* aes);
|
2017-08-30 17:50:15 -06:00
|
|
|
#endif
|
|
|
|
|
2016-06-15 14:34:59 -07:00
|
|
|
WOLFSSL_API int wc_AesGetKeySize(Aes* aes, word32* keySize);
|
|
|
|
|
2018-09-12 08:56:59 +10:00
|
|
|
WOLFSSL_API int wc_AesInit(Aes* aes, void* heap, int devId);
|
2022-03-17 14:12:13 -07:00
|
|
|
#ifdef WOLF_PRIVATE_KEY_ID
|
2018-09-12 08:56:59 +10:00
|
|
|
WOLFSSL_API int wc_AesInit_Id(Aes* aes, unsigned char* id, int len, void* heap,
|
|
|
|
int devId);
|
2020-11-02 17:13:10 +10:00
|
|
|
WOLFSSL_API int wc_AesInit_Label(Aes* aes, const char* label, void* heap,
|
|
|
|
int devId);
|
2018-09-12 08:56:59 +10:00
|
|
|
#endif
|
|
|
|
WOLFSSL_API void wc_AesFree(Aes* aes);
|
2014-12-17 09:58:11 -07:00
|
|
|
|
2022-01-14 16:52:03 -08:00
|
|
|
#ifdef WOLFSSL_AES_SIV
|
|
|
|
WOLFSSL_API
|
|
|
|
int wc_AesSivEncrypt(const byte* key, word32 keySz, const byte* assoc,
|
|
|
|
word32 assocSz, const byte* nonce, word32 nonceSz,
|
|
|
|
const byte* in, word32 inSz, byte* siv, byte* out);
|
|
|
|
WOLFSSL_API
|
|
|
|
int wc_AesSivDecrypt(const byte* key, word32 keySz, const byte* assoc,
|
|
|
|
word32 assocSz, const byte* nonce, word32 nonceSz,
|
|
|
|
const byte* in, word32 inSz, byte* siv, byte* out);
|
|
|
|
#endif
|
|
|
|
|
2014-12-17 09:58:11 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} /* extern "C" */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* NO_AES */
|
2015-02-26 12:29:15 -08:00
|
|
|
#endif /* WOLF_CRYPT_AES_H */
|