github.com/emmansun/gmsm@v0.29.1/pkcs/cipher_sm4.go (about) 1 package pkcs 2 3 import ( 4 "encoding/asn1" 5 6 "github.com/emmansun/gmsm/sm4" 7 ) 8 9 var ( 10 oidSM4CBC = asn1.ObjectIdentifier{1, 2, 156, 10197, 1, 104, 2} 11 oidSM4GCM = asn1.ObjectIdentifier{1, 2, 156, 10197, 1, 104, 8} 12 oidSM4ECB = asn1.ObjectIdentifier{1, 2, 156, 10197, 1, 104, 1} 13 oidSM4 = asn1.ObjectIdentifier{1, 2, 156, 10197, 1, 104} 14 ) 15 16 func init() { 17 RegisterCipher(oidSM4CBC, func() Cipher { 18 return SM4CBC 19 }) 20 RegisterCipher(oidSM4GCM, func() Cipher { 21 return SM4GCM 22 }) 23 RegisterCipher(oidSM4ECB, func() Cipher { 24 return SM4ECB 25 }) 26 } 27 28 // SM4ECB is the 128-bit key SM4 cipher in ECB mode. 29 var SM4ECB = &ecbBlockCipher{ 30 baseBlockCipher: baseBlockCipher{ 31 keySize: 16, 32 newBlock: sm4.NewCipher, 33 oid: oidSM4ECB, 34 }, 35 } 36 37 // SM4CBC is the 128-bit key SM4 cipher in CBC mode. 38 var SM4CBC = &cbcBlockCipher{ 39 baseBlockCipher: baseBlockCipher{ 40 keySize: 16, 41 newBlock: sm4.NewCipher, 42 oid: oidSM4CBC, 43 }, 44 ivSize: sm4.BlockSize, 45 } 46 47 // SM4GCM is the 128-bit key SM4 cipher in GCM mode. 48 var SM4GCM = &gcmBlockCipher{ 49 baseBlockCipher: baseBlockCipher{ 50 keySize: 16, 51 newBlock: sm4.NewCipher, 52 oid: oidSM4GCM, 53 }, 54 nonceSize: 12, 55 } 56 57 // SM4 is the 128-bit key SM4 cipher in CBC mode, it's just for CFCA. 58 var SM4 = &cbcBlockCipher{ 59 baseBlockCipher: baseBlockCipher{ 60 keySize: 16, 61 newBlock: sm4.NewCipher, 62 oid: oidSM4, 63 }, 64 ivSize: sm4.BlockSize, 65 }