1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-29 22:36:38 +02:00

core: add algorithms sha512-224, sha512-256, sha3-*, blake2b-* and blake2s-*` in option sec.crypt.hash_algo (closes #2008)

This commit is contained in:
Sébastien Helleu
2023-09-13 15:10:19 +02:00
parent 684bfd64c6
commit ef99d544fa
24 changed files with 1106 additions and 164 deletions
+19 -7
View File
@@ -25,7 +25,10 @@ extern "C"
{
#include <string.h>
#include <gcrypt.h>
#include "src/core/wee-config-file.h"
#include "src/core/wee-crypto.h"
#include "src/core/wee-secure.h"
#include "src/core/wee-secure-config.h"
#include "src/core/wee-string.h"
#define SECURE_PASSPHRASE "this_is_a_secret_passphrase"
@@ -88,17 +91,26 @@ TEST(CoreSecure, DeriveKey)
TEST(CoreSecure, EncryptDecryptData)
{
const char *password = SECURE_PASSWORD;
int hash_algo, cipher, rc;
int i, j, hash_algo, cipher, rc;
int length_password, length_encrypted_data, length_decrypted_data;
char *encrypted_data, *decrypted_data;
/* compute length of password, including the final \0 */
length_password = strlen (password) + 1;
for (hash_algo = 0; secure_hash_algo_string[hash_algo]; hash_algo++)
for (i = 0; i <= secure_config_crypt_hash_algo->max; i++)
{
for (cipher = 0; secure_cipher_string[cipher]; cipher++)
hash_algo = weecrypto_get_hash_algo (
secure_config_crypt_hash_algo->string_values[i]);
if (hash_algo == GCRY_MD_NONE)
continue;
for (j = 0; j <= secure_config_crypt_cipher->max; j++)
{
cipher = weecrypto_get_cipher (
secure_config_crypt_cipher->string_values[j]);
if (cipher == GCRY_CIPHER_NONE)
continue;
/* initialize data */
encrypted_data = NULL;
decrypted_data = NULL;
@@ -111,8 +123,8 @@ TEST(CoreSecure, EncryptDecryptData)
*/
rc = secure_encrypt_data (password,
length_password,
secure_hash_algo[hash_algo],
secure_cipher[cipher],
hash_algo,
cipher,
SECURE_PASSPHRASE,
&encrypted_data,
&length_encrypted_data);
@@ -121,8 +133,8 @@ TEST(CoreSecure, EncryptDecryptData)
/* decrypt the encrypted password */
rc = secure_decrypt_data (encrypted_data,
length_encrypted_data,
secure_hash_algo[hash_algo],
secure_cipher[cipher],
hash_algo,
cipher,
SECURE_PASSPHRASE,
&decrypted_data,
&length_decrypted_data);