Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002 Virtual Unlimited B.V.
-Author: Bob Deblier <bob@virtualunlimited.com>
+Author: Bob Deblier <bob.deblier@pandora.be>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
-Welcome to version 2.2.0 of BeeCrypt:
+Welcome to version 3.0.0 of BeeCrypt:
AES support has been added, and the library has been thoroughly debugged,
with the addition of unit tests. Once you've built the library, you can
verify the correct functioning with 'make check'.
+Multi-precision integer routines should now perform dramatically better
+an 64-bit processors, especially Alpha and Itanium.
+
+Benchmarks can be obtained with 'make bench'.
+
As usual, your comments are welcome.
- DHAES encryption scheme
Planned for the near future are:
- - mp64 library for operation on 64-bit computers (and possibly also
- on certain 32-bit platforms)
- compliance with and compliance statements for IEEE P1363
- more blockciphers (Twofish, ... )
- more hash functions (RIPEMD-160, SHA-384, SHA-512, HAVAL, Tiger)
- more blockcipher modes (OFB, ... )
The library has been tested on the following platforms:
+ - AIX 5.1 ppc
+ - AIX 5.1 ppc64
- FreeBSD 4.0 alpha
- FreeBSD 4.0, 4.2 x86
- - includes assembler optimization (tuned for Pentium and higher)
- Linux glibc 2.x alpha
- Linux glibc 2.x arm
- - includes assembler optimization
+ - Linux glibc 2.x ia64
- Linux glibc 2.x ppc
- - includes assembler optimization for 32-bit PowerPC
- - Linux glibc 2.x sparc
- - includes assembler optimization for Sparc v8
+ - Linux glibc 2.x sparc
- Linux glibc 2.x x86
- - includes assembler optimization (tuned for Pentium and higher)
- - Solaris 2.6/2.7/2.8 sparc (with Forte or gnu compilers)
- - includes assembler optimization for Sparc v8, v8plus and v9
- - Solaris 2.7/2.8 x86 (with Forte or gnu compilers)
- - includes assembler optimization (tuned for Pentium and higher)
+ - Solaris 2.6/2.7/2.8/2.9 sparc (with Forte or gnu compilers)
+ - Solaris 2.7/2.8 x86 (with Forte or GNU compilers)
- Tru64 Unix alpha
- - Win32 (Windows 95, 98, NT 4.0, 2000)
- - includes assembler optimization (tuned for Pentium and higher)
+ - Win32 (Windows 95, 98, NT 4.0, 2000, XP)
The library is currently in the process of being ported to:
- Darwin (apparently Apple has decided to change the PPC assembler format;
this will need a fix)
- - Cygwin (Can't seem to get the DLL to build properly with the current version of the autotools)
+ - Cygwin (Can't seem to get the DLL to build properly with the current
+ version of the autotools)
+ - HP/UX is a pain in the backside; I'll try getting it working, but the
+ configure script doesn't seem capable of properly detecting gettimeofday.
For more information, refer to the HTML documentation in the docs directory.
http://beecrypt.virtualunlimited.com/
-or contact me at mailto:beecrypt@virtualunlimited.com
+or contact me at mailto:bob.deblier@pandora.be
Sincerely,
/*!\file base64.c
* \brief Base64 encoding and decoding.
- * \author Bob Deblier <bob@virtualunlimited.com>
+ * \author Bob Deblier <bob.deblier@pandora.be>
*/
#include "system.h"
#include "base64.h"
-#include "endianness.h" /* XXX swapu32 for crc */
+#include "endianness.h"
#include "debug.h"
/*@unchecked@*/
@INCLUDE_STDINT_H@
@INCLUDE_SYNCH_H@
@INCLUDE_PTHREAD_H@
+@INCLUDE_STDLIB_H@
+@INCLUDE_MALLOC_H@
+@INCLUDE_STRING_H@
@TYPEDEF_BC_LOCK_T@
#endif
#if defined(_MSC_VER) || __MWERKS__
+#include <stdlib.h>
+#include <string.h>
+
#define HAVE_ERRNO_H 1
-#define HAVE_STRING_H 1
-#define HAVE_STDLIB_H 1
#define HAVE_CTYPE_H 1
#define HAVE_FCNTL_H 1
#define HAVE_TIME_H 1
#endif
#if __MWERKS__
-#define HAVE_UNISTD_H 1
-#define HAVE_MALLOC_H 1
-
#define HAVE_SYS_STAT_H 0
#define HAVE_LONG_LONG 1
typedef unsigned long long uint64_t;
#elif defined(_MSC_VER)
-#define HAVE_UNISTD_H 0
-#define HAVE_MALLOC_H 1
-
#define HAVE_SYS_STAT_H 1
#define HAVE_LONG_LONG 0
}
#endif
+int blowfishBlowit(blowfishParam* bp, uint32_t* dst, const uint32_t* src)
+{
+ register uint32_t xl = src[0], xr = src[1];
+ register uint32_t* p = bp->p;
+ register uint32_t* s = bp->s;
+
+ EROUND(xl, xr); EROUND(xr, xl);
+
+ dst[1] = xr;
+ dst[0] = xl;
+
+ return 0;
+}
+
#ifndef ASM_BLOWFISHENCRYPT
int blowfishEncrypt(blowfishParam* bp, uint32_t* dst, const uint32_t* src)
{
fi
],[ac_with_mtmalloc=no])
-AC_ARG_WITH(java,[ --with-java creates the java glue code [default=no]],[
+AC_ARG_WITH(java,[ --with-java creates the java glue code [default=no]],[
if test "$withval" = no; then
ac_with_java=no
else
AC_CHECK_HEADERS([ctype.h errno.h fcntl.h malloc.h termio.h termios.h])
AC_CHECK_HEADERS([sys/ioctl sys/audioio.h sys/soundcard.h])
-if test "$ac_enable_threads" = yes; then
- AC_CHECK_HEADERS([thread.h pthread.h synch.h semaphore.h])
+bc_include_stdlib_h=
+bc_include_malloc_h=
+bc_include_string_h=
+if test "$ac_cv_header_stdlib_h" = yes; then
+ bc_include_stdlib_h="#include <stdlib.h>"
+elif test "$ac_cv_header_malloc_h" = yes; then
+ bc_include_malloc_h="#include <malloc.h>"
fi
-
if test "$ac_with_mtmalloc" = yes; then
AC_CHECK_HEADERS(mtmalloc.h)
+ if test "$ac_cv_header_mtmalloc_h" = yes; then
+ bc_include_stdlib_h=
+ bc_include_malloc_h="#include <mtmalloc.h>"
+ fi
+fi
+if test "$ac_cv_header_string_h" = yes; then
+ bc_include_string_h="#include <string.h>"
+fi
+AC_SUBST(INCLUDE_STDLIB_H,$bc_include_stdlib_h)
+AC_SUBST(INCLUDE_MALLOC_H,$bc_include_malloc_h)
+AC_SUBST(INCLUDE_STRING_H,$bc_include_string_h)
+
+if test "$ac_enable_threads" = yes; then
+ AC_CHECK_HEADERS([thread.h pthread.h synch.h semaphore.h])
fi
# Checks for libraries.
AC_MSG_WARN([Don't know which thread library to check for])
fi
fi
-AC_SUBST(INCLUDE_SYNCH_H, $bc_include_synch_h)
-AC_SUBST(INCLUDE_PTHREAD_H, $bc_include_pthread_h)
-AC_SUBST(TYPEDEF_BC_LOCK_T, $bc_typedef_bc_lock_t)
+AC_SUBST(INCLUDE_SYNCH_H,$bc_include_synch_h)
+AC_SUBST(INCLUDE_PTHREAD_H,$bc_include_pthread_h)
+AC_SUBST(TYPEDEF_BC_LOCK_T,$bc_typedef_bc_lock_t)
if test "$ac_enable_aio" = yes; then
BEECRYPT_WORKING_AIO
ac_cv_java_include="$ac_cv_java_include -I$gcjpath/include"
fi
else
- AC_MSG_WARN([java headers not found, disabling java])
+ AC_MSG_WARN([java headers not found, disabling java glue])
ac_cv_java_headers=no
ac_cv_java_include=
ac_with_java=no
rm -fr conftest*
])
else
- AC_CHECK_PROG(ac_cv_have_java, java, yes, no)
- if test "$ac_cv_have_java" = yes; then
- AC_CHECK_PROG(ac_cv_have_javac, javac, yes, no)
- if test "$ac_cv_have_javac" = yes; then
- AC_CACHE_CHECK([for java native interface headers],ac_cv_java_include,[
- cat > conftest.java << EOF
+ AC_CHECK_PROG(ac_cv_have_java, java, yes, no)
+ if test "$ac_cv_have_java" = yes; then
+ AC_CHECK_PROG(ac_cv_have_javac, javac, yes, no)
+ if test "$ac_cv_have_javac" = yes; then
+ AC_CACHE_CHECK([for java native interface headers],ac_cv_java_include,[
+ cat > conftest.java << EOF
public class conftest
{
public static void main(String[[]] argv)
}
}
EOF
- java_home=`javac conftest.java; java -classpath . conftest`
- case $target_os in
- cygwin*)
- java_home=`cygpath -u -p "$java_home"` ;;
- esac
- if test -d "$java_home"; then
+ java_home=`javac conftest.java; java -classpath . conftest`
case $target_os in
- darwin*)
- java_include="$java_home/../../../Headers" ;;
- *)
- java_include="$java_home"/../include ;;
+ cygwin*)
+ java_home=`cygpath -u -p "$java_home"` ;;
esac
- if test -d "$java_include"; then
- ac_cv_java_headers=yes
+ if test -d "$java_home"; then
+ case $target_os in
+ darwin*)
+ java_include="$java_home/../../../Headers" ;;
+ *)
+ java_include="$java_home"/../include ;;
+ esac
+ if test -d "$java_include"; then
+ ac_cv_java_headers=yes
ac_cv_java_include="-I$java_include"
case $target_os in
aix*)
AC_MSG_WARN([please add appropriate -I$java_include/<operating system> flag])
ac_cv_java_include="-I$java_include" ;;
esac
- else
- AC_MSG_WARN([java headers not found, disabling java])
- ac_cv_java_headers=no
+ else
+ AC_MSG_WARN([java headers not found, disabling java])
+ ac_cv_java_headers=no
ac_cv_java_include=
- ac_with_java=no
+ ac_with_java=no
+ fi
fi
- fi
- rm -fr conftest*
- ])
- else
- AC_MSG_WARN([javac not found, disabling java])
- ac_cv_java_headers=no
+ rm -fr conftest*
+ ])
+ else
+ AC_MSG_WARN([javac not found, disabling java])
+ ac_cv_java_headers=no
ac_cv_java_include=
ac_with_java=no
+ fi
+ else
+ AC_MSG_WARN([java not found, disabling java])
+ ac_cv_java_headers=no
+ ac_with_java=no
fi
- else
- AC_MSG_WARN([java not found, disabling java])
- ac_cv_java_headers=no
- ac_with_java=no
fi
fi
-fi
if test "$ac_with_java" = yes ; then
AC_DEFINE([JAVAGLUE],1)
BEECRYPT_ASM_ALIGN
fi
- # generate assembler source files from m4 files
- BEECRYPT_ASM_SOURCES
+# generate assembler source files from m4 files
+BEECRYPT_ASM_SOURCES
# Check for standard types and integers of specific sizes
BEECRYPT_INT_TYPES
* \brief Endian-dependant encoding/decoding.
* \author Bob Deblier <bob.deblier@pandora.be>
*/
-
+
#include "system.h"
#include "endianness.h"
#include "debug.h"
-/*@-bitwisesigned -shiftimplementation@*/
int16_t swap16(int16_t n)
{
return ( ((n & 0xff) << 8) |
((n & ((int64_t) 0xff) << 48) >> 40) |
((n & ((int64_t) 0xff) << 56) >> 56) );
}
-/*@=bitwisesigned =shiftimplementation@*/
ifelse(substr(ASM_OS,0,5),linux,`
define(USE_SIZE_DIRECTIVE,yes)
+define(USE_TYPE_DIRECTIVE,yes)
')
define(SYMNAME,`GSYM_PREFIX`$1'')
define(LOCAL,`LSYM_PREFIX`$1'')
-ifdef(ALIGN,,`
-define(ALIGN)
-')
+ifdef(`ALIGN',,`define(`ALIGN',`')')
+ifelse(USE_TYPE_DIRECTIVE,yes,`
+ifelse(SUBSTR(ASM_ARCH,0,3),arm,`
+define(FUNCTION_TYPE,`function')
+',`
+ifelse(SUBSTR(ASM_ARCH,0,5),sparc,`
+define(FUNCTION_TYPE,`#function')
+',`
+define(FUNCTION_TYPE,`@function')
+')
+')
define(C_FUNCTION_BEGIN,`
TEXTSEG
ALIGN
GLOBL SYMNAME($1)
+ .type SYMNAME($1),FUNCTION_TYPE
SYMNAME($1):
')
+',`
+define(C_FUNCTION_BEGIN,`
+ TEXTSEG
+ ALIGN
+ GLOBL SYMNAME($1)
+SYMNAME($1):
+')
+')
ifelse(USE_SIZE_DIRECTIVE,yes,`
define(C_FUNCTION_END,`
.file "mpopt.s"
include(config.m4)
-include(ARM_SRCDIR/x86_64.m4)
+include(ASM_SRCDIR/x86_64.m4)
C_FUNCTION_BEGIN(mpzero)
--- /dev/null
+.deps
+.libs
+Makefile
+Makefile.in
+*.lo
* "Handbook of Applied Cryptography", Chapter 14.3.3
* Menezes, van Oorschot, Vanstone
* CRC Press
- * \author Bob Deblier <bob@virtualunlimited.com>
+ * \author Bob Deblier <bob.deblier@pandora.be>
* \ingroup MP__m
*/
INCLUDES = -I$(top_srcdir)
LDADD = $(top_builddir)/libbeecrypt.la
-TESTS = testmd5 testsha1 testsha256 testhmacmd5 testhmacsha1 testaes testblowfish testmp testmpinv testrsa testdldp
+TESTS = testmd5 testsha1 testsha256 testhmacmd5 testhmacsha1 testaes testblowfish testmp testmpinv testdsa testrsa testdldp
-check_PROGRAMS = testmd5 testsha1 testsha256 testhmacmd5 testhmacsha1 testaes testblowfish testmp testmpinv testrsa testdldp
+check_PROGRAMS = testmd5 testsha1 testsha256 testhmacmd5 testhmacsha1 testaes testblowfish testmp testmpinv testdsa testrsa testdldp
testmd5_SOURCES = testmd5.c
testmpinv_SOURCES = testmpinv.c
+testdsa_SOURCES = testdsa.c
+
testrsa_SOURCES = testrsa.c
testdldp_SOURCES = testdldp.c
static const char* expect_r = "8bac1ab66410435cb7181f95b16ab97c92b341c0";
static const char* expect_s = "41e2345f1f56df2458f426d155b4ba2db6dcd8c8";
-/* we need to fake a random generator to pass k into the signing algorithm */
-
-int fake_setup(randomGeneratorParam* p)
-{
- return 0;
-}
-
-int fake_seed(randomGeneratorParam* p, const byte* data, size_t size)
-{
- return 0;
-}
-
-int fake_next(randomGeneratorParam* p, byte* data, size_t size)
-{
- mpnumber tmp;
-
- mpnzero(&tmp);
- mpnsethex(&tmp, dsa_k);
-
- memcpy(data, tmp.data, size);
-
- mpnfree(&tmp);
-
- return 0;
-}
-
-int fake_cleanup(randomGeneratorParam* p)
-{
- return 0;
-}
-
-const randomGenerator fakeprng = { "fake", 4, fake_setup, fake_seed, fake_next, fake_cleanup };
-
int main()
{
int failures = 0;
dlkp_p keypair;
- mpnumber hm, r, s, e_r, e_s;
- randomGeneratorContext rngc;
+ mpnumber hm, r, s, k, e_r, e_s;
dlkp_pInit(&keypair);
mpnzero(&e_r);
mpnzero(&e_s);
+
mpnsethex(&e_r, expect_r);
mpnsethex(&e_s, expect_s);
mpnzero(&hm);
mpnsethex(&hm, dsa_hm);
- /* first test, from NIST FIPS 186-1 */
mpnzero(&r);
mpnzero(&s);
- if (randomGeneratorContextInit(&rngc, &fakeprng))
- return -1;
-
- if (dsasign(&keypair.param.p, &keypair.param.q, &keypair.param.g, &rngc, &hm, &keypair.x, &r, &s))
- return -1;
-
- if (mpnex(e_r.size, e_r.data, r.size, r.data) || mpnex(e_s.size, e_s.data, s.size, s.data))
- {
- printf("failed test vector 1\n");
- failures++;
- }
- else
- printf("ok\n");
-
- if (randomGeneratorContextFree(&rngc))
- return -1;
-
- mpnfree(&s);
- mpnfree(&r);
-
- /* second test, sign a hash and verify the signature */
- mpnzero(&s);
- mpnzero(&r);
-
- if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()))
- return -1;
-
- if (dsasign(&keypair.param.p, &keypair.param.q, &keypair.param.g, &rngc, &hm, &keypair.x, &r, &s))
- return -1;
-
- if (!dsavrfy(&keypair.param.p, &keypair.param.q, &keypair.param.g, &hm, &keypair.y, &r, &s))
- {
- printf("failed test vector 2\n");
+ /* first test, verify the signature result from NIST FIPS 186-1 */
+ if (!dsavrfy(&keypair.param.p, &keypair.param.q, &keypair.param.g, &hm, &keypair.y, &e_r, &e_s))
failures++;
- }
- else
- printf("ok\n");
- if (randomGeneratorContextFree(&rngc))
- return -1;
-
mpnfree(&s);
mpnfree(&r);