forked from wolfSSL/wolfssl
Added Md5GetHash for BuildCertHashes
This commit is contained in:
@@ -191,6 +191,8 @@ if BUILD_PKCS7
|
||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/pkcs7.c
|
||||
endif
|
||||
|
||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/port/ti/ti-hash.c
|
||||
|
||||
# ssl files
|
||||
src_libwolfssl_la_SOURCES += \
|
||||
src/internal.c \
|
||||
|
@@ -6925,14 +6925,14 @@ static int BuildCertHashes(WOLFSSL* ssl, Hashes* hashes)
|
||||
|
||||
if (ssl->options.tls) {
|
||||
#if ! defined( NO_OLD_TLS )
|
||||
wc_Md5Final(&ssl->hsHashes->hashMd5, hashes->md5);
|
||||
wc_ShaFinal(&ssl->hsHashes->hashSha, hashes->sha);
|
||||
wc_Md5GetHash(&ssl->hsHashes->hashMd5, hashes->md5);
|
||||
wc_ShaGetHash(&ssl->hsHashes->hashSha, hashes->sha);
|
||||
#endif
|
||||
if (IsAtLeastTLSv1_2(ssl)) {
|
||||
int ret;
|
||||
|
||||
#ifndef NO_SHA256
|
||||
ret = wc_Sha256Final(&ssl->hsHashes->hashSha256,hashes->sha256);
|
||||
ret = wc_Sha256GetHash(&ssl->hsHashes->hashSha256,hashes->sha256);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
#endif
|
||||
|
@@ -26,7 +26,7 @@
|
||||
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
|
||||
#if !defined(NO_MD5)
|
||||
#if !defined(NO_MD5) && !defined(WOLFSSL_TI_HASH)
|
||||
|
||||
#ifdef WOLFSSL_PIC32MZ_HASH
|
||||
#define wc_InitMd5 wc_InitMd5_sw
|
||||
@@ -164,6 +164,10 @@
|
||||
wc_InitMd5(md5); /* reset state */
|
||||
}
|
||||
|
||||
#elif defined(WOLFSSL_IT_HASH)
|
||||
|
||||
/* defined in port/ti_md5.c */
|
||||
|
||||
#else /* CTaoCrypt software implementation */
|
||||
|
||||
#ifndef WOLFSSL_HAVE_MIN
|
||||
@@ -176,6 +180,11 @@
|
||||
|
||||
#endif /* WOLFSSL_HAVE_MIN */
|
||||
|
||||
#ifdef TI_HASH_TEST
|
||||
void wc_InitMd5_ti(Md5* md5) ;
|
||||
void wc_Md5Update_ti(Md5* md5, const byte* data, word32 len) ;
|
||||
void wc_Md5Final_ti(Md5* md5, byte* hash) ;
|
||||
#endif
|
||||
|
||||
void wc_InitMd5(Md5* md5)
|
||||
{
|
||||
@@ -187,6 +196,10 @@ void wc_InitMd5(Md5* md5)
|
||||
md5->buffLen = 0;
|
||||
md5->loLen = 0;
|
||||
md5->hiLen = 0;
|
||||
|
||||
#ifdef TI_HASH_TEST
|
||||
wc_InitMd5_ti(md5) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef FREESCALE_MMCAU
|
||||
@@ -315,6 +328,10 @@ void wc_Md5Update(Md5* md5, const byte* data, word32 len)
|
||||
md5->buffLen = 0;
|
||||
}
|
||||
}
|
||||
#ifdef TI_HASH_TEST
|
||||
wc_Md5Update_ti(md5, data, len) ;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -359,6 +376,10 @@ void wc_Md5Final(Md5* md5, byte* hash)
|
||||
XMEMCPY(hash, md5->digest, MD5_DIGEST_SIZE);
|
||||
|
||||
wc_InitMd5(md5); /* reset state */
|
||||
|
||||
#ifdef TI_HASH_TEST
|
||||
wc_Md5Final_ti(md5, hash) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* STM32F2_HASH */
|
||||
@@ -389,4 +410,17 @@ int wc_Md5Hash(const byte* data, word32 len, byte* hash)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_TI_HASH)||defined(TI_HASH_TEST)
|
||||
#include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
|
||||
#endif
|
||||
void wc_Md5GetHash(Md5* md5, byte* hash)
|
||||
{
|
||||
#if defined(WOLFSSL_TI_HASH) || defined(TI_HASH_TEST)
|
||||
wc_Md5GetHash_ti(md5, hash) ;
|
||||
#else
|
||||
Md5 save = *md5 ;
|
||||
wc_Md5Final(md5, hash) ;
|
||||
*md5 = save ;
|
||||
#endif
|
||||
}
|
||||
#endif /* NO_MD5 */
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* port/ti/ti-hash.h
|
||||
/* port/ti/ti-hash.c
|
||||
*
|
||||
* Copyright (C) 2006-2015 wolfSSL Inc.
|
||||
*
|
||||
@@ -20,12 +20,9 @@
|
||||
*/
|
||||
|
||||
|
||||
#ifndef WOLFSSL_TI_HASH_H
|
||||
#define WOLFSSL_TI_HASH_H
|
||||
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
|
||||
#if defined(WOLFSSL_TI_HASH)
|
||||
#if defined(WOLFSSL_TI_HASH)||defined(TI_HASH_TEST)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -42,6 +39,7 @@
|
||||
#include <wolfssl/wolfcrypt/port/ti/ti-ccm.h>
|
||||
#include <wolfssl/wolfcrypt/logging.h>
|
||||
|
||||
#if !defined(TI_HASH_TEST)
|
||||
#include "inc/hw_memmap.h"
|
||||
#include "inc/hw_shamd5.h"
|
||||
#include "inc/hw_ints.h"
|
||||
@@ -49,6 +47,7 @@
|
||||
#include "driverlib/sysctl.h"
|
||||
#include "driverlib/rom_map.h"
|
||||
#include "driverlib/rom.h"
|
||||
#endif
|
||||
|
||||
static int hashInit(wolfssl_TI_Hash *hash) {
|
||||
hash->used = 0 ;
|
||||
@@ -60,6 +59,7 @@ static int hashInit(wolfssl_TI_Hash *hash) {
|
||||
static int hashUpdate(wolfssl_TI_Hash *hash, const byte* data, word32 len)
|
||||
{
|
||||
void *p ;
|
||||
|
||||
if((hash== NULL) || (data == NULL))return BAD_FUNC_ARG;
|
||||
if(hash->len < hash->used+len) {
|
||||
if(hash->msg == NULL) {
|
||||
@@ -78,7 +78,9 @@ static int hashUpdate(wolfssl_TI_Hash *hash, const byte* data, word32 len)
|
||||
|
||||
static int hashFinal(wolfssl_TI_Hash *hash, byte* result, word32 algo, word32 hsize)
|
||||
{
|
||||
#if !defined(TI_HASH_TEST)
|
||||
uint32_t h[16] ;
|
||||
|
||||
wolfSSL_TI_lockCCM() ;
|
||||
ROM_SHAMD5Reset(SHAMD5_BASE);
|
||||
ROM_SHAMD5ConfigSet(SHAMD5_BASE, algo);
|
||||
@@ -86,11 +88,38 @@ static int hashFinal(wolfssl_TI_Hash *hash, byte* result, word32 algo, word32 hs
|
||||
(uint32_t *)hash->msg, hash->used, h);
|
||||
XMEMCPY(result, h, hsize) ;
|
||||
wolfSSL_TI_unlockCCM() ;
|
||||
#else
|
||||
(void) result ;
|
||||
(void) algo ;
|
||||
(void) hsize ;
|
||||
#endif
|
||||
XFREE(hash->msg, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
hashInit(hash) ;
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
static int hashGetHash(wolfssl_TI_Hash *hash, byte* result, word32 algo, word32 hsize)
|
||||
{
|
||||
#if !defined(TI_HASH_TEST)
|
||||
uint32_t h[16] ;
|
||||
|
||||
wolfSSL_TI_lockCCM() ;
|
||||
ROM_SHAMD5Reset(SHAMD5_BASE);
|
||||
ROM_SHAMD5ConfigSet(SHAMD5_BASE, algo);
|
||||
ROM_SHAMD5DataProcess(SHAMD5_BASE,
|
||||
(uint32_t *)hash->msg, hash->used, h);
|
||||
XMEMCPY(result, h, hsize) ;
|
||||
wolfSSL_TI_unlockCCM() ;
|
||||
#else
|
||||
(void) hash ;
|
||||
(void) result ;
|
||||
(void) algo ;
|
||||
(void) hsize ;
|
||||
#endif
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
#ifndef TI_HASH_TEST
|
||||
static int hashHash(const byte* data, word32 len, byte* hash, word32 algo, word32 hsize)
|
||||
{
|
||||
int ret = 0;
|
||||
@@ -120,34 +149,80 @@ static int hashHash(const byte* data, word32 len, byte* hash, word32 algo, word3
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(NO_MD5)
|
||||
|
||||
#ifdef TI_HASH_TEST
|
||||
#define SHAMD5_ALGO_MD5 1
|
||||
void wc_InitMd5_ti(Md5* md5) ;
|
||||
void wc_Md5Update_ti(Md5* md5, const byte* data, word32 len);
|
||||
void wc_Md5Final_ti(Md5* md5, byte* hash);
|
||||
bool wolfSSL_TI_CCMInit(void) ;
|
||||
bool wolfSSL_TI_CCMInit(void) { return true ; }
|
||||
#endif
|
||||
|
||||
#ifdef TI_HASH_TEST
|
||||
void wc_InitMd5_ti(Md5* md5)
|
||||
#else
|
||||
void wc_InitMd5(Md5* md5)
|
||||
#endif
|
||||
{
|
||||
if (md5 == NULL)
|
||||
return ;
|
||||
if(!wolfSSL_TI_CCMInit())return ;
|
||||
#ifdef TI_HASH_TEST
|
||||
hashInit(&(md5->ti)) ;
|
||||
#else
|
||||
hashInit((wolfssl_TI_Hash *)md5) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef TI_HASH_TEST
|
||||
void wc_Md5Update_ti(Md5* md5, const byte* data, word32 len)
|
||||
#else
|
||||
void wc_Md5Update(Md5* md5, const byte* data, word32 len)
|
||||
#endif
|
||||
{
|
||||
#ifdef TI_HASH_TEST
|
||||
hashUpdate(&(md5->ti), data, len) ;
|
||||
#else
|
||||
hashUpdate((wolfssl_TI_Hash *)md5, data, len) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef TI_HASH_TEST
|
||||
void wc_Md5Final_ti(Md5* md5, byte* hash)
|
||||
#else
|
||||
void wc_Md5Final(Md5* md5, byte* hash)
|
||||
#endif
|
||||
{
|
||||
#ifdef TI_HASH_TEST
|
||||
hashFinal(&(md5->ti), hash, SHAMD5_ALGO_MD5, MD5_DIGEST_SIZE) ;
|
||||
#else
|
||||
hashFinal((wolfssl_TI_Hash *)md5, hash, SHAMD5_ALGO_MD5, MD5_DIGEST_SIZE) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void wc_Md5GetHash_ti(Md5* md5, byte* hash)
|
||||
{
|
||||
hashGetHash(&(md5->ti), hash, SHAMD5_ALGO_MD5, MD5_DIGEST_SIZE) ;
|
||||
#ifdef TI_HASH_TEST
|
||||
wc_Md5Final(md5, hash) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef TI_HASH_TEST
|
||||
WOLFSSL_API int wc_Md5Hash(const byte*data, word32 len, byte*hash)
|
||||
{
|
||||
return hashHash(data, len, hash, SHAMD5_ALGO_MD5, MD5_DIGEST_SIZE) ;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NO_MD5 */
|
||||
|
||||
#ifndef TI_HASH_TEST
|
||||
#if !defined(NO_SHA)
|
||||
|
||||
WOLFSSL_API int wc_InitSha(Sha* sha)
|
||||
@@ -223,9 +298,7 @@ WOLFSSL_API int wc_Sha256Hash(const byte* data, word32 len, byte*hash)
|
||||
{
|
||||
return hashHash(data, len, hash, SHAMD5_ALGO_SHA256, SHA256_DIGEST_SIZE) ;
|
||||
}
|
||||
#endif
|
||||
#endif /* TI_HASH_TEST */
|
||||
|
||||
#endif /* NO_SHA256 */
|
||||
|
||||
#endif /* WOLFSSL_TI_HASH */
|
||||
|
||||
#endif /* WOLFSSL_TI_HASH_H */
|
||||
#endif
|
||||
|
@@ -26,7 +26,7 @@
|
||||
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
|
||||
#if !defined(NO_SHA)
|
||||
#if !defined(NO_SHA) && !defined(WOLFSSL_TI_HASH)
|
||||
|
||||
#include <wolfssl/wolfcrypt/sha.h>
|
||||
#include <wolfssl/wolfcrypt/logging.h>
|
||||
@@ -196,6 +196,10 @@ int wc_ShaFinal(Sha* sha, byte* hash)
|
||||
return wc_InitSha(sha); /* reset state */
|
||||
}
|
||||
|
||||
#elif defined(WOLFSSL_TI_HASH)
|
||||
|
||||
/* defined in port/ti/ti_sha.c */
|
||||
|
||||
#else /* wc_ software implementation */
|
||||
|
||||
#ifndef WOLFSSL_HAVE_MIN
|
||||
@@ -447,6 +451,23 @@ int wc_ShaHash(const byte* data, word32 len, byte* hash)
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
#ifdef WOLFSSL_TI_HASH
|
||||
#include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
|
||||
#endif
|
||||
int wc_ShaGetHash(Sha* sha, byte* hash)
|
||||
{
|
||||
#if defined(WOLFSS_TI_HASH)
|
||||
wc_ShaGetHash_TI(sha, hash) ;
|
||||
#else
|
||||
int ret ;
|
||||
Sha save = *sha ;
|
||||
ret = wc_ShaFinal(sha, hash) ;
|
||||
*sha = save ;
|
||||
return ret ;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* HAVE_FIPS */
|
||||
#endif /* NO_SHA */
|
||||
|
||||
|
22
wolfcrypt/src/sha256.c
Executable file → Normal file
22
wolfcrypt/src/sha256.c
Executable file → Normal file
@@ -56,6 +56,9 @@ int wc_Sha256Hash(const byte* data, word32 len, byte* out)
|
||||
|
||||
#else /* else build without fips */
|
||||
|
||||
#if !defined(NO_SHA256) && !defined(WOLFSSL_TI_HASH)
|
||||
/* defined in port/ti/ti_sha256.c */
|
||||
|
||||
#if !defined (ALIGN32)
|
||||
#if defined (__GNUC__)
|
||||
#define ALIGN32 __attribute__ ( (aligned (32)))
|
||||
@@ -573,6 +576,22 @@ int wc_Sha256Hash(const byte* data, word32 len, byte* hash)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef WOLFSSL_TI_HASH
|
||||
#include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
|
||||
#endif
|
||||
int wc_Sha256GetHash(Sha256* sha256, byte* hash)
|
||||
{
|
||||
#if defined(WOLFSS_TI_HASH)
|
||||
return wc_Sha256GetHash_TI(sha256, hash) ;
|
||||
#else
|
||||
int ret ;
|
||||
Sha256 save = *sha256 ;
|
||||
ret = wc_Sha256Final(sha256, hash) ;
|
||||
*sha256 = save ;
|
||||
return ret ;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(HAVE_INTEL_AVX1) || defined(HAVE_INTEL_AVX2)
|
||||
|
||||
#define _DigestToReg(S_0, S_1, S_2, S_3, S_4, S_5, S_6, S_7 )\
|
||||
@@ -1753,6 +1772,9 @@ static int Transform_AVX2(Sha256* sha256)
|
||||
}
|
||||
|
||||
#endif /* HAVE_INTEL_AVX2 */
|
||||
|
||||
#endif /* WOLFSSL_TI_HAHS */
|
||||
|
||||
#endif /* HAVE_FIPS */
|
||||
|
||||
#endif /* NO_SHA256 */
|
||||
|
@@ -37,7 +37,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* in bytes */
|
||||
enum {
|
||||
#ifdef STM32F2_HASH
|
||||
@@ -53,6 +52,13 @@ enum {
|
||||
#include "port/pic32/pic32mz-crypt.h"
|
||||
#endif
|
||||
|
||||
#ifdef TI_HASH_TEST
|
||||
#include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef WOLFSSL_TI_HASH
|
||||
|
||||
/* MD5 digest */
|
||||
typedef struct Md5 {
|
||||
word32 buffLen; /* in bytes */
|
||||
@@ -65,13 +71,26 @@ typedef struct Md5 {
|
||||
word32 digest[PIC32_HASH_SIZE / sizeof(word32)];
|
||||
pic32mz_desc desc ; /* Crypt Engine descripter */
|
||||
#endif
|
||||
|
||||
#ifdef TI_HASH_TEST
|
||||
wolfssl_TI_Hash ti ;
|
||||
#endif
|
||||
|
||||
} Md5;
|
||||
|
||||
#if defined(TI_HASH_TEST)
|
||||
void wc_Md5GetHash_ti(Md5* md5, byte* hash) ;
|
||||
#endif
|
||||
|
||||
#else /* WOLFSSL_TI_HASH */
|
||||
#include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
|
||||
#endif
|
||||
|
||||
WOLFSSL_API void wc_InitMd5(Md5*);
|
||||
WOLFSSL_API void wc_Md5Update(Md5*, const byte*, word32);
|
||||
WOLFSSL_API void wc_Md5Final(Md5*, byte*);
|
||||
WOLFSSL_API int wc_Md5Hash(const byte*, word32, byte*);
|
||||
|
||||
WOLFSSL_API void wc_Md5GetHash(Md5*, byte*);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
@@ -51,6 +51,8 @@ enum {
|
||||
#include "port/pic32/pic32mz-crypt.h"
|
||||
#endif
|
||||
|
||||
#ifndef WOLFSSL_TI_HASH
|
||||
|
||||
/* Sha digest */
|
||||
typedef struct Sha {
|
||||
word32 buffLen; /* in bytes */
|
||||
@@ -64,12 +66,18 @@ typedef struct Sha {
|
||||
pic32mz_desc desc; /* Crypt Engine descripter */
|
||||
#endif
|
||||
} Sha;
|
||||
|
||||
#else /* WOLFSSL_TI_HASH */
|
||||
#include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
|
||||
#endif
|
||||
|
||||
#endif /* HAVE_FIPS */
|
||||
|
||||
WOLFSSL_API int wc_InitSha(Sha*);
|
||||
WOLFSSL_API int wc_ShaUpdate(Sha*, const byte*, word32);
|
||||
WOLFSSL_API int wc_ShaFinal(Sha*, byte*);
|
||||
WOLFSSL_API int wc_ShaHash(const byte*, word32, byte*);
|
||||
WOLFSSL_API int wc_ShaGetHash(Sha*, byte*);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
@@ -51,6 +51,7 @@ enum {
|
||||
SHA256_PAD_SIZE = 56
|
||||
};
|
||||
|
||||
#ifndef WOLFSSL_TI_HASH
|
||||
|
||||
/* Sha256 digest */
|
||||
typedef struct Sha256 {
|
||||
@@ -64,12 +65,17 @@ typedef struct Sha256 {
|
||||
#endif
|
||||
} Sha256;
|
||||
|
||||
#else /* WOLFSSL_TI_HASH */
|
||||
#include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
|
||||
#endif
|
||||
|
||||
#endif /* HAVE_FIPS */
|
||||
|
||||
WOLFSSL_API int wc_InitSha256(Sha256*);
|
||||
WOLFSSL_API int wc_Sha256Update(Sha256*, const byte*, word32);
|
||||
WOLFSSL_API int wc_Sha256Final(Sha256*, byte*);
|
||||
WOLFSSL_API int wc_Sha256Hash(const byte*, word32, byte*);
|
||||
WOLFSSL_API int wc_Sha256GetHash(Sha256*, byte*);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
Reference in New Issue
Block a user