x.crypto.chacha20: fix internal counter handling#25334
Conversation
|
Connected to Huly®: V_0.6-25830 |
|
@blackshirt I easily found a code combination where tests can still fail. |
i have no panic with this patch. can you give a try ? import rand
import x.crypto.chacha20
fn main() {
mut ctx := chacha20.new_cipher(rand.bytes(32)!, rand.bytes(8)!)!
for i in 0 .. 50 {
ctx.set_counter(rand.u64())
mut dst := []u8{len: rand.intn(6)!}
ctx.encrypt(mut dst, dst)
println(dst)
}
}output: [112, 89, 106, 10, 103]
[71, 80, 51, 149]
[35, 215, 91, 204, 15]
[168]
[149, 88, 106, 152, 84]
[119]
[84]
[]
[206, 177, 61]
[57, 150, 90]
[151, 236]
[198, 128, 29, 36, 24]
[]
[]
[10, 98]
[21]
[217, 193]
[31, 28, 132, 238]
[202]
[]
[215, 140]
[57, 112, 151, 29]
[240, 91, 11, 134, 248]
[184, 139, 38, 145]
[124]
[]
[160, 212, 144]
[144, 22, 237]
[28, 243]
[108, 90]
[207, 164, 21, 88]
[145, 81, 45, 127, 75]
[]
[30]
[]
[32]
[]
[225, 54]
[95]
[25, 26]
[188, 7]
[61, 233]
[104, 253, 63, 132, 48]
[]
[73, 31]
[]
[182, 179, 19, 181, 206]
[]
[98]
[73, 255, 239] |
|
@blackshirt if I uncomment line |
Its should not, in current |
i fix it in later patch |
|
@blackshirt |
i'm try to adjust it |
|
Here's my question-comment I mentioned earlier: I noticed that if I use this pseudocode, everything works fine: but if I use that code, it produces an incorrect result, and my tests against This is some kind of super trap for the user that should at least be mentioned in the documentation or fixed. |
its another culprits that should be cleans up, i think we should push this |
spytheman
left a comment
There was a problem hiding this comment.
Thank you @blackshirt and @tankf33der .
|
@spytheman thank you ..i would dig into 64-bit counter issues when i have a free time on it . I think the short current goal to improve this cipher was already reached, minimally on the Benchmark part |
This small patch fix internal counter handling after rewrites the internal of
x.crypto.chacha20. The counter increments phase not be adjusted to align with the changes and leads to the bug in 25318.In my test for
firebirdby @einar-hjortdal, it pass successfully,Besides of counter adjusment, this pr also contains some bits of clean up. It also maintain relatives stable performance with previous one, see the benchmark at here
cc @einar-hjortdal please give this pr a try, i hope this fix the bug