1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-03 00:03:12 +02:00

api: add function crypto_hmac (issue #1628)

This commit is contained in:
Sébastien Helleu
2021-06-01 20:28:24 +02:00
parent 6ac6cf7293
commit 5cffb7179f
12 changed files with 434 additions and 29 deletions
+33
View File
@@ -162,6 +162,39 @@ plugin_api_crypto_hash_pbkdf2 (const void *data, int data_size,
iterations, hash, hash_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.
*/
+4
View File
@@ -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);
+1
View File
@@ -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;
+12 -1
View File
@@ -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) \