Skip to content

Commit

Permalink
zuc: add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
emmansun authored Nov 22, 2024
1 parent 5c2a22e commit e2c430a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkcs7/envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions zuc/eea.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions zuc/eia.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down

0 comments on commit e2c430a

Please sign in to comment.