From: Nikos Mavrogiannopoulos Date: Thu, 8 Jun 2017 11:00:25 +0000 (+0200) Subject: nettle/cipher: document that ctx_ptr is 16-byte aligned, and use void* to avoid compi... X-Git-Tag: gnutls_3_6_0~457 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8fdb63854fea2956abecee6f1b2dcb24ee447ea7;p=thirdparty%2Fgnutls.git nettle/cipher: document that ctx_ptr is 16-byte aligned, and use void* to avoid compiler assumptions Signed-off-by: Nikos Mavrogiannopoulos --- 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;ienc = 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;