summaryrefslogtreecommitdiffstats
path: root/src/crypto/gcm.c
diff options
context:
space:
mode:
authorMichael Brown2024-03-27 15:28:47 +0100
committerMichael Brown2024-03-27 15:28:47 +0100
commit37850e0e854292d074c2d35d18d7bb78d8e6ff85 (patch)
tree39b0581719832b892a925706be0af3cbf6768137 /src/crypto/gcm.c
parent[efi] Extract basic network settings from loaded image device path (diff)
downloadipxe-37850e0e854292d074c2d35d18d7bb78d8e6ff85.tar.gz
ipxe-37850e0e854292d074c2d35d18d7bb78d8e6ff85.tar.xz
ipxe-37850e0e854292d074c2d35d18d7bb78d8e6ff85.zip
[build] Fix build failures with random versions of gcc
For unknown reasons, miscellaneous versions of gcc seem to struggle with the static assertions used to ensure the correct layout of the GCM structures. Adjust the assertions to use offsetof() rather than direct pointer comparison, on the basis that offsetof() must be a compile-time constant value. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/crypto/gcm.c')
-rw-r--r--src/crypto/gcm.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/crypto/gcm.c b/src/crypto/gcm.c
index a32890d5..b93925d0 100644
--- a/src/crypto/gcm.c
+++ b/src/crypto/gcm.c
@@ -109,6 +109,9 @@ static union gcm_block gcm_cached_mult[256];
*/
static uint16_t gcm_cached_reduce[256];
+/** Offset of a field within GCM context */
+#define gcm_offset( field ) offsetof ( struct gcm_context, field )
+
/**
* Reverse bits in a byte
*
@@ -470,17 +473,13 @@ int gcm_setkey ( struct gcm_context *context, const void *key, size_t keylen,
*/
void gcm_setiv ( struct gcm_context *context, const void *iv, size_t ivlen ) {
- /* Sanity check: ensure that memset()s will clear expected state */
- build_assert ( &context->hash < &context->ctr );
- build_assert ( &context->len < &context->ctr );
- build_assert ( &context->ctr < &context->key );
- build_assert ( ( ( void * ) &context->raw_cipher ) >
- ( ( void * ) &context->key ) );
- build_assert ( ( ( void * ) context->raw_ctx ) >
- ( ( void * ) &context->key ) );
-
/* Reset non-key state */
- memset ( context, 0, offsetof ( typeof ( *context ), key ) );
+ memset ( context, 0, gcm_offset ( key ) );
+ build_assert ( gcm_offset ( key ) > gcm_offset ( hash ) );
+ build_assert ( gcm_offset ( key ) > gcm_offset ( len ) );
+ build_assert ( gcm_offset ( key ) > gcm_offset ( ctr ) );
+ build_assert ( gcm_offset ( key ) < gcm_offset ( raw_cipher ) );
+ build_assert ( gcm_offset ( key ) < gcm_offset ( raw_ctx ) );
/* Reset counter */
context->ctr.ctr.value = cpu_to_be32 ( 1 );
@@ -499,7 +498,12 @@ void gcm_setiv ( struct gcm_context *context, const void *iv, size_t ivlen ) {
assert ( context->len.len.add == 0 );
/* Reset non-key, non-counter state */
- memset ( context, 0, offsetof ( typeof ( *context ), ctr ) );
+ memset ( context, 0, gcm_offset ( ctr ) );
+ build_assert ( gcm_offset ( ctr ) > gcm_offset ( hash ) );
+ build_assert ( gcm_offset ( ctr ) > gcm_offset ( len ) );
+ build_assert ( gcm_offset ( ctr ) < gcm_offset ( key ) );
+ build_assert ( gcm_offset ( ctr ) < gcm_offset ( raw_cipher ) );
+ build_assert ( gcm_offset ( ctr ) < gcm_offset ( raw_ctx ) );
}
DBGC2 ( context, "GCM %p Y[0]:\n", context );