The function crypto/cipher.xorBytes implements the XOR operations between slices of bytes, and is heavily used by encryption in CTR mode. The version in the stdlib has seen a significant amount of optimisation, but some easy optimisations are missing:
- The variable
supportUnaligned in xor_generic.go should be set for GOARCH equal to arm64.
- Said variable sohould be set for GOARCH equal to ARM and GOARM equal to 6 or 7 (but not 5).
- When
supportsUnaligned is not set, the fast version should still be called when both src and dst are multiples of wordSize (this actually happens fairly often, e.g. when encrypting a freshly allocated slice);
- When
supportsUnaligned is not set, and src and dst are equal modulo wordSize, then the initial bytes should be xored and then the fast version called on the rest of the array;
- Ideally, there should be a NEON implementation for ARMv7.
Points 1 through 3 are fairly trivial, and would bring a significant part of the benefit. This is related to #53021.
The function
crypto/cipher.xorBytesimplements the XOR operations between slices of bytes, and is heavily used by encryption in CTR mode. The version in the stdlib has seen a significant amount of optimisation, but some easy optimisations are missing:supportUnalignedin xor_generic.go should be set for GOARCH equal toarm64.supportsUnalignedis not set, the fast version should still be called when both src and dst are multiples of wordSize (this actually happens fairly often, e.g. when encrypting a freshly allocated slice);supportsUnalignedis not set, and src and dst are equal modulo wordSize, then the initial bytes should be xored and then the fast version called on the rest of the array;Points 1 through 3 are fairly trivial, and would bring a significant part of the benefit. This is related to #53021.