diff options
author | mamonet <maamoun.tk@gmail.com> | 2021-04-05 23:41:00 +0300 |
---|---|---|
committer | mamonet <maamoun.tk@gmail.com> | 2021-04-05 23:41:00 +0300 |
commit | 4651503844c1e0264ece32160c1c3bfd585b162e (patch) | |
tree | 8c3bc7123cf6ecd04c02e1151f2a1b9dc3ed93fe | |
parent | f4dc5f208135f73b15c46bd4b52e3c71939fa090 (diff) | |
download | nettle-4651503844c1e0264ece32160c1c3bfd585b162e.tar.gz |
[S390x] Basic AES-128 optimization
-rw-r--r-- | Makefile.in | 2 | ||||
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | s390x/machine.m4 | 2 | ||||
-rw-r--r-- | s390x/msa_x1/aes128-decrypt.asm | 60 | ||||
-rw-r--r-- | s390x/msa_x1/aes128-encrypt.asm | 60 | ||||
-rw-r--r-- | s390x/msa_x1/aes128-set-decrypt-key.asm | 52 | ||||
-rw-r--r-- | s390x/msa_x1/aes128-set-encrypt-key.asm | 43 |
7 files changed, 222 insertions, 1 deletions
diff --git a/Makefile.in b/Makefile.in index 8d474d1e..74a1a7e7 100644 --- a/Makefile.in +++ b/Makefile.in @@ -620,7 +620,7 @@ distdir: $(DISTFILES) arm arm/neon arm/v6 arm/fat \ arm64 arm64/crypto arm64/fat \ powerpc64 powerpc64/p7 powerpc64/p8 powerpc64/fat \ - s390x ; do \ + s390x s390x/msa_x1 ; do \ mkdir "$(distdir)/$$d" ; \ find "$(srcdir)/$$d" -maxdepth 1 '(' -name '*.asm' -o -name '*.m4' -o -name README ')' \ -exec cp '{}' "$(distdir)/$$d" ';' ; \ diff --git a/configure.ac b/configure.ac index be2916c1..cc85340e 100644 --- a/configure.ac +++ b/configure.ac @@ -553,6 +553,10 @@ asm_replace_list="aes-encrypt-internal.asm aes-decrypt-internal.asm \ sha1-compress.asm sha256-compress.asm sha512-compress.asm \ sha3-permute.asm umac-nh.asm umac-nh-n.asm machine.m4" +# Files which replace a C source file that used by S390x architecture. +asm_replace_list="$asm_replace_list aes128-set-encrypt-key.asm \ + aes128-set-decrypt-key.asm aes128-encrypt.asm aes128-decrypt.asm" + # Assembler files which generate additional object files if they are used. asm_nettle_optional_list="gcm-hash.asm gcm-hash8.asm cpuid.asm \ aes-encrypt-internal-2.asm aes-decrypt-internal-2.asm memxor-2.asm \ diff --git a/s390x/machine.m4 b/s390x/machine.m4 new file mode 100644 index 00000000..acd5e26c --- /dev/null +++ b/s390x/machine.m4 @@ -0,0 +1,2 @@ +C Register usage: +define(`RA', `%r14') diff --git a/s390x/msa_x1/aes128-decrypt.asm b/s390x/msa_x1/aes128-decrypt.asm new file mode 100644 index 00000000..25f826c4 --- /dev/null +++ b/s390x/msa_x1/aes128-decrypt.asm @@ -0,0 +1,60 @@ +C s390x/msa_x1/aes128-decrypt.asm + +ifelse(` + Copyright (C) 2020 Mamone Tarsha + This file is part of GNU Nettle. + + GNU Nettle is free software: you can redistribute it and/or + modify it under the terms of either: + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at your + option) any later version. + + or + + * the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at your + option) any later version. + + or both in parallel, as here. + + GNU Nettle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received copies of the GNU General Public License and + the GNU Lesser General Public License along with this program. If + not, see http://www.gnu.org/licenses/. +') + +C KM (CIPHER MESSAGE) is specefied in "z/Architecture Principles of Operation SA22-7832-12" as follows: +C A function specified by the function code in general register 0 is performed. +C General register 1 contains the logical address of the leftmost byte of the parameter block in storage. +C The second operand is ciphered as specified by the function code using a cryptographic +C key in the parameter block, and the result is placed in the first-operand location. + +C This implementation uses KM-AES-128 function. +C The parameter block used for the KM-AES-128 function has the following format: +C *----------------------------------------------* +C | Cryptographic Key (16 bytes) | +C *----------------------------------------------* + +.file "aes128-decrypt.asm" + +.text + +C void +C aes128_decrypt(const struct aes128_ctx *ctx, +C size_t length, uint8_t *dst, +C const uint8_t *src) + +PROLOGUE(nettle_aes128_decrypt) + lghi %r0,128|18 C KM function code (KM-AES-128), enable modifier bit to perform decryption operation + lgr %r1,%r2 C parameter block: byte offsets 0-15 Cryptographic Key + lgr %r2,%r5 +1: .long 0xb92e0042 C km %r4,%r2 + brc 1,1b C safely branch back in case of partial completion + br RA +EPILOGUE(nettle_aes128_decrypt) diff --git a/s390x/msa_x1/aes128-encrypt.asm b/s390x/msa_x1/aes128-encrypt.asm new file mode 100644 index 00000000..f8e87377 --- /dev/null +++ b/s390x/msa_x1/aes128-encrypt.asm @@ -0,0 +1,60 @@ +C s390x/msa_x1/aes128-encrypt.asm + +ifelse(` + Copyright (C) 2020 Mamone Tarsha + This file is part of GNU Nettle. + + GNU Nettle is free software: you can redistribute it and/or + modify it under the terms of either: + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at your + option) any later version. + + or + + * the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at your + option) any later version. + + or both in parallel, as here. + + GNU Nettle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received copies of the GNU General Public License and + the GNU Lesser General Public License along with this program. If + not, see http://www.gnu.org/licenses/. +') + +C KM (CIPHER MESSAGE) is specefied in "z/Architecture Principles of Operation SA22-7832-12" as follows: +C A function specified by the function code in general register 0 is performed. +C General register 1 contains the logical address of the leftmost byte of the parameter block in storage. +C The second operand is ciphered as specified by the function code using a cryptographic +C key in the parameter block, and the result is placed in the first-operand location. + +C This implementation uses KM-AES-128 function. +C The parameter block used for the KM-AES-128 function has the following format: +C *----------------------------------------------* +C | Cryptographic Key (16 bytes) | +C *----------------------------------------------* + +.file "aes128-encrypt.asm" + +.text + +C void +C aes128_encrypt(const struct aes128_ctx *ctx, +C size_t length, uint8_t *dst, +C const uint8_t *src) + +PROLOGUE(nettle_aes128_encrypt) + lghi %r0,18 C KM function code (KM-AES-128) + lgr %r1,%r2 C parameter block: byte offsets 0-15 Cryptographic Key + lgr %r2,%r5 +1: .long 0xb92e0042 C km %r4,%r2 + brc 1,1b C safely branch back in case of partial completion + br RA +EPILOGUE(nettle_aes128_encrypt) diff --git a/s390x/msa_x1/aes128-set-decrypt-key.asm b/s390x/msa_x1/aes128-set-decrypt-key.asm new file mode 100644 index 00000000..1312c3c0 --- /dev/null +++ b/s390x/msa_x1/aes128-set-decrypt-key.asm @@ -0,0 +1,52 @@ +C s390x/msa_x1/aes128-set-decrypt-key.asm + +ifelse(` + Copyright (C) 2020 Mamone Tarsha + This file is part of GNU Nettle. + + GNU Nettle is free software: you can redistribute it and/or + modify it under the terms of either: + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at your + option) any later version. + + or + + * the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at your + option) any later version. + + or both in parallel, as here. + + GNU Nettle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received copies of the GNU General Public License and + the GNU Lesser General Public License along with this program. If + not, see http://www.gnu.org/licenses/. +') + +.file "aes128-set-decrypt-key.asm" + +.text + +C void +C aes128_invert_key(struct aes128_ctx *dst, const struct aes128_ctx *src) + +PROLOGUE(nettle_aes128_invert_key) + C AES cipher functions only need the raw cryptographic key so just copy it to AES context + mvc 0(16,%r2),0(%r3) C copy Cryptographic Key (16 bytes) + br RA +EPILOGUE(nettle_aes128_invert_key) + +C void +C aes128_set_decrypt_key(struct aes128_ctx *ctx, const uint8_t *key) + +PROLOGUE(nettle_aes128_set_decrypt_key) + C AES cipher functions only need the raw cryptographic key so just copy it to AES context + mvc 0(16,%r2),0(%r3) C copy Cryptographic Key (16 bytes) + br RA +EPILOGUE(nettle_aes128_set_decrypt_key) diff --git a/s390x/msa_x1/aes128-set-encrypt-key.asm b/s390x/msa_x1/aes128-set-encrypt-key.asm new file mode 100644 index 00000000..0fa703cf --- /dev/null +++ b/s390x/msa_x1/aes128-set-encrypt-key.asm @@ -0,0 +1,43 @@ +C s390x/msa_x1/aes128-set-encrypt-key.asm + +ifelse(` + Copyright (C) 2020 Mamone Tarsha + This file is part of GNU Nettle. + + GNU Nettle is free software: you can redistribute it and/or + modify it under the terms of either: + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at your + option) any later version. + + or + + * the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at your + option) any later version. + + or both in parallel, as here. + + GNU Nettle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received copies of the GNU General Public License and + the GNU Lesser General Public License along with this program. If + not, see http://www.gnu.org/licenses/. +') + +.file "aes128-set-encrypt-key.asm" + +.text + +C void +C aes128_set_encrypt_key(struct aes128_ctx *ctx, const uint8_t *key) + +PROLOGUE(nettle_aes128_set_encrypt_key) + C AES cipher functions only need the raw cryptographic key so just copy it to AES context + mvc 0(16,%r2),0(%r3) C copy Cryptographic Key (16 bytes) + br RA +EPILOGUE(nettle_aes128_set_encrypt_key) |