mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-25 08:37:13 +09:00
Make the blake2b and poly1305 state opaque
This commit is contained in:
@@ -51,10 +51,10 @@ _bswap64(const uint64_t x)
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef struct context {
|
||||
CRYPTO_ALIGN(16) unsigned char H[16];
|
||||
__m128i rkeys[16];
|
||||
} context;
|
||||
typedef struct aes256gcm_state {
|
||||
__m128i rkeys[16];
|
||||
unsigned char H[16];
|
||||
} aes256gcm_state;
|
||||
|
||||
static inline void
|
||||
aesni_key256_expand(const unsigned char *key, __m128i * const rkeys)
|
||||
@@ -488,10 +488,10 @@ int
|
||||
crypto_aead_aes256gcm_beforenm(crypto_aead_aes256gcm_state *ctx_,
|
||||
const unsigned char *k)
|
||||
{
|
||||
context *ctx = (context *) ctx_;
|
||||
__m128i *rkeys = ctx->rkeys;
|
||||
__m128i zero = _mm_setzero_si128();
|
||||
unsigned char *H = ctx->H;
|
||||
aes256gcm_state *ctx = (aes256gcm_state *) (void *) ctx_;
|
||||
unsigned char *H = ctx->H;
|
||||
__m128i *rkeys = ctx->rkeys;
|
||||
__m128i zero = _mm_setzero_si128();
|
||||
|
||||
COMPILER_ASSERT((sizeof *ctx_) >= (sizeof *ctx));
|
||||
aesni_key256_expand(k, rkeys);
|
||||
@@ -509,13 +509,13 @@ crypto_aead_aes256gcm_encrypt_detached_afternm(unsigned char *c,
|
||||
const unsigned char *npub,
|
||||
const crypto_aead_aes256gcm_state *ctx_)
|
||||
{
|
||||
const __m128i rev = _mm_set_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
|
||||
const context *ctx = (const context *) ctx_;
|
||||
const __m128i *rkeys = ctx->rkeys;
|
||||
__m128i Hv, H2v, H3v, H4v, accv;
|
||||
unsigned long long i, j;
|
||||
unsigned long long adlen_rnd64 = adlen & ~63ULL;
|
||||
unsigned long long mlen_rnd128 = mlen & ~127ULL;
|
||||
const __m128i rev = _mm_set_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
|
||||
const aes256gcm_state *ctx = (const aes256gcm_state *) (const void *) ctx_;
|
||||
const __m128i *rkeys = ctx->rkeys;
|
||||
__m128i Hv, H2v, H3v, H4v, accv;
|
||||
unsigned long long i, j;
|
||||
unsigned long long adlen_rnd64 = adlen & ~63ULL;
|
||||
unsigned long long mlen_rnd128 = mlen & ~127ULL;
|
||||
CRYPTO_ALIGN(16) uint32_t n2[4];
|
||||
CRYPTO_ALIGN(16) unsigned char H[16];
|
||||
CRYPTO_ALIGN(16) unsigned char T[16];
|
||||
@@ -647,14 +647,14 @@ crypto_aead_aes256gcm_decrypt_detached_afternm(unsigned char *m, unsigned char *
|
||||
const unsigned char *npub,
|
||||
const crypto_aead_aes256gcm_state *ctx_)
|
||||
{
|
||||
const __m128i rev = _mm_set_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
|
||||
const context *ctx = (const context *) ctx_;
|
||||
const __m128i *rkeys = ctx->rkeys;
|
||||
__m128i Hv, H2v, H3v, H4v, accv;
|
||||
unsigned long long i, j;
|
||||
unsigned long long adlen_rnd64 = adlen & ~63ULL;
|
||||
unsigned long long mlen;
|
||||
unsigned long long mlen_rnd128;
|
||||
const __m128i rev = _mm_set_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
|
||||
const aes256gcm_state *ctx = (const aes256gcm_state *) (const void *) ctx_;
|
||||
const __m128i *rkeys = ctx->rkeys;
|
||||
__m128i Hv, H2v, H3v, H4v, accv;
|
||||
unsigned long long i, j;
|
||||
unsigned long long adlen_rnd64 = adlen & ~63ULL;
|
||||
unsigned long long mlen;
|
||||
unsigned long long mlen_rnd128;
|
||||
CRYPTO_ALIGN(16) uint32_t n2[4];
|
||||
CRYPTO_ALIGN(16) unsigned char H[16];
|
||||
CRYPTO_ALIGN(16) unsigned char T[16];
|
||||
@@ -862,7 +862,7 @@ crypto_aead_aes256gcm_encrypt(unsigned char *c,
|
||||
ret = crypto_aead_aes256gcm_encrypt_afternm
|
||||
(c, clen_p, m, mlen, ad, adlen, nsec, npub,
|
||||
(const crypto_aead_aes256gcm_state *) &ctx);
|
||||
sodium_memzero(ctx, sizeof ctx);
|
||||
sodium_memzero(&ctx, sizeof ctx);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -906,7 +906,7 @@ crypto_aead_aes256gcm_decrypt(unsigned char *m,
|
||||
ret = crypto_aead_aes256gcm_decrypt_afternm
|
||||
(m, mlen_p, nsec, c, clen, ad, adlen, npub,
|
||||
(const crypto_aead_aes256gcm_state *) &ctx);
|
||||
sodium_memzero(ctx, sizeof ctx);
|
||||
sodium_memzero(&ctx, sizeof ctx);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,14 @@ typedef struct blake2b_param_ {
|
||||
uint8_t personal[BLAKE2B_PERSONALBYTES]; /* 64 */
|
||||
} blake2b_param;
|
||||
|
||||
typedef crypto_generichash_blake2b_state blake2b_state;
|
||||
typedef struct blake2b_state {
|
||||
uint64_t h[8];
|
||||
uint64_t t[2];
|
||||
uint64_t f[2];
|
||||
uint8_t buf[2 * 128];
|
||||
size_t buflen;
|
||||
uint8_t last_node;
|
||||
} blake2b_state;
|
||||
|
||||
#if defined(__IBMC__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
|
||||
#pragma pack()
|
||||
|
||||
@@ -53,10 +53,10 @@ crypto_generichash_blake2b_init(crypto_generichash_blake2b_state *state,
|
||||
assert(outlen <= UINT8_MAX);
|
||||
assert(keylen <= UINT8_MAX);
|
||||
if (key == NULL || keylen <= 0U) {
|
||||
if (blake2b_init(state, (uint8_t) outlen) != 0) {
|
||||
if (blake2b_init((blake2b_state *) (void *) state, (uint8_t) outlen) != 0) {
|
||||
return -1; /* LCOV_EXCL_LINE */
|
||||
}
|
||||
} else if (blake2b_init_key(state, (uint8_t) outlen, key,
|
||||
} else if (blake2b_init_key((blake2b_state *) (void *) state, (uint8_t) outlen, key,
|
||||
(uint8_t) keylen) != 0) {
|
||||
return -1; /* LCOV_EXCL_LINE */
|
||||
}
|
||||
@@ -76,11 +76,12 @@ crypto_generichash_blake2b_init_salt_personal(
|
||||
assert(outlen <= UINT8_MAX);
|
||||
assert(keylen <= UINT8_MAX);
|
||||
if (key == NULL || keylen <= 0U) {
|
||||
if (blake2b_init_salt_personal(state, (uint8_t) outlen, salt,
|
||||
personal) != 0) {
|
||||
if (blake2b_init_salt_personal((blake2b_state *) (void *) state,
|
||||
(uint8_t) outlen, salt, personal) != 0) {
|
||||
return -1; /* LCOV_EXCL_LINE */
|
||||
}
|
||||
} else if (blake2b_init_key_salt_personal(state, (uint8_t) outlen, key,
|
||||
} else if (blake2b_init_key_salt_personal((blake2b_state *) (void *) state,
|
||||
(uint8_t) outlen, key,
|
||||
(uint8_t) keylen, salt,
|
||||
personal) != 0) {
|
||||
return -1; /* LCOV_EXCL_LINE */
|
||||
@@ -93,7 +94,8 @@ crypto_generichash_blake2b_update(crypto_generichash_blake2b_state *state,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen)
|
||||
{
|
||||
return blake2b_update(state, (const uint8_t *) in, (uint64_t) inlen);
|
||||
return blake2b_update((blake2b_state *) (void *) state,
|
||||
(const uint8_t *) in, (uint64_t) inlen);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -101,7 +103,8 @@ crypto_generichash_blake2b_final(crypto_generichash_blake2b_state *state,
|
||||
unsigned char *out, const size_t outlen)
|
||||
{
|
||||
assert(outlen <= UINT8_MAX);
|
||||
return blake2b_final(state, (uint8_t *) out, (uint8_t) outlen);
|
||||
return blake2b_final((blake2b_state *) (void *) state,
|
||||
(uint8_t *) out, (uint8_t) outlen);
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
@@ -56,7 +56,9 @@ size_t crypto_aead_aes256gcm_abytes(void);
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aes256gcm_messagebytes_max(void);
|
||||
|
||||
typedef CRYPTO_ALIGN(16) unsigned char crypto_aead_aes256gcm_state[512];
|
||||
typedef CRYPTO_ALIGN(16) struct crypto_aead_aes256gcm_state_ {
|
||||
unsigned char opaque[512];
|
||||
} crypto_aead_aes256gcm_state;
|
||||
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aes256gcm_statebytes(void);
|
||||
|
||||
@@ -21,12 +21,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct CRYPTO_ALIGN(64) crypto_generichash_blake2b_state {
|
||||
uint64_t h[8];
|
||||
uint64_t t[2];
|
||||
uint64_t f[2];
|
||||
uint8_t buf[2 * 128];
|
||||
size_t buflen;
|
||||
uint8_t last_node;
|
||||
unsigned char opaque[384];
|
||||
} crypto_generichash_blake2b_state;
|
||||
|
||||
#if defined(__IBMC__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
|
||||
|
||||
Reference in New Issue
Block a user