summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSalvatore Bonaccorso <carnil@debian.org>2015-04-04 16:09:09 +0200
committerSalvatore Bonaccorso <carnil@debian.org>2015-04-04 16:09:09 +0200
commit5a85909d1ee74a534673498f05bb1d7e91e479a5 (patch)
treea1923726723babb362fa583c3f4214592e225d37 /src
parent1230dd61f8d463249bb3f168a2eee2f69298cb27 (diff)
Imported Upstream version 5.95
Diffstat (limited to 'src')
-rw-r--r--src/sha.c63
-rw-r--r--src/sha.h6
-rw-r--r--src/sha64bit.c16
-rw-r--r--src/sha64bit.h8
4 files changed, 36 insertions, 57 deletions
diff --git a/src/sha.c b/src/sha.c
index 3756969..ea0d41b 100644
--- a/src/sha.c
+++ b/src/sha.c
@@ -3,10 +3,10 @@
*
* Ref: NIST FIPS PUB 180-4 Secure Hash Standard
*
- * Copyright (C) 2003-2014 Mark Shelor, All Rights Reserved
+ * Copyright (C) 2003-2015 Mark Shelor, All Rights Reserved
*
- * Version: 5.93
- * Sun Oct 26 06:00:48 MST 2014
+ * Version: 5.95
+ * Sat Jan 10 12:15:36 MST 2015
*
*/
@@ -45,7 +45,7 @@
#define K3 C32(0x8f1bbcdc)
#define K4 C32(0xca62c1d6)
-static W32 K256[64] = /* SHA-224/256 constants */
+static const W32 K256[64] = /* SHA-224/256 constants */
{
C32(0x428a2f98), C32(0x71374491), C32(0xb5c0fbcf), C32(0xe9b5dba5),
C32(0x3956c25b), C32(0x59f111f1), C32(0x923f82a4), C32(0xab1c5ed5),
@@ -65,19 +65,19 @@ static W32 K256[64] = /* SHA-224/256 constants */
C32(0x90befffa), C32(0xa4506ceb), C32(0xbef9a3f7), C32(0xc67178f2)
};
-static W32 H01[8] = /* SHA-1 initial hash value */
+static const W32 H01[8] = /* SHA-1 initial hash value */
{
C32(0x67452301), C32(0xefcdab89), C32(0x98badcfe), C32(0x10325476),
C32(0xc3d2e1f0), C32(0x00000000), C32(0x00000000), C32(0x00000000)
};
-static W32 H0224[8] = /* SHA-224 initial hash value */
+static const W32 H0224[8] = /* SHA-224 initial hash value */
{
C32(0xc1059ed8), C32(0x367cd507), C32(0x3070dd17), C32(0xf70e5939),
C32(0xffc00b31), C32(0x68581511), C32(0x64f98fa7), C32(0xbefa4fa4)
};
-static W32 H0256[8] = /* SHA-256 initial hash value */
+static const W32 H0256[8] = /* SHA-256 initial hash value */
{
C32(0x6a09e667), C32(0xbb67ae85), C32(0x3c6ef372), C32(0xa54ff53a),
C32(0x510e527f), C32(0x9b05688c), C32(0x1f83d9ab), C32(0x5be0cd19)
@@ -154,7 +154,7 @@ static void sha256(SHA *s, UCHR *block) /* SHA-224/256 transform */
{
W32 a, b, c, d, e, f, g, h, T1;
W32 W[16];
- W32 *kp = K256;
+ const W32 *kp = K256;
W32 *wp = W;
W32 *H = s->H32;
@@ -214,6 +214,7 @@ static void sha256(SHA *s, UCHR *block) /* SHA-224/256 transform */
#include "sha64bit.c"
+#define BITSET(s, pos) s[(pos) >> 3] & (UCHR) (0x01 << (7 - (pos) % 8))
#define SETBIT(s, pos) s[(pos) >> 3] |= (UCHR) (0x01 << (7 - (pos) % 8))
#define CLRBIT(s, pos) s[(pos) >> 3] &= (UCHR) ~(0x01 << (7 - (pos) % 8))
#define NBYTES(nbits) (((nbits) + 7) >> 3)
@@ -359,45 +360,23 @@ static ULNG shabytes(UCHR *bitstr, ULNG bitcnt, SHA *s)
/* shabits: updates state for bit-aligned data in s->block */
static ULNG shabits(UCHR *bitstr, ULNG bitcnt, SHA *s)
{
- UINT i;
- UINT gap;
- ULNG nbits;
- UCHR buf[1<<9];
- UINT bufsize = sizeof(buf);
- ULNG bufbits = (ULNG) bufsize << 3;
- UINT nbytes = NBYTES(bitcnt);
- ULNG savecnt = bitcnt;
+ ULNG i;
- gap = 8 - s->blockcnt % 8;
- s->block[s->blockcnt>>3] &= (UCHR) (~0 << gap);
- s->block[s->blockcnt>>3] |= (UCHR) (*bitstr >> (8 - gap));
- s->blockcnt += bitcnt < gap ? bitcnt : gap;
- if (bitcnt < gap)
- return(savecnt);
- if (s->blockcnt == s->blocksize)
- s->sha(s, s->block), s->blockcnt = 0;
- if ((bitcnt -= gap) == 0)
- return(savecnt);
- while (nbytes > bufsize) {
- for (i = 0; i < bufsize; i++)
- buf[i] = (UCHR) (bitstr[i] << gap) |
- (UCHR) (bitstr[i+1] >> (8-gap));
- nbits = bitcnt < bufbits ? bitcnt : bufbits;
- shabytes(buf, nbits, s);
- bitcnt -= nbits, bitstr += bufsize, nbytes -= bufsize;
+ for (i = 0UL; i < bitcnt; i++) {
+ if (BITSET(bitstr, i))
+ SETBIT(s->block, s->blockcnt), s->blockcnt++;
+ else
+ CLRBIT(s->block, s->blockcnt), s->blockcnt++;
+ if (s->blockcnt == s->blocksize)
+ s->sha(s, s->block), s->blockcnt = 0;
}
- for (i = 0; i < nbytes - 1; i++)
- buf[i] = (UCHR) (bitstr[i] << gap) |
- (UCHR) (bitstr[i+1] >> (8-gap));
- buf[nbytes-1] = (UCHR) (bitstr[nbytes-1] << gap);
- shabytes(buf, bitcnt, s);
- return(savecnt);
+ return(bitcnt);
}
/* shawrite: triggers a state update using data in bitstr/bitcnt */
static ULNG shawrite(UCHR *bitstr, ULNG bitcnt, SHA *s)
{
- if (bitcnt < 1)
+ if (!bitcnt)
return(0);
if (SHA_LO32(s->lenll += bitcnt) < bitcnt)
if (SHA_LO32(++s->lenlh) == 0)
@@ -439,7 +418,7 @@ static void shafinish(SHA *s)
#define shadigest(state) digcpy(state)
/* xmap: translation map for hexadecimal encoding */
-static char xmap[] =
+static const char xmap[] =
"0123456789abcdef";
/* shahex: returns pointer to current digest (hexadecimal) */
@@ -462,7 +441,7 @@ static char *shahex(SHA *s)
}
/* bmap: translation map for Base 64 encoding */
-static char bmap[] =
+static const char bmap[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/* encbase64: encodes input (0 to 3 bytes) into Base 64 */
diff --git a/src/sha.h b/src/sha.h
index 61f365e..e63d4b7 100644
--- a/src/sha.h
+++ b/src/sha.h
@@ -3,10 +3,10 @@
*
* Ref: NIST FIPS PUB 180-4 Secure Hash Standard
*
- * Copyright (C) 2003-2014 Mark Shelor, All Rights Reserved
+ * Copyright (C) 2003-2015 Mark Shelor, All Rights Reserved
*
- * Version: 5.93
- * Sun Oct 26 06:00:48 MST 2014
+ * Version: 5.95
+ * Sat Jan 10 12:15:36 MST 2015
*
*/
diff --git a/src/sha64bit.c b/src/sha64bit.c
index add57e0..2fa0dda 100644
--- a/src/sha64bit.c
+++ b/src/sha64bit.c
@@ -3,10 +3,10 @@
*
* Ref: NIST FIPS PUB 180-4 Secure Hash Standard
*
- * Copyright (C) 2003-2014 Mark Shelor, All Rights Reserved
+ * Copyright (C) 2003-2015 Mark Shelor, All Rights Reserved
*
- * Version: 5.93
- * Sun Oct 26 06:00:48 MST 2014
+ * Version: 5.95
+ * Sat Jan 10 12:15:36 MST 2015
*
*/
@@ -33,7 +33,7 @@
#define sigmaQ0(x) (ROTRQ(x, 1) ^ ROTRQ(x, 8) ^ SR64(x, 7))
#define sigmaQ1(x) (ROTRQ(x, 19) ^ ROTRQ(x, 61) ^ SR64(x, 6))
-static W64 K512[80] = /* SHA-384/512 constants */
+static const W64 K512[80] = /* SHA-384/512 constants */
{
C64(0x428a2f98d728ae22), C64(0x7137449123ef65cd), C64(0xb5c0fbcfec4d3b2f),
C64(0xe9b5dba58189dbbc), C64(0x3956c25bf348b538), C64(0x59f111f1b605d019),
@@ -64,28 +64,28 @@ C64(0x431d67c49c100d4c), C64(0x4cc5d4becb3e42b6), C64(0x597f299cfc657e2a),
C64(0x5fcb6fab3ad6faec), C64(0x6c44198c4a475817)
};
-static W64 H0384[8] = /* SHA-384 initial hash value */
+static const W64 H0384[8] = /* SHA-384 initial hash value */
{
C64(0xcbbb9d5dc1059ed8), C64(0x629a292a367cd507), C64(0x9159015a3070dd17),
C64(0x152fecd8f70e5939), C64(0x67332667ffc00b31), C64(0x8eb44a8768581511),
C64(0xdb0c2e0d64f98fa7), C64(0x47b5481dbefa4fa4)
};
-static W64 H0512[8] = /* SHA-512 initial hash value */
+static const W64 H0512[8] = /* SHA-512 initial hash value */
{
C64(0x6a09e667f3bcc908), C64(0xbb67ae8584caa73b), C64(0x3c6ef372fe94f82b),
C64(0xa54ff53a5f1d36f1), C64(0x510e527fade682d1), C64(0x9b05688c2b3e6c1f),
C64(0x1f83d9abfb41bd6b), C64(0x5be0cd19137e2179)
};
-static W64 H0512224[8] = /* SHA-512/224 initial hash value */
+static const W64 H0512224[8] = /* SHA-512/224 initial hash value */
{
C64(0x8c3d37c819544da2), C64(0x73e1996689dcd4d6), C64(0x1dfab7ae32ff9c82),
C64(0x679dd514582f9fcf), C64(0x0f6d2b697bd44da8), C64(0x77e36f7304c48942),
C64(0x3f9d85a86a1d36c8), C64(0x1112e6ad91d692a1)
};
-static W64 H0512256[8] = /* SHA-512/256 initial hash value */
+static const W64 H0512256[8] = /* SHA-512/256 initial hash value */
{
C64(0x22312194fc2bf72c), C64(0x9f555fa3c84c64c2), C64(0x2393b86b6f53b151),
C64(0x963877195940eabd), C64(0x96283ee2a88effe3), C64(0xbe5e1e2553863992),
diff --git a/src/sha64bit.h b/src/sha64bit.h
index 01dadc5..ce89548 100644
--- a/src/sha64bit.h
+++ b/src/sha64bit.h
@@ -3,10 +3,10 @@
*
* Ref: NIST FIPS PUB 180-4 Secure Hash Standard
*
- * Copyright (C) 2003-2014 Mark Shelor, All Rights Reserved
+ * Copyright (C) 2003-2015 Mark Shelor, All Rights Reserved
*
- * Version: 5.93
- * Sun Oct 26 06:00:48 MST 2014
+ * Version: 5.95
+ * Sat Jan 10 12:15:36 MST 2015
*
* The following macros supply placeholder values that enable the
* sha.c module to successfully compile when 64-bit integer types
@@ -18,7 +18,7 @@
*/
#define sha_384_512 0
-#define W64 SHA32
+#define W64 SHA64
#define sha512 NULL
#define H0384 H01
#define H0512 H01