summaryrefslogtreecommitdiffstats
path: root/security/nss/lib/freebl/sha_fast.c
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-12-23 19:02:52 +0000
committerMoonchild <moonchild@palemoon.org>2020-12-23 19:02:52 +0000
commit029bcfe189eae5eebbaf58ccff4e1200dd78b228 (patch)
tree1c226a334ea1a88e2d1c6f949c9320eb0c3bff59 /security/nss/lib/freebl/sha_fast.c
parent149d2ffa779826cb48a381099858e76e4624d471 (diff)
downloadUXP-029bcfe189eae5eebbaf58ccff4e1200dd78b228.tar
UXP-029bcfe189eae5eebbaf58ccff4e1200dd78b228.tar.gz
UXP-029bcfe189eae5eebbaf58ccff4e1200dd78b228.tar.lz
UXP-029bcfe189eae5eebbaf58ccff4e1200dd78b228.tar.xz
UXP-029bcfe189eae5eebbaf58ccff4e1200dd78b228.zip
Issue #1693 - Update NSS to 3.59.1.1
This updates to MoonchildProductions/NSS@bd49b2b88 in the repo created for our consumption of the library.
Diffstat (limited to 'security/nss/lib/freebl/sha_fast.c')
-rw-r--r--security/nss/lib/freebl/sha_fast.c51
1 files changed, 49 insertions, 2 deletions
diff --git a/security/nss/lib/freebl/sha_fast.c b/security/nss/lib/freebl/sha_fast.c
index 52071f0c9..2a8ac576c 100644
--- a/security/nss/lib/freebl/sha_fast.c
+++ b/security/nss/lib/freebl/sha_fast.c
@@ -10,6 +10,7 @@
#include "blapi.h"
#include "sha_fast.h"
#include "prerror.h"
+#include "secerr.h"
#ifdef TRACING_SSL
#include "ssl.h"
@@ -28,6 +29,28 @@ static void shaCompress(volatile SHA_HW_t *X, const PRUint32 *datain);
#define SHA_MIX(n, a, b, c) XW(n) = SHA_ROTL(XW(a) ^ XW(b) ^ XW(c) ^ XW(n), 1)
+void SHA1_Compress_Native(SHA1Context *ctx);
+void SHA1_Update_Native(SHA1Context *ctx, const unsigned char *dataIn, unsigned int len);
+
+static void SHA1_Compress_Generic(SHA1Context *ctx);
+static void SHA1_Update_Generic(SHA1Context *ctx, const unsigned char *dataIn, unsigned int len);
+
+#ifndef USE_HW_SHA1
+void
+SHA1_Compress_Native(SHA1Context *ctx)
+{
+ PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
+ PORT_Assert(0);
+}
+
+void
+SHA1_Update_Native(SHA1Context *ctx, const unsigned char *dataIn, unsigned int len)
+{
+ PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
+ PORT_Assert(0);
+}
+#endif
+
/*
* SHA: initialize context
*/
@@ -43,6 +66,18 @@ SHA1_Begin(SHA1Context *ctx)
ctx->H[2] = 0x98badcfeL;
ctx->H[3] = 0x10325476L;
ctx->H[4] = 0xc3d2e1f0L;
+
+#if defined(USE_HW_SHA1) && defined(IS_LITTLE_ENDIAN)
+ /* arm's implementation is tested on little endian only */
+ if (arm_sha1_support()) {
+ ctx->compress = SHA1_Compress_Native;
+ ctx->update = SHA1_Update_Native;
+ } else
+#endif
+ {
+ ctx->compress = SHA1_Compress_Generic;
+ ctx->update = SHA1_Update_Generic;
+ }
}
/* Explanation of H array and index values:
@@ -89,6 +124,12 @@ SHA1_Begin(SHA1Context *ctx)
void
SHA1_Update(SHA1Context *ctx, const unsigned char *dataIn, unsigned int len)
{
+ ctx->update(ctx, dataIn, len);
+}
+
+static void
+SHA1_Update_Generic(SHA1Context *ctx, const unsigned char *dataIn, unsigned int len)
+{
register unsigned int lenB;
register unsigned int togo;
@@ -166,7 +207,7 @@ SHA1_End(SHA1Context *ctx, unsigned char *hashout,
size <<= 3;
ctx->W[14] = SHA_HTONL((PRUint32)(size >> 32));
ctx->W[15] = SHA_HTONL((PRUint32)size);
- shaCompress(&ctx->H[H2X], ctx->W);
+ ctx->compress(ctx);
/*
* Output hash
@@ -460,6 +501,12 @@ shaCompress(volatile SHA_HW_t *X, const PRUint32 *inbuf)
XH(4) += E;
}
+static void
+SHA1_Compress_Generic(SHA1Context *ctx)
+{
+ shaCompress(&ctx->H[H2X], ctx->u.w);
+}
+
/*************************************************************************
** Code below this line added to make SHA code support BLAPI interface
*/
@@ -491,7 +538,7 @@ SHA1_HashBuf(unsigned char *dest, const unsigned char *src, PRUint32 src_length)
unsigned int outLen;
SHA1_Begin(&ctx);
- SHA1_Update(&ctx, src, src_length);
+ ctx.update(&ctx, src, src_length);
SHA1_End(&ctx, dest, &outLen, SHA1_LENGTH);
memset(&ctx, 0, sizeof ctx);
return SECSuccess;