Commit 53f5da92 authored by Niels Möller's avatar Niels Möller

* gcm-aes.c (gcm_aes_set_iv): Use GCM_SET_IV.

(gcm_aes_set_key): Deleted cast.
(gcm_aes_encrypt): Likewise.
(gcm_aes_decrypt): Likewise.
(gcm_aes_digest): Likewise.
(gcm_aes_update): One less argument to GCM_UPDATE.

* gcm.h (GCM_SET_KEY): Added cast to nettle_crypt_func *. Help
compiler type checking despite this cast.
(GCM_ENCRYPT): Likewise.
(GCM_DECRYPT): Likewise.
(GCM_DIGEST): Likewise.
(GCM_SET_IV): New macro, for completeness.
(GCM_UPDATE): Deleted unused argument encrypt.

Rev: nettle/ChangeLog:1.156
Rev: nettle/gcm-aes.c:1.4
Rev: nettle/gcm.h:1.12
parent ac09e0fe
2011-02-16 Niels Mller <nisse@lysator.liu.se>
* gcm-aes.c (gcm_aes_set_iv): Use GCM_SET_IV.
(gcm_aes_set_key): Deleted cast.
(gcm_aes_encrypt): Likewise.
(gcm_aes_decrypt): Likewise.
(gcm_aes_digest): Likewise.
(gcm_aes_update): One less argument to GCM_UPDATE.
* gcm.h (GCM_SET_KEY): Added cast to nettle_crypt_func *. Help
compiler type checking despite this cast.
(GCM_ENCRYPT): Likewise.
(GCM_DECRYPT): Likewise.
(GCM_DIGEST): Likewise.
(GCM_SET_IV): New macro, for completeness.
(GCM_UPDATE): Deleted unused argument encrypt.
2011-02-14 Niels Mller <nisse@lysator.liu.se>
* nettle.texinfo: Split node on cipher modes, and started on
......
......@@ -28,45 +28,40 @@
void
gcm_aes_set_key(struct gcm_aes_ctx *ctx, unsigned length, const uint8_t *key)
{
GCM_SET_KEY(ctx, aes_set_encrypt_key, (nettle_crypt_func *) aes_encrypt,
length, key);
GCM_SET_KEY(ctx, aes_set_encrypt_key, aes_encrypt, length, key);
}
void
gcm_aes_set_iv(struct gcm_aes_ctx *ctx,
unsigned length, const uint8_t *iv)
{
gcm_set_iv(&ctx->gcm, &ctx->key, length, iv);
GCM_SET_IV(ctx, length, iv);
}
void
gcm_aes_update(struct gcm_aes_ctx *ctx, unsigned length, const uint8_t *data)
{
GCM_UPDATE(ctx, (nettle_crypt_func *) aes_encrypt,
length, data);
GCM_UPDATE(ctx, length, data);
}
void
gcm_aes_encrypt(struct gcm_aes_ctx *ctx,
unsigned length, uint8_t *dst, const uint8_t *src)
{
GCM_ENCRYPT(ctx, (nettle_crypt_func *) aes_encrypt,
length, dst, src);
GCM_ENCRYPT(ctx, aes_encrypt, length, dst, src);
}
void
gcm_aes_decrypt(struct gcm_aes_ctx *ctx,
unsigned length, uint8_t *dst, const uint8_t *src)
{
GCM_DECRYPT(ctx, (nettle_crypt_func *) aes_encrypt,
length, dst, src);
GCM_DECRYPT(ctx, aes_encrypt, length, dst, src);
}
void
gcm_aes_digest(struct gcm_aes_ctx *ctx,
unsigned length, uint8_t *digest)
{
GCM_DIGEST(ctx, (nettle_crypt_func *) aes_encrypt,
length, digest);
GCM_DIGEST(ctx, aes_encrypt, length, digest);
}
......@@ -121,26 +121,38 @@ gcm_digest(struct gcm_ctx *ctx, const struct gcm_key *key,
#define GCM_CTX(type) \
{ type cipher; struct gcm_key key; struct gcm_ctx gcm; }
/* NOTE: Avoid using NULL, as we don't include anything defining it. */
#define GCM_SET_KEY(ctx, set_key, encrypt, length, data) \
do { \
(set_key)(&(ctx)->cipher, (length), (data)); \
gcm_set_key(&(ctx)->key, &(ctx)->cipher, (encrypt)); \
if (0) (encrypt)(&(ctx)->cipher, 0, (void *)0, (void *)0); \
gcm_set_key(&(ctx)->key, &(ctx)->cipher, \
(nettle_crypt_func *) (encrypt)); \
} while (0)
#define GCM_UPDATE(ctx, encrypt, length, data) \
gcm_update(&(ctx)->gcm, &(ctx)->key, (length), (data))
#define GCM_ENCRYPT(ctx, encrypt, length, dst, src) \
gcm_encrypt(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, (encrypt), \
(length), (dst), (src))
#define GCM_SET_IV(ctx, length, data) \
gcm_set_iv(&(ctx)->gcm, &(ctx)->key, (length), (data))
#define GCM_DECRYPT(ctx, encrypt, length, dst, src) \
gcm_decrypt(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, (encrypt), \
(length), (dst), (src))
#define GCM_UPDATE(ctx, length, data) \
gcm_update(&(ctx)->gcm, &(ctx)->key, (length), (data))
#define GCM_DIGEST(ctx, encrypt, length, digest) \
gcm_digest(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, (encrypt), \
(length), (digest))
#define GCM_ENCRYPT(ctx, encrypt, length, dst, src) \
(0 ? (encrypt)(&(ctx)->cipher, 0, (void *)0, (void *)0) \
: gcm_encrypt(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, \
(nettle_crypt_func *) (encrypt), \
(length), (dst), (src)))
#define GCM_DECRYPT(ctx, encrypt, length, dst, src) \
(0 ? (encrypt)(&(ctx)->cipher, 0, (void *)0, (void *)0) \
: gcm_decrypt(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, \
(nettle_crypt_func *) (encrypt), \
(length), (dst), (src)))
#define GCM_DIGEST(ctx, encrypt, length, digest) \
(0 ? (encrypt)(&(ctx)->cipher, 0, (void *)0, (void *)0) \
: gcm_digest(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, \
(nettle_crypt_func *) (encrypt), \
(length), (digest)))
struct gcm_aes_ctx GCM_CTX(struct aes_ctx);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment