From 279f1498283386a9f38f9d81dac4242618e813ea Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Fri, 19 Dec 2014 16:31:01 -0700 Subject: [PATCH] adjustments to reverse compatibility --- ctaocrypt/benchmark/benchmark.c | 147 --------------- cyassl/ctaocrypt/ecc.h | 324 ++++++++++++++++---------------- cyassl/ctaocrypt/visibility.h | 3 +- cyassl/ssl.h | 43 +++++ src/include.am | 3 +- wolfcrypt/benchmark/benchmark.c | 151 --------------- wolfcrypt/src/chacha.c | 12 +- wolfcrypt/src/ecc.c | 2 +- wolfcrypt/src/poly1305.c | 12 +- wolfssl/wolfcrypt/chacha.h | 12 ++ wolfssl/wolfcrypt/visibility.h | 3 +- 11 files changed, 234 insertions(+), 478 deletions(-) diff --git a/ctaocrypt/benchmark/benchmark.c b/ctaocrypt/benchmark/benchmark.c index 0e724eb53..58932f352 100644 --- a/ctaocrypt/benchmark/benchmark.c +++ b/ctaocrypt/benchmark/benchmark.c @@ -93,153 +93,6 @@ /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */ #pragma warning(disable: 4996) #endif -#include -#include - -#ifdef HAVE_CAVIUM - static void wc_Arc4CaviumSetKey(Arc4* arc4, const byte* key, word32 length); - static void wc_Arc4CaviumProcess(Arc4* arc4, byte* out, const byte* in, - word32 length); -#endif - - -void wc_Arc4SetKey(Arc4* arc4, const byte* key, word32 length) -{ - word32 i; - word32 keyIndex = 0, stateIndex = 0; - -#ifdef HAVE_CAVIUM - if (arc4->magic == WOLFSSL_ARC4_CAVIUM_MAGIC) - return wc_Arc4CaviumSetKey(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; - } -} - - -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]; -} - - -void wc_Arc4Process(Arc4* arc4, byte* out, const byte* in, word32 length) -{ - word32 x; - word32 y; - -#ifdef HAVE_CAVIUM - if (arc4->magic == WOLFSSL_ARC4_CAVIUM_MAGIC) - return wc_Arc4CaviumProcess(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; -} - - -#ifdef HAVE_CAVIUM - -#include -#include "cavium_common.h" - -/* Initiliaze Arc4 for use with Nitrox device */ -int wc_Arc4InitCavium(Arc4* arc4, int devId) -{ - if (arc4 == NULL) - return -1; - - if (CspAllocContext(CONTEXT_SSL, &arc4->contextHandle, devId) != 0) - return -1; - - arc4->devId = devId; - arc4->magic = WOLFSSL_ARC4_CAVIUM_MAGIC; - - return 0; -} - - -/* Free Arc4 from use with Nitrox device */ -void wc_Arc4FreeCavium(Arc4* arc4) -{ - if (arc4 == NULL) - return; - - if (arc4->magic != WOLFSSL_ARC4_CAVIUM_MAGIC) - return; - - CspFreeContext(CONTEXT_SSL, arc4->contextHandle, arc4->devId); - arc4->magic = 0; -} - - -static void wc_Arc4CaviumSetKey(Arc4* arc4, const byte* key, word32 length) -{ - word32 requestId; - - if (CspInitializeRc4(CAVIUM_BLOCKING, arc4->contextHandle, length, - (byte*)key, &requestId, arc4->devId) != 0) { - WOLFSSL_MSG("Bad Cavium Arc4 Init"); - } -} - - -static void wc_Arc4CaviumProcess(Arc4* arc4, byte* out, const byte* in, - word32 length) -{ - cyassl_word offset = 0; - word32 requestId; - - while (length > WOLFSSL_MAX_16BIT) { - word16 slen = (word16)WOLFSSL_MAX_16BIT; - if (CspEncryptRc4(CAVIUM_BLOCKING, arc4->contextHandle,CAVIUM_UPDATE, - slen, (byte*)in + offset, out + offset, &requestId, - arc4->devId) != 0) { - WOLFSSL_MSG("Bad Cavium Arc4 Encrypt"); - } - length -= WOLFSSL_MAX_16BIT; - offset += WOLFSSL_MAX_16BIT; - } - if (length) { - word16 slen = (word16)length; - if (CspEncryptRc4(CAVIUM_BLOCKING, arc4->contextHandle,CAVIUM_UPDATE, - slen, (byte*)in + offset, out + offset, &requestId, - arc4->devId) != 0) { - WOLFSSL_MSG("Bad Cavium Arc4 Encrypt"); - } - } -} - -#endif /* HAVE_CAVIUM */ void bench_des(void); diff --git a/cyassl/ctaocrypt/ecc.h b/cyassl/ctaocrypt/ecc.h index bfb0d7b75..291dddc96 100644 --- a/cyassl/ctaocrypt/ecc.h +++ b/cyassl/ctaocrypt/ecc.h @@ -24,167 +24,169 @@ #ifndef CTAO_CRYPT_ECC_H #define CTAO_CRYPT_ECC_H -#include -#include -#include - -#ifdef __cplusplus - extern "C" { -#endif - - -enum { - ECC_PUBLICKEY = 1, - ECC_PRIVATEKEY = 2, - ECC_MAXNAME = 16, /* MAX CURVE NAME LENGTH */ - SIG_HEADER_SZ = 6, /* ECC signature header size */ - ECC_BUFSIZE = 256, /* for exported keys temp buffer */ - ECC_MINSIZE = 20, /* MIN Private Key size */ - ECC_MAXSIZE = 66 /* MAX Private Key size */ -}; - - -/* ECC set type defined a NIST GF(p) curve */ -typedef struct { - int size; /* The size of the curve in octets */ - const char* name; /* name of this curve */ - const char* prime; /* prime that defines the field, curve is in (hex) */ - const char* Af; /* fields A param (hex) */ - const char* Bf; /* fields B param (hex) */ - const char* order; /* order of the curve (hex) */ - const char* Gx; /* x coordinate of the base point on curve (hex) */ - const char* Gy; /* y coordinate of the base point on curve (hex) */ -} ecc_set_type; - - -/* A point on an ECC curve, stored in Jacbobian format such that (x,y,z) => - (x/z^2, y/z^3, 1) when interpreted as affine */ -typedef struct { - mp_int x; /* The x coordinate */ - mp_int y; /* The y coordinate */ - mp_int z; /* The z coordinate */ -} ecc_point; - - -/* An ECC Key */ -typedef struct { - int type; /* Public or Private */ - int idx; /* Index into the ecc_sets[] for the parameters of - this curve if -1, this key is using user supplied - curve in dp */ - const ecc_set_type* dp; /* domain parameters, either points to NIST - curves (idx >= 0) or user supplied */ - ecc_point pubkey; /* public key */ - mp_int k; /* private key */ -} ecc_key; - - -/* ECC predefined curve sets */ -extern const ecc_set_type ecc_sets[]; - - -CYASSL_API -int ecc_make_key(RNG* rng, int keysize, ecc_key* key); -CYASSL_API -int ecc_shared_secret(ecc_key* private_key, ecc_key* public_key, byte* out, - word32* outlen); -CYASSL_API -int ecc_sign_hash(const byte* in, word32 inlen, byte* out, word32 *outlen, - RNG* rng, ecc_key* key); -CYASSL_API -int ecc_verify_hash(const byte* sig, word32 siglen, const byte* hash, - word32 hashlen, int* stat, ecc_key* key); -CYASSL_API -void ecc_init(ecc_key* key); -CYASSL_API -void ecc_free(ecc_key* key); -CYASSL_API -void ecc_fp_free(void); - - -/* ASN key helpers */ -CYASSL_API -int ecc_export_x963(ecc_key*, byte* out, word32* outLen); -CYASSL_API -int ecc_export_x963_ex(ecc_key*, byte* out, word32* outLen, int compressed); - /* extended functionality with compressed option */ -CYASSL_API -int ecc_import_x963(const byte* in, word32 inLen, ecc_key* key); -CYASSL_API -int ecc_import_private_key(const byte* priv, word32 privSz, const byte* pub, - word32 pubSz, ecc_key* key); -CYASSL_API -int ecc_rs_to_sig(const char* r, const char* s, byte* out, word32* outlen); -CYASSL_API -int ecc_import_raw(ecc_key* key, const char* qx, const char* qy, - const char* d, const char* curveName); - -CYASSL_API -int ecc_export_private_only(ecc_key* key, byte* out, word32* outLen); - -/* size helper */ -CYASSL_API -int ecc_size(ecc_key* key); -CYASSL_API -int ecc_sig_size(ecc_key* key); - - -#ifdef HAVE_ECC_ENCRYPT -/* ecc encrypt */ - -enum ecEncAlgo { - ecAES_128_CBC = 1, /* default */ - ecAES_256_CBC = 2 -}; - -enum ecKdfAlgo { - ecHKDF_SHA256 = 1, /* default */ - ecHKDF_SHA1 = 2 -}; - -enum ecMacAlgo { - ecHMAC_SHA256 = 1, /* default */ - ecHMAC_SHA1 = 2 -}; - -enum { - KEY_SIZE_128 = 16, - KEY_SIZE_256 = 32, - IV_SIZE_64 = 8, - EXCHANGE_SALT_SZ = 16, - EXCHANGE_INFO_SZ = 23 -}; - -enum ecFlags { - REQ_RESP_CLIENT = 1, - REQ_RESP_SERVER = 2 -}; - - -typedef struct ecEncCtx ecEncCtx; - -CYASSL_API -ecEncCtx* ecc_ctx_new(int flags, RNG* rng); -CYASSL_API -void ecc_ctx_free(ecEncCtx*); -CYASSL_API -int ecc_ctx_reset(ecEncCtx*, RNG*); /* reset for use again w/o alloc/free */ - -CYASSL_API -const byte* ecc_ctx_get_own_salt(ecEncCtx*); -CYASSL_API -int ecc_ctx_set_peer_salt(ecEncCtx*, const byte* salt); -CYASSL_API -int ecc_ctx_set_info(ecEncCtx*, const byte* info, int sz); - -CYASSL_API -int ecc_encrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg, - word32 msgSz, byte* out, word32* outSz, ecEncCtx* ctx); -CYASSL_API -int ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg, - word32 msgSz, byte* out, word32* outSz, ecEncCtx* ctx); - -#endif /* HAVE_ECC_ENCRYPT */ +#include +// +//#include +//#include +//#include +// +//#ifdef __cplusplus +// extern "C" { +//#endif +// +// +//enum { +// ECC_PUBLICKEY = 1, +// ECC_PRIVATEKEY = 2, +// ECC_MAXNAME = 16, /* MAX CURVE NAME LENGTH */ +// SIG_HEADER_SZ = 6, /* ECC signature header size */ +// ECC_BUFSIZE = 256, /* for exported keys temp buffer */ +// ECC_MINSIZE = 20, /* MIN Private Key size */ +// ECC_MAXSIZE = 66 /* MAX Private Key size */ +//}; +// +// +///* ECC set type defined a NIST GF(p) curve */ +//typedef struct { +// int size; /* The size of the curve in octets */ +// const char* name; /* name of this curve */ +// const char* prime; /* prime that defines the field, curve is in (hex) */ +// const char* Af; /* fields A param (hex) */ +// const char* Bf; /* fields B param (hex) */ +// const char* order; /* order of the curve (hex) */ +// const char* Gx; /* x coordinate of the base point on curve (hex) */ +// const char* Gy; /* y coordinate of the base point on curve (hex) */ +//} ecc_set_type; +// +// +///* A point on an ECC curve, stored in Jacbobian format such that (x,y,z) => +// (x/z^2, y/z^3, 1) when interpreted as affine */ +//typedef struct { +// mp_int x; /* The x coordinate */ +// mp_int y; /* The y coordinate */ +// mp_int z; /* The z coordinate */ +//} ecc_point; +// +// +///* An ECC Key */ +//typedef struct { +// int type; /* Public or Private */ +// int idx; /* Index into the ecc_sets[] for the parameters of +// this curve if -1, this key is using user supplied +// curve in dp */ +// const ecc_set_type* dp; /* domain parameters, either points to NIST +// curves (idx >= 0) or user supplied */ +// ecc_point pubkey; /* public key */ +// mp_int k; /* private key */ +//} ecc_key; +// +// +///* ECC predefined curve sets */ +//extern const ecc_set_type ecc_sets[]; +// +// +//CYASSL_API +//int ecc_make_key(RNG* rng, int keysize, ecc_key* key); +//CYASSL_API +//int ecc_shared_secret(ecc_key* private_key, ecc_key* public_key, byte* out, +// word32* outlen); +//CYASSL_API +//int ecc_sign_hash(const byte* in, word32 inlen, byte* out, word32 *outlen, +// RNG* rng, ecc_key* key); +//CYASSL_API +//int ecc_verify_hash(const byte* sig, word32 siglen, const byte* hash, +// word32 hashlen, int* stat, ecc_key* key); +//CYASSL_API +//void ecc_init(ecc_key* key); +//CYASSL_API +//void ecc_free(ecc_key* key); +//CYASSL_API +//void ecc_fp_free(void); +// +// +///* ASN key helpers */ +//CYASSL_API +//int ecc_export_x963(ecc_key*, byte* out, word32* outLen); +//CYASSL_API +//int ecc_export_x963_ex(ecc_key*, byte* out, word32* outLen, int compressed); +// /* extended functionality with compressed option */ +//CYASSL_API +//int ecc_import_x963(const byte* in, word32 inLen, ecc_key* key); +//CYASSL_API +//int ecc_import_private_key(const byte* priv, word32 privSz, const byte* pub, +// word32 pubSz, ecc_key* key); +//CYASSL_API +//int ecc_rs_to_sig(const char* r, const char* s, byte* out, word32* outlen); +//CYASSL_API +//int ecc_import_raw(ecc_key* key, const char* qx, const char* qy, +// const char* d, const char* curveName); +// +//CYASSL_API +//int ecc_export_private_only(ecc_key* key, byte* out, word32* outLen); +// +///* size helper */ +//CYASSL_API +//int ecc_size(ecc_key* key); +//CYASSL_API +//int ecc_sig_size(ecc_key* key); +// +// +//#ifdef HAVE_ECC_ENCRYPT +///* ecc encrypt */ +// +//enum ecEncAlgo { +// ecAES_128_CBC = 1, /* default */ +// ecAES_256_CBC = 2 +//}; +// +//enum ecKdfAlgo { +// ecHKDF_SHA256 = 1, /* default */ +// ecHKDF_SHA1 = 2 +//}; +// +//enum ecMacAlgo { +// ecHMAC_SHA256 = 1, /* default */ +// ecHMAC_SHA1 = 2 +//}; +// +//enum { +// KEY_SIZE_128 = 16, +// KEY_SIZE_256 = 32, +// IV_SIZE_64 = 8, +// EXCHANGE_SALT_SZ = 16, +// EXCHANGE_INFO_SZ = 23 +//}; +// +//enum ecFlags { +// REQ_RESP_CLIENT = 1, +// REQ_RESP_SERVER = 2 +//}; +// +// +//typedef struct ecEncCtx ecEncCtx; +// +//CYASSL_API +//ecEncCtx* ecc_ctx_new(int flags, RNG* rng); +//CYASSL_API +//void ecc_ctx_free(ecEncCtx*); +//CYASSL_API +//int ecc_ctx_reset(ecEncCtx*, RNG*); /* reset for use again w/o alloc/free */ +// +//CYASSL_API +//const byte* ecc_ctx_get_own_salt(ecEncCtx*); +//CYASSL_API +//int ecc_ctx_set_peer_salt(ecEncCtx*, const byte* salt); +//CYASSL_API +//int ecc_ctx_set_info(ecEncCtx*, const byte* info, int sz); +// +//CYASSL_API +//int ecc_encrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg, +// word32 msgSz, byte* out, word32* outSz, ecEncCtx* ctx); +//CYASSL_API +//int ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg, +// word32 msgSz, byte* out, word32* outSz, ecEncCtx* ctx); +// +//#endif /* HAVE_ECC_ENCRYPT */ #ifdef __cplusplus } /* extern "C" */ diff --git a/cyassl/ctaocrypt/visibility.h b/cyassl/ctaocrypt/visibility.h index 625157d5e..8aa29b279 100644 --- a/cyassl/ctaocrypt/visibility.h +++ b/cyassl/ctaocrypt/visibility.h @@ -42,8 +42,7 @@ #ifdef CYASSL_DLL #define CYASSL_API extern __declspec(dllexport) #else - //#define CYASSL_API - #define CYASSL_API: + #define CYASSL_API #endif #define CYASSL_LOCAL #else diff --git a/cyassl/ssl.h b/cyassl/ssl.h index 42d01b1bc..ae09e3029 100644 --- a/cyassl/ssl.h +++ b/cyassl/ssl.h @@ -386,8 +386,10 @@ #define CYASSL_SMALL_STACK #endif +/* change visibility to be compatible with CyaSSL visibility */ #undef WOLFSSL_API #define WOLFSSL_API CYASSL_API + #define WOLFSSL_ENTER(x) CYASSL_ENTER(x) /* @TODO*/ #define WOLFSSL_BIT_SIZE CYASSL_BIT_SIZE /* @TODO*/ @@ -535,6 +537,47 @@ #endif +/* for chacha reverse compatibility */ +#ifdef HAVE_CHACHA + #define Chacha_Process wc_Chacha_Process + #define Chacha_SetKey wc_Chacha_SetKey + #define Chacha_SetIV wc_Chacha_SetIV +#endif + + +/* for ecc reverse compatibility */ +#ifdef HAVE_ECC +#define ecc_make_key wc_ecc_make_key +#define ecc_shared_secret wc_ecc_shared_secret +#define ecc_sign_hash wc_ecc_sign_hash +#define ecc_verify_hash wc_ecc_verify_hash +#define ecc_init wc_ecc_init +#define ecc_free wc_ecc_free +#define ecc_fp_free wc_ecc_fp_free +#define ecc_export_x963 wc_ecc_export_x963 +#define ecc_export_x963_ex wc_ecc_export_x963_ex +#define ecc_import_x963 wc_ecc_import_x963 +#define ecc_import_private_key wc_ecc_import_private_key +#define ecc_rs_to_sig wc_ecc_rs_to_sig +#define ecc_import_raw wc_ecc_import_raw +#define ecc_export_private_only wc_ecc_export_private_only +#define ecc_size wc_ecc_size +#define ecc_sig_size wc_ecc_sig_size + +#ifdef HAVE_ECC_ENCRYPT +/* ecc encrypt */ +//ecEncCtx* wc_ecc_ctx_new(int flags, RNG* rng); +//void wc_ecc_ctx_free(ecEncCtx*); +//int wc_ecc_ctx_reset(ecEncCtx*, RNG*); /* reset for use again w/o alloc/free */ +//const byte* wc_ecc_ctx_get_own_salt(ecEncCtx*); +//int wc_ecc_ctx_set_peer_salt(ecEncCtx*, const byte* salt); +//int wc_ecc_ctx_set_info(ecEncCtx*, const byte* info, int sz); +//int wc_ecc_encrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg, +//int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg, +#endif /* HAVE_ECC_ENCRYPT */ +#endif + + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/include.am b/src/include.am index 2554448b3..a9e3b562a 100644 --- a/src/include.am +++ b/src/include.am @@ -179,8 +179,7 @@ src_libwolfssl_la_SOURCES += ctaocrypt/src/integer.c \ endif if BUILD_ECC -src_libwolfssl_la_SOURCES += ctaocrypt/src/ecc.c \ - wolfcrypt/src/ecc.c +src_libwolfssl_la_SOURCES += wolfcrypt/src/ecc.c endif if BUILD_LIBZ diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index 9f0ecb089..5fd341995 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -94,157 +94,6 @@ #pragma warning(disable: 4996) #endif -//#ifndef NO_RC4 -//#include -//#include -//#endif -// -//#ifdef HAVE_CAVIUM -// static void wc_wc_Arc4CaviumSetKey(Arc4* arc4, const byte* key, word32 length); -// static void wc_wc_Arc4CaviumProcess(Arc4* arc4, byte* out, const byte* in, -// word32 length); -//#endif -// -// -//void wc_wc_Arc4SetKey(Arc4* arc4, const byte* key, word32 length) -//{ -// word32 i; -// word32 keyIndex = 0, stateIndex = 0; -// -//#ifdef HAVE_CAVIUM -// if (arc4->magic == WOLFSSL_ARC4_CAVIUM_MAGIC) -// return wc_wc_Arc4CaviumSetKey(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; -// } -//} -// -// -//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]; -//} -// -// -//void wc_wc_Arc4Process(Arc4* arc4, byte* out, const byte* in, word32 length) -//{ -// word32 x; -// word32 y; -// -//#ifdef HAVE_CAVIUM -// if (arc4->magic == WOLFSSL_ARC4_CAVIUM_MAGIC) -// return wc_wc_Arc4CaviumProcess(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; -//} -// -// -//#ifdef HAVE_CAVIUM -// -//#include -//#include "cavium_common.h" -// -///* Initiliaze wc_Arc4 for use with Nitrox device */ -//int wc_wc_Arc4InitCavium(Arc4* arc4, int devId) -//{ -// if (arc4 == NULL) -// return -1; -// -// if (CspAllocContext(CONTEXT_SSL, &arc4->contextHandle, devId) != 0) -// return -1; -// -// arc4->devId = devId; -// arc4->magic = WOLFSSL_ARC4_CAVIUM_MAGIC; -// -// return 0; -//} -// -// -///* Free wc_Arc4 from use with Nitrox device */ -//void wc_wc_Arc4FreeCavium(Arc4* arc4) -//{ -// if (arc4 == NULL) -// return; -// -// if (arc4->magic != WOLFSSL_ARC4_CAVIUM_MAGIC) -// return; -// -// CspFreeContext(CONTEXT_SSL, arc4->contextHandle, arc4->devId); -// arc4->magic = 0; -//} -// -// -//static void wc_wc_Arc4CaviumSetKey(Arc4* arc4, const byte* key, word32 length) -//{ -// word32 requestId; -// -// if (CspInitializeRc4(CAVIUM_BLOCKING, arc4->contextHandle, length, -// (byte*)key, &requestId, arc4->devId) != 0) { -// WOLFSSL_MSG("Bad Cavium wc_Arc4 Init"); -// } -//} -// -// -//static void wc_wc_Arc4CaviumProcess(Arc4* arc4, byte* out, const byte* in, -// word32 length) -//{ -// cyassl_word offset = 0; -// word32 requestId; -// -// while (length > WOLFSSL_MAX_16BIT) { -// word16 slen = (word16)WOLFSSL_MAX_16BIT; -// if (CspEncryptRc4(CAVIUM_BLOCKING, arc4->contextHandle,CAVIUM_UPDATE, -// slen, (byte*)in + offset, out + offset, &requestId, -// arc4->devId) != 0) { -// WOLFSSL_MSG("Bad Cavium wc_Arc4 Encrypt"); -// } -// length -= WOLFSSL_MAX_16BIT; -// offset += WOLFSSL_MAX_16BIT; -// } -// if (length) { -// word16 slen = (word16)length; -// if (CspEncryptRc4(CAVIUM_BLOCKING, arc4->contextHandle,CAVIUM_UPDATE, -// slen, (byte*)in + offset, out + offset, &requestId, -// arc4->devId) != 0) { -// WOLFSSL_MSG("Bad Cavium wc_Arc4 Encrypt"); -// } -// } -//} -// -//#endif /* HAVE_CAVIUM */ - - void bench_des(void); void bench_arc4(void); diff --git a/wolfcrypt/src/chacha.c b/wolfcrypt/src/chacha.c index 421d2a06a..64e8e432e 100644 --- a/wolfcrypt/src/chacha.c +++ b/wolfcrypt/src/chacha.c @@ -29,17 +29,17 @@ #include #endif -#include +#include #ifdef HAVE_CHACHA -#include -#include -#include +#include +#include +#include #ifdef NO_INLINE - #include + #include #else - #include + #include #endif #ifdef CHACHA_AEAD_TEST diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index 5bce1efb4..63d7d3fba 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -2221,7 +2221,7 @@ int wc_ecc_export_x963(ecc_key* key, byte* out, word32* outLen) /* export public ECC key in ANSI X9.63 format, extended with * compression option */ -int wc_wc_ecc_export_x963_ex(ecc_key* key, byte* out, word32* outLen, int compressed) +int wc_ecc_export_x963_ex(ecc_key* key, byte* out, word32* outLen, int compressed) { if (compressed == 0) return wc_ecc_export_x963(key, out, outLen); diff --git a/wolfcrypt/src/poly1305.c b/wolfcrypt/src/poly1305.c index 56441b9ab..54a744a91 100644 --- a/wolfcrypt/src/poly1305.c +++ b/wolfcrypt/src/poly1305.c @@ -26,16 +26,16 @@ #include #endif -#include +#include #ifdef HAVE_POLY1305 -#include -#include -#include +#include +#include +#include #ifdef NO_INLINE - #include + #include #else - #include + #include #endif #ifdef CHACHA_AEAD_TEST #include diff --git a/wolfssl/wolfcrypt/chacha.h b/wolfssl/wolfcrypt/chacha.h index 9cb868c9a..922b2c7a1 100644 --- a/wolfssl/wolfcrypt/chacha.h +++ b/wolfssl/wolfcrypt/chacha.h @@ -47,6 +47,18 @@ WOLFSSL_API int wc_Chacha_SetKey(ChaCha* ctx, const byte* key, word32 keySz); */ WOLFSSL_API int wc_Chacha_SetIV(ChaCha* ctx, const byte* inIv, word32 counter); +#ifdef __cplusplus + +WOLFSSL_API int wc_Chacha_Process(ChaCha* ctx, byte* cipher, const byte* plain, + word32 msglen); +WOLFSSL_API int wc_Chacha_SetKey(ChaCha* ctx, const byte* key, word32 keySz); + +/** + * IV(nonce) changes with each record + * counter is for what value the block counter should start ... usually 0 + */ +WOLFSSL_API int wc_Chacha_SetIV(ChaCha* ctx, const byte* inIv, word32 counter); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/wolfssl/wolfcrypt/visibility.h b/wolfssl/wolfcrypt/visibility.h index 3d4335d5a..40d993688 100644 --- a/wolfssl/wolfcrypt/visibility.h +++ b/wolfssl/wolfcrypt/visibility.h @@ -42,8 +42,7 @@ #ifdef WOLFSSL_DLL #define WOLFSSL_API extern __declspec(dllexport) #else - //#define WOLFSSL_API - #define WOLFSSL_API: + #define WOLFSSL_API #endif #define WOLFSSL_LOCAL #else