Pull in RIPEMD-160 functions from OpenBSD - this has the same API as our MD4,
MD5 and SHA1 stuff.
This commit is contained in:
parent
e402955a88
commit
90517b417b
@ -1,4 +1,4 @@
|
||||
# $NetBSD: Makefile,v 1.91 2000/06/20 06:00:32 thorpej Exp $
|
||||
# $NetBSD: Makefile,v 1.92 2000/07/05 11:44:01 ad Exp $
|
||||
# @(#)Makefile 8.2 (Berkeley) 1/4/94
|
||||
|
||||
# Doing a make includes builds /usr/include
|
||||
@ -14,10 +14,10 @@ INCS= a.out.h ar.h assert.h bitstring.h bm.h cpio.h ctype.h db.h dirent.h \
|
||||
memory.h mpool.h ndbm.h netconfig.h netdb.h netgroup.h nlist.h \
|
||||
nl_types.h \
|
||||
nsswitch.h paths.h pwd.h ranlib.h re_comp.h regex.h regexp.h \
|
||||
resolv.h rmt.h search.h setjmp.h sgtty.h signal.h stab.h stddef.h \
|
||||
stdio.h stdlib.h string.h strings.h stringlist.h struct.h sysexits.h \
|
||||
tar.h time.h ttyent.h tzfile.h ulimit.h unistd.h util.h utime.h \
|
||||
utmp.h vis.h wchar.h
|
||||
resolv.h rmd160.h rmt.h search.h setjmp.h sgtty.h signal.h stab.h \
|
||||
stddef.h stdio.h stdlib.h string.h strings.h stringlist.h struct.h \
|
||||
sysexits.h tar.h time.h ttyent.h tzfile.h ulimit.h unistd.h util.h \
|
||||
utime.h utmp.h vis.h wchar.h
|
||||
INCS+= arpa/ftp.h arpa/inet.h arpa/nameser.h arpa/telnet.h arpa/tftp.h
|
||||
INCS+= protocols/dumprestore.h protocols/routed.h protocols/rwhod.h \
|
||||
protocols/talkd.h protocols/timed.h
|
||||
|
47
include/rmd160.h
Normal file
47
include/rmd160.h
Normal file
@ -0,0 +1,47 @@
|
||||
/* $NetBSD: rmd160.h,v 1.1 2000/07/05 11:44:01 ad Exp $ */
|
||||
|
||||
/********************************************************************\
|
||||
*
|
||||
* FILE: rmd160.h
|
||||
*
|
||||
* CONTENTS: Header file for a sample C-implementation of the
|
||||
* RIPEMD-160 hash-function.
|
||||
* TARGET: any computer with an ANSI C compiler
|
||||
*
|
||||
* AUTHOR: Antoon Bosselaers, ESAT-COSIC
|
||||
* DATE: 1 March 1996
|
||||
* VERSION: 1.0
|
||||
*
|
||||
* Copyright (c) Katholieke Universiteit Leuven
|
||||
* 1996, All Rights Reserved
|
||||
*
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* from OpenBSD: rmd160.h,v 1.4 1999/08/16 09:59:04 millert Exp
|
||||
*/
|
||||
|
||||
#ifndef _RMD160_H_
|
||||
#define _RMD160_H_
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
typedef struct {
|
||||
u_int32_t state[5]; /* state (ABCDE) */
|
||||
u_int32_t length[2]; /* number of bits */
|
||||
u_char bbuffer[64]; /* overflow buffer */
|
||||
u_int32_t buflen; /* number of chars in bbuffer */
|
||||
} RMD160_CTX;
|
||||
|
||||
__BEGIN_DECLS
|
||||
void RMD160Init(RMD160_CTX *);
|
||||
void RMD160Transform(u_int32_t[5], const u_int32_t[16]);
|
||||
void RMD160Update(RMD160_CTX *, const u_char *, u_int32_t);
|
||||
void RMD160Final(u_char[20], RMD160_CTX *);
|
||||
char *RMD160End(RMD160_CTX *, char *);
|
||||
char *RMD160File(char *, char *);
|
||||
char *RMD160Data(const u_char *, size_t, char *);
|
||||
__END_DECLS
|
||||
|
||||
#endif /* !_RMD160_H_ */
|
@ -1,14 +1,19 @@
|
||||
# $NetBSD: Makefile.inc,v 1.2 1999/02/24 15:05:20 drochner Exp $
|
||||
# $NetBSD: Makefile.inc,v 1.3 2000/07/05 11:44:03 ad Exp $
|
||||
# $OpenBSD: Makefile.inc,v 1.5 1997/07/17 06:02:42 millert Exp $
|
||||
|
||||
# hash functions
|
||||
.PATH: ${ARCHDIR}/hash ${.CURDIR}/hash
|
||||
|
||||
SRCS+= sha1.c sha1hl.c
|
||||
SRCS+= rmd160.c rmd160l.c sha1.c sha1hl.c
|
||||
|
||||
MAN+= sha1.3
|
||||
MAN+= sha1.3 rmd160.3
|
||||
|
||||
MLINKS+=sha1.3 SHA1Init.3 sha1.3 SHA1Update.3
|
||||
MLINKS+=sha1.3 SHA1Final.3 sha1.3 SHA1Transform.3
|
||||
MLINKS+=sha1.3 SHA1End.3 sha1.3 SHA1File.3
|
||||
MLINKS+=sha1.3 SHA1Data.3
|
||||
|
||||
MLINKS+=rmd160.3 RMD160Init.3 rmd160.3 RMD160Update.3
|
||||
MLINKS+=rmd160.3 RMD160Final.3 rmd160.3 RMD160Transform.3
|
||||
MLINKS+=rmd160.3 RMD160End.3 rmd160.3 RMD160File.3
|
||||
MLINKS+=rmd160.3 RMD160Data.3
|
||||
|
224
lib/libc/hash/rmd160.3
Normal file
224
lib/libc/hash/rmd160.3
Normal file
@ -0,0 +1,224 @@
|
||||
.\" $OpenBSD: rmd160.3,v 1.12 2000/04/18 03:01:29 aaron Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
.\" 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, this list of conditions and the following disclaimer.
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" See http://www.esat.kuleuven.ac.be/~bosselae/ripemd160.html
|
||||
.\" for detailed information about RIPEMD-160.
|
||||
.\"
|
||||
.Dd July 16, 1997
|
||||
.Dt RMD160 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm RMD160Init ,
|
||||
.Nm RMD160Update ,
|
||||
.Nm RMD160Final ,
|
||||
.Nm RMD160Transform ,
|
||||
.Nm RMD160End ,
|
||||
.Nm RMD160File ,
|
||||
.Nm RMD160Data
|
||||
.Nd calculate the ``RIPEMD-160'' message digest
|
||||
.Sh SYNOPSIS
|
||||
.Fd #include <sys/types.h>
|
||||
.Fd #include <rmd160.h>
|
||||
.Ft void
|
||||
.Fn RMD160Init "RMD160_CTX *context"
|
||||
.Ft void
|
||||
.Fn RMD160Update "RMD160_CTX *context" "const u_char *data" "u_int nbytes"
|
||||
.Ft void
|
||||
.Fn RMD160Final "u_char digest[20]" "RMD160_CTX *context"
|
||||
.Ft void
|
||||
.Fn RMD160Transform "u_int32_t state[5]" "const u_int32_t block[16]"
|
||||
.Ft "char *"
|
||||
.Fn RMD160End "RMD160_CTX *context" "char *buf"
|
||||
.Ft "char *"
|
||||
.Fn RMD160File "char *filename" "char *buf"
|
||||
.Ft "char *"
|
||||
.Fn RMD160Data "u_char *data" "u_int len" "char *buf"
|
||||
.Sh DESCRIPTION
|
||||
The RMD160 functions implement the 160-bit RIPE message digest hash algorithm
|
||||
(RMD-160).
|
||||
RMD-160 is used to generate a condensed representation
|
||||
of a message called a message digest.
|
||||
The algorithm takes a
|
||||
message less than 2^64 bits as input and produces a 160-bit digest
|
||||
suitable for use as a digital signature.
|
||||
.Pp
|
||||
The RMD160 functions are considered to be more secure than the
|
||||
.Xr md4 3
|
||||
and
|
||||
.Xr md5 3
|
||||
functions and at least as secure as the
|
||||
.Xr sha1 3
|
||||
function.
|
||||
All share a similar interface.
|
||||
.Pp
|
||||
The
|
||||
.Fn RMD160Init
|
||||
function initializes a RMD160_CTX
|
||||
.Ar context
|
||||
for use with
|
||||
.Fn RMD160Update ,
|
||||
and
|
||||
.Fn RMD160Final .
|
||||
The
|
||||
.Fn RMD160Update
|
||||
function adds
|
||||
.Ar data
|
||||
of length
|
||||
.Ar nbytes
|
||||
to the RMD160_CTX specified by
|
||||
.Ar context .
|
||||
.Fn RMD160Final
|
||||
is called when all data has been added via
|
||||
.Fn RMD160Update
|
||||
and stores a message digest in the
|
||||
.Ar digest
|
||||
parameter.
|
||||
When a null pointer is passed to
|
||||
.Fn RMD160Final
|
||||
as first argument only the final padding will be applied and the
|
||||
current context can still be used with
|
||||
.Fn RMD160Update .
|
||||
.Pp
|
||||
The
|
||||
.Fn RMD160Transform
|
||||
function is used by
|
||||
.Fn RMD160Update
|
||||
to hash 512-bit blocks and forms the core of the algorithm.
|
||||
Most programs should use the interface provided by
|
||||
.Fn RMD160Init ,
|
||||
.Fn RMD160Update
|
||||
and
|
||||
.Fn RMD160Final
|
||||
instead of calling
|
||||
.Fn RMD160Transform
|
||||
directly.
|
||||
.Pp
|
||||
The
|
||||
.Fn RMD160End
|
||||
function is a front end for
|
||||
.Fn RMD160Final
|
||||
which converts the digest into an
|
||||
.Tn ASCII
|
||||
representation of the 160 bit digest in hexadecimal.
|
||||
.Pp
|
||||
The
|
||||
.Fn RMD160File
|
||||
function calculates the digest for a file and returns the result via
|
||||
.Fn RMD160End .
|
||||
If
|
||||
.Fn RMD160File
|
||||
is unable to open the file a NULL pointer is returned.
|
||||
.Pp
|
||||
The
|
||||
.Fn RMD160Data
|
||||
function
|
||||
calculates the digest of an arbitrary string and returns the result via
|
||||
.Fn RMD160End .
|
||||
.Pp
|
||||
For each of the
|
||||
.Fn RMD160End ,
|
||||
.Fn RMD160File ,
|
||||
and
|
||||
.Fn RMD160Data
|
||||
functions the
|
||||
.Ar buf
|
||||
parameter should either be a string of at least 41 characters in
|
||||
size or a NULL pointer.
|
||||
In the latter case, space will be dynamically allocated via
|
||||
.Xr malloc 3
|
||||
and should be freed using
|
||||
.Xr free 3
|
||||
when it is no longer needed.
|
||||
.Sh EXAMPLES
|
||||
The follow code fragment will calculate the digest for
|
||||
the string "abc" which is ``0x8eb208f7e05d987a9b044a8e98c6b087f15a0bfc''.
|
||||
.Bd -literal -offset indent
|
||||
RMD160_CTX rmd;
|
||||
u_char results[20];
|
||||
char *buf;
|
||||
int n;
|
||||
|
||||
buf = "abc";
|
||||
n = strlen(buf);
|
||||
RMD160Init(&rmd);
|
||||
RMD160Update(&rmd, (u_char *)buf, n);
|
||||
RMD160Final(results, &rmd);
|
||||
|
||||
/* Print the digest as one long hex value */
|
||||
printf("0x");
|
||||
for (n = 0; n < 20; n++)
|
||||
printf("%02x", results[n]);
|
||||
putchar('\\n');
|
||||
.Ed
|
||||
.Pp
|
||||
Alternately, the helper functions could be used in the following way:
|
||||
.Bd -literal -offset indent
|
||||
RMD160_CTX rmd;
|
||||
u_char output[41];
|
||||
char *buf = "abc";
|
||||
|
||||
printf("0x%s\en", RMD160Data(buf, strlen(buf), output));
|
||||
.Ed
|
||||
.Sh CAVEATS
|
||||
If a message digest is to be copied to a multi-byte type (ie:
|
||||
an array of five 32-bit integers) it will be necessary to
|
||||
perform byte swapping on little endian machines such as the i386, alpha,
|
||||
and vax.
|
||||
.Sh AUTHOR
|
||||
This implementation of RMD-160 was written by Antoon Bosselaers.
|
||||
.Pp
|
||||
The
|
||||
.Fn RMD160End ,
|
||||
.Fn RMD160File ,
|
||||
and
|
||||
.Fn RMD160Data
|
||||
helper functions are derived from code written by Poul-Henning Kamp.
|
||||
.Sh SEE ALSO
|
||||
.Xr rmd160 1 ,
|
||||
.Xr md4 3 ,
|
||||
.Xr md5 3 ,
|
||||
.Xr sha1 3
|
||||
.Pp
|
||||
.Rs
|
||||
.%A H. Dobbertin, A. Bosselaers, B. Preneel
|
||||
.%T RIPEMD-160, a strengthened version of RIPEMD
|
||||
.Re
|
||||
.Rs
|
||||
.%T Information technology - Security techniques - Hash-functions - Part 3: Dedicated hash-functions
|
||||
.%O ISO/IEC 10118-3
|
||||
.Re
|
||||
.Rs
|
||||
.%A H. Dobbertin, A. Bosselaers, B. Preneel
|
||||
.%T The RIPEMD-160 cryptographic hash function
|
||||
.%J Dr. Dobb's Journal
|
||||
.%V Vol. 22, No. 1
|
||||
.%D January 1997
|
||||
.%P pp. 24-28
|
||||
.Re
|
||||
.Sh HISTORY
|
||||
The RMD-160 functions appeared in
|
||||
.Ox 2.1 .
|
435
lib/libc/hash/rmd160.c
Normal file
435
lib/libc/hash/rmd160.c
Normal file
@ -0,0 +1,435 @@
|
||||
/* $NetBSD: rmd160.c,v 1.1 2000/07/05 11:44:03 ad Exp $ */
|
||||
|
||||
/********************************************************************\
|
||||
*
|
||||
* FILE: rmd160.c
|
||||
*
|
||||
* CONTENTS: A sample C-implementation of the RIPEMD-160
|
||||
* hash-function.
|
||||
* TARGET: any computer with an ANSI C compiler
|
||||
*
|
||||
* AUTHOR: Antoon Bosselaers, ESAT-COSIC
|
||||
* (Arranged for libc by Todd C. Miller)
|
||||
* DATE: 1 March 1996
|
||||
* VERSION: 1.0
|
||||
*
|
||||
* Copyright (c) Katholieke Universiteit Leuven
|
||||
* 1996, All Rights Reserved
|
||||
*
|
||||
\********************************************************************/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: rmd160.c,v 1.1 2000/07/05 11:44:03 ad Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
/* header files */
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <rmd160.h>
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
/* macro definitions */
|
||||
|
||||
/* collect four bytes into one word: */
|
||||
#define BYTES_TO_DWORD(strptr) \
|
||||
(((u_int32_t) *((strptr)+3) << 24) | \
|
||||
((u_int32_t) *((strptr)+2) << 16) | \
|
||||
((u_int32_t) *((strptr)+1) << 8) | \
|
||||
((u_int32_t) *(strptr)))
|
||||
|
||||
/* ROL(x, n) cyclically rotates x over n bits to the left */
|
||||
/* x must be of an unsigned 32 bits type and 0 <= n < 32. */
|
||||
#define ROL(x, n) (((x) << (n)) | ((x) >> (32-(n))))
|
||||
|
||||
/* the three basic functions F(), G() and H() */
|
||||
#define F(x, y, z) ((x) ^ (y) ^ (z))
|
||||
#define G(x, y, z) (((x) & (y)) | (~(x) & (z)))
|
||||
#define H(x, y, z) (((x) | ~(y)) ^ (z))
|
||||
#define I(x, y, z) (((x) & (z)) | ((y) & ~(z)))
|
||||
#define J(x, y, z) ((x) ^ ((y) | ~(z)))
|
||||
|
||||
/* the eight basic operations FF() through III() */
|
||||
#define FF(a, b, c, d, e, x, s) { \
|
||||
(a) += F((b), (c), (d)) + (x); \
|
||||
(a) = ROL((a), (s)) + (e); \
|
||||
(c) = ROL((c), 10); \
|
||||
}
|
||||
#define GG(a, b, c, d, e, x, s) { \
|
||||
(a) += G((b), (c), (d)) + (x) + 0x5a827999U; \
|
||||
(a) = ROL((a), (s)) + (e); \
|
||||
(c) = ROL((c), 10); \
|
||||
}
|
||||
#define HH(a, b, c, d, e, x, s) { \
|
||||
(a) += H((b), (c), (d)) + (x) + 0x6ed9eba1U; \
|
||||
(a) = ROL((a), (s)) + (e); \
|
||||
(c) = ROL((c), 10); \
|
||||
}
|
||||
#define II(a, b, c, d, e, x, s) { \
|
||||
(a) += I((b), (c), (d)) + (x) + 0x8f1bbcdcU; \
|
||||
(a) = ROL((a), (s)) + (e); \
|
||||
(c) = ROL((c), 10); \
|
||||
}
|
||||
#define JJ(a, b, c, d, e, x, s) { \
|
||||
(a) += J((b), (c), (d)) + (x) + 0xa953fd4eU; \
|
||||
(a) = ROL((a), (s)) + (e); \
|
||||
(c) = ROL((c), 10); \
|
||||
}
|
||||
#define FFF(a, b, c, d, e, x, s) { \
|
||||
(a) += F((b), (c), (d)) + (x); \
|
||||
(a) = ROL((a), (s)) + (e); \
|
||||
(c) = ROL((c), 10); \
|
||||
}
|
||||
#define GGG(a, b, c, d, e, x, s) { \
|
||||
(a) += G((b), (c), (d)) + (x) + 0x7a6d76e9U; \
|
||||
(a) = ROL((a), (s)) + (e); \
|
||||
(c) = ROL((c), 10); \
|
||||
}
|
||||
#define HHH(a, b, c, d, e, x, s) { \
|
||||
(a) += H((b), (c), (d)) + (x) + 0x6d703ef3U; \
|
||||
(a) = ROL((a), (s)) + (e); \
|
||||
(c) = ROL((c), 10); \
|
||||
}
|
||||
#define III(a, b, c, d, e, x, s) { \
|
||||
(a) += I((b), (c), (d)) + (x) + 0x5c4dd124U; \
|
||||
(a) = ROL((a), (s)) + (e); \
|
||||
(c) = ROL((c), 10); \
|
||||
}
|
||||
#define JJJ(a, b, c, d, e, x, s) { \
|
||||
(a) += J((b), (c), (d)) + (x) + 0x50a28be6U; \
|
||||
(a) = ROL((a), (s)) + (e); \
|
||||
(c) = ROL((c), 10); \
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
void
|
||||
RMD160Init(context)
|
||||
RMD160_CTX *context;
|
||||
{
|
||||
|
||||
/* ripemd-160 initialization constants */
|
||||
context->state[0] = 0x67452301U;
|
||||
context->state[1] = 0xefcdab89U;
|
||||
context->state[2] = 0x98badcfeU;
|
||||
context->state[3] = 0x10325476U;
|
||||
context->state[4] = 0xc3d2e1f0U;
|
||||
context->length[0] = context->length[1] = 0;
|
||||
context->buflen = 0;
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
void
|
||||
RMD160Transform(state, block)
|
||||
u_int32_t state[5];
|
||||
const u_int32_t block[16];
|
||||
{
|
||||
u_int32_t aa = state[0], bb = state[1], cc = state[2],
|
||||
dd = state[3], ee = state[4];
|
||||
u_int32_t aaa = state[0], bbb = state[1], ccc = state[2],
|
||||
ddd = state[3], eee = state[4];
|
||||
|
||||
/* round 1 */
|
||||
FF(aa, bb, cc, dd, ee, block[ 0], 11);
|
||||
FF(ee, aa, bb, cc, dd, block[ 1], 14);
|
||||
FF(dd, ee, aa, bb, cc, block[ 2], 15);
|
||||
FF(cc, dd, ee, aa, bb, block[ 3], 12);
|
||||
FF(bb, cc, dd, ee, aa, block[ 4], 5);
|
||||
FF(aa, bb, cc, dd, ee, block[ 5], 8);
|
||||
FF(ee, aa, bb, cc, dd, block[ 6], 7);
|
||||
FF(dd, ee, aa, bb, cc, block[ 7], 9);
|
||||
FF(cc, dd, ee, aa, bb, block[ 8], 11);
|
||||
FF(bb, cc, dd, ee, aa, block[ 9], 13);
|
||||
FF(aa, bb, cc, dd, ee, block[10], 14);
|
||||
FF(ee, aa, bb, cc, dd, block[11], 15);
|
||||
FF(dd, ee, aa, bb, cc, block[12], 6);
|
||||
FF(cc, dd, ee, aa, bb, block[13], 7);
|
||||
FF(bb, cc, dd, ee, aa, block[14], 9);
|
||||
FF(aa, bb, cc, dd, ee, block[15], 8);
|
||||
|
||||
/* round 2 */
|
||||
GG(ee, aa, bb, cc, dd, block[ 7], 7);
|
||||
GG(dd, ee, aa, bb, cc, block[ 4], 6);
|
||||
GG(cc, dd, ee, aa, bb, block[13], 8);
|
||||
GG(bb, cc, dd, ee, aa, block[ 1], 13);
|
||||
GG(aa, bb, cc, dd, ee, block[10], 11);
|
||||
GG(ee, aa, bb, cc, dd, block[ 6], 9);
|
||||
GG(dd, ee, aa, bb, cc, block[15], 7);
|
||||
GG(cc, dd, ee, aa, bb, block[ 3], 15);
|
||||
GG(bb, cc, dd, ee, aa, block[12], 7);
|
||||
GG(aa, bb, cc, dd, ee, block[ 0], 12);
|
||||
GG(ee, aa, bb, cc, dd, block[ 9], 15);
|
||||
GG(dd, ee, aa, bb, cc, block[ 5], 9);
|
||||
GG(cc, dd, ee, aa, bb, block[ 2], 11);
|
||||
GG(bb, cc, dd, ee, aa, block[14], 7);
|
||||
GG(aa, bb, cc, dd, ee, block[11], 13);
|
||||
GG(ee, aa, bb, cc, dd, block[ 8], 12);
|
||||
|
||||
/* round 3 */
|
||||
HH(dd, ee, aa, bb, cc, block[ 3], 11);
|
||||
HH(cc, dd, ee, aa, bb, block[10], 13);
|
||||
HH(bb, cc, dd, ee, aa, block[14], 6);
|
||||
HH(aa, bb, cc, dd, ee, block[ 4], 7);
|
||||
HH(ee, aa, bb, cc, dd, block[ 9], 14);
|
||||
HH(dd, ee, aa, bb, cc, block[15], 9);
|
||||
HH(cc, dd, ee, aa, bb, block[ 8], 13);
|
||||
HH(bb, cc, dd, ee, aa, block[ 1], 15);
|
||||
HH(aa, bb, cc, dd, ee, block[ 2], 14);
|
||||
HH(ee, aa, bb, cc, dd, block[ 7], 8);
|
||||
HH(dd, ee, aa, bb, cc, block[ 0], 13);
|
||||
HH(cc, dd, ee, aa, bb, block[ 6], 6);
|
||||
HH(bb, cc, dd, ee, aa, block[13], 5);
|
||||
HH(aa, bb, cc, dd, ee, block[11], 12);
|
||||
HH(ee, aa, bb, cc, dd, block[ 5], 7);
|
||||
HH(dd, ee, aa, bb, cc, block[12], 5);
|
||||
|
||||
/* round 4 */
|
||||
II(cc, dd, ee, aa, bb, block[ 1], 11);
|
||||
II(bb, cc, dd, ee, aa, block[ 9], 12);
|
||||
II(aa, bb, cc, dd, ee, block[11], 14);
|
||||
II(ee, aa, bb, cc, dd, block[10], 15);
|
||||
II(dd, ee, aa, bb, cc, block[ 0], 14);
|
||||
II(cc, dd, ee, aa, bb, block[ 8], 15);
|
||||
II(bb, cc, dd, ee, aa, block[12], 9);
|
||||
II(aa, bb, cc, dd, ee, block[ 4], 8);
|
||||
II(ee, aa, bb, cc, dd, block[13], 9);
|
||||
II(dd, ee, aa, bb, cc, block[ 3], 14);
|
||||
II(cc, dd, ee, aa, bb, block[ 7], 5);
|
||||
II(bb, cc, dd, ee, aa, block[15], 6);
|
||||
II(aa, bb, cc, dd, ee, block[14], 8);
|
||||
II(ee, aa, bb, cc, dd, block[ 5], 6);
|
||||
II(dd, ee, aa, bb, cc, block[ 6], 5);
|
||||
II(cc, dd, ee, aa, bb, block[ 2], 12);
|
||||
|
||||
/* round 5 */
|
||||
JJ(bb, cc, dd, ee, aa, block[ 4], 9);
|
||||
JJ(aa, bb, cc, dd, ee, block[ 0], 15);
|
||||
JJ(ee, aa, bb, cc, dd, block[ 5], 5);
|
||||
JJ(dd, ee, aa, bb, cc, block[ 9], 11);
|
||||
JJ(cc, dd, ee, aa, bb, block[ 7], 6);
|
||||
JJ(bb, cc, dd, ee, aa, block[12], 8);
|
||||
JJ(aa, bb, cc, dd, ee, block[ 2], 13);
|
||||
JJ(ee, aa, bb, cc, dd, block[10], 12);
|
||||
JJ(dd, ee, aa, bb, cc, block[14], 5);
|
||||
JJ(cc, dd, ee, aa, bb, block[ 1], 12);
|
||||
JJ(bb, cc, dd, ee, aa, block[ 3], 13);
|
||||
JJ(aa, bb, cc, dd, ee, block[ 8], 14);
|
||||
JJ(ee, aa, bb, cc, dd, block[11], 11);
|
||||
JJ(dd, ee, aa, bb, cc, block[ 6], 8);
|
||||
JJ(cc, dd, ee, aa, bb, block[15], 5);
|
||||
JJ(bb, cc, dd, ee, aa, block[13], 6);
|
||||
|
||||
/* parallel round 1 */
|
||||
JJJ(aaa, bbb, ccc, ddd, eee, block[ 5], 8);
|
||||
JJJ(eee, aaa, bbb, ccc, ddd, block[14], 9);
|
||||
JJJ(ddd, eee, aaa, bbb, ccc, block[ 7], 9);
|
||||
JJJ(ccc, ddd, eee, aaa, bbb, block[ 0], 11);
|
||||
JJJ(bbb, ccc, ddd, eee, aaa, block[ 9], 13);
|
||||
JJJ(aaa, bbb, ccc, ddd, eee, block[ 2], 15);
|
||||
JJJ(eee, aaa, bbb, ccc, ddd, block[11], 15);
|
||||
JJJ(ddd, eee, aaa, bbb, ccc, block[ 4], 5);
|
||||
JJJ(ccc, ddd, eee, aaa, bbb, block[13], 7);
|
||||
JJJ(bbb, ccc, ddd, eee, aaa, block[ 6], 7);
|
||||
JJJ(aaa, bbb, ccc, ddd, eee, block[15], 8);
|
||||
JJJ(eee, aaa, bbb, ccc, ddd, block[ 8], 11);
|
||||
JJJ(ddd, eee, aaa, bbb, ccc, block[ 1], 14);
|
||||
JJJ(ccc, ddd, eee, aaa, bbb, block[10], 14);
|
||||
JJJ(bbb, ccc, ddd, eee, aaa, block[ 3], 12);
|
||||
JJJ(aaa, bbb, ccc, ddd, eee, block[12], 6);
|
||||
|
||||
/* parallel round 2 */
|
||||
III(eee, aaa, bbb, ccc, ddd, block[ 6], 9);
|
||||
III(ddd, eee, aaa, bbb, ccc, block[11], 13);
|
||||
III(ccc, ddd, eee, aaa, bbb, block[ 3], 15);
|
||||
III(bbb, ccc, ddd, eee, aaa, block[ 7], 7);
|
||||
III(aaa, bbb, ccc, ddd, eee, block[ 0], 12);
|
||||
III(eee, aaa, bbb, ccc, ddd, block[13], 8);
|
||||
III(ddd, eee, aaa, bbb, ccc, block[ 5], 9);
|
||||
III(ccc, ddd, eee, aaa, bbb, block[10], 11);
|
||||
III(bbb, ccc, ddd, eee, aaa, block[14], 7);
|
||||
III(aaa, bbb, ccc, ddd, eee, block[15], 7);
|
||||
III(eee, aaa, bbb, ccc, ddd, block[ 8], 12);
|
||||
III(ddd, eee, aaa, bbb, ccc, block[12], 7);
|
||||
III(ccc, ddd, eee, aaa, bbb, block[ 4], 6);
|
||||
III(bbb, ccc, ddd, eee, aaa, block[ 9], 15);
|
||||
III(aaa, bbb, ccc, ddd, eee, block[ 1], 13);
|
||||
III(eee, aaa, bbb, ccc, ddd, block[ 2], 11);
|
||||
|
||||
/* parallel round 3 */
|
||||
HHH(ddd, eee, aaa, bbb, ccc, block[15], 9);
|
||||
HHH(ccc, ddd, eee, aaa, bbb, block[ 5], 7);
|
||||
HHH(bbb, ccc, ddd, eee, aaa, block[ 1], 15);
|
||||
HHH(aaa, bbb, ccc, ddd, eee, block[ 3], 11);
|
||||
HHH(eee, aaa, bbb, ccc, ddd, block[ 7], 8);
|
||||
HHH(ddd, eee, aaa, bbb, ccc, block[14], 6);
|
||||
HHH(ccc, ddd, eee, aaa, bbb, block[ 6], 6);
|
||||
HHH(bbb, ccc, ddd, eee, aaa, block[ 9], 14);
|
||||
HHH(aaa, bbb, ccc, ddd, eee, block[11], 12);
|
||||
HHH(eee, aaa, bbb, ccc, ddd, block[ 8], 13);
|
||||
HHH(ddd, eee, aaa, bbb, ccc, block[12], 5);
|
||||
HHH(ccc, ddd, eee, aaa, bbb, block[ 2], 14);
|
||||
HHH(bbb, ccc, ddd, eee, aaa, block[10], 13);
|
||||
HHH(aaa, bbb, ccc, ddd, eee, block[ 0], 13);
|
||||
HHH(eee, aaa, bbb, ccc, ddd, block[ 4], 7);
|
||||
HHH(ddd, eee, aaa, bbb, ccc, block[13], 5);
|
||||
|
||||
/* parallel round 4 */
|
||||
GGG(ccc, ddd, eee, aaa, bbb, block[ 8], 15);
|
||||
GGG(bbb, ccc, ddd, eee, aaa, block[ 6], 5);
|
||||
GGG(aaa, bbb, ccc, ddd, eee, block[ 4], 8);
|
||||
GGG(eee, aaa, bbb, ccc, ddd, block[ 1], 11);
|
||||
GGG(ddd, eee, aaa, bbb, ccc, block[ 3], 14);
|
||||
GGG(ccc, ddd, eee, aaa, bbb, block[11], 14);
|
||||
GGG(bbb, ccc, ddd, eee, aaa, block[15], 6);
|
||||
GGG(aaa, bbb, ccc, ddd, eee, block[ 0], 14);
|
||||
GGG(eee, aaa, bbb, ccc, ddd, block[ 5], 6);
|
||||
GGG(ddd, eee, aaa, bbb, ccc, block[12], 9);
|
||||
GGG(ccc, ddd, eee, aaa, bbb, block[ 2], 12);
|
||||
GGG(bbb, ccc, ddd, eee, aaa, block[13], 9);
|
||||
GGG(aaa, bbb, ccc, ddd, eee, block[ 9], 12);
|
||||
GGG(eee, aaa, bbb, ccc, ddd, block[ 7], 5);
|
||||
GGG(ddd, eee, aaa, bbb, ccc, block[10], 15);
|
||||
GGG(ccc, ddd, eee, aaa, bbb, block[14], 8);
|
||||
|
||||
/* parallel round 5 */
|
||||
FFF(bbb, ccc, ddd, eee, aaa, block[12] , 8);
|
||||
FFF(aaa, bbb, ccc, ddd, eee, block[15] , 5);
|
||||
FFF(eee, aaa, bbb, ccc, ddd, block[10] , 12);
|
||||
FFF(ddd, eee, aaa, bbb, ccc, block[ 4] , 9);
|
||||
FFF(ccc, ddd, eee, aaa, bbb, block[ 1] , 12);
|
||||
FFF(bbb, ccc, ddd, eee, aaa, block[ 5] , 5);
|
||||
FFF(aaa, bbb, ccc, ddd, eee, block[ 8] , 14);
|
||||
FFF(eee, aaa, bbb, ccc, ddd, block[ 7] , 6);
|
||||
FFF(ddd, eee, aaa, bbb, ccc, block[ 6] , 8);
|
||||
FFF(ccc, ddd, eee, aaa, bbb, block[ 2] , 13);
|
||||
FFF(bbb, ccc, ddd, eee, aaa, block[13] , 6);
|
||||
FFF(aaa, bbb, ccc, ddd, eee, block[14] , 5);
|
||||
FFF(eee, aaa, bbb, ccc, ddd, block[ 0] , 15);
|
||||
FFF(ddd, eee, aaa, bbb, ccc, block[ 3] , 13);
|
||||
FFF(ccc, ddd, eee, aaa, bbb, block[ 9] , 11);
|
||||
FFF(bbb, ccc, ddd, eee, aaa, block[11] , 11);
|
||||
|
||||
/* combine results */
|
||||
ddd += cc + state[1]; /* final result for state[0] */
|
||||
state[1] = state[2] + dd + eee;
|
||||
state[2] = state[3] + ee + aaa;
|
||||
state[3] = state[4] + aa + bbb;
|
||||
state[4] = state[0] + bb + ccc;
|
||||
state[0] = ddd;
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
void
|
||||
RMD160Update(context, data, nbytes)
|
||||
RMD160_CTX *context;
|
||||
const u_char *data;
|
||||
u_int32_t nbytes;
|
||||
{
|
||||
u_int32_t X[16];
|
||||
u_int32_t ofs = 0;
|
||||
u_int32_t i;
|
||||
#if BYTE_ORDER != LITTLE_ENDIAN
|
||||
u_int32_t j;
|
||||
#endif
|
||||
|
||||
/* update length[] */
|
||||
if (context->length[0] + nbytes < context->length[0])
|
||||
context->length[1]++; /* overflow to msb of length */
|
||||
context->length[0] += nbytes;
|
||||
|
||||
(void)memset(X, 0, sizeof(X));
|
||||
|
||||
if ( context->buflen + nbytes < 64 )
|
||||
{
|
||||
(void)memcpy(context->bbuffer + context->buflen, data, nbytes);
|
||||
context->buflen += nbytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* process first block */
|
||||
ofs = 64 - context->buflen;
|
||||
(void)memcpy(context->bbuffer + context->buflen, data, ofs);
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
(void)memcpy(X, context->bbuffer, sizeof(X));
|
||||
#else
|
||||
for (j=0; j < 16; j++)
|
||||
X[j] = BYTES_TO_DWORD(context->bbuffer + (4 * j));
|
||||
#endif
|
||||
RMD160Transform(context->state, X);
|
||||
nbytes -= ofs;
|
||||
|
||||
/* process remaining complete blocks */
|
||||
for (i = 0; i < (nbytes >> 6); i++) {
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
(void)memcpy(X, data + (64 * i) + ofs, sizeof(X));
|
||||
#else
|
||||
for (j=0; j < 16; j++)
|
||||
X[j] = BYTES_TO_DWORD(data + (64 * i) + (4 * j) + ofs);
|
||||
#endif
|
||||
RMD160Transform(context->state, X);
|
||||
}
|
||||
|
||||
/*
|
||||
* Put last bytes from data into context's buffer
|
||||
*/
|
||||
context->buflen = nbytes & 63;
|
||||
memcpy(context->bbuffer, data + (64 * i) + ofs, context->buflen);
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
void
|
||||
RMD160Final(digest, context)
|
||||
u_char digest[20];
|
||||
RMD160_CTX *context;
|
||||
{
|
||||
u_int32_t i;
|
||||
u_int32_t X[16];
|
||||
#if BYTE_ORDER != LITTLE_ENDIAN
|
||||
u_int32_t j;
|
||||
#endif
|
||||
|
||||
/* append the bit m_n == 1 */
|
||||
context->bbuffer[context->buflen] = '\200';
|
||||
|
||||
(void)memset(context->bbuffer + context->buflen + 1, 0,
|
||||
63 - context->buflen);
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
(void)memcpy(X, context->bbuffer, sizeof(X));
|
||||
#else
|
||||
for (j=0; j < 16; j++)
|
||||
X[j] = BYTES_TO_DWORD(context->bbuffer + (4 * j));
|
||||
#endif
|
||||
if ((context->buflen) > 55) {
|
||||
/* length goes to next block */
|
||||
RMD160Transform(context->state, X);
|
||||
(void)memset(X, 0, sizeof(X));
|
||||
}
|
||||
|
||||
/* append length in bits */
|
||||
X[14] = context->length[0] << 3;
|
||||
X[15] = (context->length[0] >> 29) |
|
||||
(context->length[1] << 3);
|
||||
RMD160Transform(context->state, X);
|
||||
|
||||
if (digest != NULL) {
|
||||
for (i = 0; i < 20; i += 4) {
|
||||
/* extracts the 8 least significant bits. */
|
||||
digest[i] = context->state[i>>2];
|
||||
digest[i + 1] = (context->state[i>>2] >> 8);
|
||||
digest[i + 2] = (context->state[i>>2] >> 16);
|
||||
digest[i + 3] = (context->state[i>>2] >> 24);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/************************ end of file rmd160.c **********************/
|
88
lib/libc/hash/rmd160hl.c
Normal file
88
lib/libc/hash/rmd160hl.c
Normal file
@ -0,0 +1,88 @@
|
||||
/* $NetBSD: rmd160hl.c,v 1.1 2000/07/05 11:44:04 ad Exp $ */
|
||||
|
||||
/* rmd160hl.c
|
||||
* ----------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you
|
||||
* can do whatever you want with this stuff. If we meet some day, and you think
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* from OpenBSD: rmd160hl.c,v 1.2 1999/08/17 09:13:12 millert Exp $
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: rmd160hl.c,v 1.1 2000/07/05 11:44:04 ad Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <rmd160.h>
|
||||
|
||||
/* ARGSUSED */
|
||||
char *
|
||||
RMD160End(ctx, buf)
|
||||
RMD160_CTX *ctx;
|
||||
char *buf;
|
||||
{
|
||||
int i;
|
||||
char *p = buf;
|
||||
u_char digest[20];
|
||||
static const char hex[]="0123456789abcdef";
|
||||
|
||||
if (p == NULL && (p = malloc(41)) == NULL)
|
||||
return 0;
|
||||
|
||||
RMD160Final(digest,ctx);
|
||||
for (i = 0; i < 20; i++) {
|
||||
p[i + i] = hex[digest[i] >> 4];
|
||||
p[i + i + 1] = hex[digest[i] & 0x0f];
|
||||
}
|
||||
p[i + i] = '\0';
|
||||
return(p);
|
||||
}
|
||||
|
||||
char *
|
||||
RMD160File (filename, buf)
|
||||
char *filename;
|
||||
char *buf;
|
||||
{
|
||||
u_char buffer[BUFSIZ];
|
||||
RMD160_CTX ctx;
|
||||
int fd, num, oerrno;
|
||||
|
||||
RMD160Init(&ctx);
|
||||
|
||||
if ((fd = open(filename, O_RDONLY)) < 0)
|
||||
return(0);
|
||||
|
||||
while ((num = read(fd, buffer, sizeof(buffer))) > 0)
|
||||
RMD160Update(&ctx, buffer, num);
|
||||
|
||||
oerrno = errno;
|
||||
close(fd);
|
||||
errno = oerrno;
|
||||
return(num < 0 ? 0 : RMD160End(&ctx, buf));
|
||||
}
|
||||
|
||||
char *
|
||||
RMD160Data (data, len, buf)
|
||||
const u_char *data;
|
||||
size_t len;
|
||||
char *buf;
|
||||
{
|
||||
RMD160_CTX ctx;
|
||||
|
||||
RMD160Init(&ctx);
|
||||
RMD160Update(&ctx, data, len);
|
||||
return(RMD160End(&ctx, buf));
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: namespace.h,v 1.54 2000/06/26 06:33:04 kleink Exp $ */
|
||||
/* $NetBSD: namespace.h,v 1.55 2000/07/05 11:44:02 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
|
||||
@ -75,6 +75,13 @@
|
||||
#define SHA1Init _SHA1Init
|
||||
#define SHA1Transform _SHA1Transform
|
||||
#define SHA1Update _SHA1Update
|
||||
#define RMD160Data _RMD160Data
|
||||
#define RMD160End _RMD160End
|
||||
#define RMD160File _RMD160File
|
||||
#define RMD160Final _RMD160Final
|
||||
#define RMD160Init _RMD160Init
|
||||
#define RMD160Transform _RMD160Transform
|
||||
#define RMD160Update _RMD160Update
|
||||
#define a64l _a64l
|
||||
#define alarm _alarm
|
||||
#define alphasort _alphasort
|
||||
|
Loading…
Reference in New Issue
Block a user