mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-30 10:47:28 +02:00
Merge pull request #3903 from SparkiDev/sha2_arm
ARMv8 SHA256, SHA512: Add wc_Sha256Transform, wc_Sha512Transform
This commit is contained in:
@ -96,29 +96,12 @@ static WC_INLINE void AddLength(wc_Sha256* sha256, word32 len)
|
||||
|
||||
#ifdef __aarch64__
|
||||
|
||||
/* ARMv8 hardware acceleration */
|
||||
static WC_INLINE int Sha256Update(wc_Sha256* sha256, const byte* data, word32 len)
|
||||
/* First block is in sha256->buffer and rest in data. */
|
||||
static WC_INLINE void Sha256Transform(wc_Sha256* sha256, const byte* data,
|
||||
word32 numBlocks)
|
||||
{
|
||||
word32 add;
|
||||
word32 numBlocks;
|
||||
|
||||
/* only perform actions if a buffer is passed in */
|
||||
if (len > 0) {
|
||||
/* fill leftover buffer with data */
|
||||
add = min(len, WC_SHA256_BLOCK_SIZE - sha256->buffLen);
|
||||
XMEMCPY((byte*)(sha256->buffer) + sha256->buffLen, data, add);
|
||||
sha256->buffLen += add;
|
||||
data += add;
|
||||
len -= add;
|
||||
|
||||
/* number of blocks in a row to complete */
|
||||
numBlocks = (len + sha256->buffLen)/WC_SHA256_BLOCK_SIZE;
|
||||
|
||||
if (numBlocks > 0) {
|
||||
word32* k = (word32*)K;
|
||||
|
||||
/* get leftover amount after blocks */
|
||||
add = (len + sha256->buffLen) - numBlocks * WC_SHA256_BLOCK_SIZE;
|
||||
__asm__ volatile (
|
||||
"#load leftover data\n"
|
||||
"LD1 {v0.2d-v3.2d}, %[buffer] \n"
|
||||
@ -293,6 +276,31 @@ static WC_INLINE int Sha256Update(wc_Sha256* sha256, const byte* data, word32 le
|
||||
"v22", "v23", "v24", "v25", "v26", "v27", "v28",
|
||||
"v29", "v30", "v31", "w8"
|
||||
);
|
||||
}
|
||||
|
||||
/* ARMv8 hardware acceleration */
|
||||
static WC_INLINE int Sha256Update(wc_Sha256* sha256, const byte* data, word32 len)
|
||||
{
|
||||
word32 add;
|
||||
word32 numBlocks;
|
||||
|
||||
/* only perform actions if a buffer is passed in */
|
||||
if (len > 0) {
|
||||
/* fill leftover buffer with data */
|
||||
add = min(len, WC_SHA256_BLOCK_SIZE - sha256->buffLen);
|
||||
XMEMCPY((byte*)(sha256->buffer) + sha256->buffLen, data, add);
|
||||
sha256->buffLen += add;
|
||||
data += add;
|
||||
len -= add;
|
||||
|
||||
/* number of blocks in a row to complete */
|
||||
numBlocks = (len + sha256->buffLen)/WC_SHA256_BLOCK_SIZE;
|
||||
|
||||
if (numBlocks > 0) {
|
||||
/* get leftover amount after blocks */
|
||||
add = (len + sha256->buffLen) - numBlocks * WC_SHA256_BLOCK_SIZE;
|
||||
|
||||
Sha256Transform(sha256, data, numBlocks);
|
||||
|
||||
AddLength(sha256, WC_SHA256_BLOCK_SIZE * numBlocks);
|
||||
|
||||
@ -658,29 +666,12 @@ static WC_INLINE int Sha256Final(wc_Sha256* sha256, byte* hash)
|
||||
|
||||
#else /* not using 64 bit */
|
||||
|
||||
/* ARMv8 hardware acceleration Aarch32 */
|
||||
static WC_INLINE int Sha256Update(wc_Sha256* sha256, const byte* data, word32 len)
|
||||
static WC_INLINE void Sha256Transform(wc_Sha256* sha256, const byte* data,
|
||||
word32 numBlocks)
|
||||
{
|
||||
word32 add;
|
||||
word32 numBlocks;
|
||||
|
||||
/* only perform actions if a buffer is passed in */
|
||||
if (len > 0) {
|
||||
/* fill leftover buffer with data */
|
||||
add = min(len, WC_SHA256_BLOCK_SIZE - sha256->buffLen);
|
||||
XMEMCPY((byte*)(sha256->buffer) + sha256->buffLen, data, add);
|
||||
sha256->buffLen += add;
|
||||
data += add;
|
||||
len -= add;
|
||||
|
||||
/* number of blocks in a row to complete */
|
||||
numBlocks = (len + sha256->buffLen)/WC_SHA256_BLOCK_SIZE;
|
||||
|
||||
if (numBlocks > 0) {
|
||||
word32* bufPt = sha256->buffer;
|
||||
word32* digPt = sha256->digest;
|
||||
/* get leftover amount after blocks */
|
||||
add = (len + sha256->buffLen) - numBlocks * WC_SHA256_BLOCK_SIZE;
|
||||
|
||||
__asm__ volatile (
|
||||
"#load leftover data\n"
|
||||
"VLDM %[buffer]!, {q0-q3} \n"
|
||||
@ -869,6 +860,31 @@ static WC_INLINE int Sha256Update(wc_Sha256* sha256, const byte* data, word32 le
|
||||
"q8", "q9", "q10", "q11", "q12", "q13", "q14",
|
||||
"q15", "r8"
|
||||
);
|
||||
}
|
||||
|
||||
/* ARMv8 hardware acceleration Aarch32 */
|
||||
static WC_INLINE int Sha256Update(wc_Sha256* sha256, const byte* data, word32 len)
|
||||
{
|
||||
word32 add;
|
||||
word32 numBlocks;
|
||||
|
||||
/* only perform actions if a buffer is passed in */
|
||||
if (len > 0) {
|
||||
/* fill leftover buffer with data */
|
||||
add = min(len, WC_SHA256_BLOCK_SIZE - sha256->buffLen);
|
||||
XMEMCPY((byte*)(sha256->buffer) + sha256->buffLen, data, add);
|
||||
sha256->buffLen += add;
|
||||
data += add;
|
||||
len -= add;
|
||||
|
||||
/* number of blocks in a row to complete */
|
||||
numBlocks = (len + sha256->buffLen)/WC_SHA256_BLOCK_SIZE;
|
||||
|
||||
if (numBlocks > 0) {
|
||||
/* get leftover amount after blocks */
|
||||
add = (len + sha256->buffLen) - numBlocks * WC_SHA256_BLOCK_SIZE;
|
||||
|
||||
Sha256Transform(sha256, data, numBlocks);
|
||||
|
||||
AddLength(sha256, WC_SHA256_BLOCK_SIZE * numBlocks);
|
||||
|
||||
@ -1401,6 +1417,22 @@ int wc_Sha256Copy(wc_Sha256* src, wc_Sha256* dst)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef OPENSSL_EXTRA
|
||||
int wc_Sha256Transform(wc_Sha256* sha256, const unsigned char* data)
|
||||
{
|
||||
if (sha256 == NULL || data == NULL) {
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
#ifdef LITTLE_ENDIAN_ORDER
|
||||
ByteReverseWords(sha256->buffer, (word32*)data, WC_SHA256_BLOCK_SIZE);
|
||||
#else
|
||||
XMEMCPY(sha256->buffer, data, WC_SHA256_BLOCK_SIZE);
|
||||
#endif
|
||||
Sha256Transform(sha256, data, 1);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !NO_SHA256 */
|
||||
|
||||
|
||||
|
@ -483,6 +483,17 @@ void wc_Sha512Free(wc_Sha512* sha512)
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef OPENSSL_EXTRA
|
||||
int wc_Sha512Transform(wc_Sha512* sha512, const unsigned char* data)
|
||||
{
|
||||
if (sha512 == NULL || data == NULL) {
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
Transform_Sha512_Len(sha512, data, WC_SHA512_BLOCK_SIZE);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WOLFSSL_SHA512 */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
Reference in New Issue
Block a user