]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
cipher/mac: enhance handlers with setkey callback
authorDmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Thu, 17 Oct 2019 13:38:40 +0000 (16:38 +0300)
committerDmitry Baryshkov <dbaryshkov@gmail.com>
Sat, 6 Jun 2020 21:59:24 +0000 (00:59 +0300)
Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
lib/cipher_int.c
lib/cipher_int.h
lib/hash_int.c
lib/hash_int.h

index b5308aa6290ead7653b9e737c038bebfd1d3fea4..058fe7a6f8ecb626dd81522a08affd7e74401ede 100644 (file)
@@ -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
         */
index b50a59c64ad69dc82ad60392af3e28fc02186a47..b06c397fc08c327d712a10a66addd3f8ec77ffae 100644 (file)
@@ -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,
index d326960e8078d901446f28210df3929032a79273..8c528d5f9034117f33be416078a4b2b5e2b6b83c 100644 (file)
@@ -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();
index 9f6059da33745ab2b436a5e099e9ff7fe64f749e..675ac4ef7fb5ed643b57a6024d9ad9d25cc4bd4e 100644 (file)
@@ -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 */