mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-21 17:56:19 +08:00
pkcs8: rename internal struct
This commit is contained in:
parent
617d2591d6
commit
f57e6a4a1d
@ -16,22 +16,22 @@ func genRandom(len int) ([]byte, error) {
|
||||
return value, err
|
||||
}
|
||||
|
||||
type cipherWithBlock struct {
|
||||
type cbcBlockCipher struct {
|
||||
oid asn1.ObjectIdentifier
|
||||
ivSize int
|
||||
keySize int
|
||||
newBlock func(key []byte) (cipher.Block, error)
|
||||
}
|
||||
|
||||
func (c cipherWithBlock) KeySize() int {
|
||||
func (c cbcBlockCipher) KeySize() int {
|
||||
return c.keySize
|
||||
}
|
||||
|
||||
func (c cipherWithBlock) OID() asn1.ObjectIdentifier {
|
||||
func (c cbcBlockCipher) OID() asn1.ObjectIdentifier {
|
||||
return c.oid
|
||||
}
|
||||
|
||||
func (c cipherWithBlock) Encrypt(key, plaintext []byte) (*pkix.AlgorithmIdentifier, []byte, error) {
|
||||
func (c cbcBlockCipher) Encrypt(key, plaintext []byte) (*pkix.AlgorithmIdentifier, []byte, error) {
|
||||
block, err := c.newBlock(key)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@ -44,6 +44,7 @@ func (c cipherWithBlock) Encrypt(key, plaintext []byte) (*pkix.AlgorithmIdentifi
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
marshalledIV, err := asn1.Marshal(iv)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@ -57,7 +58,7 @@ func (c cipherWithBlock) Encrypt(key, plaintext []byte) (*pkix.AlgorithmIdentifi
|
||||
return &encryptionScheme, ciphertext, nil
|
||||
}
|
||||
|
||||
func (c cipherWithBlock) Decrypt(key []byte, parameters *asn1.RawValue, encryptedKey []byte) ([]byte, error) {
|
||||
func (c cbcBlockCipher) Decrypt(key []byte, parameters *asn1.RawValue, encryptedKey []byte) ([]byte, error) {
|
||||
block, err := c.newBlock(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -88,7 +89,7 @@ func cbcDecrypt(block cipher.Block, key, iv, ciphertext []byte) ([]byte, error)
|
||||
return pkcs7.Unpad(plaintext)
|
||||
}
|
||||
|
||||
type cipherWithGCM struct {
|
||||
type gcmBlockCipher struct {
|
||||
oid asn1.ObjectIdentifier
|
||||
nonceSize int
|
||||
keySize int
|
||||
@ -101,15 +102,15 @@ type gcmParameters struct {
|
||||
ICVLen int
|
||||
}
|
||||
|
||||
func (c cipherWithGCM) KeySize() int {
|
||||
func (c gcmBlockCipher) KeySize() int {
|
||||
return c.keySize
|
||||
}
|
||||
|
||||
func (c cipherWithGCM) OID() asn1.ObjectIdentifier {
|
||||
func (c gcmBlockCipher) OID() asn1.ObjectIdentifier {
|
||||
return c.oid
|
||||
}
|
||||
|
||||
func (c cipherWithGCM) Encrypt(key, plaintext []byte) (*pkix.AlgorithmIdentifier, []byte, error) {
|
||||
func (c gcmBlockCipher) Encrypt(key, plaintext []byte) (*pkix.AlgorithmIdentifier, []byte, error) {
|
||||
block, err := c.newBlock(key)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@ -141,7 +142,7 @@ func (c cipherWithGCM) Encrypt(key, plaintext []byte) (*pkix.AlgorithmIdentifier
|
||||
return &encryptionAlgorithm, ciphertext, nil
|
||||
}
|
||||
|
||||
func (c cipherWithGCM) Decrypt(key []byte, parameters *asn1.RawValue, encryptedKey []byte) ([]byte, error) {
|
||||
func (c gcmBlockCipher) Decrypt(key []byte, parameters *asn1.RawValue, encryptedKey []byte) ([]byte, error) {
|
||||
block, err := c.newBlock(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -36,7 +36,7 @@ func init() {
|
||||
}
|
||||
|
||||
// AES128CBC is the 128-bit key AES cipher in CBC mode.
|
||||
var AES128CBC = cipherWithBlock{
|
||||
var AES128CBC = cbcBlockCipher{
|
||||
ivSize: aes.BlockSize,
|
||||
keySize: 16,
|
||||
newBlock: aes.NewCipher,
|
||||
@ -44,7 +44,7 @@ var AES128CBC = cipherWithBlock{
|
||||
}
|
||||
|
||||
// AES128GCM is the 128-bit key AES cipher in GCM mode.
|
||||
var AES128GCM = cipherWithGCM{
|
||||
var AES128GCM = gcmBlockCipher{
|
||||
nonceSize: 12,
|
||||
keySize: 16,
|
||||
newBlock: aes.NewCipher,
|
||||
@ -52,7 +52,7 @@ var AES128GCM = cipherWithGCM{
|
||||
}
|
||||
|
||||
// AES192CBC is the 192-bit key AES cipher in CBC mode.
|
||||
var AES192CBC = cipherWithBlock{
|
||||
var AES192CBC = cbcBlockCipher{
|
||||
ivSize: aes.BlockSize,
|
||||
keySize: 24,
|
||||
newBlock: aes.NewCipher,
|
||||
@ -60,7 +60,7 @@ var AES192CBC = cipherWithBlock{
|
||||
}
|
||||
|
||||
// AES192GCM is the 912-bit key AES cipher in GCM mode.
|
||||
var AES192GCM = cipherWithGCM{
|
||||
var AES192GCM = gcmBlockCipher{
|
||||
nonceSize: 12,
|
||||
keySize: 24,
|
||||
newBlock: aes.NewCipher,
|
||||
@ -68,7 +68,7 @@ var AES192GCM = cipherWithGCM{
|
||||
}
|
||||
|
||||
// AES256CBC is the 256-bit key AES cipher in CBC mode.
|
||||
var AES256CBC = cipherWithBlock{
|
||||
var AES256CBC = cbcBlockCipher{
|
||||
ivSize: aes.BlockSize,
|
||||
keySize: 32,
|
||||
newBlock: aes.NewCipher,
|
||||
@ -76,7 +76,7 @@ var AES256CBC = cipherWithBlock{
|
||||
}
|
||||
|
||||
// AES256GCM is the 256-bit key AES cipher in GCM mode.
|
||||
var AES256GCM = cipherWithGCM{
|
||||
var AES256GCM = gcmBlockCipher{
|
||||
nonceSize: 12,
|
||||
keySize: 32,
|
||||
newBlock: aes.NewCipher,
|
||||
|
@ -20,7 +20,7 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
var DESCBC = cipherWithBlock{
|
||||
var DESCBC = cbcBlockCipher{
|
||||
ivSize: des.BlockSize,
|
||||
keySize: 8,
|
||||
newBlock: des.NewCipher,
|
||||
@ -28,7 +28,7 @@ var DESCBC = cipherWithBlock{
|
||||
}
|
||||
|
||||
// TripleDESCBC is the 168-bit key 3DES cipher in CBC mode.
|
||||
var TripleDESCBC = cipherWithBlock{
|
||||
var TripleDESCBC = cbcBlockCipher{
|
||||
ivSize: des.BlockSize,
|
||||
keySize: 24,
|
||||
newBlock: des.NewTripleDESCipher,
|
||||
|
@ -21,7 +21,7 @@ func init() {
|
||||
}
|
||||
|
||||
// SM4CBC is the 128-bit key SM4 cipher in CBC mode.
|
||||
var SM4CBC = cipherWithBlock{
|
||||
var SM4CBC = cbcBlockCipher{
|
||||
ivSize: sm4.BlockSize,
|
||||
keySize: 16,
|
||||
newBlock: sm4.NewCipher,
|
||||
@ -29,7 +29,7 @@ var SM4CBC = cipherWithBlock{
|
||||
}
|
||||
|
||||
// SM4GCM is the 128-bit key SM4 cipher in GCM mode.
|
||||
var SM4GCM = cipherWithGCM{
|
||||
var SM4GCM = gcmBlockCipher{
|
||||
nonceSize: 12,
|
||||
keySize: 16,
|
||||
newBlock: sm4.NewCipher,
|
||||
|
Loading…
x
Reference in New Issue
Block a user