mirror of
https://github.com/emmansun/gmsm.git
synced 2025-05-12 12:06:18 +08:00
cipher: refactor xts mode #149
This commit is contained in:
parent
9d6e46cafd
commit
0eaad02df4
@ -385,7 +385,7 @@ func benchmarkSM4CCMOpen(b *testing.B, buf []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func benchmarkXTS(b *testing.B, cipherFunc func([]byte) (cipher.Block, error), length, keylen int64) {
|
func benchmarkXTS(b *testing.B, cipherFunc func([]byte) (cipher.Block, error), length, keylen int64) {
|
||||||
c, err := smcipher.NewXTS(cipherFunc, make([]byte, keylen))
|
c, err := smcipher.NewXTSEncrypterWithSector(cipherFunc, make([]byte, keylen), make([]byte, keylen), 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatalf("NewCipher failed: %s", err)
|
b.Fatalf("NewCipher failed: %s", err)
|
||||||
}
|
}
|
||||||
@ -395,43 +395,43 @@ func benchmarkXTS(b *testing.B, cipherFunc func([]byte) (cipher.Block, error), l
|
|||||||
b.SetBytes(int64(len(plaintext)))
|
b.SetBytes(int64(len(plaintext)))
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
c.EncryptSector(encrypted, plaintext, 0)
|
c.CryptBlocks(encrypted, plaintext)
|
||||||
//c.Decrypt(decrypted, encrypted[:len(plaintext)], 0)
|
//c.Decrypt(decrypted, encrypted[:len(plaintext)], 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkAES128XTSEncrypt512(b *testing.B) {
|
func BenchmarkAES128XTSEncrypt512(b *testing.B) {
|
||||||
benchmarkXTS(b, aes.NewCipher, 512, 32)
|
benchmarkXTS(b, aes.NewCipher, 512, 16)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkAES128XTSEncrypt1K(b *testing.B) {
|
func BenchmarkAES128XTSEncrypt1K(b *testing.B) {
|
||||||
benchmarkXTS(b, aes.NewCipher, 1024, 32)
|
benchmarkXTS(b, aes.NewCipher, 1024, 16)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkAES128XTSEncrypt4K(b *testing.B) {
|
func BenchmarkAES128XTSEncrypt4K(b *testing.B) {
|
||||||
benchmarkXTS(b, aes.NewCipher, 4096, 32)
|
benchmarkXTS(b, aes.NewCipher, 4096, 16)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkAES256XTSEncrypt512(b *testing.B) {
|
func BenchmarkAES256XTSEncrypt512(b *testing.B) {
|
||||||
benchmarkXTS(b, aes.NewCipher, 512, 64)
|
benchmarkXTS(b, aes.NewCipher, 512, 32)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkAES256XTSEncrypt1K(b *testing.B) {
|
func BenchmarkAES256XTSEncrypt1K(b *testing.B) {
|
||||||
benchmarkXTS(b, aes.NewCipher, 1024, 64)
|
benchmarkXTS(b, aes.NewCipher, 1024, 32)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkAES256XTSEncrypt4K(b *testing.B) {
|
func BenchmarkAES256XTSEncrypt4K(b *testing.B) {
|
||||||
benchmarkXTS(b, aes.NewCipher, 4096, 64)
|
benchmarkXTS(b, aes.NewCipher, 4096, 32)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkSM4XTSEncrypt512(b *testing.B) {
|
func BenchmarkSM4XTSEncrypt512(b *testing.B) {
|
||||||
benchmarkXTS(b, sm4.NewCipher, 512, 32)
|
benchmarkXTS(b, sm4.NewCipher, 512, 16)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkSM4XTSEncrypt1K(b *testing.B) {
|
func BenchmarkSM4XTSEncrypt1K(b *testing.B) {
|
||||||
benchmarkXTS(b, sm4.NewCipher, 1024, 32)
|
benchmarkXTS(b, sm4.NewCipher, 1024, 16)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkSM4XTSEncrypt4K(b *testing.B) {
|
func BenchmarkSM4XTSEncrypt4K(b *testing.B) {
|
||||||
benchmarkXTS(b, sm4.NewCipher, 4096, 32)
|
benchmarkXTS(b, sm4.NewCipher, 4096, 16)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user