fix pgcrypto usage of uint

From: Marko Kreen <marko(at)l-t(dot)ee>
To: pgsql-patches(at)postgresql(dot)org
Subject: fix pgcrypto usage of uint
Date: 2001-11-20 15:25:14
Message-ID: 20011120172514.A18256@l-t.ee
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

pgcrypto uses non-standard type uint, which causes compile
failures on FreeBSD. This patch replaces uint -> unsigned.

This was reported by Daniel Holtzman against 0.4pre3 standalone
package, but it needs fixing in contrib/pgcrypto too.

Please apply.

--
marko

Index: contrib/pgcrypto/internal.c
===================================================================
RCS file: /opt/cvs/pgsql/pgsql/contrib/pgcrypto/internal.c,v
retrieving revision 1.8
diff -u -r1.8 internal.c
--- contrib/pgcrypto/internal.c 5 Nov 2001 17:46:23 -0000 1.8
+++ contrib/pgcrypto/internal.c 20 Nov 2001 11:35:39 -0000
@@ -90,7 +90,7 @@
}

static void
-int_md5_update(PX_MD * h, const uint8 *data, uint dlen)
+int_md5_update(PX_MD * h, const uint8 *data, unsigned dlen)
{
MD5_CTX *ctx = (MD5_CTX *) h->p.ptr;

@@ -137,7 +137,7 @@
}

static void
-int_sha1_update(PX_MD * h, const uint8 *data, uint dlen)
+int_sha1_update(PX_MD * h, const uint8 *data, unsigned dlen)
{
SHA1_CTX *ctx = (SHA1_CTX *) h->p.ptr;

@@ -225,7 +225,7 @@
blf_ctx bf;
rijndael_ctx rj;
} ctx;
- uint keylen;
+ unsigned keylen;
int is_init;
int mode;
};
@@ -269,7 +269,7 @@
}

static int
-rj_init(PX_Cipher * c, const uint8 *key, uint klen, const uint8 *iv)
+rj_init(PX_Cipher * c, const uint8 *key, unsigned klen, const uint8 *iv)
{
struct int_ctx *cx = (struct int_ctx *) c->ptr;

@@ -298,7 +298,7 @@
}

static int
-rj_encrypt(PX_Cipher * c, const uint8 *data, uint dlen, uint8 *res)
+rj_encrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
{
struct int_ctx *cx = (struct int_ctx *) c->ptr;

@@ -328,7 +328,7 @@
}

static int
-rj_decrypt(PX_Cipher * c, const uint8 *data, uint dlen, uint8 *res)
+rj_decrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
{
struct int_ctx *cx = (struct int_ctx *) c->ptr;

@@ -407,7 +407,7 @@
}

static int
-bf_init(PX_Cipher * c, const uint8 *key, uint klen, const uint8 *iv)
+bf_init(PX_Cipher * c, const uint8 *key, unsigned klen, const uint8 *iv)
{
struct int_ctx *cx = (struct int_ctx *) c->ptr;

@@ -419,7 +419,7 @@
}

static int
-bf_encrypt(PX_Cipher * c, const uint8 *data, uint dlen, uint8 *res)
+bf_encrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
{
struct int_ctx *cx = (struct int_ctx *) c->ptr;

@@ -443,7 +443,7 @@
}

static int
-bf_decrypt(PX_Cipher * c, const uint8 *data, uint dlen, uint8 *res)
+bf_decrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
{
struct int_ctx *cx = (struct int_ctx *) c->ptr;

Index: contrib/pgcrypto/mhash.c
===================================================================
RCS file: /opt/cvs/pgsql/pgsql/contrib/pgcrypto/mhash.c,v
retrieving revision 1.5
diff -u -r1.5 mhash.c
--- contrib/pgcrypto/mhash.c 25 Oct 2001 05:49:19 -0000 1.5
+++ contrib/pgcrypto/mhash.c 20 Nov 2001 11:35:39 -0000
@@ -75,7 +75,7 @@
}

static void
-digest_update(PX_MD * h, const uint8 *data, uint dlen)
+digest_update(PX_MD * h, const uint8 *data, unsigned dlen)
{
MHASH mh = (MHASH) h->p.ptr;

@@ -86,7 +86,7 @@
digest_finish(PX_MD * h, uint8 *dst)
{
MHASH mh = (MHASH) h->p.ptr;
- uint hlen = digest_result_size(h);
+ unsigned hlen = digest_result_size(h);
hashid id = mhash_get_mhash_algo(mh);
uint8 *buf = mhash_end(mh);

@@ -136,7 +136,7 @@
}

static int
-cipher_init(PX_Cipher * c, const uint8 *key, uint klen, const uint8 *iv)
+cipher_init(PX_Cipher * c, const uint8 *key, unsigned klen, const uint8 *iv)
{
int err;
MCRYPT ctx = (MCRYPT) c->ptr;
@@ -150,7 +150,7 @@
}

static int
-cipher_encrypt(PX_Cipher * c, const uint8 *data, uint dlen, uint8 *res)
+cipher_encrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
{
int err;
MCRYPT ctx = (MCRYPT) c->ptr;
@@ -164,7 +164,7 @@
}

static int
-cipher_decrypt(PX_Cipher * c, const uint8 *data, uint dlen, uint8 *res)
+cipher_decrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
{
int err;
MCRYPT ctx = (MCRYPT) c->ptr;
Index: contrib/pgcrypto/openssl.c
===================================================================
RCS file: /opt/cvs/pgsql/pgsql/contrib/pgcrypto/openssl.c,v
retrieving revision 1.8
diff -u -r1.8 openssl.c
--- contrib/pgcrypto/openssl.c 5 Nov 2001 17:46:23 -0000 1.8
+++ contrib/pgcrypto/openssl.c 20 Nov 2001 11:35:39 -0000
@@ -60,7 +60,7 @@
}

static void
-digest_update(PX_MD * h, const uint8 *data, uint dlen)
+digest_update(PX_MD * h, const uint8 *data, unsigned dlen)
{
EVP_MD_CTX *ctx = (EVP_MD_CTX *) h->p.ptr;

@@ -108,8 +108,8 @@
const EVP_CIPHER *evp_ciph;
uint8 key[EVP_MAX_KEY_LENGTH];
uint8 iv[EVP_MAX_IV_LENGTH];
- uint klen;
- uint init;
+ unsigned klen;
+ unsigned init;
} ossldata;

/* generic EVP */
@@ -133,7 +133,7 @@
static uint
gen_evp_iv_size(PX_Cipher * c)
{
- uint ivlen;
+ unsigned ivlen;
ossldata *od = (ossldata *) c->ptr;

ivlen = EVP_CIPHER_iv_length(od->evp_ciph);
@@ -153,10 +153,10 @@
/* fun */

static int
-gen_evp_init(PX_Cipher * c, const uint8 *key, uint klen, const uint8 *iv)
+gen_evp_init(PX_Cipher * c, const uint8 *key, unsigned klen, const uint8 *iv)
{
ossldata *od = (ossldata *) c->ptr;
- uint bs = gen_evp_block_size(c);
+ unsigned bs = gen_evp_block_size(c);

if (iv)
memcpy(od->iv, iv, bs);
@@ -179,7 +179,7 @@
}

static int
-gen_evp_encrypt(PX_Cipher * c, const uint8 *data, uint dlen, uint8 *res)
+gen_evp_encrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
{
ossldata *od = c->ptr;

@@ -190,7 +190,7 @@
}

static int
-gen_evp_decrypt(PX_Cipher * c, const uint8 *data, uint dlen, uint8 *res)
+gen_evp_decrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
{
ossldata *od = c->ptr;

@@ -203,7 +203,7 @@
/* Blowfish */

static int
-bf_init(PX_Cipher * c, const uint8 *key, uint klen, const uint8 *iv)
+bf_init(PX_Cipher * c, const uint8 *key, unsigned klen, const uint8 *iv)
{
ossldata *od = c->ptr;

@@ -217,9 +217,9 @@
}

static int
-bf_ecb_encrypt(PX_Cipher * c, const uint8 *data, uint dlen, uint8 *res)
+bf_ecb_encrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
{
- uint bs = gen_evp_block_size(c),
+ unsigned bs = gen_evp_block_size(c),
i;
ossldata *od = c->ptr;

@@ -229,9 +229,9 @@
}

static int
-bf_ecb_decrypt(PX_Cipher * c, const uint8 *data, uint dlen, uint8 *res)
+bf_ecb_decrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
{
- uint bs = gen_evp_block_size(c),
+ unsigned bs = gen_evp_block_size(c),
i;
ossldata *od = c->ptr;

@@ -241,7 +241,7 @@
}

static int
-bf_cbc_encrypt(PX_Cipher * c, const uint8 *data, uint dlen, uint8 *res)
+bf_cbc_encrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
{
ossldata *od = c->ptr;

@@ -250,7 +250,7 @@
}

static int
-bf_cbc_decrypt(PX_Cipher * c, const uint8 *data, uint dlen, uint8 *res)
+bf_cbc_decrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
{
ossldata *od = c->ptr;

@@ -259,7 +259,7 @@
}

static int
-bf_cfb64_encrypt(PX_Cipher * c, const uint8 *data, uint dlen, uint8 *res)
+bf_cfb64_encrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
{
ossldata *od = c->ptr;

@@ -269,7 +269,7 @@
}

static int
-bf_cfb64_decrypt(PX_Cipher * c, const uint8 *data, uint dlen, uint8 *res)
+bf_cfb64_decrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
{
ossldata *od = c->ptr;

@@ -279,7 +279,7 @@
}

static int
-bf_ofb64_encrypt(PX_Cipher * c, const uint8 *data, uint dlen, uint8 *res)
+bf_ofb64_encrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
{
ossldata *od = c->ptr;

@@ -288,7 +288,7 @@
}

static int
-bf_ofb64_decrypt(PX_Cipher * c, const uint8 *data, uint dlen, uint8 *res)
+bf_ofb64_decrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
{
ossldata *od = c->ptr;

@@ -371,7 +371,7 @@
static int px_openssl_initialized = 0;

/* ATM not needed
-static void *o_alloc(uint s) { return px_alloc(s); }
+static void *o_alloc(unsigned s) { return px_alloc(s); }
static void *o_realloc(void *p) { return px_realloc(p); }
static void o_free(void *p) { px_free(p); }
*/
@@ -416,7 +416,7 @@
int
px_find_cipher(const char *name, PX_Cipher ** res)
{
- uint i;
+ unsigned i;
PX_Cipher *c = NULL,
*csrc;
ossldata *od;
Index: contrib/pgcrypto/pgcrypto.c
===================================================================
RCS file: /opt/cvs/pgsql/pgsql/contrib/pgcrypto/pgcrypto.c,v
retrieving revision 1.10
diff -u -r1.10 pgcrypto.c
--- contrib/pgcrypto/pgcrypto.c 25 Oct 2001 05:49:19 -0000 1.10
+++ contrib/pgcrypto/pgcrypto.c 20 Nov 2001 11:35:39 -0000
@@ -51,7 +51,7 @@
{
bytea *arg;
text *name;
- uint len,
+ unsigned len,
hlen;
PX_MD *md;
bytea *res;
@@ -117,7 +117,7 @@
bytea *arg;
bytea *key;
text *name;
- uint len,
+ unsigned len,
hlen,
klen;
PX_HMAC *h;
@@ -187,7 +187,7 @@
pg_gen_salt(PG_FUNCTION_ARGS)
{
text *arg0;
- uint len;
+ unsigned len;
text *res;
char buf[PX_MAX_SALT_LEN + 1];

@@ -221,7 +221,7 @@
{
text *arg0;
int rounds;
- uint len;
+ unsigned len;
text *res;
char buf[PX_MAX_SALT_LEN + 1];

@@ -256,7 +256,7 @@
{
text *arg0;
text *arg1;
- uint len0,
+ unsigned len0,
len1,
clen;
char *buf0,
@@ -319,7 +319,7 @@
*res;
text *type;
PX_Combo *c;
- uint dlen,
+ unsigned dlen,
klen,
rlen;

@@ -368,7 +368,7 @@
*res;
text *type;
PX_Combo *c;
- uint dlen,
+ unsigned dlen,
klen,
rlen;

@@ -417,7 +417,7 @@
*res;
text *type;
PX_Combo *c;
- uint dlen,
+ unsigned dlen,
klen,
ivlen,
rlen;
@@ -471,7 +471,7 @@
*res;
text *type;
PX_Combo *c;
- uint dlen,
+ unsigned dlen,
klen,
rlen,
ivlen;
@@ -542,8 +542,8 @@
void *res;
char buf[PX_MAX_NAMELEN + 1],
*p;
- uint len;
- uint i;
+ unsigned len;
+ unsigned i;
int err;

len = VARSIZE(name) - VARHDRSZ;
Index: contrib/pgcrypto/px-hmac.c
===================================================================
RCS file: /opt/cvs/pgsql/pgsql/contrib/pgcrypto/px-hmac.c,v
retrieving revision 1.2
diff -u -r1.2 px-hmac.c
--- contrib/pgcrypto/px-hmac.c 25 Oct 2001 05:49:20 -0000 1.2
+++ contrib/pgcrypto/px-hmac.c 20 Nov 2001 11:35:39 -0000
@@ -50,9 +50,9 @@
}

static void
-hmac_init(PX_HMAC * h, const uint8 *key, uint klen)
+hmac_init(PX_HMAC * h, const uint8 *key, unsigned klen)
{
- uint bs,
+ unsigned bs,
hlen,
i;
uint8 *keybuf;
@@ -88,14 +88,14 @@
hmac_reset(PX_HMAC * h)
{
PX_MD *md = h->md;
- uint bs = px_md_block_size(md);
+ unsigned bs = px_md_block_size(md);

px_md_reset(md);
px_md_update(md, h->p.ipad, bs);
}

static void
-hmac_update(PX_HMAC * h, const uint8 *data, uint dlen)
+hmac_update(PX_HMAC * h, const uint8 *data, unsigned dlen)
{
px_md_update(h->md, data, dlen);
}
@@ -104,7 +104,7 @@
hmac_finish(PX_HMAC * h, uint8 *dst)
{
PX_MD *md = h->md;
- uint bs,
+ unsigned bs,
hlen;
uint8 *buf;

@@ -127,7 +127,7 @@
static void
hmac_free(PX_HMAC * h)
{
- uint bs;
+ unsigned bs;

bs = px_md_block_size(h->md);
px_md_free(h->md);
@@ -148,7 +148,7 @@
int err;
PX_MD *md;
PX_HMAC *h;
- uint bs;
+ unsigned bs;

err = px_find_digest(name, &md);
if (err)
Index: contrib/pgcrypto/px.c
===================================================================
RCS file: /opt/cvs/pgsql/pgsql/contrib/pgcrypto/px.c,v
retrieving revision 1.4
diff -u -r1.4 px.c
--- contrib/pgcrypto/px.c 8 Nov 2001 15:56:58 -0000 1.4
+++ contrib/pgcrypto/px.c 20 Nov 2001 11:35:39 -0000
@@ -51,23 +51,23 @@
*/

static uint
-combo_encrypt_len(PX_Combo * cx, uint dlen)
+combo_encrypt_len(PX_Combo * cx, unsigned dlen)
{
return dlen + 512;
}

static uint
-combo_decrypt_len(PX_Combo * cx, uint dlen)
+combo_decrypt_len(PX_Combo * cx, unsigned dlen)
{
return dlen;
}

static int
-combo_init(PX_Combo * cx, const uint8 *key, uint klen,
- const uint8 *iv, uint ivlen)
+combo_init(PX_Combo * cx, const uint8 *key, unsigned klen,
+ const uint8 *iv, unsigned ivlen)
{
int err;
- uint bs,
+ unsigned bs,
ks,
ivs;
PX_Cipher *c = cx->cipher;
@@ -104,12 +104,12 @@
}

static int
-combo_encrypt(PX_Combo * cx, const uint8 *data, uint dlen,
- uint8 *res, uint *rlen)
+combo_encrypt(PX_Combo * cx, const uint8 *data, unsigned dlen,
+ uint8 *res, unsigned *rlen)
{
int err = 0;
uint8 *bbuf;
- uint bs,
+ unsigned bs,
maxlen,
bpos,
i,
@@ -175,13 +175,13 @@
}

static int
-combo_decrypt(PX_Combo * cx, const uint8 *data, uint dlen,
- uint8 *res, uint *rlen)
+combo_decrypt(PX_Combo * cx, const uint8 *data, unsigned dlen,
+ uint8 *res, unsigned *rlen)
{
- uint bs,
+ unsigned bs,
i,
pad;
- uint pad_ok;
+ unsigned pad_ok;

PX_Cipher *c = cx->cipher;

Index: contrib/pgcrypto/px.h
===================================================================
RCS file: /opt/cvs/pgsql/pgsql/contrib/pgcrypto/px.h,v
retrieving revision 1.4
diff -u -r1.4 px.h
--- contrib/pgcrypto/px.h 5 Nov 2001 17:46:23 -0000 1.4
+++ contrib/pgcrypto/px.h 20 Nov 2001 11:35:39 -0000
@@ -64,16 +64,16 @@

struct px_digest
{
- uint (*result_size) (PX_MD * h);
- uint (*block_size) (PX_MD * h);
+ unsigned (*result_size) (PX_MD * h);
+ unsigned (*block_size) (PX_MD * h);
void (*reset) (PX_MD * h);
- void (*update) (PX_MD * h, const uint8 *data, uint dlen);
+ void (*update) (PX_MD * h, const uint8 *data, unsigned dlen);
void (*finish) (PX_MD * h, uint8 *dst);
void (*free) (PX_MD * h);
/* private */
union
{
- uint code;
+ unsigned code;
const void *ptr;
} p;
};
@@ -86,13 +86,13 @@

struct px_hmac
{
- uint (*result_size) (PX_HMAC * h);
- uint (*block_size) (PX_HMAC * h);
+ unsigned (*result_size) (PX_HMAC * h);
+ unsigned (*block_size) (PX_HMAC * h);
void (*reset) (PX_HMAC * h);
- void (*update) (PX_HMAC * h, const uint8 *data, uint dlen);
+ void (*update) (PX_HMAC * h, const uint8 *data, unsigned dlen);
void (*finish) (PX_HMAC * h, uint8 *dst);
void (*free) (PX_HMAC * h);
- void (*init) (PX_HMAC * h, const uint8 *key, uint klen);
+ void (*init) (PX_HMAC * h, const uint8 *key, unsigned klen);

PX_MD *md;
/* private */
@@ -105,13 +105,13 @@

struct px_cipher
{
- uint (*block_size) (PX_Cipher * c);
- uint (*key_size) (PX_Cipher * c); /* max key len */
- uint (*iv_size) (PX_Cipher * c);
-
- int (*init) (PX_Cipher * c, const uint8 *key, uint klen, const uint8 *iv);
- int (*encrypt) (PX_Cipher * c, const uint8 *data, uint dlen, uint8 *res);
- int (*decrypt) (PX_Cipher * c, const uint8 *data, uint dlen, uint8 *res);
+ unsigned (*block_size) (PX_Cipher * c);
+ unsigned (*key_size) (PX_Cipher * c); /* max key len */
+ unsigned (*iv_size) (PX_Cipher * c);
+
+ int (*init) (PX_Cipher * c, const uint8 *key, unsigned klen, const uint8 *iv);
+ int (*encrypt) (PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res);
+ int (*decrypt) (PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res);
void (*free) (PX_Cipher * c);
/* private */
void *ptr;
@@ -120,18 +120,18 @@

struct px_combo
{
- int (*init) (PX_Combo * cx, const uint8 *key, uint klen,
- const uint8 *iv, uint ivlen);
- int (*encrypt) (PX_Combo * cx, const uint8 *data, uint dlen,
- uint8 *res, uint *rlen);
- int (*decrypt) (PX_Combo * cx, const uint8 *data, uint dlen,
- uint8 *res, uint *rlen);
- uint (*encrypt_len) (PX_Combo * cx, uint dlen);
- uint (*decrypt_len) (PX_Combo * cx, uint dlen);
+ int (*init) (PX_Combo * cx, const uint8 *key, unsigned klen,
+ const uint8 *iv, unsigned ivlen);
+ int (*encrypt) (PX_Combo * cx, const uint8 *data, unsigned dlen,
+ uint8 *res, unsigned *rlen);
+ int (*decrypt) (PX_Combo * cx, const uint8 *data, unsigned dlen,
+ uint8 *res, unsigned *rlen);
+ unsigned (*encrypt_len) (PX_Combo * cx, unsigned dlen);
+ unsigned (*decrypt_len) (PX_Combo * cx, unsigned dlen);
void (*free) (PX_Combo * cx);

PX_Cipher *cipher;
- uint padding;
+ unsigned padding;
};

int px_find_digest(const char *name, PX_MD ** res);
Index: contrib/pgcrypto/rijndael.c
===================================================================
RCS file: /opt/cvs/pgsql/pgsql/contrib/pgcrypto/rijndael.c,v
retrieving revision 1.6
diff -u -r1.6 rijndael.c
--- contrib/pgcrypto/rijndael.c 5 Nov 2001 17:46:23 -0000 1.6
+++ contrib/pgcrypto/rijndael.c 20 Nov 2001 11:35:39 -0000
@@ -492,7 +492,7 @@
*/

void
-aes_set_key(rijndael_ctx * ctx, const uint8 *key, uint keybits, int enc)
+aes_set_key(rijndael_ctx * ctx, const uint8 *key, unsigned keybits, int enc)
{
uint32 *k;

Index: contrib/pgcrypto/rijndael.h
===================================================================
RCS file: /opt/cvs/pgsql/pgsql/contrib/pgcrypto/rijndael.h,v
retrieving revision 1.4
diff -u -r1.4 rijndael.h
--- contrib/pgcrypto/rijndael.h 5 Nov 2001 17:46:23 -0000 1.4
+++ contrib/pgcrypto/rijndael.h 20 Nov 2001 11:35:39 -0000
@@ -48,7 +48,7 @@

/* conventional interface */

-void aes_set_key(rijndael_ctx * ctx, const uint8 *key, uint keybits, int enc);
+void aes_set_key(rijndael_ctx * ctx, const uint8 *key, unsigned keybits, int enc);
void aes_ecb_encrypt(rijndael_ctx * ctx, uint8 *data, unsigned len);
void aes_ecb_decrypt(rijndael_ctx * ctx, uint8 *data, unsigned len);
void aes_cbc_encrypt(rijndael_ctx * ctx, uint8 *iva, uint8 *data, unsigned len);

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2001-11-20 15:42:33 Re: bytea functions documentation
Previous Message Greg Sabino Mullane 2001-11-20 14:34:39 Re: Version checking when loading psql