@@ -9,7 +9,7 @@ import encoding.binary
99
1010// max_64bit_counter is a 64-bit maximum internal counter of original ChaCha20 variant.
1111const max_64bit_counter = max_u64
12- // max_64bit_counter is a 32-bit maximum internal counter of standard IETF ChaCha20 variant.
12+ // max_32bit_counter is a 32-bit maximum internal counter of standard IETF ChaCha20 variant.
1313const max_32bit_counter = u64 (max_u32 )
1414
1515// default chacha20 quarter round number
@@ -107,11 +107,16 @@ fn new_stream(key []u8, nonce []u8) !Stream {
107107// reset resets internal stream
108108@[unsafe ]
109109fn (mut s Stream) reset () {
110+ s.mode = .standard
110111 s.extended = false
111112 unsafe {
112113 _ := vmemset (& s.key, 0 , 32 )
113114 _ := vmemset (& s.nonce, 0 , 16 )
114115 }
116+ s.precomp = false
117+ s.p1 , s.p5 , s.p9 , s.p13 = u32 (0 ), u32 (0 ), u32 (0 ), u32 (0 )
118+ s.p2 , s.p6 , s.p10 , s.p14 = u32 (0 ), u32 (0 ), u32 (0 ), u32 (0 )
119+ s.p3 , s.p7 , s.p11 , s.p15 = u32 (0 ), u32 (0 ), u32 (0 ), u32 (0 )
115120}
116121
117122// new_curr_state creates a new State from current stream
@@ -372,6 +377,8 @@ fn clone_state(s State) State {
372377 return sc
373378}
374379
380+ // qround_on_state_with_quartet run qround_on_state by previously set up state values in offset
381+ // (a,b,c,d) with values from quartet (q0, q1, q2, q3)
375382@[direct_array_access]
376383fn qround_on_state_with_quartet (mut s State, q0 u32 , q1 u32 , q2 u32 , q3 u32 , a int , b int , c int , d int ) {
377384 s[a] = q0
414421 e3 u32
415422}
416423
417- // chacha20 quarter round run on Quartet and stored into res
424+ // qround_on_quartet runs chacha20 quarter round run on Quartet q.
418425fn qround_on_quartet (mut q Quartet) {
419426 // a += b; d ^= a; d <<<= 16;
420427 q.e0 + = q.e1
0 commit comments