From: Niels Möller Date: Thu, 14 Mar 2024 20:29:50 +0000 (+0100) Subject: Add gcm-internal.h, declaring _gcm_aes_encrypt and _gcm_aes_decrypt. X-Git-Tag: nettle_3.10rc1~16^2~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=08b61857cde132ff9eb37e5931edd10f4fd02864;p=thirdparty%2Fnettle.git Add gcm-internal.h, declaring _gcm_aes_encrypt and _gcm_aes_decrypt. Change type of the rounds argument from size_t to unsigned. --- diff --git a/Makefile.in b/Makefile.in index ea093c00..145ec299 100644 --- a/Makefile.in +++ b/Makefile.in @@ -271,7 +271,7 @@ DISTFILES = $(SOURCES) $(HEADERS) getopt.h getopt_int.h \ nettle.pc.in hogweed.pc.in \ desdata.stamp $(des_headers) descore.README \ aes-internal.h block-internal.h blowfish-internal.h bswap-internal.h \ - camellia-internal.h \ + camellia-internal.h gcm-internal.h \ ghash-internal.h gost28147-internal.h poly1305-internal.h \ serpent-internal.h cast128_sboxes.h desinfo.h desCode.h \ ripemd160-internal.h md-internal.h sha2-internal.h \ diff --git a/fat-ppc.c b/fat-ppc.c index 70d8072e..ec6d200e 100644 --- a/fat-ppc.c +++ b/fat-ppc.c @@ -175,13 +175,13 @@ DECLARE_FAT_FUNC(_nettle_ghash_update, ghash_update_func) DECLARE_FAT_FUNC_VAR(ghash_update, ghash_update_func, c) DECLARE_FAT_FUNC_VAR(ghash_update, ghash_update_func, ppc64) -DECLARE_FAT_FUNC(_nettle_gcm_aes_encrypt, gcm_aes_encrypt_func) -DECLARE_FAT_FUNC_VAR(gcm_aes_encrypt, gcm_aes_encrypt_func, c) -DECLARE_FAT_FUNC_VAR(gcm_aes_encrypt, gcm_aes_encrypt_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_decrypt_func) -DECLARE_FAT_FUNC_VAR(gcm_aes_decrypt, gcm_aes_decrypt_func, c) -DECLARE_FAT_FUNC_VAR(gcm_aes_decrypt, gcm_aes_decrypt_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) DECLARE_FAT_FUNC(_nettle_chacha_core, chacha_core_func) DECLARE_FAT_FUNC_VAR(chacha_core, chacha_core_func, c); @@ -312,12 +312,12 @@ DEFINE_FAT_FUNC(_nettle_ghash_update, const uint8_t *, (ctx, state, blocks, data)) DEFINE_FAT_FUNC(_nettle_gcm_aes_encrypt, size_t, - (struct gcm_key *key, size_t rounds, + (struct gcm_key *key, unsigned rounds, size_t len, uint8_t *dst, const uint8_t *src), (key, rounds, len, dst, src)) DEFINE_FAT_FUNC(_nettle_gcm_aes_decrypt, size_t, - (struct gcm_key *key, size_t rounds, + (struct gcm_key *key, unsigned rounds, size_t len, uint8_t *dst, const uint8_t *src), (key, rounds, len, dst, src)) diff --git a/fat-setup.h b/fat-setup.h index c665e157..37a600a8 100644 --- a/fat-setup.h +++ b/fat-setup.h @@ -171,11 +171,8 @@ ghash_update_func (const struct gcm_key *ctx, union nettle_block16 *state, size_t blocks, const uint8_t *data); typedef size_t -gcm_aes_encrypt_func (struct gcm_key *key, size_t rounds, - size_t len, uint8_t *dst, const uint8_t *src); -typedef size_t -gcm_aes_decrypt_func (struct gcm_key *key, size_t rounds, - size_t len, uint8_t *dst, const uint8_t *src); +gcm_aes_crypt_func (struct gcm_key *key, unsigned rounds, + size_t len, uint8_t *dst, const uint8_t *src); typedef void *(memxor_func)(void *dst, const void *src, size_t n); typedef void *(memxor3_func)(void *dst_in, const void *a_in, const void *b_in, size_t n); diff --git a/gcm-aes-crypt.c b/gcm-aes-crypt.c index 675ee6b0..3b55c5ca 100644 --- a/gcm-aes-crypt.c +++ b/gcm-aes-crypt.c @@ -38,31 +38,32 @@ #include #include "gcm.h" +#include "gcm-internal.h" /* For fat builds */ #if HAVE_NATIVE_gcm_aes_encrypt size_t -_gcm_aes_encrypt (struct gcm_key *key, size_t rounds, +_gcm_aes_encrypt (struct gcm_key *key, unsigned rounds, size_t len, uint8_t *dst, const uint8_t *src); #define _nettle_gcm_aes_encrypt _nettle_gcm_aes_encrypt_c #endif #if HAVE_NATIVE_gcm_aes_decrypt size_t -_gcm_aes_decrypt (struct gcm_key *key, size_t rounds, +_gcm_aes_decrypt (struct gcm_key *key, unsigned rounds, size_t len, uint8_t *dst, const uint8_t *src); #define _nettle_gcm_aes_decrypt _nettle_gcm_aes_decrypt_c #endif size_t -_gcm_aes_encrypt (struct gcm_key *key, size_t rounds, +_gcm_aes_encrypt (struct gcm_key *key, unsigned rounds, size_t len, uint8_t *dst, const uint8_t *src) { return 0; } size_t -_gcm_aes_decrypt (struct gcm_key *key, size_t rounds, +_gcm_aes_decrypt (struct gcm_key *key, unsigned rounds, size_t len, uint8_t *dst, const uint8_t *src) { return 0; diff --git a/gcm-aes128.c b/gcm-aes128.c index 580882a4..7ff06199 100644 --- a/gcm-aes128.c +++ b/gcm-aes128.c @@ -38,6 +38,7 @@ #include #include "gcm.h" +#include "gcm-internal.h" void gcm_aes128_set_key(struct gcm_aes128_ctx *ctx, const uint8_t *key) diff --git a/gcm-aes192.c b/gcm-aes192.c index 9fd2a15d..83c32e02 100644 --- a/gcm-aes192.c +++ b/gcm-aes192.c @@ -38,6 +38,7 @@ #include #include "gcm.h" +#include "gcm-internal.h" void gcm_aes192_set_key(struct gcm_aes192_ctx *ctx, const uint8_t *key) diff --git a/gcm-aes256.c b/gcm-aes256.c index 84d44c6e..4974001f 100644 --- a/gcm-aes256.c +++ b/gcm-aes256.c @@ -38,6 +38,7 @@ #include #include "gcm.h" +#include "gcm-internal.h" void gcm_aes256_set_key(struct gcm_aes256_ctx *ctx, const uint8_t *key) diff --git a/gcm-internal.h b/gcm-internal.h new file mode 100644 index 00000000..5710bb9b --- /dev/null +++ b/gcm-internal.h @@ -0,0 +1,55 @@ +/* gcm-internal.h + + Copyright (C) 2024 Niels Möller + + 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/. +*/ + +#ifndef NETTLE_GCM_INTERNAL_H_INCLUDED +#define NETTLE_GCM_INTERNAL_H_INCLUDED + +#include "gcm.h" + +/* Name mangling */ +#define _gcm_aes_encrypt _nettle_gcm_aes_encrypt +#define _gcm_aes_decrypt _nettle_gcm_aes_decrypt + +/* To reduce the number of arguments (e.g., maximum of 6 register + arguments on x86_64), pass a pointer to gcm_key, which really is a + pointer to the first member of the appropriate gcm_aes*_ctx + struct. */ +size_t +_gcm_aes_encrypt (struct gcm_key *key, + unsigned rounds, + size_t size, uint8_t *dst, const uint8_t *src); + +size_t +_gcm_aes_decrypt (struct gcm_key *CTX, + unsigned rounds, + size_t size, uint8_t *dst, const uint8_t *src); + +#endif /* NETTLE_GCM_INTERNAL_H_INCLUDED */ diff --git a/gcm.h b/gcm.h index 52af4863..39af5ab0 100644 --- a/gcm.h +++ b/gcm.h @@ -54,9 +54,6 @@ extern "C" { #define gcm_decrypt nettle_gcm_decrypt #define gcm_digest nettle_gcm_digest -#define _gcm_aes_encrypt _nettle_gcm_aes_encrypt -#define _gcm_aes_decrypt _nettle_gcm_aes_decrypt - #define gcm_aes128_set_key nettle_gcm_aes128_set_key #define gcm_aes128_set_iv nettle_gcm_aes128_set_iv #define gcm_aes128_update nettle_gcm_aes128_update