mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-27 04:36:19 +08:00
zuc: add comments
This commit is contained in:
parent
5c2a22ec2a
commit
e2c430a0ff
@ -210,7 +210,7 @@ func newEnvelopedData(cipher pkcs.Cipher, content []byte, contentType asn1.Objec
|
|||||||
|
|
||||||
// AddRecipient adds a recipient to the EnvelopedData structure.
|
// AddRecipient adds a recipient to the EnvelopedData structure.
|
||||||
// version 0: IssuerAndSerialNumber
|
// version 0: IssuerAndSerialNumber
|
||||||
// version 1: SM2GB/T 35275-2017
|
// version 1: GB/T 35275-2017
|
||||||
// version 2: SubjectKeyIdentifier
|
// version 2: SubjectKeyIdentifier
|
||||||
func (ed *EnvelopedData) AddRecipient(cert *smx509.Certificate, version int, encryptKeyFunc func(cert *smx509.Certificate, key []byte) ([]byte, error)) error {
|
func (ed *EnvelopedData) AddRecipient(cert *smx509.Certificate, version int, encryptKeyFunc func(cert *smx509.Certificate, key []byte) ([]byte, error)) error {
|
||||||
if version < 0 || version > 2 {
|
if version < 0 || version > 2 {
|
||||||
|
@ -17,6 +17,9 @@ type eea struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewCipher create a stream cipher based on key and iv aguments.
|
// NewCipher create a stream cipher based on key and iv aguments.
|
||||||
|
// The key must be 16 bytes long and iv must be 16 bytes long for zuc 128;
|
||||||
|
// or the key must be 32 bytes long and iv must be 23 bytes long for zuc 256;
|
||||||
|
// otherwise, an error will be returned.
|
||||||
func NewCipher(key, iv []byte) (cipher.Stream, error) {
|
func NewCipher(key, iv []byte) (cipher.Stream, error) {
|
||||||
s, err := newZUCState(key, iv)
|
s, err := newZUCState(key, iv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -28,6 +31,9 @@ func NewCipher(key, iv []byte) (cipher.Stream, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewEEACipher create a stream cipher based on key, count, bearer and direction arguments according specification.
|
// NewEEACipher create a stream cipher based on key, count, bearer and direction arguments according specification.
|
||||||
|
// The key must be 16 bytes long and iv must be 16 bytes long, otherwise, an error will be returned.
|
||||||
|
// The count is the 32-bit counter value, the bearer is the 5-bit bearer identity and the direction is the 1-bit
|
||||||
|
// transmission direction flag.
|
||||||
func NewEEACipher(key []byte, count, bearer, direction uint32) (cipher.Stream, error) {
|
func NewEEACipher(key []byte, count, bearer, direction uint32) (cipher.Stream, error) {
|
||||||
iv := make([]byte, 16)
|
iv := make([]byte, 16)
|
||||||
byteorder.BEPutUint32(iv, count)
|
byteorder.BEPutUint32(iv, count)
|
||||||
|
@ -71,6 +71,9 @@ func genIV4EIA(count, bearer, direction uint32) []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewEIAHash create hash for zuc-128 eia, with arguments key, count, bearer and direction
|
// NewEIAHash create hash for zuc-128 eia, with arguments key, count, bearer and direction
|
||||||
|
// The key must be 16 bytes long and iv must be 16 bytes long, otherwise, an error will be returned.
|
||||||
|
// The count is the 32-bit counter value, the bearer is the 5-bit bearer identity and the direction is the 1-bit
|
||||||
|
// transmission direction flag.
|
||||||
func NewEIAHash(key []byte, count, bearer, direction uint32) (*ZUC128Mac, error) {
|
func NewEIAHash(key []byte, count, bearer, direction uint32) (*ZUC128Mac, error) {
|
||||||
return NewHash(key, genIV4EIA(count, bearer, direction))
|
return NewHash(key, genIV4EIA(count, bearer, direction))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user