Go: x/crypto/chacha20: add Cipher.SetCounter

Created on 11 Nov 2019  路  3Comments  路  Source: golang/go

As mentioned in #24485, it would be useful to be able to jump forward in the cipher stream, for example for QUIC. We should add a SetCounter method to the new x/crypto/chacha20 package.

NeedsFix

Most helpful comment

(In the CL above the SetCounter method is renamed to Advance.)

I think if I saw s.Advance(1) in code I don't think it would be immediately obvious to me whether the method call is trying to skip 1 byte of the keystream, increment the counter by 1, or set the value of the counter to 1.

I therefore wonder if we should call this something less ambiguous. AdvanceCounterTo perhaps?

All 3 comments

(In the CL above the SetCounter method is renamed to Advance.)

I think if I saw s.Advance(1) in code I don't think it would be immediately obvious to me whether the method call is trying to skip 1 byte of the keystream, increment the counter by 1, or set the value of the counter to 1.

I therefore wonder if we should call this something less ambiguous. AdvanceCounterTo perhaps?

Yeah, fair, naming things is hard. Let's just go back to SetCounter. The docs can explain the rollback behavior.

Change https://golang.org/cl/206638 mentions this issue: chacha20: add SetCounter method

Was this page helpful?
0 / 5 - 0 ratings

Related issues

OneOfOne picture OneOfOne  路  3Comments

Miserlou picture Miserlou  路  3Comments

natefinch picture natefinch  路  3Comments

lkarlslund picture lkarlslund  路  3Comments

enoodle picture enoodle  路  3Comments