Enable runtime override via FAT for gcm_aes_{de,en}crypt() on ppc ISA 3.0 (P9 and beyond) platforms.
Signed-off-by: Christopher M. Riedl cmr@linux.ibm.com --- fat-ppc.c | 33 +++++++++++++++++++++++++++ fat-setup.h | 6 +++++ gcm-internal.h | 14 ++++++++++++ powerpc64/fat/gcm-aes-decrypt.asm | 37 +++++++++++++++++++++++++++++++ powerpc64/fat/gcm-aes-encrypt.asm | 37 +++++++++++++++++++++++++++++++ 5 files changed, 127 insertions(+) create mode 100644 powerpc64/fat/gcm-aes-decrypt.asm create mode 100644 powerpc64/fat/gcm-aes-encrypt.asm
diff --git a/fat-ppc.c b/fat-ppc.c index 67ef46ab..9cc9d526 100644 --- a/fat-ppc.c +++ b/fat-ppc.c @@ -173,6 +173,14 @@ DECLARE_FAT_FUNC_VAR(gcm_init_key, gcm_init_key_func, ppc64) DECLARE_FAT_FUNC(_nettle_gcm_hash, gcm_hash_func) DECLARE_FAT_FUNC_VAR(gcm_hash, gcm_hash_func, c) DECLARE_FAT_FUNC_VAR(gcm_hash, gcm_hash_func, ppc64) + +DECLARE_FAT_FUNC(_nettle_gcm_aes_encrypt, gcm_aes_crypt_func) +DECLARE_FAT_FUNC_VAR(gcm_aes_encrypt, gcm_aes_crypt_func, c) +DECLARE_FAT_FUNC_VAR(gcm_aes_encrypt, gcm_aes_crypt_func, ppc64) + +DECLARE_FAT_FUNC(_nettle_gcm_aes_decrypt, gcm_aes_crypt_func) +DECLARE_FAT_FUNC_VAR(gcm_aes_decrypt, gcm_aes_crypt_func, c) +DECLARE_FAT_FUNC_VAR(gcm_aes_decrypt, gcm_aes_crypt_func, ppc64) #endif /* GCM_TABLE_BITS == 8 */
DECLARE_FAT_FUNC(_nettle_chacha_core, chacha_core_func) @@ -238,6 +246,20 @@ fat_init (void) nettle_chacha_crypt_vec = _nettle_chacha_crypt_1core; nettle_chacha_crypt32_vec = _nettle_chacha_crypt32_1core; } + if (features.have_isa_30) + { + if (verbose) + fprintf (stderr, "libnettle: enabling arch 3.0 code.\n"); +#if GCM_TABLE_BITS == 8 + _nettle_gcm_aes_encrypt_vec = _nettle_gcm_aes_encrypt_ppc64; + _nettle_gcm_aes_decrypt_vec = _nettle_gcm_aes_decrypt_ppc64; +#endif /* GCM_TABLE_BITS == 8 */ + } + else + { + _nettle_gcm_aes_encrypt_vec = _nettle_gcm_aes_encrypt_c; + _nettle_gcm_aes_decrypt_vec = _nettle_gcm_aes_decrypt_c; + } }
DEFINE_FAT_FUNC(_nettle_aes_encrypt, void, @@ -263,6 +285,17 @@ DEFINE_FAT_FUNC(_nettle_gcm_hash, void, (const struct gcm_key *key, union nettle_block16 *x, size_t length, const uint8_t *data), (key, x, length, data)) + +DEFINE_FAT_FUNC(_nettle_gcm_aes_encrypt, int, + (const struct gcm_key *key, union nettle_block16 *x, + size_t length, const uint8_t *src, unsigned rounds, + const uint32_t *keys, uint8_t *dst, uint8_t* ctr), + (key, x, length, src, rounds, keys, dst, ctr)) +DEFINE_FAT_FUNC(_nettle_gcm_aes_decrypt, int, + (const struct gcm_key *key, union nettle_block16 *x, + size_t length, const uint8_t *src, unsigned rounds, + const uint32_t *keys, uint8_t *dst, uint8_t* ctr), + (key, x, length, src, rounds, keys, dst, ctr)) #endif /* GCM_TABLE_BITS == 8 */
DEFINE_FAT_FUNC(_nettle_chacha_core, void, diff --git a/fat-setup.h b/fat-setup.h index 4e528d6b..70c271e5 100644 --- a/fat-setup.h +++ b/fat-setup.h @@ -194,3 +194,9 @@ typedef void chacha_crypt_func(struct chacha_ctx *ctx, size_t length, uint8_t *dst, const uint8_t *src); + +typedef int gcm_aes_crypt_func(const struct gcm_key *key, + union nettle_block16 *x, size_t length, + const uint8_t *src, unsigned rounds, + const uint32_t *keys, uint8_t *dst, + uint8_t* ctr); diff --git a/gcm-internal.h b/gcm-internal.h index 2e28be2d..63373d95 100644 --- a/gcm-internal.h +++ b/gcm-internal.h @@ -51,4 +51,18 @@ _nettle_gcm_hash_c (const struct gcm_key *key, union nettle_block16 *x, size_t length, const uint8_t *data); #endif
+#if HAVE_NATIVE_fat_gcm_aes_encrypt +int +_nettle_gcm_aes_encrypt_c (const struct gcm_key *key, union nettle_block16 *x, + size_t length, const uint8_t *src, unsigned rounds, + const uint32_t *keys, uint8_t *dst, uint8_t* ctr); +#endif + +#if HAVE_NATIVE_fat_gcm_aes_decrypt +int +_nettle_gcm_aes_decrypt_c (const struct gcm_key *key, union nettle_block16 *x, + size_t length, const uint8_t *src, unsigned rounds, + const uint32_t *keys, uint8_t *dst, uint8_t* ctr); +#endif + #endif /* NETTLE_GCM_INTERNAL_H_INCLUDED */ diff --git a/powerpc64/fat/gcm-aes-decrypt.asm b/powerpc64/fat/gcm-aes-decrypt.asm new file mode 100644 index 00000000..a6bd2e36 --- /dev/null +++ b/powerpc64/fat/gcm-aes-decrypt.asm @@ -0,0 +1,37 @@ +C powerpc64/fat/gcm-aes-decrypt.asm + +ifelse(` + Copyright (C) 2021 Christopher M. Riedl + + 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/. +') + +dnl picked up by configure +dnl PROLOGUE(_nettle_fat_gcm_aes_decrypt) + +define(`fat_transform', `$1_ppc64') +include_src(`powerpc64/p9/gcm-aes-decrypt.asm') diff --git a/powerpc64/fat/gcm-aes-encrypt.asm b/powerpc64/fat/gcm-aes-encrypt.asm new file mode 100644 index 00000000..1cffce9d --- /dev/null +++ b/powerpc64/fat/gcm-aes-encrypt.asm @@ -0,0 +1,37 @@ +C powerpc64/fat/gcm-aes-encrypt.asm + +ifelse(` + Copyright (C) 2021 Christopher M. Riedl + + 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/. +') + +dnl picked up by configure +dnl PROLOGUE(_nettle_fat_gcm_aes_encrypt) + +define(`fat_transform', `$1_ppc64') +include_src(`powerpc64/p9/gcm-aes-encrypt.asm')