forked from wolfSSL/wolfssl
Merge branch 'master' into blake2
This commit is contained in:
@@ -437,9 +437,10 @@ __asm__( \
|
||||
|
||||
#define INNERMUL \
|
||||
do { fp_word t; \
|
||||
_c[0] = t = ((fp_word)_c[0] + (fp_word)cy) + \
|
||||
t = ((fp_word)_c[0] + (fp_word)cy) + \
|
||||
(((fp_word)mu) * ((fp_word)*tmpm++)); \
|
||||
cy = (t >> DIGIT_BIT); \
|
||||
_c[0] = (fp_digit)t; \
|
||||
cy = (fp_digit)(t >> DIGIT_BIT); \
|
||||
} while (0)
|
||||
|
||||
#define PROPCARRY \
|
||||
@@ -975,8 +976,9 @@ __asm__( \
|
||||
/* multiplies point i and j, updates carry "c1" and digit c2 */
|
||||
#define SQRADD(i, j) \
|
||||
do { fp_word t; \
|
||||
t = c0 + ((fp_word)i) * ((fp_word)j); c0 = t; \
|
||||
t = c1 + (t >> DIGIT_BIT); c1 = t; c2 += t >> DIGIT_BIT; \
|
||||
t = c0 + ((fp_word)i) * ((fp_word)j); c0 = (fp_digit)t; \
|
||||
t = c1 + (t >> DIGIT_BIT); c1 = (fp_digit)t; \
|
||||
c2 +=(fp_digit) (t >> DIGIT_BIT); \
|
||||
} while (0);
|
||||
|
||||
|
||||
@@ -984,10 +986,12 @@ __asm__( \
|
||||
#define SQRADD2(i, j) \
|
||||
do { fp_word t; \
|
||||
t = ((fp_word)i) * ((fp_word)j); \
|
||||
tt = (fp_word)c0 + t; c0 = tt; \
|
||||
tt = (fp_word)c1 + (tt >> DIGIT_BIT); c1 = tt; c2 += tt >> DIGIT_BIT; \
|
||||
tt = (fp_word)c0 + t; c0 = tt; \
|
||||
tt = (fp_word)c1 + (tt >> DIGIT_BIT); c1 = tt; c2 += tt >> DIGIT_BIT; \
|
||||
tt = (fp_word)c0 + t; c0 = (fp_digit)tt; \
|
||||
tt = (fp_word)c1 + (tt >> DIGIT_BIT); c1 = (fp_digit)tt; \
|
||||
c2 +=(fp_digit)( tt >> DIGIT_BIT); \
|
||||
tt = (fp_word)c0 + t; c0 = (fp_digit)tt; \
|
||||
tt = (fp_word)c1 + (tt >> DIGIT_BIT); c1 = (fp_digit)tt; \
|
||||
c2 +=(fp_digit) (tt >> DIGIT_BIT); \
|
||||
} while (0);
|
||||
|
||||
#define SQRADDSC(i, j) \
|
||||
@@ -1274,10 +1278,11 @@ ____asm__( \
|
||||
|
||||
#define COMBA_FINI
|
||||
|
||||
#define MULADD(i, j) \
|
||||
do { fp_word t; \
|
||||
t = (fp_word)c0 + ((fp_word)i) * ((fp_word)j); c0 = t; \
|
||||
t = (fp_word)c1 + (t >> DIGIT_BIT); c1 = t; c2 += t >> DIGIT_BIT; \
|
||||
#define MULADD(i, j) \
|
||||
do { fp_word t; \
|
||||
t = (fp_word)c0 + ((fp_word)i) * ((fp_word)j); c0 = (fp_digit)t; \
|
||||
t = (fp_word)c1 + (t >> DIGIT_BIT); \
|
||||
c1 = (fp_digit)t; c2 += (fp_digit)(t >> DIGIT_BIT); \
|
||||
} while (0);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -71,10 +71,10 @@
|
||||
|
||||
|
||||
#ifndef TRUE
|
||||
enum {
|
||||
FALSE = 0,
|
||||
TRUE = 1
|
||||
};
|
||||
#define TRUE 1
|
||||
#endif
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
|
||||
@@ -92,12 +92,33 @@ enum {
|
||||
#define NO_TIME_H
|
||||
/* since Micrium not defining XTIME or XGMTIME, CERT_GEN not available */
|
||||
#elif defined(USER_TIME)
|
||||
/* no <time.h> structures used */
|
||||
#define NO_TIME_H
|
||||
/* user time, and gmtime compatible functions, there is a gmtime
|
||||
implementation here that WINCE uses, so really just need some ticks
|
||||
since the EPOCH
|
||||
*/
|
||||
|
||||
struct tm {
|
||||
int tm_sec; /* seconds after the minute [0-60] */
|
||||
int tm_min; /* minutes after the hour [0-59] */
|
||||
int tm_hour; /* hours since midnight [0-23] */
|
||||
int tm_mday; /* day of the month [1-31] */
|
||||
int tm_mon; /* months since January [0-11] */
|
||||
int tm_year; /* years since 1900 */
|
||||
int tm_wday; /* days since Sunday [0-6] */
|
||||
int tm_yday; /* days since January 1 [0-365] */
|
||||
int tm_isdst; /* Daylight Savings Time flag */
|
||||
long tm_gmtoff; /* offset from CUT in seconds */
|
||||
char *tm_zone; /* timezone abbreviation */
|
||||
};
|
||||
typedef long time_t;
|
||||
|
||||
/* forward declaration */
|
||||
struct tm* gmtime(const time_t* timer);
|
||||
extern time_t XTIME(time_t * timer);
|
||||
|
||||
#define XGMTIME(c) gmtime((c))
|
||||
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
|
||||
|
||||
#else
|
||||
/* default */
|
||||
/* uses complete <time.h> facility */
|
||||
@@ -137,7 +158,8 @@ time_t time(time_t* timer)
|
||||
return *timer;
|
||||
}
|
||||
|
||||
|
||||
#endif /* _WIN32_WCE */
|
||||
#if defined( _WIN32_WCE ) || defined( USER_TIME )
|
||||
|
||||
struct tm* gmtime(const time_t* timer)
|
||||
{
|
||||
@@ -155,17 +177,17 @@ struct tm* gmtime(const time_t* timer)
|
||||
|
||||
static struct tm st_time;
|
||||
struct tm* ret = &st_time;
|
||||
time_t time = *timer;
|
||||
time_t secs = *timer;
|
||||
unsigned long dayclock, dayno;
|
||||
int year = EPOCH_YEAR;
|
||||
|
||||
dayclock = (unsigned long)time % SECS_DAY;
|
||||
dayno = (unsigned long)time / SECS_DAY;
|
||||
dayclock = (unsigned long)secs % SECS_DAY;
|
||||
dayno = (unsigned long)secs / SECS_DAY;
|
||||
|
||||
ret->tm_sec = dayclock % 60;
|
||||
ret->tm_min = (dayclock % 3600) / 60;
|
||||
ret->tm_hour = dayclock / 3600;
|
||||
ret->tm_wday = (dayno + 4) % 7; /* day 0 a Thursday */
|
||||
ret->tm_sec = (int) dayclock % 60;
|
||||
ret->tm_min = (int)(dayclock % 3600) / 60;
|
||||
ret->tm_hour = (int) dayclock / 3600;
|
||||
ret->tm_wday = (int) (dayno + 4) % 7; /* day 0 a Thursday */
|
||||
|
||||
while(dayno >= (unsigned long)YEARSIZE(year)) {
|
||||
dayno -= YEARSIZE(year);
|
||||
@@ -173,7 +195,7 @@ struct tm* gmtime(const time_t* timer)
|
||||
}
|
||||
|
||||
ret->tm_year = year - YEAR0;
|
||||
ret->tm_yday = dayno;
|
||||
ret->tm_yday = (int)dayno;
|
||||
ret->tm_mon = 0;
|
||||
|
||||
while(dayno >= (unsigned long)_ytab[LEAPYEAR(year)][ret->tm_mon]) {
|
||||
@@ -181,13 +203,13 @@ struct tm* gmtime(const time_t* timer)
|
||||
ret->tm_mon++;
|
||||
}
|
||||
|
||||
ret->tm_mday = ++dayno;
|
||||
ret->tm_mday = (int)++dayno;
|
||||
ret->tm_isdst = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* _WIN32_WCE */
|
||||
#endif /* _WIN32_WCE || USER_TIME */
|
||||
|
||||
|
||||
#ifdef THREADX
|
||||
@@ -386,6 +408,7 @@ static int GetMyVersion(const byte* input, word32* inOutIdx, int* version)
|
||||
}
|
||||
|
||||
|
||||
#ifndef NO_PWDBASED
|
||||
/* Get small count integer, 32 bits or less */
|
||||
static int GetShortInt(const byte* input, word32* inOutIdx, int* number)
|
||||
{
|
||||
@@ -409,7 +432,7 @@ static int GetShortInt(const byte* input, word32* inOutIdx, int* number)
|
||||
|
||||
return *number;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* May not have one, not an error */
|
||||
static int GetExplicitVersion(const byte* input, word32* inOutIdx, int* version)
|
||||
@@ -1413,7 +1436,9 @@ static int GetKey(DecodedCert* cert)
|
||||
/* process NAME, either issuer or subject */
|
||||
static int GetName(DecodedCert* cert, int nameType)
|
||||
{
|
||||
#ifndef NO_SHA
|
||||
Sha sha;
|
||||
#endif
|
||||
int length; /* length of all distinguished names */
|
||||
int dummy;
|
||||
char* full = (nameType == ISSUER) ? cert->issuer : cert->subject;
|
||||
@@ -1438,12 +1463,14 @@ static int GetName(DecodedCert* cert, int nameType)
|
||||
if (GetSequence(cert->source, &cert->srcIdx, &length, cert->maxIdx) < 0)
|
||||
return ASN_PARSE_E;
|
||||
|
||||
#ifndef NO_SHA
|
||||
InitSha(&sha);
|
||||
ShaUpdate(&sha, &cert->source[idx], length + cert->srcIdx - idx);
|
||||
if (nameType == ISSUER)
|
||||
ShaFinal(&sha, cert->issuerHash);
|
||||
else
|
||||
ShaFinal(&sha, cert->subjectHash);
|
||||
#endif
|
||||
|
||||
length += cert->srcIdx;
|
||||
idx = 0;
|
||||
@@ -1884,7 +1911,7 @@ static word32 BytePrecision(word32 value)
|
||||
{
|
||||
word32 i;
|
||||
for (i = sizeof(value); i; --i)
|
||||
if (value >> ((i - 1) * BIT_SIZE))
|
||||
if (value >> ((i - 1) * CYASSL_BIT_SIZE))
|
||||
break;
|
||||
|
||||
return i;
|
||||
@@ -1901,7 +1928,7 @@ static word32 SetLength(word32 length, byte* output)
|
||||
output[i++] = (byte)(BytePrecision(length) | ASN_LONG_LENGTH);
|
||||
|
||||
for (j = BytePrecision(length); j; --j) {
|
||||
output[i] = (byte)(length >> ((j - 1) * BIT_SIZE));
|
||||
output[i] = (byte)(length >> ((j - 1) * CYASSL_BIT_SIZE));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@@ -2101,8 +2128,10 @@ static int ConfirmSignature(const byte* buf, word32 bufSz,
|
||||
(void)sig;
|
||||
(void)sigSz;
|
||||
(void)heap;
|
||||
(void)ret;
|
||||
|
||||
switch (sigOID) {
|
||||
#ifndef NO_MD5
|
||||
case CTC_MD5wRSA:
|
||||
{
|
||||
Md5 md5;
|
||||
@@ -2113,6 +2142,7 @@ static int ConfirmSignature(const byte* buf, word32 bufSz,
|
||||
digestSz = MD5_DIGEST_SIZE;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#if defined(CYASSL_MD2)
|
||||
case CTC_MD2wRSA:
|
||||
{
|
||||
@@ -2125,6 +2155,7 @@ static int ConfirmSignature(const byte* buf, word32 bufSz,
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifndef NO_SHA
|
||||
case CTC_SHAwRSA:
|
||||
case CTC_SHAwDSA:
|
||||
case CTC_SHAwECDSA:
|
||||
@@ -2137,6 +2168,7 @@ static int ConfirmSignature(const byte* buf, word32 bufSz,
|
||||
digestSz = SHA_DIGEST_SIZE;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifndef NO_SHA256
|
||||
case CTC_SHA256wRSA:
|
||||
case CTC_SHA256wECDSA:
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifndef NO_CODING
|
||||
|
||||
#include <cyassl/ctaocrypt/coding.h>
|
||||
#include <cyassl/ctaocrypt/error.h>
|
||||
#include <cyassl/ctaocrypt/logging.h>
|
||||
@@ -104,16 +106,18 @@ int Base64_Decode(const byte* in, word32 inLen, byte* out, word32* outLen)
|
||||
break;
|
||||
|
||||
inLen -= 4;
|
||||
if (in[j] == ' ' || in[j] == '\r' || in[j] == '\n') {
|
||||
if (inLen && (in[j] == ' ' || in[j] == '\r' || in[j] == '\n')) {
|
||||
byte endLine = in[j++];
|
||||
inLen--;
|
||||
while (endLine == ' ') { /* allow trailing whitespace */
|
||||
while (inLen && endLine == ' ') { /* allow trailing whitespace */
|
||||
endLine = in[j++];
|
||||
inLen--;
|
||||
}
|
||||
if (endLine == '\r') {
|
||||
endLine = in[j++];
|
||||
inLen--;
|
||||
if (inLen) {
|
||||
endLine = in[j++];
|
||||
inLen--;
|
||||
}
|
||||
}
|
||||
if (endLine != '\n') {
|
||||
CYASSL_MSG("Bad end of line in Base64 Decode");
|
||||
@@ -263,3 +267,4 @@ int Base16_Decode(const byte* in, word32 inLen, byte* out, word32* outLen)
|
||||
|
||||
|
||||
#endif /* defined(OPENSSL_EXTRA) || defined (SESSION_CERTS) || defined(CYASSL_KEY_GEN) || defined(CYASSL_CERT_GEN) || defined(HAVE_WEBSERVER) */
|
||||
#endif /* NO_CODING */
|
||||
|
||||
168
ctaocrypt/src/compress.c
Normal file
168
ctaocrypt/src/compress.c
Normal file
@@ -0,0 +1,168 @@
|
||||
/* compress.c
|
||||
*
|
||||
* Copyright (C) 2006-2013 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_LIBZ
|
||||
|
||||
|
||||
#include <cyassl/ctaocrypt/compress.h>
|
||||
#include <cyassl/ctaocrypt/error.h>
|
||||
#include <cyassl/ctaocrypt/logging.h>
|
||||
#ifdef NO_INLINE
|
||||
#include <cyassl/ctaocrypt/misc.h>
|
||||
#else
|
||||
#include <ctaocrypt/src/misc.c>
|
||||
#endif
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
|
||||
/* alloc user allocs to work with zlib */
|
||||
static void* myAlloc(void* opaque, unsigned int item, unsigned int size)
|
||||
{
|
||||
(void)opaque;
|
||||
return XMALLOC(item * size, opaque, DYNAMIC_TYPE_LIBZ);
|
||||
}
|
||||
|
||||
|
||||
static void myFree(void* opaque, void* memory)
|
||||
{
|
||||
(void)opaque;
|
||||
XFREE(memory, opaque, DYNAMIC_TYPE_LIBZ);
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_MCAPI
|
||||
#define DEFLATE_DEFAULT_WINDOWBITS 11
|
||||
#define DEFLATE_DEFAULT_MEMLEVEL 1
|
||||
#else
|
||||
#define DEFLATE_DEFAULT_WINDOWBITS 15
|
||||
#define DEFLATE_DEFAULT_MEMLEVEL 8
|
||||
#endif
|
||||
|
||||
|
||||
int Compress(byte* out, word32 outSz, const byte* in, word32 inSz, word32 flags)
|
||||
/*
|
||||
* out - pointer to destination buffer
|
||||
* outSz - size of destination buffer
|
||||
* in - pointer to source buffer to compress
|
||||
* inSz - size of source to compress
|
||||
* flags - flags to control how compress operates
|
||||
*
|
||||
* return:
|
||||
* negative - error code
|
||||
* positive - bytes stored in out buffer
|
||||
*
|
||||
* Note, the output buffer still needs to be larger than the input buffer.
|
||||
* The right chunk of data won't compress at all, and the lookup table will
|
||||
* add to the size of the output. The libz code says the compressed
|
||||
* buffer should be srcSz + 0.1% + 12.
|
||||
*/
|
||||
{
|
||||
z_stream stream;
|
||||
int result = 0;
|
||||
|
||||
stream.next_in = (Bytef*)in;
|
||||
stream.avail_in = (uInt)inSz;
|
||||
#ifdef MAXSEG_64K
|
||||
/* Check for source > 64K on 16-bit machine: */
|
||||
if ((uLong)stream.avail_in != inSz) return COMPRESS_INIT_E;
|
||||
#endif
|
||||
stream.next_out = out;
|
||||
stream.avail_out = (uInt)outSz;
|
||||
if ((uLong)stream.avail_out != outSz) return COMPRESS_INIT_E;
|
||||
|
||||
stream.zalloc = (alloc_func)myAlloc;
|
||||
stream.zfree = (free_func)myFree;
|
||||
stream.opaque = (voidpf)0;
|
||||
|
||||
if (deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
|
||||
DEFLATE_DEFAULT_WINDOWBITS, DEFLATE_DEFAULT_MEMLEVEL,
|
||||
flags ? Z_FIXED : Z_DEFAULT_STRATEGY) != Z_OK)
|
||||
return COMPRESS_INIT_E;
|
||||
|
||||
if (deflate(&stream, Z_FINISH) != Z_STREAM_END) {
|
||||
deflateEnd(&stream);
|
||||
return COMPRESS_E;
|
||||
}
|
||||
|
||||
result = (int)stream.total_out;
|
||||
|
||||
if (deflateEnd(&stream) != Z_OK)
|
||||
result = COMPRESS_E;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int DeCompress(byte* out, word32 outSz, const byte* in, word32 inSz)
|
||||
/*
|
||||
* out - pointer to destination buffer
|
||||
* outSz - size of destination buffer
|
||||
* in - pointer to source buffer to compress
|
||||
* inSz - size of source to compress
|
||||
* flags - flags to control how compress operates
|
||||
*
|
||||
* return:
|
||||
* negative - error code
|
||||
* positive - bytes stored in out buffer
|
||||
*/
|
||||
{
|
||||
z_stream stream;
|
||||
int result = 0;
|
||||
|
||||
stream.next_in = (Bytef*)in;
|
||||
stream.avail_in = (uInt)inSz;
|
||||
/* Check for source > 64K on 16-bit machine: */
|
||||
if ((uLong)stream.avail_in != inSz) return DECOMPRESS_INIT_E;
|
||||
|
||||
stream.next_out = out;
|
||||
stream.avail_out = (uInt)outSz;
|
||||
if ((uLong)stream.avail_out != outSz) return DECOMPRESS_INIT_E;
|
||||
|
||||
stream.zalloc = (alloc_func)myAlloc;
|
||||
stream.zfree = (free_func)myFree;
|
||||
stream.opaque = (voidpf)0;
|
||||
|
||||
if (inflateInit2(&stream, DEFLATE_DEFAULT_WINDOWBITS) != Z_OK)
|
||||
return DECOMPRESS_INIT_E;
|
||||
|
||||
if (inflate(&stream, Z_FINISH) != Z_STREAM_END) {
|
||||
inflateEnd(&stream);
|
||||
return DECOMPRESS_E;
|
||||
}
|
||||
|
||||
result = (int)stream.total_out;
|
||||
|
||||
if (inflateEnd(&stream) != Z_OK)
|
||||
result = DECOMPRESS_E;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
#endif /* HAVE_LIBZ */
|
||||
|
||||
@@ -83,8 +83,8 @@ static word32 DiscreteLogWorkFactor(word32 n)
|
||||
static void GeneratePrivate(DhKey* key, RNG* rng, byte* priv, word32* privSz)
|
||||
{
|
||||
word32 sz = mp_unsigned_bin_size(&key->p);
|
||||
sz = min(sz, 2 * DiscreteLogWorkFactor(sz * BIT_SIZE) / BIT_SIZE + 1);
|
||||
|
||||
sz = min(sz, 2 * DiscreteLogWorkFactor(sz * CYASSL_BIT_SIZE) /
|
||||
CYASSL_BIT_SIZE + 1);
|
||||
RNG_GenerateBlock(rng, priv, sz);
|
||||
priv[0] |= 0x0C;
|
||||
|
||||
|
||||
@@ -281,6 +281,22 @@ void CTaoCryptErrorString(int error, char* buffer)
|
||||
XSTRNCPY(buffer, "Cavium Init type error", max);
|
||||
break;
|
||||
|
||||
case COMPRESS_INIT_E:
|
||||
XSTRNCPY(buffer, "Compress Init error", max);
|
||||
break;
|
||||
|
||||
case COMPRESS_E:
|
||||
XSTRNCPY(buffer, "Compress error", max);
|
||||
break;
|
||||
|
||||
case DECOMPRESS_INIT_E:
|
||||
XSTRNCPY(buffer, "DeCompress Init error", max);
|
||||
break;
|
||||
|
||||
case DECOMPRESS_E:
|
||||
XSTRNCPY(buffer, "DeCompress error", max);
|
||||
break;
|
||||
|
||||
default:
|
||||
XSTRNCPY(buffer, "unknown error number", max);
|
||||
|
||||
|
||||
@@ -42,7 +42,8 @@ static int InitHmac(Hmac* hmac, int type)
|
||||
hmac->innerHashKeyed = 0;
|
||||
hmac->macType = (byte)type;
|
||||
|
||||
if (!(type == MD5 || type == SHA || type == SHA256 || type == SHA384))
|
||||
if (!(type == MD5 || type == SHA || type == SHA256 || type == SHA384
|
||||
|| type == SHA512))
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
switch (type) {
|
||||
@@ -52,9 +53,11 @@ static int InitHmac(Hmac* hmac, int type)
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA
|
||||
case SHA:
|
||||
InitSha(&hmac->hash.sha);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA256
|
||||
case SHA256:
|
||||
@@ -68,6 +71,12 @@ static int InitHmac(Hmac* hmac, int type)
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CYASSL_SHA512
|
||||
case SHA512:
|
||||
InitSha512(&hmac->hash.sha512);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -80,7 +89,7 @@ void HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length)
|
||||
{
|
||||
byte* ip = (byte*) hmac->ipad;
|
||||
byte* op = (byte*) hmac->opad;
|
||||
word32 i, hmac_block_size = SHA_BLOCK_SIZE;
|
||||
word32 i, hmac_block_size = 0;
|
||||
|
||||
#ifdef HAVE_CAVIUM
|
||||
if (hmac->magic == CYASSL_HMAC_CAVIUM_MAGIC)
|
||||
@@ -106,8 +115,10 @@ void HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length)
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA
|
||||
case SHA:
|
||||
{
|
||||
hmac_block_size = SHA_BLOCK_SIZE;
|
||||
if (length <= SHA_BLOCK_SIZE) {
|
||||
XMEMCPY(ip, key, length);
|
||||
}
|
||||
@@ -118,6 +129,7 @@ void HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length)
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA256
|
||||
case SHA256:
|
||||
@@ -151,6 +163,22 @@ void HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length)
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CYASSL_SHA512
|
||||
case SHA512:
|
||||
{
|
||||
hmac_block_size = SHA512_BLOCK_SIZE;
|
||||
if (length <= SHA512_BLOCK_SIZE) {
|
||||
XMEMCPY(ip, key, length);
|
||||
}
|
||||
else {
|
||||
Sha512Update(&hmac->hash.sha512, key, length);
|
||||
Sha512Final(&hmac->hash.sha512, ip);
|
||||
length = SHA512_DIGEST_SIZE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -173,9 +201,11 @@ static void HmacKeyInnerHash(Hmac* hmac)
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA
|
||||
case SHA:
|
||||
ShaUpdate(&hmac->hash.sha, (byte*) hmac->ipad, SHA_BLOCK_SIZE);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA256
|
||||
case SHA256:
|
||||
@@ -191,6 +221,13 @@ static void HmacKeyInnerHash(Hmac* hmac)
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CYASSL_SHA512
|
||||
case SHA512:
|
||||
Sha512Update(&hmac->hash.sha512,
|
||||
(byte*) hmac->ipad, SHA512_BLOCK_SIZE);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -216,9 +253,11 @@ void HmacUpdate(Hmac* hmac, const byte* msg, word32 length)
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA
|
||||
case SHA:
|
||||
ShaUpdate(&hmac->hash.sha, msg, length);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA256
|
||||
case SHA256:
|
||||
@@ -232,6 +271,12 @@ void HmacUpdate(Hmac* hmac, const byte* msg, word32 length)
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CYASSL_SHA512
|
||||
case SHA512:
|
||||
Sha512Update(&hmac->hash.sha512, msg, length);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -264,6 +309,7 @@ void HmacFinal(Hmac* hmac, byte* hash)
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA
|
||||
case SHA:
|
||||
{
|
||||
ShaFinal(&hmac->hash.sha, (byte*) hmac->innerHash);
|
||||
@@ -275,6 +321,7 @@ void HmacFinal(Hmac* hmac, byte* hash)
|
||||
ShaFinal(&hmac->hash.sha, hash);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA256
|
||||
case SHA256:
|
||||
@@ -306,6 +353,21 @@ void HmacFinal(Hmac* hmac, byte* hash)
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CYASSL_SHA512
|
||||
case SHA512:
|
||||
{
|
||||
Sha512Final(&hmac->hash.sha512, (byte*) hmac->innerHash);
|
||||
|
||||
Sha512Update(&hmac->hash.sha512,
|
||||
(byte*) hmac->opad, SHA512_BLOCK_SIZE);
|
||||
Sha512Update(&hmac->hash.sha512,
|
||||
(byte*) hmac->innerHash, SHA512_DIGEST_SIZE);
|
||||
|
||||
Sha512Final(&hmac->hash.sha512, hash);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
/* in case user set USE_FAST_MATH there */
|
||||
#include <cyassl/ctaocrypt/settings.h>
|
||||
|
||||
#ifndef NO_BIG_INT
|
||||
|
||||
#ifndef USE_FAST_MATH
|
||||
|
||||
#include <cyassl/ctaocrypt/integer.h>
|
||||
@@ -43,6 +45,8 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static void bn_reverse (unsigned char *s, int len);
|
||||
|
||||
/* math settings check */
|
||||
word32 CheckRunTimeSettings(void)
|
||||
{
|
||||
@@ -3732,7 +3736,7 @@ int mp_sqrmod (mp_int * a, mp_int * b, mp_int * c)
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(CYASSL_KEY_GEN) || defined(HAVE_ECC) || !defined(NO_PWDBASED)
|
||||
#if defined(CYASSL_KEY_GEN) || defined(HAVE_ECC) || defined(OPENSSL_EXTRA)
|
||||
|
||||
/* single digit addition */
|
||||
int mp_add_d (mp_int* a, mp_digit b, mp_int* c)
|
||||
@@ -4452,3 +4456,4 @@ int mp_read_radix (mp_int * a, const char *str, int radix)
|
||||
|
||||
#endif /* USE_FAST_MATH */
|
||||
|
||||
#endif /* NO_BIG_INT */
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifndef NO_MD5
|
||||
|
||||
#include <cyassl/ctaocrypt/md5.h>
|
||||
|
||||
#ifdef NO_INLINE
|
||||
@@ -340,3 +342,4 @@ void Md5Final(Md5* md5, byte* hash)
|
||||
|
||||
#endif /* STM32F2_CRYPTO */
|
||||
|
||||
#endif /* NO_MD5 */
|
||||
|
||||
@@ -163,8 +163,8 @@ STATIC INLINE void XorWords(word* r, const word* a, word32 n)
|
||||
|
||||
STATIC INLINE void xorbuf(byte* buf, const byte* mask, word32 count)
|
||||
{
|
||||
if (((word)buf | (word)mask | count) % WORD_SIZE == 0)
|
||||
XorWords( (word*)buf, (const word*)mask, count / WORD_SIZE);
|
||||
if (((word)buf | (word)mask | count) % CYASSL_WORD_SIZE == 0)
|
||||
XorWords( (word*)buf, (const word*)mask, count / CYASSL_WORD_SIZE);
|
||||
else {
|
||||
word32 i;
|
||||
for (i = 0; i < count; i++) buf[i] ^= mask[i];
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
#endif
|
||||
#endif /* USE_WINDOWS_API */
|
||||
|
||||
#if !defined( NO_CYASSL_RANDOM )
|
||||
|
||||
#ifdef NO_RC4
|
||||
|
||||
@@ -568,7 +569,7 @@ int GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||
|
||||
#elif defined(NO_DEV_RANDOM)
|
||||
|
||||
#error "you need to write an os specific GenerateSeed() here"
|
||||
#warning "you need to write an os specific GenerateSeed() here"
|
||||
|
||||
|
||||
#else /* !USE_WINDOWS_API && !THREADX && !MICRIUM && !NO_DEV_RANDOM */
|
||||
@@ -613,3 +614,4 @@ int GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||
|
||||
#endif /* USE_WINDOWS_API */
|
||||
|
||||
#endif /* NO_CYASSL_RANDOM */
|
||||
|
||||
@@ -19,10 +19,13 @@
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA
|
||||
|
||||
#include <cyassl/ctaocrypt/sha.h>
|
||||
#ifdef NO_INLINE
|
||||
#include <cyassl/ctaocrypt/misc.h>
|
||||
@@ -345,3 +348,4 @@ void ShaFinal(Sha* sha, byte* hash)
|
||||
|
||||
#endif /* STM32F2_CRYPTO */
|
||||
|
||||
#endif /* NO_SHA */
|
||||
|
||||
Reference in New Issue
Block a user