]> Cypherpunks.ru repositories - gogost.git/blobdiff - gost3412128/xor_words.go
Optimized Kuznechik
[gogost.git] / gost3412128 / xor_words.go
diff --git a/gost3412128/xor_words.go b/gost3412128/xor_words.go
new file mode 100644 (file)
index 0000000..36582c3
--- /dev/null
@@ -0,0 +1,21 @@
+//go:build amd64 || 386 || ppc64 || ppc64le || s390x
+// +build amd64 386 ppc64 ppc64le s390x
+
+// Fast XOR taken from native crypto/cipher
+
+package gost3412128
+
+import (
+       "unsafe"
+)
+
+const xorWords = BlockSize / int(unsafe.Sizeof(uintptr(0)))
+
+func xor(dst, a, b []byte) {
+       dw := *(*[]uintptr)(unsafe.Pointer(&dst))
+       aw := *(*[]uintptr)(unsafe.Pointer(&a))
+       bw := *(*[]uintptr)(unsafe.Pointer(&b))
+       for i := 0; i < xorWords; i++ {
+               dw[i] = aw[i] ^ bw[i]
+       }
+}