SHA1 reversed bytes?

Tony Garnock-Jones tonyg at lshift.net
Fri Mar 11 09:53:44 UTC 2005


Ned Konz wrote:
> Well, there you go... So use SecureHashAlgorithm instead. On my little-endian 
> machine, BTW, this is what happens:
> [...]

Yep, SecureHashAlgorithm is the way to go. Thanks.

For the record, these two expressions are equivalent:

   (SHA1 new hashMessage: 'hi') reversed
   (SecureHashAlgorithm new hashMessage: 'hi') asByteArray

The differences:

  - SHA1 returns a ByteArray
  - SecureHashAlgorithm returns a LargePositiveInteger (which means
    you have to be careful when converting to hex, if that's required)

  - SHA1 returns bytes in the reverse order from openssl, java, c# etc
  - SecureHashAlgorithm returns bytes in the same order as openssl, java,
    c# etc

Consequently I'll retire SHA1 in favour of SecureHashAlgorithm - 
although of course some care will have to be taken regarding 
left-zero-padding during the conversion from LargePositiveInteger to hex!

Cheers,
   Tony
-- 
  [][][] Tony Garnock-Jones  | Mob: +44 (0)7905 974 211
    [][] LShift Ltd          | Tel: +44 (0)20 7729 7060
  []  [] www.lshift.net      | Email: tonyg at lshift.net



More information about the Squeak-dev mailing list