Split and XOR a 160bits SHA Digest?

yerl@REDACTED yerl@REDACTED
Fri May 14 18:26:21 CEST 2004


Hi Sean,

I'm running it in erl shell like this:

$ erlc -W -v split_and_xor.erl
$ erl -noinput -noshell -nostick +B -s split_and_xor test

By compiling, do you mean native compilation? like:
$ erlc +native +'{hipe,[verbose,debug]} .......

I never could setup the native compilation in my box (Suse Linux). When I use native, any module compiles correctly and   immediatly crashes in startup.

Thanks
/yerl




>Note that the bit syntax has a special implementation for >commands 
>which are run in the the erl shell - are you seeing this >slowness in a 
>properly compiled module or just running it at the shell?
>


----Message d'origine----
>Copie à: erlang-questions@REDACTED
>De: Sean Hinde <sean.hinde@REDACTED>
>Sujet: Re: Split and XOR a 160bits SHA Digest?
>Date: Fri, 14 May 2004 17:07:57 +0100
>A: yerl@REDACTED
>
>
>
>On 14 May 2004, at 18:15, yerl@REDACTED wrote:
>
>> 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?
>
>I would expect at least the second to do quite well in normal compiled 
>code.
>
>Note that the bit syntax has a special implementation for commands 
>which are run in the the erl shell - are you seeing this slowness in a 
>properly compiled module or just running it at the shell?
>
>Sean
>
>




More information about the erlang-questions mailing list