Remove ctx_new and ctx_free function pointers
Now that HMAC isn't special anymore, and with the help of init params,
this isn't needed anymore as we only allocate memory for the state.
This effectively reverts e9bcc64e62
.
This commit is contained in:
parent
666b833b98
commit
6677c6cab3
1
aead.h
1
aead.h
@ -24,5 +24,6 @@ struct lc_aead_impl {
|
||||
int (*open)(uint8_t *, size_t *, void *, const uint8_t *, size_t,
|
||||
const uint8_t *, size_t);
|
||||
|
||||
size_t argsz;
|
||||
size_t blocklen;
|
||||
};
|
||||
|
9
auth.c
9
auth.c
@ -54,8 +54,8 @@ lc_auth_ctx_new(const struct lc_auth_impl *impl)
|
||||
ctx = malloc(sizeof(*ctx));
|
||||
if (ctx == NULL)
|
||||
return NULL;
|
||||
if (impl->ctx_new != NULL) {
|
||||
ctx->arg = impl->ctx_new();
|
||||
if (impl->argsz > 0) {
|
||||
ctx->arg = malloc(impl->argsz);
|
||||
if (ctx->arg == NULL) {
|
||||
free(ctx);
|
||||
return NULL;
|
||||
@ -70,10 +70,7 @@ lc_auth_ctx_new(const struct lc_auth_impl *impl)
|
||||
void
|
||||
lc_auth_ctx_free(struct lc_auth_ctx *ctx)
|
||||
{
|
||||
if (ctx != NULL) {
|
||||
if (ctx->impl != NULL && ctx->impl->ctx_free != NULL)
|
||||
ctx->impl->ctx_free(ctx->arg);
|
||||
if (ctx != NULL)
|
||||
free(ctx->arg);
|
||||
}
|
||||
free(ctx);
|
||||
}
|
||||
|
4
auth.h
4
auth.h
@ -24,9 +24,7 @@ struct lc_auth_impl {
|
||||
int (*final)(void *, uint8_t *, size_t *);
|
||||
int (*auth)(uint8_t *, size_t *, void *, const uint8_t *, size_t);
|
||||
|
||||
void *(*ctx_new)(void);
|
||||
void (*ctx_free)(void *);
|
||||
|
||||
size_t argsz;
|
||||
size_t blocklen;
|
||||
size_t taglen;
|
||||
};
|
||||
|
10
auth_hmac.c
10
auth_hmac.c
@ -114,12 +114,6 @@ hmac_auth(uint8_t *out, size_t *outlen, void *initparams, const uint8_t *in,
|
||||
hmac_final(&ctx, out, outlen);
|
||||
}
|
||||
|
||||
static void *
|
||||
hmac_ctx_new(void)
|
||||
{
|
||||
return malloc(sizeof(struct hmac_ctx));
|
||||
}
|
||||
|
||||
|
||||
static struct lc_auth_impl hmac_impl = {
|
||||
.init = &hmac_init,
|
||||
@ -127,9 +121,7 @@ static struct lc_auth_impl hmac_impl = {
|
||||
.final = &hmac_final,
|
||||
.auth = &hmac_auth,
|
||||
|
||||
.ctx_new = &hmac_ctx_new,
|
||||
.ctx_free = NULL,
|
||||
|
||||
.argsz = sizeof(struct hmac_ctx),
|
||||
.blocklen = 0,
|
||||
.taglen = 0,
|
||||
};
|
||||
|
@ -150,12 +150,6 @@ poly1305_auth(uint8_t *out, size_t *outlen, void *initparams,
|
||||
poly1305_final(&ctx, out, outlen);
|
||||
}
|
||||
|
||||
static void *
|
||||
poly1305_ctx_new(void)
|
||||
{
|
||||
return malloc(sizeof(struct poly1305_ctx));
|
||||
}
|
||||
|
||||
|
||||
static struct lc_auth_impl poly1305_impl = {
|
||||
.init = &poly1305_init,
|
||||
@ -163,9 +157,7 @@ static struct lc_auth_impl poly1305_impl = {
|
||||
.final = &poly1305_final,
|
||||
.auth = &poly1305_auth,
|
||||
|
||||
.ctx_new = &poly1305_ctx_new,
|
||||
.ctx_free = NULL,
|
||||
|
||||
.argsz = sizeof(struct poly1305_ctx),
|
||||
.blocklen = LC_POLY1305_BLOCKLEN,
|
||||
.taglen = LC_POLY1305_TAGLEN,
|
||||
};
|
||||
|
9
cipher.c
9
cipher.c
@ -82,8 +82,8 @@ lc_cipher_ctx_new(const struct lc_cipher_impl *impl)
|
||||
ctx = malloc(sizeof(*ctx));
|
||||
if (ctx == NULL)
|
||||
return NULL;
|
||||
if (impl->ctx_new != NULL) {
|
||||
ctx->arg = impl->ctx_new();
|
||||
if (impl->argsz > 0) {
|
||||
ctx->arg = malloc(impl->argsz);
|
||||
if (ctx->arg == NULL) {
|
||||
free(ctx);
|
||||
return NULL;
|
||||
@ -98,10 +98,7 @@ lc_cipher_ctx_new(const struct lc_cipher_impl *impl)
|
||||
void
|
||||
lc_cipher_ctx_free(struct lc_cipher_ctx *ctx)
|
||||
{
|
||||
if (ctx != NULL) {
|
||||
if (ctx->impl != NULL && ctx->impl->ctx_free != NULL)
|
||||
ctx->impl->ctx_free(ctx->arg);
|
||||
if (ctx != NULL)
|
||||
free(ctx->arg);
|
||||
}
|
||||
free(ctx);
|
||||
}
|
||||
|
12
cipher.h
12
cipher.h
@ -20,22 +20,20 @@
|
||||
|
||||
struct lc_cipher_impl {
|
||||
int (*encrypt_init)(void *, void *);
|
||||
int (*encrypt_update)(void *, uint8_t *, size_t *,
|
||||
const uint8_t *, size_t);
|
||||
int (*encrypt_update)(void *, uint8_t *, size_t *, const uint8_t *,
|
||||
size_t);
|
||||
int (*encrypt_final)(void *, uint8_t *, size_t *);
|
||||
int (*encrypt)(uint8_t *, size_t *, void *, const uint8_t *,
|
||||
size_t);
|
||||
|
||||
int (*decrypt_init)(void *, void *);
|
||||
int (*decrypt_update)(void *, uint8_t *, size_t *,
|
||||
const uint8_t *, size_t);
|
||||
int (*decrypt_update)(void *, uint8_t *, size_t *, const uint8_t *,
|
||||
size_t);
|
||||
int (*decrypt_final)(void *, uint8_t *, size_t *);
|
||||
int (*decrypt)(uint8_t *, size_t *, void *, const uint8_t *,
|
||||
size_t);
|
||||
|
||||
void *(*ctx_new)(void);
|
||||
void (*ctx_free)(void *);
|
||||
|
||||
size_t argsz;
|
||||
size_t blocklen;
|
||||
};
|
||||
|
||||
|
@ -209,12 +209,6 @@ chacha20_anycrypt(uint8_t *out, size_t *outlen, void *initparams,
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void *
|
||||
chacha20_ctx_new(void)
|
||||
{
|
||||
return malloc(sizeof(struct chacha20_ctx));
|
||||
}
|
||||
|
||||
|
||||
static struct lc_cipher_impl chacha20_impl = {
|
||||
.encrypt_init = &chacha20_anycrypt_init,
|
||||
@ -227,9 +221,7 @@ static struct lc_cipher_impl chacha20_impl = {
|
||||
.decrypt_final = &chacha20_anycrypt_final,
|
||||
.decrypt = &chacha20_anycrypt,
|
||||
|
||||
.ctx_new = &chacha20_ctx_new,
|
||||
.ctx_free = NULL,
|
||||
|
||||
.argsz = sizeof(struct chacha20_ctx),
|
||||
.blocklen = LC_CHACHA20_BLOCKLEN,
|
||||
};
|
||||
|
||||
@ -244,9 +236,7 @@ static struct lc_cipher_impl xchacha20_impl = {
|
||||
.decrypt_final = &chacha20_anycrypt_final,
|
||||
.decrypt = &chacha20_anycrypt,
|
||||
|
||||
.ctx_new = &chacha20_ctx_new,
|
||||
.ctx_free = NULL,
|
||||
|
||||
.argsz = sizeof(struct chacha20_ctx),
|
||||
.blocklen = LC_XCHACHA20_BLOCKLEN,
|
||||
};
|
||||
|
||||
|
9
hash.c
9
hash.c
@ -54,8 +54,8 @@ lc_hash_ctx_new(const struct lc_hash_impl *impl)
|
||||
ctx = malloc(sizeof(*ctx));
|
||||
if (ctx == NULL)
|
||||
return NULL;
|
||||
if (impl->ctx_new != NULL) {
|
||||
ctx->arg = impl->ctx_new();
|
||||
if (impl->argsz > 0) {
|
||||
ctx->arg = malloc(impl->argsz);
|
||||
if (ctx->arg == NULL) {
|
||||
free(ctx);
|
||||
return NULL;
|
||||
@ -70,10 +70,7 @@ lc_hash_ctx_new(const struct lc_hash_impl *impl)
|
||||
void
|
||||
lc_hash_ctx_free(struct lc_hash_ctx *ctx)
|
||||
{
|
||||
if (ctx != NULL) {
|
||||
if (ctx->impl != NULL && ctx->impl->ctx_free != NULL)
|
||||
ctx->impl->ctx_free(ctx->arg);
|
||||
if (ctx != NULL)
|
||||
free(ctx->arg);
|
||||
}
|
||||
free(ctx);
|
||||
}
|
||||
|
4
hash.h
4
hash.h
@ -24,9 +24,7 @@ struct lc_hash_impl {
|
||||
int (*final)(void *, uint8_t *, size_t *);
|
||||
int (*hash)(uint8_t *, size_t *, const uint8_t *, size_t);
|
||||
|
||||
void *(*ctx_new)(void);
|
||||
void (*ctx_free)(void *);
|
||||
|
||||
size_t argsz;
|
||||
size_t blocklen;
|
||||
size_t hashlen;
|
||||
};
|
||||
|
@ -251,12 +251,6 @@ sha256_hash(uint8_t *out, size_t *outlen, const uint8_t *in, size_t inlen)
|
||||
sha256_final(&ctx, out, outlen);
|
||||
}
|
||||
|
||||
static void *
|
||||
sha224_sha256_ctx_new(void)
|
||||
{
|
||||
return malloc(sizeof(struct sha256_ctx));
|
||||
}
|
||||
|
||||
|
||||
static struct lc_hash_impl sha224_impl = {
|
||||
.init = &sha224_init,
|
||||
@ -264,9 +258,7 @@ static struct lc_hash_impl sha224_impl = {
|
||||
.final = &sha224_final,
|
||||
.hash = &sha224_hash,
|
||||
|
||||
.ctx_new = &sha224_sha256_ctx_new,
|
||||
.ctx_free = NULL,
|
||||
|
||||
.argsz = sizeof(struct sha256_ctx),
|
||||
.blocklen = LC_SHA224_BLOCKLEN,
|
||||
.hashlen = LC_SHA224_HASHLEN,
|
||||
};
|
||||
@ -277,9 +269,7 @@ static struct lc_hash_impl sha256_impl = {
|
||||
.final = &sha256_final,
|
||||
.hash = &sha256_hash,
|
||||
|
||||
.ctx_new = &sha224_sha256_ctx_new,
|
||||
.ctx_free = NULL,
|
||||
|
||||
.argsz = sizeof(struct sha256_ctx),
|
||||
.blocklen = LC_SHA256_BLOCKLEN,
|
||||
.hashlen = LC_SHA256_HASHLEN,
|
||||
};
|
||||
|
@ -256,12 +256,6 @@ sha512_hash(uint8_t *out, size_t *outlen, const uint8_t *in, size_t inlen)
|
||||
sha512_final(&ctx, out, outlen);
|
||||
}
|
||||
|
||||
static void *
|
||||
sha384_sha512_ctx_new(void)
|
||||
{
|
||||
return malloc(sizeof(struct sha512_ctx));
|
||||
}
|
||||
|
||||
|
||||
static struct lc_hash_impl sha384_impl = {
|
||||
.init = &sha384_init,
|
||||
@ -269,9 +263,7 @@ static struct lc_hash_impl sha384_impl = {
|
||||
.final = &sha384_final,
|
||||
.hash = &sha384_hash,
|
||||
|
||||
.ctx_new = &sha384_sha512_ctx_new,
|
||||
.ctx_free = NULL,
|
||||
|
||||
.argsz = sizeof(struct sha512_ctx),
|
||||
.blocklen = LC_SHA384_BLOCKLEN,
|
||||
.hashlen = LC_SHA384_HASHLEN,
|
||||
};
|
||||
@ -282,9 +274,7 @@ static struct lc_hash_impl sha512_impl = {
|
||||
.final = &sha512_final,
|
||||
.hash = &sha512_hash,
|
||||
|
||||
.ctx_new = &sha384_sha512_ctx_new,
|
||||
.ctx_free = NULL,
|
||||
|
||||
.argsz = sizeof(struct sha512_ctx),
|
||||
.blocklen = LC_SHA512_BLOCKLEN,
|
||||
.hashlen = LC_SHA512_HASHLEN,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user