Commit dc391344 authored by Geoff Simmons's avatar Geoff Simmons

Properly allocate the cipher handle for symmetric objects.

parent 2c4d27f9
......@@ -63,7 +63,7 @@
struct vmod_gcrypt_symmetric {
unsigned magic;
#define VMOD_GCRYPT_SYMMETRIC_MAGIC 0x82c7ffe2
gcry_cipher_hd_t *hd;
gcry_cipher_hd_t hd;
char *vcl_name;
size_t blocklen;
};
......@@ -117,7 +117,7 @@ vmod_symmetric__init(VRT_CTX, struct vmod_gcrypt_symmetric **symmetricp,
VCL_BOOL enable_sync, VCL_BOOL cbc_cts, VCL_BOOL cbc_mac)
{
struct vmod_gcrypt_symmetric *symmetric;
gcry_cipher_hd_t *hd = NULL;
gcry_cipher_hd_t hd;
int algo = GCRY_CIPHER_NONE, mode = GCRY_CIPHER_MODE_NONE;
unsigned int flags = 0;
gcry_error_t err = GPG_ERR_NO_ERROR;
......@@ -172,13 +172,13 @@ vmod_symmetric__init(VRT_CTX, struct vmod_gcrypt_symmetric **symmetricp,
if (cbc_mac)
flags |= GCRY_CIPHER_CBC_MAC;
if ((err = gcry_cipher_open(hd, algo, mode, flags))
if ((err = gcry_cipher_open(&hd, algo, mode, flags))
!= GPG_ERR_NO_ERROR) {
VERR(ctx, "Cannot open cipher in %s constructor: %s/%s",
vcl_name, gcry_strsource(err), gcry_strerror(err));
return;
}
if ((err = gcry_cipher_setkey(*hd, key->priv, key->len))
if ((err = gcry_cipher_setkey(hd, key->priv, key->len))
!= GPG_ERR_NO_ERROR) {
VERR(ctx, "Cannot set key in %s constructor: %s/%s",
vcl_name, gcry_strsource(err), gcry_strerror(err));
......@@ -186,7 +186,7 @@ vmod_symmetric__init(VRT_CTX, struct vmod_gcrypt_symmetric **symmetricp,
}
if (iv != NULL && iv->priv != NULL) {
assert(iv->len >= 0);
if ((err = gcry_cipher_setiv(*hd, iv->priv, iv->len))
if ((err = gcry_cipher_setiv(hd, iv->priv, iv->len))
!= GPG_ERR_NO_ERROR) {
VERR(ctx, "Cannot set initialization vector in %s "
"constructor: %s/%s", vcl_name,
......@@ -196,7 +196,7 @@ vmod_symmetric__init(VRT_CTX, struct vmod_gcrypt_symmetric **symmetricp,
}
if (ctr != NULL && ctr->priv != NULL) {
assert(ctr->len >= 0);
if ((err = gcry_cipher_setctr(*hd, ctr->priv, ctr->len))
if ((err = gcry_cipher_setctr(hd, ctr->priv, ctr->len))
!= GPG_ERR_NO_ERROR) {
VERR(ctx, "Cannot set counter vector in %s "
"constructor: %s/%s", vcl_name,
......@@ -208,7 +208,7 @@ vmod_symmetric__init(VRT_CTX, struct vmod_gcrypt_symmetric **symmetricp,
ALLOC_OBJ(symmetric, VMOD_GCRYPT_SYMMETRIC_MAGIC);
AN(symmetric);
*symmetricp = symmetric;
symmetric->hd = hd;
memcpy(&symmetric->hd, &hd, sizeof(hd));
symmetric->vcl_name = strdup(vcl_name);
AN(symmetric->vcl_name);
symmetric->blocklen = len;
......@@ -227,7 +227,7 @@ vmod_symmetric__fini(struct vmod_gcrypt_symmetric **symmetricp)
CHECK_OBJ(symmetric, VMOD_GCRYPT_SYMMETRIC_MAGIC);
if (symmetric->vcl_name != NULL)
free(symmetric->vcl_name);
gcry_cipher_close(*symmetric->hd);
gcry_cipher_close(symmetric->hd);
FREE_OBJ(symmetric);
}
......@@ -264,7 +264,7 @@ vmod_symmetric_encrypt(VRT_CTX, struct vmod_gcrypt_symmetric *symmetric,
return NULL;
}
if ((err = gcry_cipher_encrypt(*symmetric->hd, ciphertext->priv,
if ((err = gcry_cipher_encrypt(symmetric->hd, ciphertext->priv,
len, plaintext->priv, plaintext->len))
!= GPG_ERR_NO_ERROR) {
VERR(ctx, "in %s.encrypt: %s/%s", symmetric->vcl_name,
......@@ -307,7 +307,7 @@ vmod_symmetric_decrypt(VRT_CTX, struct vmod_gcrypt_symmetric *symmetric,
return NULL;
}
if ((err = gcry_cipher_decrypt(*symmetric->hd, plaintext->priv,
if ((err = gcry_cipher_decrypt(symmetric->hd, plaintext->priv,
ciphertext->len, ciphertext->priv,
ciphertext->len))
!= GPG_ERR_NO_ERROR) {
......
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