MAGIC - avoid nil message passed in

This commit is contained in:
Emman 2021-03-24 16:20:01 +08:00
parent 14cafa5e9e
commit c3f59f3e7b
2 changed files with 11 additions and 29 deletions

View File

@ -189,6 +189,9 @@ func calculateC3(curve elliptic.Curve, x2, y2 *big.Int, msg []byte) []byte {
func Encrypt(random io.Reader, pub *ecdsa.PublicKey, msg []byte, opts *EncrypterOpts) ([]byte, error) { func Encrypt(random io.Reader, pub *ecdsa.PublicKey, msg []byte, opts *EncrypterOpts) ([]byte, error) {
curve := pub.Curve curve := pub.Curve
msgLen := len(msg) msgLen := len(msg)
if msgLen == 0 {
return nil, nil
}
if opts == nil { if opts == nil {
opts = &defaultEncrypterOpts opts = &defaultEncrypterOpts
} }

View File

@ -56,21 +56,9 @@ DATA r24_mask<>+0x00(SB)/8, $0x0407060500030201
DATA r24_mask<>+0x08(SB)/8, $0x0C0F0E0D080B0A09 DATA r24_mask<>+0x08(SB)/8, $0x0C0F0E0D080B0A09
GLOBL r24_mask<>(SB), RODATA, $16 GLOBL r24_mask<>(SB), RODATA, $16
DATA fk00_mask<>+0x00(SB)/8, $0xa3b1bac6a3b1bac6 DATA fk_mask<>+0x00(SB)/8, $0x56aa3350a3b1bac6
DATA fk00_mask<>+0x08(SB)/8, $0xa3b1bac6a3b1bac6 DATA fk_mask<>+0x08(SB)/8, $0xb27022dc677d9197
GLOBL fk00_mask<>(SB), RODATA, $16 GLOBL fk_mask<>(SB), RODATA, $16
DATA fk01_mask<>+0x00(SB)/8, $0x56aa335056aa3350
DATA fk01_mask<>+0x08(SB)/8, $0x56aa335056aa3350
GLOBL fk01_mask<>(SB), RODATA, $16
DATA fk02_mask<>+0x00(SB)/8, $0x677d9197677d9197
DATA fk02_mask<>+0x08(SB)/8, $0x677d9197677d9197
GLOBL fk02_mask<>(SB), RODATA, $16
DATA fk03_mask<>+0x00(SB)/8, $0xb27022dcb27022dc
DATA fk03_mask<>+0x08(SB)/8, $0xb27022dcb27022dc
GLOBL fk03_mask<>(SB), RODATA, $16
#define SM4_SBOX(x, y) \ #define SM4_SBOX(x, y) \
; \ //############################# inner affine ############################// ; \ //############################# inner affine ############################//
@ -139,21 +127,12 @@ TEXT ·expandKeyAsm(SB),NOSPLIT,$0
MOVQ enc+16(FP), DX MOVQ enc+16(FP), DX
MOVQ dec+24(FP), DI MOVQ dec+24(FP), DI
PINSRD $0, 0(AX), t0 MOVUPS 0(AX), t0
PSHUFB flip_mask<>(SB), t0 PSHUFB flip_mask<>(SB), t0
PXOR fk00_mask<>(SB), t0 PXOR fk_mask<>(SB), t0
PSHUFD $1, t0, t1
PINSRD $0, 4(AX), t1 PSHUFD $2, t0, t2
PSHUFB flip_mask<>(SB), t1 PSHUFD $3, t0, t3
PXOR fk01_mask<>(SB), t1
PINSRD $0, 8(AX), t2
PSHUFB flip_mask<>(SB), t2
PXOR fk02_mask<>(SB), t2
PINSRD $0, 12(AX), t3
PSHUFB flip_mask<>(SB), t3
PXOR fk03_mask<>(SB), t3
XORL CX, CX XORL CX, CX
MOVL $112, SI MOVL $112, SI