Bruno Haible <[EMAIL PROTECTED]> writes: > Hi Simon, > > On MacOS X 10.3.9 the 'gc-gnulib' (or 'gc-des') module fails to build: > > depbase=`echo gc-gnulib.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\ > gcc -std=gnu99 -DHAVE_CONFIG_H -DEXEEXT=\"\" -DEXEEXT=\"\" -DNO_XMALLOC > -DEXEEXT=\"\" -I. -I.. -I../intl -Wall -g -O2 -MT gc-gnulib.o -MD -MP -MF > $depbase.Tpo -c -o gc-gnulib.o gc-gnulib.c &&\ > mv -f $depbase.Tpo $depbase.Po > In file included from gc-gnulib.c:65: > des.h:62: error: conflicting types for `des_setkey' > /usr/include/unistd.h:196: error: previous declaration of `des_setkey' > make[3]: *** [gc-gnulib.o] Error 1 > > The declaration in /usr/include/unistd.h looks like this: > > int des_setkey(const char *key); > > which is clearly different from the one in gnulib's des.h: > > extern void > des_setkey (des_ctx *ctx, const char * key);
Gnulib's goal here isn't trying to be compatible with whatever standard specified the MacOS X 'des_setkey'. I suspect their functions use global variables for the context, which isn't something we should promote. I changed the namespace to gl_des as below. /Simon Index: lib/des.c =================================================================== RCS file: /sources/gnulib/gnulib/lib/des.c,v retrieving revision 1.3 diff -u -p -r1.3 des.c --- lib/des.c 29 Oct 2006 21:52:55 -0000 1.3 +++ lib/des.c 12 Mar 2007 11:37:57 -0000 @@ -1,5 +1,5 @@ /* des.c --- DES and Triple-DES encryption/decryption Algorithm - * Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004, 2005, 2006 + * Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004, 2005, 2006, 2007 * Free Software Foundation, Inc. * * This file is free software; you can redistribute it and/or modify @@ -54,7 +54,7 @@ * unsigned char plaintext[8]; * unsigned char ciphertext[8]; * unsigned char recoverd[8]; - * des_ctx context; + * gl_des_ctx context; * * // Fill 'key' and 'plaintext' with some data * .... @@ -77,20 +77,20 @@ * unsigned char plaintext[8]; * unsigned char ciphertext[8]; * unsigned char recoverd[8]; - * tripledes_ctx context; + * gl_3des_ctx context; * * // If you would like to use two 64bit keys, fill 'key1' and'key2' * // then setup the encryption context: - * tripledes_set2keys(&context, key1, key2); + * gl_3des_set2keys(&context, key1, key2); * * // To use three 64bit keys with Triple-DES use: - * tripledes_set3keys(&context, key1, key2, key3); + * gl_3des_set3keys(&context, key1, key2, key3); * * // Encrypting plaintext with Triple-DES - * tripledes_ecb_encrypt(&context, plaintext, ciphertext); + * gl_3des_ecb_encrypt(&context, plaintext, ciphertext); * * // Decrypting ciphertext to recover the plaintext with Triple-DES - * tripledes_ecb_decrypt(&context, ciphertext, recoverd); + * gl_3des_ecb_decrypt(&context, ciphertext, recoverd); */ @@ -324,7 +324,7 @@ static const unsigned char weak_keys_chk }; bool -des_is_weak_key (const char * key) +gl_des_is_weak_key (const char * key) { char work[8]; int i, left, right, middle, cmp_result; @@ -424,14 +424,6 @@ des_is_weak_key (const char * key) data[6] = (right >> 8) &0xff; data[7] = right &0xff; /* - * Handy macros for encryption and decryption of data - */ -#define des_ecb_encrypt(ctx, from, to) des_ecb_crypt(ctx, from, to, 0) -#define des_ecb_decrypt(ctx, from, to) des_ecb_crypt(ctx, from, to, 1) -#define tripledes_ecb_encrypt(ctx, from, to) tripledes_ecb_crypt(ctx,from,to,0) -#define tripledes_ecb_decrypt(ctx, from, to) tripledes_ecb_crypt(ctx,from,to,1) - -/* * des_key_schedule(): Calculate 16 subkeys pairs (even/odd) for * 16 encryption rounds. * To calculate subkeys for decryption the caller @@ -530,7 +522,7 @@ des_key_schedule (const char * _rawkey, } void -des_setkey (des_ctx *ctx, const char * key) +gl_des_setkey (gl_des_ctx *ctx, const char * key) { int i; @@ -544,7 +536,7 @@ des_setkey (des_ctx *ctx, const char * k } bool -des_makekey (des_ctx *ctx, const char * key, size_t keylen) +gl_des_makekey (gl_des_ctx *ctx, const char * key, size_t keylen) { if (keylen != 8) return false; @@ -555,7 +547,7 @@ des_makekey (des_ctx *ctx, const char * } void -des_ecb_crypt (des_ctx *ctx, const char * _from, char * _to, int mode) +gl_des_ecb_crypt (gl_des_ctx *ctx, const char * _from, char * _to, int mode) { const unsigned char *from = (const unsigned char *) _from; unsigned char *to = (unsigned char *) _to; @@ -579,7 +571,7 @@ des_ecb_crypt (des_ctx *ctx, const char } void -tripledes_set2keys (tripledes_ctx *ctx, const char * key1, const char * key2) +gl_3des_set2keys (gl_3des_ctx *ctx, const char * key1, const char * key2) { int i; @@ -603,7 +595,7 @@ tripledes_set2keys (tripledes_ctx *ctx, } void -tripledes_set3keys (tripledes_ctx *ctx, const char * key1, +gl_3des_set3keys (gl_3des_ctx *ctx, const char * key1, const char * key2, const char * key3) { int i; @@ -626,9 +618,9 @@ tripledes_set3keys (tripledes_ctx *ctx, } void -tripledes_ecb_crypt (tripledes_ctx *ctx, - const char * _from, - char * _to, int mode) +gl_3des_ecb_crypt (gl_3des_ctx *ctx, + const char * _from, + char * _to, int mode) { const unsigned char *from = (const unsigned char *) _from; unsigned char *to = (unsigned char *) _to; @@ -668,12 +660,12 @@ tripledes_ecb_crypt (tripledes_ctx *ctx, } bool -tripledes_makekey (tripledes_ctx *ctx, const char * key, size_t keylen) +gl_3des_makekey (gl_3des_ctx *ctx, const char * key, size_t keylen) { if (keylen != 24) return false; - tripledes_set3keys (ctx, key, key + 8, key + 16); + gl_3des_set3keys (ctx, key, key + 8, key + 16); return !(des_is_weak_key (key) || des_is_weak_key (key + 8) Index: lib/des.h =================================================================== RCS file: /sources/gnulib/gnulib/lib/des.h,v retrieving revision 1.1 diff -u -p -r1.1 des.h --- lib/des.h 21 Oct 2005 12:28:18 -0000 1.1 +++ lib/des.h 12 Mar 2007 11:37:57 -0000 @@ -1,5 +1,5 @@ /* des.h --- DES cipher implementation. - * Copyright (C) 2005 Free Software Foundation, Inc. + * Copyright (C) 2005, 2007 Free Software Foundation, Inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published @@ -34,7 +34,7 @@ typedef struct { uint32_t encrypt_subkeys[32]; uint32_t decrypt_subkeys[32]; -} des_ctx; +} gl_des_ctx; /* * Encryption/Decryption context of Triple-DES @@ -43,12 +43,12 @@ typedef struct { uint32_t encrypt_subkeys[96]; uint32_t decrypt_subkeys[96]; -} tripledes_ctx; +} gl_3des_ctx; /* Check whether the 8 byte key is weak. Does not check the parity * bits of the key but simple ignore them. */ extern bool -des_is_weak_key (const char * key); +gl_des_is_weak_key (const char * key); /* * DES @@ -59,21 +59,21 @@ des_is_weak_key (const char * key); * Does not check parity bits, but simply ignore them. Does not check * for weak keys. */ extern void -des_setkey (des_ctx *ctx, const char * key); +gl_des_setkey (gl_des_ctx *ctx, const char * key); /* Fill a DES context CTX with subkeys calculated from 64bit KEY, with * weak key checking. Does not check parity bits, but simply ignore * them. */ extern bool -des_makekey (des_ctx *ctx, const char * key, size_t keylen); +gl_des_makekey (gl_des_ctx *ctx, const char * key, size_t keylen); /* Electronic Codebook Mode DES encryption/decryption of data * according to 'mode'. */ extern void -des_ecb_crypt (des_ctx *ctx, const char * from, char * to, int mode); +gl_des_ecb_crypt (gl_des_ctx *ctx, const char * from, char * to, int mode); -#define des_ecb_encrypt(ctx, from, to) des_ecb_crypt(ctx, from, to, 0) -#define des_ecb_decrypt(ctx, from, to) des_ecb_crypt(ctx, from, to, 1) +#define gl_des_ecb_encrypt(ctx, from, to) gl_des_ecb_crypt(ctx, from, to, 0) +#define gl_des_ecb_decrypt(ctx, from, to) gl_des_ecb_crypt(ctx, from, to, 1) /* Triple-DES * ---------- @@ -83,7 +83,9 @@ des_ecb_crypt (des_ctx *ctx, const char * 64bit keys in KEY1 and KEY2. Does not check the parity bits of the * keys, but simply ignore them. Does not check for weak keys. */ extern void -tripledes_set2keys (tripledes_ctx *ctx, const char * key1, const char * key2); +gl_3des_set2keys (gl_3des_ctx *ctx, + const char * key1, + const char * key2); /* * Fill a Triple-DES context CTX with subkeys calculated from three @@ -91,24 +93,29 @@ tripledes_set2keys (tripledes_ctx *ctx, * of the keys, but simply ignore them. Does not check for weak * keys. */ extern void -tripledes_set3keys (tripledes_ctx *ctx, const char * key1, - const char * key2, const char * key3); +gl_3des_set3keys (gl_3des_ctx *ctx, + const char * key1, + const char * key2, + const char * key3); /* Fill a Triple-DES context CTX with subkeys calculated from three * concatenated 64bit keys in KEY, with weak key checking. Does not * check the parity bits of the keys, but simply ignore them. */ extern bool -tripledes_makekey (tripledes_ctx *ctx, const char * key, size_t keylen); +gl_3des_makekey (gl_3des_ctx *ctx, + const char * key, + size_t keylen); /* Electronic Codebook Mode Triple-DES encryption/decryption of data * according to 'mode'. Sometimes this mode is named 'EDE' mode * (Encryption-Decryption-Encryption). */ extern void -tripledes_ecb_crypt (tripledes_ctx *ctx, - const char * from, - char * to, int mode); +gl_3des_ecb_crypt (gl_3des_ctx *ctx, + const char * from, + char * to, + int mode); -#define tripledes_ecb_encrypt(ctx, from, to) tripledes_ecb_crypt(ctx,from,to,0) -#define tripledes_ecb_decrypt(ctx, from, to) tripledes_ecb_crypt(ctx,from,to,1) +#define gl_3des_ecb_encrypt(ctx, from, to) gl_3des_ecb_crypt(ctx,from,to,0) +#define gl_3des_ecb_decrypt(ctx, from, to) gl_3des_ecb_crypt(ctx,from,to,1) #endif /* DES_H */ Index: lib/gc-gnulib.c =================================================================== RCS file: /sources/gnulib/gnulib/lib/gc-gnulib.c,v retrieving revision 1.22 diff -u -p -r1.22 gc-gnulib.c --- lib/gc-gnulib.c 14 Jan 2007 11:32:10 -0000 1.22 +++ lib/gc-gnulib.c 12 Mar 2007 11:37:57 -0000 @@ -187,7 +187,7 @@ typedef struct _gc_cipher_ctx { arcfour_context arcfourContext; #endif #ifdef GNULIB_GC_DES - des_ctx desContext; + gl_des_ctx desContext; #endif #ifdef GNULIB_GC_RIJNDAEL rijndaelKeyInstance aesEncKey; @@ -305,7 +305,7 @@ gc_cipher_setkey (gc_cipher_handle handl case GC_DES: if (keylen != 8) return GC_INVALID_CIPHER; - des_setkey (&ctx->desContext, key); + gl_des_setkey (&ctx->desContext, key); break; #endif @@ -443,7 +443,7 @@ gc_cipher_encrypt_inline (gc_cipher_hand #ifdef GNULIB_GC_DES case GC_DES: for (; len >= 8; len -= 8, data += 8) - des_ecb_encrypt (&ctx->desContext, data, data); + gl_des_ecb_encrypt (&ctx->desContext, data, data); break; #endif @@ -515,7 +515,7 @@ gc_cipher_decrypt_inline (gc_cipher_hand #ifdef GNULIB_GC_DES case GC_DES: for (; len >= 8; len -= 8, data += 8) - des_ecb_decrypt (&ctx->desContext, data, data); + gl_des_ecb_decrypt (&ctx->desContext, data, data); break; #endif