aboutsummaryrefslogtreecommitdiff
path: root/openssl/crypto/whrlpool/wp_dgst.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2015-02-22 14:43:31 +0100
committermarha <marha@users.sourceforge.net>2015-02-22 14:43:31 +0100
commitc9aad1ae6227c434d480d1d3aa8eae3c3c910c18 (patch)
tree94b917df998c3d547e191b3b9c58bbffc616470e /openssl/crypto/whrlpool/wp_dgst.c
parentf1c2db43dcf35d2cf4715390bd2391c28e42a8c2 (diff)
downloadvcxsrv-c9aad1ae6227c434d480d1d3aa8eae3c3c910c18.tar.gz
vcxsrv-c9aad1ae6227c434d480d1d3aa8eae3c3c910c18.tar.bz2
vcxsrv-c9aad1ae6227c434d480d1d3aa8eae3c3c910c18.zip
Upgraded to openssl-1.0.2
Diffstat (limited to 'openssl/crypto/whrlpool/wp_dgst.c')
-rw-r--r--openssl/crypto/whrlpool/wp_dgst.c370
1 files changed, 181 insertions, 189 deletions
diff --git a/openssl/crypto/whrlpool/wp_dgst.c b/openssl/crypto/whrlpool/wp_dgst.c
index 7e28bef51..e33bb4f83 100644
--- a/openssl/crypto/whrlpool/wp_dgst.c
+++ b/openssl/crypto/whrlpool/wp_dgst.c
@@ -56,210 +56,202 @@
#include <string.h>
fips_md_init(WHIRLPOOL)
- {
- memset (c,0,sizeof(*c));
- return(1);
- }
+{
+ memset(c, 0, sizeof(*c));
+ return (1);
+}
-int WHIRLPOOL_Update (WHIRLPOOL_CTX *c,const void *_inp,size_t bytes)
- {
- /* Well, largest suitable chunk size actually is
- * (1<<(sizeof(size_t)*8-3))-64, but below number
- * is large enough for not to care about excessive
- * calls to WHIRLPOOL_BitUpdate... */
- size_t chunk = ((size_t)1)<<(sizeof(size_t)*8-4);
- const unsigned char *inp = _inp;
+int WHIRLPOOL_Update(WHIRLPOOL_CTX *c, const void *_inp, size_t bytes)
+{
+ /*
+ * Well, largest suitable chunk size actually is
+ * (1<<(sizeof(size_t)*8-3))-64, but below number is large enough for not
+ * to care about excessive calls to WHIRLPOOL_BitUpdate...
+ */
+ size_t chunk = ((size_t)1) << (sizeof(size_t) * 8 - 4);
+ const unsigned char *inp = _inp;
- while (bytes>=chunk)
- {
- WHIRLPOOL_BitUpdate(c,inp,chunk*8);
- bytes -= chunk;
- inp += chunk;
- }
- if (bytes)
- WHIRLPOOL_BitUpdate(c,inp,bytes*8);
+ while (bytes >= chunk) {
+ WHIRLPOOL_BitUpdate(c, inp, chunk * 8);
+ bytes -= chunk;
+ inp += chunk;
+ }
+ if (bytes)
+ WHIRLPOOL_BitUpdate(c, inp, bytes * 8);
- return(1);
- }
+ return (1);
+}
-void WHIRLPOOL_BitUpdate(WHIRLPOOL_CTX *c,const void *_inp,size_t bits)
- {
- size_t n;
- unsigned int bitoff = c->bitoff,
- bitrem = bitoff%8,
- inpgap = (8-(unsigned int)bits%8)&7;
- const unsigned char *inp=_inp;
-
- /* This 256-bit increment procedure relies on the size_t
- * being natural size of CPU register, so that we don't
- * have to mask the value in order to detect overflows. */
- c->bitlen[0] += bits;
- if (c->bitlen[0] < bits) /* overflow */
- {
- n = 1;
- do { c->bitlen[n]++;
- } while(c->bitlen[n]==0
- && ++n<(WHIRLPOOL_COUNTER/sizeof(size_t)));
- }
+void WHIRLPOOL_BitUpdate(WHIRLPOOL_CTX *c, const void *_inp, size_t bits)
+{
+ size_t n;
+ unsigned int bitoff = c->bitoff,
+ bitrem = bitoff % 8, inpgap = (8 - (unsigned int)bits % 8) & 7;
+ const unsigned char *inp = _inp;
+ /*
+ * This 256-bit increment procedure relies on the size_t being natural
+ * size of CPU register, so that we don't have to mask the value in order
+ * to detect overflows.
+ */
+ c->bitlen[0] += bits;
+ if (c->bitlen[0] < bits) { /* overflow */
+ n = 1;
+ do {
+ c->bitlen[n]++;
+ } while (c->bitlen[n] == 0
+ && ++n < (WHIRLPOOL_COUNTER / sizeof(size_t)));
+ }
#ifndef OPENSSL_SMALL_FOOTPRINT
- reconsider:
- if (inpgap==0 && bitrem==0) /* byte-oriented loop */
- {
- while (bits)
- {
- if (bitoff==0 && (n=bits/WHIRLPOOL_BBLOCK))
- {
- whirlpool_block(c,inp,n);
- inp += n*WHIRLPOOL_BBLOCK/8;
- bits %= WHIRLPOOL_BBLOCK;
- }
- else
- {
- unsigned int byteoff = bitoff/8;
+ reconsider:
+ if (inpgap == 0 && bitrem == 0) { /* byte-oriented loop */
+ while (bits) {
+ if (bitoff == 0 && (n = bits / WHIRLPOOL_BBLOCK)) {
+ whirlpool_block(c, inp, n);
+ inp += n * WHIRLPOOL_BBLOCK / 8;
+ bits %= WHIRLPOOL_BBLOCK;
+ } else {
+ unsigned int byteoff = bitoff / 8;
- bitrem = WHIRLPOOL_BBLOCK - bitoff;/* re-use bitrem */
- if (bits >= bitrem)
- {
- bits -= bitrem;
- bitrem /= 8;
- memcpy(c->data+byteoff,inp,bitrem);
- inp += bitrem;
- whirlpool_block(c,c->data,1);
- bitoff = 0;
- }
- else
- {
- memcpy(c->data+byteoff,inp,bits/8);
- bitoff += (unsigned int)bits;
- bits = 0;
- }
- c->bitoff = bitoff;
- }
- }
- }
- else /* bit-oriented loop */
+ bitrem = WHIRLPOOL_BBLOCK - bitoff; /* re-use bitrem */
+ if (bits >= bitrem) {
+ bits -= bitrem;
+ bitrem /= 8;
+ memcpy(c->data + byteoff, inp, bitrem);
+ inp += bitrem;
+ whirlpool_block(c, c->data, 1);
+ bitoff = 0;
+ } else {
+ memcpy(c->data + byteoff, inp, bits / 8);
+ bitoff += (unsigned int)bits;
+ bits = 0;
+ }
+ c->bitoff = bitoff;
+ }
+ }
+ } else /* bit-oriented loop */
#endif
- {
- /*
- inp
- |
- +-------+-------+-------
- |||||||||||||||||||||
- +-------+-------+-------
- +-------+-------+-------+-------+-------
- |||||||||||||| c->data
- +-------+-------+-------+-------+-------
- |
- c->bitoff/8
- */
- while (bits)
- {
- unsigned int byteoff = bitoff/8;
- unsigned char b;
+ {
+ /*-
+ inp
+ |
+ +-------+-------+-------
+ |||||||||||||||||||||
+ +-------+-------+-------
+ +-------+-------+-------+-------+-------
+ |||||||||||||| c->data
+ +-------+-------+-------+-------+-------
+ |
+ c->bitoff/8
+ */
+ while (bits) {
+ unsigned int byteoff = bitoff / 8;
+ unsigned char b;
#ifndef OPENSSL_SMALL_FOOTPRINT
- if (bitrem==inpgap)
- {
- c->data[byteoff++] |= inp[0] & (0xff>>inpgap);
- inpgap = 8-inpgap;
- bitoff += inpgap; bitrem = 0; /* bitoff%8 */
- bits -= inpgap; inpgap = 0; /* bits%8 */
- inp++;
- if (bitoff==WHIRLPOOL_BBLOCK)
- {
- whirlpool_block(c,c->data,1);
- bitoff = 0;
- }
- c->bitoff = bitoff;
- goto reconsider;
- }
- else
+ if (bitrem == inpgap) {
+ c->data[byteoff++] |= inp[0] & (0xff >> inpgap);
+ inpgap = 8 - inpgap;
+ bitoff += inpgap;
+ bitrem = 0; /* bitoff%8 */
+ bits -= inpgap;
+ inpgap = 0; /* bits%8 */
+ inp++;
+ if (bitoff == WHIRLPOOL_BBLOCK) {
+ whirlpool_block(c, c->data, 1);
+ bitoff = 0;
+ }
+ c->bitoff = bitoff;
+ goto reconsider;
+ } else
#endif
- if (bits>=8)
- {
- b = ((inp[0]<<inpgap) | (inp[1]>>(8-inpgap)));
- b &= 0xff;
- if (bitrem) c->data[byteoff++] |= b>>bitrem;
- else c->data[byteoff++] = b;
- bitoff += 8;
- bits -= 8;
- inp++;
- if (bitoff>=WHIRLPOOL_BBLOCK)
- {
- whirlpool_block(c,c->data,1);
- byteoff = 0;
- bitoff %= WHIRLPOOL_BBLOCK;
- }
- if (bitrem) c->data[byteoff] = b<<(8-bitrem);
- }
- else /* remaining less than 8 bits */
- {
- b = (inp[0]<<inpgap)&0xff;
- if (bitrem) c->data[byteoff++] |= b>>bitrem;
- else c->data[byteoff++] = b;
- bitoff += (unsigned int)bits;
- if (bitoff==WHIRLPOOL_BBLOCK)
- {
- whirlpool_block(c,c->data,1);
- byteoff = 0;
- bitoff %= WHIRLPOOL_BBLOCK;
- }
- if (bitrem) c->data[byteoff] = b<<(8-bitrem);
- bits = 0;
- }
- c->bitoff = bitoff;
- }
- }
- }
+ if (bits >= 8) {
+ b = ((inp[0] << inpgap) | (inp[1] >> (8 - inpgap)));
+ b &= 0xff;
+ if (bitrem)
+ c->data[byteoff++] |= b >> bitrem;
+ else
+ c->data[byteoff++] = b;
+ bitoff += 8;
+ bits -= 8;
+ inp++;
+ if (bitoff >= WHIRLPOOL_BBLOCK) {
+ whirlpool_block(c, c->data, 1);
+ byteoff = 0;
+ bitoff %= WHIRLPOOL_BBLOCK;
+ }
+ if (bitrem)
+ c->data[byteoff] = b << (8 - bitrem);
+ } else { /* remaining less than 8 bits */
+
+ b = (inp[0] << inpgap) & 0xff;
+ if (bitrem)
+ c->data[byteoff++] |= b >> bitrem;
+ else
+ c->data[byteoff++] = b;
+ bitoff += (unsigned int)bits;
+ if (bitoff == WHIRLPOOL_BBLOCK) {
+ whirlpool_block(c, c->data, 1);
+ byteoff = 0;
+ bitoff %= WHIRLPOOL_BBLOCK;
+ }
+ if (bitrem)
+ c->data[byteoff] = b << (8 - bitrem);
+ bits = 0;
+ }
+ c->bitoff = bitoff;
+ }
+ }
+}
-int WHIRLPOOL_Final (unsigned char *md,WHIRLPOOL_CTX *c)
- {
- unsigned int bitoff = c->bitoff,
- byteoff = bitoff/8;
- size_t i,j,v;
- unsigned char *p;
+int WHIRLPOOL_Final(unsigned char *md, WHIRLPOOL_CTX *c)
+{
+ unsigned int bitoff = c->bitoff, byteoff = bitoff / 8;
+ size_t i, j, v;
+ unsigned char *p;
- bitoff %= 8;
- if (bitoff) c->data[byteoff] |= 0x80>>bitoff;
- else c->data[byteoff] = 0x80;
- byteoff++;
+ bitoff %= 8;
+ if (bitoff)
+ c->data[byteoff] |= 0x80 >> bitoff;
+ else
+ c->data[byteoff] = 0x80;
+ byteoff++;
- /* pad with zeros */
- if (byteoff > (WHIRLPOOL_BBLOCK/8-WHIRLPOOL_COUNTER))
- {
- if (byteoff<WHIRLPOOL_BBLOCK/8)
- memset(&c->data[byteoff],0,WHIRLPOOL_BBLOCK/8-byteoff);
- whirlpool_block(c,c->data,1);
- byteoff = 0;
- }
- if (byteoff < (WHIRLPOOL_BBLOCK/8-WHIRLPOOL_COUNTER))
- memset(&c->data[byteoff],0,
- (WHIRLPOOL_BBLOCK/8-WHIRLPOOL_COUNTER)-byteoff);
- /* smash 256-bit c->bitlen in big-endian order */
- p = &c->data[WHIRLPOOL_BBLOCK/8-1]; /* last byte in c->data */
- for(i=0;i<WHIRLPOOL_COUNTER/sizeof(size_t);i++)
- for(v=c->bitlen[i],j=0;j<sizeof(size_t);j++,v>>=8)
- *p-- = (unsigned char)(v&0xff);
+ /* pad with zeros */
+ if (byteoff > (WHIRLPOOL_BBLOCK / 8 - WHIRLPOOL_COUNTER)) {
+ if (byteoff < WHIRLPOOL_BBLOCK / 8)
+ memset(&c->data[byteoff], 0, WHIRLPOOL_BBLOCK / 8 - byteoff);
+ whirlpool_block(c, c->data, 1);
+ byteoff = 0;
+ }
+ if (byteoff < (WHIRLPOOL_BBLOCK / 8 - WHIRLPOOL_COUNTER))
+ memset(&c->data[byteoff], 0,
+ (WHIRLPOOL_BBLOCK / 8 - WHIRLPOOL_COUNTER) - byteoff);
+ /* smash 256-bit c->bitlen in big-endian order */
+ p = &c->data[WHIRLPOOL_BBLOCK / 8 - 1]; /* last byte in c->data */
+ for (i = 0; i < WHIRLPOOL_COUNTER / sizeof(size_t); i++)
+ for (v = c->bitlen[i], j = 0; j < sizeof(size_t); j++, v >>= 8)
+ *p-- = (unsigned char)(v & 0xff);
- whirlpool_block(c,c->data,1);
+ whirlpool_block(c, c->data, 1);
- if (md) {
- memcpy(md,c->H.c,WHIRLPOOL_DIGEST_LENGTH);
- memset(c,0,sizeof(*c));
- return(1);
- }
- return(0);
- }
+ if (md) {
+ memcpy(md, c->H.c, WHIRLPOOL_DIGEST_LENGTH);
+ memset(c, 0, sizeof(*c));
+ return (1);
+ }
+ return (0);
+}
-unsigned char *WHIRLPOOL(const void *inp, size_t bytes,unsigned char *md)
- {
- WHIRLPOOL_CTX ctx;
- static unsigned char m[WHIRLPOOL_DIGEST_LENGTH];
+unsigned char *WHIRLPOOL(const void *inp, size_t bytes, unsigned char *md)
+{
+ WHIRLPOOL_CTX ctx;
+ static unsigned char m[WHIRLPOOL_DIGEST_LENGTH];
- if (md == NULL) md=m;
- WHIRLPOOL_Init(&ctx);
- WHIRLPOOL_Update(&ctx,inp,bytes);
- WHIRLPOOL_Final(md,&ctx);
- return(md);
- }
+ if (md == NULL)
+ md = m;
+ WHIRLPOOL_Init(&ctx);
+ WHIRLPOOL_Update(&ctx, inp, bytes);
+ WHIRLPOOL_Final(md, &ctx);
+ return (md);
+}