mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-06-24 14:13:45 +08:00
update
This commit is contained in:
@@ -74,6 +74,8 @@ tests:
|
||||
lint:
|
||||
lint -DLINT $(INCLUDES) $(SRC)>fluff
|
||||
|
||||
update: depend
|
||||
|
||||
depend:
|
||||
@[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
|
||||
$(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
|
||||
@@ -89,5 +91,8 @@ clean:
|
||||
|
||||
wp_block.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
|
||||
wp_block.o: ../../include/openssl/whrlpool.h wp_block.c wp_locl.h
|
||||
wp_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
|
||||
wp_dgst.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
|
||||
wp_dgst.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
|
||||
wp_dgst.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
|
||||
wp_dgst.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
|
||||
wp_dgst.o: ../../include/openssl/whrlpool.h wp_dgst.c wp_locl.h
|
||||
|
||||
@@ -118,34 +118,36 @@ $tbl="ebp";
|
||||
&movq (@mm[0],&QWP(2048*$SCALE,$tbl,"esi",8)); # rc[r]
|
||||
&mov ("eax",&DWP(0,"esp"));
|
||||
&mov ("ebx",&DWP(4,"esp"));
|
||||
&movz ("ecx",&LB("eax"));
|
||||
&movz ("edx",&HB("eax"));
|
||||
for($i=0;$i<8;$i++) {
|
||||
my $func = ($i==0)? movq : pxor;
|
||||
&movb (&LB("ecx"),&LB("eax"));
|
||||
&movb (&LB("edx"),&HB("eax"));
|
||||
&scale ("esi","ecx");
|
||||
&scale ("edi","edx");
|
||||
my $func = ($i==0)? \&movq : \&pxor;
|
||||
&shr ("eax",16);
|
||||
&scale ("esi","ecx");
|
||||
&movz ("ecx",&LB("eax"));
|
||||
&scale ("edi","edx");
|
||||
&movz ("edx",&HB("eax"));
|
||||
&pxor (@mm[0],&QWP(&row(0),$tbl,"esi",8));
|
||||
&$func (@mm[1],&QWP(&row(1),$tbl,"edi",8));
|
||||
&movb (&LB("ecx"),&LB("eax"));
|
||||
&movb (&LB("edx"),&HB("eax"));
|
||||
&mov ("eax",&DWP(($i+1)*8,"esp"));
|
||||
&scale ("esi","ecx");
|
||||
&movz ("ecx",&LB("ebx"));
|
||||
&scale ("edi","edx");
|
||||
&movz ("edx",&HB("ebx"));
|
||||
&$func (@mm[2],&QWP(&row(2),$tbl,"esi",8));
|
||||
&$func (@mm[3],&QWP(&row(3),$tbl,"edi",8));
|
||||
&movb (&LB("ecx"),&LB("ebx"));
|
||||
&movb (&LB("edx"),&HB("ebx"));
|
||||
&scale ("esi","ecx");
|
||||
&scale ("edi","edx");
|
||||
&shr ("ebx",16);
|
||||
&scale ("esi","ecx");
|
||||
&movz ("ecx",&LB("ebx"));
|
||||
&scale ("edi","edx");
|
||||
&movz ("edx",&HB("ebx"));
|
||||
&$func (@mm[4],&QWP(&row(4),$tbl,"esi",8));
|
||||
&$func (@mm[5],&QWP(&row(5),$tbl,"edi",8));
|
||||
&movb (&LB("ecx"),&LB("ebx"));
|
||||
&movb (&LB("edx"),&HB("ebx"));
|
||||
&mov ("ebx",&DWP(($i+1)*8+4,"esp"));
|
||||
&scale ("esi","ecx");
|
||||
&movz ("ecx",&LB("eax"));
|
||||
&scale ("edi","edx");
|
||||
&movz ("edx",&HB("eax"));
|
||||
&$func (@mm[6],&QWP(&row(6),$tbl,"esi",8));
|
||||
&$func (@mm[7],&QWP(&row(7),$tbl,"edi",8));
|
||||
push(@mm,shift(@mm));
|
||||
@@ -154,32 +156,32 @@ for($i=0;$i<8;$i++) {
|
||||
for($i=0;$i<8;$i++) { &movq(&QWP($i*8,"esp"),@mm[$i]); } # K=L
|
||||
|
||||
for($i=0;$i<8;$i++) {
|
||||
&movb (&LB("ecx"),&LB("eax"));
|
||||
&movb (&LB("edx"),&HB("eax"));
|
||||
&scale ("esi","ecx");
|
||||
&scale ("edi","edx");
|
||||
&shr ("eax",16);
|
||||
&scale ("esi","ecx");
|
||||
&movz ("ecx",&LB("eax"));
|
||||
&scale ("edi","edx");
|
||||
&movz ("edx",&HB("eax"));
|
||||
&pxor (@mm[0],&QWP(&row(0),$tbl,"esi",8));
|
||||
&pxor (@mm[1],&QWP(&row(1),$tbl,"edi",8));
|
||||
&movb (&LB("ecx"),&LB("eax"));
|
||||
&movb (&LB("edx"),&HB("eax"));
|
||||
&mov ("eax",&DWP(64+($i+1)*8,"esp")) if ($i<7);
|
||||
&scale ("esi","ecx");
|
||||
&movz ("ecx",&LB("ebx"));
|
||||
&scale ("edi","edx");
|
||||
&movz ("edx",&HB("ebx"));
|
||||
&pxor (@mm[2],&QWP(&row(2),$tbl,"esi",8));
|
||||
&pxor (@mm[3],&QWP(&row(3),$tbl,"edi",8));
|
||||
&movb (&LB("ecx"),&LB("ebx"));
|
||||
&movb (&LB("edx"),&HB("ebx"));
|
||||
&scale ("esi","ecx");
|
||||
&scale ("edi","edx");
|
||||
&shr ("ebx",16);
|
||||
&scale ("esi","ecx");
|
||||
&movz ("ecx",&LB("ebx"));
|
||||
&scale ("edi","edx");
|
||||
&movz ("edx",&HB("ebx"));
|
||||
&pxor (@mm[4],&QWP(&row(4),$tbl,"esi",8));
|
||||
&pxor (@mm[5],&QWP(&row(5),$tbl,"edi",8));
|
||||
&movb (&LB("ecx"),&LB("ebx"));
|
||||
&movb (&LB("edx"),&HB("ebx"));
|
||||
&mov ("ebx",&DWP(64+($i+1)*8+4,"esp")) if ($i<7);
|
||||
&scale ("esi","ecx");
|
||||
&movz ("ecx",&LB("eax"));
|
||||
&scale ("edi","edx");
|
||||
&movz ("edx",&HB("eax"));
|
||||
&pxor (@mm[6],&QWP(&row(6),$tbl,"esi",8));
|
||||
&pxor (@mm[7],&QWP(&row(7),$tbl,"edi",8));
|
||||
push(@mm,shift(@mm));
|
||||
|
||||
@@ -41,7 +41,8 @@ $0 =~ m/(.*[\/\\])[^\/\\]+$/; my $dir=$1; my $xlate;
|
||||
( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
|
||||
die "can't locate x86_64-xlate.pl";
|
||||
|
||||
open STDOUT,"| $^X $xlate $flavour $output";
|
||||
open OUT,"| \"$^X\" $xlate $flavour $output";
|
||||
*STDOUT=*OUT;
|
||||
|
||||
sub L() { $code.=".byte ".join(',',@_)."\n"; }
|
||||
sub LL(){ $code.=".byte ".join(',',@_).",".join(',',@_)."\n"; }
|
||||
@@ -90,41 +91,44 @@ for($i=0;$i<8;$i++) { $code.="mov @mm[$i],64+$i*8(%rsp)\n"; } # S=L
|
||||
$code.=<<___;
|
||||
xor %rsi,%rsi
|
||||
mov %rsi,24(%rbx) # zero round counter
|
||||
jmp .Lround
|
||||
.align 16
|
||||
.Lround:
|
||||
mov 4096(%rbp,%rsi,8),@mm[0] # rc[r]
|
||||
mov 0(%rsp),%eax
|
||||
mov 4(%rsp),%ebx
|
||||
movz %al,%ecx
|
||||
movz %ah,%edx
|
||||
___
|
||||
for($i=0;$i<8;$i++) {
|
||||
my $func = ($i==0)? "mov" : "xor";
|
||||
$code.=<<___;
|
||||
mov %al,%cl
|
||||
mov %ah,%dl
|
||||
lea (%rcx,%rcx),%rsi
|
||||
lea (%rdx,%rdx),%rdi
|
||||
shr \$16,%eax
|
||||
lea (%rcx,%rcx),%rsi
|
||||
movz %al,%ecx
|
||||
lea (%rdx,%rdx),%rdi
|
||||
movz %ah,%edx
|
||||
xor 0(%rbp,%rsi,8),@mm[0]
|
||||
$func 7(%rbp,%rdi,8),@mm[1]
|
||||
mov %al,%cl
|
||||
mov %ah,%dl
|
||||
mov $i*8+8(%rsp),%eax # ($i+1)*8
|
||||
lea (%rcx,%rcx),%rsi
|
||||
movz %bl,%ecx
|
||||
lea (%rdx,%rdx),%rdi
|
||||
movz %bh,%edx
|
||||
$func 6(%rbp,%rsi,8),@mm[2]
|
||||
$func 5(%rbp,%rdi,8),@mm[3]
|
||||
mov %bl,%cl
|
||||
mov %bh,%dl
|
||||
lea (%rcx,%rcx),%rsi
|
||||
lea (%rdx,%rdx),%rdi
|
||||
shr \$16,%ebx
|
||||
lea (%rcx,%rcx),%rsi
|
||||
movz %bl,%ecx
|
||||
lea (%rdx,%rdx),%rdi
|
||||
movz %bh,%edx
|
||||
$func 4(%rbp,%rsi,8),@mm[4]
|
||||
$func 3(%rbp,%rdi,8),@mm[5]
|
||||
mov %bl,%cl
|
||||
mov %bh,%dl
|
||||
mov $i*8+8+4(%rsp),%ebx # ($i+1)*8+4
|
||||
lea (%rcx,%rcx),%rsi
|
||||
movz %al,%ecx
|
||||
lea (%rdx,%rdx),%rdi
|
||||
movz %ah,%edx
|
||||
$func 2(%rbp,%rsi,8),@mm[6]
|
||||
$func 1(%rbp,%rdi,8),@mm[7]
|
||||
___
|
||||
@@ -133,32 +137,32 @@ ___
|
||||
for($i=0;$i<8;$i++) { $code.="mov @mm[$i],$i*8(%rsp)\n"; } # K=L
|
||||
for($i=0;$i<8;$i++) {
|
||||
$code.=<<___;
|
||||
mov %al,%cl
|
||||
mov %ah,%dl
|
||||
lea (%rcx,%rcx),%rsi
|
||||
lea (%rdx,%rdx),%rdi
|
||||
shr \$16,%eax
|
||||
lea (%rcx,%rcx),%rsi
|
||||
movz %al,%ecx
|
||||
lea (%rdx,%rdx),%rdi
|
||||
movz %ah,%edx
|
||||
xor 0(%rbp,%rsi,8),@mm[0]
|
||||
xor 7(%rbp,%rdi,8),@mm[1]
|
||||
mov %al,%cl
|
||||
mov %ah,%dl
|
||||
`"mov 64+$i*8+8(%rsp),%eax" if($i<7);` # 64+($i+1)*8
|
||||
lea (%rcx,%rcx),%rsi
|
||||
movz %bl,%ecx
|
||||
lea (%rdx,%rdx),%rdi
|
||||
movz %bh,%edx
|
||||
xor 6(%rbp,%rsi,8),@mm[2]
|
||||
xor 5(%rbp,%rdi,8),@mm[3]
|
||||
mov %bl,%cl
|
||||
mov %bh,%dl
|
||||
lea (%rcx,%rcx),%rsi
|
||||
lea (%rdx,%rdx),%rdi
|
||||
shr \$16,%ebx
|
||||
lea (%rcx,%rcx),%rsi
|
||||
movz %bl,%ecx
|
||||
lea (%rdx,%rdx),%rdi
|
||||
movz %bh,%edx
|
||||
xor 4(%rbp,%rsi,8),@mm[4]
|
||||
xor 3(%rbp,%rdi,8),@mm[5]
|
||||
mov %bl,%cl
|
||||
mov %bh,%dl
|
||||
`"mov 64+$i*8+8+4(%rsp),%ebx" if($i<7);` # 64+($i+1)*8+4
|
||||
lea (%rcx,%rcx),%rsi
|
||||
movz %al,%ecx
|
||||
lea (%rdx,%rdx),%rdi
|
||||
movz %ah,%edx
|
||||
xor 2(%rbp,%rsi,8),@mm[6]
|
||||
xor 1(%rbp,%rdi,8),@mm[7]
|
||||
___
|
||||
|
||||
@@ -1,35 +1,38 @@
|
||||
#ifndef HEADER_WHRLPOOL_H
|
||||
#define HEADER_WHRLPOOL_H
|
||||
# define HEADER_WHRLPOOL_H
|
||||
|
||||
#include <openssl/e_os2.h>
|
||||
#include <stddef.h>
|
||||
# include <openssl/e_os2.h>
|
||||
# include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define WHIRLPOOL_DIGEST_LENGTH (512/8)
|
||||
#define WHIRLPOOL_BBLOCK 512
|
||||
#define WHIRLPOOL_COUNTER (256/8)
|
||||
# define WHIRLPOOL_DIGEST_LENGTH (512/8)
|
||||
# define WHIRLPOOL_BBLOCK 512
|
||||
# define WHIRLPOOL_COUNTER (256/8)
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
unsigned char c[WHIRLPOOL_DIGEST_LENGTH];
|
||||
/* double q is here to ensure 64-bit alignment */
|
||||
double q[WHIRLPOOL_DIGEST_LENGTH/sizeof(double)];
|
||||
} H;
|
||||
unsigned char data[WHIRLPOOL_BBLOCK/8];
|
||||
unsigned int bitoff;
|
||||
size_t bitlen[WHIRLPOOL_COUNTER/sizeof(size_t)];
|
||||
} WHIRLPOOL_CTX;
|
||||
typedef struct {
|
||||
union {
|
||||
unsigned char c[WHIRLPOOL_DIGEST_LENGTH];
|
||||
/* double q is here to ensure 64-bit alignment */
|
||||
double q[WHIRLPOOL_DIGEST_LENGTH / sizeof(double)];
|
||||
} H;
|
||||
unsigned char data[WHIRLPOOL_BBLOCK / 8];
|
||||
unsigned int bitoff;
|
||||
size_t bitlen[WHIRLPOOL_COUNTER / sizeof(size_t)];
|
||||
} WHIRLPOOL_CTX;
|
||||
|
||||
#ifndef OPENSSL_NO_WHIRLPOOL
|
||||
int WHIRLPOOL_Init (WHIRLPOOL_CTX *c);
|
||||
int WHIRLPOOL_Update (WHIRLPOOL_CTX *c,const void *inp,size_t bytes);
|
||||
void WHIRLPOOL_BitUpdate(WHIRLPOOL_CTX *c,const void *inp,size_t bits);
|
||||
int WHIRLPOOL_Final (unsigned char *md,WHIRLPOOL_CTX *c);
|
||||
unsigned char *WHIRLPOOL(const void *inp,size_t bytes,unsigned char *md);
|
||||
#endif
|
||||
# ifndef OPENSSL_NO_WHIRLPOOL
|
||||
# ifdef OPENSSL_FIPS
|
||||
int private_WHIRLPOOL_Init(WHIRLPOOL_CTX *c);
|
||||
# endif
|
||||
int WHIRLPOOL_Init(WHIRLPOOL_CTX *c);
|
||||
int WHIRLPOOL_Update(WHIRLPOOL_CTX *c, const void *inp, size_t bytes);
|
||||
void WHIRLPOOL_BitUpdate(WHIRLPOOL_CTX *c, const void *inp, size_t bits);
|
||||
int WHIRLPOOL_Final(unsigned char *md, WHIRLPOOL_CTX *c);
|
||||
unsigned char *WHIRLPOOL(const void *inp, size_t bytes, unsigned char *md);
|
||||
# endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -52,213 +52,206 @@
|
||||
*/
|
||||
|
||||
#include "wp_locl.h"
|
||||
#include <openssl/crypto.h>
|
||||
#include <string.h>
|
||||
|
||||
int WHIRLPOOL_Init (WHIRLPOOL_CTX *c)
|
||||
{
|
||||
memset (c,0,sizeof(*c));
|
||||
return(1);
|
||||
}
|
||||
fips_md_init(WHIRLPOOL)
|
||||
{
|
||||
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;
|
||||
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)));
|
||||
}
|
||||
/*
|
||||
* 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;
|
||||
|
||||
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;
|
||||
|
||||
#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;
|
||||
|
||||
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 */
|
||||
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
|
||||
{
|
||||
/*
|
||||
inp
|
||||
|
|
||||
+-------+-------+-------
|
||||
|||||||||||||||||||||
|
||||
+-------+-------+-------
|
||||
+-------+-------+-------+-------+-------
|
||||
|||||||||||||| c->data
|
||||
+-------+-------+-------+-------+-------
|
||||
|
|
||||
c->bitoff/8
|
||||
*/
|
||||
while (bits)
|
||||
{
|
||||
unsigned int byteoff = bitoff/8;
|
||||
unsigned char b;
|
||||
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 */
|
||||
|
||||
#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
|
||||
#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;
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -1,3 +1,3 @@
|
||||
#include <openssl/whrlpool.h>
|
||||
|
||||
void whirlpool_block(WHIRLPOOL_CTX *,const void *,size_t);
|
||||
void whirlpool_block(WHIRLPOOL_CTX *, const void *, size_t);
|
||||
|
||||
@@ -13,216 +13,229 @@
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No Whirlpool support\n");
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
|
||||
/* ISO/IEC 10118-3 test vector set */
|
||||
unsigned char iso_test_1[WHIRLPOOL_DIGEST_LENGTH] = {
|
||||
0x19,0xFA,0x61,0xD7,0x55,0x22,0xA4,0x66,
|
||||
0x9B,0x44,0xE3,0x9C,0x1D,0x2E,0x17,0x26,
|
||||
0xC5,0x30,0x23,0x21,0x30,0xD4,0x07,0xF8,
|
||||
0x9A,0xFE,0xE0,0x96,0x49,0x97,0xF7,0xA7,
|
||||
0x3E,0x83,0xBE,0x69,0x8B,0x28,0x8F,0xEB,
|
||||
0xCF,0x88,0xE3,0xE0,0x3C,0x4F,0x07,0x57,
|
||||
0xEA,0x89,0x64,0xE5,0x9B,0x63,0xD9,0x37,
|
||||
0x08,0xB1,0x38,0xCC,0x42,0xA6,0x6E,0xB3 };
|
||||
0x19, 0xFA, 0x61, 0xD7, 0x55, 0x22, 0xA4, 0x66,
|
||||
0x9B, 0x44, 0xE3, 0x9C, 0x1D, 0x2E, 0x17, 0x26,
|
||||
0xC5, 0x30, 0x23, 0x21, 0x30, 0xD4, 0x07, 0xF8,
|
||||
0x9A, 0xFE, 0xE0, 0x96, 0x49, 0x97, 0xF7, 0xA7,
|
||||
0x3E, 0x83, 0xBE, 0x69, 0x8B, 0x28, 0x8F, 0xEB,
|
||||
0xCF, 0x88, 0xE3, 0xE0, 0x3C, 0x4F, 0x07, 0x57,
|
||||
0xEA, 0x89, 0x64, 0xE5, 0x9B, 0x63, 0xD9, 0x37,
|
||||
0x08, 0xB1, 0x38, 0xCC, 0x42, 0xA6, 0x6E, 0xB3
|
||||
};
|
||||
|
||||
unsigned char iso_test_2[WHIRLPOOL_DIGEST_LENGTH] = {
|
||||
0x8A,0xCA,0x26,0x02,0x79,0x2A,0xEC,0x6F,
|
||||
0x11,0xA6,0x72,0x06,0x53,0x1F,0xB7,0xD7,
|
||||
0xF0,0xDF,0xF5,0x94,0x13,0x14,0x5E,0x69,
|
||||
0x73,0xC4,0x50,0x01,0xD0,0x08,0x7B,0x42,
|
||||
0xD1,0x1B,0xC6,0x45,0x41,0x3A,0xEF,0xF6,
|
||||
0x3A,0x42,0x39,0x1A,0x39,0x14,0x5A,0x59,
|
||||
0x1A,0x92,0x20,0x0D,0x56,0x01,0x95,0xE5,
|
||||
0x3B,0x47,0x85,0x84,0xFD,0xAE,0x23,0x1A };
|
||||
0x8A, 0xCA, 0x26, 0x02, 0x79, 0x2A, 0xEC, 0x6F,
|
||||
0x11, 0xA6, 0x72, 0x06, 0x53, 0x1F, 0xB7, 0xD7,
|
||||
0xF0, 0xDF, 0xF5, 0x94, 0x13, 0x14, 0x5E, 0x69,
|
||||
0x73, 0xC4, 0x50, 0x01, 0xD0, 0x08, 0x7B, 0x42,
|
||||
0xD1, 0x1B, 0xC6, 0x45, 0x41, 0x3A, 0xEF, 0xF6,
|
||||
0x3A, 0x42, 0x39, 0x1A, 0x39, 0x14, 0x5A, 0x59,
|
||||
0x1A, 0x92, 0x20, 0x0D, 0x56, 0x01, 0x95, 0xE5,
|
||||
0x3B, 0x47, 0x85, 0x84, 0xFD, 0xAE, 0x23, 0x1A
|
||||
};
|
||||
|
||||
unsigned char iso_test_3[WHIRLPOOL_DIGEST_LENGTH] = {
|
||||
0x4E,0x24,0x48,0xA4,0xC6,0xF4,0x86,0xBB,
|
||||
0x16,0xB6,0x56,0x2C,0x73,0xB4,0x02,0x0B,
|
||||
0xF3,0x04,0x3E,0x3A,0x73,0x1B,0xCE,0x72,
|
||||
0x1A,0xE1,0xB3,0x03,0xD9,0x7E,0x6D,0x4C,
|
||||
0x71,0x81,0xEE,0xBD,0xB6,0xC5,0x7E,0x27,
|
||||
0x7D,0x0E,0x34,0x95,0x71,0x14,0xCB,0xD6,
|
||||
0xC7,0x97,0xFC,0x9D,0x95,0xD8,0xB5,0x82,
|
||||
0xD2,0x25,0x29,0x20,0x76,0xD4,0xEE,0xF5 };
|
||||
0x4E, 0x24, 0x48, 0xA4, 0xC6, 0xF4, 0x86, 0xBB,
|
||||
0x16, 0xB6, 0x56, 0x2C, 0x73, 0xB4, 0x02, 0x0B,
|
||||
0xF3, 0x04, 0x3E, 0x3A, 0x73, 0x1B, 0xCE, 0x72,
|
||||
0x1A, 0xE1, 0xB3, 0x03, 0xD9, 0x7E, 0x6D, 0x4C,
|
||||
0x71, 0x81, 0xEE, 0xBD, 0xB6, 0xC5, 0x7E, 0x27,
|
||||
0x7D, 0x0E, 0x34, 0x95, 0x71, 0x14, 0xCB, 0xD6,
|
||||
0xC7, 0x97, 0xFC, 0x9D, 0x95, 0xD8, 0xB5, 0x82,
|
||||
0xD2, 0x25, 0x29, 0x20, 0x76, 0xD4, 0xEE, 0xF5
|
||||
};
|
||||
|
||||
unsigned char iso_test_4[WHIRLPOOL_DIGEST_LENGTH] = {
|
||||
0x37,0x8C,0x84,0xA4,0x12,0x6E,0x2D,0xC6,
|
||||
0xE5,0x6D,0xCC,0x74,0x58,0x37,0x7A,0xAC,
|
||||
0x83,0x8D,0x00,0x03,0x22,0x30,0xF5,0x3C,
|
||||
0xE1,0xF5,0x70,0x0C,0x0F,0xFB,0x4D,0x3B,
|
||||
0x84,0x21,0x55,0x76,0x59,0xEF,0x55,0xC1,
|
||||
0x06,0xB4,0xB5,0x2A,0xC5,0xA4,0xAA,0xA6,
|
||||
0x92,0xED,0x92,0x00,0x52,0x83,0x8F,0x33,
|
||||
0x62,0xE8,0x6D,0xBD,0x37,0xA8,0x90,0x3E };
|
||||
0x37, 0x8C, 0x84, 0xA4, 0x12, 0x6E, 0x2D, 0xC6,
|
||||
0xE5, 0x6D, 0xCC, 0x74, 0x58, 0x37, 0x7A, 0xAC,
|
||||
0x83, 0x8D, 0x00, 0x03, 0x22, 0x30, 0xF5, 0x3C,
|
||||
0xE1, 0xF5, 0x70, 0x0C, 0x0F, 0xFB, 0x4D, 0x3B,
|
||||
0x84, 0x21, 0x55, 0x76, 0x59, 0xEF, 0x55, 0xC1,
|
||||
0x06, 0xB4, 0xB5, 0x2A, 0xC5, 0xA4, 0xAA, 0xA6,
|
||||
0x92, 0xED, 0x92, 0x00, 0x52, 0x83, 0x8F, 0x33,
|
||||
0x62, 0xE8, 0x6D, 0xBD, 0x37, 0xA8, 0x90, 0x3E
|
||||
};
|
||||
|
||||
unsigned char iso_test_5[WHIRLPOOL_DIGEST_LENGTH] = {
|
||||
0xF1,0xD7,0x54,0x66,0x26,0x36,0xFF,0xE9,
|
||||
0x2C,0x82,0xEB,0xB9,0x21,0x2A,0x48,0x4A,
|
||||
0x8D,0x38,0x63,0x1E,0xAD,0x42,0x38,0xF5,
|
||||
0x44,0x2E,0xE1,0x3B,0x80,0x54,0xE4,0x1B,
|
||||
0x08,0xBF,0x2A,0x92,0x51,0xC3,0x0B,0x6A,
|
||||
0x0B,0x8A,0xAE,0x86,0x17,0x7A,0xB4,0xA6,
|
||||
0xF6,0x8F,0x67,0x3E,0x72,0x07,0x86,0x5D,
|
||||
0x5D,0x98,0x19,0xA3,0xDB,0xA4,0xEB,0x3B };
|
||||
0xF1, 0xD7, 0x54, 0x66, 0x26, 0x36, 0xFF, 0xE9,
|
||||
0x2C, 0x82, 0xEB, 0xB9, 0x21, 0x2A, 0x48, 0x4A,
|
||||
0x8D, 0x38, 0x63, 0x1E, 0xAD, 0x42, 0x38, 0xF5,
|
||||
0x44, 0x2E, 0xE1, 0x3B, 0x80, 0x54, 0xE4, 0x1B,
|
||||
0x08, 0xBF, 0x2A, 0x92, 0x51, 0xC3, 0x0B, 0x6A,
|
||||
0x0B, 0x8A, 0xAE, 0x86, 0x17, 0x7A, 0xB4, 0xA6,
|
||||
0xF6, 0x8F, 0x67, 0x3E, 0x72, 0x07, 0x86, 0x5D,
|
||||
0x5D, 0x98, 0x19, 0xA3, 0xDB, 0xA4, 0xEB, 0x3B
|
||||
};
|
||||
|
||||
unsigned char iso_test_6[WHIRLPOOL_DIGEST_LENGTH] = {
|
||||
0xDC,0x37,0xE0,0x08,0xCF,0x9E,0xE6,0x9B,
|
||||
0xF1,0x1F,0x00,0xED,0x9A,0xBA,0x26,0x90,
|
||||
0x1D,0xD7,0xC2,0x8C,0xDE,0xC0,0x66,0xCC,
|
||||
0x6A,0xF4,0x2E,0x40,0xF8,0x2F,0x3A,0x1E,
|
||||
0x08,0xEB,0xA2,0x66,0x29,0x12,0x9D,0x8F,
|
||||
0xB7,0xCB,0x57,0x21,0x1B,0x92,0x81,0xA6,
|
||||
0x55,0x17,0xCC,0x87,0x9D,0x7B,0x96,0x21,
|
||||
0x42,0xC6,0x5F,0x5A,0x7A,0xF0,0x14,0x67 };
|
||||
0xDC, 0x37, 0xE0, 0x08, 0xCF, 0x9E, 0xE6, 0x9B,
|
||||
0xF1, 0x1F, 0x00, 0xED, 0x9A, 0xBA, 0x26, 0x90,
|
||||
0x1D, 0xD7, 0xC2, 0x8C, 0xDE, 0xC0, 0x66, 0xCC,
|
||||
0x6A, 0xF4, 0x2E, 0x40, 0xF8, 0x2F, 0x3A, 0x1E,
|
||||
0x08, 0xEB, 0xA2, 0x66, 0x29, 0x12, 0x9D, 0x8F,
|
||||
0xB7, 0xCB, 0x57, 0x21, 0x1B, 0x92, 0x81, 0xA6,
|
||||
0x55, 0x17, 0xCC, 0x87, 0x9D, 0x7B, 0x96, 0x21,
|
||||
0x42, 0xC6, 0x5F, 0x5A, 0x7A, 0xF0, 0x14, 0x67
|
||||
};
|
||||
|
||||
unsigned char iso_test_7[WHIRLPOOL_DIGEST_LENGTH] = {
|
||||
0x46,0x6E,0xF1,0x8B,0xAB,0xB0,0x15,0x4D,
|
||||
0x25,0xB9,0xD3,0x8A,0x64,0x14,0xF5,0xC0,
|
||||
0x87,0x84,0x37,0x2B,0xCC,0xB2,0x04,0xD6,
|
||||
0x54,0x9C,0x4A,0xFA,0xDB,0x60,0x14,0x29,
|
||||
0x4D,0x5B,0xD8,0xDF,0x2A,0x6C,0x44,0xE5,
|
||||
0x38,0xCD,0x04,0x7B,0x26,0x81,0xA5,0x1A,
|
||||
0x2C,0x60,0x48,0x1E,0x88,0xC5,0xA2,0x0B,
|
||||
0x2C,0x2A,0x80,0xCF,0x3A,0x9A,0x08,0x3B };
|
||||
0x46, 0x6E, 0xF1, 0x8B, 0xAB, 0xB0, 0x15, 0x4D,
|
||||
0x25, 0xB9, 0xD3, 0x8A, 0x64, 0x14, 0xF5, 0xC0,
|
||||
0x87, 0x84, 0x37, 0x2B, 0xCC, 0xB2, 0x04, 0xD6,
|
||||
0x54, 0x9C, 0x4A, 0xFA, 0xDB, 0x60, 0x14, 0x29,
|
||||
0x4D, 0x5B, 0xD8, 0xDF, 0x2A, 0x6C, 0x44, 0xE5,
|
||||
0x38, 0xCD, 0x04, 0x7B, 0x26, 0x81, 0xA5, 0x1A,
|
||||
0x2C, 0x60, 0x48, 0x1E, 0x88, 0xC5, 0xA2, 0x0B,
|
||||
0x2C, 0x2A, 0x80, 0xCF, 0x3A, 0x9A, 0x08, 0x3B
|
||||
};
|
||||
|
||||
unsigned char iso_test_8[WHIRLPOOL_DIGEST_LENGTH] = {
|
||||
0x2A,0x98,0x7E,0xA4,0x0F,0x91,0x70,0x61,
|
||||
0xF5,0xD6,0xF0,0xA0,0xE4,0x64,0x4F,0x48,
|
||||
0x8A,0x7A,0x5A,0x52,0xDE,0xEE,0x65,0x62,
|
||||
0x07,0xC5,0x62,0xF9,0x88,0xE9,0x5C,0x69,
|
||||
0x16,0xBD,0xC8,0x03,0x1B,0xC5,0xBE,0x1B,
|
||||
0x7B,0x94,0x76,0x39,0xFE,0x05,0x0B,0x56,
|
||||
0x93,0x9B,0xAA,0xA0,0xAD,0xFF,0x9A,0xE6,
|
||||
0x74,0x5B,0x7B,0x18,0x1C,0x3B,0xE3,0xFD };
|
||||
0x2A, 0x98, 0x7E, 0xA4, 0x0F, 0x91, 0x70, 0x61,
|
||||
0xF5, 0xD6, 0xF0, 0xA0, 0xE4, 0x64, 0x4F, 0x48,
|
||||
0x8A, 0x7A, 0x5A, 0x52, 0xDE, 0xEE, 0x65, 0x62,
|
||||
0x07, 0xC5, 0x62, 0xF9, 0x88, 0xE9, 0x5C, 0x69,
|
||||
0x16, 0xBD, 0xC8, 0x03, 0x1B, 0xC5, 0xBE, 0x1B,
|
||||
0x7B, 0x94, 0x76, 0x39, 0xFE, 0x05, 0x0B, 0x56,
|
||||
0x93, 0x9B, 0xAA, 0xA0, 0xAD, 0xFF, 0x9A, 0xE6,
|
||||
0x74, 0x5B, 0x7B, 0x18, 0x1C, 0x3B, 0xE3, 0xFD
|
||||
};
|
||||
|
||||
unsigned char iso_test_9[WHIRLPOOL_DIGEST_LENGTH] = {
|
||||
0x0C,0x99,0x00,0x5B,0xEB,0x57,0xEF,0xF5,
|
||||
0x0A,0x7C,0xF0,0x05,0x56,0x0D,0xDF,0x5D,
|
||||
0x29,0x05,0x7F,0xD8,0x6B,0x20,0xBF,0xD6,
|
||||
0x2D,0xEC,0xA0,0xF1,0xCC,0xEA,0x4A,0xF5,
|
||||
0x1F,0xC1,0x54,0x90,0xED,0xDC,0x47,0xAF,
|
||||
0x32,0xBB,0x2B,0x66,0xC3,0x4F,0xF9,0xAD,
|
||||
0x8C,0x60,0x08,0xAD,0x67,0x7F,0x77,0x12,
|
||||
0x69,0x53,0xB2,0x26,0xE4,0xED,0x8B,0x01 };
|
||||
0x0C, 0x99, 0x00, 0x5B, 0xEB, 0x57, 0xEF, 0xF5,
|
||||
0x0A, 0x7C, 0xF0, 0x05, 0x56, 0x0D, 0xDF, 0x5D,
|
||||
0x29, 0x05, 0x7F, 0xD8, 0x6B, 0x20, 0xBF, 0xD6,
|
||||
0x2D, 0xEC, 0xA0, 0xF1, 0xCC, 0xEA, 0x4A, 0xF5,
|
||||
0x1F, 0xC1, 0x54, 0x90, 0xED, 0xDC, 0x47, 0xAF,
|
||||
0x32, 0xBB, 0x2B, 0x66, 0xC3, 0x4F, 0xF9, 0xAD,
|
||||
0x8C, 0x60, 0x08, 0xAD, 0x67, 0x7F, 0x77, 0x12,
|
||||
0x69, 0x53, 0xB2, 0x26, 0xE4, 0xED, 0x8B, 0x01
|
||||
};
|
||||
|
||||
int main (int argc,char *argv[])
|
||||
{ unsigned char md[WHIRLPOOL_DIGEST_LENGTH];
|
||||
int i;
|
||||
WHIRLPOOL_CTX ctx;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
unsigned char md[WHIRLPOOL_DIGEST_LENGTH];
|
||||
int i;
|
||||
WHIRLPOOL_CTX ctx;
|
||||
|
||||
#ifdef OPENSSL_IA32_SSE2
|
||||
/* Alternative to this is to call OpenSSL_add_all_algorithms...
|
||||
* The below code is retained exclusively for debugging purposes. */
|
||||
{ char *env;
|
||||
# ifdef OPENSSL_IA32_SSE2
|
||||
/*
|
||||
* Alternative to this is to call OpenSSL_add_all_algorithms... The below
|
||||
* code is retained exclusively for debugging purposes.
|
||||
*/
|
||||
{
|
||||
char *env;
|
||||
|
||||
if ((env=getenv("OPENSSL_ia32cap")))
|
||||
OPENSSL_ia32cap = strtoul (env,NULL,0);
|
||||
if ((env = getenv("OPENSSL_ia32cap")))
|
||||
OPENSSL_ia32cap = strtoul(env, NULL, 0);
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
|
||||
fprintf(stdout,"Testing Whirlpool ");
|
||||
fprintf(stdout, "Testing Whirlpool ");
|
||||
|
||||
WHIRLPOOL("",0,md);
|
||||
if (memcmp(md,iso_test_1,sizeof(iso_test_1)))
|
||||
{ fflush(stdout);
|
||||
fprintf(stderr,"\nTEST 1 of 9 failed.\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
fprintf(stdout,"."); fflush(stdout);
|
||||
WHIRLPOOL("", 0, md);
|
||||
if (memcmp(md, iso_test_1, sizeof(iso_test_1))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 1 of 9 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
WHIRLPOOL("a",1,md);
|
||||
if (memcmp(md,iso_test_2,sizeof(iso_test_2)))
|
||||
{ fflush(stdout);
|
||||
fprintf(stderr,"\nTEST 2 of 9 failed.\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
fprintf(stdout,"."); fflush(stdout);
|
||||
WHIRLPOOL("a", 1, md);
|
||||
if (memcmp(md, iso_test_2, sizeof(iso_test_2))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 2 of 9 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
WHIRLPOOL("abc",3,md);
|
||||
if (memcmp(md,iso_test_3,sizeof(iso_test_3)))
|
||||
{ fflush(stdout);
|
||||
fprintf(stderr,"\nTEST 3 of 9 failed.\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
fprintf(stdout,"."); fflush(stdout);
|
||||
WHIRLPOOL("abc", 3, md);
|
||||
if (memcmp(md, iso_test_3, sizeof(iso_test_3))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 3 of 9 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
WHIRLPOOL("message digest",14,md);
|
||||
if (memcmp(md,iso_test_4,sizeof(iso_test_4)))
|
||||
{ fflush(stdout);
|
||||
fprintf(stderr,"\nTEST 4 of 9 failed.\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
fprintf(stdout,"."); fflush(stdout);
|
||||
WHIRLPOOL("message digest", 14, md);
|
||||
if (memcmp(md, iso_test_4, sizeof(iso_test_4))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 4 of 9 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
WHIRLPOOL("abcdefghijklmnopqrstuvwxyz",26,md);
|
||||
if (memcmp(md,iso_test_5,sizeof(iso_test_5)))
|
||||
{ fflush(stdout);
|
||||
fprintf(stderr,"\nTEST 5 of 9 failed.\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
fprintf(stdout,"."); fflush(stdout);
|
||||
WHIRLPOOL("abcdefghijklmnopqrstuvwxyz", 26, md);
|
||||
if (memcmp(md, iso_test_5, sizeof(iso_test_5))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 5 of 9 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
WHIRLPOOL( "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789",62,md);
|
||||
if (memcmp(md,iso_test_6,sizeof(iso_test_6)))
|
||||
{ fflush(stdout);
|
||||
fprintf(stderr,"\nTEST 6 of 9 failed.\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
fprintf(stdout,"."); fflush(stdout);
|
||||
WHIRLPOOL("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz" "0123456789", 62, md);
|
||||
if (memcmp(md, iso_test_6, sizeof(iso_test_6))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 6 of 9 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
WHIRLPOOL( "1234567890""1234567890""1234567890""1234567890"
|
||||
"1234567890""1234567890""1234567890""1234567890",80,md);
|
||||
if (memcmp(md,iso_test_7,sizeof(iso_test_7)))
|
||||
{ fflush(stdout);
|
||||
fprintf(stderr,"\nTEST 7 of 9 failed.\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
fprintf(stdout,"."); fflush(stdout);
|
||||
WHIRLPOOL("1234567890" "1234567890" "1234567890" "1234567890"
|
||||
"1234567890" "1234567890" "1234567890" "1234567890", 80, md);
|
||||
if (memcmp(md, iso_test_7, sizeof(iso_test_7))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 7 of 9 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
WHIRLPOOL("abcdbcdecdefdefgefghfghighijhijk",32,md);
|
||||
if (memcmp(md,iso_test_8,sizeof(iso_test_8)))
|
||||
{ fflush(stdout);
|
||||
fprintf(stderr,"\nTEST 8 of 9 failed.\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
fprintf(stdout,"."); fflush(stdout);
|
||||
|
||||
WHIRLPOOL_Init (&ctx);
|
||||
for (i=0;i<1000000;i+=288)
|
||||
WHIRLPOOL_Update (&ctx, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
|
||||
"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
|
||||
"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
|
||||
"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
|
||||
"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
|
||||
"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
|
||||
"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
|
||||
"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
|
||||
"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa",
|
||||
(1000000-i)<288?1000000-i:288);
|
||||
WHIRLPOOL_Final (md,&ctx);
|
||||
if (memcmp(md,iso_test_9,sizeof(iso_test_9)))
|
||||
{ fflush(stdout);
|
||||
fprintf(stderr,"\nTEST 9 of 9 failed.\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
fprintf(stdout,"."); fflush(stdout);
|
||||
WHIRLPOOL("abcdbcdecdefdefgefghfghighijhijk", 32, md);
|
||||
if (memcmp(md, iso_test_8, sizeof(iso_test_8))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 8 of 9 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
fprintf(stdout," passed.\n"); fflush(stdout);
|
||||
WHIRLPOOL_Init(&ctx);
|
||||
for (i = 0; i < 1000000; i += 288)
|
||||
WHIRLPOOL_Update(&ctx, "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa",
|
||||
(1000000 - i) < 288 ? 1000000 - i : 288);
|
||||
WHIRLPOOL_Final(md, &ctx);
|
||||
if (memcmp(md, iso_test_9, sizeof(iso_test_9))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 9 of 9 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
return 0;
|
||||
fprintf(stdout, " passed.\n");
|
||||
fflush(stdout);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user