diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2023-09-10 14:02:58 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-09-13 15:09:34 +0200 |
commit | 684bfd64c6893d12b6a4f82fe61e33e7d14e0a4d (patch) | |
tree | 21e8df9781cd283b0f34e0710a98ed5b7d121b0e | |
parent | 29c4aa4620288991a1baf75a95e42dadb1cdf5dd (diff) | |
download | weechat-684bfd64c6893d12b6a4f82fe61e33e7d14e0a4d.zip |
api: add algorithms `sha512-224`, `sha512-256`, blake2b-*` and `blake2s-*` in hash functions (issue #2008)
-rw-r--r-- | ChangeLog.adoc | 1 | ||||
-rw-r--r-- | doc/en/weechat_plugin_api.en.adoc | 34 | ||||
-rw-r--r-- | doc/fr/weechat_plugin_api.fr.adoc | 34 | ||||
-rw-r--r-- | doc/it/weechat_plugin_api.it.adoc | 34 | ||||
-rw-r--r-- | doc/ja/weechat_plugin_api.ja.adoc | 34 | ||||
-rw-r--r-- | doc/sr/weechat_plugin_api.sr.adoc | 34 | ||||
-rw-r--r-- | src/core/wee-crypto.c | 144 | ||||
-rw-r--r-- | tests/unit/core/test-core-crypto.cpp | 68 |
8 files changed, 286 insertions, 97 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc index bbca1cc4d..7474d3a91 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -27,6 +27,7 @@ New features:: * core: add options weechat.buffer.* to save buffer properties set by user, add option `setauto` in command `/buffer` (issue #352) * core: add parameters and key bindings to move to edges of current area with commands `/cursor go` and `/cursor move` (issue #1282) * core: add variables "_chat_focused_line_bol" and "_chat_focused_line_eol" in focus data (issue #1955) + * api: add algorithms `sha512-224`, `sha512-256`, blake2b-*` and `blake2s-*` in hash functions (issue #2008) * api: add support of path to variable and hashtable comparison in function hdata_compare (issue #1066) * api: add infos "nick_color_ignore_case" and "nick_color_name_ignore_case" (issue #194) * api: add info "buffer" (issue #1962) diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc index 5ea06d649..da0f8bda2 100644 --- a/doc/en/weechat_plugin_api.en.adoc +++ b/doc/en/weechat_plugin_api.en.adoc @@ -4028,18 +4028,28 @@ Supported hash algorithms: [width="100%",cols="2,2,3,6",options="header"] |=== -| Value | Algorithm | Hash size | Notes -| `+crc32+` | CRC32 | 4 bytes (32 bits) | Not a hash algorithm in the cryptographic sense. -| `+md5+` | MD5 | 16 bytes (128 bits) | *Weak*, not recommended for cryptography usage. -| `+sha1+` | SHA-1 | 20 bytes (160 bits) | *Weak*, not recommended for cryptography usage. -| `+sha224+` | SHA-224 | 28 bytes (224 bits) | -| `+sha256+` | SHA-256 | 32 bytes (256 bits) | -| `+sha384+` | SHA-384 | 48 bytes (384 bits) | -| `+sha512+` | SHA-512 | 64 bytes (512 bits) | -| `+sha3-224+` | SHA3-224 | 28 bytes (224 bits) | Algorithm available with libgcrypt ≥ 1.7.0. -| `+sha3-256+` | SHA3-256 | 32 bytes (256 bits) | Algorithm available with libgcrypt ≥ 1.7.0. -| `+sha3-384+` | SHA3-384 | 48 bytes (384 bits) | Algorithm available with libgcrypt ≥ 1.7.0. -| `+sha3-512+` | SHA3-512 | 64 bytes (512 bits) | Algorithm available with libgcrypt ≥ 1.7.0. +| Value | Algorithm | Hash size | Notes +| `+crc32+` | CRC32 | 4 bytes (32 bits) | Not a hash algorithm in the cryptographic sense. +| `+md5+` | MD5 | 16 bytes (128 bits) | *Weak*, not recommended for cryptography usage. +| `+sha1+` | SHA-1 | 20 bytes (160 bits) | *Weak*, not recommended for cryptography usage. +| `+sha224+` | SHA-224 | 28 bytes (224 bits) | +| `+sha256+` | SHA-256 | 32 bytes (256 bits) | +| `+sha384+` | SHA-384 | 48 bytes (384 bits) | +| `+sha512+` | SHA-512 | 64 bytes (512 bits) | +| `+sha512-224+` | SHA-512/224 | 28 bytes (224 bits) | Algorithm available with libgcrypt ≥ 1.9.4. +| `+sha512-256+` | SHA-512/256 | 32 bytes (256 bits) | Algorithm available with libgcrypt ≥ 1.9.4. +| `+sha3-224+` | SHA3-224 | 28 bytes (224 bits) | Algorithm available with libgcrypt ≥ 1.7.0. +| `+sha3-256+` | SHA3-256 | 32 bytes (256 bits) | Algorithm available with libgcrypt ≥ 1.7.0. +| `+sha3-384+` | SHA3-384 | 48 bytes (384 bits) | Algorithm available with libgcrypt ≥ 1.7.0. +| `+sha3-512+` | SHA3-512 | 64 bytes (512 bits) | Algorithm available with libgcrypt ≥ 1.7.0. +| `+blake2b-160+` | BLAKE2B-160 | 20 bytes (160 bits) | Algorithm available with libgcrypt ≥ 1.8.0. +| `+blake2b-256+` | BLAKE2B-256 | 32 bytes (256 bits) | Algorithm available with libgcrypt ≥ 1.8.0. +| `+blake2b-384+` | BLAKE2B-384 | 48 bytes (384 bits) | Algorithm available with libgcrypt ≥ 1.8.0. +| `+blake2b-512+` | BLAKE2B-512 | 64 bytes (512 bits) | Algorithm available with libgcrypt ≥ 1.8.0. +| `+blake2s-128+` | BLAKE2S-128 | 16 bytes (128 bits) | Algorithm available with libgcrypt ≥ 1.8.0. +| `+blake2s-160+` | BLAKE2S-160 | 20 bytes (160 bits) | Algorithm available with libgcrypt ≥ 1.8.0. +| `+blake2s-224+` | BLAKE2S-224 | 28 bytes (224 bits) | Algorithm available with libgcrypt ≥ 1.8.0. +| `+blake2s-256+` | BLAKE2S-256 | 32 bytes (256 bits) | Algorithm available with libgcrypt ≥ 1.8.0. |=== Return value: diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc index 111a3362b..cd4bdc33f 100644 --- a/doc/fr/weechat_plugin_api.fr.adoc +++ b/doc/fr/weechat_plugin_api.fr.adoc @@ -4100,18 +4100,28 @@ Algorithmes de hachage supportés : [width="100%",cols="2,2,3,6",options="header"] |=== -| Valeur | Algorithme | Taille du haché | Notes -| `+crc32+` | CRC32 | 4 octets (32 bits) | Pas un algorithme de hachage au sens cryptographique. -| `+md5+` | MD5 | 16 octets (128 bits) | *Faible*, non recommandé pour un usage cryptographique. -| `+sha1+` | SHA-1 | 20 octets (160 bits) | *Faible*, non recommandé pour un usage cryptographique. -| `+sha224+` | SHA-224 | 28 octets (224 bits) | -| `+sha256+` | SHA-256 | 32 octets (256 bits) | -| `+sha384+` | SHA-384 | 48 octets (384 bits) | -| `+sha512+` | SHA-512 | 64 octets (512 bits) | -| `+sha3-224+` | SHA3-224 | 28 octets (224 bits) | Algorithme disponible avec libgcrypt ≥ 1.7.0. -| `+sha3-256+` | SHA3-256 | 32 octets (256 bits) | Algorithme disponible avec libgcrypt ≥ 1.7.0. -| `+sha3-384+` | SHA3-384 | 48 octets (384 bits) | Algorithme disponible avec libgcrypt ≥ 1.7.0. -| `+sha3-512+` | SHA3-512 | 64 octets (512 bits) | Algorithme disponible avec libgcrypt ≥ 1.7.0. +| Valeur | Algorithme | Taille du haché | Notes +| `+crc32+` | CRC32 | 4 octets (32 bits) | Pas un algorithme de hachage au sens cryptographique. +| `+md5+` | MD5 | 16 octets (128 bits) | *Faible*, non recommandé pour un usage cryptographique. +| `+sha1+` | SHA-1 | 20 octets (160 bits) | *Faible*, non recommandé pour un usage cryptographique. +| `+sha224+` | SHA-224 | 28 octets (224 bits) | +| `+sha256+` | SHA-256 | 32 octets (256 bits) | +| `+sha384+` | SHA-384 | 48 octets (384 bits) | +| `+sha512+` | SHA-512 | 64 octets (512 bits) | +| `+sha512-224+` | SHA-512/224 | 28 octets (224 bits) | Algorithme disponible avec libgcrypt ≥ 1.9.4. +| `+sha512-256+` | SHA-512/256 | 32 octets (256 bits) | Algorithme disponible avec libgcrypt ≥ 1.9.4. +| `+sha3-224+` | SHA3-224 | 28 octets (224 bits) | Algorithme disponible avec libgcrypt ≥ 1.7.0. +| `+sha3-256+` | SHA3-256 | 32 octets (256 bits) | Algorithme disponible avec libgcrypt ≥ 1.7.0. +| `+sha3-384+` | SHA3-384 | 48 octets (384 bits) | Algorithme disponible avec libgcrypt ≥ 1.7.0. +| `+sha3-512+` | SHA3-512 | 64 octets (512 bits) | Algorithme disponible avec libgcrypt ≥ 1.7.0. +| `+blake2b-160+` | BLAKE2B-160 | 20 octets (160 bits) | Algorithme disponible avec libgcrypt ≥ 1.8.0. +| `+blake2b-256+` | BLAKE2B-256 | 32 octets (256 bits) | Algorithme disponible avec libgcrypt ≥ 1.8.0. +| `+blake2b-384+` | BLAKE2B-384 | 48 octets (384 bits) | Algorithme disponible avec libgcrypt ≥ 1.8.0. +| `+blake2b-512+` | BLAKE2B-512 | 64 octets (512 bits) | Algorithme disponible avec libgcrypt ≥ 1.8.0. +| `+blake2s-128+` | BLAKE2S-128 | 16 octets (128 bits) | Algorithme disponible avec libgcrypt ≥ 1.8.0. +| `+blake2s-160+` | BLAKE2S-160 | 20 octets (160 bits) | Algorithme disponible avec libgcrypt ≥ 1.8.0. +| `+blake2s-224+` | BLAKE2S-224 | 28 octets (224 bits) | Algorithme disponible avec libgcrypt ≥ 1.8.0. +| `+blake2s-256+` | BLAKE2S-256 | 32 octets (256 bits) | Algorithme disponible avec libgcrypt ≥ 1.8.0. |=== Valeur de retour : diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc index 874a5909e..4b998b0f2 100644 --- a/doc/it/weechat_plugin_api.it.adoc +++ b/doc/it/weechat_plugin_api.it.adoc @@ -4219,18 +4219,28 @@ Supported hash algorithms: [width="100%",cols="2,2,3,6",options="header"] |=== -| Value | Algorithm | Hash size | Notes -| `+crc32+` | CRC32 | 4 bytes (32 bits) | Not a hash algorithm in the cryptographic sense. -| `+md5+` | MD5 | 16 bytes (128 bits) | *Weak*, not recommended for cryptography usage. -| `+sha1+` | SHA-1 | 20 bytes (160 bits) | *Weak*, not recommended for cryptography usage. -| `+sha224+` | SHA-224 | 28 bytes (224 bits) | -| `+sha256+` | SHA-256 | 32 bytes (256 bits) | -| `+sha384+` | SHA-384 | 48 bytes (384 bits) | -| `+sha512+` | SHA-512 | 64 bytes (512 bits) | -| `+sha3-224+` | SHA3-224 | 28 bytes (224 bits) | Algorithm available with libgcrypt ≥ 1.7.0. -| `+sha3-256+` | SHA3-256 | 32 bytes (256 bits) | Algorithm available with libgcrypt ≥ 1.7.0. -| `+sha3-384+` | SHA3-384 | 48 bytes (384 bits) | Algorithm available with libgcrypt ≥ 1.7.0. -| `+sha3-512+` | SHA3-512 | 64 bytes (512 bits) | Algorithm available with libgcrypt ≥ 1.7.0. +| Value | Algorithm | Hash size | Notes +| `+crc32+` | CRC32 | 4 bytes (32 bits) | Not a hash algorithm in the cryptographic sense. +| `+md5+` | MD5 | 16 bytes (128 bits) | *Weak*, not recommended for cryptography usage. +| `+sha1+` | SHA-1 | 20 bytes (160 bits) | *Weak*, not recommended for cryptography usage. +| `+sha224+` | SHA-224 | 28 bytes (224 bits) | +| `+sha256+` | SHA-256 | 32 bytes (256 bits) | +| `+sha384+` | SHA-384 | 48 bytes (384 bits) | +| `+sha512+` | SHA-512 | 64 bytes (512 bits) | +| `+sha512-224+` | SHA-512/224 | 28 bytes (224 bits) | Algorithm available with libgcrypt ≥ 1.9.4. +| `+sha512-256+` | SHA-512/256 | 32 bytes (256 bits) | Algorithm available with libgcrypt ≥ 1.9.4. +| `+sha3-224+` | SHA3-224 | 28 bytes (224 bits) | Algorithm available with libgcrypt ≥ 1.7.0. +| `+sha3-256+` | SHA3-256 | 32 bytes (256 bits) | Algorithm available with libgcrypt ≥ 1.7.0. +| `+sha3-384+` | SHA3-384 | 48 bytes (384 bits) | Algorithm available with libgcrypt ≥ 1.7.0. +| `+sha3-512+` | SHA3-512 | 64 bytes (512 bits) | Algorithm available with libgcrypt ≥ 1.7.0. +| `+blake2b-160+` | BLAKE2B-160 | 20 bytes (160 bits) | Algorithm available with libgcrypt ≥ 1.8.0. +| `+blake2b-256+` | BLAKE2B-256 | 32 bytes (256 bits) | Algorithm available with libgcrypt ≥ 1.8.0. +| `+blake2b-384+` | BLAKE2B-384 | 48 bytes (384 bits) | Algorithm available with libgcrypt ≥ 1.8.0. +| `+blake2b-512+` | BLAKE2B-512 | 64 bytes (512 bits) | Algorithm available with libgcrypt ≥ 1.8.0. +| `+blake2s-128+` | BLAKE2S-128 | 16 bytes (128 bits) | Algorithm available with libgcrypt ≥ 1.8.0. +| `+blake2s-160+` | BLAKE2S-160 | 20 bytes (160 bits) | Algorithm available with libgcrypt ≥ 1.8.0. +| `+blake2s-224+` | BLAKE2S-224 | 28 bytes (224 bits) | Algorithm available with libgcrypt ≥ 1.8.0. +| `+blake2s-256+` | BLAKE2S-256 | 32 bytes (256 bits) | Algorithm available with libgcrypt ≥ 1.8.0. |=== Valore restituito: diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc index cdce16dcf..cea431ebb 100644 --- a/doc/ja/weechat_plugin_api.ja.adoc +++ b/doc/ja/weechat_plugin_api.ja.adoc @@ -4141,18 +4141,28 @@ Supported hash algorithms: [width="100%",cols="2,2,3,6",options="header"] |=== -| Value | Algorithm | Hash size | Notes -| `+crc32+` | CRC32 | 4 bytes (32 bits) | Not a hash algorithm in the cryptographic sense. -| `+md5+` | MD5 | 16 bytes (128 bits) | *Weak*, not recommended for cryptography usage. -| `+sha1+` | SHA-1 | 20 bytes (160 bits) | *Weak*, not recommended for cryptography usage. -| `+sha224+` | SHA-224 | 28 bytes (224 bits) | -| `+sha256+` | SHA-256 | 32 bytes (256 bits) | -| `+sha384+` | SHA-384 | 48 bytes (384 bits) | -| `+sha512+` | SHA-512 | 64 bytes (512 bits) | -| `+sha3-224+` | SHA3-224 | 28 bytes (224 bits) | Algorithm available with libgcrypt ≥ 1.7.0. -| `+sha3-256+` | SHA3-256 | 32 bytes (256 bits) | Algorithm available with libgcrypt ≥ 1.7.0. -| `+sha3-384+` | SHA3-384 | 48 bytes (384 bits) | Algorithm available with libgcrypt ≥ 1.7.0. -| `+sha3-512+` | SHA3-512 | 64 bytes (512 bits) | Algorithm available with libgcrypt ≥ 1.7.0. +| Value | Algorithm | Hash size | Notes +| `+crc32+` | CRC32 | 4 bytes (32 bits) | Not a hash algorithm in the cryptographic sense. +| `+md5+` | MD5 | 16 bytes (128 bits) | *Weak*, not recommended for cryptography usage. +| `+sha1+` | SHA-1 | 20 bytes (160 bits) | *Weak*, not recommended for cryptography usage. +| `+sha224+` | SHA-224 | 28 bytes (224 bits) | +| `+sha256+` | SHA-256 | 32 bytes (256 bits) | +| `+sha384+` | SHA-384 | 48 bytes (384 bits) | +| `+sha512+` | SHA-512 | 64 bytes (512 bits) | +| `+sha512-224+` | SHA-512/224 | 28 bytes (224 bits) | Algorithm available with libgcrypt ≥ 1.9.4. +| `+sha512-256+` | SHA-512/256 | 32 bytes (256 bits) | Algorithm available with libgcrypt ≥ 1.9.4. +| `+sha3-224+` | SHA3-224 | 28 bytes (224 bits) | Algorithm available with libgcrypt ≥ 1.7.0. +| `+sha3-256+` | SHA3-256 | 32 bytes (256 bits) | Algorithm available with libgcrypt ≥ 1.7.0. +| `+sha3-384+` | SHA3-384 | 48 bytes (384 bits) | Algorithm available with libgcrypt ≥ 1.7.0. +| `+sha3-512+` | SHA3-512 | 64 bytes (512 bits) | Algorithm available with libgcrypt ≥ 1.7.0. +| `+blake2b-160+` | BLAKE2B-160 | 20 bytes (160 bits) | Algorithm available with libgcrypt ≥ 1.8.0. +| `+blake2b-256+` | BLAKE2B-256 | 32 bytes (256 bits) | Algorithm available with libgcrypt ≥ 1.8.0. +| `+blake2b-384+` | BLAKE2B-384 | 48 bytes (384 bits) | Algorithm available with libgcrypt ≥ 1.8.0. +| `+blake2b-512+` | BLAKE2B-512 | 64 bytes (512 bits) | Algorithm available with libgcrypt ≥ 1.8.0. +| `+blake2s-128+` | BLAKE2S-128 | 16 bytes (128 bits) | Algorithm available with libgcrypt ≥ 1.8.0. +| `+blake2s-160+` | BLAKE2S-160 | 20 bytes (160 bits) | Algorithm available with libgcrypt ≥ 1.8.0. +| `+blake2s-224+` | BLAKE2S-224 | 28 bytes (224 bits) | Algorithm available with libgcrypt ≥ 1.8.0. +| `+blake2s-256+` | BLAKE2S-256 | 32 bytes (256 bits) | Algorithm available with libgcrypt ≥ 1.8.0. |=== 戻り値: diff --git a/doc/sr/weechat_plugin_api.sr.adoc b/doc/sr/weechat_plugin_api.sr.adoc index 62f7cd707..c2bc5a982 100644 --- a/doc/sr/weechat_plugin_api.sr.adoc +++ b/doc/sr/weechat_plugin_api.sr.adoc @@ -3901,18 +3901,28 @@ int weechat_crypto_hash (const void *data, int data_size, const char *hash_algo, [width="100%", cols="2,2,3,6", options="header"] |=== -| Вредност | Алгоритам | Величина хеша | Напомене -| `+crc32+` | CRC32 | 4 бајта (32 бита) | Није хеш алгоритам у криптографском смислу. -| `+md5+` | MD5 | 16 бајтова (128 бита) | *Слаб*, не препоручује се за криптографску употребу. -| `+sha1+` | SHA-1 | 20 бајтова (160 бита) | *Слаб*, не препоручује се за криптографску употребу. -| `+sha224+` | SHA-224 | 28 бајтова (224 бита) | -| `+sha256+` | SHA-256 | 32 бајта (256 бита) | -| `+sha384+` | SHA-384 | 48 бајтова (384 бита) | -| `+sha512+` | SHA-512 | 64 бајта (512 бита) | -| `+sha3-224+` | SHA3-224 | 28 бајтова (224 бита) | Алгоритам је доступан у libgcrypt ≥ 1.7.0. -| `+sha3-256+` | SHA3-256 | 32 бајта (256 бита) | Алгоритам је доступан у libgcrypt ≥ 1.7.0. -| `+sha3-384+` | SHA3-384 | 48 бајтова (384 бита) | Алгоритам је доступан у libgcrypt ≥ 1.7.0. -| `+sha3-512+` | SHA3-512 | 64 бајта (512 бита) | Алгоритам је доступан у libgcrypt ≥ 1.7.0. +| Вредност | Алгоритам | Величина хеша | Напомене +| `+crc32+` | CRC32 | 4 бајта (32 бита) | Није хеш алгоритам у криптографском смислу. +| `+md5+` | MD5 | 16 бајтова (128 бита) | *Слаб*, не препоручује се за криптографску употребу. +| `+sha1+` | SHA-1 | 20 бајтова (160 бита) | *Слаб*, не препоручује се за криптографску употребу. +| `+sha224+` | SHA-224 | 28 бајтова (224 бита) | +| `+sha256+` | SHA-256 | 32 бајта (256 бита) | +| `+sha384+` | SHA-384 | 48 бајтова (384 бита) | +| `+sha512+` | SHA-512 | 64 бајта (512 бита) | +| `+sha512-224+` | SHA-512/224 | 28 бајтова (224 бита) | Алгоритам је доступан у libgcrypt ≥ 1.9.4. +| `+sha512-256+` | SHA-512/256 | 32 бајта (256 бита) | Алгоритам је доступан у libgcrypt ≥ 1.9.4. +| `+sha3-224+` | SHA3-224 | 28 бајтова (224 бита) | Алгоритам је доступан у libgcrypt ≥ 1.7.0. +| `+sha3-256+` | SHA3-256 | 32 бајта (256 бита) | Алгоритам је доступан у libgcrypt ≥ 1.7.0. +| `+sha3-384+` | SHA3-384 | 48 бајтова (384 бита) | Алгоритам је доступан у libgcrypt ≥ 1.7.0. +| `+sha3-512+` | SHA3-512 | 64 бајта (512 бита) | Алгоритам је доступан у libgcrypt ≥ 1.7.0. +| `+blake2b-160+` | BLAKE2B-160 | 20 бајтова (160 бита) | Алгоритам је доступан у libgcrypt ≥ 1.8.0. +| `+blake2b-256+` | BLAKE2B-256 | 32 бајта (256 бита) | Алгоритам је доступан у libgcrypt ≥ 1.8.0. +| `+blake2b-384+` | BLAKE2B-384 | 48 бајтова (384 бита) | Алгоритам је доступан у libgcrypt ≥ 1.8.0. +| `+blake2b-512+` | BLAKE2B-512 | 64 бајта (512 бита) | Алгоритам је доступан у libgcrypt ≥ 1.8.0. +| `+blake2s-128+` | BLAKE2S-128 | 16 бајтова (128 бита) | Алгоритам је доступан у libgcrypt ≥ 1.8.0. +| `+blake2s-160+` | BLAKE2S-160 | 20 бајтова (160 бита) | Алгоритам је доступан у libgcrypt ≥ 1.8.0. +| `+blake2s-224+` | BLAKE2S-224 | 28 бајтова (224 бита) | Алгоритам је доступан у libgcrypt ≥ 1.8.0. +| `+blake2s-256+` | BLAKE2S-256 | 32 бајта (256 бита) ) | Алгоритам је доступан у libgcrypt ≥ 1.8.0. |=== Повратна вредност: diff --git a/src/core/wee-crypto.c b/src/core/wee-crypto.c index 3b86f5def..77d1629c9 100644 --- a/src/core/wee-crypto.c +++ b/src/core/wee-crypto.c @@ -42,9 +42,29 @@ char *weecrypto_hash_algo_string[] = { "crc32", "md5", "sha1", - "sha224", "sha256", "sha384", "sha512", + "sha224", + "sha256", + "sha384", + "sha512", #if GCRYPT_VERSION_NUMBER >= 0x010700 - "sha3-224", "sha3-256", "sha3-384", "sha3-512", + "sha3-224", + "sha3-256", + "sha3-384", + "sha3-512", +#endif +#if GCRYPT_VERSION_NUMBER >= 0x010800 + "blake2b-160", + "blake2b-256", + "blake2b-384", + "blake2b-512", + "blake2s-128", + "blake2s-160", + "blake2s-224", + "blake2s-256", +#endif +#if GCRYPT_VERSION_NUMBER >= 0x010904 + "sha512-224", + "sha512-256", #endif NULL, }; @@ -52,9 +72,29 @@ int weecrypto_hash_algo[] = { GCRY_MD_CRC32, GCRY_MD_MD5, GCRY_MD_SHA1, - GCRY_MD_SHA224, GCRY_MD_SHA256, GCRY_MD_SHA384, GCRY_MD_SHA512, + GCRY_MD_SHA224, + GCRY_MD_SHA256, + GCRY_MD_SHA384, + GCRY_MD_SHA512, #if GCRYPT_VERSION_NUMBER >= 0x010700 - GCRY_MD_SHA3_224, GCRY_MD_SHA3_256, GCRY_MD_SHA3_384, GCRY_MD_SHA3_512, + GCRY_MD_SHA3_224, + GCRY_MD_SHA3_256, + GCRY_MD_SHA3_384, + GCRY_MD_SHA3_512, +#endif +#if GCRYPT_VERSION_NUMBER >= 0x010800 + GCRY_MD_BLAKE2B_160, + GCRY_MD_BLAKE2B_256, + GCRY_MD_BLAKE2B_384, + GCRY_MD_BLAKE2B_512, + GCRY_MD_BLAKE2S_128, + GCRY_MD_BLAKE2S_160, + GCRY_MD_BLAKE2S_224, + GCRY_MD_BLAKE2S_256, +#endif +#if GCRYPT_VERSION_NUMBER >= 0x010904 + GCRY_MD_SHA512_224, + GCRY_MD_SHA512_256, #endif }; @@ -85,17 +125,27 @@ weecrypto_get_hash_algo (const char *hash_algo) * * The hash size depends on the algorithm, common ones are: * - * GCRY_MD_CRC32 32 bits == 4 bytes - * GCRY_MD_MD5 128 bits == 16 bytes - * GCRY_MD_SHA1 160 bits == 20 bytes - * GCRY_MD_SHA224 224 bits == 28 bytes - * GCRY_MD_SHA256 256 bits == 32 bytes - * GCRY_MD_SHA384 384 bits == 48 bytes - * GCRY_MD_SHA512 512 bits == 64 bytes - * GCRY_MD_SHA3_224 224 bits == 28 bytes (libgcrypt ≥ 1.7.0) - * GCRY_MD_SHA3_256 256 bits == 32 bytes (libgcrypt ≥ 1.7.0) - * GCRY_MD_SHA3_384 384 bits == 48 bytes (libgcrypt ≥ 1.7.0) - * GCRY_MD_SHA3_512 512 bits == 64 bytes (libgcrypt ≥ 1.7.0) + * GCRY_MD_CRC32 32 bits == 4 bytes + * GCRY_MD_MD5 128 bits == 16 bytes + * GCRY_MD_SHA1 160 bits == 20 bytes + * GCRY_MD_SHA224 224 bits == 28 bytes + * GCRY_MD_SHA256 256 bits == 32 bytes + * GCRY_MD_SHA384 384 bits == 48 bytes + * GCRY_MD_SHA512 512 bits == 64 bytes + * GCRY_MD_SHA512_256 256 bits == 32 bytes (libgcrypt ≥ 1.9.4) + * GCRY_MD_SHA512_224 224 bits == 28 bytes (libgcrypt ≥ 1.9.4) + * GCRY_MD_SHA3_224 224 bits == 28 bytes (libgcrypt ≥ 1.7.0) + * GCRY_MD_SHA3_256 256 bits == 32 bytes (libgcrypt ≥ 1.7.0) + * GCRY_MD_SHA3_384 384 bits == 48 bytes (libgcrypt ≥ 1.7.0) + * GCRY_MD_SHA3_512 512 bits == 64 bytes (libgcrypt ≥ 1.7.0) + * GCRY_MD_BLAKE2B_160 160 bits == 20 bytes (libgcrypt ≥ 1.8.0) + * GCRY_MD_BLAKE2B_256 256 bits == 32 bytes (libgcrypt ≥ 1.8.0) + * GCRY_MD_BLAKE2B_384 384 bits == 48 bytes (libgcrypt ≥ 1.8.0) + * GCRY_MD_BLAKE2B_512 512 bits == 64 bytes (libgcrypt ≥ 1.8.0) + * GCRY_MD_BLAKE2S_128 128 bits == 16 bytes (libgcrypt ≥ 1.8.0) + * GCRY_MD_BLAKE2S_160 160 bits == 20 bytes (libgcrypt ≥ 1.8.0) + * GCRY_MD_BLAKE2S_224 224 bits == 28 bytes (libgcrypt ≥ 1.8.0) + * GCRY_MD_BLAKE2S_256 256 bits == 32 bytes (libgcrypt ≥ 1.8.0) * * The result hash is stored in "hash" (the buffer must be large enough). * @@ -165,17 +215,27 @@ hash_end: * * The hash size depends on the algorithm, common ones are: * - * GCRY_MD_CRC32 32 bits == 4 bytes - * GCRY_MD_MD5 128 bits == 16 bytes - * GCRY_MD_SHA1 160 bits == 20 bytes - * GCRY_MD_SHA224 224 bits == 28 bytes - * GCRY_MD_SHA256 256 bits == 32 bytes - * GCRY_MD_SHA384 384 bits == 48 bytes - * GCRY_MD_SHA512 512 bits == 64 bytes - * GCRY_MD_SHA3_224 224 bits == 28 bytes (libgcrypt ≥ 1.7.0) - * GCRY_MD_SHA3_256 256 bits == 32 bytes (libgcrypt ≥ 1.7.0) - * GCRY_MD_SHA3_384 384 bits == 48 bytes (libgcrypt ≥ 1.7.0) - * GCRY_MD_SHA3_512 512 bits == 64 bytes (libgcrypt ≥ 1.7.0) + * GCRY_MD_CRC32 32 bits == 4 bytes + * GCRY_MD_MD5 128 bits == 16 bytes + * GCRY_MD_SHA1 160 bits == 20 bytes + * GCRY_MD_SHA224 224 bits == 28 bytes + * GCRY_MD_SHA256 256 bits == 32 bytes + * GCRY_MD_SHA384 384 bits == 48 bytes + * GCRY_MD_SHA512 512 bits == 64 bytes + * GCRY_MD_SHA512_224 224 bits == 28 bytes (libgcrypt ≥ 1.9.4) + * GCRY_MD_SHA512_256 256 bits == 32 bytes (libgcrypt ≥ 1.9.4) + * GCRY_MD_SHA3_224 224 bits == 28 bytes (libgcrypt ≥ 1.7.0) + * GCRY_MD_SHA3_256 256 bits == 32 bytes (libgcrypt ≥ 1.7.0) + * GCRY_MD_SHA3_384 384 bits == 48 bytes (libgcrypt ≥ 1.7.0) + * GCRY_MD_SHA3_512 512 bits == 64 bytes (libgcrypt ≥ 1.7.0) + * GCRY_MD_BLAKE2B_160 160 bits == 20 bytes (libgcrypt ≥ 1.8.0) + * GCRY_MD_BLAKE2B_256 256 bits == 32 bytes (libgcrypt ≥ 1.8.0) + * GCRY_MD_BLAKE2B_384 384 bits == 48 bytes (libgcrypt ≥ 1.8.0) + * GCRY_MD_BLAKE2B_512 512 bits == 64 bytes (libgcrypt ≥ 1.8.0) + * GCRY_MD_BLAKE2S_128 128 bits == 16 bytes (libgcrypt ≥ 1.8.0) + * GCRY_MD_BLAKE2S_160 160 bits == 20 bytes (libgcrypt ≥ 1.8.0) + * GCRY_MD_BLAKE2S_224 224 bits == 28 bytes (libgcrypt ≥ 1.8.0) + * GCRY_MD_BLAKE2S_256 256 bits == 32 bytes (libgcrypt ≥ 1.8.0) * * The result hash is stored in "hash" (the buffer must be large enough). * @@ -322,17 +382,27 @@ hash_pbkdf2_end: * * The hash size depends on the algorithm, common ones are: * - * GCRY_MD_CRC32 32 bits == 4 bytes - * GCRY_MD_MD5 128 bits == 16 bytes - * GCRY_MD_SHA1 160 bits == 20 bytes - * GCRY_MD_SHA224 224 bits == 28 bytes - * GCRY_MD_SHA256 256 bits == 32 bytes - * GCRY_MD_SHA384 384 bits == 48 bytes - * GCRY_MD_SHA512 512 bits == 64 bytes - * GCRY_MD_SHA3_224 224 bits == 28 bytes (libgcrypt ≥ 1.7.0) - * GCRY_MD_SHA3_256 256 bits == 32 bytes (libgcrypt ≥ 1.7.0) - * GCRY_MD_SHA3_384 384 bits == 48 bytes (libgcrypt ≥ 1.7.0) - * GCRY_MD_SHA3_512 512 bits == 64 bytes (libgcrypt ≥ 1.7.0) + * GCRY_MD_CRC32 32 bits == 4 bytes + * GCRY_MD_MD5 128 bits == 16 bytes + * GCRY_MD_SHA1 160 bits == 20 bytes + * GCRY_MD_SHA224 224 bits == 28 bytes + * GCRY_MD_SHA256 256 bits == 32 bytes + * GCRY_MD_SHA384 384 bits == 48 bytes + * GCRY_MD_SHA512 512 bits == 64 bytes + * GCRY_MD_SHA512_224 224 bits == 28 bytes (libgcrypt ≥ 1.9.4) + * GCRY_MD_SHA512_256 256 bits == 32 bytes (libgcrypt ≥ 1.9.4) + * GCRY_MD_SHA3_224 224 bits == 28 bytes (libgcrypt ≥ 1.7.0) + * GCRY_MD_SHA3_256 256 bits == 32 bytes (libgcrypt ≥ 1.7.0) + * GCRY_MD_SHA3_384 384 bits == 48 bytes (libgcrypt ≥ 1.7.0) + * GCRY_MD_SHA3_512 512 bits == 64 bytes (libgcrypt ≥ 1.7.0) + * GCRY_MD_BLAKE2B_160 160 bits == 20 bytes (libgcrypt ≥ 1.8.0) + * GCRY_MD_BLAKE2B_256 256 bits == 32 bytes (libgcrypt ≥ 1.8.0) + * GCRY_MD_BLAKE2B_384 384 bits == 48 bytes (libgcrypt ≥ 1.8.0) + * GCRY_MD_BLAKE2B_512 512 bits == 64 bytes (libgcrypt ≥ 1.8.0) + * GCRY_MD_BLAKE2S_128 128 bits == 16 bytes (libgcrypt ≥ 1.8.0) + * GCRY_MD_BLAKE2S_160 160 bits == 20 bytes (libgcrypt ≥ 1.8.0) + * GCRY_MD_BLAKE2S_224 224 bits == 28 bytes (libgcrypt ≥ 1.8.0) + * GCRY_MD_BLAKE2S_256 256 bits == 32 bytes (libgcrypt ≥ 1.8.0) * * The result hash is stored in "hash" (the buffer must be large enough). * diff --git a/tests/unit/core/test-core-crypto.cpp b/tests/unit/core/test-core-crypto.cpp index 4e6894063..df1fdf267 100644 --- a/tests/unit/core/test-core-crypto.cpp +++ b/tests/unit/core/test-core-crypto.cpp @@ -45,6 +45,10 @@ extern "C" #define DATA_HASH_SHA512 "4469190d4e0d1fdc0afb6f408d9873c89b8ce89cc4db79fe0" \ "58255c55ad6821fa5e9bb068f9e578c8ae7cc825d85ff99c439d59e439bc589d95620a" \ "1e6b8ae6e" +#define DATA_HASH_SHA512_224 "5c442c9389a2b72103e16a863e753f4ca98f232ba13e6" \ + "946df97f955" +#define DATA_HASH_SHA512_256 "d9157dc21fffaaea696a868d2c5b29ca7b622c9bcdd7d" \ + "55031589c4a840d43cc" #define DATA_HASH_SHA3_224 "26432a3a4ea998790be43386b1de417f88be43146a4af98" \ "2a9627d10" #define DATA_HASH_SHA3_256 "226e3830306711cf653c1661765c304b37038e7457c35dd" \ @@ -54,6 +58,20 @@ extern "C" #define DATA_HASH_SHA3_512 "31dfb5fc8f30ac7007acddc4fce562d408706833d0d2af2" \ "e5f61a179099592927ff7d100e278406c7f98d42575001e26e153b135c21f7ef5b00c8" \ "cef93ca048d" +#define DATA_HASH_BLAKE2B_160 "4b69099962d678140e7c22f3f98edad60432ed3d" +#define DATA_HASH_BLAKE2B_256 "21b3e26905be39894328222c10b009a64633109db228" \ + "df8222d1ff61cf6bd6a8" +#define DATA_HASH_BLAKE2B_384 "a3e35d3ac1b866a4836cefe4c29610792c30c5380dcf" \ + "56fdffa29397b92110fba0d24df470f0aa4563d12f3e31511bab" +#define DATA_HASH_BLAKE2B_512 "ef694e494cf17a4c5e43644d185ee48e2f16ec85e13d" \ + "bd22dfcc415c7eb187baa08befe3422d630de486f07d417551730db8d29944c151bdfe" \ + "d016e84510565c" +#define DATA_HASH_BLAKE2S_128 "b0c4131eab265ea16b7b8b4770ac7b7d" +#define DATA_HASH_BLAKE2S_160 "02d2dde62d0512368041ddbbda348404f3c8d528" +#define DATA_HASH_BLAKE2S_224 "2f25961aff8a79b4ac9a1cfd956d2b590bb900466660" \ + "0d595820acaf" +#define DATA_HASH_BLAKE2S_256 "f0fa555b88a92ec73b25527da818338fcf295449e6c0" \ + "04b8b0ec392e0fc44d7c" /* Hash PBKDF2 */ #define DATA_HASH_SALT "this is a salt of 32 bytes xxxxx" @@ -80,6 +98,10 @@ extern "C" #define DATA_HMAC_SHA512 "940e5c280c08cd858f79a6085b4bdc54710ed339dd1008fa2" \ "1643b7bbeea8a5f61c77f395708505461af62776c9cb7be1c263f39055eb8478190cd8" \ "0ea5b0850" +#define DATA_HMAC_SHA512_224 "521860f56b6c429a20357055dd1f18ea706543c2e2bab" \ + "be06ff8c610" +#define DATA_HMAC_SHA512_256 "1da19faaa2b3fca54a08c6694123c465e7da76ad8c672" \ + "a5ad323e824e1c3b523" #define DATA_HMAC_SHA3_224 "a08c7f1598ecc7ea54feeb920ef90b3748d59b3203caa74" \ "7316eb2d4" #define DATA_HMAC_SHA3_256 "21aca280bc1ac1fa261b1169a321eb7a49e38a8ddec66a8" \ @@ -225,12 +247,26 @@ TEST(CoreCrypto, GetHashAlgo) LONGS_EQUAL(GCRY_MD_SHA256, weecrypto_get_hash_algo ("sha256")); LONGS_EQUAL(GCRY_MD_SHA384, weecrypto_get_hash_algo ("sha384")); LONGS_EQUAL(GCRY_MD_SHA512, weecrypto_get_hash_algo ("sha512")); +#if GCRYPT_VERSION_NUMBER >= 0x010904 + LONGS_EQUAL(GCRY_MD_SHA512_224, weecrypto_get_hash_algo ("sha512-224")); + LONGS_EQUAL(GCRY_MD_SHA512_256, weecrypto_get_hash_algo ("sha512-256")); +#endif #if GCRYPT_VERSION_NUMBER >= 0x010700 LONGS_EQUAL(GCRY_MD_SHA3_224, weecrypto_get_hash_algo ("sha3-224")); LONGS_EQUAL(GCRY_MD_SHA3_256, weecrypto_get_hash_algo ("sha3-256")); LONGS_EQUAL(GCRY_MD_SHA3_384, weecrypto_get_hash_algo ("sha3-384")); LONGS_EQUAL(GCRY_MD_SHA3_512, weecrypto_get_hash_algo ("sha3-512")); #endif +#if GCRYPT_VERSION_NUMBER >= 0x010800 + LONGS_EQUAL(GCRY_MD_BLAKE2B_160, weecrypto_get_hash_algo ("blake2b-160")); + LONGS_EQUAL(GCRY_MD_BLAKE2B_256, weecrypto_get_hash_algo ("blake2b-256")); + LONGS_EQUAL(GCRY_MD_BLAKE2B_384, weecrypto_get_hash_algo ("blake2b-384")); + LONGS_EQUAL(GCRY_MD_BLAKE2B_512, weecrypto_get_hash_algo ("blake2b-512")); + LONGS_EQUAL(GCRY_MD_BLAKE2S_128, weecrypto_get_hash_algo ("blake2s-128")); + LONGS_EQUAL(GCRY_MD_BLAKE2S_160, weecrypto_get_hash_algo ("blake2s-160")); + LONGS_EQUAL(GCRY_MD_BLAKE2S_224, weecrypto_get_hash_algo ("blake2s-224")); + LONGS_EQUAL(GCRY_MD_BLAKE2S_256, weecrypto_get_hash_algo ("blake2s-256")); +#endif } /* @@ -259,12 +295,26 @@ TEST(CoreCrypto, Hash) WEE_CHECK_HASH(1, DATA_HASH_SHA256, data, data_size, GCRY_MD_SHA256); WEE_CHECK_HASH(1, DATA_HASH_SHA384, data, data_size, GCRY_MD_SHA384); WEE_CHECK_HASH(1, DATA_HASH_SHA512, data, data_size, GCRY_MD_SHA512); +#if GCRYPT_VERSION_NUMBER >= 0x010904 + WEE_CHECK_HASH(1, DATA_HASH_SHA512_224, data, data_size, GCRY_MD_SHA512_224); + WEE_CHECK_HASH(1, DATA_HASH_SHA512_256, data, data_size, GCRY_MD_SHA512_256); +#endif #if GCRYPT_VERSION_NUMBER >= 0x010700 WEE_CHECK_HASH(1, DATA_HASH_SHA3_224, data, data_size, GCRY_MD_SHA3_224); WEE_CHECK_HASH(1, DATA_HASH_SHA3_256, data, data_size, GCRY_MD_SHA3_256); WEE_CHECK_HASH(1, DATA_HASH_SHA3_384, data, data_size, GCRY_MD_SHA3_384); WEE_CHECK_HASH(1, DATA_HASH_SHA3_512, data, data_size, GCRY_MD_SHA3_512); #endif +#if GCRYPT_VERSION_NUMBER >= 0x010800 + WEE_CHECK_HASH(1, DATA_HASH_BLAKE2B_160, data, data_size, GCRY_MD_BLAKE2B_160); + WEE_CHECK_HASH(1, DATA_HASH_BLAKE2B_256, data, data_size, GCRY_MD_BLAKE2B_256); + WEE_CHECK_HASH(1, DATA_HASH_BLAKE2B_384, data, data_size, GCRY_MD_BLAKE2B_384); + WEE_CHECK_HASH(1, DATA_HASH_BLAKE2B_512, data, data_size, GCRY_MD_BLAKE2B_512); + WEE_CHECK_HASH(1, DATA_HASH_BLAKE2S_128, data, data_size, GCRY_MD_BLAKE2S_128); + WEE_CHECK_HASH(1, DATA_HASH_BLAKE2S_160, data, data_size, GCRY_MD_BLAKE2S_160); + WEE_CHECK_HASH(1, DATA_HASH_BLAKE2S_224, data, data_size, GCRY_MD_BLAKE2S_224); + WEE_CHECK_HASH(1, DATA_HASH_BLAKE2S_256, data, data_size, GCRY_MD_BLAKE2S_256); +#endif } /* @@ -299,11 +349,25 @@ TEST(CoreCrypto, HashFile) WEE_CHECK_HASH_FILE(1, DATA_HASH_SHA384, filename, GCRY_MD_SHA384); WEE_CHECK_HASH_FILE(1, DATA_HASH_SHA512, filename, GCRY_MD_SHA512); #if GCRYPT_VERSION_NUMBER >= 0x010700 + WEE_CHECK_HASH_FILE(1, DATA_HASH_SHA512_224, filename, GCRY_MD_SHA512_224); + WEE_CHECK_HASH_FILE(1, DATA_HASH_SHA512_256, filename, GCRY_MD_SHA512_256); +#endif +#if GCRYPT_VERSION_NUMBER >= 0x010700 WEE_CHECK_HASH_FILE(1, DATA_HASH_SHA3_224, filename, GCRY_MD_SHA3_224); WEE_CHECK_HASH_FILE(1, DATA_HASH_SHA3_256, filename, GCRY_MD_SHA3_256); WEE_CHECK_HASH_FILE(1, DATA_HASH_SHA3_384, filename, GCRY_MD_SHA3_384); WEE_CHECK_HASH_FILE(1, DATA_HASH_SHA3_512, filename, GCRY_MD_SHA3_512); #endif +#if GCRYPT_VERSION_NUMBER >= 0x010800 + WEE_CHECK_HASH_FILE(1, DATA_HASH_BLAKE2B_160, filename, GCRY_MD_BLAKE2B_160); + WEE_CHECK_HASH_FILE(1, DATA_HASH_BLAKE2B_256, filename, GCRY_MD_BLAKE2B_256); + WEE_CHECK_HASH_FILE(1, DATA_HASH_BLAKE2B_384, filename, GCRY_MD_BLAKE2B_384); + WEE_CHECK_HASH_FILE(1, DATA_HASH_BLAKE2B_512, filename, GCRY_MD_BLAKE2B_512); + WEE_CHECK_HASH_FILE(1, DATA_HASH_BLAKE2S_128, filename, GCRY_MD_BLAKE2S_128); + WEE_CHECK_HASH_FILE(1, DATA_HASH_BLAKE2S_160, filename, GCRY_MD_BLAKE2S_160); + WEE_CHECK_HASH_FILE(1, DATA_HASH_BLAKE2S_224, filename, GCRY_MD_BLAKE2S_224); + WEE_CHECK_HASH_FILE(1, DATA_HASH_BLAKE2S_256, filename, GCRY_MD_BLAKE2S_256); +#endif unlink (filename); free (filename); @@ -382,6 +446,10 @@ TEST(CoreCrypto, Hmac) WEE_CHECK_HMAC(1, DATA_HMAC_SHA256, key, key_size, msg, msg_size, GCRY_MD_SHA256); WEE_CHECK_HMAC(1, DATA_HMAC_SHA384, key, key_size, msg, msg_size, GCRY_MD_SHA384); WEE_CHECK_HMAC(1, DATA_HMAC_SHA512, key, key_size, msg, msg_size, GCRY_MD_SHA512); +#if GCRYPT_VERSION_NUMBER >= 0x010904 + WEE_CHECK_HMAC(1, DATA_HMAC_SHA512_224, key, key_size, msg, msg_size, GCRY_MD_SHA512_224); + WEE_CHECK_HMAC(1, DATA_HMAC_SHA512_256, key, key_size, msg, msg_size, GCRY_MD_SHA512_256); +#endif #if GCRYPT_VERSION_NUMBER >= 0x010700 WEE_CHECK_HMAC(1, DATA_HMAC_SHA3_224, key, key_size, msg, msg_size, GCRY_MD_SHA3_224); WEE_CHECK_HMAC(1, DATA_HMAC_SHA3_256, key, key_size, msg, msg_size, GCRY_MD_SHA3_256); |