mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-26 12:16:20 +08:00
[SM4] Non-owners do not invoke asm method directly
This commit is contained in:
parent
acabed56bd
commit
e515088882
@ -49,7 +49,7 @@ func (x *cbc) CryptBlocks(dst, src []byte) {
|
|||||||
var temp []byte = make([]byte, x.b.blocksSize)
|
var temp []byte = make([]byte, x.b.blocksSize)
|
||||||
var batchSrc []byte = make([]byte, x.b.blocksSize)
|
var batchSrc []byte = make([]byte, x.b.blocksSize)
|
||||||
for start > 0 {
|
for start > 0 {
|
||||||
encryptBlocksAsm(&x.b.dec[0], &temp[0], &src[start:end][0])
|
x.b.DecryptBlocks(temp, src[start:end])
|
||||||
for i := 0; i < x.b.batchBlocks; i++ {
|
for i := 0; i < x.b.batchBlocks; i++ {
|
||||||
xor.XorBytes(dst[end-(i+1)*BlockSize:end-i*BlockSize], temp[x.b.blocksSize-(i+1)*BlockSize:x.b.blocksSize-i*BlockSize], src[end-(i+2)*BlockSize:end-(i+1)*BlockSize])
|
xor.XorBytes(dst[end-(i+1)*BlockSize:end-i*BlockSize], temp[x.b.blocksSize-(i+1)*BlockSize:x.b.blocksSize-i*BlockSize], src[end-(i+2)*BlockSize:end-(i+1)*BlockSize])
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ func (x *cbc) CryptBlocks(dst, src []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
copy(batchSrc, src[:end])
|
copy(batchSrc, src[:end])
|
||||||
encryptBlocksAsm(&x.b.dec[0], &temp[0], &batchSrc[0])
|
x.b.DecryptBlocks(temp, batchSrc)
|
||||||
count := end / BlockSize
|
count := end / BlockSize
|
||||||
for i := count; i > 1; i-- {
|
for i := count; i > 1; i-- {
|
||||||
xor.XorBytes(dst[end-BlockSize:end], temp[end-BlockSize:end], src[end-2*BlockSize:end-BlockSize])
|
xor.XorBytes(dst[end-BlockSize:end], temp[end-BlockSize:end], src[end-2*BlockSize:end-BlockSize])
|
||||||
|
@ -67,7 +67,7 @@ func (x *ctr) refill() {
|
|||||||
copy(x.out, x.out[x.outUsed:])
|
copy(x.out, x.out[x.outUsed:])
|
||||||
x.out = x.out[:cap(x.out)]
|
x.out = x.out[:cap(x.out)]
|
||||||
for remain <= len(x.out)-x.b.blocksSize {
|
for remain <= len(x.out)-x.b.blocksSize {
|
||||||
encryptBlocksAsm(&x.b.enc[0], &x.out[remain:][0], &x.ctr[0])
|
x.b.EncryptBlocks(x.out[remain:], x.ctr)
|
||||||
remain += x.b.blocksSize
|
remain += x.b.blocksSize
|
||||||
|
|
||||||
// Increment counter
|
// Increment counter
|
||||||
|
@ -273,7 +273,7 @@ func (g *gcm) counterCrypt(out, in []byte, counter *[gcmBlockSize]byte) {
|
|||||||
copy(counters[i*gcmBlockSize:(i+1)*gcmBlockSize], counter[:])
|
copy(counters[i*gcmBlockSize:(i+1)*gcmBlockSize], counter[:])
|
||||||
gcmInc32(counter)
|
gcmInc32(counter)
|
||||||
}
|
}
|
||||||
encryptBlocksAsm(&g.cipher.enc[0], &mask[0], &counters[0])
|
g.cipher.EncryptBlocks(mask, counters)
|
||||||
xor.XorWords(out, in, mask[:])
|
xor.XorWords(out, in, mask[:])
|
||||||
out = out[g.cipher.blocksSize:]
|
out = out[g.cipher.blocksSize:]
|
||||||
in = in[g.cipher.blocksSize:]
|
in = in[g.cipher.blocksSize:]
|
||||||
@ -285,7 +285,7 @@ func (g *gcm) counterCrypt(out, in []byte, counter *[gcmBlockSize]byte) {
|
|||||||
copy(counters[i*gcmBlockSize:], counter[:])
|
copy(counters[i*gcmBlockSize:], counter[:])
|
||||||
gcmInc32(counter)
|
gcmInc32(counter)
|
||||||
}
|
}
|
||||||
encryptBlocksAsm(&g.cipher.enc[0], &mask[0], &counters[0])
|
g.cipher.EncryptBlocks(mask, counters)
|
||||||
xor.XorBytes(out, in, mask[:blocks*gcmBlockSize])
|
xor.XorBytes(out, in, mask[:blocks*gcmBlockSize])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user