-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crypto.cipher: make Stream.xor_key_stream implementers require a mutable receiver #21974
Conversation
Please review tests in particular. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like errors are thrown in des_ofb_test.v
, these should be fixed before merge
Should be ready now |
They way you did it is fine. Another approach is having a function, that would not be called, but only checked: fn implements(x cipher.Ctr) cipher.Stream { return x } ... which relies that the compiler will then ensure, that |
pub fn (mut x Cfb) xor_key_stream(mut dst_ []u8, src_ []u8) { | ||
pub fn (mut x Cfb) xor_key_stream(mut dst []u8, src []u8) { | ||
unsafe { | ||
mut dst := *dst_ | ||
mut src := src_ | ||
if dst.len < src.len { | ||
mut local_dst := *dst | ||
mut local_src := src | ||
if local_dst.len < local_src.len { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are good changes, just a bit unrelated to the topic of the PR.
pub fn (mut c Cipher) xor_key_stream(mut dst []u8, mut src []u8) { | ||
pub fn (mut c Cipher) xor_key_stream(mut dst []u8, src []u8) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good find.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work.
Addresses #21973
This may impact stream ciphers that implement xor_key_stream with immutable implementers, and may therefore be breaking.
Further checks should be made so that all stream ciphers implement xor_key_stream correctly, tests are missing for this scenario in all stream cipher implementations.
I am not sure how to perform such tests, help is needed to add such tests.