Browse Source

o Ansi function headers

o Add __BEGIN_DECLS/__END_DECLS to include files
o Safe macros
o Remove useless variable assignment in the End function of *hl.c
o Some minor KNF, needs more
From Dan Weeks
OPENBSD_3_3
millert 21 years ago
parent
commit
bd747228df
8 changed files with 86 additions and 86 deletions
  1. +5
    -1
      src/include/md4.h
  2. +5
    -1
      src/include/md5.h
  3. +5
    -1
      src/include/rmd160.h
  4. +20
    -16
      src/include/sha1.h
  5. +17
    -17
      src/lib/libc/hash/rmd160.c
  6. +11
    -19
      src/lib/libc/hash/rmd160hl.c
  7. +13
    -13
      src/lib/libc/hash/sha1.c
  8. +10
    -18
      src/lib/libc/hash/sha1hl.c

+ 5
- 1
src/include/md4.h View File

@ -1,5 +1,5 @@
/* MD4.H - header file for MD4C.C
* $OpenBSD: md4.h,v 1.6 2002/02/16 21:27:17 millert Exp $
* $OpenBSD: md4.h,v 1.7 2002/12/23 04:33:31 millert Exp $
*/
/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
@ -33,6 +33,9 @@ typedef struct MD4Context {
unsigned char buffer[64]; /* input buffer */
} MD4_CTX;
#include <sys/cdefs.h>
__BEGIN_DECLS
void MD4Init(MD4_CTX *);
void MD4Update(MD4_CTX *, const unsigned char *, size_t);
void MD4Final(unsigned char [16], MD4_CTX *);
@ -40,5 +43,6 @@ void MD4Transform(u_int32_t [4], const unsigned char [64]);
char * MD4End(MD4_CTX *, char *);
char * MD4File(char *, char *);
char * MD4Data(const unsigned char *, size_t, char *);
__END_DECLS
#endif /* _MD4_H_ */

+ 5
- 1
src/include/md5.h View File

@ -1,5 +1,5 @@
/* MD5.H - header file for MD5C.C
* $OpenBSD: md5.h,v 1.6 2002/02/16 21:27:17 millert Exp $
* $OpenBSD: md5.h,v 1.7 2002/12/23 04:33:31 millert Exp $
*/
/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
@ -34,6 +34,9 @@ typedef struct MD5Context {
unsigned char buffer[64]; /* input buffer */
} MD5_CTX;
#include <sys/cdefs.h>
__BEGIN_DECLS
void MD5Init(MD5_CTX *);
void MD5Update(MD5_CTX *, const unsigned char *, size_t);
void MD5Final(unsigned char [16], MD5_CTX *);
@ -41,5 +44,6 @@ void MD5Transform(u_int32_t [4], const unsigned char [64]);
char * MD5End(MD5_CTX *, char *);
char * MD5File(char *, char *);
char * MD5Data(const unsigned char *, size_t, char *);
__END_DECLS
#endif /* _MD5_H_ */

+ 5
- 1
src/include/rmd160.h View File

@ -1,4 +1,4 @@
/* $OpenBSD: rmd160.h,v 1.6 2002/02/16 21:27:17 millert Exp $ */
/* $OpenBSD: rmd160.h,v 1.7 2002/12/23 04:33:31 millert Exp $ */
/*
* Copyright (c) 2001 Markus Friedl. All rights reserved.
*
@ -32,6 +32,9 @@ typedef struct RMD160Context {
u_char buffer[64]; /* input buffer */
} RMD160_CTX;
#include <sys/cdefs.h>
__BEGIN_DECLS
void RMD160Init(RMD160_CTX *);
void RMD160Transform(u_int32_t [5], const u_char [64]);
void RMD160Update(RMD160_CTX *, const u_char *, u_int32_t);
@ -39,5 +42,6 @@ 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 */

+ 20
- 16
src/include/sha1.h View File

@ -1,4 +1,4 @@
/* $OpenBSD: sha1.h,v 1.10 2002/02/16 21:27:17 millert Exp $ */
/* $OpenBSD: sha1.h,v 1.11 2002/12/23 04:33:31 millert Exp $ */
/*
* SHA-1 in C
@ -11,10 +11,13 @@
typedef struct {
u_int32_t state[5];
u_int32_t count[2];
u_int32_t count[2];
u_char buffer[64];
} SHA1_CTX;
#include <sys/cdefs.h>
__BEGIN_DECLS
void SHA1Transform(u_int32_t state[5], const u_char buffer[64]);
void SHA1Init(SHA1_CTX *context);
void SHA1Update(SHA1_CTX *context, const u_char *data, u_int len);
@ -22,21 +25,22 @@ void SHA1Final(u_char digest[20], SHA1_CTX *context);
char *SHA1End(SHA1_CTX *, char *);
char *SHA1File(char *, char *);
char *SHA1Data(const u_char *, size_t, char *);
__END_DECLS
#define SHA1_DIGESTSIZE 20
#define SHA1_BLOCKSIZE 64
#define HTONDIGEST(x) { \
x[0] = htonl(x[0]); \
x[1] = htonl(x[1]); \
x[2] = htonl(x[2]); \
x[3] = htonl(x[3]); \
x[4] = htonl(x[4]); }
#define NTOHDIGEST(x) { \
x[0] = ntohl(x[0]); \
x[1] = ntohl(x[1]); \
x[2] = ntohl(x[2]); \
x[3] = ntohl(x[3]); \
x[4] = ntohl(x[4]); }
#define HTONDIGEST(x) do { \
x[0] = htonl(x[0]); \
x[1] = htonl(x[1]); \
x[2] = htonl(x[2]); \
x[3] = htonl(x[3]); \
x[4] = htonl(x[4]); } while (0)
#define NTOHDIGEST(x) do { \
x[0] = ntohl(x[0]); \
x[1] = ntohl(x[1]); \
x[2] = ntohl(x[2]); \
x[3] = ntohl(x[3]); \
x[4] = ntohl(x[4]); } while (0)
#endif /* _SHA1_H */

+ 17
- 17
src/lib/libc/hash/rmd160.c View File

@ -32,23 +32,23 @@
#include <rmd160.h>
#if defined(LIBC_SCCS) && !defined(lint)
static char rcsid[] = "$OpenBSD: rmd160.c,v 1.11 2001/10/01 20:36:17 markus Exp $";
static char rcsid[] = "$OpenBSD: rmd160.c,v 1.12 2002/12/23 04:33:31 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#define PUT_64BIT_LE(cp, value) do { \
(cp)[7] = (value) >> 56; \
(cp)[6] = (value) >> 48; \
(cp)[5] = (value) >> 40; \
(cp)[4] = (value) >> 32; \
(cp)[3] = (value) >> 24; \
(cp)[2] = (value) >> 16; \
(cp)[1] = (value) >> 8; \
#define PUT_64BIT_LE(cp, value) do { \
(cp)[7] = (value) >> 56; \
(cp)[6] = (value) >> 48; \
(cp)[5] = (value) >> 40; \
(cp)[4] = (value) >> 32; \
(cp)[3] = (value) >> 24; \
(cp)[2] = (value) >> 16; \
(cp)[1] = (value) >> 8; \
(cp)[0] = (value); } while (0)
#define PUT_32BIT_LE(cp, value) do { \
(cp)[3] = (value) >> 24; \
(cp)[2] = (value) >> 16; \
(cp)[1] = (value) >> 8; \
#define PUT_32BIT_LE(cp, value) do { \
(cp)[3] = (value) >> 24; \
(cp)[2] = (value) >> 16; \
(cp)[1] = (value) >> 8; \
(cp)[0] = (value); } while (0)
#define H0 0x67452301U
@ -78,10 +78,10 @@ static char rcsid[] = "$OpenBSD: rmd160.c,v 1.11 2001/10/01 20:36:17 markus Exp
#define F3(x, y, z) (((x) & (z)) | ((y) & (~z)))
#define F4(x, y, z) ((x) ^ ((y) | (~z)))
#define R(a, b, c, d, e, Fj, Kj, sj, rj) \
do { \
a = ROL(sj, a + Fj(b,c,d) + X(rj) + Kj) + e; \
c = ROL(10, c); \
#define R(a, b, c, d, e, Fj, Kj, sj, rj) \
do { \
a = ROL(sj, a + Fj(b,c,d) + X(rj) + Kj) + e; \
c = ROL(10, c); \
} while(0)
#define X(i) x[i]


+ 11
- 19
src/lib/libc/hash/rmd160hl.c View File

@ -8,7 +8,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char rcsid[] = "$OpenBSD: rmd160hl.c,v 1.2 1999/08/17 09:13:12 millert Exp $";
static char rcsid[] = "$OpenBSD: rmd160hl.c,v 1.3 2002/12/23 04:33:31 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdlib.h>
@ -22,31 +22,26 @@ static char rcsid[] = "$OpenBSD: rmd160hl.c,v 1.2 1999/08/17 09:13:12 millert Ex
/* ARGSUSED */
char *
RMD160End(ctx, buf)
RMD160_CTX *ctx;
char *buf;
RMD160End(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;
if (buf == NULL && (buf = malloc(41)) == NULL)
return(NULL);
RMD160Final(digest,ctx);
RMD160Final(digest, ctx);
for (i = 0; i < 20; i++) {
p[i + i] = hex[digest[i] >> 4];
p[i + i + 1] = hex[digest[i] & 0x0f];
buf[i + i] = hex[digest[i] >> 4];
buf[i + i + 1] = hex[digest[i] & 0x0f];
}
p[i + i] = '\0';
return(p);
buf[i + i] = '\0';
return(buf);
}
char *
RMD160File (filename, buf)
char *filename;
char *buf;
RMD160File (char *filename, char *buf)
{
u_char buffer[BUFSIZ];
RMD160_CTX ctx;
@ -67,10 +62,7 @@ RMD160File (filename, buf)
}
char *
RMD160Data (data, len, buf)
const u_char *data;
size_t len;
char *buf;
RMD160Data (const u_char *data, size_t len, char *buf)
{
RMD160_CTX ctx;


+ 13
- 13
src/lib/libc/hash/sha1.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: sha1.c,v 1.9 1997/07/23 21:12:32 kstailey Exp $ */
/* $OpenBSD: sha1.c,v 1.10 2002/12/23 04:33:31 millert Exp $ */
/*
* SHA-1 in C
@ -14,6 +14,10 @@
* 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char rcsid[] = "$OpenBSD: sha1.c,v 1.10 2002/12/23 04:33:31 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#define SHA1HANDSOFF /* Copies data before messing with it. */
#include <sys/param.h>
@ -48,9 +52,8 @@
/*
* Hash a single 512-bit block. This is the core of the algorithm.
*/
void SHA1Transform(state, buffer)
u_int32_t state[5];
const u_char buffer[64];
void
SHA1Transform(u_int32_t state[5], const u_char buffer[64])
{
u_int32_t a, b, c, d, e;
typedef union {
@ -111,8 +114,8 @@ void SHA1Transform(state, buffer)
/*
* SHA1Init - Initialize new context
*/
void SHA1Init(context)
SHA1_CTX *context;
void
SHA1Init(SHA1_CTX *context)
{
/* SHA1 initialization constants */
@ -128,10 +131,8 @@ void SHA1Init(context)
/*
* Run your data through this.
*/
void SHA1Update(context, data, len)
SHA1_CTX *context;
const u_char *data;
u_int len;
void
SHA1Update(SHA1_CTX *context, const u_char *data, u_int len)
{
u_int i, j;
@ -155,9 +156,8 @@ void SHA1Update(context, data, len)
/*
* Add padding and return the message digest.
*/
void SHA1Final(digest, context)
u_char digest[20];
SHA1_CTX* context;
void
SHA1Final(u_char digest[20], SHA1_CTX *context)
{
u_int i;
u_char finalcount[8];


+ 10
- 18
src/lib/libc/hash/sha1hl.c View File

@ -8,7 +8,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char rcsid[] = "$OpenBSD: sha1hl.c,v 1.2 1999/08/17 09:13:12 millert Exp $";
static char rcsid[] = "$OpenBSD: sha1hl.c,v 1.3 2002/12/23 04:33:31 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdlib.h>
@ -22,31 +22,26 @@ static char rcsid[] = "$OpenBSD: sha1hl.c,v 1.2 1999/08/17 09:13:12 millert Exp
/* ARGSUSED */
char *
SHA1End(ctx, buf)
SHA1_CTX *ctx;
char *buf;
SHA1End(SHA1_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;
if (buf == NULL && (buf = malloc(41)) == NULL)
return(NULL);
SHA1Final(digest,ctx);
for (i = 0; i < 20; i++) {
p[i + i] = hex[digest[i] >> 4];
p[i + i + 1] = hex[digest[i] & 0x0f];
buf[i + i] = hex[digest[i] >> 4];
buf[i + i + 1] = hex[digest[i] & 0x0f];
}
p[i + i] = '\0';
return(p);
buf[i + i] = '\0';
return(buf);
}
char *
SHA1File (filename, buf)
char *filename;
char *buf;
SHA1File (char *filename, char *buf)
{
u_char buffer[BUFSIZ];
SHA1_CTX ctx;
@ -67,10 +62,7 @@ SHA1File (filename, buf)
}
char *
SHA1Data (data, len, buf)
const u_char *data;
size_t len;
char *buf;
SHA1Data (const u_char *data, size_t len, char *buf)
{
SHA1_CTX ctx;


Loading…
Cancel
Save