summaryrefslogtreecommitdiffstats
path: root/src/crypto/gcm.c
diff options
context:
space:
mode:
authorMichael Brown2024-01-16 14:24:29 +0100
committerMichael Brown2024-01-16 14:35:08 +0100
commit4b7d9a6af08cb704ce77eadba2a7bb1b06c1554c (patch)
tree9ee6e4fab3807cea2b6b4c5fa8f1984510e6107a /src/crypto/gcm.c
parent[libc] Make static_assert() available via assert.h (diff)
downloadipxe-4b7d9a6af08cb704ce77eadba2a7bb1b06c1554c.tar.gz
ipxe-4b7d9a6af08cb704ce77eadba2a7bb1b06c1554c.tar.xz
ipxe-4b7d9a6af08cb704ce77eadba2a7bb1b06c1554c.zip
[libc] Replace linker_assert() with build_assert()
We currently implement build-time assertions via a mechanism that generates a call to an undefined external function that will cause the link to fail unless the compiler can prove that the asserted condition is true (and thereby eliminate the undefined function call). This assertion mechanism can be used for conditions that are not amenable to the use of static_assert(), since static_assert() will not allow for proofs via dead code elimination. Add __attribute__((error(...))) to the undefined external function, so that the error is raised at compile time rather than at link time. This allows us to provide a more meaningful error message (which will include the file name and line number, as with any other compile-time error), and avoids the need for the caller to specify a unique symbol name for the external function. Change the name from linker_assert() to build_assert(), since the assertion now takes place at compile time rather than at link time. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/crypto/gcm.c')
-rw-r--r--src/crypto/gcm.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/crypto/gcm.c b/src/crypto/gcm.c
index 9d8bae82..c21aad14 100644
--- a/src/crypto/gcm.c
+++ b/src/crypto/gcm.c
@@ -472,10 +472,10 @@ void gcm_setiv ( struct gcm_context *context, const void *iv, size_t ivlen ) {
union gcm_block *check = ( ( void * ) context );
/* Sanity checks */
- linker_assert ( &context->hash == check, gcm_bad_layout );
- linker_assert ( &context->len == check + 1, gcm_bad_layout );
- linker_assert ( &context->ctr == check + 2, gcm_bad_layout );
- linker_assert ( &context->key == check + 3, gcm_bad_layout );
+ build_assert ( &context->hash == check );
+ build_assert ( &context->len == check + 1 );
+ build_assert ( &context->ctr == check + 2 );
+ build_assert ( &context->key == check + 3 );
/* Reset non-key state */
memset ( context, 0, offsetof ( typeof ( *context ), key ) );