summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2017-06-08 13:00:25 +0200
committerNikos Mavrogiannopoulos <nmav@redhat.com>2017-06-08 13:00:55 +0200
commit8fdb63854fea2956abecee6f1b2dcb24ee447ea7 (patch)
treed7a3e5d64ed8b1dbe3b1a1cdf6329ff45299867f
parent999bbe1eb74e6c4f7d7827c8875276eb0293d7ee (diff)
downloadgnutls-8fdb63854fea2956abecee6f1b2dcb24ee447ea7.tar.gz
nettle/cipher: document that ctx_ptr is 16-byte aligned, and use void* to avoid compiler assumptions
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
-rw-r--r--lib/nettle/cipher.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/nettle/cipher.c b/lib/nettle/cipher.c
index 269001ae0c..61e4a6cb62 100644
--- a/lib/nettle/cipher.c
+++ b/lib/nettle/cipher.c
@@ -92,7 +92,7 @@ struct nettle_cipher_st {
struct nettle_cipher_ctx {
const struct nettle_cipher_st *cipher;
- uint8_t *ctx_ptr;
+ void *ctx_ptr; /* always 16-aligned */
uint8_t iv[MAX_CIPHER_BLOCK_SIZE];
unsigned iv_size;
@@ -517,6 +517,7 @@ wrap_nettle_cipher_init(gnutls_cipher_algorithm_t algo, void **_ctx,
ptrdiff_t cur_alignment;
int idx = -1;
unsigned i;
+ uint8_t *ctx_ptr;
for (i=0;i<sizeof(builtin_ciphers)/sizeof(builtin_ciphers[0]);i++) {
if (algo == builtin_ciphers[i].algo) {
@@ -538,12 +539,13 @@ wrap_nettle_cipher_init(gnutls_cipher_algorithm_t algo, void **_ctx,
}
ctx->enc = enc;
- ctx->ctx_ptr = ((uint8_t*)ctx) + sizeof(*ctx);
+ ctx_ptr = ((uint8_t*)ctx) + sizeof(*ctx);
- cur_alignment = ((ptrdiff_t)ctx->ctx_ptr) % 16;
+ cur_alignment = ((ptrdiff_t)ctx_ptr) % 16;
if (cur_alignment > 0)
- ctx->ctx_ptr += 16 - cur_alignment;
+ ctx_ptr += 16 - cur_alignment;
+ ctx->ctx_ptr = ctx_ptr;
ctx->cipher = &builtin_ciphers[idx];
*_ctx = ctx;