[Botan-devel] Endianness

Jack Lloyd lloyd at randombit.net
Tue Jan 13 12:16:23 EST 2009


On Tue, Jan 13, 2009 at 05:21:24PM +0100, Rickard Bondesson wrote:
> Hi
> 
> Am I correct if I state that BigInt is big-endian internally, but
> the binary_decode and binary_encode have little-endian interfaces?

Um, maybe? This sort of depends on how you look at the memory
ordering, I think. But here are the facts:

- In BigInt, rep[0] is the least significant word, and
  rep[rep.size()-1] is the most significant. (The bytes in each word
  are encoded as either big or little endian, depending on the CPU).

- In the binary encoding of a BigInt, array[0] is the most significant
  byte and array[sizeof(array)-1] is the least significant.

So they do certainly use the opposite convention. My inclination would
be to call BigInt's rep little-endian and the encoding as big-endian,
though - in the encoding, the MSB is stored at the lowest address (0),
next to most significant byte is at the next lowest address (1), etc,
which, while I have not had my caffeine yet this morning, seems big
endian to me.

In any case if the opposite convention is desired the easiest thing to
do is probably call std::reverse on the buffer.

-Jack



More information about the botan-devel mailing list