blib/lib/Ordeal/Model/ChaCha20.pm

filter: Statementstmt 87.9% 211 / 240 Branchbran 71.8% 23 / 32 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 84.0% 21 / 25 Podpod 100% 6 / 6 totaltotal 85.3% 263 / 308 SCAR 31.0
CC
21
Cov
86%
_restore_01
12.0
int_rand
7.0
reset
6.0
CRAP 22.3
« blib/lib/Ordeal/Model.pm ↑ Summary blib/lib/Ordeal/Model/Shuffle.pm »
1 package Ordeal::Model::ChaCha20;
2  
3 # vim: ts=3 sts=3 sw=3 et ai :
4  
5 # Adapted from Math::Prime::Util::ChaCha 0.70
6 # https://metacpan.org/pod/Math::Prime::Util::ChaCha
7 # which is copyright 2017 by Dana Jacobsen E<lt>dana@acm.orgE<gt>
8  
9 5 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 { our $VERSION = '0.002'; }
13 5 ▶use Ouch;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use Mo qw< build default >;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use experimental qw< signatures postderef >;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶no warnings qw< experimental::signatures experimental::postderef >;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 5 ▶use constant BITS => (~0 == 4294967295) ? 32 : 64;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use constant CACHE_SIZE => 1000;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use constant ROUNDS => 20;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 5 ▶use constant RELEASE => 0x01; # 0x00 marks extension
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 5 has _state => ();
25 5 has _buffer => ();
26 5 has seed => ();
27  
28 ▶sub _bits_rand ($self, $n) {
Subroutine _bits_rand: called CC=2 SCAR=6.9
29 15 ▶ while (length($self->{_buffer}) < $n) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"_buffer"} < $n) 3 15 18
30 3 my $add_on = $self->_core((int($n / 8) + 64) >> 6);
31 3 $self->{_buffer} .= unpack 'b*', $add_on;
32 }
33 15 return substr $self->{_buffer}, 0, $n, '';
34 } ## end sub _bits_rand
35  
36 ▶sub BUILD ($self) {
Subroutine BUILD: called CC=3 SCAR=11.2
Pod documented
37 3 ▶ my $seed = $self->seed // do {
Condition66%2/3
$self->seed // do {
l!l&&r!l&&!r
210
MC/DC0%0/2
$self->seed // do { my $s = rand 1000000; $s < 4294967295 ? pack("V", $s) : pack("V2", $s, $s >> 32) }
$self->seed do { my $s = rand 1000000; $s < 4294967295 ? pack("V", $s) : pack("V2", $s, $s >> 32) }
Truth table66%2/3
A // B
A= $self->seedB= do { my $s = rand 1000000; $s < 4294967295 ? pack("V", $s) : pack("V2", $s, $s >> 32) }
ABresult
1X1
011
000
38 1 my $s = CORE::rand 1_000_000;
39 1 ▶ $s < 4294967295
Branch: 1 branch
BranchTrueFalseTotal
$s < 4294967295 ? : 1 0 1
40 ? pack 'V', $s
41 : pack 'V2', $s, $s >> 32;
42 };
43 3 $self->seed($seed);
44 3 $self->reset;
45 } ## end sub BUILD ($self)
46  
47 0 ▶sub clone ($self) { return ref($self)->new->restore($self->freeze) }
Subroutine clone: not called CC=1 SCAR=6.9
Pod documented
48  
49 ▶sub freeze ($self) {
Subroutine freeze: not called CC=1 SCAR=6.9
Pod documented
50 0 my $release = unpack 'H*', pack 'C*', RELEASE;
51 0 my $state = unpack 'H*', join '', pack 'N*', $self->_state->@*;
52 0 my $buffer = $self->_buffer;
53 0 my $buflen = unpack 'H*', pack 'N', length $buffer;
54 0 $buffer = unpack 'H*', join '', pack 'B*', $buffer;
55 0 my $seed = unpack 'H*', substr $self->seed, 0, 40;
56 0 return join '', $release, $state, $buflen, $buffer, $seed;
57 }
58  
59 ▶sub int_rand ($self, $low, $high) {
Subroutine int_rand: called CC=7 SCAR=19.5
Pod documented
60 13 my $N = $high - $low + 1;
61 13 state $cache = {};
62 13 my ($nbits, $reject_threshold);
63 13 ▶ if (exists $cache->{$N}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cache->{$N}) { } 8 5 13
64 8 ($nbits, $reject_threshold) = $cache->{$N}->@*;
65 }
66 else {
67 5 $nbits = int(log($N) / log(2));
68 5 my $M = 2 ** $nbits;
69 5 ▶ while ($M < $N) {
Branch: 1 branch
BranchTrueFalseTotal
if ($M < $N) 2 5 7
70 2 $nbits++;
71 2 $M *= 2;
72 }
73 5 $reject_threshold = $M - $M % $N;
74 5 ▶ if (keys($cache->%*) <= CACHE_SIZE) { # will cache, optimize it
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$cache <= 1000) 5 0 5
75 5 ▶ while (($nbits * $M / $reject_threshold) > ($nbits + 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nbits * $M / $reject_threshold > $nbits + 1) 1 5 6
76 1 $nbits++;
77 1 $M *= 2;
78 1 $reject_threshold = $M - $M % $N;
79 }
80 5 $cache->{$N} = [$nbits, $reject_threshold];
81 }
82 } ## end else [ if ($N <= CACHE_SIZE &&...)]
83 13 my $retval = $reject_threshold;
84 13 ▶ while ($retval >= $reject_threshold) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retval >= $reject_threshold) 15 13 28
85 15 my $bitsequence = $self->_bits_rand($nbits);
86 15 $retval = 0;
87 15 for my $v (reverse split //, pack 'b*', $bitsequence) {
88 13 $retval <<= 8;
89 13 $retval += ord $v;
90 }
91 } ## end while ($retval >= $reject_threshold)
92 13 return $low + $retval % $N;
93 } ## end sub int_rand
94  
95 ▶sub reset ($self) {
Subroutine reset: called CC=6 SCAR=18.0
Pod documented
96 3 my $seed = $self->seed;
97 3 ▶ $seed .= pack 'C', 0 while length($seed) % 4;
Branch: 1 branch
BranchTrueFalseTotal
length($seed) % 4 and do { $seed .= "\000" } 2 3 5
98 3 my @seed = unpack 'V*', substr $seed, 0, 40;
99 3 ▶ if (@seed < 10) {
Branch: 1 branch
BranchTrueFalseTotal
if (@seed < 10) 3 0 3
100 3 ▶ my $rng = __prng_new(map { $_ <= $#seed ? $seed[$_] : 0 } 0 .. 3);
Branch: 1 branch
BranchTrueFalseTotal
$_ <= $#seed ? : 5 7 12
101 3 ▶ push @seed, __prng_next($rng) while @seed < 10;
Branch: 1 branch
BranchTrueFalseTotal
@seed < 10 and do { push @seed, __prng_next($rng) } 25 3 28
102 }
103 3 ▶ ouch 500, 'seed count failure', @seed if @seed != 10;
Branch: 1 branch
BranchTrueFalseTotal
if @seed != 10 0 3 3
104 3 $self->_state(
105 [
106 0x61707865, 0x3320646e, 0x79622d32, 0x6b206574, # 1^ row
107 @seed[0 .. 3], # 2^ row
108 @seed[4 .. 7], # 3^ row
109 0, 0, @seed[8 .. 9], # 4^ row
110 ]
111 );
112 3 $self->_buffer('');
113 }
114  
115 ▶sub _restore_01 ($self, $opaque) {
Subroutine _restore_01: not called CC=3 SCAR=24.8
116 0 for ($opaque) {
117 0 my @state = unpack 'N*', join '', pack 'H*', substr $_, 0, 128, '';
118 0 $self->_state(\@state);
119 0 s{^-}{}mxs;
120 0 my $buflen = unpack 'N', pack 'H*', substr $_, 0, 8, '';
121 0 s{^-}{}mxs;
122 0 my $buffer = '';
123 0 ▶ if ($buflen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buflen) 0 0 0
124 0 my $sl = ($buflen + (8 - $buflen % 8) % 8) / 4; # 2 * ... / 8
125 0 $buffer = unpack 'B*', join '', pack 'H*', substr $_, 0, $sl, '';
126 0 $buffer = substr $buffer, 0, $buflen;
127 }
128 0 $self->_buffer($buffer);
129 0 s{^-}{}mxs;
130 0 $self->seed(join '', pack 'H*', $_);
131 }
132 0 return $self;
133 }
134  
135 ▶sub restore ($self, $opaque) {
Subroutine restore: not called CC=2 SCAR=17.9
Pod documented
136 0 my $release = substr $opaque, 0, 2, '';
137 0 ▶ my $method = $self->can("_restore_$release")
Branch: 1 branch
BranchTrueFalseTotal
my $method = $self->can("_restore_$release") or ouch(400, "cannot restore release", $release) 0 0 0
138 or ouch 400, 'cannot restore release', $release;
139 0 $self->$method($opaque);
140 0 return $self;
141 }
142  
143 # Simple PRNG used to fill small seeds
144 ▶sub __prng_next ($s) {
Subroutine __prng_next: called CC=1 SCAR=0.0
145 37 my $word;
146 37 my $oldstate = $s->[0];
147 37 if (BITS == 64) {
148 37 $s->[0] = ($s->[0] * 747796405 + $s->[1]) & 0xFFFFFFFF;
149 37 $word =
150 ((($oldstate >> (($oldstate >> 28) + 4)) ^ $oldstate) * 277803737)
151 & 0xFFFFFFFF;
152 } ## end if (BITS == 64)
153 else {
154 {
155 5 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
156 $s->[0] = unpack("L", pack("L", $s->[0] * 747796405 + $s->[1]));
157 }
158 $word =
159 (($oldstate >> (($oldstate >> 28) + 4)) ^ $oldstate) & 0xFFFFFFFF;
160 5 ▶ { use integer; $word = unpack("L", pack("L", $word * 277803737)); }
Subroutine BEGIN: called CC=1 SCAR=0.0
161 } ## end else [ if (BITS == 64) ]
162 37 ($word >> 22) ^ $word;
163 } ## end sub __prng_next ($s)
164  
165 ▶sub __prng_new ($A, $B, $C, $D) {
Subroutine __prng_new: called CC=1 SCAR=0.0
166 3 my @s = (0, (($B << 1) | 1) & 0xFFFFFFFF);
167 3 __prng_next(\@s);
168 3 $s[0] = ($s[0] + $A) & 0xFFFFFFFF;
169 3 __prng_next(\@s);
170 3 $s[0] = ($s[0] ^ $C) & 0xFFFFFFFF;
171 3 __prng_next(\@s);
172 3 $s[0] = ($s[0] ^ $D) & 0xFFFFFFFF;
173 3 __prng_next(\@s);
174 3 return \@s;
175 } ## end sub __prng_new
176  
177 ###############################################################################
178 # Begin ChaCha core, reference RFC 7539
179 # with change to make blockcount/nonce be 64/64 from 32/96
180 # Dana Jacobsen, 9 Apr 2017
181 # Adapted Flavio Poletti, 3 Feb 2018
182  
183 # State is:
184 # cccccccc cccccccc cccccccc cccccccc
185 # kkkkkkkk kkkkkkkk kkkkkkkk kkkkkkkk
186 # kkkkkkkk kkkkkkkk kkkkkkkk kkkkkkkk
187 # bbbbbbbb nnnnnnnn nnnnnnnn nnnnnnnn
188 #
189 # c=constant k=key b=blockcount n=nonce
190  
191 # We have to take care with 32-bit Perl so it sticks with integers.
192 # Unfortunately the pragma "use integer" means signed integer so
193 # it ruins right shifts. We also must ensure we save as unsigned.
194  
195 ▶sub _core ($self, $blocks) {
Subroutine _core: called CC=4 SCAR=13.9
196 3 my $j = $self->_state;
197 3 my $ks = '';
198  
199 3 ▶ while ($blocks-- > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($blocks-- > 0) 3 3 6
200 my (
201 3 $x0, $x1, $x2, $x3, $x4, $x5, $x6, $x7,
202 $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15
203 ) = @$j;
204 3 for (1 .. ROUNDS / 2) {
205 5 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
206 30 if (BITS == 64) {
207 30 $x0 = ($x0 + $x4) & 0xFFFFFFFF;
208 30 $x12 ^= $x0;
209 30 $x12 = (($x12 << 16) | ($x12 >> 16)) & 0xFFFFFFFF;
210 30 $x8 = ($x8 + $x12) & 0xFFFFFFFF;
211 30 $x4 ^= $x8;
212 30 $x4 = (($x4 << 12) | ($x4 >> 20)) & 0xFFFFFFFF;
213 30 $x0 = ($x0 + $x4) & 0xFFFFFFFF;
214 30 $x12 ^= $x0;
215 30 $x12 = (($x12 << 8) | ($x12 >> 24)) & 0xFFFFFFFF;
216 30 $x8 = ($x8 + $x12) & 0xFFFFFFFF;
217 30 $x4 ^= $x8;
218 30 $x4 = (($x4 << 7) | ($x4 >> 25)) & 0xFFFFFFFF;
219 30 $x1 = ($x1 + $x5) & 0xFFFFFFFF;
220 30 $x13 ^= $x1;
221 30 $x13 = (($x13 << 16) | ($x13 >> 16)) & 0xFFFFFFFF;
222 30 $x9 = ($x9 + $x13) & 0xFFFFFFFF;
223 30 $x5 ^= $x9;
224 30 $x5 = (($x5 << 12) | ($x5 >> 20)) & 0xFFFFFFFF;
225 30 $x1 = ($x1 + $x5) & 0xFFFFFFFF;
226 30 $x13 ^= $x1;
227 30 $x13 = (($x13 << 8) | ($x13 >> 24)) & 0xFFFFFFFF;
228 30 $x9 = ($x9 + $x13) & 0xFFFFFFFF;
229 30 $x5 ^= $x9;
230 30 $x5 = (($x5 << 7) | ($x5 >> 25)) & 0xFFFFFFFF;
231 30 $x2 = ($x2 + $x6) & 0xFFFFFFFF;
232 30 $x14 ^= $x2;
233 30 $x14 = (($x14 << 16) | ($x14 >> 16)) & 0xFFFFFFFF;
234 30 $x10 = ($x10 + $x14) & 0xFFFFFFFF;
235 30 $x6 ^= $x10;
236 30 $x6 = (($x6 << 12) | ($x6 >> 20)) & 0xFFFFFFFF;
237 30 $x2 = ($x2 + $x6) & 0xFFFFFFFF;
238 30 $x14 ^= $x2;
239 30 $x14 = (($x14 << 8) | ($x14 >> 24)) & 0xFFFFFFFF;
240 30 $x10 = ($x10 + $x14) & 0xFFFFFFFF;
241 30 $x6 ^= $x10;
242 30 $x6 = (($x6 << 7) | ($x6 >> 25)) & 0xFFFFFFFF;
243 30 $x3 = ($x3 + $x7) & 0xFFFFFFFF;
244 30 $x15 ^= $x3;
245 30 $x15 = (($x15 << 16) | ($x15 >> 16)) & 0xFFFFFFFF;
246 30 $x11 = ($x11 + $x15) & 0xFFFFFFFF;
247 30 $x7 ^= $x11;
248 30 $x7 = (($x7 << 12) | ($x7 >> 20)) & 0xFFFFFFFF;
249 30 $x3 = ($x3 + $x7) & 0xFFFFFFFF;
250 30 $x15 ^= $x3;
251 30 $x15 = (($x15 << 8) | ($x15 >> 24)) & 0xFFFFFFFF;
252 30 $x11 = ($x11 + $x15) & 0xFFFFFFFF;
253 30 $x7 ^= $x11;
254 30 $x7 = (($x7 << 7) | ($x7 >> 25)) & 0xFFFFFFFF;
255 30 $x0 = ($x0 + $x5) & 0xFFFFFFFF;
256 30 $x15 ^= $x0;
257 30 $x15 = (($x15 << 16) | ($x15 >> 16)) & 0xFFFFFFFF;
258 30 $x10 = ($x10 + $x15) & 0xFFFFFFFF;
259 30 $x5 ^= $x10;
260 30 $x5 = (($x5 << 12) | ($x5 >> 20)) & 0xFFFFFFFF;
261 30 $x0 = ($x0 + $x5) & 0xFFFFFFFF;
262 30 $x15 ^= $x0;
263 30 $x15 = (($x15 << 8) | ($x15 >> 24)) & 0xFFFFFFFF;
264 30 $x10 = ($x10 + $x15) & 0xFFFFFFFF;
265 30 $x5 ^= $x10;
266 30 $x5 = (($x5 << 7) | ($x5 >> 25)) & 0xFFFFFFFF;
267 30 $x1 = ($x1 + $x6) & 0xFFFFFFFF;
268 30 $x12 ^= $x1;
269 30 $x12 = (($x12 << 16) | ($x12 >> 16)) & 0xFFFFFFFF;
270 30 $x11 = ($x11 + $x12) & 0xFFFFFFFF;
271 30 $x6 ^= $x11;
272 30 $x6 = (($x6 << 12) | ($x6 >> 20)) & 0xFFFFFFFF;
273 30 $x1 = ($x1 + $x6) & 0xFFFFFFFF;
274 30 $x12 ^= $x1;
275 30 $x12 = (($x12 << 8) | ($x12 >> 24)) & 0xFFFFFFFF;
276 30 $x11 = ($x11 + $x12) & 0xFFFFFFFF;
277 30 $x6 ^= $x11;
278 30 $x6 = (($x6 << 7) | ($x6 >> 25)) & 0xFFFFFFFF;
279 30 $x2 = ($x2 + $x7) & 0xFFFFFFFF;
280 30 $x13 ^= $x2;
281 30 $x13 = (($x13 << 16) | ($x13 >> 16)) & 0xFFFFFFFF;
282 30 $x8 = ($x8 + $x13) & 0xFFFFFFFF;
283 30 $x7 ^= $x8;
284 30 $x7 = (($x7 << 12) | ($x7 >> 20)) & 0xFFFFFFFF;
285 30 $x2 = ($x2 + $x7) & 0xFFFFFFFF;
286 30 $x13 ^= $x2;
287 30 $x13 = (($x13 << 8) | ($x13 >> 24)) & 0xFFFFFFFF;
288 30 $x8 = ($x8 + $x13) & 0xFFFFFFFF;
289 30 $x7 ^= $x8;
290 30 $x7 = (($x7 << 7) | ($x7 >> 25)) & 0xFFFFFFFF;
291 30 $x3 = ($x3 + $x4) & 0xFFFFFFFF;
292 30 $x14 ^= $x3;
293 30 $x14 = (($x14 << 16) | ($x14 >> 16)) & 0xFFFFFFFF;
294 30 $x9 = ($x9 + $x14) & 0xFFFFFFFF;
295 30 $x4 ^= $x9;
296 30 $x4 = (($x4 << 12) | ($x4 >> 20)) & 0xFFFFFFFF;
297 30 $x3 = ($x3 + $x4) & 0xFFFFFFFF;
298 30 $x14 ^= $x3;
299 30 $x14 = (($x14 << 8) | ($x14 >> 24)) & 0xFFFFFFFF;
300 30 $x9 = ($x9 + $x14) & 0xFFFFFFFF;
301 30 $x4 ^= $x9;
302 30 $x4 = (($x4 << 7) | ($x4 >> 25)) & 0xFFFFFFFF;
303 } ## end if (BITS == 64)
304 else { # 32-bit
305 $x0 += $x4;
306 $x12 ^= $x0;
307 $x12 = ($x12 << 16) | (($x12 >> 16) & 0xFFFF);
308 $x8 += $x12;
309 $x4 ^= $x8;
310 $x4 = ($x4 << 12) | (($x4 >> 20) & 0xFFF);
311 $x0 += $x4;
312 $x12 ^= $x0;
313 $x12 = ($x12 << 8) | (($x12 >> 24) & 0xFF);
314 $x8 += $x12;
315 $x4 ^= $x8;
316 $x4 = ($x4 << 7) | (($x4 >> 25) & 0x7F);
317 $x1 += $x5;
318 $x13 ^= $x1;
319 $x13 = ($x13 << 16) | (($x13 >> 16) & 0xFFFF);
320 $x9 += $x13;
321 $x5 ^= $x9;
322 $x5 = ($x5 << 12) | (($x5 >> 20) & 0xFFF);
323 $x1 += $x5;
324 $x13 ^= $x1;
325 $x13 = ($x13 << 8) | (($x13 >> 24) & 0xFF);
326 $x9 += $x13;
327 $x5 ^= $x9;
328 $x5 = ($x5 << 7) | (($x5 >> 25) & 0x7F);
329 $x2 += $x6;
330 $x14 ^= $x2;
331 $x14 = ($x14 << 16) | (($x14 >> 16) & 0xFFFF);
332 $x10 += $x14;
333 $x6 ^= $x10;
334 $x6 = ($x6 << 12) | (($x6 >> 20) & 0xFFF);
335 $x2 += $x6;
336 $x14 ^= $x2;
337 $x14 = ($x14 << 8) | (($x14 >> 24) & 0xFF);
338 $x10 += $x14;
339 $x6 ^= $x10;
340 $x6 = ($x6 << 7) | (($x6 >> 25) & 0x7F);
341 $x3 += $x7;
342 $x15 ^= $x3;
343 $x15 = ($x15 << 16) | (($x15 >> 16) & 0xFFFF);
344 $x11 += $x15;
345 $x7 ^= $x11;
346 $x7 = ($x7 << 12) | (($x7 >> 20) & 0xFFF);
347 $x3 += $x7;
348 $x15 ^= $x3;
349 $x15 = ($x15 << 8) | (($x15 >> 24) & 0xFF);
350 $x11 += $x15;
351 $x7 ^= $x11;
352 $x7 = ($x7 << 7) | (($x7 >> 25) & 0x7F);
353 $x0 += $x5;
354 $x15 ^= $x0;
355 $x15 = ($x15 << 16) | (($x15 >> 16) & 0xFFFF);
356 $x10 += $x15;
357 $x5 ^= $x10;
358 $x5 = ($x5 << 12) | (($x5 >> 20) & 0xFFF);
359 $x0 += $x5;
360 $x15 ^= $x0;
361 $x15 = ($x15 << 8) | (($x15 >> 24) & 0xFF);
362 $x10 += $x15;
363 $x5 ^= $x10;
364 $x5 = ($x5 << 7) | (($x5 >> 25) & 0x7F);
365 $x1 += $x6;
366 $x12 ^= $x1;
367 $x12 = ($x12 << 16) | (($x12 >> 16) & 0xFFFF);
368 $x11 += $x12;
369 $x6 ^= $x11;
370 $x6 = ($x6 << 12) | (($x6 >> 20) & 0xFFF);
371 $x1 += $x6;
372 $x12 ^= $x1;
373 $x12 = ($x12 << 8) | (($x12 >> 24) & 0xFF);
374 $x11 += $x12;
375 $x6 ^= $x11;
376 $x6 = ($x6 << 7) | (($x6 >> 25) & 0x7F);
377 $x2 += $x7;
378 $x13 ^= $x2;
379 $x13 = ($x13 << 16) | (($x13 >> 16) & 0xFFFF);
380 $x8 += $x13;
381 $x7 ^= $x8;
382 $x7 = ($x7 << 12) | (($x7 >> 20) & 0xFFF);
383 $x2 += $x7;
384 $x13 ^= $x2;
385 $x13 = ($x13 << 8) | (($x13 >> 24) & 0xFF);
386 $x8 += $x13;
387 $x7 ^= $x8;
388 $x7 = ($x7 << 7) | (($x7 >> 25) & 0x7F);
389 $x3 += $x4;
390 $x14 ^= $x3;
391 $x14 = ($x14 << 16) | (($x14 >> 16) & 0xFFFF);
392 $x9 += $x14;
393 $x4 ^= $x9;
394 $x4 = ($x4 << 12) | (($x4 >> 20) & 0xFFF);
395 $x3 += $x4;
396 $x14 ^= $x3;
397 $x14 = ($x14 << 8) | (($x14 >> 24) & 0xFF);
398 $x9 += $x14;
399 $x4 ^= $x9;
400 $x4 = ($x4 << 7) | (($x4 >> 25) & 0x7F);
401 } ## end else [ if (BITS == 64) ]
402 } ## end for (1 .. ROUNDS / 2)
403 3 $ks .= pack("V16",
404 $x0 + $j->[0],
405 $x1 + $j->[1],
406 $x2 + $j->[2],
407 $x3 + $j->[3],
408 $x4 + $j->[4],
409 $x5 + $j->[5],
410 $x6 + $j->[6],
411 $x7 + $j->[7],
412 $x8 + $j->[8],
413 $x9 + $j->[9],
414 $x10 + $j->[10],
415 $x11 + $j->[11],
416 $x12 + $j->[12],
417 $x13 + $j->[13],
418 $x14 + $j->[14],
419 $x15 + $j->[15]);
420 3 ▶ if (++$j->[12] > 4294967295) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$j->[12] > 4294967295) 0 3 3
421 0 $j->[12] = 0;
422 0 $j->[13]++;
423 }
424 } ## end while ($blocks-- > 0)
425 3 return $ks;
426 } ## end sub _core
427  
428 # End ChaCha core
429 ###############################################################################
430  
431 5 1;
432 __END__
« blib/lib/Ordeal/Model.pm ↑ Summary blib/lib/Ordeal/Model/Shuffle.pm »