diff --git a/Makefile.am b/Makefile.am index e4f15a297..86d49e5c1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -60,8 +60,8 @@ EXTRA_DIST+= README.md EXTRA_DIST+= LICENSING #-------------------------------------# -include cyassl/include.am include wolfssl/include.am +include cyassl/include.am #-------------------------------------# include certs/include.am include certs/1024/include.am @@ -72,14 +72,14 @@ include swig/include.am include src/include.am include support/include.am #-------------------------------------# -include ctaocrypt/benchmark/include.am include wolfcrypt/benchmark/include.am +include ctaocrypt/benchmark/include.am #-------------------------------------# -include ctaocrypt/src/include.am include wolfcrypt/src/include.am +include ctaocrypt/src/include.am #-------------------------------------# -include ctaocrypt/test/include.am include wolfcrypt/test/include.am +include ctaocrypt/test/include.am #-------------------------------------# include examples/client/include.am include examples/server/include.am diff --git a/ctaocrypt/benchmark/benchmark.c b/ctaocrypt/benchmark/benchmark.c index 6aff3fd5e..0e724eb53 100644 --- a/ctaocrypt/benchmark/benchmark.c +++ b/ctaocrypt/benchmark/benchmark.c @@ -93,6 +93,154 @@ /* 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); void bench_arc4(void); diff --git a/ctaocrypt/test/test.c b/ctaocrypt/test/test.c index d207761ef..1ca3bd418 100644 --- a/ctaocrypt/test/test.c +++ b/ctaocrypt/test/test.c @@ -22,6 +22,8 @@ /* wolfssl_cyassl compatibility layer */ #include +#include + #ifdef HAVE_CONFIG_H #include #endif diff --git a/cyassl/ssl.h b/cyassl/ssl.h index dadf97788..4ba9ac3dc 100644 --- a/cyassl/ssl.h +++ b/cyassl/ssl.h @@ -386,6 +386,8 @@ #define CYASSL_SMALL_STACK #endif +#undef WOLFSSL_API +#define WOLFSSL_API CYASSL_API #define WOLFSSL_ENTER(x) CYASSL_ENTER(x) /* @TODO*/ #define WOLFSSL_BIT_SIZE CYASSL_BIT_SIZE /* @TODO*/ @@ -399,7 +401,8 @@ /* for arc4 reverse compatibility */ #ifndef NO_RC4 - #define CYASSL_ARC4_CAVIUM_MAGIC WOLFSSL_ARC4_CAVIUM_MAGIC +#include + #define CYASSL_ARC4_CAVIUM_MAGIC WOLFSSL_ARC4_CAVIUM_MAGIC #define Arc4Process wc_Arc4Process #define Arc4SetKey wc_Arc4SetKey #define Arc4InitCavium wc_Arc4InitCavium diff --git a/examples/client/client.c b/examples/client/client.c index 895fea870..584375146 100644 --- a/examples/client/client.c +++ b/examples/client/client.c @@ -24,6 +24,7 @@ #endif #include /* name change portability layer */ + #if defined(CYASSL_MDK_ARM) #include #include diff --git a/wolfcrypt/benchmark/benchmark b/wolfcrypt/benchmark/benchmark new file mode 100755 index 000000000..85c097516 --- /dev/null +++ b/wolfcrypt/benchmark/benchmark @@ -0,0 +1,210 @@ +#! /bin/sh + +# wolfcrypt/benchmark/benchmark - temporary wrapper script for .libs/benchmark +# Generated by libtool (GNU libtool) 2.4.2 +# +# The wolfcrypt/benchmark/benchmark program cannot be directly executed until all the libtool +# libraries that it depends on are installed. +# +# This wrapper script should never be moved out of the build directory. +# If it is, it will not operate correctly. + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +sed_quote_subst='s/\([`"$\\]\)/\\\1/g' + +# Be Bourne compatible +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac +fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +relink_command="" + +# This environment variable determines our operation mode. +if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then + # install mode needs the following variables: + generated_by_libtool_version='2.4.2' + notinst_deplibs=' src/libwolfssl.la' +else + # When we are sourced in execute mode, $file and $ECHO are already set. + if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then + file="$0" + +# A function that is used when there is no print builtin or printf. +func_fallback_echo () +{ + eval 'cat <<_LTECHO_EOF +$1 +_LTECHO_EOF' +} + ECHO="printf %s\\n" + fi + +# Very basic option parsing. These options are (a) specific to +# the libtool wrapper, (b) are identical between the wrapper +# /script/ and the wrapper /executable/ which is used only on +# windows platforms, and (c) all begin with the string --lt- +# (application programs are unlikely to have options which match +# this pattern). +# +# There are only two supported options: --lt-debug and +# --lt-dump-script. There is, deliberately, no --lt-help. +# +# The first argument to this parsing function should be the +# script's ./libtool value, followed by no. +lt_option_debug= +func_parse_lt_options () +{ + lt_script_arg0=$0 + shift + for lt_opt + do + case "$lt_opt" in + --lt-debug) lt_option_debug=1 ;; + --lt-dump-script) + lt_dump_D=`$ECHO "X$lt_script_arg0" | /usr/bin/sed -e 's/^X//' -e 's%/[^/]*$%%'` + test "X$lt_dump_D" = "X$lt_script_arg0" && lt_dump_D=. + lt_dump_F=`$ECHO "X$lt_script_arg0" | /usr/bin/sed -e 's/^X//' -e 's%^.*/%%'` + cat "$lt_dump_D/$lt_dump_F" + exit 0 + ;; + --lt-*) + $ECHO "Unrecognized --lt- option: '$lt_opt'" 1>&2 + exit 1 + ;; + esac + done + + # Print the debug banner immediately: + if test -n "$lt_option_debug"; then + echo "benchmark:wolfcrypt/benchmark/benchmark:${LINENO}: libtool wrapper (GNU libtool) 2.4.2" 1>&2 + fi +} + +# Used when --lt-debug. Prints its arguments to stdout +# (redirection is the responsibility of the caller) +func_lt_dump_args () +{ + lt_dump_args_N=1; + for lt_arg + do + $ECHO "benchmark:wolfcrypt/benchmark/benchmark:${LINENO}: newargv[$lt_dump_args_N]: $lt_arg" + lt_dump_args_N=`expr $lt_dump_args_N + 1` + done +} + +# Core function for launching the target application +func_exec_program_core () +{ + + if test -n "$lt_option_debug"; then + $ECHO "benchmark:wolfcrypt/benchmark/benchmark:${LINENO}: newargv[0]: $progdir/$program" 1>&2 + func_lt_dump_args ${1+"$@"} 1>&2 + fi + exec "$progdir/$program" ${1+"$@"} + + $ECHO "$0: cannot exec $program $*" 1>&2 + exit 1 +} + +# A function to encapsulate launching the target application +# Strips options in the --lt-* namespace from $@ and +# launches target application with the remaining arguments. +func_exec_program () +{ + case " $* " in + *\ --lt-*) + for lt_wr_arg + do + case $lt_wr_arg in + --lt-*) ;; + *) set x "$@" "$lt_wr_arg"; shift;; + esac + shift + done ;; + esac + func_exec_program_core ${1+"$@"} +} + + # Parse options + func_parse_lt_options "$0" ${1+"$@"} + + # Find the directory that this script lives in. + thisdir=`$ECHO "$file" | /usr/bin/sed 's%/[^/]*$%%'` + test "x$thisdir" = "x$file" && thisdir=. + + # Follow symbolic links until we get to the real thisdir. + file=`ls -ld "$file" | /usr/bin/sed -n 's/.*-> //p'` + while test -n "$file"; do + destdir=`$ECHO "$file" | /usr/bin/sed 's%/[^/]*$%%'` + + # If there was a directory component, then change thisdir. + if test "x$destdir" != "x$file"; then + case "$destdir" in + [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;; + *) thisdir="$thisdir/$destdir" ;; + esac + fi + + file=`$ECHO "$file" | /usr/bin/sed 's%^.*/%%'` + file=`ls -ld "$thisdir/$file" | /usr/bin/sed -n 's/.*-> //p'` + done + + # Usually 'no', except on cygwin/mingw when embedded into + # the cwrapper. + WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no + if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then + # special case for '.' + if test "$thisdir" = "."; then + thisdir=`pwd` + fi + # remove .libs from thisdir + case "$thisdir" in + *[\\/].libs ) thisdir=`$ECHO "$thisdir" | /usr/bin/sed 's%[\\/][^\\/]*$%%'` ;; + .libs ) thisdir=. ;; + esac + fi + + # Try to get the absolute directory name. + absdir=`cd "$thisdir" && pwd` + test -n "$absdir" && thisdir="$absdir" + + program='benchmark' + progdir="$thisdir/.libs" + + + if test -f "$progdir/$program"; then + # Add our own library path to DYLD_LIBRARY_PATH + DYLD_LIBRARY_PATH="/Users/sweetness/Documents/cyassl-wolfssl/src/.libs:$DYLD_LIBRARY_PATH" + + # Some systems cannot cope with colon-terminated DYLD_LIBRARY_PATH + # The second colon is a workaround for a bug in BeOS R4 sed + DYLD_LIBRARY_PATH=`$ECHO "$DYLD_LIBRARY_PATH" | /usr/bin/sed 's/::*$//'` + + export DYLD_LIBRARY_PATH + + if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then + # Run the actual program with our arguments. + func_exec_program ${1+"$@"} + fi + else + # The program doesn't exist. + $ECHO "$0: error: \`$progdir/$program' does not exist" 1>&2 + $ECHO "This script is just a wrapper for $program." 1>&2 + $ECHO "See the libtool documentation for more information." 1>&2 + exit 1 + fi +fi diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index 9b7118c2b..9f0ecb089 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -94,6 +94,158 @@ #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); void bench_hc128(void); @@ -569,15 +721,15 @@ void bench_arc4(void) int i; #ifdef HAVE_CAVIUM - if (Arc4InitCavium(&enc, CAVIUM_DEV_ID) != 0) + if (wc_Arc4InitCavium(&enc, CAVIUM_DEV_ID) != 0) printf("arc4 init cavium failed\n"); #endif - Arc4SetKey(&enc, key, 16); + wc_Arc4SetKey(&enc, key, 16); start = current_time(1); for(i = 0; i < numBlocks; i++) - Arc4Process(&enc, cipher, plain, sizeof(plain)); + wc_Arc4Process(&enc, cipher, plain, sizeof(plain)); total = current_time(0) - start; persec = 1 / total * numBlocks; @@ -589,7 +741,7 @@ void bench_arc4(void) printf("ARC4 %d %s took %5.3f seconds, %7.3f MB/s\n", numBlocks, blockType, total, persec); #ifdef HAVE_CAVIUM - Arc4FreeCavium(&enc); + wc_Arc4FreeCavium(&enc); #endif } #endif diff --git a/wolfcrypt/src/arc4.c b/wolfcrypt/src/arc4.c index 410ad34f2..7bfbc3920 100644 --- a/wolfcrypt/src/arc4.c +++ b/wolfcrypt/src/arc4.c @@ -23,13 +23,15 @@ #include #endif -#include +#include +//#include +//#undef WOLFSSL_API +//#define WOLFSSL_API CYASSL_API #ifndef NO_RC4 #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, diff --git a/wolfcrypt/src/md2.c b/wolfcrypt/src/md2.c index 3940f28c1..77d6285eb 100644 --- a/wolfcrypt/src/md2.c +++ b/wolfcrypt/src/md2.c @@ -24,17 +24,17 @@ #include #endif -#include +#include #ifdef WOLFSSL_MD2 -#include -#include +#include +#include #ifdef NO_INLINE - #include + #include #else - #include + #include #endif diff --git a/wolfcrypt/src/md5.c b/wolfcrypt/src/md5.c index c59840d7d..3b25c7fd4 100644 --- a/wolfcrypt/src/md5.c +++ b/wolfcrypt/src/md5.c @@ -24,7 +24,7 @@ #include #endif -#include +#include #if !defined(NO_MD5) @@ -35,12 +35,12 @@ #endif #include -#include +#include #ifdef NO_INLINE - #include + #include #else - #include + #include #endif #ifdef FREESCALE_MMCAU diff --git a/wolfcrypt/src/misc.c b/wolfcrypt/src/misc.c new file mode 100644 index 000000000..d542701c9 --- /dev/null +++ b/wolfcrypt/src/misc.c @@ -0,0 +1,173 @@ +/* misc.c + * + * Copyright (C) 2006-2014 wolfSSL Inc. + * + * This file is part of CyaSSL. + * + * CyaSSL 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. + * + * CyaSSL 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-1301, USA + */ + +#ifdef HAVE_CONFIG_H + #include +#endif + +#include + +#include + +/* inlining these functions is a huge speed increase and a small size decrease, + because the functions are smaller than function call setup/cleanup, e.g., + md5 benchmark is twice as fast with inline. If you don't want it, then + define NO_INLINE and compile this file into cyassl, otherwise it's used as + a source header + */ + +#ifdef NO_INLINE + #define STATIC +#else + #define STATIC static +#endif + + +#ifdef INTEL_INTRINSICS + + #include /* get intrinsic definitions */ + + /* for non visual studio probably need no long version, 32 bit only + * i.e., _rotl and _rotr */ + #pragma intrinsic(_lrotl, _lrotr) + + STATIC INLINE word32 rotlFixed(word32 x, word32 y) + { + return y ? _lrotl(x, y) : x; + } + + STATIC INLINE word32 rotrFixed(word32 x, word32 y) + { + return y ? _lrotr(x, y) : x; + } + +#else /* generic */ + + STATIC INLINE word32 rotlFixed(word32 x, word32 y) + { + return (x << y) | (x >> (sizeof(y) * 8 - y)); + } + + + STATIC INLINE word32 rotrFixed(word32 x, word32 y) + { + return (x >> y) | (x << (sizeof(y) * 8 - y)); + } + +#endif + + +STATIC INLINE word32 ByteReverseWord32(word32 value) +{ +#ifdef PPC_INTRINSICS + /* PPC: load reverse indexed instruction */ + return (word32)__lwbrx(&value,0); +#elif defined(KEIL_INTRINSICS) + return (word32)__rev(value); +#elif defined(FAST_ROTATE) + /* 5 instructions with rotate instruction, 9 without */ + return (rotrFixed(value, 8U) & 0xff00ff00) | + (rotlFixed(value, 8U) & 0x00ff00ff); +#else + /* 6 instructions with rotate instruction, 8 without */ + value = ((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8); + return rotlFixed(value, 16U); +#endif +} + + +STATIC INLINE void ByteReverseWords(word32* out, const word32* in, + word32 byteCount) +{ + word32 count = byteCount/(word32)sizeof(word32), i; + + for (i = 0; i < count; i++) + out[i] = ByteReverseWord32(in[i]); + +} + + +#ifdef WORD64_AVAILABLE + + +STATIC INLINE word64 rotlFixed64(word64 x, word64 y) +{ + return (x << y) | (x >> (sizeof(y) * 8 - y)); +} + + +STATIC INLINE word64 rotrFixed64(word64 x, word64 y) +{ + return (x >> y) | (x << (sizeof(y) * 8 - y)); +} + + +STATIC INLINE word64 ByteReverseWord64(word64 value) +{ +#ifdef CTAOCRYPT_SLOW_WORD64 + return (word64)(ByteReverseWord32((word32)value)) << 32 | + ByteReverseWord32((word32)(value>>32)); +#else + value = ((value & W64LIT(0xFF00FF00FF00FF00)) >> 8) | + ((value & W64LIT(0x00FF00FF00FF00FF)) << 8); + value = ((value & W64LIT(0xFFFF0000FFFF0000)) >> 16) | + ((value & W64LIT(0x0000FFFF0000FFFF)) << 16); + return rotlFixed64(value, 32U); +#endif +} + + +STATIC INLINE void ByteReverseWords64(word64* out, const word64* in, + word32 byteCount) +{ + word32 count = byteCount/(word32)sizeof(word64), i; + + for (i = 0; i < count; i++) + out[i] = ByteReverseWord64(in[i]); + +} + +#endif /* WORD64_AVAILABLE */ + + +STATIC INLINE void XorWords(cyassl_word* r, const cyassl_word* a, word32 n) +{ + word32 i; + + for (i = 0; i < n; i++) r[i] ^= a[i]; +} + + +STATIC INLINE void xorbuf(void* buf, const void* mask, word32 count) +{ + if (((cyassl_word)buf | (cyassl_word)mask | count) % CYASSL_WORD_SIZE == 0) + XorWords( (cyassl_word*)buf, + (const cyassl_word*)mask, count / CYASSL_WORD_SIZE); + else { + word32 i; + byte* b = (byte*)buf; + const byte* m = (const byte*)mask; + + for (i = 0; i < count; i++) b[i] ^= m[i]; + } +} +#undef STATIC + diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index dbc3b70ac..6e9ffc56a 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -1676,18 +1676,18 @@ int arc4_test(void) keylen = 4; #ifdef HAVE_CAVIUM - if (Arc4InitCavium(&enc, CAVIUM_DEV_ID) != 0) + if (wc_Arc4InitCavium(&enc, CAVIUM_DEV_ID) != 0) return -20001; - if (Arc4InitCavium(&dec, CAVIUM_DEV_ID) != 0) + if (wc_Arc4InitCavium(&dec, CAVIUM_DEV_ID) != 0) return -20002; #endif - Arc4SetKey(&enc, (byte*)keys[i], keylen); - Arc4SetKey(&dec, (byte*)keys[i], keylen); + wc_Arc4SetKey(&enc, (byte*)keys[i], keylen); + wc_Arc4SetKey(&dec, (byte*)keys[i], keylen); - Arc4Process(&enc, cipher, (byte*)test_arc4[i].input, + wc_Arc4Process(&enc, cipher, (byte*)test_arc4[i].input, (word32)test_arc4[i].outLen); - Arc4Process(&dec, plain, cipher, (word32)test_arc4[i].outLen); + wc_Arc4Process(&dec, plain, cipher, (word32)test_arc4[i].outLen); if (memcmp(plain, test_arc4[i].input, test_arc4[i].outLen)) return -20 - i; @@ -1696,8 +1696,8 @@ int arc4_test(void) return -20 - 5 - i; #ifdef HAVE_CAVIUM - Arc4FreeCavium(&enc); - Arc4FreeCavium(&dec); + wc_Arc4FreeCavium(&enc); + wc_Arc4FreeCavium(&dec); #endif } diff --git a/wolfcrypt/test/testwolfcrypt b/wolfcrypt/test/testwolfcrypt new file mode 100755 index 000000000..d502da959 --- /dev/null +++ b/wolfcrypt/test/testwolfcrypt @@ -0,0 +1,210 @@ +#! /bin/sh + +# wolfcrypt/test/testwolfcrypt - temporary wrapper script for .libs/testwolfcrypt +# Generated by libtool (GNU libtool) 2.4.2 +# +# The wolfcrypt/test/testwolfcrypt program cannot be directly executed until all the libtool +# libraries that it depends on are installed. +# +# This wrapper script should never be moved out of the build directory. +# If it is, it will not operate correctly. + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +sed_quote_subst='s/\([`"$\\]\)/\\\1/g' + +# Be Bourne compatible +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac +fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +relink_command="" + +# This environment variable determines our operation mode. +if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then + # install mode needs the following variables: + generated_by_libtool_version='2.4.2' + notinst_deplibs=' src/libwolfssl.la' +else + # When we are sourced in execute mode, $file and $ECHO are already set. + if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then + file="$0" + +# A function that is used when there is no print builtin or printf. +func_fallback_echo () +{ + eval 'cat <<_LTECHO_EOF +$1 +_LTECHO_EOF' +} + ECHO="printf %s\\n" + fi + +# Very basic option parsing. These options are (a) specific to +# the libtool wrapper, (b) are identical between the wrapper +# /script/ and the wrapper /executable/ which is used only on +# windows platforms, and (c) all begin with the string --lt- +# (application programs are unlikely to have options which match +# this pattern). +# +# There are only two supported options: --lt-debug and +# --lt-dump-script. There is, deliberately, no --lt-help. +# +# The first argument to this parsing function should be the +# script's ./libtool value, followed by no. +lt_option_debug= +func_parse_lt_options () +{ + lt_script_arg0=$0 + shift + for lt_opt + do + case "$lt_opt" in + --lt-debug) lt_option_debug=1 ;; + --lt-dump-script) + lt_dump_D=`$ECHO "X$lt_script_arg0" | /usr/bin/sed -e 's/^X//' -e 's%/[^/]*$%%'` + test "X$lt_dump_D" = "X$lt_script_arg0" && lt_dump_D=. + lt_dump_F=`$ECHO "X$lt_script_arg0" | /usr/bin/sed -e 's/^X//' -e 's%^.*/%%'` + cat "$lt_dump_D/$lt_dump_F" + exit 0 + ;; + --lt-*) + $ECHO "Unrecognized --lt- option: '$lt_opt'" 1>&2 + exit 1 + ;; + esac + done + + # Print the debug banner immediately: + if test -n "$lt_option_debug"; then + echo "testwolfcrypt:wolfcrypt/test/testwolfcrypt:${LINENO}: libtool wrapper (GNU libtool) 2.4.2" 1>&2 + fi +} + +# Used when --lt-debug. Prints its arguments to stdout +# (redirection is the responsibility of the caller) +func_lt_dump_args () +{ + lt_dump_args_N=1; + for lt_arg + do + $ECHO "testwolfcrypt:wolfcrypt/test/testwolfcrypt:${LINENO}: newargv[$lt_dump_args_N]: $lt_arg" + lt_dump_args_N=`expr $lt_dump_args_N + 1` + done +} + +# Core function for launching the target application +func_exec_program_core () +{ + + if test -n "$lt_option_debug"; then + $ECHO "testwolfcrypt:wolfcrypt/test/testwolfcrypt:${LINENO}: newargv[0]: $progdir/$program" 1>&2 + func_lt_dump_args ${1+"$@"} 1>&2 + fi + exec "$progdir/$program" ${1+"$@"} + + $ECHO "$0: cannot exec $program $*" 1>&2 + exit 1 +} + +# A function to encapsulate launching the target application +# Strips options in the --lt-* namespace from $@ and +# launches target application with the remaining arguments. +func_exec_program () +{ + case " $* " in + *\ --lt-*) + for lt_wr_arg + do + case $lt_wr_arg in + --lt-*) ;; + *) set x "$@" "$lt_wr_arg"; shift;; + esac + shift + done ;; + esac + func_exec_program_core ${1+"$@"} +} + + # Parse options + func_parse_lt_options "$0" ${1+"$@"} + + # Find the directory that this script lives in. + thisdir=`$ECHO "$file" | /usr/bin/sed 's%/[^/]*$%%'` + test "x$thisdir" = "x$file" && thisdir=. + + # Follow symbolic links until we get to the real thisdir. + file=`ls -ld "$file" | /usr/bin/sed -n 's/.*-> //p'` + while test -n "$file"; do + destdir=`$ECHO "$file" | /usr/bin/sed 's%/[^/]*$%%'` + + # If there was a directory component, then change thisdir. + if test "x$destdir" != "x$file"; then + case "$destdir" in + [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;; + *) thisdir="$thisdir/$destdir" ;; + esac + fi + + file=`$ECHO "$file" | /usr/bin/sed 's%^.*/%%'` + file=`ls -ld "$thisdir/$file" | /usr/bin/sed -n 's/.*-> //p'` + done + + # Usually 'no', except on cygwin/mingw when embedded into + # the cwrapper. + WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no + if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then + # special case for '.' + if test "$thisdir" = "."; then + thisdir=`pwd` + fi + # remove .libs from thisdir + case "$thisdir" in + *[\\/].libs ) thisdir=`$ECHO "$thisdir" | /usr/bin/sed 's%[\\/][^\\/]*$%%'` ;; + .libs ) thisdir=. ;; + esac + fi + + # Try to get the absolute directory name. + absdir=`cd "$thisdir" && pwd` + test -n "$absdir" && thisdir="$absdir" + + program='testwolfcrypt' + progdir="$thisdir/.libs" + + + if test -f "$progdir/$program"; then + # Add our own library path to DYLD_LIBRARY_PATH + DYLD_LIBRARY_PATH="/Users/sweetness/Documents/cyassl-wolfssl/src/.libs:$DYLD_LIBRARY_PATH" + + # Some systems cannot cope with colon-terminated DYLD_LIBRARY_PATH + # The second colon is a workaround for a bug in BeOS R4 sed + DYLD_LIBRARY_PATH=`$ECHO "$DYLD_LIBRARY_PATH" | /usr/bin/sed 's/::*$//'` + + export DYLD_LIBRARY_PATH + + if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then + # Run the actual program with our arguments. + func_exec_program ${1+"$@"} + fi + else + # The program doesn't exist. + $ECHO "$0: error: \`$progdir/$program' does not exist" 1>&2 + $ECHO "This script is just a wrapper for $program." 1>&2 + $ECHO "See the libtool documentation for more information." 1>&2 + exit 1 + fi +fi diff --git a/wolfssl/wolfcrypt/md2.h b/wolfssl/wolfcrypt/md2.h index 2d55cd9ea..5e524f12f 100644 --- a/wolfssl/wolfcrypt/md2.h +++ b/wolfssl/wolfcrypt/md2.h @@ -20,12 +20,12 @@ */ -#ifdef CYASSL_MD2 +#ifdef WOLFSSL_MD2 -#ifndef CTAO_CRYPT_MD2_H -#define CTAO_CRYPT_MD2_H +#ifndef WOLF_CRYPT_MD2_H +#define WOLF_CRYPT_MD2_H -#include +#include #ifdef __cplusplus extern "C" { @@ -51,10 +51,10 @@ typedef struct Md2 { } Md2; -CYASSL_API void InitMd2(Md2*); -CYASSL_API void Md2Update(Md2*, const byte*, word32); -CYASSL_API void Md2Final(Md2*, byte*); -CYASSL_API int Md2Hash(const byte*, word32, byte*); +WOLFSSL_API void wc_InitMd2(Md2*); +WOLFSSL_API void wc_Md2Update(Md2*, const byte*, word32); +WOLFSSL_API void wc_Md2Final(Md2*, byte*); +WOLFSSL_API int wc_Md2Hash(const byte*, word32, byte*); #ifdef __cplusplus diff --git a/wolfssl/wolfcrypt/md5.h b/wolfssl/wolfcrypt/md5.h index e09187769..8b5f0e9cc 100644 --- a/wolfssl/wolfcrypt/md5.h +++ b/wolfssl/wolfcrypt/md5.h @@ -24,7 +24,7 @@ #ifndef WOLF_CRYPT_MD5_H #define WOLF_CRYPT_MD5_H -#include +#include #include