aboutsummaryrefslogtreecommitdiffstats
path: root/library/sodium-plus/docs/SodiumPlus/short-input-hashing.md
diff options
context:
space:
mode:
Diffstat (limited to 'library/sodium-plus/docs/SodiumPlus/short-input-hashing.md')
-rw-r--r--library/sodium-plus/docs/SodiumPlus/short-input-hashing.md39
1 files changed, 39 insertions, 0 deletions
diff --git a/library/sodium-plus/docs/SodiumPlus/short-input-hashing.md b/library/sodium-plus/docs/SodiumPlus/short-input-hashing.md
new file mode 100644
index 000000000..54c910afe
--- /dev/null
+++ b/library/sodium-plus/docs/SodiumPlus/short-input-hashing.md
@@ -0,0 +1,39 @@
+## Short-input hashing
+
+> **See also**: [Libsodium's documentation on its short-input hashing features](https://download.libsodium.org/doc/hashing/short-input_hashing).
+
+### crypto_shorthash
+
+Calculate a fast hash for short inputs.
+
+**Parameters and their respective types**:
+
+1. `{string|Buffer}` input
+3. `{CryptographyKey}` key
+
+Returns a `Promise` that resolves to a `Buffer`.
+
+### crypto_shorthash_keygen
+
+Returns a `CryptographyKey` object containing a key appropriate
+for the `crypto_shorthash` API.
+
+### Example for crypto_shorthash
+
+> **Warning:** You probably want [`crypto_generichash()`](general-purpose-cryptographic-hash.md)
+> for most use-cases. `crypto_shorthash()` does not offer collision resistance.
+
+```javascript
+const { SodiumPlus } = require('sodium-plus');
+let sodium;
+
+(async function () {
+ if (!sodium) sodium = await SodiumPlus.auto();
+ let key = await sodium.crypto_shorthash_keygen();
+ let mapped = {};
+ mapped['foo'] = (await sodium.crypto_shorthash('foo', key)).toString('hex');
+ mapped['bar'] = (await sodium.crypto_shorthash('bar', key)).toString('hex');
+ mapped['baz'] = (await sodium.crypto_shorthash('baz', key)).toString('hex');
+ console.log(mapped);
+})();
+```