sm4soft

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const BlockSize = 16

BlockSize 分组长度 16字节

Variables

View Source
var IVDefault = make([]byte, BlockSize)

IVDefault 默认初始化向量 IVDefault

Functions

func DecryptBlock

func DecryptBlock(key SM4Key, dst, src []byte)

DecryptBlock 分组解密

func EncryptBlock

func EncryptBlock(key SM4Key, dst, src []byte)

EncryptBlock 分组加密

func GCMDecrypt

func GCMDecrypt(K, IV, C, A []byte) (P, _T []byte)

func GCMEncrypt

func GCMEncrypt(K, IV, P, A []byte) (C, T []byte)

GCMEncrypt 可鉴别加密函数 (GCM-AE(k)) K: 对称密钥 IV: IV向量 P: 明文 A: 附加的鉴别数据

return: 密文, 鉴别标签

func GHASH

func GHASH(H []byte, A []byte, C []byte) (X []byte)

func GetH

func GetH(key []byte) (H []byte)

GetH 对“0”分组的加密得到 GHASH泛杂凑函数的子密钥 key: 对称密钥 return: GHASH泛杂凑函数的子密钥

func GetY0

func GetY0(H, IV []byte) []byte

GetY0 生成初始的计数器时钟J0

H: GHASH自密钥 IV: IV向量 return: 初始的计数器时钟(J0)

func MSB

func MSB(len int, S []byte) (out []byte)

func NewCipher

func NewCipher(key []byte) (cipher.Block, error)

NewCipher creates and returns a new cipher.Block.

func Rightshift

func Rightshift(V []byte)

func SetIVDefault

func SetIVDefault(iv []byte) error

func Sm4CFB

func Sm4CFB(key []byte, iv []byte, in []byte, encrypt bool) (out []byte, err error)

Sm4CFB sm4加密(CFB模式),需要IV,没有PKCS#7填充

func Sm4Cbc

func Sm4Cbc(key []byte, iv []byte, in []byte, encrypt bool) (out []byte, err error)

Sm4Cbc sm4加密(CBC模式),需要IV,有PKCS#7填充

func Sm4Ecb

func Sm4Ecb(key []byte, in []byte, encrypt bool) (out []byte, err error)

Sm4Ecb sm4加密(ECB模式),不需要IV,有PKCS#7填充

func Sm4GCM

func Sm4GCM(key []byte, IV, in, A []byte, mode bool) ([]byte, []byte, error)

Sm4GCM SM4 GCM 加解密模式 Paper: The Galois/Counter Mode of Operation (GCM) David A. Mcgrew,John Viega .2004. key: 对称加密密钥 IV: IV向量 in: A: 附加的可鉴别数据(ADD) mode: true - 加密; false - 解密验证

return: 密文C, 鉴别标签T, 错误

func Sm4OFB

func Sm4OFB(key []byte, iv []byte, in []byte, encrypt bool) (out []byte, err error)

Sm4OFB sm4加密(OFB模式),需要IV,没有PKCS#7填充

func WriteKeyToPem

func WriteKeyToPem(key SM4Key, pwd []byte) ([]byte, error)

WriteKeyToPem will convert SM4Key to PEM format data and return it.

func WriteKeyToPemFile

func WriteKeyToPemFile(FileName string, key SM4Key, pwd []byte) error

WriteKeyToPemFile will convert SM4Key to PEM format data, then write it into the input filename.

func WriteKeytoMem

func WriteKeytoMem(key SM4Key, pwd []byte) ([]byte, error)

WriteKeytoMem sm4密钥转为pem字节数组

Types

type SM4Key

type SM4Key []byte

SM4Key sm4密钥

func ReadKeyFromMem

func ReadKeyFromMem(data []byte, pwd []byte) (SM4Key, error)

ReadKeyFromMem 将pem字节数组转为sm4密钥

func ReadKeyFromPem

func ReadKeyFromPem(data []byte, pwd []byte) (SM4Key, error)

ReadKeyFromPem will return SM4Key from PEM format data.

func ReadKeyFromPemFile

func ReadKeyFromPemFile(FileName string, pwd []byte) (SM4Key, error)

ReadKeyFromPemFile will return SM4Key from filename that saved PEM format data.

type Sm4Cipher

type Sm4Cipher struct {
	// contains filtered or unexported fields
}

Cipher is an instance of SM4 encryption. Sm4Cipher sm4加密实例结构体

func (*Sm4Cipher) BlockSize

func (c *Sm4Cipher) BlockSize() int

BlockSize 获取分组长度(字节数量)

func (*Sm4Cipher) Decrypt

func (c *Sm4Cipher) Decrypt(dst, src []byte)

Decrypt 块解密

func (*Sm4Cipher) Encrypt

func (c *Sm4Cipher) Encrypt(dst, src []byte)

Encrypt 块加密

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL