github.com/4ad/go@v0.0.0-20161219182952-69a12818b605/src/crypto/aes/asm_s390x.s (about)

     1  // Copyright 2016 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  #include "textflag.h"
     6  
     7  // func hasAsm() bool
     8  TEXT ·hasAsm(SB),NOSPLIT,$16-1
     9  	XOR	R0, R0          // set function code to 0 (query)
    10  	LA	mask-16(SP), R1 // 16-byte stack variable for mask
    11  	MOVD	$(0x38<<40), R3 // mask for bits 18-20 (big endian)
    12  
    13  	// check for KM AES functions
    14  	WORD	$0xB92E0024 // cipher message (KM)
    15  	MOVD	mask-16(SP), R2
    16  	AND	R3, R2
    17  	CMPBNE	R2, R3, notfound
    18  
    19  	// check for KMC AES functions
    20  	WORD	$0xB92F0024 // cipher message with chaining (KMC)
    21  	MOVD	mask-16(SP), R2
    22  	AND	R3, R2
    23  	CMPBNE	R2, R3, notfound
    24  
    25  	MOVB	$1, ret+0(FP)
    26  	RET
    27  notfound:
    28  	MOVB	$0, ret+0(FP)
    29  	RET
    30  
    31  // func cryptBlocks(function code, key, dst, src *byte, length int)
    32  TEXT ·cryptBlocks(SB),NOSPLIT,$0-40
    33  	MOVD	key+8(FP), R1
    34  	MOVD	dst+16(FP), R2
    35  	MOVD	src+24(FP), R4
    36  	MOVD	length+32(FP), R5
    37  	MOVD	function+0(FP), R0
    38  loop:
    39  	WORD	$0xB92E0024 // cipher message (KM)
    40  	BVS	loop        // branch back if interrupted
    41  	XOR	R0, R0
    42  	RET
    43  
    44  // func cryptBlocksChain(function code, iv, key, dst, src *byte, length int)
    45  TEXT ·cryptBlocksChain(SB),NOSPLIT,$48-48
    46  	LA	params-48(SP), R1
    47  	MOVD	iv+8(FP), R8
    48  	MOVD	key+16(FP), R9
    49  	MVC	$16, 0(R8), 0(R1)  // move iv into params
    50  	MVC	$32, 0(R9), 16(R1) // move key into params
    51  	MOVD	dst+24(FP), R2
    52  	MOVD	src+32(FP), R4
    53  	MOVD	length+40(FP), R5
    54  	MOVD	function+0(FP), R0
    55  loop:
    56  	WORD	$0xB92F0024       // cipher message with chaining (KMC)
    57  	BVS	loop              // branch back if interrupted
    58  	XOR	R0, R0
    59  	MVC	$16, 0(R1), 0(R8) // update iv
    60  	RET
    61  
    62  // func xorBytes(dst, a, b []byte) int
    63  TEXT ·xorBytes(SB),NOSPLIT,$0-80
    64  	MOVD	dst_base+0(FP), R1
    65  	MOVD	a_base+24(FP), R2
    66  	MOVD	b_base+48(FP), R3
    67  	MOVD	a_len+32(FP), R4
    68  	MOVD	b_len+56(FP), R5
    69  	CMPBLE	R4, R5, skip
    70  	MOVD	R5, R4
    71  skip:
    72  	MOVD	R4, ret+72(FP)
    73  	MOVD	$0, R5
    74  	CMPBLT	R4, $8, tail
    75  loop:
    76  	MOVD	0(R2)(R5*1), R7
    77  	MOVD	0(R3)(R5*1), R8
    78  	XOR	R7, R8
    79  	MOVD	R8, 0(R1)(R5*1)
    80  	LAY	8(R5), R5
    81  	SUB	$8, R4
    82  	CMPBGE	R4, $8, loop
    83  tail:
    84  	CMPBEQ	R4, $0, done
    85  	MOVB	0(R2)(R5*1), R7
    86  	MOVB	0(R3)(R5*1), R8
    87  	XOR	R7, R8
    88  	MOVB	R8, 0(R1)(R5*1)
    89  	LAY	1(R5), R5
    90  	SUB	$1, R4
    91  	BR	tail
    92  done:
    93  	RET