Re: SHA-512 and 128-bit integers

From: Benjamin Goldberg (goldbb2_at_earthlink.net)
Date: 04/29/03


Date: Tue, 29 Apr 2003 15:42:44 -0400


Ken Very Big Liar wrote:
>
> Ok, does anyone have a good solution to using 128-bit integers on 32
> bit machines?

Well, if you need a *full* set of arithmetic operations (add, subtract,
multiply, divide, modulo, pow, log, etc.) for your 128-bit integers,
then I would suggest that you get a bignum library.

> The Linux Pent III that I'm using to develop the different SHAs
> supports the C type "long long", which is a 64-bit type, but there is
> no support for 128-bit integers. Probably because there is no machine
> code for this, I'm not sure.

Indeed -- there are few, if any, machines with opcodes designed for 128
bit math.

Fortunatly, if you only need addition of 128-bit ints and 32-bit ints,
you can do:

   typedef uint32 int128[4];
   #define add128(a, b) \
      ((a[0] += (b)) >= (b)) || ++a[1] || ++a[2] || ++a[3])

> I noticed that the even Tom's crypt library sidesteps this issue by
> hoping that you won't be using huge data sets.

Ehh, what are you talking about?

> That's fine I guess, but I wanted to take a quick poll out there to see
> what others have come up with. An unsigned 64-bit integer has a
> maximum value of 18,446,744,073,709,551,615.

Which is actually 18,446,744,073,709,551,616 different possible values.

> Divide that up by 8 (the traditional number of bits in a byte) and you
> get 2,305,843,009,213,693,951. Ok, a pretty huge number. Nevermind.
> ;-)

Why are you dividing 2^64 by 8?

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


Relevant Pages

  • Re: Bug in mktime(), cant go past year 2038
    ... "we can't just recompile everything all at once" objection is bogus. ... Systems would be SUS v4 compliant over the next ten years, ... machines, if there were a mix of 32-bit and 64-bit machines, the ... systems that won't have 64-bit ints even in 25 years. ...
    (comp.unix.programmer)
  • Re: 32 or 64 bit processor info in C
    ... registers, so it makes sense to use the same registers to hold pointers and ... ints. ... about imposing non-trivial architecture restrictions on the machines ... We're not taling about removing latitude from the language so that DSP chips and the like can't use funny integer sizes if it is appropriate for them, nor are we talking about modifying the standard. ...
    (comp.lang.c)
  • Re: An implementation where sizeof(short int) does not divide sizeof(int)
    ... > CDC Cyber UTexas C compiler ... But on those machines it is much more reasonable to have 48 bit ints ... (The reason behind it is that the multiply ...
    (comp.lang.c)
  • Re: An implementation where sizeof(short int) does not divide sizeof(int)
    ... > CDC Cyber UTexas C compiler ... But on those machines it is much more reasonable to have 48 bit ints ... with the remaining 16 bits garbage. ...
    (comp.lang.c)
  • Re: Declaration problem
    ... Longs are the native size and therefore more effecient than ints on 32 ... bit machines. ... memory is the same I ... Simon Murphy ...
    (microsoft.public.excel.programming)