gmsm/zuc/eea.go

37 lines
1.3 KiB
Go
Raw Normal View History

// Package zuc implements ShangMi(SM) zuc stream cipher and integrity algorithm.
2022-04-19 11:25:14 +08:00
package zuc
import (
2024-11-29 11:44:59 +08:00
"github.com/emmansun/gmsm/cipher"
"github.com/emmansun/gmsm/internal/zuc"
2022-04-19 11:25:14 +08:00
)
const (
// IV size in bytes for zuc 128
IVSize128 = 16
// IV size in bytes for zuc 256
IVSize256 = 23
// number of words in a round
RoundWords = 32
// number of bytes in a word
WordSize = 4
// number of bytes in a round
RoundBytes = RoundWords * WordSize
)
2022-06-30 11:29:42 +08:00
2022-04-19 11:25:14 +08:00
// NewCipher create a stream cipher based on key and iv aguments.
2024-11-22 08:33:24 +08:00
// 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.
2024-11-29 11:44:59 +08:00
func NewCipher(key, iv []byte) (cipher.SeekableStream, error) {
return zuc.NewCipher(key, iv)
2022-04-19 11:25:14 +08:00
}
// NewEEACipher create a stream cipher based on key, count, bearer and direction arguments according specification.
2024-11-22 08:33:24 +08:00
// The key must be 16 bytes long and iv must be 16 bytes long, otherwise, an error will be returned.
2024-11-29 11:44:59 +08:00
// The count is the 32-bit counter value, the bearer is the 5-bit bearer identity and the direction is the 1-bit
2024-11-22 08:33:24 +08:00
// transmission direction flag.
2024-11-29 11:44:59 +08:00
func NewEEACipher(key []byte, count, bearer, direction uint32) (cipher.SeekableStream, error) {
return zuc.NewEEACipher(key, count, bearer, direction)
2022-04-19 11:25:14 +08:00
}