From caee135c54ea54149775d61dc49d4bcf58ff2268 Mon Sep 17 00:00:00 2001 From: jbj Date: Fri, 16 May 2003 17:19:42 +0000 Subject: Merge to latest beecrypt-3.0.0. CVS patchset: 6847 CVS date: 2003/05/16 17:19:42 --- beecrypt/acinclude.m4 | 36 ++-- beecrypt/aes.h | 2 +- beecrypt/beecrypt.api.h | 22 +-- beecrypt/beecrypt.c | 36 ++-- beecrypt/configure.ac | 9 +- beecrypt/dldp.c | 11 -- beecrypt/endianness.c | 422 +------------------------------------------ beecrypt/endianness.h | 251 ++----------------------- beecrypt/fips186.c | 29 ++- beecrypt/fips186.h | 2 +- beecrypt/gas/mpopt.ia64.m4 | 95 +++++++--- beecrypt/gas/mpopt.x86.m4 | 6 +- beecrypt/gas/mpopt.x86_64.m4 | 108 +++++++++++ beecrypt/gas/sha1opt.x86.m4 | 11 +- beecrypt/gas/x86_64.m4 | 20 ++ beecrypt/hmacmd5.h | 2 +- beecrypt/hmacsha1.h | 2 +- beecrypt/installgen.sh | 6 - beecrypt/md5.c | 34 ++-- beecrypt/md5.h | 20 +- beecrypt/mpbarrett.c | 4 - beecrypt/mpopt.h | 13 +- beecrypt/mpprime.h | 1 + beecrypt/rsa.c | 2 +- beecrypt/rsakp.c | 4 - beecrypt/sha1.h | 2 +- beecrypt/system.h | 11 ++ beecrypt/tests/Makefile.am | 10 +- beecrypt/tests/testmp.c | 74 ++++++++ beecrypt/types.h.in | 6 +- 30 files changed, 455 insertions(+), 796 deletions(-) create mode 100644 beecrypt/gas/mpopt.x86_64.m4 create mode 100644 beecrypt/gas/x86_64.m4 delete mode 100755 beecrypt/installgen.sh create mode 100644 beecrypt/tests/testmp.c (limited to 'beecrypt') diff --git a/beecrypt/acinclude.m4 b/beecrypt/acinclude.m4 index 9c5e148f3..064eed209 100644 --- a/beecrypt/acinclude.m4 +++ b/beecrypt/acinclude.m4 @@ -107,14 +107,12 @@ dnl BEECRYPT_WORKING_AIO AC_DEFUN(BEECRYPT_WORKING_AIO,[ AC_CHECK_HEADERS(aio.h) if test "$ac_cv_header_aio_h" = yes; then - AC_SEARCH_LIBS([aio_read],[c rt aio posix4],,[ - AC_MSG_ERROR([no library containing aio routines found]) - ]) - AC_CACHE_CHECK([whether aio works],bc_cv_working_aio,[ - cat > conftest.aio << EOF + AC_SEARCH_LIBS([aio_read],[c rt aio posix4],[ + AC_CACHE_CHECK([whether aio works],bc_cv_working_aio,[ + cat > conftest.aio << EOF The quick brown fox jumps over the lazy dog. EOF - AC_RUN_IFELSE([AC_LANG_SOURCE([[ + AC_RUN_IFELSE([AC_LANG_SOURCE([[ #if HAVE_ERRNO_H # include #endif @@ -191,13 +189,16 @@ main() exit(0); } - ]])],[bc_cv_working_aio=yes],[bc_cv_working_aio=no],[ - case $target_os in - linux* | solaris*) - bc_cv_working_aio=yes ;; - *) - bc_cv_working_aio=no ;; - esac + ]])],[bc_cv_working_aio=yes],[bc_cv_working_aio=no],[ + case $target_os in + linux* | solaris*) + bc_cv_working_aio=yes ;; + *) + bc_cv_working_aio=no ;; + esac + ]) + ],[ + bc_cv_working_aio=no ]) ]) rm -fr conftest.aio @@ -241,6 +242,7 @@ AC_DEFUN(BEECRYPT_GNU_CC,[ case $target_os in aix*) CC="$CC -maix64" + LDFLAGS="$LDFLAGS -b64" ;; esac ;; @@ -323,12 +325,13 @@ AC_DEFUN(BEECRYPT_COMPAQ_CC,[ #endif ],bc_cv_prog_COMPAQ_CC=yes,bc_cv_prog_COMPAQ_CC=no) ]) - if test "$bc_cv_COMPAQ_CC" = yes; then + if test "$bc_cv_prog_COMPAQ_CC" = yes; then if test "$ac_enable_threads" = yes; then CFLAGS="$CFLAGS -pthread" CPPFLAGS="$CPPFLAGS -pthread" fi if test "$ac_enable_debug" != yes; then + BEECRYPT_CFLAGS_REM([-g]) CFLAGS="$CFLAGS -fast" fi fi @@ -594,6 +597,11 @@ AC_DEFUN(BEECRYPT_ASM_SOURCES,[ m4 $srcdir/gas/mpopt.sparcv8plus.m4 > mpopt.s ]) ;; + x86_64) + AC_CONFIG_COMMANDS([mpopt.x86_m4],[ + m4 $srcdir/gas/mpopt.x86_m4.m4 > mpopt.s + ]) + ;; esac if test "$ac_with_arch" = yes; then # Code is i586-specific! diff --git a/beecrypt/aes.h b/beecrypt/aes.h index 109d67fc6..89b1c115c 100644 --- a/beecrypt/aes.h +++ b/beecrypt/aes.h @@ -41,7 +41,7 @@ extern "C" { /** \ingroup BC_aes_m */ -/*@observer@*/ /*@checked@*/ +/*@observer@*/ /*@unchecked@*/ extern const BEECRYPTAPI blockCipher aes; /** \ingroup BC_aes_m diff --git a/beecrypt/beecrypt.api.h b/beecrypt/beecrypt.api.h index af116618f..6dcea4559 100644 --- a/beecrypt/beecrypt.api.h +++ b/beecrypt/beecrypt.api.h @@ -41,14 +41,6 @@ # define BEECRYPTAPI #endif -#if HAVE_INTTYPES_H -# include -#else -# if HAVE_STDINT_H -# include -# endif -#endif - /* Starting from GCC 3.2, the compiler seems smart enough to figure * out that we're trying to do a rotate without having to specify it. */ @@ -56,22 +48,24 @@ # if defined(__i386__) static inline uint32_t _rotl32(uint32_t x, const unsigned char n) { - __asm__("roll %[n],%[x]" - : [x] "=r" (x) - : "0" (x), [n] "I" (n)); + __asm__("roll %2,%0" + : "=r" (x) + : "0" (x), "I" (n)); return x; } + #define ROTL32(x, n) _rotl32(x, n) static inline uint32_t _rotr32(uint32_t x, const unsigned char n) { - __asm__("rorl %[n],%[x]" - : [x] "=r" (x) - : "0" (x), [n] "I" (n)); + __asm__("rorl %2,%0" + : "=r" (x) + : "0" (x), "I" (n)); return x; } + #define ROTR32(x, n) _rotr32(x, n) # endif diff --git a/beecrypt/beecrypt.c b/beecrypt/beecrypt.c index 058afac2b..873936b5e 100644 --- a/beecrypt/beecrypt.c +++ b/beecrypt/beecrypt.c @@ -26,16 +26,6 @@ #include "system.h" #include "beecrypt.h" -#if defined(__LCLINT__) -/* XXX from /usr/include/bits/sigest.h in glibc-2.2.4 */ -# define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int))) -typedef struct - { - unsigned long int __val[_SIGSET_NWORDS]; - } __sigset_t; -#endif - -#include "endianness.h" #include "entropy.h" #include "fips186.h" #include "hmacmd5.h" @@ -193,9 +183,9 @@ const randomGenerator* randomGeneratorDefault() if (selection) return randomGeneratorFind(selection); else - /*@-globs -compmempass @*/ + /*@-compmempass @*/ return &fips186prng; - /*@=globs =compmempass @*/ + /*@=compmempass @*/ } int randomGeneratorContextInit(randomGeneratorContext* ctxt, const randomGenerator* rng) @@ -270,9 +260,9 @@ const hashFunction* hashFunctionDefault() if (selection) return hashFunctionFind(selection); else - /*@-globs -compmempass @*/ + /*@-compmempass @*/ return &sha1; - /*@=globs =compmempass @*/ + /*@=compmempass @*/ } const hashFunction* hashFunctionGet(int index) @@ -516,9 +506,9 @@ const keyedHashFunction* keyedHashFunctionDefault() if (selection) return keyedHashFunctionFind(selection); else - /*@-globs -compmempass @*/ + /*@-compmempass @*/ return &hmacsha1; - /*@=globs =compmempass @*/ + /*@=compmempass @*/ } const keyedHashFunction* keyedHashFunctionGet(int index) @@ -665,19 +655,19 @@ int keyedHashFunctionContextUpdateMP(keyedHashFunctionContext* ctxt, const mpnum if (n != (mpnumber*) 0) { register int rc; - register byte* temp = (byte*) malloc((n->size << 2) + 1); + register byte* temp = (byte*) malloc(MP_WORDS_TO_BYTES(n->size)+1); /*@-nullpass -nullderef -nullptrarith @*/ /* FIX: temp may be NULL */ if (mpmsbset(n->size, n->data)) { temp[0] = 0; - (void) encodeInts((javaint*) n->data, temp+1, n->size); - rc = ctxt->algo->update(ctxt->param, temp, (n->size << 2) + 1); + (void) i2osp(temp+1, MP_WORDS_TO_BYTES(n->size), n->data, n->size); + rc = ctxt->algo->update(ctxt->param, temp, MP_WORDS_TO_BYTES(n->size)+1); } else { - (void) encodeInts((javaint*) n->data, temp, n->size); - rc = ctxt->algo->update(ctxt->param, temp, n->size << 2); + (void) i2osp(temp, MP_WORDS_TO_BYTES(n->size), n->data, n->size); + rc = ctxt->algo->update(ctxt->param, temp, MP_WORDS_TO_BYTES(n->size)); } free(temp); /*@=nullpass =nullderef =nullptrarith @*/ @@ -778,9 +768,9 @@ const blockCipher* blockCipherDefault() if (selection) return blockCipherFind(selection); else - /*@-globs -compmempass @*/ + /*@-compmempass @*/ return &aes; - /*@=globs =compmempass @*/ + /*@=compmempass @*/ } const blockCipher* blockCipherGet(int index) diff --git a/beecrypt/configure.ac b/beecrypt/configure.ac index e1fd1f6f6..2ade73b7d 100644 --- a/beecrypt/configure.ac +++ b/beecrypt/configure.ac @@ -129,6 +129,9 @@ AC_ARG_WITH(arch,[ --with-arch optimize for specific architecture ( sparc*) bc_target_arch=sparc ;; + x86_64) + bc_target_arch=x86_64 + ;; esac ]) @@ -181,8 +184,7 @@ AC_SUBST(MARK64) # Checks for C compiler and preprocessor AC_PROG_CC AC_PROG_CPP -test -n "$CCAS" || CCAS="$CC -c" -AC_SUBST(CCAS) +AM_PROG_AS # Checks for compiler characteristics and flags if test "$ac_cv_c_compiler_gnu" = yes; then @@ -615,6 +617,9 @@ if test "$ac_enable_debug" != yes; then CPPFLAGS="$CPPFLAGS -DOPTIMIZE_SPARCV9" CFLAGS="$CFLAGS -Wa,-xarch=v9" ;; + x86_64) + CPPFLAGS="$CPPFLAGS -DOPTIMIZE_X86_64" + ;; esac fi diff --git a/beecrypt/dldp.c b/beecrypt/dldp.c index 364c69d2b..079aa6493 100644 --- a/beecrypt/dldp.c +++ b/beecrypt/dldp.c @@ -183,14 +183,10 @@ int dldp_pgoqMake(dldp_p* dp, randomGeneratorContext* rgc, size_t pbits, size_t if (temp) { /* first generate q */ - /*@-globs@*/ mpprnd_w(&dp->q, rgc, qbits, mpptrials(qbits), (const mpnumber*) 0, temp); - /*@=globs@*/ /* generate p with the appropriate congruences */ - /*@-globs@*/ mpprndconone_w(&dp->p, rgc, pbits, mpptrials(pbits), &dp->q, (const mpnumber*) 0, &dp->r, cofactor, temp); - /*@=globs@*/ /* clear n */ mpbzero(&dp->n); @@ -221,9 +217,7 @@ int dldp_pgoqMakeSafe(dldp_p* dp, randomGeneratorContext* rgc, size_t bits) if (temp) { /* generate p */ - /*@-globs@*/ mpprndsafe_w(&dp->p, rgc, bits, mpptrials(bits), temp); - /*@=globs@*/ /* set q */ mpcopy(size, temp, dp->p.modl); @@ -316,14 +310,10 @@ int dldp_pgonMake(dldp_p* dp, randomGeneratorContext* rgc, size_t pbits, size_t if (temp) { /* generate q */ - /*@-globs@*/ mpprnd_w(&dp->q, rgc, qbits, mpptrials(qbits), (const mpnumber*) 0, temp); - /*@=globs@*/ /* generate p with the appropriate congruences */ - /*@-globs@*/ mpprndconone_w(&dp->p, rgc, pbits, mpptrials(pbits), &dp->q, (const mpnumber*) 0, &dp->r, 2, temp); - /*@=globs@*/ /* set n */ mpbsubone(&dp->p, temp); @@ -350,7 +340,6 @@ int dldp_pgonMakeSafe(dldp_p* dp, randomGeneratorContext* rgc, size_t pbits) if (temp) { /* generate safe p */ - /*@-globs@*/ mpprndsafe_w(&dp->p, rgc, pbits, mpptrials(pbits), temp); /*@=globs@*/ diff --git a/beecrypt/endianness.c b/beecrypt/endianness.c index c280fc64b..85a5654c5 100644 --- a/beecrypt/endianness.c +++ b/beecrypt/endianness.c @@ -57,419 +57,13 @@ uint32_t swapu32(uint32_t n) int64_t swap64(int64_t n) { - #if HAVE_LONG_LONG - return ( ((n & 0xffLL) << 56) | - ((n & 0xff00LL) << 40) | - ((n & 0xff0000LL) << 24) | - ((n & 0xff000000LL) << 8) | - ((n & 0xff00000000LL) >> 8) | - ((n & 0xff0000000000LL) >> 24) | - ((n & 0xff000000000000LL) >> 40) | - ((n & 0xff00000000000000LL) >> 56) ); - #else - return ( ((n & 0xffL) << 56) | - ((n & 0xff00L) << 40) | - ((n & 0xff0000L) << 24) | - ((n & 0xff000000L) << 8) | - ((n & 0xff00000000L) >> 8) | - ((n & 0xff0000000000L) >> 24) | - ((n & 0xff000000000000L) >> 40) | - ((n & 0xff00000000000000L) >> 56) ); - #endif + return ( ((n & ((int64_t) 0xff) ) << 56) | + ((n & ((int64_t) 0xff) << 8) << 40) | + ((n & ((int64_t) 0xff) << 16) << 24) | + ((n & ((int64_t) 0xff) << 24) << 8) | + ((n & ((int64_t) 0xff) << 32) >> 8) | + ((n & ((int64_t) 0xff) << 40) >> 24) | + ((n & ((int64_t) 0xff) << 48) >> 40) | + ((n & ((int64_t) 0xff) << 56) >> 56) ); } /*@=bitwisesigned =shiftimplementation@*/ - -int encodeByte(javabyte b, byte *data) -{ - *data = b; - return 1; -} - -int encodeShort(javashort s, byte *data) -{ - #if (!WORDS_BIGENDIAN) - s = swap16(s); - #endif - memcpy(data, &s, 2); - return 2; -} - -int encodeInt(javaint i, byte* data) -{ - #if (!WORDS_BIGENDIAN) - i = swap32(i); - #endif - memcpy(data, &i, 4); - return 4; -} - -int encodeLong(javalong l, byte* data) -{ - #if (!WORDS_BIGENDIAN) - l = swap64(l); - #endif - memcpy(data, &l, 8); - return 8; -} - -int encodeChar(javachar c, byte* data) -{ - #if (!WORDS_BIGENDIAN) - c = swapu16(c); - #endif - memcpy(data, &c, 2); - return 2; -} - -int encodeInts(const javaint* i, byte* data, int count) -{ - register int rc = ((uint32_t)count) << 2; - #if (WORDS_BIGENDIAN) - memcpy(data, i, rc); - #else - javaint tmp; - while (count--) - { - tmp = swap32(*(i++)); - memcpy(data, &tmp, 4); - data += 4; - } - #endif - return rc; -} - -int encodeIntsPartial(const javaint* i, byte* data, int bytecount) -{ - register int rc = bytecount; - #if (WORDS_BIGENDIAN) - memcpy(data, i, rc); - #else - javaint tmp; - - while (bytecount > 0) - { - tmp = swap32(*(i++)); - memcpy(data, &tmp, (bytecount > 4) ? 4 : bytecount); - data += 4; - bytecount -= 4; - } - #endif - return rc; -} - -int encodeIntsPartialPad(const javaint* i, byte* data, int bytecount, byte padvalue) -{ - register int rc = bytecount; - - #if (WORDS_BIGENDIAN) - memcpy(data, i, rc); - if (rc & 0x3) - memset(data+rc, padvalue, 4 -(rc & 0x3)); - #else - javaint tmp; - - while (bytecount > 0) - { - tmp = swap32(*(i++)); - memcpy(data, &tmp, (bytecount > 4) ? 4 : bytecount); - data += 4; - bytecount -= 4; - } - if (bytecount) - memset(data+bytecount, padvalue, -bytecount); - #endif - return rc; -} - -int encodeChars(const javachar* c, byte* data, int count) -{ - register int rc = ((uint32_t)count) << 1; - #if (WORDS_BIGENDIAN) - memcpy(data, c, rc); - #else - javaint tmp; - while (count--) - { - tmp = swapu16(*(c++)); - memcpy(data, &tmp, 2); - data += 2; - } - #endif - return rc; -} - -int decodeByte(javabyte* b, const byte* data) -{ - *b = *data; - return 1; -} - -int decodeShort(javashort* s, const byte* data) -{ - #if (WORDS_BIGENDIAN) - memcpy(s, data, 2); - #else - javashort tmp; - memcpy(&tmp, data, 2); - *s = swap16(tmp); - #endif - return 2; -} - -int decodeInt(javaint* i, const byte* data) -{ - #if (WORDS_BIGENDIAN) - memcpy(i, data, 4); - #else - javaint tmp; - memcpy(&tmp, data, 4); - *i = swap32(tmp); - #endif - return 4; -} - -int decodeLong(javalong* l, const byte* data) -{ - #if (WORDS_BIGENDIAN) - memcpy(l, data, 8); - #else - javalong tmp; - memcpy(&tmp, data, 8); - *l = swap64(tmp); - #endif - return 8; -} - -int decodeChar(javachar* c, const byte* data) -{ - #if (WORDS_BIGENDIAN) - memcpy(c, data, 2); - #else - javachar tmp; - memcpy(&tmp, data, 2); - *c = swapu16(tmp); - #endif - return 2; -} - -int decodeInts(javaint* i, const byte* data, int count) -{ - register int rc = ((uint32_t)count) << 2; - #if (WORDS_BIGENDIAN) - memcpy(i, data, rc); - #else - javaint tmp; - while (count--) - { - memcpy(&tmp, data, 4); - *(i++) = swap32(tmp); - data += 4; - } - #endif - return rc; -} - -int decodeIntsPartial(javaint* i, const byte* data, int bytecount) -{ - register int rc = bytecount; - #if (WORDS_BIGENDIAN) - memcpy(i, data, rc); - if (rc & 0x3) - memset(((byte*) i) + rc, 0, 4 - (rc & 0x3)); - #else - javaint tmp; - while (bytecount >= 4) - { - memcpy(&tmp, data, 4); - *(i++) = swap32(tmp); - data += 4; - bytecount -= 4; - } - if (bytecount) - { - tmp = 0; - memcpy(&tmp, data, bytecount); - *(i++) = swap32(tmp); - } - #endif - return rc; -} - -int decodeChars(javachar* c, const byte* data, int count) -{ - register int rc = ((uint32_t)count) << 1; - #if (WORDS_BIGENDIAN) - memcpy(c, data, rc); - #else - javachar tmp; - while (count--) - { - memcpy(&tmp, data, 2); - *(c++) = swapu16(tmp); - data += 2; - } - #endif - return rc; -} - -int readByte(javabyte* b, FILE* ifp) -{ - return fread(b, 1, 1, ifp); -} - -int readShort(javashort* s, FILE* ifp) -{ - register int rc = fread(s, 2, 1, ifp); - #if !(WORDS_BIGENDIAN) - if (rc == 1) - { - register javashort tmp = *s; - *s = swap16(tmp); - } - #endif - return rc; -} - -int readInt(javaint* i, FILE* ifp) -{ - register int rc = fread(i, 4, 1, ifp); - #if !(WORDS_BIGENDIAN) - if (rc == 1) - { - register javaint tmp = *i; - *i = swap32(tmp); - } - #endif - return rc; -} - -int readLong(javalong* l, FILE* ifp) -{ - register int rc = fread(l, 8, 1, ifp); - #if !(WORDS_BIGENDIAN) - if (rc == 1) - { - register javalong tmp = *l; - *l = swap64(tmp); - } - #endif - return rc; -} - -int readChar(javachar* c, FILE* ifp) -{ - register int rc = fread(c, 2, 1, ifp); - #if !(WORDS_BIGENDIAN) - if (rc == 1) - { - register javachar tmp = *c; - *c = swapu16(tmp); - } - #endif - return rc; -} - -int readInts(javaint* i, FILE* ifp, int count) -{ - register int rc = fread(i, 4, count, ifp); - #if !(WORDS_BIGENDIAN) - if (rc == count) - { - while (count > 0) - { - register javaint tmp = *i; - *(i++) = swap32(tmp); - count--; - } - } - #endif - return rc; -} - -int readChars(javachar* c, FILE* ifp, int count) -{ - register int rc = fread(c, 2, count, ifp); - #if !(WORDS_BIGENDIAN) - if (rc == count) - { - while (count > 0) - { - register javachar tmp = *c; - *(c++) = swap16(tmp); - count--; - } - } - #endif - return rc; -} - -int writeByte(javabyte b, FILE* ofp) -{ - return fwrite(&b, 1, 1, ofp); -} - -int writeShort(javashort s, FILE* ofp) -{ - #if !(WORDS_BIGENDIAN) - s = swap16(s); - #endif - return fwrite(&s, 2, 1, ofp); -} - -int writeInt(javaint i, FILE* ofp) -{ - #if !(WORDS_BIGENDIAN) - i = swap32(i); - #endif - return fwrite(&i, 4, 1, ofp); -} - -int writeLong(javalong l, FILE* ofp) -{ - #if !(WORDS_BIGENDIAN) - l = swap64(l); - #endif - return fwrite(&l, 8, 1, ofp); -} - -int writeChar(javachar c, FILE* ofp) -{ - #if !(WORDS_BIGENDIAN) - c = swap16(c); - #endif - return fwrite(&c, 2, 1, ofp); -} - -int writeInts(const javaint* i, FILE* ofp, int count) -{ - #if WORDS_BIGENDIAN - return fwrite(i, 4, count, ofp); - #else - register int total = 0; - while (count-- > 0) - { - register int rc = writeInt(*(i++), ofp); - if (rc < 0) - break; - total += rc; - } - return total; - #endif -} - -int writeChars(const javachar* c, FILE* ofp, int count) -{ - #if WORDS_BIGENDIAN - return fwrite(c, 2, count, ofp); - #else - register int total = 0; - while (count-- > 0) - { - register int rc = writeChar(*(c++), ofp); - if (rc < 0) - break; - total += rc; - } - return total; - #endif -} diff --git a/beecrypt/endianness.h b/beecrypt/endianness.h index 13ab1d12c..d4289a62f 100644 --- a/beecrypt/endianness.h +++ b/beecrypt/endianness.h @@ -43,17 +43,10 @@ inline uint16_t swapu16(uint16_t n) inline int32_t swap32(int32_t n) { - #if (SIZEOF_LONG == 4) return ( ((n & 0xff) << 24) | ((n & 0xff00) << 8) | ((n & 0xff0000) >> 8) | ((n & 0xff000000) >> 24) ); - #else - return ( ((n & 0xffL) << 24) | - ((n & 0xff00L) << 8) | - ((n & 0xff0000L) >> 8) | - ((n & 0xff000000L) >> 24) ); - #endif } inline uint32_t swapu32(uint32_t n) @@ -73,31 +66,20 @@ inline uint32_t swapu32(uint32_t n) inline int64_t swap64(int64_t n) { - #if HAVE_LONG_LONG - return ( ((n & 0xffLL) << 56) | - ((n & 0xff00LL) << 40) | - ((n & 0xff0000LL) << 24) | - ((n & 0xff000000LL) << 8) | - ((n & 0xff00000000LL) >> 8) | - ((n & 0xff0000000000LL) >> 24) | - ((n & 0xff000000000000LL) >> 40) | - ((n & 0xff00000000000000LL) >> 56) ); - #else - return ( ((n & 0xffL) << 56) | - ((n & 0xff00L) << 40) | - ((n & 0xff0000L) << 24) | - ((n & 0xff000000L) << 8) | - ((n & 0xff00000000L) >> 8) | - ((n & 0xff0000000000L) >> 24) | - ((n & 0xff000000000000L) >> 40) | - ((n & 0xff00000000000000L) >> 56) ); - #endif + return ( ((n & ((int64_t) 0xff) ) << 56) | + ((n & ((int64_t) 0xff) << 8) << 40) | + ((n & ((int64_t) 0xff) << 16) << 24) | + ((n & ((int64_t) 0xff) << 24) << 8) | + ((n & ((int64_t) 0xff) << 32) >> 8) | + ((n & ((int64_t) 0xff) << 40) >> 24) | + ((n & ((int64_t) 0xff) << 48) >> 40) | + ((n & ((int64_t) 0xff) << 56) >> 56) ); } #else /*@-exportlocal@*/ - /** */ +/*@unused@*/ int16_t swap16 (int16_t n) /*@*/; @@ -108,6 +90,7 @@ uint16_t swapu16(uint16_t n) /** */ +/*@unused@*/ int32_t swap32 (int32_t n) /*@*/; @@ -118,222 +101,10 @@ uint32_t swapu32(uint32_t n) /** */ +/*@unused@*/ int64_t swap64 (int64_t n) /*@*/; /*@=exportlocal@*/ #endif -#ifdef __cplusplus -extern "C" { -#endif - - -/** - */ -BEECRYPTAPI /*@unused@*/ -int encodeByte(javabyte b, /*@out@*/ byte* data) - /*@modifies data @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int encodeShort(javashort s, /*@out@*/ byte* data) - /*@modifies data @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int encodeInt(javaint i, /*@out@*/ byte* data) - /*@modifies data @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int encodeLong(javalong l, /*@out@*/ byte* data) - /*@modifies data @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int encodeChar(javachar c, /*@out@*/ byte* data) - /*@modifies data @*/; - -/** - */ -BEECRYPTAPI -int encodeInts(const javaint* i, /*@out@*/ byte* data, int count) - /*@modifies data @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int encodeIntsPartial(const javaint* i, /*@out@*/ byte* data, int bytecount) - /*@modifies data @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int encodeIntsPartialPad(const javaint* i, byte* data, int bytecount, byte padvalue) - /*@modifies data @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int encodeChars(const javachar* c, /*@out@*/ byte* data, int count) - /*@modifies data @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int decodeByte(/*@out@*/ javabyte* b, const byte* data) - /*@modifies b @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int decodeShort(/*@out@*/ javashort* s, const byte* data) - /*@modifies s @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int decodeInt(/*@out@*/ javaint* i, const byte* data) - /*@modifies i @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int decodeLong(/*@out@*/ javalong* l, const byte* data) - /*@modifies l @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int decodeChar(/*@out@*/ javachar* c, const byte* data) - /*@modifies c @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int decodeInts(/*@out@*/ javaint* i, const byte* data, int count) - /*@modifies i @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int decodeIntsPartial(/*@out@*/ javaint* i, const byte* data, int bytecount) - /*@modifies i @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int decodeChars(/*@out@*/ javachar* c, const byte* data, int count) - /*@modifies c @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int writeByte(javabyte b, FILE* ofp) - /*@globals fileSystem @*/ - /*@modifies ofp, fileSystem @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int writeShort(javashort s, FILE* ofp) - /*@globals fileSystem @*/ - /*@modifies ofp, fileSystem @*/; - -/** - */ -/*@-exportlocal@*/ -BEECRYPTAPI -int writeInt(javaint i, FILE* ofp) - /*@globals fileSystem @*/ - /*@modifies ofp, fileSystem @*/; -/*@=exportlocal@*/ - -/** - */ -BEECRYPTAPI /*@unused@*/ -int writeLong(javalong l, FILE* ofp) - /*@globals fileSystem @*/ - /*@modifies ofp, fileSystem @*/; - -/** - */ -/*@-exportlocal@*/ -BEECRYPTAPI -int writeChar(javachar c, FILE* ofp) - /*@globals fileSystem @*/ - /*@modifies ofp, fileSystem @*/; -/*@=exportlocal@*/ - -/** - */ -BEECRYPTAPI /*@unused@*/ -int writeInts(const javaint* i, FILE* ofp, int count) - /*@globals fileSystem @*/ - /*@modifies ofp, fileSystem @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int writeChars(const javachar* c, FILE* ofp, int count) - /*@globals fileSystem @*/ - /*@modifies ofp, fileSystem @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int readByte(/*@out@*/ javabyte* b, FILE* ifp) - /*@globals fileSystem @*/ - /*@modifies b, ifp, fileSystem @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int readShort(/*@out@*/ javashort* s, FILE* ifp) - /*@globals fileSystem @*/ - /*@modifies s, ifp, fileSystem @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int readInt(/*@out@*/ javaint* i, FILE* ifp) - /*@globals fileSystem @*/ - /*@modifies i, ifp, fileSystem @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int readLong(/*@out@*/ javalong* l, FILE* ifp) - /*@globals fileSystem @*/ - /*@modifies l, ifp, fileSystem @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int readChar(/*@out@*/ javachar* c, FILE* ifp) - /*@globals fileSystem @*/ - /*@modifies c, ifp, fileSystem @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int readInts(/*@out@*/ javaint* i, FILE* ifp, int count) - /*@globals fileSystem @*/ - /*@modifies i, ifp, fileSystem @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int readChars(/*@out@*/ javachar* c, FILE* ifp, int count) - /*@globals fileSystem @*/ - /*@modifies c, ifp, fileSystem @*/; - -#ifdef __cplusplus -} -#endif - #endif diff --git a/beecrypt/fips186.c b/beecrypt/fips186.c index b1f0a2e1a..015d51b45 100644 --- a/beecrypt/fips186.c +++ b/beecrypt/fips186.c @@ -25,7 +25,6 @@ #include "system.h" #include "beecrypt.h" -#include "endianness.h" /* XXX for encodeInts */ #include "fips186.h" #include "mpopt.h" #include "mp.h" @@ -170,7 +169,33 @@ int fips186Next(fips186Param* fp, byte* data, size_t size) memcpy(fp->param.data, fp->state, MP_WORDS_TO_BYTES(FIPS186_STATE_SIZE)); /* process the data */ sha1Process(&fp->param); - (void) encodeInts(fp->param.h, fp->digest, 5); + + #if WORDS_BIGENDIAN + memcpy(fp->digest, fp->param.h, 20); + #else + /* encode 5 integers big-endian style */ + fp->digest[ 0] = (byte)(fp->param.h[0] >> 24); + fp->digest[ 1] = (byte)(fp->param.h[0] >> 16); + fp->digest[ 2] = (byte)(fp->param.h[0] >> 8); + fp->digest[ 3] = (byte)(fp->param.h[0] >> 0); + fp->digest[ 4] = (byte)(fp->param.h[1] >> 24); + fp->digest[ 5] = (byte)(fp->param.h[1] >> 16); + fp->digest[ 6] = (byte)(fp->param.h[1] >> 8); + fp->digest[ 7] = (byte)(fp->param.h[1] >> 0); + fp->digest[ 8] = (byte)(fp->param.h[2] >> 24); + fp->digest[ 9] = (byte)(fp->param.h[2] >> 16); + fp->digest[10] = (byte)(fp->param.h[2] >> 8); + fp->digest[11] = (byte)(fp->param.h[2] >> 0); + fp->digest[12] = (byte)(fp->param.h[3] >> 24); + fp->digest[13] = (byte)(fp->param.h[3] >> 16); + fp->digest[14] = (byte)(fp->param.h[3] >> 8); + fp->digest[15] = (byte)(fp->param.h[3] >> 0); + fp->digest[16] = (byte)(fp->param.h[4] >> 24); + fp->digest[17] = (byte)(fp->param.h[4] >> 16); + fp->digest[18] = (byte)(fp->param.h[4] >> 8); + fp->digest[19] = (byte)(fp->param.h[4] >> 0); + #endif + if (os2ip(dig, FIPS186_STATE_SIZE, fp->digest, 20) == 0) { /* set state to state + digest + 1 mod 2^512 */ diff --git a/beecrypt/fips186.h b/beecrypt/fips186.h index 8c14697aa..46dfcd8c6 100644 --- a/beecrypt/fips186.h +++ b/beecrypt/fips186.h @@ -60,7 +60,7 @@ extern "C" { /** */ -/*@observer@*/ /*@checked@*/ +/*@observer@*/ /*@unchecked@*/ extern BEECRYPTAPI const randomGenerator fips186prng; /** diff --git a/beecrypt/gas/mpopt.ia64.m4 b/beecrypt/gas/mpopt.ia64.m4 index 8486fe2e5..b15b8ad2d 100644 --- a/beecrypt/gas/mpopt.ia64.m4 +++ b/beecrypt/gas/mpopt.ia64.m4 @@ -21,7 +21,7 @@ dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA include(config.m4) include(ASM_SRCDIR/ia64.m4) -define(`size',`r16') +define(`sze',`r16') define(`dst',`r17') define(`src',`r18') define(`alt',`r19') @@ -30,15 +30,15 @@ define(`alt',`r19') C_FUNCTION_BEGIN(mpadd) alloc saved_pfs = ar.pfs,3,5,0,8 mov saved_lc = ar.lc - sub size = in0,r0,1;; + sub sze = in0,r0,1;; dnl adjust addresses - shladd dst = size,3,in1 - shladd src = size,3,in2 - shladd alt = size,3,in1 + shladd dst = sze,3,in1 + shladd src = sze,3,in2 + shladd alt = sze,3,in1 dnl prepare modulo-scheduled loop - mov ar.lc = size + mov ar.lc = sze mov ar.ec = 2 mov pr.rot = ((1 << 16) | (1 << 19));; @@ -69,15 +69,15 @@ C_FUNCTION_END(mpadd) C_FUNCTION_BEGIN(mpsub) alloc saved_pfs = ar.pfs,3,5,0,8 mov saved_lc = ar.lc - sub size = in0,r0,1;; + sub sze = in0,r0,1;; dnl adjust addresses - shladd dst = size,3,in1 - shladd src = size,3,in2 - shladd alt = size,3,in1 + shladd dst = sze,3,in1 + shladd src = sze,3,in2 + shladd alt = sze,3,in1 dnl prepare modulo-scheduled loop - mov ar.lc = size + mov ar.lc = sze mov ar.ec = 2 mov pr.rot = ((1 << 16) | (1 << 19));; @@ -111,14 +111,14 @@ C_FUNCTION_BEGIN(mpsetmul) setf.sig f6 = in3 setf.sig f7 = r0 - sub size = in0,r0,1;; + sub sze = in0,r0,1;; dnl adjust addresses - shladd dst = size,3,in1 - shladd src = size,3,in2 + shladd dst = sze,3,in1 + shladd src = sze,3,in2 dnl prepare modulo-scheduled loop - mov ar.lc = size + mov ar.lc = sze mov ar.ec = 3 mov pr.rot = (1 << 16);; @@ -143,18 +143,18 @@ C_FUNCTION_BEGIN(mpaddmul) mov saved_lc = ar.lc setf.sig f6 = in3 - sub size = in0,r0,1;; + sub sze = in0,r0,1;; dnl adjust addresses - shladd dst = size,3,in1 - shladd src = size,3,in2 - shladd alt = size,3,in1;; + shladd dst = sze,3,in1 + shladd src = sze,3,in2 + shladd alt = sze,3,in1;; dnl prepare the rotate-in carry - mov r32 = r0 + mov r32 = r0 dnl prepare modulo-scheduled loop - mov ar.lc = size + mov ar.lc = sze mov ar.ec = 4 mov pr.rot = ((1 << 16) | (1 << 21)); @@ -185,3 +185,56 @@ dnl return carry mov ar.pfs = saved_pfs br.ret.sptk b0 C_FUNCTION_END(mpaddmul) + + +divert(-1) +C_FUNCTION_BEGIN(mpaddsqrtrc) + alloc saved_pfs = ar.pfs,4,4,0,8 + mov saved_lc = ar.lc + + setf.sig f6 = in3 + sub sze = in0,r0,1;; + +dnl adjust addresses + shladd dst = sze,4,in1 + shladd src = sze,3,in2 + shladd alt = sze,4,in1;; + +dnl prepare the rotate-in carry + mov r32 = r0 + +dnl prepare modulo-scheduled loop + mov ar.lc = sze + mov ar.ec = 5 + mov pr.rot = ((1 << 16) | (1 << 21)); + +LOCAL(mpaddsqrtrc_loop): + (p16) ldf8 f32 = [src],-8 + (p16) ldf8 f36 = [alt],-8 + (p17) xma.lu f34 = f33,f33,f37 + (p17) xma.hu f38 = f33,f33,f37 + (p18) getf.sig r37 = f35 + (p18) getf.sig r33 = f39 + (p?) add lo to carry + (p?+?) add lo to carry+1 + (p?) cmpleu lo + (p?+?) cmpltu lo + (p?) add hi to carry + (p?+?) add hi to carry+1 + (p16) ld8 r?? = [alt],-8 + (p20) st8 lo + (p?) cmpleu hi + (p?+?) cmpltu hi + (p21) st8 hi + ;; + br.ctop.dptk LOCAL(mpaddsqrtrc_loop);; + +dnl loop epilogue: final store + (p21) st8 [dst] = r36,-8 + +dnl return carry + (p24) add ret0 = r35,r0 + (p26) add ret0 = r35,r0,1 + +C_FUNCTION_END(mpaddsqrtrc) +divert(0) diff --git a/beecrypt/gas/mpopt.x86.m4 b/beecrypt/gas/mpopt.x86.m4 index e1097999d..98e9d213d 100644 --- a/beecrypt/gas/mpopt.x86.m4 +++ b/beecrypt/gas/mpopt.x86.m4 @@ -331,9 +331,9 @@ LOCAL(mpaddmul_loop): movl (%esi,%ecx,4),%eax mull %ebp addl %ebx,%eax - adcl $0,%edx + adcl `$'0,%edx addl (%edi,%ecx,4),%eax - adcl $0,%edx + adcl `$'0,%edx movl %eax,(%edi,%ecx,4) decl %ecx jns LOCAL(mpaddmul_loop) @@ -393,7 +393,7 @@ LOCAL(mpaddsqrtrc_loop): movl (%esi,%ecx,4),%eax mull %eax addl %ebx,%eax - adcl $0,%edx + adcl `$'0,%edx addl %eax,4(%edi,%ecx,8) adcl %edx,(%edi,%ecx,8) sbbl %ebx,%ebx diff --git a/beecrypt/gas/mpopt.x86_64.m4 b/beecrypt/gas/mpopt.x86_64.m4 new file mode 100644 index 000000000..2fa8a1892 --- /dev/null +++ b/beecrypt/gas/mpopt.x86_64.m4 @@ -0,0 +1,108 @@ +dnl mpopt.x86_64.m4 +dnl +dnl Copyright (c) 2003 Bob Deblier +dnl +dnl Author: Bob Deblier +dnl +dnl This library is free software; you can redistribute it and/or +dnl modify it under the terms of the GNU Lesser General Public +dnl License as published by the Free Software Foundation; either +dnl version 2.1 of the License, or (at your option) any later version. +dnl +dnl This library is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +dnl Lesser General Public License for more details. +dnl +dnl You should have received a copy of the GNU Lesser General Public +dnl License along with this library; if not, write to the Free Software +dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + .file "mpopt.s" + +include(config.m4) +include(ARM_SRCDIR/x86_64.m4) + + +C_FUNCTION_BEGIN(mpzero) + movq %rdi,%rcx + movq %rsi,%rdi + xorq %rax,%rax + repz stosq + ret +C_FUNCTION_END(mpzero) + + +C_FUNCTION_BEGIN(mpfill) + movq %rdi,%rcx + movq %rsi,%rdi + movq %rdx,%rdi + repz stosq + ret +C_FUNCTION_END(mpfill) + + +C_FUNCTION_BEGIN(mpeven) + movq -8(%rsi,%rdi,8),%rax + notq %rax + andq `$'1,%rax + ret +C_FUNCTION_END(mpeven) + + +C_FUNCTION_BEGIN(mpodd) + movq -8(%rsi,%rdi,8),%rax + andq `$'1,%rax + ret +C_FUNCTION_END(mpodd) + + +C_FUNCTION_BEGIN(mpsetmul) + movq %rcx,%r8 + movq %rdi,%rcx + movq %rdx,%rdi + + xorq %rdx,%rdx + decq %rcx + + .align 4 +LOCAL(mpsetmul_loop): + movq %rdx,%r9 + movq (%rdi,%rcx,8),%rax + mulq %r8 + addq %r9,%rax + adcq `$'0,%rdx + movq %rax,(%rsi,%rcx,8) + decq %rcx + jns LOCAL(mpsetmul_loop) + + movq %rdx,%rax + + ret +C_FUNCTION_END(mpsetmul) + + +C_FUNCTION_BEGIN(mpaddmul) + movq %rcx,%r8 + movq %rdi,%rcx + movq %rdx,%rdi + + xorq %rdx,%rdx + decq %rcx + + .align 4 +LOCAL(mpaddmul_loop): + movq %rdx,%r9 + movq (%rdi,%rcx,8),%rax + mulq %r8 + addq %r9,%rax + adcq `$'0,%rdx + addq (%rsi,%rcx,8),%rax + adcq `$'0,%rdx + movq %rax,(%rsi,%rcx,8) + decq %rcx + jns LOCAL(mpaddmul_loop) + + movq %rdx,%rax + ret +C_FUNCTION_END(mpaddmul) diff --git a/beecrypt/gas/sha1opt.x86.m4 b/beecrypt/gas/sha1opt.x86.m4 index a8d8ec6b5..1784f5fc2 100644 --- a/beecrypt/gas/sha1opt.x86.m4 +++ b/beecrypt/gas/sha1opt.x86.m4 @@ -113,18 +113,27 @@ LOCAL(0): jns LOCAL(0) movl `$'15,%ecx - xorl %eax,%eax .align 4 LOCAL(1): movl (%edi,%ecx,4),%edx +ifdef(`USE_BSWAP',` bswap %edx +',` + movl %edx,%eax + andl `$'0xff00ff,%edx + rol `$'8,%eax + andl `$'0xff00ff,%eax + ror `$'8,%edx + or %eax,%edx +') mov %edx,(%edi,%ecx,4) decl %ecx jns LOCAL(1) leal PARAM_DATA(%esi),%edi movl `$'16,%ecx + xorl %eax,%eax .align 4 LOCAL(2): diff --git a/beecrypt/gas/x86_64.m4 b/beecrypt/gas/x86_64.m4 new file mode 100644 index 000000000..3fcfbf987 --- /dev/null +++ b/beecrypt/gas/x86_64.m4 @@ -0,0 +1,20 @@ +dnl x86_64.m4 +dnl +dnl Copyright (c) 2003 Bob Deblier +dnl +dnl Author: Bob Deblier +dnl +dnl This library is free software; you can redistribute it and/or +dnl modify it under the terms of the GNU Lesser General Public +dnl License as published by the Free Software Foundation; either +dnl version 2.1 of the License, or (at your option) any later version. +dnl +dnl This library is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +dnl Lesser General Public License for more details. +dnl +dnl You should have received a copy of the GNU Lesser General Public +dnl License along with this library; if not, write to the Free Software +dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + diff --git a/beecrypt/hmacmd5.h b/beecrypt/hmacmd5.h index 4a6d29c8d..eafa7e7e1 100644 --- a/beecrypt/hmacmd5.h +++ b/beecrypt/hmacmd5.h @@ -44,7 +44,7 @@ extern "C" { /** \ingroup HMAC_md5_m */ -/*@observer@*/ /*@checked@*/ +/*@observer@*/ /*@unchecked@*/ extern BEECRYPTAPI const keyedHashFunction hmacmd5; /** \ingroup HMAC_md5_m diff --git a/beecrypt/hmacsha1.h b/beecrypt/hmacsha1.h index 003b1400b..c710309e7 100644 --- a/beecrypt/hmacsha1.h +++ b/beecrypt/hmacsha1.h @@ -44,7 +44,7 @@ extern "C" { /** \ingroup HMAC_sha1_m */ -/*@observer@*/ /*@checked@*/ +/*@observer@*/ /*@unchecked@*/ extern BEECRYPTAPI const keyedHashFunction hmacsha1; /** \ingroup HMAC_sha1_m diff --git a/beecrypt/installgen.sh b/beecrypt/installgen.sh deleted file mode 100755 index ca366bde0..000000000 --- a/beecrypt/installgen.sh +++ /dev/null @@ -1,6 +0,0 @@ -#! /bin/sh -libtoolize --force --copy -aclocal -autoheader -automake -a Makefile docs/Makefile gas/Makefile masm/Makefile mwerks/Makefile tests/Makefile -autoconf diff --git a/beecrypt/md5.c b/beecrypt/md5.c index 2e458c566..73f2e55c5 100644 --- a/beecrypt/md5.c +++ b/beecrypt/md5.c @@ -260,27 +260,27 @@ static void md5Finish(md5Param* mp) mp->offset = 0; } -int md5Digest(md5Param* mp, byte* data) +int md5Digest(md5Param* mp, byte* digest) { md5Finish(mp); /* encode 4 integers little-endian style */ - data[ 0] = (byte)(mp->h[0] ); - data[ 1] = (byte)(mp->h[0] >> 8); - data[ 2] = (byte)(mp->h[0] >> 16); - data[ 3] = (byte)(mp->h[0] >> 24); - data[ 4] = (byte)(mp->h[1] ); - data[ 5] = (byte)(mp->h[1] >> 8); - data[ 6] = (byte)(mp->h[1] >> 16); - data[ 7] = (byte)(mp->h[1] >> 24); - data[ 8] = (byte)(mp->h[2] ); - data[ 9] = (byte)(mp->h[2] >> 8); - data[10] = (byte)(mp->h[2] >> 16); - data[11] = (byte)(mp->h[2] >> 24); - data[12] = (byte)(mp->h[3] ); - data[13] = (byte)(mp->h[3] >> 8); - data[14] = (byte)(mp->h[3] >> 16); - data[15] = (byte)(mp->h[3] >> 24); + digest[ 0] = (byte)(mp->h[0] ); + digest[ 1] = (byte)(mp->h[0] >> 8); + digest[ 2] = (byte)(mp->h[0] >> 16); + digest[ 3] = (byte)(mp->h[0] >> 24); + digest[ 4] = (byte)(mp->h[1] ); + digest[ 5] = (byte)(mp->h[1] >> 8); + digest[ 6] = (byte)(mp->h[1] >> 16); + digest[ 7] = (byte)(mp->h[1] >> 24); + digest[ 8] = (byte)(mp->h[2] ); + digest[ 9] = (byte)(mp->h[2] >> 8); + digest[10] = (byte)(mp->h[2] >> 16); + digest[11] = (byte)(mp->h[2] >> 24); + digest[12] = (byte)(mp->h[3] ); + digest[13] = (byte)(mp->h[3] >> 8); + digest[14] = (byte)(mp->h[3] >> 16); + digest[15] = (byte)(mp->h[3] >> 24); (void) md5Reset(mp); return 0; diff --git a/beecrypt/md5.h b/beecrypt/md5.h index ed6b0ab6b..fd3d00553 100644 --- a/beecrypt/md5.h +++ b/beecrypt/md5.h @@ -49,11 +49,14 @@ extern "C" { #endif /** \ingroup HASH_md5_m + * Holds the full API description of the MD5 algorithm. */ /*@observer@*/ /*@checked@*/ extern BEECRYPTAPI const hashFunction md5; /** \ingroup HASH_md5_m + * This function performs the MD5 hash algorithm on 64 byte blocks of data. + * @param mp hash parameter block */ /*@-exportlocal@*/ BEECRYPTAPI @@ -62,6 +65,9 @@ void md5Process(md5Param* mp) /*@=exportlocal@*/ /** \ingroup HASH_md5_m + * This function resets the parameter block so that it's ready for a new hash. + * @param mp hash parameter block + * @return 0 on success. */ /*@-exportlocal@*/ BEECRYPTAPI @@ -70,6 +76,11 @@ int md5Reset (md5Param* mp) /*@=exportlocal@*/ /** \ingroup HASH_md5_m + * This function should be used to pass successive blocks of data to be hashed. + * @param mp hash parameter block + * @param *data bytes to hash + * @param size no. of bytes to hash + * @return 0 on success */ /*@-exportlocal@*/ BEECRYPTAPI @@ -78,11 +89,16 @@ int md5Update (md5Param* mp, const byte* data, size_t size) /*@=exportlocal@*/ /** \ingroup HASH_md5_m + * This function finishes the current hash computation, returning the digest + * value in \a digest. + * @param sp hash parameter block + * @retval *digest 16 byte MD5 digest + * @return 0 on success. */ /*@-exportlocal@*/ BEECRYPTAPI -int md5Digest (md5Param* mp, /*@out@*/ byte* data) - /*@modifies mp, data @*/; +int md5Digest (md5Param* mp, /*@out@*/ byte* digest) + /*@modifies mp, digest @*/; /*@=exportlocal@*/ #ifdef __cplusplus diff --git a/beecrypt/mpbarrett.c b/beecrypt/mpbarrett.c index 12a849b21..f7f8f19a6 100644 --- a/beecrypt/mpbarrett.c +++ b/beecrypt/mpbarrett.c @@ -1105,18 +1105,14 @@ int mpbpprime_w(const mpbarrett* b, randomGeneratorContext* r, int t, mpw* wksp) if (size > SMALL_PRIMES_PRODUCT_MAX) { - /*@-globs@*/ mpsetx(size, wksp+size, SMALL_PRIMES_PRODUCT_MAX, mpspprod[SMALL_PRIMES_PRODUCT_MAX-1]); - /*@=globs@*/ /*@-compdef@*/ /* LCL: wksp+size */ mpgcd_w(size, b->modl, wksp+size, wksp, wksp+2*size); /*@=compdef@*/ } else { - /*@-globs@*/ mpgcd_w(size, b->modl, mpspprod[size-1], wksp, wksp+2*size); - /*@=globs@*/ } if (mpisone(size, wksp)) diff --git a/beecrypt/mpopt.h b/beecrypt/mpopt.h index db6499893..3fb64de07 100644 --- a/beecrypt/mpopt.h +++ b/beecrypt/mpopt.h @@ -31,8 +31,8 @@ # elif defined(_MSC_VER) && defined(_M_IX86) # define ASM_MPZERO # define ASM_MPFILL -# define ASM_MPODD # define ASM_MPEVEN +# define ASM_MPODD # define ASM_MPADDW # define ASM_MPSUBW # define ASM_MPADD @@ -69,8 +69,8 @@ # elif defined(OPTIMIZE_I386) || defined(OPTIMIZE_I486) || defined(OPTIMIZE_I586) || defined(OPTIMIZE_I686) # define ASM_MPZERO # define ASM_MPFILL -# define ASM_MPODD # define ASM_MPEVEN +# define ASM_MPODD # define ASM_MPADDW # define ASM_MPSUBW # define ASM_MPADD @@ -114,6 +114,13 @@ # define ASM_MPSETMUL # define ASM_MPADDMUL # define ASM_MPADDSQRTRC +# elif defined(OPTIMIZE_X86_64) +# define ASM_MPZERO +# define ASM_MPFILL +# define ASM_MPEVEN +# define ASM_MPODD +# define ASM_MPSETMUL +# define ASM_MPADDMUL # endif #endif @@ -134,8 +141,8 @@ # if defined(OPTIMIZE_I386) || defined(OPTIMIZE_I486) || defined(OPTIMIZE_I586) || defined(OPTIMIZE_I686) # define ASM_MPZERO # define ASM_MPFILL -# define ASM_MPODD # define ASM_MPEVEN +# define ASM_MPODD # define ASM_MPADDW # define ASM_MPSUBW # define ASM_MPADD diff --git a/beecrypt/mpprime.h b/beecrypt/mpprime.h index db965c125..0b7e27f8f 100644 --- a/beecrypt/mpprime.h +++ b/beecrypt/mpprime.h @@ -33,6 +33,7 @@ /** */ /*@-exportlocal@*/ +/*@unchecked@*/ extern mpw* mpspprod[SMALL_PRIMES_PRODUCT_MAX]; /*@=exportlocal@*/ diff --git a/beecrypt/rsa.c b/beecrypt/rsa.c index d1a6cf92e..23827b7ab 100644 --- a/beecrypt/rsa.c +++ b/beecrypt/rsa.c @@ -104,7 +104,7 @@ int rsapricrt(const rsakp* kp, const mpnumber* c, mpnumber* m) /* compute j1 = c^d1 mod p, store @ ptemp */ mpbpowmod_w(&kp->p, psize, ptemp+psize, kp->d1.size, kp->d1.data, ptemp, ptemp+2*psize); - /* resize c for powmod p */ + /* resize c for powmod q */ mpsetx(qsize*2, qtemp, c->size, c->data); /* reduce modulo q before we powmod */ diff --git a/beecrypt/rsakp.c b/beecrypt/rsakp.c index b53fdab8d..b47db79ba 100644 --- a/beecrypt/rsakp.c +++ b/beecrypt/rsakp.c @@ -53,10 +53,8 @@ int rsakpMake(rsakp* kp, randomGeneratorContext* rgc, size_t nsize) mpnsetw(&kp->e, 65535); /* generate a random prime p and q */ - /*@-globs@*/ mpprnd_w(&kp->p, rgc, pqsize, mpptrials(MP_WORDS_TO_BITS(pqsize)), &kp->e, temp); mpprnd_w(&kp->q, rgc, pqsize, mpptrials(MP_WORDS_TO_BITS(pqsize)), &kp->e, temp); - /*@=globs@*/ /* if p <= q, perform a swap to make p larger than q */ if (mple(pqsize, kp->p.modl, kp->q.modl)) @@ -80,9 +78,7 @@ int rsakpMake(rsakp* kp, randomGeneratorContext* rgc, size_t nsize) /* product of p and q doesn't have the required size (one bit short) */ - /*@-globs@*/ mpprnd_w(&r, rgc, pqsize, mpptrials(MP_WORDS_TO_BITS(pqsize)), &kp->e, temp); - /*@=globs@*/ /*@-usedef -branchstate @*/ /* r is set */ if (mple(pqsize, kp->p.modl, r.modl)) diff --git a/beecrypt/sha1.h b/beecrypt/sha1.h index a057120f2..8d170bd22 100644 --- a/beecrypt/sha1.h +++ b/beecrypt/sha1.h @@ -50,7 +50,7 @@ extern "C" { /** \ingroup HASH_sha1_m */ -/*@observer@*/ /*@checked@*/ +/*@observer@*/ /*@unchecked@*/ extern BEECRYPTAPI const hashFunction sha1; /** \ingroup HASH_sha1_m diff --git a/beecrypt/system.h b/beecrypt/system.h index af8b5efbe..6ca004a52 100644 --- a/beecrypt/system.h +++ b/beecrypt/system.h @@ -19,6 +19,17 @@ # endif #endif +#if defined(__LCLINT__) +/* XXX from /usr/include/bits/sigest.h in glibc-2.2.4 */ +/*@-sizeoftype@*/ +# define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int))) +typedef struct + { + unsigned long int __val[_SIGSET_NWORDS]; + } __sigset_t; +/*@=sizeoftype@*/ +#endif + #include "types.h" #if HAVE_SYS_STAT_H diff --git a/beecrypt/tests/Makefile.am b/beecrypt/tests/Makefile.am index b973c93b0..fecdd2cb9 100644 --- a/beecrypt/tests/Makefile.am +++ b/beecrypt/tests/Makefile.am @@ -25,11 +25,9 @@ AUTOMAKE_OPTIONS = gnu no-dependencies INCLUDES = -I$(top_srcdir) LDADD = $(top_builddir)/libbeecrypt.la -TESTS = testmd5 testsha1 testsha256 testhmacmd5 testhmacsha1 testblowfish testrsa testdldp +TESTS = testmd5 testsha1 testsha256 testhmacmd5 testhmacsha1 testmp testrsa testdldp -staticLDFLAGS = -all-static - -check_PROGRAMS = testmd5 testsha1 testsha256 testhmacmd5 testhmacsha1 testblowfish testrsa testdldp +check_PROGRAMS = testmd5 testsha1 testsha256 testhmacmd5 testhmacsha1 testmp testrsa testdldp testmd5_SOURCES = testmd5.c @@ -41,13 +39,11 @@ testhmacmd5_SOURCES = testhmacmd5.c testhmacsha1_SOURCES = testhmacsha1.c -testblowfish_SOURCES = testblowfish.c +testmp_SOURCES = testmp.c testrsa_SOURCES = testrsa.c testdldp_SOURCES = testdldp.c -#testdldp_LDADD = $(LDADD) -lpthread -#testdldp_LDFLAGS = $(staticLDFLAGS) EXTRA_PROGRAMS = benchme benchhf benchbc diff --git a/beecrypt/tests/testmp.c b/beecrypt/tests/testmp.c new file mode 100644 index 000000000..e8ecf31f3 --- /dev/null +++ b/beecrypt/tests/testmp.c @@ -0,0 +1,74 @@ +#include + +#include "beecrypt.h" +#include "mp.h" + +#define INIT 0xdeadbeefU; + +static const mpw z[4] = { 0U, 0U, 0U, 0U }; +static const mpw f[4] = { ~((mpw) 0U), ~((mpw) 0U), ~((mpw) 0U), ~((mpw) 0U)}; + +int main() +{ + int i; + mpw x[4]; + mpw y[4]; + + for (i = 0; i < 4; i++) + x[i] = INIT; + + mpcopy(4, x, z); + for (i = 0; i < 4; i++) + { + if (x[i] != 0) + { + printf("mpcopy failed\n"); + return 1; + } + } + + if (!mpeq(4, x, z)) + { + printf("mpeq failed\n"); + return 1; + } + if (mpne(4, x, z)) + { + printf("mpne failed\n"); + return 1; + } + + mpcopy(4, x, f); + for (i = 0; i < 4; i++) + { + if (x[i] != ~((mpw) 0)) + { + printf("mpcopy failed\n"); + return 1; + } + } + + if (!mpz(4, z) || mpz(4, f)) + { + printf("mpz failed\n"); + return 1; + } + if (mpnz(4, z) || !mpnz(4, f)) + { + printf("mpnz failed\n"); + return 1; + } + + if (!mpeq(4, x, f)) + { + printf("mpeq failed\n"); + return 1; + } + if (mpne(4, x, f)) + { + printf("mpne failed\n"); + return 1; + } + + return 0; +} diff --git a/beecrypt/types.h.in b/beecrypt/types.h.in index eed73acd5..8489cd9fc 100644 --- a/beecrypt/types.h.in +++ b/beecrypt/types.h.in @@ -68,12 +68,14 @@ static inline uint32_t _rotr32(uint32_t x, const unsigned char n) typedef uint8_t byte; +/*@-typeuse@*/ typedef int8_t javabyte; typedef int16_t javashort; +typedef uint16_t javachar; typedef int32_t javaint; -typedef int64_t javalong; +/*@=typeuse@*/ -typedef uint16_t javachar; +typedef int64_t javalong; #if !defined(MP_WBITS) #define MP_WBITS @MP_WBITS@ -- cgit v1.2.3