diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2020-03-01 16:41:28 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2020-03-01 16:41:28 +0100 |
commit | c4ef3d6c2e5339d3b6ac2ba255d166a4d8984bce (patch) | |
tree | b36837b6da12cc2e262caf887ab592843d9bda53 /doc/en | |
parent | 1ae25914588221ece76da2d39ddece16de0c7712 (diff) | |
download | weechat-c4ef3d6c2e5339d3b6ac2ba255d166a4d8984bce.zip |
core: merge functions string_hash_binary and string_hash into a single function string_hash
Diffstat (limited to 'doc/en')
-rw-r--r-- | doc/en/weechat_plugin_api.en.adoc | 104 |
1 files changed, 26 insertions, 78 deletions
diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc index 832eb91f6..f1c3be540 100644 --- a/doc/en/weechat_plugin_api.en.adoc +++ b/doc/en/weechat_plugin_api.en.adoc @@ -2061,113 +2061,61 @@ char *dump = weechat_string_hex_dump (string, strlen (string), 8, " >> ", NULL); [NOTE] This function is not available in scripting API. -==== string_hash_binary - -_WeeChat ≥ 2.8._ - -Compute hash of data. - -Prototype: - -[source,C] ----- -void string_hash_binary (const char *data, int length_data, const char *hash_algo, - char **hash, int *length_hash); ----- - -Arguments: - -* _data_: the data to hash -* _length_data_: number of bytes to hash in _data_ -* _hash_algo_: the hash algorithm, see table below -* _hash_: pointer to the hash variable, which is allocated by the function and - used to store the resulting hash (NULL if error) -* _length_hash_: pointer to a variable used to store the length of the hash - computed (in bytes) (0 if error) - -Supported hash algorithms: - -[width="100%",cols="4,4,4,5,12",options="header"] -|=== -| Value | Algorithm | Hash size | Output (binary) | Notes -| `+crc32+` | CRC32 | 32 bits | 4 bytes | Not a hash algorithm in the cryptographic sense. -| `+md5+` | MD5 | 128 bits | 16 bytes | *Weak*, not recommended for cryptography usage. -| `+sha1+` | SHA-1 | 160 bits | 20 bytes | *Weak*, not recommended for cryptography usage. -| `+sha224+` | SHA-224 | 224 bits | 28 bytes | -| `+sha256+` | SHA-256 | 256 bits | 32 bytes | -| `+sha384+` | SHA-384 | 384 bits | 48 bytes | -| `+sha512+` | SHA-512 | 512 bits | 64 bytes | -| `+sha3-224+` | SHA3-224 | 224 bits | 28 bytes | -| `+sha3-256+` | SHA3-256 | 256 bits | 32 bytes | -| `+sha3-384+` | SHA3-384 | 384 bits | 48 bytes | -| `+sha3-512+` | SHA3-512 | 512 bits | 64 bytes | -|=== - -C example: - -[source,C] ----- -const char *data = "abcdefghijklmnopqrstuvwxyz"; -char *hash; -int length_hash; -weechat_string_hash_binary (data, strlen (data), "sha256", &hash, &length_hash); -/* hash is a binary buffer with: - 71 c4 80 df 93 d6 ae 2f 1e fa d1 44 7c 66 c9 52 5e 31 62 18 cf 51 fc 8d 9e d8 32 f2 da f1 8b 73 */ ----- - -[NOTE] -This function is not available in scripting API. - ==== string_hash _WeeChat ≥ 2.8._ -Compute hash of data, as hexadecimal string. +Compute hash of data. Prototype: [source,C] ---- -char *string_hash (const char *data, int length_data, const char *hash_algo); +int string_hash (const void *data, int data_size, const char *hash_algo, void *hash, int *hash_size); ---- Arguments: * _data_: the data to hash -* _length_data_: number of bytes to hash in _data_ +* _data_size_: number of bytes to hash in _data_ * _hash_algo_: the hash algorithm, see table below +* _hash_: pointer to the hash variable, which is used to store the resulting hash + (the buffer must be large enough, according to the algorithm, see table below) +* _hash_size_: pointer to a variable used to store the size of the hash computed + (in bytes) (can be NULL) Supported hash algorithms: -[width="100%",cols="4,4,4,5,12",options="header"] +[width="100%",cols="2,2,3,6",options="header"] |=== -| Value | Algorithm | Hash size | Output (string) | Notes -| `+crc32+` | CRC32 | 32 bits | 8 hex chars | Not a hash algorithm in the cryptographic sense. -| `+md5+` | MD5 | 128 bits | 32 hex chars | *Weak*, not recommended for cryptography usage. -| `+sha1+` | SHA-1 | 160 bits | 40 hex chars | *Weak*, not recommended for cryptography usage. -| `+sha224+` | SHA-224 | 224 bits | 56 hex chars | -| `+sha256+` | SHA-256 | 256 bits | 64 hex chars | -| `+sha384+` | SHA-384 | 384 bits | 96 hex chars | -| `+sha512+` | SHA-512 | 512 bits | 128 hex chars | -| `+sha3-224+` | SHA3-224 | 224 bits | 56 hex chars | -| `+sha3-256+` | SHA3-256 | 256 bits | 64 hex chars | -| `+sha3-384+` | SHA3-384 | 384 bits | 96 hex chars | -| `+sha3-512+` | SHA3-512 | 512 bits | 128 hex chars | +| 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) | +| `+sha3-256+` | SHA3-256 | 32 bytes (256 bits) | +| `+sha3-384+` | SHA3-384 | 48 bytes (384 bits) | +| `+sha3-512+` | SHA3-512 | 64 bytes (512 bits) | |=== Return value: -* string with hash of data as hexadecimal (must be freed by calling "free" - after use), NULL if error +* 1 if OK, 0 if error C example: [source,C] ---- const char *data = "abcdefghijklmnopqrstuvwxyz"; -char *hash; -hash = weechat_string_hash (data, strlen (data), "sha256"); -/* hash == "71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73" +char hash[256 / 8]; +int rc, hash_size; +rc = weechat_string_hash (data, strlen (data), "sha256", hash, &hash_size); +/* rc == 1, hash_size == 32 and hash is a buffer with: + 71 c4 80 df 93 d6 ae 2f 1e fa d1 44 7c 66 c9 52 5e 31 62 18 cf 51 fc 8d 9e d8 32 f2 da f1 8b 73 */ ---- [NOTE] |