Fix constness of |gcm128_context.key|.

The key is never modified through the key pointer member, and the
calling code relies on that fact for maintaining its own
const-correctness.

Change-Id: I63946451aa7c400cd127895a61c30d9a647b1b8c
This commit is contained in:
Brian Smith 2015-09-29 14:58:06 -10:00
parent fa2324001a
commit 06b550adc4
3 changed files with 11 additions and 9 deletions

View File

@ -403,7 +403,7 @@ void gcm_ghash_neon(uint64_t Xi[2], const u128 Htable[16], const uint8_t *inp,
#endif
#endif
GCM128_CONTEXT *CRYPTO_gcm128_new(void *key, block128_f block) {
GCM128_CONTEXT *CRYPTO_gcm128_new(const void *key, block128_f block) {
GCM128_CONTEXT *ret;
ret = (GCM128_CONTEXT *)OPENSSL_malloc(sizeof(GCM128_CONTEXT));
@ -414,7 +414,8 @@ GCM128_CONTEXT *CRYPTO_gcm128_new(void *key, block128_f block) {
return ret;
}
void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, void *key, block128_f block) {
void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, const void *key,
block128_f block) {
const union {
long one;
char little;
@ -591,7 +592,7 @@ int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx, const unsigned char *in,
size_t i;
uint64_t mlen = ctx->len.u[1];
block128_f block = ctx->block;
void *key = ctx->key;
const void *key = ctx->key;
#ifdef GCM_FUNCREF_4BIT
void (*gcm_gmult_p)(uint64_t Xi[2], const u128 Htable[16]) = ctx->gmult;
#ifdef GHASH
@ -751,7 +752,7 @@ int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx, const unsigned char *in,
size_t i;
uint64_t mlen = ctx->len.u[1];
block128_f block = ctx->block;
void *key = ctx->key;
const void *key = ctx->key;
#ifdef GCM_FUNCREF_4BIT
void (*gcm_gmult_p)(uint64_t Xi[2], const u128 Htable[16]) = ctx->gmult;
#ifdef GHASH
@ -917,7 +918,7 @@ int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx, const uint8_t *in,
unsigned int n, ctr;
size_t i;
uint64_t mlen = ctx->len.u[1];
void *key = ctx->key;
const void *key = ctx->key;
#ifdef GCM_FUNCREF_4BIT
void (*gcm_gmult_p)(uint64_t Xi[2], const u128 Htable[16]) = ctx->gmult;
#ifdef GHASH
@ -1027,7 +1028,7 @@ int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx, const uint8_t *in,
unsigned int n, ctr;
size_t i;
uint64_t mlen = ctx->len.u[1];
void *key = ctx->key;
const void *key = ctx->key;
#ifdef GCM_FUNCREF_4BIT
void (*gcm_gmult_p)(uint64_t Xi[2], const u128 Htable[16]) = ctx->gmult;
#ifdef GHASH

View File

@ -170,7 +170,7 @@ struct gcm128_context {
unsigned int mres, ares;
block128_f block;
void *key;
const void *key;
};
struct xts128_context {

View File

@ -97,11 +97,12 @@ typedef struct gcm128_context GCM128_CONTEXT;
/* CRYPTO_gcm128_new allocates a fresh |GCM128_CONTEXT| and calls
* |CRYPTO_gcm128_init|. It returns the new context, or NULL on error. */
OPENSSL_EXPORT GCM128_CONTEXT *CRYPTO_gcm128_new(void *key, block128_f block);
OPENSSL_EXPORT GCM128_CONTEXT *CRYPTO_gcm128_new(const void *key,
block128_f block);
/* CRYPTO_gcm128_init initialises |ctx| to use |block| (typically AES) with the
* given key. */
OPENSSL_EXPORT void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, void *key,
OPENSSL_EXPORT void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, const void *key,
block128_f block);
/* CRYPTO_gcm128_set_96_bit_iv sets the IV (nonce) for |ctx|. |iv| must be 12