From e2c430a0ff03ec7ff634585dc50d0117c8aa6808 Mon Sep 17 00:00:00 2001 From: Sun Yimin Date: Fri, 22 Nov 2024 08:33:24 +0800 Subject: [PATCH] zuc: add comments --- pkcs7/envelope.go | 2 +- zuc/eea.go | 6 ++++++ zuc/eia.go | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkcs7/envelope.go b/pkcs7/envelope.go index a5c6288..3bc90a5 100644 --- a/pkcs7/envelope.go +++ b/pkcs7/envelope.go @@ -210,7 +210,7 @@ func newEnvelopedData(cipher pkcs.Cipher, content []byte, contentType asn1.Objec // AddRecipient adds a recipient to the EnvelopedData structure. // version 0: IssuerAndSerialNumber -// version 1: SM2GB/T 35275-2017 +// version 1: GB/T 35275-2017 // version 2: SubjectKeyIdentifier func (ed *EnvelopedData) AddRecipient(cert *smx509.Certificate, version int, encryptKeyFunc func(cert *smx509.Certificate, key []byte) ([]byte, error)) error { if version < 0 || version > 2 { diff --git a/zuc/eea.go b/zuc/eea.go index 726510b..ea01b58 100644 --- a/zuc/eea.go +++ b/zuc/eea.go @@ -17,6 +17,9 @@ type eea struct { } // 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) { s, err := newZUCState(key, iv) 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. +// 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) { iv := make([]byte, 16) byteorder.BEPutUint32(iv, count) diff --git a/zuc/eia.go b/zuc/eia.go index b2ea401..8905791 100644 --- a/zuc/eia.go +++ b/zuc/eia.go @@ -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 +// 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) { return NewHash(key, genIV4EIA(count, bearer, direction)) }