MAGIC - align error message

This commit is contained in:
Emman 2021-04-06 15:24:00 +08:00
parent cab0150f3c
commit ddea2f74c8
4 changed files with 17 additions and 17 deletions

View File

@ -28,13 +28,13 @@ func (x *cbc) BlockSize() int { return BlockSize }
func (x *cbc) CryptBlocks(dst, src []byte) {
if len(src)%BlockSize != 0 {
panic("crypto/cipher: input not full blocks")
panic("cipher: input not full blocks")
}
if len(dst) < len(src) {
panic("crypto/cipher: output smaller than input")
panic("cipher: output smaller than input")
}
if smcipher.InexactOverlap(dst[:len(src)], src) {
panic("crypto/cipher: invalid buffer overlap")
panic("cipher: invalid buffer overlap")
}
if len(src) == 0 {
return

View File

@ -78,10 +78,10 @@ func (x *ctr) refill() {
func (x *ctr) XORKeyStream(dst, src []byte) {
if len(dst) < len(src) {
panic("crypto/cipher: output smaller than input")
panic("cipher: output smaller than input")
}
if smcipher.InexactOverlap(dst[:len(src)], src) {
panic("crypto/cipher: invalid buffer overlap")
panic("cipher: invalid buffer overlap")
}
for len(src) > 0 {
if x.outUsed >= len(x.out)-BlockSize {

View File

@ -76,15 +76,15 @@ func (g *gcm) Overhead() int {
func (g *gcm) Seal(dst, nonce, plaintext, data []byte) []byte {
if len(nonce) != g.nonceSize {
panic("crypto/cipher: incorrect nonce length given to GCM")
panic("cipher: incorrect nonce length given to GCM")
}
if uint64(len(plaintext)) > ((1<<32)-2)*uint64(g.cipher.BlockSize()) {
panic("crypto/cipher: message too large for GCM")
panic("cipher: message too large for GCM")
}
ret, out := smcipher.SliceForAppend(dst, len(plaintext)+g.tagSize)
if smcipher.InexactOverlap(out, plaintext) {
panic("crypto/cipher: invalid buffer overlap")
panic("cipher: invalid buffer overlap")
}
var counter, tagMask [gcmBlockSize]byte
@ -106,12 +106,12 @@ var errOpen = errors.New("cipher: message authentication failed")
func (g *gcm) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) {
if len(nonce) != g.nonceSize {
panic("crypto/cipher: incorrect nonce length given to GCM")
panic("cipher: incorrect nonce length given to GCM")
}
// Sanity check to prevent the authentication from always succeeding if an implementation
// leaves tagSize uninitialized, for example.
if g.tagSize < gcmMinimumTagSize {
panic("crypto/cipher: incorrect GCM tag size")
panic("cipher: incorrect GCM tag size")
}
if len(ciphertext) < g.tagSize {
@ -135,7 +135,7 @@ func (g *gcm) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) {
ret, out := smcipher.SliceForAppend(dst, len(ciphertext))
if smcipher.InexactOverlap(out, ciphertext) {
panic("crypto/cipher: invalid buffer overlap")
panic("cipher: invalid buffer overlap")
}
if subtle.ConstantTimeCompare(expectedTag[:g.tagSize], tag) != 1 {

View File

@ -57,10 +57,10 @@ func (g *gcmAsm) Overhead() int {
// details.
func (g *gcmAsm) Seal(dst, nonce, plaintext, data []byte) []byte {
if len(nonce) != g.nonceSize {
panic("crypto/cipher: incorrect nonce length given to GCM")
panic("cipher: incorrect nonce length given to GCM")
}
if uint64(len(plaintext)) > ((1<<32)-2)*BlockSize {
panic("crypto/cipher: message too large for GCM")
panic("cipher: message too large for GCM")
}
var counter, tagMask [gcmBlockSize]byte
@ -84,7 +84,7 @@ func (g *gcmAsm) Seal(dst, nonce, plaintext, data []byte) []byte {
ret, out := smcipher.SliceForAppend(dst, len(plaintext)+g.tagSize)
if smcipher.InexactOverlap(out[:len(plaintext)], plaintext) {
panic("crypto/cipher: invalid buffer overlap")
panic("cipher: invalid buffer overlap")
}
if len(plaintext) > 0 {
@ -101,12 +101,12 @@ func (g *gcmAsm) Seal(dst, nonce, plaintext, data []byte) []byte {
// for details.
func (g *gcmAsm) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) {
if len(nonce) != g.nonceSize {
panic("crypto/cipher: incorrect nonce length given to GCM")
panic("cipher: incorrect nonce length given to GCM")
}
// Sanity check to prevent the authentication from always succeeding if an implementation
// leaves tagSize uninitialized, for example.
if g.tagSize < gcmMinimumTagSize {
panic("crypto/cipher: incorrect GCM tag size")
panic("cipher: incorrect GCM tag size")
}
if len(ciphertext) < g.tagSize {
@ -140,7 +140,7 @@ func (g *gcmAsm) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) {
ret, out := smcipher.SliceForAppend(dst, len(ciphertext))
if smcipher.InexactOverlap(out, ciphertext) {
panic("crypto/cipher: invalid buffer overlap")
panic("cipher: invalid buffer overlap")
}
if len(ciphertext) > 0 {
gcmSm4Data(&g.bytesProductTable, ciphertext, &expectedTag)