patch: contrib/pgcrypto sanity
The KAME files md5.* and sha1.* have the following changelog
entry:
----------------------------
revision 1.2
date: 2000/12/04 01:20:38; author: tgl; state: Exp; lines:
+18 -18
Eliminate some of the more blatant platform-dependencies ... it
builds here now, anyway ...
----------------------------
Which basically changes u_int*_t -> uint*_t, so now it does not
compile neither under Debian 2.2 nor under NetBSD 1.5 which
is platform independent� all right. Also it replaces $KAME$
with $Id$ which is Bad Thing. PostgreSQL Id should be added as a
separate line so the file history could be seen.
So here is patch:
* changes uint*_t -> uint*. I guess that was the original
intention
* adds uint64 type to include/c.h because its needed
[somebody should check if I did it right]
* adds back KAME Id, because KAME is the master repository
* removes stupid c++ comments in pgcrypto.c
* removes <sys/types.h> from the code, its not needed
--
marko
Attachments:
pgcrypto-sane.difftext/plain; charset=us-asciiDownload
Index: pgsql/contrib/pgcrypto/md5.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/contrib/pgcrypto/md5.c,v
retrieving revision 1.2
diff -u -r1.2 md5.c
--- pgsql/contrib/pgcrypto/md5.c 2000/12/04 01:20:38 1.2
+++ pgsql/contrib/pgcrypto/md5.c 2001/01/07 16:45:13
@@ -1,4 +1,5 @@
/* $Id: md5.c,v 1.2 2000/12/04 01:20:38 tgl Exp $ */
+/* $KAME: md5.c,v 1.3 2000/02/22 14:01:17 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -30,7 +31,6 @@
*/
#include <postgres.h>
-#include "pgcrypto.h"
#include "md5.h"
@@ -91,7 +91,7 @@
#define MD5_D0 0x10325476
/* Integer part of 4294967296 times abs(sin(i)), where i is in radians. */
-static const uint32_t T[65] = {
+static const uint32 T[65] = {
0,
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
@@ -114,7 +114,7 @@
0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,
};
-static const uint8_t md5_paddat[MD5_BUFLEN] = {
+static const uint8 md5_paddat[MD5_BUFLEN] = {
0x80, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
@@ -125,7 +125,7 @@
0, 0, 0, 0, 0, 0, 0, 0,
};
-static void md5_calc (uint8_t *, md5_ctxt *);
+static void md5_calc (uint8 *, md5_ctxt *);
void md5_init(ctxt)
md5_ctxt *ctxt;
@@ -141,7 +141,7 @@
void md5_loop(ctxt, input, len)
md5_ctxt *ctxt;
- uint8_t *input;
+ uint8 *input;
unsigned int len; /* number of bytes */
{
unsigned int gap, i;
@@ -155,7 +155,7 @@
md5_calc(ctxt->md5_buf, ctxt);
for (i = gap; i + MD5_BUFLEN <= len; i += MD5_BUFLEN) {
- md5_calc((uint8_t *)(input + i), ctxt);
+ md5_calc((uint8 *)(input + i), ctxt);
}
ctxt->md5_i = len - i;
@@ -207,7 +207,7 @@
}
void md5_result(digest, ctxt)
- uint8_t *digest;
+ uint8 *digest;
md5_ctxt *ctxt;
{
/* 4 byte words */
@@ -227,24 +227,24 @@
}
#if BYTE_ORDER == BIG_ENDIAN
-uint32_t X[16];
+uint32 X[16];
#endif
static void md5_calc(b64, ctxt)
- uint8_t *b64;
+ uint8 *b64;
md5_ctxt *ctxt;
{
- uint32_t A = ctxt->md5_sta;
- uint32_t B = ctxt->md5_stb;
- uint32_t C = ctxt->md5_stc;
- uint32_t D = ctxt->md5_std;
+ uint32 A = ctxt->md5_sta;
+ uint32 B = ctxt->md5_stb;
+ uint32 C = ctxt->md5_stc;
+ uint32 D = ctxt->md5_std;
#if BYTE_ORDER == LITTLE_ENDIAN
- uint32_t *X = (uint32_t *)b64;
+ uint32 *X = (uint32 *)b64;
#endif
#if BYTE_ORDER == BIG_ENDIAN
/* 4 byte words */
/* what a brute force but fast! */
- uint8_t *y = (uint8_t *)X;
+ uint8 *y = (uint8 *)X;
y[ 0] = b64[ 3]; y[ 1] = b64[ 2]; y[ 2] = b64[ 1]; y[ 3] = b64[ 0];
y[ 4] = b64[ 7]; y[ 5] = b64[ 6]; y[ 6] = b64[ 5]; y[ 7] = b64[ 4];
y[ 8] = b64[11]; y[ 9] = b64[10]; y[10] = b64[ 9]; y[11] = b64[ 8];
Index: pgsql/contrib/pgcrypto/md5.h
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/contrib/pgcrypto/md5.h,v
retrieving revision 1.2
diff -u -r1.2 md5.h
--- pgsql/contrib/pgcrypto/md5.h 2000/12/04 01:20:38 1.2
+++ pgsql/contrib/pgcrypto/md5.h 2001/01/07 16:45:13
@@ -1,4 +1,5 @@
/* $Id: md5.h,v 1.2 2000/12/04 01:20:38 tgl Exp $ */
+/* $KAME: md5.h,v 1.3 2000/02/22 14:01:18 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -36,8 +37,8 @@
typedef struct {
union {
- uint32_t md5_state32[4];
- uint8_t md5_state8[16];
+ uint32 md5_state32[4];
+ uint8 md5_state8[16];
} md5_st;
#define md5_sta md5_st.md5_state32[0]
@@ -47,20 +48,20 @@
#define md5_st8 md5_st.md5_state8
union {
- uint64_t md5_count64;
- uint8_t md5_count8[8];
+ uint64 md5_count64;
+ uint8 md5_count8[8];
} md5_count;
#define md5_n md5_count.md5_count64
#define md5_n8 md5_count.md5_count8
unsigned int md5_i;
- uint8_t md5_buf[MD5_BUFLEN];
+ uint8 md5_buf[MD5_BUFLEN];
} md5_ctxt;
extern void md5_init (md5_ctxt *);
-extern void md5_loop (md5_ctxt *, uint8_t *, unsigned int);
+extern void md5_loop (md5_ctxt *, uint8 *, unsigned int);
extern void md5_pad (md5_ctxt *);
-extern void md5_result (uint8_t *, md5_ctxt *);
+extern void md5_result (uint8 *, md5_ctxt *);
/* compatibility */
#define MD5_CTX md5_ctxt
Index: pgsql/contrib/pgcrypto/pgcrypto.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/contrib/pgcrypto/pgcrypto.c,v
retrieving revision 1.2
diff -u -r1.2 pgcrypto.c
--- pgsql/contrib/pgcrypto/pgcrypto.c 2000/11/20 20:36:56 1.2
+++ pgsql/contrib/pgcrypto/pgcrypto.c 2001/01/07 16:45:13
@@ -91,7 +91,7 @@
to_hex(p, hlen, VARDATA(res));
PG_FREE_IF_COPY(arg, 0);
- PG_FREE_IF_COPY(name, 0); // unnecessary i guess
+ PG_FREE_IF_COPY(name, 0);
PG_RETURN_TEXT_P(res);
}
@@ -112,7 +112,7 @@
res = find_digest(&_hbuf, name, 1);
- PG_FREE_IF_COPY(name, 0); // unnecessary i guess
+ PG_FREE_IF_COPY(name, 0);
if (res != NULL)
PG_RETURN_BOOL(true);
Index: pgsql/contrib/pgcrypto/pgcrypto.h
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/contrib/pgcrypto/pgcrypto.h,v
retrieving revision 1.1
diff -u -r1.1 pgcrypto.h
--- pgsql/contrib/pgcrypto/pgcrypto.h 2000/10/31 13:11:28 1.1
+++ pgsql/contrib/pgcrypto/pgcrypto.h 2001/01/07 16:45:13
@@ -32,8 +32,6 @@
#ifndef _PG_CRYPTO_H
#define _PG_CRYPTO_H
-#include <sys/types.h>
-
typedef struct _pg_digest pg_digest;
struct _pg_digest {
char *name;
Index: pgsql/contrib/pgcrypto/sha1.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/contrib/pgcrypto/sha1.c,v
retrieving revision 1.2
diff -u -r1.2 sha1.c
--- pgsql/contrib/pgcrypto/sha1.c 2000/12/04 01:20:38 1.2
+++ pgsql/contrib/pgcrypto/sha1.c 2001/01/07 16:45:14
@@ -1,4 +1,5 @@
/* $Id: sha1.c,v 1.2 2000/12/04 01:20:38 tgl Exp $ */
+/* $KAME: sha1.c,v 1.3 2000/02/22 14:01:18 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -35,7 +36,6 @@
*/
#include <postgres.h>
-#include "pgcrypto.h"
#include "sha1.h"
@@ -49,7 +49,7 @@
#ifndef unsupported
/* constant table */
-static uint32_t _K[] = { 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6 };
+static uint32 _K[] = { 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6 };
#define K(t) _K[(t) / 20]
#define F0(b, c, d) (((b) & (c)) | ((~(b)) & (d)))
@@ -87,9 +87,9 @@
sha1_step(ctxt)
struct sha1_ctxt *ctxt;
{
- uint32_t a, b, c, d, e;
+ uint32 a, b, c, d, e;
size_t t, s;
- uint32_t tmp;
+ uint32 tmp;
#if BYTE_ORDER == LITTLE_ENDIAN
struct sha1_ctxt tctxt;
@@ -221,13 +221,13 @@
const caddr_t input0;
size_t len;
{
- const uint8_t *input;
+ const uint8 *input;
size_t gaplen;
size_t gapstart;
size_t off;
size_t copysiz;
- input = (const uint8_t *)input0;
+ input = (const uint8 *)input0;
off = 0;
while (off < len) {
@@ -250,9 +250,9 @@
struct sha1_ctxt *ctxt;
caddr_t digest0;
{
- uint8_t *digest;
+ uint8 *digest;
- digest = (uint8_t *)digest0;
+ digest = (uint8 *)digest0;
sha1_pad(ctxt);
#if BYTE_ORDER == BIG_ENDIAN
bcopy(&ctxt->h.b8[0], digest, 20);
Index: pgsql/contrib/pgcrypto/sha1.h
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/contrib/pgcrypto/sha1.h,v
retrieving revision 1.2
diff -u -r1.2 sha1.h
--- pgsql/contrib/pgcrypto/sha1.h 2000/12/04 01:20:38 1.2
+++ pgsql/contrib/pgcrypto/sha1.h 2001/01/07 16:45:14
@@ -1,4 +1,5 @@
/* $Id: sha1.h,v 1.2 2000/12/04 01:20:38 tgl Exp $ */
+/* $KAME: sha1.h,v 1.4 2000/02/22 14:01:18 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -39,18 +40,18 @@
struct sha1_ctxt {
union {
- uint8_t b8[20];
- uint32_t b32[5];
+ uint8 b8[20];
+ uint32 b32[5];
} h;
union {
- uint8_t b8[8];
- uint64_t b64[1];
+ uint8 b8[8];
+ uint64 b64[1];
} c;
union {
- uint8_t b8[64];
- uint32_t b32[16];
+ uint8 b8[64];
+ uint32 b32[16];
} m;
- uint8_t count;
+ uint8 count;
};
extern void sha1_init (struct sha1_ctxt *);
Index: pgsql/src/include/c.h
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/include/c.h,v
retrieving revision 1.85
diff -u -r1.85 c.h
--- pgsql/src/include/c.h 2000/11/03 18:43:52 1.85
+++ pgsql/src/include/c.h 2001/01/07 16:45:24
@@ -277,13 +277,16 @@
#ifdef HAVE_LONG_INT_64
/* Plain "long int" fits, use it */
typedef long int int64;
+typedef unsigned long int uint64;
#else
#ifdef HAVE_LONG_LONG_INT_64
/* We have working support for "long long int", use that */
typedef long long int int64;
+typedef unsigned long long int uint64;
#else
/* Won't actually work, but fall back to long int so that code compiles */
typedef long int int64;
+typedef unsigned long int uint64;
#define INT64_IS_BUSTED
#endif
#endif
Marko Kreen <marko@l-t.ee> writes:
date: 2000/12/04 01:20:38; author: tgl; state: Exp; lines: +18 -18
Eliminate some of the more blatant platform-dependencies ... it
builds here now, anyway ...
Which basically changes u_int*_t -> uint*_t, so now it does not
compile neither under Debian 2.2 nor under NetBSD 1.5 which
is platform independent� all right.
Well, that's annoying. I guess those platforms are out of step with the
C99 standard, which specifies uint*_t not u_int*_t (cf. C99 7.4.1.1).
I agree with your solution of switching to Postgres-supplied typenames.
Also it replaces $KAME$ with $Id$ which is Bad Thing. PostgreSQL Id
should be added as a separate line so the file history could be seen.
I didn't know what $KAME$ was, and took it for some national-language
variant of $Id$ that our CVS server didn't know about. Who/what is
KAME anyway?
* adds back KAME Id, because KAME is the master repository
Is that a good idea? If we are deliberately deviating from whatever
"master repository" this is, I'm not sure that we should continue to
label the code with their revision ID.
regards, tom lane
On Sun, Jan 07, 2001 at 08:09:07PM -0500, Tom Lane wrote:
Marko Kreen <marko@l-t.ee> writes:
date: 2000/12/04 01:20:38; author: tgl; state: Exp; lines: +18 -18
Eliminate some of the more blatant platform-dependencies ... it
builds here now, anyway ...Which basically changes u_int*_t -> uint*_t, so now it does not
compile neither under Debian 2.2 nor under NetBSD 1.5 which
is platform independent� all right.Well, that's annoying. I guess those platforms are out of step with the
C99 standard, which specifies uint*_t not u_int*_t (cf. C99 7.4.1.1).
I agree with your solution of switching to Postgres-supplied typenames.
Well, actually they do. glibc in <stdint.h> and NetBSD in
<sys/inttypes.h> which is a mess, all rigth. Problem is that
postgres.h does not know about this. I guess that C99 forgot
to specify _where_ they should be defined.
But the point is, what are the standard types in PostgreSQL? C99
ones are not, because there would be lots of noise raised
already. If you think that the C99 should be standard someday,
then postgres.h should also provide them, because older
platforms definitely do not provide them.
Also it replaces $KAME$ with $Id$ which is Bad Thing. PostgreSQL Id
should be added as a separate line so the file history could be seen.I didn't know what $KAME$ was, and took it for some national-language
variant of $Id$ that our CVS server didn't know about. Who/what is
KAME anyway?
KAME is the project that provides IPv6 to all the free BSD's.
(www.kame.net)
* adds back KAME Id, because KAME is the master repository
Is that a good idea? If we are deliberately deviating from whatever
"master repository" this is, I'm not sure that we should continue to
label the code with their revision ID.
I think it is. I think they are more competent on maintaining
crypto than PostgreSQL team (at least they devote more time on
it). This makes tracking changes easier. This (special Id's)
are widely used practice in BSD's, this makes clear whether a
file is 'original' or 'imported'; and from where.
--
marko
On Mon, Jan 08, 2001 at 04:06:09AM +0200, Marko Kreen wrote:
On Sun, Jan 07, 2001 at 08:09:07PM -0500, Tom Lane wrote:
Marko Kreen <marko@l-t.ee> writes:
Which basically changes u_int*_t -> uint*_t, so now it does not
compile neither under Debian 2.2 nor under NetBSD 1.5 which
is platform independent� all right.Well, that's annoying. I guess those platforms are out of step with the
C99 standard, which specifies uint*_t not u_int*_t (cf. C99 7.4.1.1).
I agree with your solution of switching to Postgres-supplied typenames.Well, actually they do. glibc in <stdint.h> and NetBSD in
<sys/inttypes.h> which is a mess, all rigth. Problem is that
postgres.h does not know about this. I guess that C99 forgot
to specify _where_ they should be defined.
Correction, they both have <inttypes.h> which probably is the
right location for this.
* adds back KAME Id, because KAME is the master repository
Is that a good idea? If we are deliberately deviating from whatever
"master repository" this is, I'm not sure that we should continue to
label the code with their revision ID.I think it is. I think they are more competent on maintaining
crypto than PostgreSQL team (at least they devote more time on
it). This makes tracking changes easier. This (special Id's)
are widely used practice in BSD's, this makes clear whether a
file is 'original' or 'imported'; and from where.
The "master" only means that occasionally somebody (e.g. I) can
check if their revision is increased and then can merge changes
into our sources, if needed. Also _I_ know where I got these
sources but this makes it easier for others too.
--
marko
Marko Kreen writes:
On Mon, Jan 08, 2001 at 04:06:09AM +0200, Marko Kreen wrote:
On Sun, Jan 07, 2001 at 08:09:07PM -0500, Tom Lane wrote:
Marko Kreen <marko@l-t.ee> writes:
Which basically changes u_int*_t -> uint*_t, so now it does
not compile neither under Debian 2.2 nor under NetBSD 1.5
which is platform independent� all right.Well, that's annoying. I guess those platforms are out of step
with the C99 standard, which specifies uint*_t not u_int*_t
(cf. C99 7.4.1.1). I agree with your solution of switching to
Postgres-supplied typenames.Well, actually they do. glibc in <stdint.h> and NetBSD in
<sys/inttypes.h> which is a mess, all rigth. Problem is that
postgres.h does not know about this. I guess that C99 forgot to
specify _where_ they should be defined.Correction, they both have <inttypes.h> which probably is the right
location for this.
<stdint.h> is adequate to pick up uint*_t. <inttypes.h> is defined to
include <stdint.h>. Of course all this C99 stuff is new and existing
implementations may have the typedefs in different files or not have
them at all.
--
Pete Forman -./\.- Disclaimer: This post is originated
WesternGeco -./\.- by myself and does not represent
pete.forman@westerngeco.com -./\.- opinion of Schlumberger, Baker
http://www.crosswinds.net/~petef -./\.- Hughes or their divisions.
On Mon, Jan 08, 2001 at 10:03:25AM +0000, Pete Forman wrote:
Marko Kreen writes:
On Mon, Jan 08, 2001 at 04:06:09AM +0200, Marko Kreen wrote:
Well, actually they do. glibc in <stdint.h> and NetBSD in
<sys/inttypes.h> which is a mess, all rigth. Problem is that
postgres.h does not know about this. I guess that C99 forgot to
specify _where_ they should be defined.Correction, they both have <inttypes.h> which probably is the right
location for this.<stdint.h> is adequate to pick up uint*_t. <inttypes.h> is defined to
include <stdint.h>. Of course all this C99 stuff is new and existing
implementations may have the typedefs in different files or not have
them at all.
But as I said, NetBSD does not have it. So what is the
correct/portable/standard location for it? Can anyone with C99
standard in hand find that out?
E.g. Tom Lane has some OS where these types are in
std{io|lib|def|arg} but on NetBSD and glibc/Linux you must include
separate header file for them.
--
marko
Applied. Thanks.
[ Charset ISO-8859-1 unsupported, converting... ]
The KAME files md5.* and sha1.* have the following changelog
entry:----------------------------
revision 1.2
date: 2000/12/04 01:20:38; author: tgl; state: Exp; lines:
+18 -18
Eliminate some of the more blatant platform-dependencies ... it
builds here now, anyway ...
----------------------------Which basically changes u_int*_t -> uint*_t, so now it does not
compile neither under Debian 2.2 nor under NetBSD 1.5 which
is platform independent? all right. Also it replaces $KAME$
with $Id$ which is Bad Thing. PostgreSQL Id should be added as a
separate line so the file history could be seen.So here is patch:
* changes uint*_t -> uint*. I guess that was the original
intention
* adds uint64 type to include/c.h because its needed
[somebody should check if I did it right]
* adds back KAME Id, because KAME is the master repository
* removes stupid c++ comments in pgcrypto.c
* removes <sys/types.h> from the code, its not needed--
marko
[ Attachment, skipping... ]
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026