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: move xorBytes function to internal #28465

Open
mengzhuo opened this issue Oct 29, 2018 · 6 comments

Comments

@mengzhuo
Copy link
Contributor

commented Oct 29, 2018

Some packages need an efficient xor function bytes, for example:

gogrep -x 'for $*_ { $m[i] = $k[i] ^ $l[i] }' std cmd
src/crypto/rand/rand_unix.go:149:3: for i := 0; i < aes.BlockSize; i++ { r.dst[i] = r.time[i] ^ r.seed[i]; }
src/crypto/rand/rand_unix.go:153:3: for i := 0; i < aes.BlockSize; i++ { r.seed[i] = r.time[i] ^ r.dst[i]; }

And about 18 code pieces in golang.org/x/crypto https://github.com/golang/crypto/search?l=Go&q=xor

If this CL( https://go-review.googlesource.com/c/go/+/125316 ) get merged in master we will get a SIMD xorBytes which will be a benefit for all other package that use xor function and reduce redundancy.

@gopherbot gopherbot added this to the Proposal milestone Oct 29, 2018

@gopherbot gopherbot added the Proposal label Oct 29, 2018

@agnivade

This comment has been minimized.

Copy link
Member

commented Oct 29, 2018

Please see this #28113, which was already rejected.

@mengzhuo

This comment has been minimized.

Copy link
Contributor Author

commented Oct 29, 2018

@randall77

This comment has been minimized.

Copy link
Contributor

commented Oct 29, 2018

What did you want to use it for, exactly? math/big has an xor operation but I'd be very surprised if that function shows up in profiles of typical math/big operations.

If you want to use xor within the stdlib, we could move such a function to internal/bytealg and redirect current uses to there. That would not involve any new API.

@mengzhuo

This comment has been minimized.

Copy link
Contributor Author

commented Oct 30, 2018

Moving xor into internal sounds great, I will change title to that.
But I found that math/big using xor for []Word(uint) instead of []byte.

replace target:
math/big

func (z nat) xor(x, y nat) nat {

crypto/rand

r.dst[i] = r.time[i] ^ r.seed[i]

@mengzhuo mengzhuo changed the title proposal: crypto/cipher: export xorBytes function proposal: crypto/cipher: move xorBytes function to internal Oct 30, 2018

@agnivade

This comment has been minimized.

Copy link
Member

commented Oct 31, 2018

@andybons

This comment has been minimized.

Copy link
Member

commented Oct 31, 2018

This appears to be an internal implementation detail, not a user-facing change. @FiloSottile should still take a look, but removing the proposal tag.

@gopherbot gopherbot added the Proposal label Oct 31, 2018

@andybons andybons changed the title proposal: crypto/cipher: move xorBytes function to internal crypto/cipher: move xorBytes function to internal Oct 31, 2018

@andybons andybons removed the Proposal label Oct 31, 2018

@andybons andybons removed this from the Proposal milestone Oct 31, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.