Skip to content

Commit

Permalink
move amd64 code for generic AES functions to separate files
Browse files Browse the repository at this point in the history
This commit moves AMD64 code for generic AES functions - like
key-schedule and encrypting 128 bit blocks to separate files:
 - aes_amd64.go
 - aes_amd64.s
  • Loading branch information
Andreas Auernhammer committed Sep 22, 2018
1 parent 12a3f3b commit 339dd21
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 32 deletions.
14 changes: 14 additions & 0 deletions aes_amd64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) 2018 Andreas Auernhammer. All rights reserved.
// Use of this source code is governed by a license that can be
// found in the LICENSE file.

// +build amd64,!gccgo,!appengine

package siv

// keySchedule performs an AES key-schedule and is implemented in aes_amd64.s
func keySchedule(keys, key []byte)

// encryptBlock encrypts one 128 bit block from src to dst using AES and is
// implemented in aes_amd64.s
func encryptBlock(dst, src, keys []byte, keyLen uint64)
63 changes: 63 additions & 0 deletions aes_amd64.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) 2018 Andreas Auernhammer. All rights reserved.
// Use of this source code is governed by a license that can be
// found in the LICENSE file.

// +build amd64,!gccgo,!appengine

#include "aes_macros_amd64.s"

// func keySchedule(keys []uint32, key []byte)
TEXT ·keySchedule(SB), 4, $0-48
MOVQ keys+0(FP), AX
MOVQ key+24(FP), BX
MOVQ keyLen+32(FP), DX

CMPQ DX, $24
JE aes_192
JB aes_128

aes_256:
MOVUPS (0 * 16)(BX), X0
MOVUPS (1 * 16)(BX), X1
AES_KEY_SCHEDULE_256(AX, X0, X1, X2, X3)
JMP return

aes_192:
MOVUPS (0 * 16)(BX), X0
MOVQ (1 * 16)(BX), X1
AES_KEY_SCHEDULE_192(AX, X0, X1, X2, X3, X4, X5, X6)
JMP return

aes_128:
MOVUPS (0 * 16)(BX), X0
AES_KEY_SCHEDULE_128(AX, X0, X1, X2)

return:
RET

// func encryptBlock(dst, src, keys []byte, keyLen uint64)
TEXT ·encryptBlock(SB), 4, $0-80
MOVQ dst+0(FP), DI
MOVQ src+24(FP), SI
MOVQ keys+48(FP), AX
MOVQ keyLen+72(FP), DX

MOVUPS (0 * 16)(SI), X0
CMPQ DX, $24
JE aes_192
JB aes_128

aes_256:
AES_256(X0, X1, AX)
JMP return

aes_192:
AES_192(X0, X1, AX)
JMP return

aes_128:
AES_128(X0, X1, AX)

return:
MOVUPS X0, (0 * 16)(DI)
RET
2 changes: 0 additions & 2 deletions aes_cmac_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
"golang.org/x/sys/cpu"
)

func keySchedule(keys, key []byte)

func aesCMacXORKeyStream(dst, src, iv, keys []byte, keyLen uint64)

func newCMAC(key []byte) aead {
Expand Down
30 changes: 0 additions & 30 deletions aes_cmac_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

// +build amd64,!gccgo,!appengine

#include "textflag.h"
#include "aes_macros_amd64.s"

#define LOAD_COUNTER(C, c0, c1, T) \
Expand All @@ -21,35 +20,6 @@
BSWAPQ c1; \
BSWAPQ c0

// func keySchedule(keys []uint32, key []byte)
TEXT ·keySchedule(SB), 4, $0-48
MOVQ keys+0(FP), AX
MOVQ key+24(FP), BX
MOVQ keyLen+32(FP), DX

CMPQ DX, $24
JE aes_192
JB aes_128

aes_256:
MOVUPS (0 * 16)(BX), X0
MOVUPS (1 * 16)(BX), X1
AES_KEY_SCHEDULE_256(AX, X0, X1, X2, X3)
JMP return

aes_192:
MOVUPS (0 * 16)(BX), X0
MOVQ (1 * 16)(BX), X1
AES_KEY_SCHEDULE_192(AX, X0, X1, X2, X3, X4, X5, X6)
JMP return

aes_128:
MOVUPS (0 * 16)(BX), X0
AES_KEY_SCHEDULE_128(AX, X0, X1, X2)

return:
RET

// func aesCMacXORKeyStream(dst, src, iv, keys []byte, keyLen uint64)
TEXT ·aesCMacXORKeyStream(SB), 4, $0-104
MOVQ dst+0(FP), DI
Expand Down

0 comments on commit 339dd21

Please sign in to comment.