Skip to content
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

Merged
merged 6 commits into from
Aug 1, 2024

Conversation

einar-hjortdal
Copy link
Contributor

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.

@einar-hjortdal einar-hjortdal reopened this Aug 1, 2024
@einar-hjortdal einar-hjortdal marked this pull request as ready for review August 1, 2024 08:29
@einar-hjortdal
Copy link
Contributor Author

Please review tests in particular.

Copy link
Contributor Author

@einar-hjortdal einar-hjortdal left a 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

@einar-hjortdal
Copy link
Contributor Author

Should be ready now

@spytheman spytheman changed the title cypto.cipher: make xor_key_stream implementers mutable. crypto.cipher: make xor_key_stream implementers mutable. Aug 1, 2024
@spytheman spytheman changed the title crypto.cipher: make xor_key_stream implementers mutable. crypto.cipher: make Stream.xor_key_stream implementers mutable Aug 1, 2024
@spytheman spytheman changed the title crypto.cipher: make Stream.xor_key_stream implementers mutable crypto.cipher: make Stream.xor_key_stream implementers require a mutable receiver Aug 1, 2024
@spytheman
Copy link
Member

spytheman commented Aug 1, 2024

I am not sure how to perform such tests, help is needed to add such tests.

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 cipher.Ctr can be converted to a cipher.Stream interface value.

Comment on lines -66 to +70
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 {
Copy link
Member

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find.

Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@spytheman spytheman merged commit a4b8768 into vlang:master Aug 1, 2024
61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants