Saturday, March 10, 2007

A Small Start on SHA1 Performance Part II

The function k is a bit inefficient.


k n
| (0 <= n) &&amp;amp; (n <= 19) = 0x5a827999
| (20 <= n) && (n <= 39) = 0x6ed9eba1
| (40 <= n) && (n <= 59) = 0x8f1bbcdc
| (60 <= n) && (n <= 79) = 0xca62c1d6
| otherwise = error "invalid index for k"


Since we know that n is always greater than or equal 0 and less than 80, we can use this.


k' n
| n <= 19 = 0x5a827999
| n <= 39 = 0x6ed9eba1
| n <= 59 = 0x8f1bbcdc
| n <= 79 = 0xca62c1d6


This gives a bit more of a saving.


Sat Mar 10 13:49 2007 Time and Allocation Profiling Report (Final)

perfTest +RTS -p -RTS eg

total time = 9.55 secs (191 ticks @ 50 ms)
total alloc = 1,847,562,152 bytes (excludes profiling overheads)

COST CENTRE MODULE %time %alloc

oneBlock Data.Digest.SHA1 25.1 30.7
f Data.Digest.SHA1 16.2 11.7
$& Data.Digest.SHA1 14.7 17.3
rotL Data.Digest.SHA1 14.1 14.4
blockWord8sIn512 Data.Digest.SHA1 8.9 3.5
k' Data.Digest.SHA1 4.7 0.0
pad Data.Digest.SHA1 4.2 2.8
test2 Main 4.2 7.0
getWord32s' Data.Digest.SHA1 2.6 5.3
blockWord8sIn32 Data.Digest.SHA1 2.6 4.3
hash Data.Digest.SHA1 1.0 0.0
fromBytes Data.Digest.SHA1 1.0 2.8


We can do the same with f.


Sat Mar 10 14:03 2007 Time and Allocation Profiling Report (Final)

perfTest +RTS -p -RTS eg

total time = 8.70 secs (174 ticks @ 50 ms)
total alloc = 1,722,554,056 bytes (excludes profiling overheads)

COST CENTRE MODULE %time %alloc

oneBlock Data.Digest.SHA1 29.3 32.9
rotL Data.Digest.SHA1 19.0 15.4
$& Data.Digest.SHA1 13.8 18.6
f' Data.Digest.SHA1 11.5 5.3
getWord32s' Data.Digest.SHA1 8.0 5.7
test2 Main 5.7 7.5
blockWord8sIn512 Data.Digest.SHA1 4.0 3.8
fromBytes Data.Digest.SHA1 2.9 3.0
k' Data.Digest.SHA1 2.3 0.0
pad Data.Digest.SHA1 1.7 3.0
blockWord8sIn32 Data.Digest.SHA1 1.7 4.6

No comments: