]> Cypherpunks.ru repositories - gogost.git/blobdiff - mgm/mul64_test.go
Separate GF^64 and GF^128 multiplier implementations
[gogost.git] / mgm / mul64_test.go
similarity index 58%
rename from mgm/mul.go
rename to mgm/mul64_test.go
index 8fec46619ded35d6e7fb430492254366a22c2060..43411cd948dd18c3ae6ad4f5a4fc344da555a2b5 100644 (file)
 
 package mgm
 
-func (mgm *MGM) mul(xBuf, yBuf []byte) []byte {
-       mgm.x.SetBytes(xBuf)
-       mgm.y.SetBytes(yBuf)
-       mgm.z.SetInt64(0)
-       for mgm.y.BitLen() != 0 {
-               if mgm.y.Bit(0) == 1 {
-                       mgm.z.Xor(mgm.z, mgm.x)
-               }
-               if mgm.x.Bit(mgm.maxBit) == 1 {
-                       mgm.x.SetBit(mgm.x, mgm.maxBit, 0)
-                       mgm.x.Lsh(mgm.x, 1)
-                       mgm.x.Xor(mgm.x, mgm.r)
-               } else {
-                       mgm.x.Lsh(mgm.x, 1)
-               }
-               mgm.y.Rsh(mgm.y, 1)
-       }
-       zBytes := mgm.z.Bytes()
-       rem := len(xBuf) - len(zBytes)
-       for i := 0; i < rem; i++ {
-               mgm.mulBuf[i] = 0
+import (
+       "crypto/rand"
+       "testing"
+
+       "go.cypherpunks.ru/gogost/v5/gost341264"
+)
+
+func BenchmarkMul64(b *testing.B) {
+       x := make([]byte, gost341264.BlockSize)
+       y := make([]byte, gost341264.BlockSize)
+       rand.Read(x)
+       rand.Read(y)
+       mul := newMul64()
+       b.ResetTimer()
+       for i := 0; i < b.N; i++ {
+               mul.Mul(x, y)
        }
-       copy(mgm.mulBuf[rem:], zBytes)
-       return mgm.mulBuf
 }