Commit bc4e831c authored by Patrick Steuer's avatar Patrick Steuer Committed by Andy Polyakov
Browse files

s390x assembly pack: extend s390x capability vector.



Extend the s390x capability vector to store the longer facility list
available from z13 onwards. The bits indicating the vector extensions
are set to zero, if the kernel does not enable the vector facility.

Also add capability bits returned by the crypto instructions' query
functions.

Signed-off-by: default avatarPatrick Steuer <patrick.steuer@de.ibm.com>

Reviewed-by: default avatarAndy Polyakov <appro@openssl.org>
Reviewed-by: default avatarTim Hudson <tjh@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4542)
parent 7a908204
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -129,6 +129,8 @@ sub _data_word()
}

$code=<<___;
#include "s390x_arch.h"

.text

.type	AES_Te,\@object
@@ -823,8 +825,8 @@ $code.=<<___ if (!$softonly);
	larl	%r1,OPENSSL_s390xcap_P
	llihh	%r0,0x8000
	srlg	%r0,%r0,0(%r5)
	ng	%r0,32(%r1)	# check availability of both km...
	ng	%r0,48(%r1)	# ...and kmc support for given key length
	ng	%r0,S390X_KM(%r1)  # check availability of both km...
	ng	%r0,S390X_KMC(%r1) # ...and kmc support for given key length
	jz	.Lekey_internal

	lmg	%r0,%r1,0($inp)	# just copy 128 bits...
@@ -1442,7 +1444,7 @@ $code.=<<___ if (!$softonly && 0);# kmctr code was measured to be ~12% slower
	larl	%r1,OPENSSL_s390xcap_P
	llihh	%r0,0x8000	# check if kmctr supports the function code
	srlg	%r0,%r0,0($s0)
	ng	%r0,64(%r1)	# check kmctr capability vector
	ng	%r0,S390X_KMCTR(%r1)	# check kmctr capability vector
	lgr	%r0,$s0
	lgr	%r1,$s1
	jz	.Lctr32_km_loop
@@ -1592,7 +1594,7 @@ $code.=<<___ if(1);
	larl	%r1,OPENSSL_s390xcap_P
	llihh	%r0,0x8000
	srlg	%r0,%r0,32($s1)		# check for 32+function code
	ng	%r0,32(%r1)		# check km capability vector
	ng	%r0,S390X_KM(%r1)	# check km capability vector
	lgr	%r0,$s0			# restore the function code
	la	%r1,0($key1)		# restore $key1
	jz	.Lxts_km_vanilla
@@ -2219,7 +2221,6 @@ ___
}
$code.=<<___;
.string	"AES for s390x, CRYPTOGAMS by <appro\@openssl.org>"
.comm	OPENSSL_s390xcap_P,80,8
___

$code =~ s/\`([^\`]*)\`/eval $1/gem;
+3 −0
Original line number Diff line number Diff line
@@ -46,6 +46,9 @@ INCLUDE[aes-armv4.o]=..
GENERATE[bsaes-armv7.S]=asm/bsaes-armv7.pl $(PERLASM_SCHEME)
INCLUDE[bsaes-armv7.o]=..

GENERATE[aes-s390x.S]=asm/aes-s390x.pl $(PERLASM_SCHEME)
INCLUDE[aes-s390x.o]=..

BEGINRAW[Makefile]
##### AES assembler implementations

+8 −4
Original line number Diff line number Diff line
@@ -80,6 +80,8 @@ $rem_4bit="%r14";
$sp="%r15";

$code.=<<___;
#include "s390x_arch.h"

.text

.globl	gcm_gmult_4bit
@@ -89,12 +91,13 @@ ___
$code.=<<___ if(!$softonly && 0);	# hardware is slow for single block...
	larl	%r1,OPENSSL_s390xcap_P
	lghi	%r0,0
	lg	%r1,24(%r1)	# load second word of kimd capabilities vector
	lg	%r1,S390X_KIMD+8(%r1)	# load second word of kimd capabilities
					#  vector
	tmhh	%r1,0x4000	# check for function 65
	jz	.Lsoft_gmult
	stg	%r0,16($sp)	# arrange 16 bytes of zero input
	stg	%r0,24($sp)
	lghi	%r0,65		# function 65
	lghi	%r0,S390X_GHASH	# function 65
	la	%r1,0($Xi)	# H lies right after Xi in gcm128_context
	la	$inp,16($sp)
	lghi	$len,16
@@ -123,10 +126,11 @@ gcm_ghash_4bit:
___
$code.=<<___ if(!$softonly);
	larl	%r1,OPENSSL_s390xcap_P
	lg	%r0,24(%r1)	# load second word of kimd capabilities vector
	lg	%r0,S390X_KIMD+8(%r1)	# load second word of kimd capabilities
					#  vector
	tmhh	%r0,0x4000	# check for function 65
	jz	.Lsoft_ghash
	lghi	%r0,65		# function 65
	lghi	%r0,S390X_GHASH	# function 65
	la	%r1,0($Xi)	# H lies right after Xi in gcm128_context
	.long	0xb93e0004	# kimd %r0,$inp
	brc	1,.-4		# pay attention to "partial completion"
+2 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ GENERATE[ghash-armv4.S]=asm/ghash-armv4.pl $(PERLASM_SCHEME)
INCLUDE[ghash-armv4.o]=..
GENERATE[ghashv8-armx.S]=asm/ghashv8-armx.pl $(PERLASM_SCHEME)
INCLUDE[ghashv8-armx.o]=..
GENERATE[ghash-s390x.S]=asm/ghash-s390x.pl $(PERLASM_SCHEME)
INCLUDE[ghash-s390x.o]=..

BEGINRAW[Makefile]
# GNU make "catch all"

crypto/s390x_arch.h

0 → 100644
+82 −0
Original line number Diff line number Diff line
/*
 * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
 *
 * Licensed under the OpenSSL license (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
 */

#ifndef S390X_ARCH_H
# define S390X_ARCH_H

# ifndef __ASSEMBLER__

/*
 * The field elements of OPENSSL_s390xcap_P are the 64-bit words returned by
 * the STFLE instruction followed by the 64-bit word pairs returned by
 * instructions' QUERY functions. If STFLE returns fewer data or an instruction
 * is not supported, the corresponding field elements are zero.
 */
struct OPENSSL_s390xcap_st {
    unsigned long long stfle[4];
    unsigned long long kimd[2];
    unsigned long long klmd[2];
    unsigned long long km[2];
    unsigned long long kmc[2];
    unsigned long long kmac[2];
    unsigned long long kmctr[2];
    unsigned long long kmo[2];
    unsigned long long kmf[2];
    unsigned long long prno[2];
    unsigned long long kma[2];
};

extern struct OPENSSL_s390xcap_st OPENSSL_s390xcap_P;

/* convert facility bit number or function code to bit mask */
#  define S390X_CAPBIT(i)	(1ULL << (63 - (i) % 64))

# endif

/* OPENSSL_s390xcap_P offsets [bytes] */
# define S390X_STFLE		0x00
# define S390X_KIMD		0x20
# define S390X_KLMD		0x30
# define S390X_KM		0x40
# define S390X_KMC		0x50
# define S390X_KMAC		0x60
# define S390X_KMCTR		0x70
# define S390X_KMO		0x80
# define S390X_KMF		0x90
# define S390X_PRNO		0xa0
# define S390X_KMA		0xb0

/* Facility Bit Numbers */
# define S390X_VX		129
# define S390X_VXD		134
# define S390X_VXE		135

/* Function Codes */

/* all instructions */
# define S390X_QUERY		0

/* kimd/klmd */
# define S390X_SHA3_224		32
# define S390X_SHA3_256		33
# define S390X_SHA3_384		34
# define S390X_SHA3_512		35
# define S390X_SHAKE_128	36
# define S390X_SHAKE_256	37
# define S390X_GHASH		65

/* km/kmc/kmac/kmctr/kmo/kmf/kma */
# define S390X_AES_128		18
# define S390X_AES_192		19
# define S390X_AES_256		20

/* prno */
# define S390X_TRNG		114

#endif
Loading