sym enc

func main() {
n := 0x5fffff
key := make([]byte, 32)
nonce := make([]byte, 12)
copy(key, []byte("ok, this is key..."))
copy(nonce, []byte("ok, this is nonce"))

plaintext := []byte("ok, ewasflkjewaojhewofhaowigqherdveuiwprqufuepriauwafeshfjkaewhfhjsadjfhasukfjasjfsaahashjkfewiuhfiuwfiuahfhuawhufhuawufhiawuhfiuwafghigiuihuhuiu9yr8p98yqp3894y3-aqrst3qfdegr423qe43")
ciphertext := make([]byte, len(plaintext))
b, err := chacha20.NewCipher(key, nonce)
if err != nil{
panic(err)
}
s := chacha20.NewChaCha20(b)
t1 := time.Now()
for i:=0; i<=n; i++{
s.XORKeyStream(ciphertext, plaintext)
}
t1e := time.Now()

ciphertext1 := make([]byte, len(plaintext))
s1,_ := salsa.NewUnauthenticatedCipher(key, nonce)
t2 := time.Now()
for i:=0; i<=n; i++{
s1.XORKeyStream(ciphertext1, plaintext)
}
t2e := time.Now()

akey := make([]byte, 16)
aiv := make([]byte, 16)
copy(akey, []byte("ok, this is key..."))
copy(aiv, []byte("ok, this is nonce"))
ab, err := aes.NewCipher(akey)
if (err != nil){
panic(err)
}
as := cipher.NewCTR(ab, aiv)
t3 := time.Now()
for i:=0; i<=n; i++{
as.XORKeyStream(ciphertext, plaintext)
}
t3e := time.Now()

sb, err := sm4.NewCipher(akey)
if (err != nil){
panic(err)
}
ss := cipher.NewCTR(sb, aiv)
t4 := time.Now()
for i:=0; i<=n; i++{
ss.XORKeyStream(ciphertext, plaintext)
}
t4e := time.Now()

fmt.Println(t1e.Sub(t1))
fmt.Println(t2e.Sub(t2))
fmt.Println(t3e.Sub(t3))
fmt.Println(t4e.Sub(t4))
cnt := float64(n * len(plaintext));
cnt /= 1024 * 1024;
fmt.Println(cnt)
fmt.Println("end")
}





3.548263042s
2.368485207s
1.549265953s
11.349872991s
1085.9998273849487



posted @ 2020-12-02 20:03  zJanly  阅读(190)  评论(0)    收藏  举报