mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-26 04:06:18 +08:00
cipher: align error message pattern
This commit is contained in:
parent
3c11e3a166
commit
82125c00a4
@ -120,7 +120,7 @@ func (h *hctr) BlockSize() int {
|
|||||||
// in HCTR mode. The lenght of tweak and hash key must be the same as the [Block]'s block size.
|
// in HCTR mode. The lenght of tweak and hash key must be the same as the [Block]'s block size.
|
||||||
func NewHCTR(cipher _cipher.Block, tweak, hkey []byte) (LengthPreservingMode, error) {
|
func NewHCTR(cipher _cipher.Block, tweak, hkey []byte) (LengthPreservingMode, error) {
|
||||||
if len(tweak) != blockSize || len(hkey) != blockSize {
|
if len(tweak) != blockSize || len(hkey) != blockSize {
|
||||||
return nil, errors.New("hctr: invalid tweak and/or hash key length")
|
return nil, errors.New("cipher: invalid tweak and/or hash key length")
|
||||||
}
|
}
|
||||||
c := &hctr{}
|
c := &hctr{}
|
||||||
c.cipher = cipher
|
c.cipher = cipher
|
||||||
@ -220,13 +220,13 @@ func (h *hctr) uhash(m []byte, out *[blockSize]byte) {
|
|||||||
|
|
||||||
func (h *hctr) EncryptBytes(ciphertext, plaintext []byte) {
|
func (h *hctr) EncryptBytes(ciphertext, plaintext []byte) {
|
||||||
if len(ciphertext) < len(plaintext) {
|
if len(ciphertext) < len(plaintext) {
|
||||||
panic("hctr: ciphertext is smaller than plaintext")
|
panic("cipher: ciphertext is smaller than plaintext")
|
||||||
}
|
}
|
||||||
if len(plaintext) < blockSize {
|
if len(plaintext) < blockSize {
|
||||||
panic("hctr: plaintext length is smaller than the block size")
|
panic("cipher: plaintext length is smaller than the block size")
|
||||||
}
|
}
|
||||||
if alias.InexactOverlap(ciphertext[:len(plaintext)], plaintext) {
|
if alias.InexactOverlap(ciphertext[:len(plaintext)], plaintext) {
|
||||||
panic("hctr: invalid buffer overlap")
|
panic("cipher: invalid buffer overlap")
|
||||||
}
|
}
|
||||||
|
|
||||||
var z1, z2 [blockSize]byte
|
var z1, z2 [blockSize]byte
|
||||||
@ -245,13 +245,13 @@ func (h *hctr) EncryptBytes(ciphertext, plaintext []byte) {
|
|||||||
|
|
||||||
func (h *hctr) DecryptBytes(plaintext, ciphertext []byte) {
|
func (h *hctr) DecryptBytes(plaintext, ciphertext []byte) {
|
||||||
if len(plaintext) < len(ciphertext) {
|
if len(plaintext) < len(ciphertext) {
|
||||||
panic("hctr: plaintext is smaller than cihpertext")
|
panic("cipher: plaintext is smaller than cihpertext")
|
||||||
}
|
}
|
||||||
if len(ciphertext) < blockSize {
|
if len(ciphertext) < blockSize {
|
||||||
panic("hctr: ciphertext length is smaller than the block size")
|
panic("cipher: ciphertext length is smaller than the block size")
|
||||||
}
|
}
|
||||||
if alias.InexactOverlap(plaintext[:len(ciphertext)], ciphertext) {
|
if alias.InexactOverlap(plaintext[:len(ciphertext)], ciphertext) {
|
||||||
panic("hctr: invalid buffer overlap")
|
panic("cipher: invalid buffer overlap")
|
||||||
}
|
}
|
||||||
|
|
||||||
var z1, z2 [blockSize]byte
|
var z1, z2 [blockSize]byte
|
||||||
|
@ -72,7 +72,7 @@ func NewGBXTSEncrypterWithSector(cipherFunc CipherCreator, key, tweakKey []byte,
|
|||||||
|
|
||||||
func newXTSEncrypter(cipherFunc CipherCreator, key, tweakKey, tweak []byte, isGB bool) (_cipher.BlockMode, error) {
|
func newXTSEncrypter(cipherFunc CipherCreator, key, tweakKey, tweak []byte, isGB bool) (_cipher.BlockMode, error) {
|
||||||
if len(tweak) != blockSize {
|
if len(tweak) != blockSize {
|
||||||
return nil, errors.New("xts: invalid tweak length")
|
return nil, errors.New("cipher: invalid tweak length")
|
||||||
}
|
}
|
||||||
|
|
||||||
k1, err := cipherFunc(key)
|
k1, err := cipherFunc(key)
|
||||||
@ -80,7 +80,7 @@ func newXTSEncrypter(cipherFunc CipherCreator, key, tweakKey, tweak []byte, isGB
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if k1.BlockSize() != blockSize {
|
if k1.BlockSize() != blockSize {
|
||||||
return nil, errors.New("xts: cipher does not have a block size of 16")
|
return nil, errors.New("cipher: cipher does not have a block size of 16")
|
||||||
}
|
}
|
||||||
|
|
||||||
k2, err := cipherFunc(tweakKey)
|
k2, err := cipherFunc(tweakKey)
|
||||||
@ -144,7 +144,7 @@ func NewGBXTSDecrypterWithSector(cipherFunc CipherCreator, key, tweakKey []byte,
|
|||||||
|
|
||||||
func newXTSDecrypter(cipherFunc CipherCreator, key, tweakKey, tweak []byte, isGB bool) (_cipher.BlockMode, error) {
|
func newXTSDecrypter(cipherFunc CipherCreator, key, tweakKey, tweak []byte, isGB bool) (_cipher.BlockMode, error) {
|
||||||
if len(tweak) != blockSize {
|
if len(tweak) != blockSize {
|
||||||
return nil, errors.New("xts: invalid tweak length")
|
return nil, errors.New("cipher: invalid tweak length")
|
||||||
}
|
}
|
||||||
|
|
||||||
k1, err := cipherFunc(key)
|
k1, err := cipherFunc(key)
|
||||||
@ -152,7 +152,7 @@ func newXTSDecrypter(cipherFunc CipherCreator, key, tweakKey, tweak []byte, isGB
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if k1.BlockSize() != blockSize {
|
if k1.BlockSize() != blockSize {
|
||||||
return nil, errors.New("xts: cipher does not have a block size of 16")
|
return nil, errors.New("cipher: cipher does not have a block size of 16")
|
||||||
}
|
}
|
||||||
|
|
||||||
k2, err := cipherFunc(tweakKey)
|
k2, err := cipherFunc(tweakKey)
|
||||||
@ -183,13 +183,13 @@ func (c *xtsEncrypter) BlockSize() int {
|
|||||||
// Sectors must be a multiple of 16 bytes and less than 2²⁴ bytes.
|
// Sectors must be a multiple of 16 bytes and less than 2²⁴ bytes.
|
||||||
func (c *xtsEncrypter) CryptBlocks(ciphertext, plaintext []byte) {
|
func (c *xtsEncrypter) CryptBlocks(ciphertext, plaintext []byte) {
|
||||||
if len(ciphertext) < len(plaintext) {
|
if len(ciphertext) < len(plaintext) {
|
||||||
panic("xts: ciphertext is smaller than plaintext")
|
panic("cipher: ciphertext is smaller than plaintext")
|
||||||
}
|
}
|
||||||
if len(plaintext) < blockSize {
|
if len(plaintext) < blockSize {
|
||||||
panic("xts: plaintext length is smaller than the block size")
|
panic("cipher: plaintext length is smaller than the block size")
|
||||||
}
|
}
|
||||||
if alias.InexactOverlap(ciphertext[:len(plaintext)], plaintext) {
|
if alias.InexactOverlap(ciphertext[:len(plaintext)], plaintext) {
|
||||||
panic("xts: invalid buffer overlap")
|
panic("cipher: invalid buffer overlap")
|
||||||
}
|
}
|
||||||
|
|
||||||
lastCiphertext := ciphertext
|
lastCiphertext := ciphertext
|
||||||
@ -244,13 +244,13 @@ func (c *xtsDecrypter) BlockSize() int {
|
|||||||
// Sectors must be a multiple of 16 bytes and less than 2²⁴ bytes.
|
// Sectors must be a multiple of 16 bytes and less than 2²⁴ bytes.
|
||||||
func (c *xtsDecrypter) CryptBlocks(plaintext, ciphertext []byte) {
|
func (c *xtsDecrypter) CryptBlocks(plaintext, ciphertext []byte) {
|
||||||
if len(plaintext) < len(ciphertext) {
|
if len(plaintext) < len(ciphertext) {
|
||||||
panic("xts: plaintext is smaller than ciphertext")
|
panic("cipher: plaintext is smaller than ciphertext")
|
||||||
}
|
}
|
||||||
if len(ciphertext) < blockSize {
|
if len(ciphertext) < blockSize {
|
||||||
panic("xts: ciphertext length is smaller than the block size")
|
panic("cipher: ciphertext length is smaller than the block size")
|
||||||
}
|
}
|
||||||
if alias.InexactOverlap(plaintext[:len(ciphertext)], ciphertext) {
|
if alias.InexactOverlap(plaintext[:len(ciphertext)], ciphertext) {
|
||||||
panic("xts: invalid buffer overlap")
|
panic("cipher: invalid buffer overlap")
|
||||||
}
|
}
|
||||||
|
|
||||||
if concCipher, ok := c.b.(concurrentBlocks); ok {
|
if concCipher, ok := c.b.(concurrentBlocks); ok {
|
||||||
|
@ -56,13 +56,13 @@ func decryptSm4XtsGB(xk *uint32, tweak *[BlockSize]byte, dst, src []byte)
|
|||||||
|
|
||||||
func validateXtsInput(dst, src []byte) {
|
func validateXtsInput(dst, src []byte) {
|
||||||
if len(dst) < len(src) {
|
if len(dst) < len(src) {
|
||||||
panic("xts: dst is smaller than src")
|
panic("cipher: dst is smaller than src")
|
||||||
}
|
}
|
||||||
if len(src) < BlockSize {
|
if len(src) < BlockSize {
|
||||||
panic("xts: src length is smaller than the block size")
|
panic("cipher: src length is smaller than the block size")
|
||||||
}
|
}
|
||||||
if alias.InexactOverlap(dst[:len(src)], src) {
|
if alias.InexactOverlap(dst[:len(src)], src) {
|
||||||
panic("xts: invalid buffer overlap")
|
panic("cipher: invalid buffer overlap")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user