]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
[S390x] Basic AES-128 optimization
authormamonet <maamoun.tk@gmail.com>
Mon, 5 Apr 2021 20:41:00 +0000 (23:41 +0300)
committermamonet <maamoun.tk@gmail.com>
Mon, 5 Apr 2021 20:41:00 +0000 (23:41 +0300)
Makefile.in
configure.ac
s390x/machine.m4 [new file with mode: 0644]
s390x/msa_x1/aes128-decrypt.asm [new file with mode: 0644]
s390x/msa_x1/aes128-encrypt.asm [new file with mode: 0644]
s390x/msa_x1/aes128-set-decrypt-key.asm [new file with mode: 0644]
s390x/msa_x1/aes128-set-encrypt-key.asm [new file with mode: 0644]

index 8d474d1e27925ca039ea7ced87161a0c36919b28..74a1a7e7dbb481687e1693458a45b54362663e56 100644 (file)
@@ -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" ';' ; \
index be2916c15e8f2100e8989eb41c88325a752100cf..cc85340e4644404f417aae6f7410f4ebf0074550 100644 (file)
@@ -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 (file)
index 0000000..acd5e26
--- /dev/null
@@ -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 (file)
index 0000000..25f826c
--- /dev/null
@@ -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 (file)
index 0000000..f8e8737
--- /dev/null
@@ -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 (file)
index 0000000..1312c3c
--- /dev/null
@@ -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 (file)
index 0000000..0fa703c
--- /dev/null
@@ -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)