Skip to content

Commit

Permalink
Use newly implemented :radix[] notation where it works
Browse files Browse the repository at this point in the history
Also note where it can be used once some bugs are fixed
  • Loading branch information
skids committed Oct 30, 2012
1 parent aa45ac0 commit 0f4d567
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
27 changes: 11 additions & 16 deletions lib/Sum/SHA.pm6
Expand Up @@ -184,10 +184,7 @@ role Sum::SHA1 [ :$insecure_sha0_obselete = False, :$mod8 = False ] does Sum {
# First 16 uint32's are a straight copy of the data. # First 16 uint32's are a straight copy of the data.
# When endianness matches and with native types, # When endianness matches and with native types,
# this would boil down to a simple memcpy. # this would boil down to a simple memcpy.
my @m = ((($block[ (4 X* 0..^16)]) X+< 24) my @m = (:256[ $block[ $_ ..^ $_+4 ] ] for 0,4,{$^idx + 4} ...^ 64);
<<+|<< (($block[ 1 X+ (4 X* 0..^16)]) X+< 16)
<<+|<< (($block[ 2 X+ (4 X* 0..^16)]) X+< 8)
<<+|<< (($block[ 3 X+ (4 X* 0..^16)])));


# Fill the rest of the scratchpad with permutations. # Fill the rest of the scratchpad with permutations.
@m.push(rol(([+^] @m[* <<-<< (3,8,14,16)]),+!$insecure_sha0_obselete)) @m.push(rol(([+^] @m[* <<-<< (3,8,14,16)]),+!$insecure_sha0_obselete))
Expand Down Expand Up @@ -216,6 +213,8 @@ role Sum::SHA1 [ :$insecure_sha0_obselete = False, :$mod8 = False ] does Sum {
# push that many addends, you probably have bigger problems. # push that many addends, you probably have bigger problems.
return fail(X::Sum::Spill.new()) if $!o > 0xffffffffffffffff; return fail(X::Sum::Spill.new()) if $!o > 0xffffffffffffffff;


# This does not work yet on 32-bit machines
# :4294967296[@!s[]];
[+|] (@!s[] »+<« (32 X* (4,3,2,1,0))); [+|] (@!s[] »+<« (32 X* (4,3,2,1,0)));
} }
method Numeric () { self.finalize }; method Numeric () { self.finalize };
Expand Down Expand Up @@ -429,10 +428,7 @@ role Sum::SHA2 [ :$columns where { * == (224|256|384|512) } = 256,
# First 16 uint32's are a straight copy of the data. # First 16 uint32's are a straight copy of the data.
# When endianness matches and with native types, # When endianness matches and with native types,
# this would boil down to a simple memcpy. # this would boil down to a simple memcpy.
@m = ((($block[ (4 X* 0..^16)]) X+< 24) @m = (:256[ $block[ $_ ..^ $_+4 ] ] for 0,{$^idx + 4} ...^ 64);
<<+|<< (($block[ 1 X+ (4 X* 0..^16)]) X+< 16)
<<+|<< (($block[ 2 X+ (4 X* 0..^16)]) X+< 8)
<<+|<< (($block[ 3 X+ (4 X* 0..^16)])));


# Fill the rest of the scratchpad with permutations. # Fill the rest of the scratchpad with permutations.
@m.push($rmask +& ( @m.push($rmask +& (
Expand All @@ -445,14 +441,7 @@ role Sum::SHA2 [ :$columns where { * == (224|256|384|512) } = 256,
# First 16 uint64's are a straight copy of the data. # First 16 uint64's are a straight copy of the data.
# When endianness matches and with native types, # When endianness matches and with native types,
# this would boil down to a simple memcpy. # this would boil down to a simple memcpy.
@m = ((($block[ (8 X* 0..^16)]) X+< 56) @m = (:256[ $block[ $_ ..^ $_+8 ] ] for 0,{$^idx + 8} ...^ 128);
<<+|<< (($block[ 1 X+ (8 X* 0..^16)]) X+< 48)
<<+|<< (($block[ 2 X+ (8 X* 0..^16)]) X+< 40)
<<+|<< (($block[ 3 X+ (8 X* 0..^16)]) X+< 32)
<<+|<< (($block[ 4 X+ (8 X* 0..^16)]) X+< 24)
<<+|<< (($block[ 5 X+ (8 X* 0..^16)]) X+< 16)
<<+|<< (($block[ 6 X+ (8 X* 0..^16)]) X+< 8)
<<+|<< (($block[ 7 X+ (8 X* 0..^16)])));


# Fill the rest of the scratchpad with permutations. # Fill the rest of the scratchpad with permutations.
@m.push($rmask +& ( @m.push($rmask +& (
Expand Down Expand Up @@ -494,6 +483,12 @@ role Sum::SHA2 [ :$columns where { * == (224|256|384|512) } = 256,
$columns < 257 and $!o > 0xffffffffffffffff; $columns < 257 and $!o > 0xffffffffffffffff;


given $columns { given $columns {

# These don't work yet
# when 224 { :4294967296[@!s[^7]] }
# when 256 { :4294967296[@!s[]] }
# when 384 { :18446744073709551616[@!s[^6]] }
# when 512 { :18446744073709551616[@!s[]] }
when 224 { [+|] (@!s[0..6] »+<« (32 X* (6,5,4,3,2,1,0))) } when 224 { [+|] (@!s[0..6] »+<« (32 X* (6,5,4,3,2,1,0))) }
when 256 { [+|] (@!s[] »+<« (32 X* (7,6,5,4,3,2,1,0))) } when 256 { [+|] (@!s[] »+<« (32 X* (7,6,5,4,3,2,1,0))) }
when 384 { [+|] (@!s[0..5] »+<« (64 X* (5,4,3,2,1,0))) } when 384 { [+|] (@!s[0..5] »+<« (64 X* (5,4,3,2,1,0))) }
Expand Down
10 changes: 5 additions & 5 deletions lib/Sum/SipHash.pm6
Expand Up @@ -129,11 +129,11 @@ role SipHash [ :$c = 2, :$d = 4, Int :$defkey = 0 ] does Sum {
$!k0 +|= $key +& 255; $!k0 +|= $key +& 255;
$key +>= 8; $key +>= 8;
} }
# The internal key is also a little-endian representation. # The internal key also uses a little-endian representation.
$!v0 = [+|] $keyfrob[0..^8] »+<« [56,48,40,32,24,16,8,0]; $!v0 = :256[$keyfrob[^8]];
$!v1 = [+|] $keyfrob[8..^16] »+<« [56,48,40,32,24,16,8,0]; $!v1 = :256[$keyfrob[8..^16]];
$!v2 = [+|] $keyfrob[16..^24] »+<« [56,48,40,32,24,16,8,0]; $!v2 = :256[$keyfrob[16..^24]];
$!v3 = [+|] $keyfrob[24..^32] »+<« [56,48,40,32,24,16,8,0]; $!v3 = :256[$keyfrob[24..^32]];
$!v0 +^= $!k0; $!v0 +^= $!k0;
$!v1 +^= $!k1; $!v1 +^= $!k1;
$!v2 +^= $!k0; $!v2 +^= $!k0;
Expand Down

0 comments on commit 0f4d567

Please sign in to comment.