github.com/emmansun/gmsm@v0.29.1/sm4/modes.go (about) 1 package sm4 2 3 import "crypto/cipher" 4 5 // ecbcEncAble is implemented by cipher.Blocks that can provide an optimized 6 // implementation of ECB encryption through the cipher.BlockMode interface. 7 // See crypto/ecb.go. 8 type ecbEncAble interface { 9 NewECBEncrypter() cipher.BlockMode 10 } 11 12 // ecbDecAble is implemented by cipher.Blocks that can provide an optimized 13 // implementation of ECB decryption through the cipher.BlockMode interface. 14 // See crypto/ecb.go. 15 type ecbDecAble interface { 16 NewECBDecrypter() cipher.BlockMode 17 } 18 19 // cbcEncAble is implemented by cipher.Blocks that can provide an optimized 20 // implementation of CBC encryption through the cipher.BlockMode interface. 21 // See crypto/cipher/cbc.go. 22 type cbcEncAble interface { 23 NewCBCEncrypter(iv []byte) cipher.BlockMode 24 } 25 26 // cbcDecAble is implemented by cipher.Blocks that can provide an optimized 27 // implementation of CBC decryption through the cipher.BlockMode interface. 28 // See crypto/cipher/cbc.go. 29 type cbcDecAble interface { 30 NewCBCDecrypter(iv []byte) cipher.BlockMode 31 } 32 33 // ctrAble is implemented by cipher.Blocks that can provide an optimized 34 // implementation of CTR through the cipher.Stream interface. 35 // See crypto/cipher/ctr.go. 36 type ctrAble interface { 37 NewCTR(iv []byte) cipher.Stream 38 } 39 40 // gcmAble is implemented by cipher.Blocks that can provide an optimized 41 // implementation of GCM through the AEAD interface. 42 // See crypto/cipher/gcm.go. 43 type gcmAble interface { 44 NewGCM(nonceSize, tagSize int) (cipher.AEAD, error) 45 } 46 47 // xtsEncAble is an interface implemented by ciphers that have a specific 48 // optimized implementation of XTS encryption, like sm4. 49 // NewXTSEncrypter will check for this interface and return the specific 50 // BlockMode if found. 51 type xtsEncAble interface { 52 NewXTSEncrypter(encryptedTweak *[BlockSize]byte, isGB bool) cipher.BlockMode 53 } 54 55 // xtsDecAble is an interface implemented by ciphers that have a specific 56 // optimized implementation of XTS encryption, like sm4. 57 // NewXTSDecrypter will check for this interface and return the specific 58 // BlockMode if found. 59 type xtsDecAble interface { 60 NewXTSDecrypter(encryptedTweak *[BlockSize]byte, isGB bool) cipher.BlockMode 61 }