1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-06 17:53:13 +02:00

api: add function crypto_hash_pbkdf2

This commit is contained in:
Sébastien Helleu
2020-03-01 22:27:56 +01:00
parent 9a6a27ef58
commit 3157d1f06e
12 changed files with 293 additions and 11 deletions
+39
View File
@@ -138,6 +138,10 @@ plugin_api_string_base_decode (int base, const char *from, char *to)
/*
* Computes hash of data using the given algorithm.
*
* Returns:
* 1: OK
* 0: error
*/
int
@@ -162,6 +166,41 @@ plugin_api_crypto_hash (const void *data, int data_size, const char *hash_algo,
return weecrypto_hash (data, data_size, algo, hash, hash_size);
}
/*
* Computes PKCS#5 Passphrase Based Key Derivation Function number 2 (PBKDF2)
* hash of data.
*
* Returns:
* 1: OK
* 0: error
*/
int
plugin_api_crypto_hash_pbkdf2 (const void *data, int data_size,
const char *hash_algo,
const void *salt, int salt_size,
int iterations,
void *hash, int *hash_size)
{
int algo;
if (!hash)
return 0;
if (hash_size)
*hash_size = 0;
if (!data || (data_size < 1) || !hash_algo || !salt || (salt_size < 1))
return 0;
algo = weecrypto_get_hash_algo (hash_algo);
if (algo == GCRY_MD_NONE)
return 0;
return weecrypto_hash_pbkdf2 (data, data_size, algo, salt, salt_size,
iterations, hash, hash_size);
}
/*
* Frees an option.
*/
+5
View File
@@ -37,6 +37,11 @@ extern int plugin_api_string_base_decode (int base, const char *from,
extern int plugin_api_crypto_hash (const void *data, int data_size,
const char *hash_algo,
void *hash, int *hash_size);
extern int plugin_api_crypto_hash_pbkdf2 (const void *data, int data_size,
const char *hash_algo,
const void *salt, int salt_size,
int iterations,
void *hash, int *hash_size);
/* config */
extern void plugin_api_config_file_option_free (struct t_config_option *option);
+1
View File
@@ -650,6 +650,7 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv)
new_plugin->utf8_strndup = &utf8_strndup;
new_plugin->crypto_hash = &plugin_api_crypto_hash;
new_plugin->crypto_hash_pbkdf2 = &plugin_api_crypto_hash_pbkdf2;
new_plugin->mkdir_home = &util_mkdir_home;
new_plugin->mkdir = &util_mkdir;
+14 -1
View File
@@ -67,7 +67,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 "20200301-02"
#define WEECHAT_PLUGIN_API_VERSION "20200301-03"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@@ -375,6 +375,11 @@ struct t_weechat_plugin
/* crypto */
int (*crypto_hash) (const void *data, int data_size,
const char *hash_algo, void *hash, int *hash_size);
int (*crypto_hash_pbkdf2) (const void *data, int data_size,
const char *hash_algo,
const void *salt, int salt_size,
int iterations,
void *hash, int *hash_size);
/* directories/files */
int (*mkdir_home) (const char *directory, int mode);
@@ -1316,6 +1321,14 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
__hash, __hash_size) \
(weechat_plugin->crypto_hash)(__data, __data_size, __hash_algo, \
__hash, __hash_size)
#define weechat_crypto_hash_pbkdf2(__data, __data_size, __hash_algo, \
__salt, __salt_size, __iterations, \
__hash, __hash_size) \
(weechat_plugin->crypto_hash_pbkdf2)(__data, __data_size, \
__hash_algo, \
__salt, __salt_size, \
__iterations, \
__hash, __hash_size)
/* directories */
#define weechat_mkdir_home(__directory, __mode) \