github.com/emmansun/gmsm@v0.29.1/pkcs/cipher_aes.go (about)

     1  package pkcs
     2  
     3  import (
     4  	"crypto/aes"
     5  	"encoding/asn1"
     6  )
     7  
     8  var (
     9  	oidAES128CBC = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 4, 1, 2}
    10  	oidAES128GCM = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 4, 1, 6}
    11  	oidAES192CBC = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 4, 1, 22}
    12  	oidAES192GCM = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 4, 1, 26}
    13  	oidAES256CBC = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 4, 1, 42}
    14  	oidAES256GCM = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 4, 1, 46}
    15  )
    16  
    17  func init() {
    18  	RegisterCipher(oidAES128CBC, func() Cipher {
    19  		return AES128CBC
    20  	})
    21  	RegisterCipher(oidAES128GCM, func() Cipher {
    22  		return AES128GCM
    23  	})
    24  	RegisterCipher(oidAES192CBC, func() Cipher {
    25  		return AES192CBC
    26  	})
    27  	RegisterCipher(oidAES192GCM, func() Cipher {
    28  		return AES192GCM
    29  	})
    30  	RegisterCipher(oidAES256CBC, func() Cipher {
    31  		return AES256CBC
    32  	})
    33  	RegisterCipher(oidAES256GCM, func() Cipher {
    34  		return AES256GCM
    35  	})
    36  }
    37  
    38  // AES128CBC is the 128-bit key AES cipher in CBC mode.
    39  var AES128CBC = &cbcBlockCipher{
    40  	baseBlockCipher: baseBlockCipher{
    41  		keySize:  16,
    42  		newBlock: aes.NewCipher,
    43  		oid:      oidAES128CBC,
    44  	},
    45  	ivSize: aes.BlockSize,
    46  }
    47  
    48  // AES128GCM is the 128-bit key AES cipher in GCM mode.
    49  var AES128GCM = &gcmBlockCipher{
    50  	baseBlockCipher: baseBlockCipher{
    51  		keySize:  16,
    52  		newBlock: aes.NewCipher,
    53  		oid:      oidAES128GCM,
    54  	},
    55  	nonceSize: 12,
    56  }
    57  
    58  // AES192CBC is the 192-bit key AES cipher in CBC mode.
    59  var AES192CBC = &cbcBlockCipher{
    60  	baseBlockCipher: baseBlockCipher{
    61  		keySize:  24,
    62  		newBlock: aes.NewCipher,
    63  		oid:      oidAES192CBC,
    64  	},
    65  	ivSize:   aes.BlockSize,
    66  }
    67  
    68  // AES192GCM is the 912-bit key AES cipher in GCM mode.
    69  var AES192GCM = &gcmBlockCipher{
    70  	baseBlockCipher: baseBlockCipher{
    71  		keySize:  24,
    72  		newBlock: aes.NewCipher,
    73  		oid:      oidAES192GCM,
    74  	},
    75  	nonceSize: 12,
    76  }
    77  
    78  // AES256CBC is the 256-bit key AES cipher in CBC mode.
    79  var AES256CBC = &cbcBlockCipher{
    80  	baseBlockCipher: baseBlockCipher{
    81  		keySize:  32,
    82  		newBlock: aes.NewCipher,
    83  		oid:      oidAES256CBC,
    84  	},
    85  	ivSize:   aes.BlockSize,
    86  }
    87  
    88  // AES256GCM is the 256-bit key AES cipher in GCM mode.
    89  var AES256GCM = &gcmBlockCipher{
    90  	baseBlockCipher: baseBlockCipher{
    91  		keySize:  32,
    92  		newBlock: aes.NewCipher,
    93  		oid:      oidAES256GCM,
    94  	},
    95  	nonceSize: 12,
    96  }