Split and XOR a 160bits SHA Digest?

yerl@REDACTED yerl@REDACTED
Fri May 14 17:15:58 CEST 2004


Hi All,

I'm wondering if there are a better way to split and xor a 160 bits sha-digest. I tryed this 2 functions (see below), but both are very slow.

% Create 160 bits masks
-define(BIT_MASK1, 4294967295). % First 32 bits on
-define(BIT_MASK2, 18446744069414584320). % Second 32 bits on
-define(BIT_MASK3, 79228162495817593519834398720). % ...
-define(BIT_MASK4, 340282366841710300949110269838224261120). 
-define(BIT_MASK5, 1461501636990620551282746369252908412224164331520).


split_and_xor_version1(S, Key) ->
<<SHA:160>> = crypto:sha_mac(S, Key),
D5 = SHA band ?BIT_MASK5,
D4 = SHA band ?BIT_MASK4,
D3 = SHA band ?BIT_MASK3,
D2 = SHA band ?BIT_MASK2,
D1 = SHA band ?BIT_MASK1,
D5 bxor D4 bxor D3 bxor D2 bxor D1.

split_and_xor_version2(S, Key) ->
<<D5:32, D4:32, D3:32, D2:32, D1:32>> = crypto:sha_mac(S, Key),
D5 bxor D4 bxor D3 bxor D2 bxor D1.

Any other ideas?

Regards,
/yerl




More information about the erlang-questions mailing list