summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2021-06-01 20:28:24 +0200
committerSébastien Helleu <flashcode@flashtux.org>2021-06-01 20:39:04 +0200
commit5cffb7179fee6d70d5c8cee5b5c18ec51f1272f6 (patch)
tree9ed26ffd6cfd3d0e1dadfb83322e10b5eca04fce /src/plugins
parent6ac6cf729329559fa80ece1c057cb56fac81ff30 (diff)
downloadweechat-5cffb7179fee6d70d5c8cee5b5c18ec51f1272f6.zip
api: add function crypto_hmac (issue #1628)
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/plugin-api.c33
-rw-r--r--src/plugins/plugin-api.h4
-rw-r--r--src/plugins/plugin.c1
-rw-r--r--src/plugins/weechat-plugin.h13
4 files changed, 50 insertions, 1 deletions
diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c
index 95d46bf4c..2201eb4db 100644
--- a/src/plugins/plugin-api.c
+++ b/src/plugins/plugin-api.c
@@ -163,6 +163,39 @@ plugin_api_crypto_hash_pbkdf2 (const void *data, int data_size,
}
/*
+ * Computes HMAC of key + message using the given algorithm.
+ *
+ * Returns:
+ * 1: OK
+ * 0: error
+ */
+
+int
+plugin_api_crypto_hmac (const void *key, int key_size,
+ const void *message, int message_size,
+ const char *hash_algo,
+ void *hash, int *hash_size)
+{
+ int algo;
+
+ if (!hash)
+ return 0;
+
+ if (hash_size)
+ *hash_size = 0;
+
+ if (!key || (key_size < 1) || !message || (message_size < 1) || !hash_algo)
+ return 0;
+
+ algo = weecrypto_get_hash_algo (hash_algo);
+ if (algo == GCRY_MD_NONE)
+ return 0;
+
+ return weecrypto_hmac (key, key_size, message, message_size,
+ algo, hash, hash_size);
+}
+
+/*
* Frees an option.
*/
diff --git a/src/plugins/plugin-api.h b/src/plugins/plugin-api.h
index b8d377017..e266b5c69 100644
--- a/src/plugins/plugin-api.h
+++ b/src/plugins/plugin-api.h
@@ -38,6 +38,10 @@ extern int plugin_api_crypto_hash_pbkdf2 (const void *data, int data_size,
const void *salt, int salt_size,
int iterations,
void *hash, int *hash_size);
+extern int plugin_api_crypto_hmac (const void *key, int key_size,
+ const void *message, int message_size,
+ const char *hash_algo,
+ void *hash, int *hash_size);
/* config */
extern void plugin_api_config_file_option_free (struct t_config_option *option);
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index 26cbff783..6254b613b 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -665,6 +665,7 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv)
new_plugin->crypto_hash = &plugin_api_crypto_hash;
new_plugin->crypto_hash_pbkdf2 = &plugin_api_crypto_hash_pbkdf2;
+ new_plugin->crypto_hmac = &plugin_api_crypto_hmac;
new_plugin->mkdir_home = &dir_mkdir_home;
new_plugin->mkdir = &dir_mkdir;
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index a261d8f44..9eb42f7e9 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -68,7 +68,7 @@ struct timeval;
* please change the date with current one; for a second change at same
* date, increment the 01, otherwise please keep 01.
*/
-#define WEECHAT_PLUGIN_API_VERSION "20201004-01"
+#define WEECHAT_PLUGIN_API_VERSION "20210601-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@@ -382,6 +382,9 @@ struct t_weechat_plugin
const void *salt, int salt_size,
int iterations,
void *hash, int *hash_size);
+ int (*crypto_hmac) (const void *key, int key_size,
+ const void *message, int message_size,
+ const char *hash_algo, void *hash, int *hash_size);
/* directories/files */
int (*mkdir_home) (const char *directory, int mode);
@@ -1347,6 +1350,14 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
__salt, __salt_size, \
__iterations, \
__hash, __hash_size)
+#define weechat_crypto_hmac(__key, __key_size, \
+ __message, __message_size, \
+ __hash_algo, \
+ __hash, __hash_size) \
+ (weechat_plugin->crypto_hmac)(__key, __key_size, \
+ __message, __message_size, \
+ __hash_algo, \
+ __hash, __hash_size)
/* directories */
#define weechat_mkdir_home(__directory, __mode) \