summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Eremin-Solenikov <dbaryshkov@gmail.com>2019-10-17 16:38:40 +0300
committerDmitry Baryshkov <dbaryshkov@gmail.com>2020-06-07 00:59:24 +0300
commite4bc91220bce4e7e421f99ad652fd8fae8525141 (patch)
tree18ba0c04bf8be2b96f033c4d462ea48943d6eba4
parent45413cef9d86d94d6c6932c35926f185758a679c (diff)
downloadgnutls-e4bc91220bce4e7e421f99ad652fd8fae8525141.tar.gz
cipher/mac: enhance handlers with setkey callback
Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
-rw-r--r--lib/cipher_int.c2
-rw-r--r--lib/cipher_int.h9
-rw-r--r--lib/hash_int.c2
-rw-r--r--lib/hash_int.h9
4 files changed, 22 insertions, 0 deletions
diff --git a/lib/cipher_int.c b/lib/cipher_int.c
index b5308aa629..058fe7a6f8 100644
--- a/lib/cipher_int.c
+++ b/lib/cipher_int.c
@@ -102,6 +102,7 @@ _gnutls_cipher_init(cipher_hd_st *handle, const cipher_entry_st *e,
handle->tag = cc->tag;
handle->setiv = cc->setiv;
handle->getiv = cc->getiv;
+ handle->setkey = cc->setkey;
/* if cc->init() returns GNUTLS_E_NEED_FALLBACK we
* use the default ciphers */
@@ -128,6 +129,7 @@ _gnutls_cipher_init(cipher_hd_st *handle, const cipher_entry_st *e,
handle->tag = _gnutls_cipher_ops.tag;
handle->setiv = _gnutls_cipher_ops.setiv;
handle->getiv = _gnutls_cipher_ops.getiv;
+ handle->setkey = _gnutls_cipher_ops.setkey;
/* otherwise use generic cipher interface
*/
diff --git a/lib/cipher_int.h b/lib/cipher_int.h
index b50a59c64a..b06c397fc0 100644
--- a/lib/cipher_int.h
+++ b/lib/cipher_int.h
@@ -52,6 +52,8 @@ typedef int (*cipher_auth_func) (void *hd, const void *data, size_t);
typedef int (*cipher_setiv_func) (void *hd, const void *iv, size_t);
typedef int (*cipher_getiv_func) (void *hd, void *iv, size_t);
+typedef int (*cipher_setkey_func) (void *hd, const void *key, size_t keysize);
+
typedef void (*cipher_tag_func) (void *hd, void *tag, size_t);
typedef struct {
@@ -65,6 +67,7 @@ typedef struct {
cipher_tag_func tag;
cipher_setiv_func setiv;
cipher_getiv_func getiv;
+ cipher_setkey_func setkey;
cipher_deinit_func deinit;
} cipher_hd_st;
@@ -88,6 +91,12 @@ inline static int _gnutls_cipher_getiv(const cipher_hd_st * handle,
return handle->getiv(handle->handle, iv, ivlen);
}
+inline static int _gnutls_cipher_setkey(const cipher_hd_st * handle,
+ const void *key, size_t keylen)
+{
+ return handle->setkey(handle->handle, key, keylen);
+}
+
inline static int
_gnutls_cipher_encrypt2(const cipher_hd_st * handle, const void *text,
size_t textlen, void *ciphertext,
diff --git a/lib/hash_int.c b/lib/hash_int.c
index d326960e80..8c528d5f90 100644
--- a/lib/hash_int.c
+++ b/lib/hash_int.c
@@ -242,6 +242,7 @@ _gnutls_mac_init(mac_hd_st * mac, const mac_entry_st * e,
mac->output = cc->output;
mac->deinit = cc->deinit;
mac->copy = cc->copy;
+ mac->setkey = cc->setkey;
return 0;
}
@@ -257,6 +258,7 @@ _gnutls_mac_init(mac_hd_st * mac, const mac_entry_st * e,
mac->output = _gnutls_mac_ops.output;
mac->deinit = _gnutls_mac_ops.deinit;
mac->copy = _gnutls_mac_ops.copy;
+ mac->setkey = _gnutls_mac_ops.setkey;
if (_gnutls_mac_ops.setkey(mac->handle, key, keylen) < 0) {
gnutls_assert();
diff --git a/lib/hash_int.h b/lib/hash_int.h
index 9f6059da33..675ac4ef7f 100644
--- a/lib/hash_int.h
+++ b/lib/hash_int.h
@@ -42,6 +42,7 @@ typedef int (*output_func) (void *src_ctx, void *digest,
size_t digestsize);
typedef void (*hash_deinit_func) (void *handle);
typedef void *(*copy_func) (const void *handle);
+typedef int (*setkey_func) (void *handle, const void *key, size_t keysize);
typedef struct {
const mac_entry_st *e;
@@ -65,6 +66,7 @@ typedef struct {
output_func output;
hash_deinit_func deinit;
copy_func copy;
+ setkey_func setkey;
void *handle;
} mac_hd_st;
@@ -106,6 +108,13 @@ _gnutls_mac_set_nonce(mac_hd_st * handle, const void *nonce, size_t n_size)
return 0;
}
+inline static int
+_gnutls_mac_setkey(mac_hd_st * handle, const void *key, size_t key_size)
+{
+ return handle->setkey(handle->handle, key, key_size);
+}
+
+
void _gnutls_mac_deinit(mac_hd_st * handle, void *digest);
/* Hash interface */