summaryrefslogtreecommitdiffstats
path: root/src/crypto/gcm.c
diff options
context:
space:
mode:
authorMichael Brown2024-02-10 15:41:29 +0100
committerMichael Brown2024-02-10 15:48:56 +0100
commit94b39fbe9298160b034c93ca06deb39a907e3b3f (patch)
tree2dfc041ae6f3dac2f3444cd6efed768b25b17e17 /src/crypto/gcm.c
parent[libc] Allow build_assert() failures to be ignored via NO_WERROR=1 (diff)
downloadipxe-94b39fbe9298160b034c93ca06deb39a907e3b3f.tar.gz
ipxe-94b39fbe9298160b034c93ca06deb39a907e3b3f.tar.xz
ipxe-94b39fbe9298160b034c93ca06deb39a907e3b3f.zip
[build] Fix build failures with older versions of gcc
Some versions of gcc (observed with gcc 4.8.5 in CentOS 7) will report spurious build_assert() failures for some assertions about structure layouts. There is no clear pattern as to what causes these spurious failures, and the build assertion does succeed in that no unresolvable symbol reference is generated in the compiled code. Adjust the assertions to work around these apparent compiler issues. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/crypto/gcm.c')
-rw-r--r--src/crypto/gcm.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/crypto/gcm.c b/src/crypto/gcm.c
index c21aad14..a32890d5 100644
--- a/src/crypto/gcm.c
+++ b/src/crypto/gcm.c
@@ -469,13 +469,15 @@ int gcm_setkey ( struct gcm_context *context, const void *key, size_t keylen,
* @v ivlen Initialisation vector length
*/
void gcm_setiv ( struct gcm_context *context, const void *iv, size_t ivlen ) {
- union gcm_block *check = ( ( void * ) context );
- /* Sanity checks */
- build_assert ( &context->hash == check );
- build_assert ( &context->len == check + 1 );
- build_assert ( &context->ctr == check + 2 );
- build_assert ( &context->key == check + 3 );
+ /* 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 ) );