* 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).
142 lines
3.3 KiB
C
142 lines
3.3 KiB
C
/* arc4.c
|
|
*
|
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
|
*
|
|
* This file is part of wolfSSL.
|
|
*
|
|
* wolfSSL is free software; you can redistribute it and/or modify
|
|
* 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.
|
|
*
|
|
* wolfSSL is distributed in the hope that it will be useful,
|
|
* 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
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
|
*/
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include <config.h>
|
|
#endif
|
|
|
|
#include <wolfssl/wolfcrypt/settings.h>
|
|
|
|
#ifndef NO_RC4
|
|
|
|
#include <wolfssl/wolfcrypt/error-crypt.h>
|
|
#include <wolfssl/wolfcrypt/arc4.h>
|
|
|
|
|
|
int wc_Arc4SetKey(Arc4* arc4, const byte* key, word32 length)
|
|
{
|
|
int ret = 0;
|
|
word32 i;
|
|
word32 keyIndex = 0, stateIndex = 0;
|
|
|
|
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ARC4) && \
|
|
defined(HAVE_CAVIUM) && !defined(HAVE_CAVIUM_V)
|
|
if (arc4->asyncDev.marker == WOLFSSL_ASYNC_MARKER_ARC4) {
|
|
return NitroxArc4SetKey(arc4, key, length);
|
|
}
|
|
#endif
|
|
|
|
arc4->x = 1;
|
|
arc4->y = 0;
|
|
|
|
for (i = 0; i < ARC4_STATE_SIZE; i++)
|
|
arc4->state[i] = (byte)i;
|
|
|
|
for (i = 0; i < ARC4_STATE_SIZE; i++) {
|
|
word32 a = arc4->state[i];
|
|
stateIndex += key[keyIndex] + a;
|
|
stateIndex &= 0xFF;
|
|
arc4->state[i] = arc4->state[stateIndex];
|
|
arc4->state[stateIndex] = (byte)a;
|
|
|
|
if (++keyIndex >= length)
|
|
keyIndex = 0;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
|
|
static INLINE byte MakeByte(word32* x, word32* y, byte* s)
|
|
{
|
|
word32 a = s[*x], b;
|
|
*y = (*y+a) & 0xff;
|
|
|
|
b = s[*y];
|
|
s[*x] = (byte)b;
|
|
s[*y] = (byte)a;
|
|
*x = (*x+1) & 0xff;
|
|
|
|
return s[(a+b) & 0xff];
|
|
}
|
|
|
|
|
|
int wc_Arc4Process(Arc4* arc4, byte* out, const byte* in, word32 length)
|
|
{
|
|
int ret = 0;
|
|
word32 x;
|
|
word32 y;
|
|
|
|
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ARC4) && \
|
|
defined(HAVE_CAVIUM) && !defined(HAVE_CAVIUM_V)
|
|
if (arc4->asyncDev.marker == WOLFSSL_ASYNC_MARKER_ARC4) {
|
|
return NitroxArc4Process(arc4, out, in, length);
|
|
}
|
|
#endif
|
|
|
|
x = arc4->x;
|
|
y = arc4->y;
|
|
|
|
while(length--)
|
|
*out++ = *in++ ^ MakeByte(&x, &y, arc4->state);
|
|
|
|
arc4->x = (byte)x;
|
|
arc4->y = (byte)y;
|
|
|
|
return ret;
|
|
}
|
|
|
|
/* Initialize Arc4 for use with async device */
|
|
int wc_Arc4Init(Arc4* arc4, void* heap, int devId)
|
|
{
|
|
int ret = 0;
|
|
|
|
if (arc4 == NULL)
|
|
return BAD_FUNC_ARG;
|
|
|
|
arc4->heap = heap;
|
|
|
|
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ARC4)
|
|
ret = wolfAsync_DevCtxInit(&arc4->asyncDev, WOLFSSL_ASYNC_MARKER_ARC4,
|
|
arc4->heap, devId);
|
|
#else
|
|
(void)devId;
|
|
#endif /* WOLFSSL_ASYNC_CRYPT */
|
|
|
|
return ret;
|
|
}
|
|
|
|
|
|
/* Free Arc4 from use with async device */
|
|
void wc_Arc4Free(Arc4* arc4)
|
|
{
|
|
if (arc4 == NULL)
|
|
return;
|
|
|
|
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ARC4)
|
|
wolfAsync_DevCtxFree(&arc4->asyncDev, WOLFSSL_ASYNC_MARKER_ARC4);
|
|
#endif /* WOLFSSL_ASYNC_CRYPT */
|
|
}
|
|
|
|
#endif /* NO_RC4 */
|
|
|