// In amd64, Encrypt4 implemented
package sm4

import "xdx.jelly/xgcl/internal/subtle"

//go:noescape
func encrypt4(dst []byte, src []byte, rk []uint32)

func (c *sm4CipherAsm) Encrypt4(dst, src []byte) {
	if len(src) < BlockSize {
		panic("gcl/sm/sm4/Encrypt: input not full block")
	}
	if len(dst) < BlockSize {
		panic("gcl/sm/sm4/Encrypt: output not full block")
	}
	if subtle.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
		panic("gcl/sm/sm4/Encrypt: invalid buffer overlap")
	}
	encrypt4(dst, src, c.encKey[:])
}

func (c *sm4CipherAsm) Decrypt4(dst, src []byte) {
	if len(src) < BlockSize {
		panic("gcl/sm/sm4/Decrypt: input not full block")
	}
	if len(dst) < BlockSize {
		panic("gcl/sm/sm4/Decrypt: output not full block")
	}
	if subtle.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
		panic("gcl/sm/sm4/Decrypt: invalid buffer overlap")
	}
	encrypt4(dst, src, c.decKey[:])
}
