patch for cipher/sha512.c (u64 numbers)
mooney at dogbert.cc.ndsu.NoDak.edu
Fri May 9 22:07:02 CEST 2003
In regard to: Re: patch for cipher/sha512.c (u64 numbers), David Shaw said...:
>-----BEGIN PGP SIGNED MESSAGE-----
>On Fri, May 09, 2003 at 09:05:43AM -0400, David Shaw wrote:
>> On Thu, May 08, 2003 at 05:01:12PM +0200, Werner Koch wrote:
>> > On Tue, 6 May 2003 16:50:52 +0200, Christoph Moench-Tegeder said:
>> > > In cipher/sha512.c u64 (long long int on most platforms) constants
>> > > are without modifier 'LL' in assignments. At least HP's cc in ANSI
>> > To my knowledge the LL suffix is not C-89 and thus we can't use it.
>> > The simple solution is to fix HP's compiler or write an autoconf test
>> > to detect such a broken compiler.
>> Yes, LL is C99. I think I can make an autoconf test without too much
>Okay, here's what I'm thinking:
>1) c89 does not guarantee that 64-bit ints are available, and does not
>2) c99 does guarantee 64-bit ints, and does support LL.
>3) Some/many supposedly "c89" compilers support 64-bit ints and LL
>anyway as an extension.
>So the answer is to always use LL in the code, and try and weed out
>any compilers that don't support LL in autoconf. This will work on
>all c99 compilers, and any c89 compilers that support 64-bit ints. If
>it is a pure c89 compiler (and therefore doesn't support 64-bit ints),
>it doesn't matter if it supports LL or not.
I don't think that's quite correct. c89 says nothing about the
availability of 64-bit ints. The size of short int vs. int vs. long int
is implementation dependant. A `long int' could be a 64 bit type with
a pure c89 compiler quite easily.
What c89 doesn't include is the `long long int' type or the LL "postfix".
On a pure 32 bit architecture, the `long long int' extension to c89
may be the only way to get a 64 bit type, but on a 64 bit architecture
`long long int' might be larger than 64 bits, especially for those
platforms that have some or all of the c99 bits.
That also means that blindly using `LL' as the postfix might be incorrect,
since a long long int might be 128 bits.
> The only thing this test
>won't handle is a c89 compiler that does support 64-bit ints, but does
>not support LL. I can live with that, especially since the digest
>code in question is optional anyway.
You're talking about several vendor compilers in 64 bit mode. The
Solaris, Tru64, and IRIX compilers have all added bits and peices of c99
in recent versions, but all of them supported a 64 bit type *that was not
long long int* well before they supported `LL'.
What would be better is to use AC_SIZEOF to find a 64 bit type, trying
first `long' and then `long long'. Next, check for the `int64_t', and if
it doesn't exist, use AC_TYPEDEF to define the "right sized" integer type
to it. At the same time, define a
(for long == 8 bytes):
#define INT64_INITIALIZER L
#define INT64_FORMATTER ld
(for long long == 8 bytes):
#define INT64_INITIALIZER LL
#define INT64_FORMATTER lld /* or whatever it is for long long */
and then use those throughout the code.
I could help with the autoconf code, if you want.
Tim Mooney mooney at dogbert.cc.ndsu.NoDak.edu
Information Technology Services (701) 231-1076 (Voice)
Room 242-J6, IACC Building (701) 231-8541 (Fax)
North Dakota State University, Fargo, ND 58105-5164
More information about the Gnupg-devel