Skip to content

Commit ed8cbaf

Browse files
srinivas-pokalacherrymui
authored andcommitted
cmd/asm: add s390x crypto related instructions
This CL add's the following instructions,useful for cipher and message digest operations: * KM - cipher message * KMC - cipher message with chaining * KLMD - compute last message digest * KIMD - compute intermediate message digest Fixes #61163 Change-Id: Ib0636430c3e4888ed61b86c5acae45ee596463ff Reviewed-on: https://go-review.googlesource.com/c/go/+/509075 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Run-TryBot: Cherry Mui <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent fbf9076 commit ed8cbaf

File tree

9 files changed

+70
-10
lines changed

9 files changed

+70
-10
lines changed

src/cmd/asm/internal/asm/testdata/s390x.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,11 @@ TEXT main·foo(SB),DUPOK|NOSPLIT,$16-0 // TEXT main.foo(SB), DUPOK|NOSPLIT, $16-
415415

416416
SYNC // 07e0
417417

418+
KM R2, R4 // b92e0024
419+
KMC R2, R6 // b92f0026
420+
KLMD R2, R8 // b93f0028
421+
KIMD R0, R4 // b93e0004
422+
418423
// vector add and sub instructions
419424
VAB V3, V4, V4 // e743400000f3
420425
VAH V3, V4, V4 // e743400010f3

src/cmd/internal/obj/s390x/a.out.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,12 @@ const (
480480
// macros
481481
ACLEAR
482482

483+
// crypto
484+
AKM
485+
AKMC
486+
AKLMD
487+
AKIMD
488+
483489
// vector
484490
AVA
485491
AVAB

src/cmd/internal/obj/s390x/anames.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/internal/obj/s390x/asmz.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ var optab = []Optab{
339339
// 2 byte no-operation
340340
{i: 66, as: ANOPH},
341341

342+
// crypto instructions
343+
344+
// KM
345+
{i: 124, as: AKM, a1: C_REG, a6: C_REG},
346+
342347
// vector instructions
343348

344349
// VRX store
@@ -1480,6 +1485,10 @@ func buildop(ctxt *obj.Link) {
14801485
opset(AVFMSDB, r)
14811486
opset(AWFMSDB, r)
14821487
opset(AVPERM, r)
1488+
case AKM:
1489+
opset(AKMC, r)
1490+
opset(AKLMD, r)
1491+
opset(AKIMD, r)
14831492
}
14841493
}
14851494
}
@@ -4366,6 +4375,42 @@ func (c *ctxtz) asmout(p *obj.Prog, asm *[]byte) {
43664375
op, _, _ := vop(p.As)
43674376
m4 := c.regoff(&p.From)
43684377
zVRRc(op, uint32(p.To.Reg), uint32(p.Reg), uint32(p.GetFrom3().Reg), 0, 0, uint32(m4), asm)
4378+
4379+
case 124:
4380+
var opcode uint32
4381+
switch p.As {
4382+
default:
4383+
c.ctxt.Diag("unexpected opcode %v", p.As)
4384+
case AKM, AKMC, AKLMD:
4385+
if p.From.Reg == REG_R0 {
4386+
c.ctxt.Diag("input must not be R0 in %v", p)
4387+
}
4388+
if p.From.Reg&1 != 0 {
4389+
c.ctxt.Diag("input must be even register in %v", p)
4390+
}
4391+
if p.To.Reg == REG_R0 {
4392+
c.ctxt.Diag("second argument must not be R0 in %v", p)
4393+
}
4394+
if p.To.Reg&1 != 0 {
4395+
c.ctxt.Diag("second argument must be even register in %v", p)
4396+
}
4397+
if p.As == AKM {
4398+
opcode = op_KM
4399+
} else if p.As == AKMC {
4400+
opcode = op_KMC
4401+
} else {
4402+
opcode = op_KLMD
4403+
}
4404+
case AKIMD:
4405+
if p.To.Reg == REG_R0 {
4406+
c.ctxt.Diag("second argument must not be R0 in %v", p)
4407+
}
4408+
if p.To.Reg&1 != 0 {
4409+
c.ctxt.Diag("second argument must be even register in %v", p)
4410+
}
4411+
opcode = op_KIMD
4412+
}
4413+
zRRE(opcode, uint32(p.From.Reg), uint32(p.To.Reg), asm)
43694414
}
43704415
}
43714416

src/crypto/aes/asm_s390x.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ TEXT ·cryptBlocks(SB),NOSPLIT,$0-40
1212
MOVD length+32(FP), R5
1313
MOVD c+0(FP), R0
1414
loop:
15-
WORD $0xB92E0024 // cipher message (KM)
15+
KM R2, R4 // cipher message (KM)
1616
BVS loop // branch back if interrupted
1717
XOR R0, R0
1818
RET
@@ -29,7 +29,7 @@ TEXT ·cryptBlocksChain(SB),NOSPLIT,$48-48
2929
MOVD length+40(FP), R5
3030
MOVD c+0(FP), R0
3131
loop:
32-
WORD $0xB92F0024 // cipher message with chaining (KMC)
32+
KMC R2, R4 // cipher message with chaining (KMC)
3333
BVS loop // branch back if interrupted
3434
XOR R0, R0
3535
MVC $16, 0(R1), 0(R8) // update iv
@@ -145,7 +145,7 @@ TEXT ·ghash(SB),NOSPLIT,$32-40
145145
STMG R4, R7, (R1)
146146
LMG data+16(FP), R2, R3 // R2=base, R3=len
147147
loop:
148-
WORD $0xB93E0002 // compute intermediate message digest (KIMD)
148+
KIMD R0, R2 // compute intermediate message digest (KIMD)
149149
BVS loop // branch back if interrupted
150150
MVC $16, (R1), (R8)
151151
MOVD $0, R0

src/crypto/sha1/sha1block_s390x.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ TEXT ·block(SB), NOSPLIT|NOFRAME, $0-32
1212
CMPBEQ R4, $0, generic
1313

1414
loop:
15-
WORD $0xB93E0002 // KIMD R2
15+
KIMD R0, R2 // compute intermediate message digest (KIMD)
1616
BVS loop // continue if interrupted
1717
RET
1818

src/crypto/sha256/sha256block_s390x.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ TEXT ·block(SB), NOSPLIT|NOFRAME, $0-32
1212
CMPBEQ R4, $0, generic
1313

1414
loop:
15-
WORD $0xB93E0002 // KIMD R2
15+
KIMD R0, R2 // compute intermediate message digest (KIMD)
1616
BVS loop // continue if interrupted
1717
RET
1818

src/crypto/sha512/sha512block_s390x.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ TEXT ·block(SB), NOSPLIT|NOFRAME, $0-32
1212
CMPBEQ R4, $0, generic
1313

1414
loop:
15-
WORD $0xB93E0002 // KIMD R2
15+
KIMD R0, R2 // compute intermediate message digest (KIMD)
1616
BVS loop // continue if interrupted
1717
RET
1818

src/internal/cpu/cpu_s390x.s

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ TEXT ·stfle(SB), NOSPLIT|NOFRAME, $0-32
1616
TEXT ·kmQuery(SB), NOSPLIT|NOFRAME, $0-16
1717
MOVD $0, R0 // set function code to 0 (KM-Query)
1818
MOVD $ret+0(FP), R1 // address of 16-byte return value
19-
WORD $0xB92E0024 // cipher message (KM)
19+
KM R2, R4 // cipher message (KM)
2020
RET
2121

2222
// func kmcQuery() queryResult
2323
TEXT ·kmcQuery(SB), NOSPLIT|NOFRAME, $0-16
2424
MOVD $0, R0 // set function code to 0 (KMC-Query)
2525
MOVD $ret+0(FP), R1 // address of 16-byte return value
26-
WORD $0xB92F0024 // cipher message with chaining (KMC)
26+
KMC R2, R4 // cipher message with chaining (KMC)
2727
RET
2828

2929
// func kmctrQuery() queryResult
@@ -44,14 +44,14 @@ TEXT ·kmaQuery(SB), NOSPLIT|NOFRAME, $0-16
4444
TEXT ·kimdQuery(SB), NOSPLIT|NOFRAME, $0-16
4545
MOVD $0, R0 // set function code to 0 (KIMD-Query)
4646
MOVD $ret+0(FP), R1 // address of 16-byte return value
47-
WORD $0xB93E0024 // compute intermediate message digest (KIMD)
47+
KIMD R2, R4 // compute intermediate message digest (KIMD)
4848
RET
4949

5050
// func klmdQuery() queryResult
5151
TEXT ·klmdQuery(SB), NOSPLIT|NOFRAME, $0-16
5252
MOVD $0, R0 // set function code to 0 (KLMD-Query)
5353
MOVD $ret+0(FP), R1 // address of 16-byte return value
54-
WORD $0xB93F0024 // compute last message digest (KLMD)
54+
KLMD R2, R4 // compute last message digest (KLMD)
5555
RET
5656

5757
// func kdsaQuery() queryResult

0 commit comments

Comments
 (0)