Documentation
¶
Overview ¶
Package sm4 implements SM4 encryption and decryption with streaming support. It provides SM4 encryption and decryption operations using the standard SM4 algorithm with support for various cipher modes.
Index ¶
- Constants
- func NewCipher(key []byte) (cipher.Block, error)
- func NewStreamDecrypter(r io.Reader, c *cipher.Sm4Cipher) io.Reader
- func NewStreamEncrypter(w io.Writer, c *cipher.Sm4Cipher) io.WriteCloser
- type DecryptError
- type EncryptError
- type KeySizeError
- type ReadError
- type StdDecrypter
- type StdEncrypter
- type StreamDecrypter
- type StreamEncrypter
Constants ¶
const ( // BlockSize is the SM4 block size in bytes. BlockSize = 16 // KeySize is the SM4 key size in bytes. KeySize = 16 )
Variables ¶
This section is empty.
Functions ¶
func NewCipher ¶
NewCipher creates a new SM4 cipher with the given key. The key must be exactly 16 bytes (128 bits).
func NewStreamDecrypter ¶
NewStreamDecrypter creates a new streaming SM4 decrypter that reads encrypted data from the provided io.Reader. The decrypter uses the specified cipher interface and validates the key length for proper SM4 decryption.
func NewStreamEncrypter ¶
NewStreamEncrypter creates a new streaming SM4 encrypter that writes encrypted data to the provided io.Writer. The encrypter uses the specified cipher interface and validates the key length for proper SM4 encryption.
Types ¶
type DecryptError ¶
type DecryptError struct {
Err error
}
DecryptError represents an error during SM4 decryption.
func (DecryptError) Error ¶
func (d DecryptError) Error() string
Error returns the error message for DecryptError.
type EncryptError ¶
type EncryptError struct {
Err error
}
EncryptError represents an error during SM4 encryption.
func (EncryptError) Error ¶
func (e EncryptError) Error() string
Error returns the error message for EncryptError.
type KeySizeError ¶
type KeySizeError int
KeySizeError represents an error when the SM4 key size is invalid. SM4 keys must be exactly 16 bytes (128 bits).
func (KeySizeError) Error ¶
func (k KeySizeError) Error() string
Error returns the error message for KeySizeError.
type ReadError ¶
type ReadError struct {
Err error
}
ReadError represents an error during data reading in streaming operations.
type StdDecrypter ¶
type StdDecrypter struct {
Error error // Error field for storing decryption errors
// contains filtered or unexported fields
}
StdDecrypter represents an SM4 decrypter for standard decryption operations.
func NewStdDecrypter ¶
func NewStdDecrypter(c *cipher.Sm4Cipher) *StdDecrypter
NewStdDecrypter creates a new SM4 decrypter with the specified cipher and key.
func (*StdDecrypter) Decrypt ¶
func (d *StdDecrypter) Decrypt(src []byte) (dst []byte, err error)
Decrypt decrypts the given byte slice using SM4 decryption.
type StdEncrypter ¶
type StdEncrypter struct {
Error error // Error field for storing encryption errors
// contains filtered or unexported fields
}
StdEncrypter represents an SM4 encrypter for standard encryption operations.
func NewStdEncrypter ¶
func NewStdEncrypter(c *cipher.Sm4Cipher) *StdEncrypter
NewStdEncrypter creates a new SM4 encrypter with the specified cipher and key.
func (*StdEncrypter) Encrypt ¶
func (e *StdEncrypter) Encrypt(src []byte) (dst []byte, err error)
Encrypt encrypts the given byte slice using SM4 encryption.
type StreamDecrypter ¶
type StreamDecrypter struct {
Error error // Error field for storing decryption errors
// contains filtered or unexported fields
}
StreamDecrypter represents a streaming SM4 decrypter that implements io.Reader.
func (*StreamDecrypter) Read ¶
func (d *StreamDecrypter) Read(dst []byte) (n int, err error)
Read implements the io.Reader interface for streaming SM4 decryption.
type StreamEncrypter ¶
type StreamEncrypter struct {
Error error // Error field for storing encryption errors
// contains filtered or unexported fields
}
StreamEncrypter represents a streaming SM4 encrypter that implements io.WriteCloser.
func (*StreamEncrypter) Close ¶
func (e *StreamEncrypter) Close() error
Close implements the io.Closer interface for the streaming SM4 encrypter.
func (*StreamEncrypter) Write ¶
func (e *StreamEncrypter) Write(src []byte) (n int, err error)
Write implements the io.Writer interface for streaming SM4 encryption.
Source Files
¶
- core.go
- errors.go
- sm4.go