Page MenuHome GnuPG

No OneTemporary

diff --git a/INSTALL b/INSTALL
index bf72ad4d..c5242221 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,26 +1,183 @@
-
- 1) Configure for your machine:
-
- ./configure
-
- or use
-
- ./configure --enable-m-debug
-
- to enable the integrated malloc debugging stuff.
-
-
- 2) Run make:
-
- make
-
-
- 3) Install
-
- make install
-
-
- 4) You end up with a binary "g10" in /usr/local/bin
-
-
+Basic Installation
+==================
+
+ These are generic installation instructions.
+
+ The `configure' shell script attempts to guess correct values for
+various system-dependent variables used during compilation. It uses
+those values to create a `Makefile' in each directory of the package.
+It may also create one or more `.h' files containing system-dependent
+definitions. Finally, it creates a shell script `config.status' that
+you can run in the future to recreate the current configuration, a file
+`config.cache' that saves the results of its tests to speed up
+reconfiguring, and a file `config.log' containing compiler output
+(useful mainly for debugging `configure').
+
+ If you need to do unusual things to compile the package, please try
+to figure out how `configure' could check whether to do them, and mail
+diffs or instructions to the address given in the `README' so they can
+be considered for the next release. If at some point `config.cache'
+contains results you don't want to keep, you may remove or edit it.
+
+ The file `configure.in' is used to create `configure' by a program
+called `autoconf'. You only need `configure.in' if you want to change
+it or regenerate `configure' using a newer version of `autoconf'.
+
+The simplest way to compile this package is:
+
+ 1. `cd' to the directory containing the package's source code and type
+ `./configure' to configure the package for your system. If you're
+ using `csh' on an old version of System V, you might need to type
+ `sh ./configure' instead to prevent `csh' from trying to execute
+ `configure' itself.
+
+ Running `configure' takes awhile. While running, it prints some
+ messages telling which features it is checking for.
+
+ 2. Type `make' to compile the package.
+
+ 3. Optionally, type `make check' to run any self-tests that come with
+ the package.
+
+ 4. Type `make install' to install the programs and any data files and
+ documentation.
+
+ 5. You can remove the program binaries and object files from the
+ source code directory by typing `make clean'. To also remove the
+ files that `configure' created (so you can compile the package for
+ a different kind of computer), type `make distclean'. There is
+ also a `make maintainer-clean' target, but that is intended mainly
+ for the package's developers. If you use it, you may have to get
+ all sorts of other programs in order to regenerate files that came
+ with the distribution.
+
+Compilers and Options
+=====================
+
+ Some systems require unusual options for compilation or linking that
+the `configure' script does not know about. You can give `configure'
+initial values for variables by setting them in the environment. Using
+a Bourne-compatible shell, you can do that on the command line like
+this:
+ CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
+
+Or on systems that have the `env' program, you can do it like this:
+ env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
+
+Compiling For Multiple Architectures
+====================================
+
+ You can compile the package for more than one kind of computer at the
+same time, by placing the object files for each architecture in their
+own directory. To do this, you must use a version of `make' that
+supports the `VPATH' variable, such as GNU `make'. `cd' to the
+directory where you want the object files and executables to go and run
+the `configure' script. `configure' automatically checks for the
+source code in the directory that `configure' is in and in `..'.
+
+ If you have to use a `make' that does not supports the `VPATH'
+variable, you have to compile the package for one architecture at a time
+in the source code directory. After you have installed the package for
+one architecture, use `make distclean' before reconfiguring for another
+architecture.
+
+Installation Names
+==================
+
+ By default, `make install' will install the package's files in
+`/usr/local/bin', `/usr/local/man', etc. You can specify an
+installation prefix other than `/usr/local' by giving `configure' the
+option `--prefix=PATH'.
+
+ You can specify separate installation prefixes for
+architecture-specific files and architecture-independent files. If you
+give `configure' the option `--exec-prefix=PATH', the package will use
+PATH as the prefix for installing programs and libraries.
+Documentation and other data files will still use the regular prefix.
+
+ In addition, if you use an unusual directory layout you can give
+options like `--bindir=PATH' to specify different values for particular
+kinds of files. Run `configure --help' for a list of the directories
+you can set and what kinds of files go in them.
+
+ If the package supports it, you can cause programs to be installed
+with an extra prefix or suffix on their names by giving `configure' the
+option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
+
+Optional Features
+=================
+
+ Some packages pay attention to `--enable-FEATURE' options to
+`configure', where FEATURE indicates an optional part of the package.
+They may also pay attention to `--with-PACKAGE' options, where PACKAGE
+is something like `gnu-as' or `x' (for the X Window System). The
+`README' should mention any `--enable-' and `--with-' options that the
+package recognizes.
+
+ For packages that use the X Window System, `configure' can usually
+find the X include and library files automatically, but if it doesn't,
+you can use the `configure' options `--x-includes=DIR' and
+`--x-libraries=DIR' to specify their locations.
+
+Specifying the System Type
+==========================
+
+ There may be some features `configure' can not figure out
+automatically, but needs to determine by the type of host the package
+will run on. Usually `configure' can figure that out, but if it prints
+a message saying it can not guess the host type, give it the
+`--host=TYPE' option. TYPE can either be a short name for the system
+type, such as `sun4', or a canonical name with three fields:
+ CPU-COMPANY-SYSTEM
+
+See the file `config.sub' for the possible values of each field. If
+`config.sub' isn't included in this package, then this package doesn't
+need to know the host type.
+
+ If you are building compiler tools for cross-compiling, you can also
+use the `--target=TYPE' option to select the type of system they will
+produce code for and the `--build=TYPE' option to select the type of
+system on which you are compiling the package.
+
+Sharing Defaults
+================
+
+ If you want to set default values for `configure' scripts to share,
+you can create a site shell script called `config.site' that gives
+default values for variables like `CC', `cache_file', and `prefix'.
+`configure' looks for `PREFIX/share/config.site' if it exists, then
+`PREFIX/etc/config.site' if it exists. Or, you can set the
+`CONFIG_SITE' environment variable to the location of the site script.
+A warning: not all `configure' scripts look for a site script.
+
+Operation Controls
+==================
+
+ `configure' recognizes the following options to control how it
+operates.
+
+`--cache-file=FILE'
+ Use and save the results of the tests in FILE instead of
+ `./config.cache'. Set FILE to `/dev/null' to disable caching, for
+ debugging `configure'.
+
+`--help'
+ Print a summary of the options to `configure', and exit.
+
+`--quiet'
+`--silent'
+`-q'
+ Do not print messages saying which checks are being made. To
+ suppress all normal output, redirect it to `/dev/null' (any error
+ messages will still be shown).
+
+`--srcdir=DIR'
+ Look for the package's source code in directory DIR. Usually
+ `configure' can determine that directory automatically.
+
+`--version'
+ Print the version of Autoconf used to generate the `configure'
+ script, and exit.
+
+`configure' also accepts some other, not widely useful, options.
diff --git a/README b/README
index 18301898..55be1b29 100644
--- a/README
+++ b/README
@@ -1,214 +1,232 @@
G10 - The GNU Encryption and Signing Tool
------------------------------------------
THIS IS VERSION IS ONLY A TEST VERSION ! YOU SHOULD NOT
USE IT FOR OTHER PURPOSES THAN EVALUATING THE CURRENT CODE.
* The data format may change in the next version!
* Some features are not yet implemented
I provide this version as a reality check to start discussion.
Please subscribe to g10@net.lut.ac.uk by sending a mail with
the word "subscribe" in the body to "g10-request@net.lut.ac.uk".
See the file COPYING for copyright and warranty information.
Due to the fact that G10 does not use use any patented algorithm,
it cannot be compatible to old PGP versions, because those use
IDEA (which is worldwide patented) and RSA (which is patented in
the United States until Sep 20, 2000). I'm sorry about this, but
this is the world we have created (e.g. by using proprietary software).
Because the OpenPGP standard is still a draft, G10 is not yet
compatible to it (or PGP 5) - but it will. The data structures
used are compatible with PGP 2.x, so it can parse an list such files
and PGP should be able to parse data created by G10 and complain
about unsupported algorithms.
The default algorithms used by G10 are ElGamal for public-key
encryption and signing; Blowfish with a 160 bit key for protecting
the secret-key components, conventional and session encryption;
RIPE MD-160 to create message digest. DSA, SHA-1 and CAST are
also implemented, but not used on default. I decided not
to use DSA as default signing algorithm, because it allows only for
1024 bit keys and this may be not enough in a couple of years.
+ Installation
+ ------------
+
+ 1) "./configure"
+
+ to enable the integrated malloc debugging stuff, use:
+
+ "./configure --enable-m-debug"
+
+ 2) "make"
+
+ 3) "make install"
+
+ 4) You end up with a binary "g10" in /usr/local/bin
+
+
+
+
Resources
---------
G10 needs a directory "~/.g10" to store the default keyrings
and other files.
Key Generation
--------------
g10 --gen-key
This asks some questions and then starts key generation. To create
good random numbers for prime number generation, it uses a /dev/random
which will emit only bytes if the kernel can gather enough entropy.
If you see no progress, you should start some other activities such
as mouse moves or a "find /". Because we have no hardware device
to generate random we have to use this method.
Key generation shows progress by printing different characters to
stderr:
"." Miller-Rabin test failed.
"+" Miller-Rabin test succeeded.
"!" Reloading the pool with fresh prime numbers
"^" Checking a new value for the generator
"~" Issued during generator checks
"<" Size of one factor decreased
">" Size of one factor increased
The prime number for ElGamal is generated this way:
1) Make a prime number q of 160, 200, 240 bits (depending on the keysize).
2) Select the length of the other prime factors to be at least the size
of q and calculate the number of prime factors needed
3) Make a pool of prime number, each of the length determined in step 2
4) Get a new permutation out of the pool or continue with step 3
if we have tested all permutations.
5) Calculate a candidate prime p = 2 * q * p[1] * ... * p[n] + 1
6) Check that this prime has the correct length (this may change q if
it seems not to be possible to make a prime of the desired length)
7) Check whether this is a prime using trial divisions and the
Miller-Rabin test.
8) Continue with step 4 if we did not find a prime in step 7.
9) Find a generator for that prime.
You can sign a key with this command:
g10 --sign-key Donald
To sign the key of of "Donald" with your default userid
g10 --sign-key -u Karl -u Joe Donald
To sign the key of of "Donald" with the userids of "Karl" and "Joe".
All existing signatures are checked, if some are invalid, a menu is
offered to delete some of them, and the you are asked for every user
wether you want to sign this key.
You may remove a signature at any time by usiing the option "--edit-sig",
which also asks for the sigs to remove.
Sign
----
g10 -s file
This creates a file file.g10 which is compressed and has a signature
attached.
g10 -sa file
Same as above, but file.g10 is ascii armored.
g10 -s -o out file
Creates a signature of file, but writes the output to the file "out".
Encrypt
-------
g10 -e -r heine file
This encrypts files with the public key of "heine" and writes it
to "file.g10"
echo "hallo" | g10 -ea -r heine | mail heine
Ditto, but encrypts "hallo\n" and mails it as ascii armored message.
Sign and Encrypt
----------------
g10 -se -r heine file
This encrypts files with the public key of "heine" and writes it
to "file.g10" after signing it with the default user id.
g10 -se -r heine -u Suttner file
Ditto, but sign the file with the user id "Suttner"
Examine a data or key file
--------------------------
g10 --list-packets datafile
Use this to list the contents of a data file. If the file is encrypted
you are asked for the passphrase, so that G10 is able to look at the
inner structure of a encrypted packet.
Batch mode
----------
If you use the option "--batch", G10 runs in non-interactive mode and
never prompts for input data. This even does not allow to enter
passphrase; until we have a better solution (something like ssh-agent),
you can use the option "--passhrase-fd n", which works like PGPs
PGPPASSFD.
Batch mode also causes PGP to terminate as soon as a BAD signature is
detected.
Exit status
-----------
G10 returns with an exit status of 1 if in batch mode and a bad signature
has been detected or 2 or higher for all other errors. You should parse
stderr to get detailed informations about the errors.
Debug Flags
-----------
Use the option "--debug n" to output debug informations. This option
can be used multiple times, all values are ORed; n maybe prefixed with
0x to use hex-values.
value used for
----- ----------------------------------------------
1 packet reading/writing
2 MPI details
4 ciphers and primes (may reveal sensitive data)
8 iobuf filter functions
16 iobuf stuff
32 memory allocation stuff
64 caching
128 show memory statistics at exit
Other Notes
-----------
This is work in progress, so you may find duplicated code fragments,
ugly data structures, weird usage of filenames and other thinks.
I will run "indent" over the source when making a real distribution,
but for now I stick to my own formatting rules.
The primary FTP site is "ftp://ftp.guug.de/pub/gcrypt/"
The primary WWW page is "http://www.d.shuttle.de/isil/g10.html"
Please direct bug reports to <g10-bugs@isil.d.shuttle.de> or better
post them to the mailing list <g10@net.lut.ac.uk>.
diff --git a/cipher/Makefile.am b/cipher/Makefile.am
index 0855d7da..ecd91a73 100644
--- a/cipher/Makefile.am
+++ b/cipher/Makefile.am
@@ -1,31 +1,32 @@
## Process this file with automake to produce Makefile.in
INCLUDES = -I$(top_srcdir)/include
EXTRA_DIST = @CIPHER_EXTRA_DIST@
noinst_LIBRARIES = cipher
cipher_SOURCES = blowfish.c \
blowfish.h \
elgamal.c \
elgamal.h \
gost.c \
gost.h \
md5.c \
md5.h \
primegen.c \
random.c \
rmd.h \
rmd160.c \
sha1.h \
sha1.c \
dsa.h \
dsa.c \
md.c \
+ md.h \
misc.c \
smallprime.c
cipher_LIBADD = @CIPHER_EXTRA_OBJS@
diff --git a/cipher/Makefile.in b/cipher/Makefile.in
index 7bd7691f..221efdd2 100644
--- a/cipher/Makefile.in
+++ b/cipher/Makefile.in
@@ -1,267 +1,268 @@
# Makefile.in generated automatically by automake 1.0 from Makefile.am
# Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy, distribute and modify it.
SHELL = /bin/sh
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ..
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@
INCLUDES = -I$(top_srcdir)/include
EXTRA_DIST = @CIPHER_EXTRA_DIST@
noinst_LIBRARIES = cipher
cipher_SOURCES = blowfish.c \
blowfish.h \
elgamal.c \
elgamal.h \
gost.c \
gost.h \
md5.c \
md5.h \
primegen.c \
random.c \
rmd.h \
rmd160.c \
sha1.h \
sha1.c \
dsa.h \
dsa.c \
md.c \
+ md.h \
misc.c \
smallprime.c
cipher_LIBADD = @CIPHER_EXTRA_OBJS@
mkinstalldirs = $(top_srcdir)/scripts/mkinstalldirs
CONFIG_HEADER = ../config.h
LIBRARIES = $(noinst_LIBRARIES)
noinst_LIBFILES = libcipher.a
CC = @CC@
LEX = @LEX@
YACC = @YACC@
DEFS = @DEFS@ -I. -I$(srcdir) -I..
CPPFLAGS = @CPPFLAGS@
CFLAGS = @CFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
COMPILE = $(CC) -c $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
LINK = $(CC) $(LDFLAGS) -o $@
cipher_OBJECTS = blowfish.o elgamal.o gost.o md5.o primegen.o random.o \
rmd160.o sha1.o dsa.o md.o misc.o smallprime.o
EXTRA_cipher_SOURCES =
LIBFILES = libcipher.a
AR = ar
RANLIB = @RANLIB@
DIST_COMMON = Makefile.am Makefile.in
PACKAGE = @PACKAGE@
VERSION = @VERSION@
DISTFILES = $(DIST_COMMON) $(SOURCES) $(BUILT_SOURCES) $(HEADERS) \
$(TEXINFOS) $(INFOS) $(MANS) $(EXTRA_DIST) $(DATA)
DEP_DISTFILES = $(DIST_COMMON) $(SOURCES) $(BUILT_SOURCES) $(HEADERS) \
$(TEXINFOS) $(INFO_DEPS) $(MANS) $(EXTRA_DIST) $(DATA)
TAR = tar
DEP_FILES = $(srcdir)/.deps/blowfish.P $(srcdir)/.deps/dsa.P \
$(srcdir)/.deps/elgamal.P $(srcdir)/.deps/gost.P $(srcdir)/.deps/md.P \
$(srcdir)/.deps/md5.P $(srcdir)/.deps/misc.P $(srcdir)/.deps/primegen.P \
$(srcdir)/.deps/random.P $(srcdir)/.deps/rmd160.P \
$(srcdir)/.deps/sha1.P $(srcdir)/.deps/smallprime.P
SOURCES = $(cipher_SOURCES)
OBJECTS = $(cipher_OBJECTS)
default: all
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in
cd $(top_srcdir) && automake $(subdir)/Makefile
Makefile: $(top_builddir)/config.status Makefile.in
cd $(top_builddir) && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= ./config.status
mostlyclean-noinstLIBRARIES:
clean-noinstLIBRARIES:
rm -f $(noinst_LIBFILES)
distclean-noinstLIBRARIES:
maintainer-clean-noinstLIBRARIES:
.c.o:
$(COMPILE) $<
mostlyclean-compile:
rm -f *.o core
clean-compile:
distclean-compile:
rm -f *.tab.c
maintainer-clean-compile:
$(cipher_OBJECTS): ../config.h
libcipher.a: $(cipher_OBJECTS) $(cipher_LIBADD)
rm -f libcipher.a
$(AR) cru libcipher.a $(cipher_OBJECTS) $(cipher_LIBADD)
$(RANLIB) libcipher.a
ID: $(HEADERS) $(SOURCES)
here=`pwd` && cd $(srcdir) && mkid -f$$here/ID $(SOURCES) $(HEADERS)
tags: TAGS
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES)
here=`pwd` && cd $(srcdir) && etags $(ETAGS_ARGS) $(SOURCES) $(HEADERS) -o $$here/TAGS
mostlyclean-tags:
clean-tags:
distclean-tags:
rm -f TAGS ID
maintainer-clean-tags:
subdir = cipher
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
distdir: $(DEP_DISTFILES)
@for file in `cd $(srcdir) && echo $(DISTFILES)`; do \
test -f $(distdir)/$$file \
|| ln $(srcdir)/$$file $(distdir)/$$file 2> /dev/null \
|| cp -p $(srcdir)/$$file $(distdir)/$$file; \
done
# This fragment is probably only useful for maintainers. It relies on
# GNU make and gcc. It is only included in the generated Makefile.in
# if `automake' is not passed the `--include-deps' flag.
MKDEP = gcc -MM $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
-include $(srcdir)/.deps/.P
$(srcdir)/.deps/.P: $(BUILT_SOURCES)
cd $(srcdir) && test -d .deps || mkdir .deps
echo > $@
-include $(DEP_FILES)
$(DEP_FILES): $(srcdir)/.deps/.P
$(srcdir)/.deps/%.P: $(srcdir)/%.c
@echo "mkdeps $< > $@"
@re=`echo 's,^$(srcdir)//*,,g;s, $(srcdir)//*, ,g' | sed 's,\.,\\\\.,g'`; \
$(MKDEP) $< | sed "$$re" > $@-tmp
@if test -n "$o"; then \
sed 's/\.o:/$$o:/' $@-tmp > $@; \
rm $@-tmp; \
else \
mv $@-tmp $@; \
fi
# End of maintainer-only section
info:
dvi:
check: all
installcheck:
install-exec:
install-data:
install: install-exec install-data all
@:
uninstall:
all: $(LIBFILES) Makefile
install-strip:
$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install
installdirs:
mostlyclean-generic:
test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES)
clean-generic:
test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
distclean-generic:
rm -f Makefile $(DISTCLEANFILES)
rm -f config.cache config.log $(CONFIG_HEADER) stamp-h
maintainer-clean-generic:
test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES)
test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES)
mostlyclean: mostlyclean-noinstLIBRARIES mostlyclean-compile \
mostlyclean-tags mostlyclean-generic
clean: clean-noinstLIBRARIES clean-compile clean-tags clean-generic \
mostlyclean
distclean: distclean-noinstLIBRARIES distclean-compile distclean-tags \
distclean-generic clean
rm -f config.status
maintainer-clean: maintainer-clean-noinstLIBRARIES \
maintainer-clean-compile maintainer-clean-tags \
maintainer-clean-generic distclean
@echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
.PHONY: default mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \
clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \
mostlyclean-compile distclean-compile clean-compile \
maintainer-clean-compile tags mostlyclean-tags distclean-tags \
clean-tags maintainer-clean-tags distdir info dvi check installcheck \
install-exec install-data install uninstall all installdirs \
mostlyclean-generic distclean-generic clean-generic \
maintainer-clean-generic clean mostlyclean distclean maintainer-clean
.SUFFIXES:
.SUFFIXES: .c .o
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
diff --git a/cipher/md.c b/cipher/md.c
index 67f5356a..e88a45c7 100644
--- a/cipher/md.c
+++ b/cipher/md.c
@@ -1,172 +1,161 @@
/* md.c - message digest dispatcher
* Copyright (c) 1997 by Werner Koch (dd9jn)
*
* This file is part of G10.
*
* G10 is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* G10 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include "util.h"
#include "cipher.h"
#include "errors.h"
-int
-md_okay( int algo )
-{
- return check_digest_algo( algo );
-}
-
-
-MD_HANDLE *
+/****************
+ * Open a message digest handle for use with algorithm ALGO.
+ * More algorithms may be added by md_enable(). The initial algorithm
+ * may be 0.
+ */
+MD_HANDLE
md_open( int algo, int secure )
{
- MD_HANDLE *hd;
-
- hd = m_alloc( sizeof *hd + 19 );
- hd->algo = algo;
- hd->datalen = 0;
- if( algo == DIGEST_ALGO_MD5 )
- hd->u.md5 = md5_open( secure );
- else if( algo == DIGEST_ALGO_RMD160 )
- hd->u.rmd= rmd160_open( secure );
- else if( algo == DIGEST_ALGO_SHA1 )
- hd->u.sha1 = sha1_open( secure );
- else
- return NULL;
+ MD_HANDLE hd;
+ hd = secure ? m_alloc_secure_clear( sizeof *hd )
+ : m_alloc_clear( sizeof *hd );
+ if( algo )
+ md_enable( hd, algo );
return hd;
}
-
-MD_HANDLE *
-md_copy( MD_HANDLE *a )
+void
+md_enable( MD_HANDLE h, int algo )
{
- MD_HANDLE *hd;
-
- hd = m_alloc( sizeof *hd + 19 );
- hd->algo = a->algo;
- hd->datalen = 0;
- if( a->algo == DIGEST_ALGO_MD5 )
- hd->u.md5 = md5_copy( a->u.md5 );
- else if( a->algo == DIGEST_ALGO_RMD160 )
- hd->u.rmd= rmd160_copy( a->u.rmd );
- else if( a->algo == DIGEST_ALGO_SHA1 )
- hd->u.sha1= sha1_copy( a->u.sha1 );
+ if( algo == DIGEST_ALGO_MD5 ) {
+ md5_init( &h->md5 );
+ h->use_md5 = 1;
+ }
+ else if( algo == DIGEST_ALGO_RMD160 ) {
+ rmd160_init( &h->rmd160 );
+ h->use_rmd160 = 1;
+ }
+ else if( algo == DIGEST_ALGO_SHA1 ) {
+ sha1_init( &h->sha1 );
+ h->use_sha1 = 1;
+ }
else
- log_bug(NULL);
- return hd;
+ log_bug("md_enable(%d)", algo );
}
-/* used for a BAD Kludge in rmd160.c, md5.c */
-MD_HANDLE *
-md_makecontainer( int algo )
+MD_HANDLE
+md_copy( MD_HANDLE a )
{
- MD_HANDLE *hd;
-
- hd = m_alloc( sizeof *hd + 19 );
- hd->algo = algo;
- hd->datalen = 0;
- if( algo == DIGEST_ALGO_MD5 )
- ;
- else if( algo == DIGEST_ALGO_RMD160 )
- ;
- else if( algo == DIGEST_ALGO_SHA1 )
- ;
- else
- log_bug(NULL);
- return hd;
+ MD_HANDLE b;
+
+ b = m_is_secure(a)? m_alloc_secure( sizeof *b )
+ : m_alloc( sizeof *b );
+ memcpy( b, a, sizeof *a );
+ return b;
}
+
void
-md_close(MD_HANDLE *a)
+md_close(MD_HANDLE a)
{
if( !a )
return;
- if( a->algo == DIGEST_ALGO_MD5 )
- md5_close( a->u.md5 );
- else if( a->algo == DIGEST_ALGO_RMD160 )
- rmd160_close( a->u.rmd );
- else if( a->algo == DIGEST_ALGO_SHA1 )
- sha1_close( a->u.sha1 );
- else
- log_bug(NULL);
m_free(a);
}
void
-md_write( MD_HANDLE *a, byte *inbuf, size_t inlen)
+md_write( MD_HANDLE a, byte *inbuf, size_t inlen)
{
- if( a->algo == DIGEST_ALGO_MD5 )
- md5_write( a->u.md5, inbuf, inlen );
- else if( a->algo == DIGEST_ALGO_RMD160 )
- rmd160_write( a->u.rmd, inbuf, inlen );
- else if( a->algo == DIGEST_ALGO_SHA1 )
- sha1_write( a->u.sha1, inbuf, inlen );
- else
- log_bug(NULL);
+ if( a->use_rmd160 ) {
+ rmd160_write( &a->rmd160, a->buffer, a->bufcount );
+ rmd160_write( &a->rmd160, inbuf, inlen );
+ }
+ if( a->use_sha1 ) {
+ sha1_write( &a->sha1, a->buffer, a->bufcount );
+ sha1_write( &a->sha1, inbuf, inlen );
+ }
+ if( a->use_md5 ) {
+ md5_write( &a->md5, a->buffer, a->bufcount );
+ md5_write( &a->md5, inbuf, inlen );
+ }
+ a->bufcount = 0;
}
+
void
-md_putchar( MD_HANDLE *a, int c )
+md_final(MD_HANDLE a)
{
- if( a->algo == DIGEST_ALGO_MD5 )
- md5_putchar( a->u.md5, c );
- else if( a->algo == DIGEST_ALGO_RMD160 )
- rmd160_putchar( a->u.rmd, c );
- else if( a->algo == DIGEST_ALGO_SHA1 )
- sha1_putchar( a->u.sha1, c );
- else
- log_bug(NULL);
+ if( a->bufcount )
+ md_write( a, NULL, 0 );
+ if( a->use_rmd160 ) {
+ byte *p;
+ rmd160_final( &a->rmd160 );
+ p = rmd160_read( &a->rmd160 );
+ }
+ if( a->use_sha1 )
+ sha1_final( &a->sha1 );
+ if( a->use_md5 )
+ md5_final( &a->md5 );
}
+/****************
+ * if ALGO is null get the digest for the used algo (which should be only one)
+ */
byte *
-md_final(MD_HANDLE *a)
+md_read( MD_HANDLE a, int algo )
{
- if( a->algo == DIGEST_ALGO_MD5 ) {
- if( !a->datalen ) {
- md5_final( a->u.md5 );
- memcpy(a->data, md5_read( a->u.md5 ), 16);
- a->datalen = 16;
- }
- return a->data;
+ if( !algo ) {
+ if( a->use_rmd160 )
+ return rmd160_read( &a->rmd160 );
+ if( a->use_sha1 )
+ return sha1_read( &a->sha1 );
+ if( a->use_md5 )
+ return md5_read( &a->md5 );
}
- else if( a->algo == DIGEST_ALGO_RMD160 ) {
- if( !a->datalen ) {
- memcpy(a->data, rmd160_final( a->u.rmd ), 20 );
- a->datalen = 20;
- }
- return a->data;
+ else {
+ if( algo == DIGEST_ALGO_RMD160 )
+ return rmd160_read( &a->rmd160 );
+ if( algo == DIGEST_ALGO_SHA1 )
+ return sha1_read( &a->sha1 );
+ if( algo == DIGEST_ALGO_MD5 )
+ return md5_read( &a->md5 );
}
- else if( a->algo == DIGEST_ALGO_SHA1 ) {
- if( !a->datalen ) {
- memcpy(a->data, sha1_final( a->u.sha1 ), 20 );
- a->datalen = 20;
- }
- return a->data;
- }
- else
- log_bug(NULL);
+ log_bug(NULL);
}
+int
+md_get_algo( MD_HANDLE a )
+{
+ if( a->use_rmd160 )
+ return DIGEST_ALGO_RMD160;
+ if( a->use_sha1 )
+ return DIGEST_ALGO_SHA1;
+ if( a->use_md5 )
+ return DIGEST_ALGO_MD5;
+ return 0;
+}
diff --git a/cipher/rmd.h b/cipher/md.h
similarity index 53%
copy from cipher/rmd.h
copy to cipher/md.h
index 3d260cdc..8a7886d0 100644
--- a/cipher/rmd.h
+++ b/cipher/md.h
@@ -1,51 +1,60 @@
-/* rmd.h - RIPE-MD hash functions
+/* md.h - digest functions
* Copyright (c) 1997 by Werner Koch (dd9jn)
*
* This file is part of G10.
*
* G10 is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* G10 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
-#ifndef G10_RMD_H
-#define G10_RMD_H
+#ifndef G10_MD_H
+#define G10_MD_H
#include "types.h"
+#include "rmd.h"
+#include "sha1.h"
+#include "md5.h"
+
+#define MD_BUFFER_SIZE 512
typedef struct {
- u32 h0,h1,h2,h3,h4;
- u32 nblocks;
- byte buffer[64];
+ int use_rmd160;
+ RMD160_CONTEXT rmd160;
+ int use_sha1;
+ SHA1_CONTEXT sha1;
+ int use_md5;
+ MD5_CONTEXT md5;
+ byte buffer[MD_BUFFER_SIZE]; /* primary buffer */
int bufcount;
-} *RMDHANDLE;
+} *MD_HANDLE;
-/****************
- * Process a single character, this character will be buffered to
- * increase performance.
- */
-#define rmd160_putchar(h,c) \
+#define md_putc(h,c) \
do { \
- if( (h)->bufcount == 64 ) \
- rmd160_write( (h), NULL, 0 ); \
+ if( (h)->bufcount == MD_BUFFER_SIZE ) \
+ md_write( (h), NULL, 0 ); \
(h)->buffer[(h)->bufcount++] = (c) & 0xff; \
} while(0)
-RMDHANDLE rmd160_open( int secure );
-RMDHANDLE rmd160_copy( RMDHANDLE a );
-void rmd160_close(RMDHANDLE hd);
-void rmd160_write( RMDHANDLE hd, byte *inbuf, size_t inlen);
-byte * rmd160_final(RMDHANDLE hd);
+/*-- md.c --*/
+MD_HANDLE md_open( int algo, int secure );
+void md_enable( MD_HANDLE hd, int algo );
+MD_HANDLE md_copy( MD_HANDLE a );
+void md_close(MD_HANDLE a);
+void md_write( MD_HANDLE a, byte *inbuf, size_t inlen);
+void md_final(MD_HANDLE a);
+byte *md_read( MD_HANDLE a, int algo );
+int md_get_algo( MD_HANDLE a );
-#endif /*G10_RMD_H*/
+#endif /*G10_MD_H*/
diff --git a/cipher/md5.c b/cipher/md5.c
index be260269..6906503d 100644
--- a/cipher/md5.c
+++ b/cipher/md5.c
@@ -1,438 +1,333 @@
/* md5.c - MD5 Message-Digest Algorithm
* Copyright (c) 1994 by Werner Koch (dd9jn)
*
* This is a hacked version from WkLib
*
* This file is part of WkLib.
*
* WkLib is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* WkLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
***********************************************************************
** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **
** **
** License to copy and use this software is granted provided that **
** it is identified as the "RSA Data Security, Inc. MD5 Message- **
** Digest Algorithm" in all material mentioning or referencing this **
** software or this function. **
** **
** License is also granted to make and use derivative works **
** provided that such works are identified as "derived from the RSA **
** Data Security, Inc. MD5 Message-Digest Algorithm" in all **
** material mentioning or referencing the derived work. **
** **
** RSA Data Security, Inc. makes no representations concerning **
** either the merchantability of this software or the suitability **
** of this software for any particular purpose. It is provided "as **
** is" without express or implied warranty of any kind. **
** **
** These notices must be retained in any copies of any part of this **
** documentation and/or software. **
***********************************************************************
*
* History:
* 16.01.95 wk now uses generic base-64 support
* 24.01.95 wk changed back to original base-64 coding, because
* the generic base-64 support was changed to go conform
* with RFC1113 !
*/
/* Test values:
* "" D4 1D 8C D9 8F 00 B2 04 E9 80 09 98 EC F8 42 7E
* "a" 0C C1 75 B9 C0 F1 B6 A8 31 C3 99 E2 69 77 26 61
* "abc 90 01 50 98 3C D2 4F B0 D6 96 3F 7D 28 E1 7F 72
* "message digest" F9 6B 69 7D 7C B7 93 8D 52 5A 2F 31 AA F1 61 D0
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "util.h"
#include "md5.h"
-#include "cipher.h" /* kludge for md5_copy2md() */
#include "memory.h"
#if __WATCOMC__ && defined(M_I86)
/* 16-Bit Compiler breaks Code in Function Transform() */
/* (at least when compiling for windows) */
#ifndef __SW_OD
#error must be compiled without optimizations
#endif
#endif
-static void Init( MD5HANDLE mdContext);
+static void Init( MD5_CONTEXT *mdContext);
static void Transform(u32 *buf,u32 *in);
static byte PADDING[64] = {
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
/* F, G, H and I are basic MD5 functions */
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
#define H(x, y, z) ((x) ^ (y) ^ (z))
#define I(x, y, z) ((y) ^ ((x) | (~z)))
/* ROTATE_LEFT rotates x left n bits */
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */
/* Rotation is separate from addition to prevent recomputation */
#define FF(a, b, c, d, x, s, ac) \
{(a) += F ((b), (c), (d)) + (x) + (u32)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define GG(a, b, c, d, x, s, ac) \
{(a) += G ((b), (c), (d)) + (x) + (u32)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define HH(a, b, c, d, x, s, ac) \
{(a) += H ((b), (c), (d)) + (x) + (u32)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define II(a, b, c, d, x, s, ac) \
{(a) += I ((b), (c), (d)) + (x) + (u32)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
-/* The routine Init initializes the message-digest context
- * mdContext. All fields are set to zero.
- * mode should be zero is reserved for extensions.
- */
-
-MD5HANDLE
-md5_open(int secure)
-{
- MD5HANDLE mdContext;
-
- mdContext = secure? m_alloc_secure( sizeof *mdContext )
- : m_alloc( sizeof *mdContext );
- Init(mdContext);
- return mdContext;
-}
-
-
-MD5HANDLE
-md5_copy( MD5HANDLE a )
-{
- MD5HANDLE mdContext;
-
- assert(a);
- mdContext = m_is_secure(a)? m_alloc_secure( sizeof *mdContext )
- : m_alloc( sizeof *mdContext );
- memcpy( mdContext, a, sizeof *a );
- return mdContext;
-}
-
-
-/* BAD Kludge!!! */
-MD_HANDLE *
-md5_copy2md( MD5HANDLE a )
-{
- MD_HANDLE *md = md_makecontainer( DIGEST_ALGO_MD5 );
- md->u.md5 = md5_copy( a );
- return md;
-}
-
void
-md5_close(MD5HANDLE hd)
-{
- if( hd )
- m_free(hd);
-}
-
-
-static void
-Init( MD5HANDLE mdContext)
+md5_init( MD5_CONTEXT *mdContext)
{
mdContext->i[0] = mdContext->i[1] = (u32)0;
/* Load magic initialization constants.
*/
mdContext->buf[0] = (u32)0x67452301L;
mdContext->buf[1] = (u32)0xefcdab89L;
mdContext->buf[2] = (u32)0x98badcfeL;
mdContext->buf[3] = (u32)0x10325476L;
- mdContext->bufcount = 0;
+ mdContext->count = 0;
}
/* The routine Update updates the message-digest context to
* account for the presence of each of the characters inBuf[0..inLen-1]
* in the message whose digest is being computed.
*/
void
-md5_write( MD5HANDLE mdContext, byte *inBuf, size_t inLen)
+md5_write( MD5_CONTEXT *mdContext, byte *inBuf, size_t inLen)
{
register int i, ii;
int mdi;
u32 in[16];
- if(mdContext->bufcount) { /* flush the buffer */
- i = mdContext->bufcount;
- mdContext->bufcount = 0;
+ if(mdContext->count) { /* flush the buffer */
+ i = mdContext->count;
+ mdContext->count = 0;
md5_write( mdContext, mdContext->digest, i);
}
if( !inBuf )
return;
/* compute number of bytes mod 64 */
mdi = (int)((mdContext->i[0] >> 3) & 0x3F);
/* update number of bits */
if((mdContext->i[0] + ((u32)inLen << 3)) < mdContext->i[0])
mdContext->i[1]++;
mdContext->i[0] += ((u32)inLen << 3);
mdContext->i[1] += ((u32)inLen >> 29);
while(inLen--) {
/* add new character to buffer, increment mdi */
mdContext->in[mdi++] = *inBuf++;
/* transform if necessary */
if( mdi == 0x40 ) {
for(i = 0, ii = 0; i < 16; i++, ii += 4)
in[i] = (((u32)mdContext->in[ii+3]) << 24) |
(((u32)mdContext->in[ii+2]) << 16) |
(((u32)mdContext->in[ii+1]) << 8) |
((u32)mdContext->in[ii]);
Transform(mdContext->buf, in);
mdi = 0;
}
}
}
-/****************
- * Process a single character, this character will be buffered to
- * increase performance. The digest-field is used as a buffer.
- */
-
-void
-md5_putchar( MD5HANDLE mdContext, int c )
-{
- if(mdContext->bufcount == 16)
- md5_write( mdContext, NULL, 0 );
- mdContext->digest[mdContext->bufcount++] = c & 0xff;
-}
-
-
/* The routine final terminates the message-digest computation and
* ends with the desired message digest in mdContext->digest[0...15].
* The handle is prepared for a new MD5 cycle.
* Returns 16 bytes representing the digest.
*/
void
-md5_final(MD5HANDLE mdContext)
+md5_final( MD5_CONTEXT *mdContext )
{
u32 in[16];
int mdi;
unsigned int i, ii;
unsigned int padLen;
- if(mdContext->bufcount) /* flush buffer */
+ if(mdContext->count) /* flush buffer */
md5_write(mdContext, NULL, 0 );
/* save number of bits */
in[14] = mdContext->i[0];
in[15] = mdContext->i[1];
/* compute number of bytes mod 64 */
mdi = (int)((mdContext->i[0] >> 3) & 0x3F);
/* pad out to 56 mod 64 */
padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);
md5_write(mdContext, PADDING, padLen);
/* append length in bits and transform */
for(i = 0, ii = 0; i < 14; i++, ii += 4)
in[i] = (((u32)mdContext->in[ii+3]) << 24) |
(((u32)mdContext->in[ii+2]) << 16) |
(((u32)mdContext->in[ii+1]) << 8) |
((u32)mdContext->in[ii]);
Transform(mdContext->buf, in);
/* store buffer in digest */
for(i = 0, ii = 0; i < 4; i++, ii += 4) {
mdContext->digest[ii] = (byte)(mdContext->buf[i] & 0xFF);
mdContext->digest[ii+1] = (byte)((mdContext->buf[i] >> 8) & 0xFF);
mdContext->digest[ii+2] = (byte)((mdContext->buf[i] >> 16) & 0xFF);
mdContext->digest[ii+3] = (byte)((mdContext->buf[i] >> 24) & 0xFF);
}
- Init(mdContext);
-}
-
-/**********
- * Returns 16 bytes representing the digest.
- */
-byte *
-md5_read(MD5HANDLE mdContext)
-{
- return mdContext->digest;
-}
-
-
-
-/****************
- * Converts the result form Read into a printable representation.
- * This should only be used direct after a md5_read(), because it uses
- * In-Place conversion.
- * Returns digest.
- */
-
-char *
-md5_tostring( byte *digest )
-{
- static byte bintoasc[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ."
- "abcdefghijklmnopqrstuvwxyz_"
- "0123456789";
- int i;
- byte *d, *s;
-
- memmove(digest+8,digest, 16); /* make some room */
- d = digest;
- s = digest+8;
- for(i=0; i < 5; i++, s += 3 ) {
- *d++ = bintoasc[(*s >> 2) & 077];
- *d++ = bintoasc[(((*s << 4) & 060) | ((s[1] >> 4) & 017)) & 077];
- *d++ = bintoasc[(((s[1] << 2) & 074) | ((s[2] >> 6) & 03)) & 077];
- *d++ = bintoasc[s[2] & 077];
- }
- *d++ = bintoasc[(*s >> 2) & 077];
- *d++ = bintoasc[((*s << 4) & 060) & 077];
- *d = 0;
- return (char*)digest;
}
/* Basic MD5 step. Transforms buf based on in. Note that if the Mysterious
* Constants are arranged backwards in little-endian order and decrypted with
* the DES they produce OCCULT MESSAGES!
*/
static void
Transform(register u32 *buf,register u32 *in)
{
register u32 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
/* Round 1 */
#define S11 7
#define S12 12
#define S13 17
#define S14 22
FF ( a, b, c, d, in[ 0], S11, 0xD76AA478L); /* 1 */
FF ( d, a, b, c, in[ 1], S12, 0xE8C7B756L); /* 2 */
FF ( c, d, a, b, in[ 2], S13, 0x242070DBL); /* 3 */
FF ( b, c, d, a, in[ 3], S14, 0xC1BDCEEEL); /* 4 */
FF ( a, b, c, d, in[ 4], S11, 0xF57C0FAFL); /* 5 */
FF ( d, a, b, c, in[ 5], S12, 0x4787C62AL); /* 6 */
FF ( c, d, a, b, in[ 6], S13, 0xA8304613L); /* 7 */
FF ( b, c, d, a, in[ 7], S14, 0xFD469501L); /* 8 */
FF ( a, b, c, d, in[ 8], S11, 0x698098D8L); /* 9 */
FF ( d, a, b, c, in[ 9], S12, 0x8B44F7AFL); /* 10 */
FF ( c, d, a, b, in[10], S13, 0xFFFF5BB1L); /* 11 */
FF ( b, c, d, a, in[11], S14, 0x895CD7BEL); /* 12 */
FF ( a, b, c, d, in[12], S11, 0x6B901122L); /* 13 */
FF ( d, a, b, c, in[13], S12, 0xFD987193L); /* 14 */
FF ( c, d, a, b, in[14], S13, 0xA679438EL); /* 15 */
FF ( b, c, d, a, in[15], S14, 0x49B40821L); /* 16 */
/* Round 2 */
#define S21 5
#define S22 9
#define S23 14
#define S24 20
GG ( a, b, c, d, in[ 1], S21, 0xF61E2562L); /* 17 */
GG ( d, a, b, c, in[ 6], S22, 0xC040B340L); /* 18 */
GG ( c, d, a, b, in[11], S23, 0x265E5A51L); /* 19 */
GG ( b, c, d, a, in[ 0], S24, 0xE9B6C7AAL); /* 20 */
GG ( a, b, c, d, in[ 5], S21, 0xD62F105DL); /* 21 */
GG ( d, a, b, c, in[10], S22, 0x02441453L); /* 22 */
GG ( c, d, a, b, in[15], S23, 0xD8A1E681L); /* 23 */
GG ( b, c, d, a, in[ 4], S24, 0xE7D3FBC8L); /* 24 */
GG ( a, b, c, d, in[ 9], S21, 0x21E1CDE6L); /* 25 */
GG ( d, a, b, c, in[14], S22, 0xC33707D6L); /* 26 */
GG ( c, d, a, b, in[ 3], S23, 0xF4D50D87L); /* 27 */
GG ( b, c, d, a, in[ 8], S24, 0x455A14EDL); /* 28 */
GG ( a, b, c, d, in[13], S21, 0xA9E3E905L); /* 29 */
GG ( d, a, b, c, in[ 2], S22, 0xFCEFA3F8L); /* 30 */
GG ( c, d, a, b, in[ 7], S23, 0x676F02D9L); /* 31 */
GG ( b, c, d, a, in[12], S24, 0x8D2A4C8AL); /* 32 */
/* Round 3 */
#define S31 4
#define S32 11
#define S33 16
#define S34 23
HH ( a, b, c, d, in[ 5], S31, 0xFFFA3942L); /* 33 */
HH ( d, a, b, c, in[ 8], S32, 0x8771F681L); /* 34 */
HH ( c, d, a, b, in[11], S33, 0x6D9D6122L); /* 35 */
HH ( b, c, d, a, in[14], S34, 0xFDE5380CL); /* 36 */
HH ( a, b, c, d, in[ 1], S31, 0xA4BEEA44L); /* 37 */
HH ( d, a, b, c, in[ 4], S32, 0x4BDECFA9L); /* 38 */
HH ( c, d, a, b, in[ 7], S33, 0xF6BB4B60L); /* 39 */
HH ( b, c, d, a, in[10], S34, 0xBEBFBC70L); /* 40 */
HH ( a, b, c, d, in[13], S31, 0x289B7EC6L); /* 41 */
HH ( d, a, b, c, in[ 0], S32, 0xEAA127FAL); /* 42 */
HH ( c, d, a, b, in[ 3], S33, 0xD4EF3085L); /* 43 */
HH ( b, c, d, a, in[ 6], S34, 0x04881D05L); /* 44 */
HH ( a, b, c, d, in[ 9], S31, 0xD9D4D039L); /* 45 */
HH ( d, a, b, c, in[12], S32, 0xE6DB99E5L); /* 46 */
HH ( c, d, a, b, in[15], S33, 0x1FA27CF8L); /* 47 */
HH ( b, c, d, a, in[ 2], S34, 0xC4AC5665L); /* 48 */
/* Round 4 */
#define S41 6
#define S42 10
#define S43 15
#define S44 21
II ( a, b, c, d, in[ 0], S41, 0xF4292244L); /* 49 */
II ( d, a, b, c, in[ 7], S42, 0x432AFF97L); /* 50 */
II ( c, d, a, b, in[14], S43, 0xAB9423A7L); /* 51 */
II ( b, c, d, a, in[ 5], S44, 0xFC93A039L); /* 52 */
II ( a, b, c, d, in[12], S41, 0x655B59C3L); /* 53 */
II ( d, a, b, c, in[ 3], S42, 0x8F0CCC92L); /* 54 */
II ( c, d, a, b, in[10], S43, 0xFFEFF47DL); /* 55 */
II ( b, c, d, a, in[ 1], S44, 0x85845DD1L); /* 56 */
II ( a, b, c, d, in[ 8], S41, 0x6FA87E4FL); /* 57 */
II ( d, a, b, c, in[15], S42, 0xFE2CE6E0L); /* 58 */
II ( c, d, a, b, in[ 6], S43, 0xA3014314L); /* 59 */
II ( b, c, d, a, in[13], S44, 0x4E0811A1L); /* 60 */
II ( a, b, c, d, in[ 4], S41, 0xF7537E82L); /* 61 */
II ( d, a, b, c, in[11], S42, 0xBD3AF235L); /* 62 */
II ( c, d, a, b, in[ 2], S43, 0x2AD7D2BBL); /* 63 */
II ( b, c, d, a, in[ 9], S44, 0xEB86D391L); /* 64 */
buf[0] += a;
buf[1] += b;
buf[2] += c;
buf[3] += d;
}
/* end of file */
diff --git a/cipher/md5.h b/cipher/md5.h
index fa401a16..c46075a3 100644
--- a/cipher/md5.h
+++ b/cipher/md5.h
@@ -1,44 +1,39 @@
/* md5.h - message digest 5
* Copyright (c) 1997 by Werner Koch (dd9jn)
*
* This file is part of G10.
*
* G10 is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* G10 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifndef G10_MD5_H
#define G10_MD5_H
#include "types.h"
typedef struct {
u32 i[2]; /* number of _bits_ handled mod 2^64 */
u32 buf[4]; /* scratch buffer */
+ int count;
byte in[64]; /* input buffer */
byte digest[16+8+1]; /* actual digest after Final call */
- byte bufcount; /* extra room for bintoascii */
-} *MD5HANDLE;
+} MD5_CONTEXT;
-/*-- md5.c --*/
-MD5HANDLE md5_open(int);
-MD5HANDLE md5_copy(MD5HANDLE a);
-void md5_write(MD5HANDLE hd, byte *inBuf, size_t inLen);
-void md5_putchar(MD5HANDLE hd, int c );
-void md5_final(MD5HANDLE hd);
-byte *md5_read(MD5HANDLE hd);
-char *md5_tostring( byte *digest );
-void md5_close(MD5HANDLE hd);
+void md5_init( MD5_CONTEXT *c );
+void md5_write( MD5_CONTEXT *hd, byte *inbuf, size_t inlen);
+void md5_final( MD5_CONTEXT *hd);
+#define md5_read(h) ( (h)->digest )
#endif /*G10_MD5_H*/
diff --git a/cipher/random.c b/cipher/random.c
index a95e7e50..41f001e7 100644
--- a/cipher/random.c
+++ b/cipher/random.c
@@ -1,174 +1,177 @@
/* random.c - random number generator
* Copyright (c) 1997 by Werner Koch (dd9jn)
*
* This file is part of G10.
*
* G10 is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* G10 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include "util.h"
#include "cipher.h"
struct cache {
int len;
byte buffer[100]; /* fixme: should be allocated with m_alloc_secure()*/
};
static struct cache cache[3];
#define MASK_LEVEL(a) do {if( a > 2 ) a = 2; else if( a < 0 ) a = 0; } while(0)
static void fill_buffer( byte *buffer, size_t length, int level );
/****************
* Fill the buffer with LENGTH bytes of cryptologic strong
* random bytes. level 0 is not very strong, 1 is strong enough
* for most usage, 2 is good for key generation stuff but may be very slow.
*/
void
randomize_buffer( byte *buffer, size_t length, int level )
{
for( ; length; length-- )
*buffer++ = get_random_byte(level);
}
byte
get_random_byte( int level )
{
MASK_LEVEL(level);
if( !cache[level].len ) {
fill_buffer(cache[level].buffer, DIM(cache[level].buffer), level );
cache[level].len = DIM(cache[level].buffer);
}
return cache[level].buffer[--cache[level].len];
}
#ifdef HAVE_DEV_RANDOM
static int
open_device( const char *name, int minor )
{
int fd;
struct stat sb;
fd = open( name, O_RDONLY );
if( fd == -1 )
log_fatal("can't open %s: %s\n", name, strerror(errno) );
if( fstat( fd, &sb ) )
log_fatal("stat() off %s failed: %s\n", name, strerror(errno) );
- if( !S_ISCHR(sb.st_mode)
- #ifdef __linux__
- || (sb.st_rdev >> 8) != 1
- || (sb.st_rdev & 0xff) != minor
- #endif
- )
+ #if defined(__sparc__) && defined(__linux__)
+ #warning something is wrong with UltraPenguin /dev/random
+ #else
+ if( !S_ISCHR(sb.st_mode) )
log_fatal("invalid random device!\n" );
+ #endif
return fd;
}
static void
fill_buffer( byte *buffer, size_t length, int level )
{
FILE *fp;
static int fd_urandom = -1;
static int fd_random = -1;
int fd;
int n;
int warn=0;
if( level == 2 ) {
if( fd_random == -1 )
fd_random = open_device( "/dev/random", 8 );
fd = fd_random;
}
else {
if( fd_urandom == -1 )
fd_urandom = open_device( "/dev/urandom", 9 );
fd = fd_urandom;
}
do {
fd_set rfds;
struct timeval tv;
int rc;
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
tv.tv_sec = 3;
tv.tv_usec = 0;
if( !(rc=select(fd+1, &rfds, NULL, NULL, &tv)) ) {
if( !warn )
tty_printf(
"\nNot enough random bytes available. Please do some other work to give
the OS a chance to collect more entropy! (Need %d more bytes)\n", length );
warn = 1;
continue;
}
else if( rc == -1 ) {
tty_printf("select() error: %s\n", strerror(errno));
continue;
}
assert( length < 200 );
do {
n = read(fd, buffer, length );
+ if( n > length ) {
+ log_error("bogus read from random device (n=%d)\n", n );
+ n = length;
+ }
} while( n == -1 && errno == EINTR );
if( n == -1 )
log_fatal("read error on random device: %s\n", strerror(errno) );
assert( n <= length );
buffer += n;
length -= n;
} while( length );
}
#else /* not HAVE_DEV_RANDOM */
static void
fill_buffer( byte *buffer, size_t length, int level )
{
static int initialized=0;
if( !initialized ) {
log_info("warning: using insecure random number generator!!\n");
tty_printf("The random number generator is only a kludge to let\n"
"it compile - it is in no way a strong RNG!\n\n"
"DON'T USE ANY DATA GENERATED BY THIS PROGRAM!!\n\n");
initialized=1;
srand(make_timestamp()*getpid());
}
while( length-- )
*buffer++ = ((unsigned)(1 + (int) (256.0*rand()/(RAND_MAX+1.0)))-1);
}
#endif
diff --git a/cipher/rmd.h b/cipher/rmd.h
index 3d260cdc..8f53634d 100644
--- a/cipher/rmd.h
+++ b/cipher/rmd.h
@@ -1,51 +1,38 @@
/* rmd.h - RIPE-MD hash functions
* Copyright (c) 1997 by Werner Koch (dd9jn)
*
* This file is part of G10.
*
* G10 is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* G10 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifndef G10_RMD_H
#define G10_RMD_H
#include "types.h"
typedef struct {
u32 h0,h1,h2,h3,h4;
u32 nblocks;
- byte buffer[64];
- int bufcount;
-} *RMDHANDLE;
+ byte buf[64];
+ int count;
+} RMD160_CONTEXT;
-/****************
- * Process a single character, this character will be buffered to
- * increase performance.
- */
-#define rmd160_putchar(h,c) \
- do { \
- if( (h)->bufcount == 64 ) \
- rmd160_write( (h), NULL, 0 ); \
- (h)->buffer[(h)->bufcount++] = (c) & 0xff; \
- } while(0)
-
-RMDHANDLE rmd160_open( int secure );
-RMDHANDLE rmd160_copy( RMDHANDLE a );
-void rmd160_close(RMDHANDLE hd);
-void rmd160_write( RMDHANDLE hd, byte *inbuf, size_t inlen);
-byte * rmd160_final(RMDHANDLE hd);
-
+void rmd160_init( RMD160_CONTEXT *c );
+void rmd160_write( RMD160_CONTEXT *hd, byte *inbuf, size_t inlen);
+void rmd160_final(RMD160_CONTEXT *hd);
+#define rmd160_read(h) ( (h)->buf )
#endif /*G10_RMD_H*/
diff --git a/cipher/rmd160.c b/cipher/rmd160.c
index e8c424fa..0b501d77 100644
--- a/cipher/rmd160.c
+++ b/cipher/rmd160.c
@@ -1,409 +1,354 @@
/* rmd160.c - RIPE-MD160
* Copyright (c) 1997 by Werner Koch (dd9jn)
*
* This file is part of G10.
*
* G10 is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* G10 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "util.h"
#include "memory.h"
-#include "cipher.h" /* grrrr */
#include "rmd.h"
/*********************************
* RIPEMD-160 is not patented, see (as of 25.10.97)
* http://www.esat.kuleuven.ac.be/~bosselae/ripemd160.html
* Note that the code uses Little Endian byteorder, which is good for
* 386 etc, but we must add some conversion when used on a big endian box.
*
*
* Pseudo-code for RIPEMD-160
*
* RIPEMD-160 is an iterative hash function that operates on 32-bit words.
* The round function takes as input a 5-word chaining variable and a 16-word
* message block and maps this to a new chaining variable. All operations are
* defined on 32-bit words. Padding is identical to that of MD4.
*
*
* RIPEMD-160: definitions
*
*
* nonlinear functions at bit level: exor, mux, -, mux, -
*
* f(j, x, y, z) = x XOR y XOR z (0 <= j <= 15)
* f(j, x, y, z) = (x AND y) OR (NOT(x) AND z) (16 <= j <= 31)
* f(j, x, y, z) = (x OR NOT(y)) XOR z (32 <= j <= 47)
* f(j, x, y, z) = (x AND z) OR (y AND NOT(z)) (48 <= j <= 63)
* f(j, x, y, z) = x XOR (y OR NOT(z)) (64 <= j <= 79)
*
*
* added constants (hexadecimal)
*
* K(j) = 0x00000000 (0 <= j <= 15)
* K(j) = 0x5A827999 (16 <= j <= 31) int(2**30 x sqrt(2))
* K(j) = 0x6ED9EBA1 (32 <= j <= 47) int(2**30 x sqrt(3))
* K(j) = 0x8F1BBCDC (48 <= j <= 63) int(2**30 x sqrt(5))
* K(j) = 0xA953FD4E (64 <= j <= 79) int(2**30 x sqrt(7))
* K'(j) = 0x50A28BE6 (0 <= j <= 15) int(2**30 x cbrt(2))
* K'(j) = 0x5C4DD124 (16 <= j <= 31) int(2**30 x cbrt(3))
* K'(j) = 0x6D703EF3 (32 <= j <= 47) int(2**30 x cbrt(5))
* K'(j) = 0x7A6D76E9 (48 <= j <= 63) int(2**30 x cbrt(7))
* K'(j) = 0x00000000 (64 <= j <= 79)
*
*
* selection of message word
*
* r(j) = j (0 <= j <= 15)
* r(16..31) = 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8
* r(32..47) = 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12
* r(48..63) = 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2
* r(64..79) = 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
* r0(0..15) = 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12
* r0(16..31)= 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2
* r0(32..47)= 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13
* r0(48..63)= 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14
* r0(64..79)= 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
*
*
* amount for rotate left (rol)
*
* s(0..15) = 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8
* s(16..31) = 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12
* s(32..47) = 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5
* s(48..63) = 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12
* s(64..79) = 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
* s'(0..15) = 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6
* s'(16..31)= 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11
* s'(32..47)= 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5
* s'(48..63)= 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8
* s'(64..79)= 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
*
*
* initial value (hexadecimal)
*
* h0 = 0x67452301; h1 = 0xEFCDAB89; h2 = 0x98BADCFE; h3 = 0x10325476;
* h4 = 0xC3D2E1F0;
*
*
* RIPEMD-160: pseudo-code
*
* It is assumed that the message after padding consists of t 16-word blocks
* that will be denoted with X[i][j], with 0 <= i <= t-1 and 0 <= j <= 15.
* The symbol [+] denotes addition modulo 2**32 and rol_s denotes cyclic left
* shift (rotate) over s positions.
*
*
* for i := 0 to t-1 {
* A := h0; B := h1; C := h2; D = h3; E = h4;
* A' := h0; B' := h1; C' := h2; D' = h3; E' = h4;
* for j := 0 to 79 {
* T := rol_s(j)(A [+] f(j, B, C, D) [+] X[i][r(j)] [+] K(j)) [+] E;
* A := E; E := D; D := rol_10(C); C := B; B := T;
* T := rol_s'(j)(A' [+] f(79-j, B', C', D') [+] X[i][r'(j)]
[+] K'(j)) [+] E';
* A' := E'; E' := D'; D' := rol_10(C'); C' := B'; B' := T;
* }
* T := h1 [+] C [+] D'; h1 := h2 [+] D [+] E'; h2 := h3 [+] E [+] A';
* h3 := h4 [+] A [+] B'; h4 := h0 [+] B [+] C'; h0 := T;
* }
*/
/* Some examples:
* "" 9c1185a5c5e9fc54612808977ee8f548b2258d31
* "a" 0bdc9d2d256b3ee9daae347be6f4dc835a467ffe
* "abc" 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc
* "message digest" 5d0689ef49d2fae572b881b123a85ffa21595f36
* "a...z" f71c27109c692c1b56bbdceb5b9d2865b3708dbc
* "abcdbcde...nopq" 12a053384a9c0c88e405a06c27dcf49ada62eb2b
* "A...Za...z0...9" b0e20b6e3116640286ed3a87a5713079b21f5189
* 8 times "1234567890" 9b752e45573d4b39f4dbd3323cab82bf63326bfb
* 1 million times "a" 52783243c1697bdbe16d37f97f68f08325dc1528
*/
-static void
-initialize( RMDHANDLE hd )
+void
+rmd160_init( RMD160_CONTEXT *hd )
{
hd->h0 = 0x67452301;
hd->h1 = 0xEFCDAB89;
hd->h2 = 0x98BADCFE;
hd->h3 = 0x10325476;
hd->h4 = 0xC3D2E1F0;
- hd->bufcount = 0;
hd->nblocks = 0;
+ hd->count = 0;
}
/****************
* Transform the message X which consists of 16 32-bit-words
*/
static void
-transform( RMDHANDLE hd, byte *data )
+transform( RMD160_CONTEXT *hd, byte *data )
{
static int r[80] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13 };
static int rr[80] = {
5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11 };
static int s[80] = {
11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 };
static int ss[80] = {
8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 };
u32 a,b,c,d,e,aa,bb,cc,dd,ee,t;
int rbits, j;
#ifdef BIG_ENDIAN_HOST
u32 x[16];
#else
u32 *x;
#endif
#define K(a) ( (a) < 16 ? 0x00000000 : \
(a) < 32 ? 0x5A827999 : \
(a) < 48 ? 0x6ED9EBA1 : \
(a) < 64 ? 0x8F1BBCDC : 0xA953FD4E )
#define KK(a) ( (a) < 16 ? 0x50A28BE6 : \
(a) < 32 ? 0x5C4DD124 : \
(a) < 48 ? 0x6D703EF3 : \
(a) < 64 ? 0x7A6D76E9 : 0x00000000 )
#define F0(x,y,z) ( (x) ^ (y) ^ (z) )
#define F1(x,y,z) ( ((x) & (y)) | (~(x) & (z)) )
#define F2(x,y,z) ( ((x) | ~(y)) ^ (z) )
#define F3(x,y,z) ( ((x) & (z)) | ((y) & ~(z)) )
#define F4(x,y,z) ( (x) ^ ((y) | ~(z)) )
#define F(a,x,y,z) ( (a) < 16 ? F0((x),(y),(z)) : \
(a) < 32 ? F1((x),(y),(z)) : \
(a) < 48 ? F2((x),(y),(z)) : \
(a) < 64 ? F3((x),(y),(z)) : \
F4((x),(y),(z)) )
#define rol(n,x) ( ((x) << (n)) | ((x) >> (32-(n))) )
#ifdef BIG_ENDIAN_HOST
{ int i;
byte *p2, *p1;
for(i=0, p1=data, p2=(byte*)x; i < 16; i++, p2 += 4 ) {
p2[3] = *p1++;
p2[2] = *p1++;
p2[1] = *p1++;
p2[0] = *p1++;
}
}
#else
x = (u32*)data;
#endif
a = aa = hd->h0;
b = bb = hd->h1;
c = cc = hd->h2;
d = dd = hd->h3;
e = ee = hd->h4;
for(j=0; j < 80; j++ ) {
t = a + F( j, b, c, d ) + x[ r[j] ] + K(j);
rbits = s[j];
a = rol(rbits, t) + e;
c = rol(10,c);
t = a; a = e; e = d; d = c; c = b; b = t;
t = aa + F(79-j, bb, cc, dd ) + x[ rr[j] ] + KK(j);
rbits = ss[j];
aa = rol(rbits, t) + ee;
cc = rol(10,cc);
t = aa; aa = ee; ee = dd; dd = cc; cc = bb; bb = t;
}
t = hd->h1 + c + dd;
hd->h1 = hd->h2 + d + ee;
hd->h2 = hd->h3 + e + aa;
hd->h3 = hd->h4 + a + bb;
hd->h4 = hd->h0 + b + cc;
hd->h0 = t;
}
-
-RMDHANDLE
-rmd160_open( int secure )
-{
- RMDHANDLE hd;
-
- hd = secure? m_alloc_secure( sizeof *hd )
- : m_alloc( sizeof *hd );
- initialize(hd);
- return hd;
-}
-
-
-RMDHANDLE
-rmd160_copy( RMDHANDLE a )
-{
- RMDHANDLE b;
-
- assert(a);
- b = m_is_secure(a)? m_alloc_secure( sizeof *b )
- : m_alloc( sizeof *b );
- memcpy( b, a, sizeof *a );
- return b;
-}
-
-
-/* BAD Kludge!!! */
-MD_HANDLE *
-rmd160_copy2md( RMDHANDLE a )
-{
- MD_HANDLE *md = md_makecontainer( DIGEST_ALGO_RMD160 );
- md->u.rmd = rmd160_copy( a );
- return md;
-}
-
-
-
-void
-rmd160_close(RMDHANDLE hd)
-{
- if( hd )
- m_free(hd);
-}
-
-
-
/* Update the message digest with the contents
* of INBUF with length INLEN.
*/
void
-rmd160_write( RMDHANDLE hd, byte *inbuf, size_t inlen)
+rmd160_write( RMD160_CONTEXT *hd, byte *inbuf, size_t inlen)
{
- if( hd->bufcount == 64 ) { /* flush the buffer */
- transform( hd, hd->buffer );
- hd->bufcount = 0;
+ if( hd->count == 64 ) { /* flush the buffer */
+ transform( hd, hd->buf );
+ hd->count = 0;
hd->nblocks++;
}
if( !inbuf )
return;
- if( hd->bufcount ) {
- for( ; inlen && hd->bufcount < 64; inlen-- )
- hd->buffer[hd->bufcount++] = *inbuf++;
+ if( hd->count ) {
+ for( ; inlen && hd->count < 64; inlen-- )
+ hd->buf[hd->count++] = *inbuf++;
rmd160_write( hd, NULL, 0 );
if( !inlen )
return;
}
while( inlen >= 64 ) {
transform( hd, inbuf );
- hd->bufcount = 0;
+ hd->count = 0;
hd->nblocks++;
inlen -= 64;
inbuf += 64;
}
- for( ; inlen && hd->bufcount < 64; inlen-- )
- hd->buffer[hd->bufcount++] = *inbuf++;
+ for( ; inlen && hd->count < 64; inlen-- )
+ hd->buf[hd->count++] = *inbuf++;
}
-/* The routine final terminates the computation and
- * returns the digest.
- * The handle is prepared for a new cycle, but adding bytes to the
- * handle will the destroy the returned buffer.
- * Returns: 20 bytes representing the digest.
+/* The routine terminates the computation
*/
-byte *
-rmd160_final(RMDHANDLE hd)
+void
+rmd160_final( RMD160_CONTEXT *hd )
{
u32 t, msb, lsb;
byte *p;
rmd160_write(hd, NULL, 0); /* flush */;
msb = 0;
t = hd->nblocks;
if( (lsb = t << 6) < t ) /* multiply by 64 to make a byte count */
msb++;
msb += t >> 26;
t = lsb;
- if( (lsb = t + hd->bufcount) < t ) /* add the bufcount */
+ if( (lsb = t + hd->count) < t ) /* add the count */
msb++;
t = lsb;
if( (lsb = t << 3) < t ) /* multiply by 8 to make a bit count */
msb++;
msb += t >> 29;
- if( hd->bufcount < 56 ) { /* enough room */
- hd->buffer[hd->bufcount++] = 0x80; /* pad */
- while( hd->bufcount < 56 )
- hd->buffer[hd->bufcount++] = 0; /* pad */
+ if( hd->count < 56 ) { /* enough room */
+ hd->buf[hd->count++] = 0x80; /* pad */
+ while( hd->count < 56 )
+ hd->buf[hd->count++] = 0; /* pad */
}
else { /* need one extra block */
- hd->buffer[hd->bufcount++] = 0x80; /* pad character */
- while( hd->bufcount < 64 )
- hd->buffer[hd->bufcount++] = 0;
+ hd->buf[hd->count++] = 0x80; /* pad character */
+ while( hd->count < 64 )
+ hd->buf[hd->count++] = 0;
rmd160_write(hd, NULL, 0); /* flush */;
- memset(hd->buffer, 0, 56 ); /* fill next block with zeroes */
+ memset(hd->buf, 0, 56 ); /* fill next block with zeroes */
}
/* append the 64 bit count */
- hd->buffer[56] = lsb ;
- hd->buffer[57] = lsb >> 8;
- hd->buffer[58] = lsb >> 16;
- hd->buffer[59] = lsb >> 24;
- hd->buffer[60] = msb ;
- hd->buffer[61] = msb >> 8;
- hd->buffer[62] = msb >> 16;
- hd->buffer[63] = msb >> 24;
- transform( hd, hd->buffer );
-
- p = hd->buffer;
+ hd->buf[56] = lsb ;
+ hd->buf[57] = lsb >> 8;
+ hd->buf[58] = lsb >> 16;
+ hd->buf[59] = lsb >> 24;
+ hd->buf[60] = msb ;
+ hd->buf[61] = msb >> 8;
+ hd->buf[62] = msb >> 16;
+ hd->buf[63] = msb >> 24;
+ transform( hd, hd->buf );
+
+ p = hd->buf;
#ifdef BIG_ENDIAN_HOST
#define X(a) do { *p++ = hd->h##a ; *p++ = hd->h##a >> 8; \
*p++ = hd->h##a >> 16; *p++ = hd->h##a >> 24; } while(0)
#else /* little endian */
#define X(a) do { *(u32*)p = hd->h##a ; p += 4; } while(0)
#endif
X(0);
X(1);
X(2);
X(3);
X(4);
#undef X
-
- initialize( hd ); /* prepare for next cycle */
- return hd->buffer; /* now contains the digest */
}
-
diff --git a/cipher/sha1.c b/cipher/sha1.c
index 1685058f..51029c45 100644
--- a/cipher/sha1.c
+++ b/cipher/sha1.c
@@ -1,399 +1,349 @@
/* sha1.c - SHA1 hash function
* Copyright (c) 1997 by Werner Koch (dd9jn)
*
* Please see below for more legal informations!
*
* This file is part of G10.
*
* G10 is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* G10 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/* I took the code for transform() from the Linux kernel
* (/usr/src/linux/drivers/char/random.c) which has
*
* a) This notice:
* ---------------
* SHA transform algorithm, taken from code written by Peter Gutman,
* and apparently in the public domain.
*
* b) This copyright notice:
* -------------------------
* Version 1.00, last modified 26-May-96
*
* Copyright Theodore Ts'o, 1994, 1995, 1996. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, and the entire permission notice in its entirety,
* including the disclaimer of warranties.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* ALTERNATIVELY, this product may be distributed under the terms of
* the GNU Public License, in which case the provisions of the GPL are
* required INSTEAD OF the above restrictions. (This clause is
* necessary due to a potential bad interaction between the GPL and
* the restrictions contained in a BSD-style copyright.)
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* Test vectors:
*
* "abc"
* A999 3E36 4706 816A BA3E 2571 7850 C26C 9CD0 D89D
*
* "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
* 8498 3E44 1C3B D26E BAAE 4AA1 F951 29E5 E546 70F1
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "util.h"
#include "memory.h"
-#include "cipher.h" /* grrrr */
#include "sha1.h"
/* The SHA f()-functions. */
#define f1(x,y,z) ( z ^ ( x & ( y ^ z ) ) ) /* Rounds 0-19 */
#define f2(x,y,z) ( x ^ y ^ z ) /* Rounds 20-39 */
#define f3(x,y,z) ( ( x & y ) | ( z & ( x | y ) ) ) /* Rounds 40-59 */
#define f4(x,y,z) ( x ^ y ^ z ) /* Rounds 60-79 */
/* The SHA Mysterious Constants */
#define K1 0x5A827999L /* Rounds 0-19 */
#define K2 0x6ED9EBA1L /* Rounds 20-39 */
#define K3 0x8F1BBCDCL /* Rounds 40-59 */
#define K4 0xCA62C1D6L /* Rounds 60-79 */
#define ROTL(n,X) ( ( ( X ) << n ) | ( ( X ) >> ( 32 - n ) ) )
#define expand(W,i) ( W[ i & 15 ] = \
ROTL( 1, ( W[ i & 15 ] ^ W[ (i - 14) & 15 ] ^ \
W[ (i - 8) & 15 ] ^ W[ (i - 3) & 15 ] ) ) )
#define subRound(a, b, c, d, e, f, k, data) \
( e += ROTL( 5, a ) + f( b, c, d ) + k + data, b = ROTL( 30, b ) )
-static void
-initialize( SHA1HANDLE hd )
+void
+sha1_init( SHA1_CONTEXT *hd )
{
hd->h0 = 0x67452301;
hd->h1 = 0xefcdab89;
hd->h2 = 0x98badcfe;
hd->h3 = 0x10325476;
hd->h4 = 0xc3d2e1f0;
- hd->bufcount = 0;
hd->nblocks = 0;
+ hd->count = 0;
}
/****************
* Transform the message X which consists of 16 32-bit-words
*/
static void
-transform( SHA1HANDLE hd, byte *data )
+transform( SHA1_CONTEXT *hd, byte *data )
{
u32 A, B, C, D, E; /* Local vars */
u32 eData[ 16 ]; /* Expanded data */
/* Set up first buffer and local data buffer */
A = hd->h0;
B = hd->h1;
C = hd->h2;
D = hd->h3;
E = hd->h4;
#ifdef BIG_ENDIAN_HOST
memcpy( eData, data, 64 );
#else
{ int i;
byte *p2;
for(i=0, p2=(byte*)eData; i < 16; i++, p2 += 4 ) {
p2[3] = *data++;
p2[2] = *data++;
p2[1] = *data++;
p2[0] = *data++;
}
}
#endif
/* Heavy mangling, in 4 sub-rounds of 20 iterations each. */
subRound( A, B, C, D, E, f1, K1, eData[ 0 ] );
subRound( E, A, B, C, D, f1, K1, eData[ 1 ] );
subRound( D, E, A, B, C, f1, K1, eData[ 2 ] );
subRound( C, D, E, A, B, f1, K1, eData[ 3 ] );
subRound( B, C, D, E, A, f1, K1, eData[ 4 ] );
subRound( A, B, C, D, E, f1, K1, eData[ 5 ] );
subRound( E, A, B, C, D, f1, K1, eData[ 6 ] );
subRound( D, E, A, B, C, f1, K1, eData[ 7 ] );
subRound( C, D, E, A, B, f1, K1, eData[ 8 ] );
subRound( B, C, D, E, A, f1, K1, eData[ 9 ] );
subRound( A, B, C, D, E, f1, K1, eData[ 10 ] );
subRound( E, A, B, C, D, f1, K1, eData[ 11 ] );
subRound( D, E, A, B, C, f1, K1, eData[ 12 ] );
subRound( C, D, E, A, B, f1, K1, eData[ 13 ] );
subRound( B, C, D, E, A, f1, K1, eData[ 14 ] );
subRound( A, B, C, D, E, f1, K1, eData[ 15 ] );
subRound( E, A, B, C, D, f1, K1, expand( eData, 16 ) );
subRound( D, E, A, B, C, f1, K1, expand( eData, 17 ) );
subRound( C, D, E, A, B, f1, K1, expand( eData, 18 ) );
subRound( B, C, D, E, A, f1, K1, expand( eData, 19 ) );
subRound( A, B, C, D, E, f2, K2, expand( eData, 20 ) );
subRound( E, A, B, C, D, f2, K2, expand( eData, 21 ) );
subRound( D, E, A, B, C, f2, K2, expand( eData, 22 ) );
subRound( C, D, E, A, B, f2, K2, expand( eData, 23 ) );
subRound( B, C, D, E, A, f2, K2, expand( eData, 24 ) );
subRound( A, B, C, D, E, f2, K2, expand( eData, 25 ) );
subRound( E, A, B, C, D, f2, K2, expand( eData, 26 ) );
subRound( D, E, A, B, C, f2, K2, expand( eData, 27 ) );
subRound( C, D, E, A, B, f2, K2, expand( eData, 28 ) );
subRound( B, C, D, E, A, f2, K2, expand( eData, 29 ) );
subRound( A, B, C, D, E, f2, K2, expand( eData, 30 ) );
subRound( E, A, B, C, D, f2, K2, expand( eData, 31 ) );
subRound( D, E, A, B, C, f2, K2, expand( eData, 32 ) );
subRound( C, D, E, A, B, f2, K2, expand( eData, 33 ) );
subRound( B, C, D, E, A, f2, K2, expand( eData, 34 ) );
subRound( A, B, C, D, E, f2, K2, expand( eData, 35 ) );
subRound( E, A, B, C, D, f2, K2, expand( eData, 36 ) );
subRound( D, E, A, B, C, f2, K2, expand( eData, 37 ) );
subRound( C, D, E, A, B, f2, K2, expand( eData, 38 ) );
subRound( B, C, D, E, A, f2, K2, expand( eData, 39 ) );
subRound( A, B, C, D, E, f3, K3, expand( eData, 40 ) );
subRound( E, A, B, C, D, f3, K3, expand( eData, 41 ) );
subRound( D, E, A, B, C, f3, K3, expand( eData, 42 ) );
subRound( C, D, E, A, B, f3, K3, expand( eData, 43 ) );
subRound( B, C, D, E, A, f3, K3, expand( eData, 44 ) );
subRound( A, B, C, D, E, f3, K3, expand( eData, 45 ) );
subRound( E, A, B, C, D, f3, K3, expand( eData, 46 ) );
subRound( D, E, A, B, C, f3, K3, expand( eData, 47 ) );
subRound( C, D, E, A, B, f3, K3, expand( eData, 48 ) );
subRound( B, C, D, E, A, f3, K3, expand( eData, 49 ) );
subRound( A, B, C, D, E, f3, K3, expand( eData, 50 ) );
subRound( E, A, B, C, D, f3, K3, expand( eData, 51 ) );
subRound( D, E, A, B, C, f3, K3, expand( eData, 52 ) );
subRound( C, D, E, A, B, f3, K3, expand( eData, 53 ) );
subRound( B, C, D, E, A, f3, K3, expand( eData, 54 ) );
subRound( A, B, C, D, E, f3, K3, expand( eData, 55 ) );
subRound( E, A, B, C, D, f3, K3, expand( eData, 56 ) );
subRound( D, E, A, B, C, f3, K3, expand( eData, 57 ) );
subRound( C, D, E, A, B, f3, K3, expand( eData, 58 ) );
subRound( B, C, D, E, A, f3, K3, expand( eData, 59 ) );
subRound( A, B, C, D, E, f4, K4, expand( eData, 60 ) );
subRound( E, A, B, C, D, f4, K4, expand( eData, 61 ) );
subRound( D, E, A, B, C, f4, K4, expand( eData, 62 ) );
subRound( C, D, E, A, B, f4, K4, expand( eData, 63 ) );
subRound( B, C, D, E, A, f4, K4, expand( eData, 64 ) );
subRound( A, B, C, D, E, f4, K4, expand( eData, 65 ) );
subRound( E, A, B, C, D, f4, K4, expand( eData, 66 ) );
subRound( D, E, A, B, C, f4, K4, expand( eData, 67 ) );
subRound( C, D, E, A, B, f4, K4, expand( eData, 68 ) );
subRound( B, C, D, E, A, f4, K4, expand( eData, 69 ) );
subRound( A, B, C, D, E, f4, K4, expand( eData, 70 ) );
subRound( E, A, B, C, D, f4, K4, expand( eData, 71 ) );
subRound( D, E, A, B, C, f4, K4, expand( eData, 72 ) );
subRound( C, D, E, A, B, f4, K4, expand( eData, 73 ) );
subRound( B, C, D, E, A, f4, K4, expand( eData, 74 ) );
subRound( A, B, C, D, E, f4, K4, expand( eData, 75 ) );
subRound( E, A, B, C, D, f4, K4, expand( eData, 76 ) );
subRound( D, E, A, B, C, f4, K4, expand( eData, 77 ) );
subRound( C, D, E, A, B, f4, K4, expand( eData, 78 ) );
subRound( B, C, D, E, A, f4, K4, expand( eData, 79 ) );
/* Build message digest */
hd->h0 += A;
hd->h1 += B;
hd->h2 += C;
hd->h3 += D;
hd->h4 += E;
}
-
-
-SHA1HANDLE
-sha1_open( int secure )
-{
- SHA1HANDLE hd;
-
- hd = secure? m_alloc_secure( sizeof *hd )
- : m_alloc( sizeof *hd );
- initialize(hd);
- return hd;
-}
-
-
-SHA1HANDLE
-sha1_copy( SHA1HANDLE a )
-{
- SHA1HANDLE b;
-
- assert(a);
- b = m_is_secure(a)? m_alloc_secure( sizeof *b )
- : m_alloc( sizeof *b );
- memcpy( b, a, sizeof *a );
- return b;
-}
-
-
-/* BAD Kludge!!! */
-MD_HANDLE *
-sha1_copy2md( SHA1HANDLE a )
-{
- MD_HANDLE *md = md_makecontainer( DIGEST_ALGO_SHA1 );
- md->u.sha1 = sha1_copy( a );
- return md;
-}
-
-
-
-void
-sha1_close(SHA1HANDLE hd)
-{
- if( hd )
- m_free(hd);
-}
-
-
-
/* Update the message digest with the contents
* of INBUF with length INLEN.
*/
void
-sha1_write( SHA1HANDLE hd, byte *inbuf, size_t inlen)
+sha1_write( SHA1_CONTEXT *hd, byte *inbuf, size_t inlen)
{
- if( hd->bufcount == 64 ) { /* flush the buffer */
- transform( hd, hd->buffer );
- hd->bufcount = 0;
+ if( hd->count == 64 ) { /* flush the buffer */
+ transform( hd, hd->buf );
+ hd->count = 0;
hd->nblocks++;
}
if( !inbuf )
return;
- if( hd->bufcount ) {
- for( ; inlen && hd->bufcount < 64; inlen-- )
- hd->buffer[hd->bufcount++] = *inbuf++;
+ if( hd->count ) {
+ for( ; inlen && hd->count < 64; inlen-- )
+ hd->buf[hd->count++] = *inbuf++;
sha1_write( hd, NULL, 0 );
if( !inlen )
return;
}
while( inlen >= 64 ) {
transform( hd, inbuf );
- hd->bufcount = 0;
+ hd->count = 0;
hd->nblocks++;
inlen -= 64;
inbuf += 64;
}
- for( ; inlen && hd->bufcount < 64; inlen-- )
- hd->buffer[hd->bufcount++] = *inbuf++;
+ for( ; inlen && hd->count < 64; inlen-- )
+ hd->buf[hd->count++] = *inbuf++;
}
/* The routine final terminates the computation and
* returns the digest.
* The handle is prepared for a new cycle, but adding bytes to the
* handle will the destroy the returned buffer.
* Returns: 20 bytes representing the digest.
*/
-byte *
-sha1_final(SHA1HANDLE hd)
+void
+sha1_final(SHA1_CONTEXT *hd)
{
u32 t, msb, lsb;
byte *p;
sha1_write(hd, NULL, 0); /* flush */;
msb = 0;
t = hd->nblocks;
if( (lsb = t << 6) < t ) /* multiply by 64 to make a byte count */
msb++;
msb += t >> 26;
t = lsb;
- if( (lsb = t + hd->bufcount) < t ) /* add the bufcount */
+ if( (lsb = t + hd->count) < t ) /* add the count */
msb++;
t = lsb;
if( (lsb = t << 3) < t ) /* multiply by 8 to make a bit count */
msb++;
msb += t >> 29;
- if( hd->bufcount < 56 ) { /* enough room */
- hd->buffer[hd->bufcount++] = 0x80; /* pad */
- while( hd->bufcount < 56 )
- hd->buffer[hd->bufcount++] = 0; /* pad */
+ if( hd->count < 56 ) { /* enough room */
+ hd->buf[hd->count++] = 0x80; /* pad */
+ while( hd->count < 56 )
+ hd->buf[hd->count++] = 0; /* pad */
}
else { /* need one extra block */
- hd->buffer[hd->bufcount++] = 0x80; /* pad character */
- while( hd->bufcount < 64 )
- hd->buffer[hd->bufcount++] = 0;
+ hd->buf[hd->count++] = 0x80; /* pad character */
+ while( hd->count < 64 )
+ hd->buf[hd->count++] = 0;
sha1_write(hd, NULL, 0); /* flush */;
- memset(hd->buffer, 0, 56 ); /* fill next block with zeroes */
+ memset(hd->buf, 0, 56 ); /* fill next block with zeroes */
}
/* append the 64 bit count */
- hd->buffer[56] = msb >> 24;
- hd->buffer[57] = msb >> 16;
- hd->buffer[58] = msb >> 8;
- hd->buffer[59] = msb ;
- hd->buffer[60] = lsb >> 24;
- hd->buffer[61] = lsb >> 16;
- hd->buffer[62] = lsb >> 8;
- hd->buffer[63] = lsb ;
- transform( hd, hd->buffer );
-
- p = hd->buffer;
+ hd->buf[56] = msb >> 24;
+ hd->buf[57] = msb >> 16;
+ hd->buf[58] = msb >> 8;
+ hd->buf[59] = msb ;
+ hd->buf[60] = lsb >> 24;
+ hd->buf[61] = lsb >> 16;
+ hd->buf[62] = lsb >> 8;
+ hd->buf[63] = lsb ;
+ transform( hd, hd->buf );
+
+ p = hd->buf;
#ifdef BIG_ENDIAN_HOST
#define X(a) do { *(u32*)p = hd->h##a ; p += 4; } while(0)
#else /* little endian */
#define X(a) do { *p++ = hd->h##a >> 24; *p++ = hd->h##a >> 16; \
*p++ = hd->h##a >> 8; *p++ = hd->h##a; } while(0)
#endif
X(0);
X(1);
X(2);
X(3);
X(4);
#undef X
- initialize( hd ); /* prepare for next cycle */
- return hd->buffer; /* now contains the digest */
}
diff --git a/cipher/sha1.h b/cipher/sha1.h
index ca03936f..93af2cac 100644
--- a/cipher/sha1.h
+++ b/cipher/sha1.h
@@ -1,50 +1,38 @@
/* sha1.h - SHA1 hash function
* Copyright (c) 1997 by Werner Koch (dd9jn)
*
* This file is part of G10.
*
* G10 is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* G10 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifndef G10_SHA1_H
#define G10_SHA1_H
#include "types.h"
typedef struct {
u32 h0,h1,h2,h3,h4;
u32 nblocks;
- byte buffer[64];
- int bufcount;
-} *SHA1HANDLE;
+ byte buf[64];
+ int count;
+} SHA1_CONTEXT;
-/****************
- * Process a single character, this character will be buffered to
- * increase performance.
- */
-#define sha1_putchar(h,c) \
- do { \
- if( (h)->bufcount == 64 ) \
- sha1_write( (h), NULL, 0 ); \
- (h)->buffer[(h)->bufcount++] = (c) & 0xff; \
- } while(0)
-
-SHA1HANDLE sha1_open( int secure );
-SHA1HANDLE sha1_copy( SHA1HANDLE a );
-void sha1_close( SHA1HANDLE hd );
-void sha1_write( SHA1HANDLE hd, byte *inbuf, size_t inlen );
-byte * sha1_final( SHA1HANDLE hd );
+void sha1_init( SHA1_CONTEXT *c );
+void sha1_write( SHA1_CONTEXT *hd, byte *inbuf, size_t inlen);
+void sha1_final( SHA1_CONTEXT *hd);
+#define sha1_read(h) ( (h)->buf )
#endif /*G10_SHA1_H*/
diff --git a/mpi/config.links b/mpi/config.links
index 9ee1d056..fd580e51 100644
--- a/mpi/config.links
+++ b/mpi/config.links
@@ -1,113 +1,131 @@
# sourced my ../configure to get the list of files to link
# this should set $mpi_ln_src and mpi_ln_dst.
# Note: this is called from the above directory.
mpi_extra_modules=
echo '/* created by config.links - do not edit */' >./mpi/asm-syntax.h
case "${target}" in
i[345]86*-*-linuxaout* | i[345]86*-*-linuxoldld* | i[345]86*-*-*bsd*)
echo '#define BSD_SYNTAX' >>./mpi/asm-syntax.h
echo '#include "./i386/syntax.h"' >>./mpi/asm-syntax.h
path="i386"
;;
i[56]86*-*-linuxaout* | i[56]86*-*-linuxoldld* | i[56]86*-*-*bsd*)
echo '#define BSD_SYNTAX' >>./mpi/asm-syntax.h
echo '#include "./i386/syntax.h"' >>./mpi/asm-syntax.h
path="i586 i386"
;;
i[3456]86*-*-*)
echo '#define ELF_SYNTAX' >>./mpi/asm-syntax.h
echo '#include "./i386/syntax.h"' >>./mpi/asm-syntax.h
path="i386"
;;
i[56]86*-*-* | pentium-*-* | pentiumpro-*-*)
echo '#define ELF_SYNTAX' >>./mpi/asm-syntax.h
echo '#include "./i586/syntax.h"' >>./mpi/asm-syntax.h
path="i586 i386"
;;
alpha*-*-*)
echo '/* configured for alpha */' >>./mpi/asm-syntax.h
path="alpha"
mpi_extra_modules="udiv-qrnnd"
;;
hppa7000*-*-*)
echo '/* configured for HPPA (pa7000) */' >>./mpi/asm-syntax.h
path="hppa1_1 hppa"
mpi_extra_modules="udiv-qrnnd"
;;
hppa1.0*-*-*)
echo '/* configured for HPPA 1.0 */' >>./mpi/asm-syntax.h
path="hppa"
mpi_extra_modules="udiv-qrnnd"
;;
hppa*-*-*) # assume pa7100
echo '/* configured for HPPA (pa7100) */' >>./mpi/asm-syntax.h
path="pa7100 hppa1_1 hppa"
mpi_extra_modules="udiv-qrnnd"
;;
+ sparc9*-*-* | sparc64*-*-* | ultrasparc*-*-*)
+ echo '/* configured for sparc9 or higher */' >>./mpi/asm-syntax.h
+ path="sparc32v8 sparc32"
+ ;;
+ sparc8*-*-* | microsparc*-*-*)
+ echo '/* configured for sparc8 */' >>./mpi/asm-syntax.h
+ path="sparc32v8"
+ ;;
+ supersparc*-*-*)
+ echo '/* configured for supersparc */' >>./mpi/asm-syntax.h
+ path="supersparc sparc32v8 sparc32"
+ mpi_extra_modules="udiv"
+ ;;
+ sparc*-*-*)
+ echo '/* configured for sparc */' >>./mpi/asm-syntax.h
+ path="sparc32"
+ mpi_extra_modules="udiv"
+ ;;
*)
echo '/* No assembler modules configured */' >>./mpi/asm-syntax.h
path=""
;;
esac
case "${target}" in
*-*-linuxaout* | *-*-linuxoldld*)
needs_underscore="y"
;;
*-*-linux* | *-sysv* | *-solaris* | *-gnu*)
needs_underscore="n"
;;
*)
needs_underscore="y"
;;
esac
# Make sysdep.h
echo '/* created by config.links - do not edit */' >./mpi/sysdep.h
if test "$needs_underscore" = "y" ; then
cat <<EOF >>./mpi/sysdep.h
#if __STDC__
#define C_SYMBOL_NAME(name) _##name
#else
#define C_SYMBOL_NAME(name) _/**/name
#endif
EOF
else
cat <<EOF >>./mpi/sysdep.h
#define C_SYMBOL_NAME(name) name
EOF
fi
# fixme: grep these modules from Makefile.in
mpi_ln_modules="${mpi_extra_modules} mpih-add1 mpih-mul1 mpih-mul2 mpih-mul3 \
mpih-shift mpih-sub1"
mpi_ln_objects=
mpi_ln_src=
mpi_ln_dst=
# try to get file to link from the assembler subdirectory and
# if this fails get it from the generic subdirectory.
path="$path generic"
for fn in $mpi_ln_modules ; do
mpi_ln_objects="$mpi_ln_objects $fn.o"
for dir in $path ; do
rm -f ./mpi/$fn.[Sc]
if test -f ./mpi/$dir/$fn.S ; then
mpi_ln_src="$mpi_ln_src mpi/$dir/$fn.S"
mpi_ln_dst="$mpi_ln_dst mpi/$fn.S"
break;
elif test -f ./mpi/$dir/$fn.c ; then
mpi_ln_src="$mpi_ln_src mpi/$dir/$fn.c"
mpi_ln_dst="$mpi_ln_dst mpi/$fn.c"
break;
fi
done
done
diff --git a/mpi/sparc32/distfiles b/mpi/sparc32/distfiles
new file mode 100644
index 00000000..7933edc8
--- /dev/null
+++ b/mpi/sparc32/distfiles
@@ -0,0 +1,4 @@
+
+mpih-add1.S
+udiv.S
+
diff --git a/mpi/sparc32/mpih-add1.S b/mpi/sparc32/mpih-add1.S
new file mode 100644
index 00000000..04315d10
--- /dev/null
+++ b/mpi/sparc32/mpih-add1.S
@@ -0,0 +1,237 @@
+! SPARC __mpn_add_n -- Add two limb vectors of the same length > 0 and store
+! sum in a third limb vector.
+
+! Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+
+! This file is part of the GNU MP Library.
+
+! The GNU MP Library is free software; you can redistribute it and/or modify
+! it under the terms of the GNU Library General Public License as published by
+! the Free Software Foundation; either version 2 of the License, or (at your
+! option) any later version.
+
+! The GNU MP Library is distributed in the hope that it will be useful, but
+! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+! or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
+! License for more details.
+
+! You should have received a copy of the GNU Library General Public License
+! along with the GNU MP Library; see the file COPYING.LIB. If not, write to
+! the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+! MA 02111-1307, USA.
+
+
+/*******************
+ * mpi_limb_t
+ * mpihelp_add_n( mpi_ptr_t res_ptr,
+ * mpi_ptr_t s1_ptr,
+ * mpi_ptr_t s2_ptr,
+ * mpi_size_t size)
+ */
+
+! INPUT PARAMETERS
+#define res_ptr %o0
+#define s1_ptr %o1
+#define s2_ptr %o2
+#define size %o3
+
+#include "sysdep.h"
+
+ .text
+ .align 4
+ .global C_SYMBOL_NAME(mpihelp_add_n)
+C_SYMBOL_NAME(mpihelp_add_n):
+ xor s2_ptr,res_ptr,%g1
+ andcc %g1,4,%g0
+ bne L1 ! branch if alignment differs
+ nop
+! ** V1a **
+L0: andcc res_ptr,4,%g0 ! res_ptr unaligned? Side effect: cy=0
+ be L_v1 ! if no, branch
+ nop
+/* Add least significant limb separately to align res_ptr and s2_ptr */
+ ld [s1_ptr],%g4
+ add s1_ptr,4,s1_ptr
+ ld [s2_ptr],%g2
+ add s2_ptr,4,s2_ptr
+ add size,-1,size
+ addcc %g4,%g2,%o4
+ st %o4,[res_ptr]
+ add res_ptr,4,res_ptr
+L_v1: addx %g0,%g0,%o4 ! save cy in register
+ cmp size,2 ! if size < 2 ...
+ bl Lend2 ! ... branch to tail code
+ subcc %g0,%o4,%g0 ! restore cy
+
+ ld [s1_ptr+0],%g4
+ addcc size,-10,size
+ ld [s1_ptr+4],%g1
+ ldd [s2_ptr+0],%g2
+ blt Lfin1
+ subcc %g0,%o4,%g0 ! restore cy
+/* Add blocks of 8 limbs until less than 8 limbs remain */
+Loop1: addxcc %g4,%g2,%o4
+ ld [s1_ptr+8],%g4
+ addxcc %g1,%g3,%o5
+ ld [s1_ptr+12],%g1
+ ldd [s2_ptr+8],%g2
+ std %o4,[res_ptr+0]
+ addxcc %g4,%g2,%o4
+ ld [s1_ptr+16],%g4
+ addxcc %g1,%g3,%o5
+ ld [s1_ptr+20],%g1
+ ldd [s2_ptr+16],%g2
+ std %o4,[res_ptr+8]
+ addxcc %g4,%g2,%o4
+ ld [s1_ptr+24],%g4
+ addxcc %g1,%g3,%o5
+ ld [s1_ptr+28],%g1
+ ldd [s2_ptr+24],%g2
+ std %o4,[res_ptr+16]
+ addxcc %g4,%g2,%o4
+ ld [s1_ptr+32],%g4
+ addxcc %g1,%g3,%o5
+ ld [s1_ptr+36],%g1
+ ldd [s2_ptr+32],%g2
+ std %o4,[res_ptr+24]
+ addx %g0,%g0,%o4 ! save cy in register
+ addcc size,-8,size
+ add s1_ptr,32,s1_ptr
+ add s2_ptr,32,s2_ptr
+ add res_ptr,32,res_ptr
+ bge Loop1
+ subcc %g0,%o4,%g0 ! restore cy
+
+Lfin1: addcc size,8-2,size
+ blt Lend1
+ subcc %g0,%o4,%g0 ! restore cy
+/* Add blocks of 2 limbs until less than 2 limbs remain */
+Loope1: addxcc %g4,%g2,%o4
+ ld [s1_ptr+8],%g4
+ addxcc %g1,%g3,%o5
+ ld [s1_ptr+12],%g1
+ ldd [s2_ptr+8],%g2
+ std %o4,[res_ptr+0]
+ addx %g0,%g0,%o4 ! save cy in register
+ addcc size,-2,size
+ add s1_ptr,8,s1_ptr
+ add s2_ptr,8,s2_ptr
+ add res_ptr,8,res_ptr
+ bge Loope1
+ subcc %g0,%o4,%g0 ! restore cy
+Lend1: addxcc %g4,%g2,%o4
+ addxcc %g1,%g3,%o5
+ std %o4,[res_ptr+0]
+ addx %g0,%g0,%o4 ! save cy in register
+
+ andcc size,1,%g0
+ be Lret1
+ subcc %g0,%o4,%g0 ! restore cy
+/* Add last limb */
+ ld [s1_ptr+8],%g4
+ ld [s2_ptr+8],%g2
+ addxcc %g4,%g2,%o4
+ st %o4,[res_ptr+8]
+
+Lret1: retl
+ addx %g0,%g0,%o0 ! return carry-out from most sign. limb
+
+L1: xor s1_ptr,res_ptr,%g1
+ andcc %g1,4,%g0
+ bne L2
+ nop
+! ** V1b **
+ mov s2_ptr,%g1
+ mov s1_ptr,s2_ptr
+ b L0
+ mov %g1,s1_ptr
+
+! ** V2 **
+/* If we come here, the alignment of s1_ptr and res_ptr as well as the
+ alignment of s2_ptr and res_ptr differ. Since there are only two ways
+ things can be aligned (that we care about) we now know that the alignment
+ of s1_ptr and s2_ptr are the same. */
+
+L2: cmp size,1
+ be Ljone
+ nop
+ andcc s1_ptr,4,%g0 ! s1_ptr unaligned? Side effect: cy=0
+ be L_v2 ! if no, branch
+ nop
+/* Add least significant limb separately to align s1_ptr and s2_ptr */
+ ld [s1_ptr],%g4
+ add s1_ptr,4,s1_ptr
+ ld [s2_ptr],%g2
+ add s2_ptr,4,s2_ptr
+ add size,-1,size
+ addcc %g4,%g2,%o4
+ st %o4,[res_ptr]
+ add res_ptr,4,res_ptr
+
+L_v2: addx %g0,%g0,%o4 ! save cy in register
+ addcc size,-8,size
+ blt Lfin2
+ subcc %g0,%o4,%g0 ! restore cy
+/* Add blocks of 8 limbs until less than 8 limbs remain */
+Loop2: ldd [s1_ptr+0],%g2
+ ldd [s2_ptr+0],%o4
+ addxcc %g2,%o4,%g2
+ st %g2,[res_ptr+0]
+ addxcc %g3,%o5,%g3
+ st %g3,[res_ptr+4]
+ ldd [s1_ptr+8],%g2
+ ldd [s2_ptr+8],%o4
+ addxcc %g2,%o4,%g2
+ st %g2,[res_ptr+8]
+ addxcc %g3,%o5,%g3
+ st %g3,[res_ptr+12]
+ ldd [s1_ptr+16],%g2
+ ldd [s2_ptr+16],%o4
+ addxcc %g2,%o4,%g2
+ st %g2,[res_ptr+16]
+ addxcc %g3,%o5,%g3
+ st %g3,[res_ptr+20]
+ ldd [s1_ptr+24],%g2
+ ldd [s2_ptr+24],%o4
+ addxcc %g2,%o4,%g2
+ st %g2,[res_ptr+24]
+ addxcc %g3,%o5,%g3
+ st %g3,[res_ptr+28]
+ addx %g0,%g0,%o4 ! save cy in register
+ addcc size,-8,size
+ add s1_ptr,32,s1_ptr
+ add s2_ptr,32,s2_ptr
+ add res_ptr,32,res_ptr
+ bge Loop2
+ subcc %g0,%o4,%g0 ! restore cy
+
+Lfin2: addcc size,8-2,size
+ blt Lend2
+ subcc %g0,%o4,%g0 ! restore cy
+Loope2: ldd [s1_ptr+0],%g2
+ ldd [s2_ptr+0],%o4
+ addxcc %g2,%o4,%g2
+ st %g2,[res_ptr+0]
+ addxcc %g3,%o5,%g3
+ st %g3,[res_ptr+4]
+ addx %g0,%g0,%o4 ! save cy in register
+ addcc size,-2,size
+ add s1_ptr,8,s1_ptr
+ add s2_ptr,8,s2_ptr
+ add res_ptr,8,res_ptr
+ bge Loope2
+ subcc %g0,%o4,%g0 ! restore cy
+Lend2: andcc size,1,%g0
+ be Lret2
+ subcc %g0,%o4,%g0 ! restore cy
+/* Add last limb */
+Ljone: ld [s1_ptr],%g4
+ ld [s2_ptr],%g2
+ addxcc %g4,%g2,%o4
+ st %o4,[res_ptr]
+
+Lret2: retl
+ addx %g0,%g0,%o0 ! return carry-out from most sign. limb
+
+
+
diff --git a/mpi/sparc32/udiv.S b/mpi/sparc32/udiv.S
new file mode 100644
index 00000000..3e2376cf
--- /dev/null
+++ b/mpi/sparc32/udiv.S
@@ -0,0 +1,188 @@
+! SPARC v7 __udiv_qrnnd division support, used from longlong.h.
+! This is for v7 CPUs without a floating-point unit.
+
+! Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
+
+! This file is part of the GNU MP Library.
+
+! The GNU MP Library is free software; you can redistribute it and/or modify
+! it under the terms of the GNU Library General Public License as published by
+! the Free Software Foundation; either version 2 of the License, or (at your
+! option) any later version.
+
+! The GNU MP Library is distributed in the hope that it will be useful, but
+! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+! or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
+! License for more details.
+
+! You should have received a copy of the GNU Library General Public License
+! along with the GNU MP Library; see the file COPYING.LIB. If not, write to
+! the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+! MA 02111-1307, USA.
+
+
+! INPUT PARAMETERS
+! rem_ptr o0
+! n1 o1
+! n0 o2
+! d o3
+
+#include "sysdep.h"
+
+ .text
+ .align 4
+ .global C_SYMBOL_NAME(__udiv_qrnnd)
+C_SYMBOL_NAME(__udiv_qrnnd):
+ tst %o3
+ bneg Largedivisor
+ mov 8,%g1
+
+ b Lp1
+ addxcc %o2,%o2,%o2
+
+Lplop: bcc Ln1
+ addxcc %o2,%o2,%o2
+Lp1: addx %o1,%o1,%o1
+ subcc %o1,%o3,%o4
+ bcc Ln2
+ addxcc %o2,%o2,%o2
+Lp2: addx %o1,%o1,%o1
+ subcc %o1,%o3,%o4
+ bcc Ln3
+ addxcc %o2,%o2,%o2
+Lp3: addx %o1,%o1,%o1
+ subcc %o1,%o3,%o4
+ bcc Ln4
+ addxcc %o2,%o2,%o2
+Lp4: addx %o1,%o1,%o1
+ addcc %g1,-1,%g1
+ bne Lplop
+ subcc %o1,%o3,%o4
+ bcc Ln5
+ addxcc %o2,%o2,%o2
+Lp5: st %o1,[%o0]
+ retl
+ xnor %g0,%o2,%o0
+
+Lnlop: bcc Lp1
+ addxcc %o2,%o2,%o2
+Ln1: addx %o4,%o4,%o4
+ subcc %o4,%o3,%o1
+ bcc Lp2
+ addxcc %o2,%o2,%o2
+Ln2: addx %o4,%o4,%o4
+ subcc %o4,%o3,%o1
+ bcc Lp3
+ addxcc %o2,%o2,%o2
+Ln3: addx %o4,%o4,%o4
+ subcc %o4,%o3,%o1
+ bcc Lp4
+ addxcc %o2,%o2,%o2
+Ln4: addx %o4,%o4,%o4
+ addcc %g1,-1,%g1
+ bne Lnlop
+ subcc %o4,%o3,%o1
+ bcc Lp5
+ addxcc %o2,%o2,%o2
+Ln5: st %o4,[%o0]
+ retl
+ xnor %g0,%o2,%o0
+
+Largedivisor:
+ and %o2,1,%o5 ! %o5 = n0 & 1
+
+ srl %o2,1,%o2
+ sll %o1,31,%g2
+ or %g2,%o2,%o2 ! %o2 = lo(n1n0 >> 1)
+ srl %o1,1,%o1 ! %o1 = hi(n1n0 >> 1)
+
+ and %o3,1,%g2
+ srl %o3,1,%g3 ! %g3 = floor(d / 2)
+ add %g3,%g2,%g3 ! %g3 = ceil(d / 2)
+
+ b LLp1
+ addxcc %o2,%o2,%o2
+
+LLplop: bcc LLn1
+ addxcc %o2,%o2,%o2
+LLp1: addx %o1,%o1,%o1
+ subcc %o1,%g3,%o4
+ bcc LLn2
+ addxcc %o2,%o2,%o2
+LLp2: addx %o1,%o1,%o1
+ subcc %o1,%g3,%o4
+ bcc LLn3
+ addxcc %o2,%o2,%o2
+LLp3: addx %o1,%o1,%o1
+ subcc %o1,%g3,%o4
+ bcc LLn4
+ addxcc %o2,%o2,%o2
+LLp4: addx %o1,%o1,%o1
+ addcc %g1,-1,%g1
+ bne LLplop
+ subcc %o1,%g3,%o4
+ bcc LLn5
+ addxcc %o2,%o2,%o2
+LLp5: add %o1,%o1,%o1 ! << 1
+ tst %g2
+ bne Oddp
+ add %o5,%o1,%o1
+ st %o1,[%o0]
+ retl
+ xnor %g0,%o2,%o0
+
+LLnlop: bcc LLp1
+ addxcc %o2,%o2,%o2
+LLn1: addx %o4,%o4,%o4
+ subcc %o4,%g3,%o1
+ bcc LLp2
+ addxcc %o2,%o2,%o2
+LLn2: addx %o4,%o4,%o4
+ subcc %o4,%g3,%o1
+ bcc LLp3
+ addxcc %o2,%o2,%o2
+LLn3: addx %o4,%o4,%o4
+ subcc %o4,%g3,%o1
+ bcc LLp4
+ addxcc %o2,%o2,%o2
+LLn4: addx %o4,%o4,%o4
+ addcc %g1,-1,%g1
+ bne LLnlop
+ subcc %o4,%g3,%o1
+ bcc LLp5
+ addxcc %o2,%o2,%o2
+LLn5: add %o4,%o4,%o4 ! << 1
+ tst %g2
+ bne Oddn
+ add %o5,%o4,%o4
+ st %o4,[%o0]
+ retl
+ xnor %g0,%o2,%o0
+
+Oddp: xnor %g0,%o2,%o2
+ ! q' in %o2. r' in %o1
+ addcc %o1,%o2,%o1
+ bcc LLp6
+ addx %o2,0,%o2
+ sub %o1,%o3,%o1
+LLp6: subcc %o1,%o3,%g0
+ bcs LLp7
+ subx %o2,-1,%o2
+ sub %o1,%o3,%o1
+LLp7: st %o1,[%o0]
+ retl
+ mov %o2,%o0
+
+Oddn: xnor %g0,%o2,%o2
+ ! q' in %o2. r' in %o4
+ addcc %o4,%o2,%o4
+ bcc LLn6
+ addx %o2,0,%o2
+ sub %o4,%o3,%o4
+LLn6: subcc %o4,%o3,%g0
+ bcs LLn7
+ subx %o2,-1,%o2
+ sub %o4,%o3,%o4
+LLn7: st %o4,[%o0]
+ retl
+ mov %o2,%o0
diff --git a/mpi/sparc32v8/distfiles b/mpi/sparc32v8/distfiles
new file mode 100644
index 00000000..5789f35b
--- /dev/null
+++ b/mpi/sparc32v8/distfiles
@@ -0,0 +1,5 @@
+
+mpih-mul1.S
+mpih-mul2.S
+mpih-mul3.S
+
diff --git a/mpi/sparc32v8/mpih-mul1.S b/mpi/sparc32v8/mpih-mul1.S
new file mode 100644
index 00000000..8bc1db57
--- /dev/null
+++ b/mpi/sparc32v8/mpih-mul1.S
@@ -0,0 +1,101 @@
+! SPARC v8 __mpn_mul_1 -- Multiply a limb vector with a single limb and
+! store the product in a second limb vector.
+
+! Copyright (C) 1992, 1994, 1995 Free Software Foundation, Inc.
+
+! This file is part of the GNU MP Library.
+
+! The GNU MP Library is free software; you can redistribute it and/or modify
+! it under the terms of the GNU Library General Public License as published by
+! the Free Software Foundation; either version 2 of the License, or (at your
+! option) any later version.
+
+! The GNU MP Library is distributed in the hope that it will be useful, but
+! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+! or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
+! License for more details.
+
+! You should have received a copy of the GNU Library General Public License
+! along with the GNU MP Library; see the file COPYING.LIB. If not, write to
+! the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+! MA 02111-1307, USA.
+
+
+! INPUT PARAMETERS
+! res_ptr o0
+! s1_ptr o1
+! size o2
+! s2_limb o3
+
+#include "sysdep.h"
+
+.text
+ .align 8
+ .global C_SYMBOL_NAME(mpihelp_mul_1)
+C_SYMBOL_NAME(mpihelp_mul_1):
+ sll %o2,4,%g1
+ and %g1,(4-1)<<4,%g1
+#if PIC
+ mov %o7,%g4 ! Save return address register
+ call 1f
+ add %o7,LL-1f,%g3
+1: mov %g4,%o7 ! Restore return address register
+#else
+ sethi %hi(LL),%g3
+ or %g3,%lo(LL),%g3
+#endif
+ jmp %g3+%g1
+ ld [%o1+0],%o4 ! 1
+LL:
+LL00: add %o0,-4,%o0
+ add %o1,-4,%o1
+ b Loop00 /* 4, 8, 12, ... */
+ orcc %g0,%g0,%g2
+LL01: b Loop01 /* 1, 5, 9, ... */
+ orcc %g0,%g0,%g2
+ nop
+ nop
+LL10: add %o0,-12,%o0 /* 2, 6, 10, ... */
+ add %o1,4,%o1
+ b Loop10
+ orcc %g0,%g0,%g2
+ nop
+LL11: add %o0,-8,%o0 /* 3, 7, 11, ... */
+ add %o1,-8,%o1
+ b Loop11
+ orcc %g0,%g0,%g2
+
+Loop: addcc %g3,%g2,%g3 ! 1
+ ld [%o1+4],%o4 ! 2
+ st %g3,[%o0+0] ! 1
+ rd %y,%g2 ! 1
+Loop00: umul %o4,%o3,%g3 ! 2
+ addxcc %g3,%g2,%g3 ! 2
+ ld [%o1+8],%o4 ! 3
+ st %g3,[%o0+4] ! 2
+ rd %y,%g2 ! 2
+Loop11: umul %o4,%o3,%g3 ! 3
+ addxcc %g3,%g2,%g3 ! 3
+ ld [%o1+12],%o4 ! 4
+ add %o1,16,%o1
+ st %g3,[%o0+8] ! 3
+ rd %y,%g2 ! 3
+Loop10: umul %o4,%o3,%g3 ! 4
+ addxcc %g3,%g2,%g3 ! 4
+ ld [%o1+0],%o4 ! 1
+ st %g3,[%o0+12] ! 4
+ add %o0,16,%o0
+ rd %y,%g2 ! 4
+ addx %g0,%g2,%g2
+Loop01: addcc %o2,-4,%o2
+ bg Loop
+ umul %o4,%o3,%g3 ! 1
+
+ addcc %g3,%g2,%g3 ! 4
+ st %g3,[%o0+0] ! 4
+ rd %y,%g2 ! 4
+
+ retl
+ addx %g0,%g2,%o0
+
+
diff --git a/mpi/sparc32v8/mpih-mul2.S b/mpi/sparc32v8/mpih-mul2.S
new file mode 100644
index 00000000..9055f89e
--- /dev/null
+++ b/mpi/sparc32v8/mpih-mul2.S
@@ -0,0 +1,124 @@
+! SPARC v8 __mpn_addmul_1 -- Multiply a limb vector with a limb and
+! add the result to a second limb vector.
+
+! Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
+
+! This file is part of the GNU MP Library.
+
+! The GNU MP Library is free software; you can redistribute it and/or modify
+! it under the terms of the GNU Library General Public License as published by
+! the Free Software Foundation; either version 2 of the License, or (at your
+! option) any later version.
+
+! The GNU MP Library is distributed in the hope that it will be useful, but
+! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+! or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
+! License for more details.
+
+! You should have received a copy of the GNU Library General Public License
+! along with the GNU MP Library; see the file COPYING.LIB. If not, write to
+! the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+! MA 02111-1307, USA.
+
+
+! INPUT PARAMETERS
+! res_ptr o0
+! s1_ptr o1
+! size o2
+! s2_limb o3
+
+#include "sysdep.h"
+
+.text
+ .align 4
+ .global C_SYMBOL_NAME(mpihelp_addmul_1)
+C_SYMBOL_NAME(mpihelp_addmul_1):
+ orcc %g0,%g0,%g2
+ ld [%o1+0],%o4 ! 1
+
+ sll %o2,4,%g1
+ and %g1,(4-1)<<4,%g1
+#if PIC
+ mov %o7,%g4 ! Save return address register
+ call 1f
+ add %o7,LL-1f,%g3
+1: mov %g4,%o7 ! Restore return address register
+#else
+ sethi %hi(LL),%g3
+ or %g3,%lo(LL),%g3
+#endif
+ jmp %g3+%g1
+ nop
+LL:
+LL00: add %o0,-4,%o0
+ b Loop00 /* 4, 8, 12, ... */
+ add %o1,-4,%o1
+ nop
+LL01: b Loop01 /* 1, 5, 9, ... */
+ nop
+ nop
+ nop
+LL10: add %o0,-12,%o0 /* 2, 6, 10, ... */
+ b Loop10
+ add %o1,4,%o1
+ nop
+LL11: add %o0,-8,%o0 /* 3, 7, 11, ... */
+ b Loop11
+ add %o1,-8,%o1
+ nop
+
+1: addcc %g3,%g2,%g3 ! 1
+ ld [%o1+4],%o4 ! 2
+ rd %y,%g2 ! 1
+ addx %g0,%g2,%g2
+ ld [%o0+0],%g1 ! 2
+ addcc %g1,%g3,%g3
+ st %g3,[%o0+0] ! 1
+Loop00: umul %o4,%o3,%g3 ! 2
+ ld [%o0+4],%g1 ! 2
+ addxcc %g3,%g2,%g3 ! 2
+ ld [%o1+8],%o4 ! 3
+ rd %y,%g2 ! 2
+ addx %g0,%g2,%g2
+ nop
+ addcc %g1,%g3,%g3
+ st %g3,[%o0+4] ! 2
+Loop11: umul %o4,%o3,%g3 ! 3
+ addxcc %g3,%g2,%g3 ! 3
+ ld [%o1+12],%o4 ! 4
+ rd %y,%g2 ! 3
+ add %o1,16,%o1
+ addx %g0,%g2,%g2
+ ld [%o0+8],%g1 ! 2
+ addcc %g1,%g3,%g3
+ st %g3,[%o0+8] ! 3
+Loop10: umul %o4,%o3,%g3 ! 4
+ addxcc %g3,%g2,%g3 ! 4
+ ld [%o1+0],%o4 ! 1
+ rd %y,%g2 ! 4
+ addx %g0,%g2,%g2
+ ld [%o0+12],%g1 ! 2
+ addcc %g1,%g3,%g3
+ st %g3,[%o0+12] ! 4
+ add %o0,16,%o0
+ addx %g0,%g2,%g2
+Loop01: addcc %o2,-4,%o2
+ bg 1b
+ umul %o4,%o3,%g3 ! 1
+
+ addcc %g3,%g2,%g3 ! 4
+ rd %y,%g2 ! 4
+ addx %g0,%g2,%g2
+ ld [%o0+0],%g1 ! 2
+ addcc %g1,%g3,%g3
+ st %g3,[%o0+0] ! 4
+ addx %g0,%g2,%o0
+
+ retl
+ nop
+
+
+! umul, ld, addxcc, rd, st
+
+! umul, ld, addxcc, rd, ld, addcc, st, addx
+
diff --git a/mpi/sparc32v8/mpih-mul3.S b/mpi/sparc32v8/mpih-mul3.S
new file mode 100644
index 00000000..efd83de4
--- /dev/null
+++ b/mpi/sparc32v8/mpih-mul3.S
@@ -0,0 +1,60 @@
+! SPARC v8 __mpn_submul_1 -- Multiply a limb vector with a limb and
+! subtract the result from a second limb vector.
+
+! Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
+
+! This file is part of the GNU MP Library.
+
+! The GNU MP Library is free software; you can redistribute it and/or modify
+! it under the terms of the GNU Library General Public License as published by
+! the Free Software Foundation; either version 2 of the License, or (at your
+! option) any later version.
+
+! The GNU MP Library is distributed in the hope that it will be useful, but
+! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+! or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
+! License for more details.
+
+! You should have received a copy of the GNU Library General Public License
+! along with the GNU MP Library; see the file COPYING.LIB. If not, write to
+! the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+! MA 02111-1307, USA.
+
+
+! INPUT PARAMETERS
+! res_ptr o0
+! s1_ptr o1
+! size o2
+! s2_limb o3
+
+#include "sysdep.h"
+
+.text
+ .align 4
+ .global C_SYMBOL_NAME(mpihelp_submul_1)
+C_SYMBOL_NAME(mpihelp_submul_1):
+ sub %g0,%o2,%o2 ! negate ...
+ sll %o2,2,%o2 ! ... and scale size
+ sub %o1,%o2,%o1 ! o1 is offset s1_ptr
+ sub %o0,%o2,%g1 ! g1 is offset res_ptr
+
+ mov 0,%o0 ! clear cy_limb
+
+Loop: ld [%o1+%o2],%o4
+ ld [%g1+%o2],%g2
+ umul %o4,%o3,%o5
+ rd %y,%g3
+ addcc %o5,%o0,%o5
+ addx %g3,0,%o0
+ subcc %g2,%o5,%g2
+ addx %o0,0,%o0
+ st %g2,[%g1+%o2]
+
+ addcc %o2,4,%o2
+ bne Loop
+ nop
+
+ retl
+ nop
+
+
diff --git a/mpi/supersparc/distfiles b/mpi/supersparc/distfiles
new file mode 100644
index 00000000..5506c419
--- /dev/null
+++ b/mpi/supersparc/distfiles
@@ -0,0 +1,3 @@
+
+udiv.S
+
diff --git a/mpi/supersparc/udiv.S b/mpi/supersparc/udiv.S
new file mode 100644
index 00000000..07d904c7
--- /dev/null
+++ b/mpi/supersparc/udiv.S
@@ -0,0 +1,110 @@
+! SuperSPARC __udiv_qrnnd division support, used from longlong.h.
+! This is for SuperSPARC only, to compensate for its semi-functional
+! udiv instruction.
+
+! Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
+
+! This file is part of the GNU MP Library.
+
+! The GNU MP Library is free software; you can redistribute it and/or modify
+! it under the terms of the GNU Library General Public License as published by
+! the Free Software Foundation; either version 2 of the License, or (at your
+! option) any later version.
+
+! The GNU MP Library is distributed in the hope that it will be useful, but
+! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+! or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
+! License for more details.
+
+! You should have received a copy of the GNU Library General Public License
+! along with the GNU MP Library; see the file COPYING.LIB. If not, write to
+! the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+! MA 02111-1307, USA.
+
+
+! INPUT PARAMETERS
+! rem_ptr i0
+! n1 i1
+! n0 i2
+! d i3
+
+#include "sysdep.h"
+#undef ret /* Kludge for glibc */
+
+ .text
+ .align 8
+LC0: .double 0r4294967296
+LC1: .double 0r2147483648
+
+ .align 4
+ .global C_SYMBOL_NAME(__udiv_qrnnd)
+C_SYMBOL_NAME(__udiv_qrnnd):
+ !#PROLOGUE# 0
+ save %sp,-104,%sp
+ !#PROLOGUE# 1
+ st %i1,[%fp-8]
+ ld [%fp-8],%f10
+ sethi %hi(LC0),%o7
+ fitod %f10,%f4
+ ldd [%o7+%lo(LC0)],%f8
+ cmp %i1,0
+ bge L248
+ mov %i0,%i5
+ faddd %f4,%f8,%f4
+L248:
+ st %i2,[%fp-8]
+ ld [%fp-8],%f10
+ fmuld %f4,%f8,%f6
+ cmp %i2,0
+ bge L249
+ fitod %f10,%f2
+ faddd %f2,%f8,%f2
+L249:
+ st %i3,[%fp-8]
+ faddd %f6,%f2,%f2
+ ld [%fp-8],%f10
+ cmp %i3,0
+ bge L250
+ fitod %f10,%f4
+ faddd %f4,%f8,%f4
+L250:
+ fdivd %f2,%f4,%f2
+ sethi %hi(LC1),%o7
+ ldd [%o7+%lo(LC1)],%f4
+ fcmped %f2,%f4
+ nop
+ fbge,a L251
+ fsubd %f2,%f4,%f2
+ fdtoi %f2,%f2
+ st %f2,[%fp-8]
+ b L252
+ ld [%fp-8],%i4
+L251:
+ fdtoi %f2,%f2
+ st %f2,[%fp-8]
+ ld [%fp-8],%i4
+ sethi %hi(-2147483648),%g2
+ xor %i4,%g2,%i4
+L252:
+ umul %i3,%i4,%g3
+ rd %y,%i0
+ subcc %i2,%g3,%o7
+ subxcc %i1,%i0,%g0
+ be L253
+ cmp %o7,%i3
+
+ add %i4,-1,%i0
+ add %o7,%i3,%o7
+ st %o7,[%i5]
+ ret
+ restore
+L253:
+ blu L246
+ mov %i4,%i0
+ add %i4,1,%i0
+ sub %o7,%i3,%o7
+L246:
+ st %o7,[%i5]
+ ret
+ restore
+

File Metadata

Mime Type
text/x-diff
Expires
Tue, Jul 8, 12:35 PM (5 h, 5 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
6e/51/bb768f9b5c7d7ba52034df9966fd

Event Timeline