All Projects → phusion → Node Sha3

phusion / Node Sha3

Licence: mit
SHA3 for JavaScript - The Keccak family of hash algorithms

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Node Sha3

Jssha
A JavaScript/TypeScript implementation of the complete Secure Hash Standard (SHA) family (SHA-1, SHA-224/256/384/512, SHA3-224/256/384/512, SHAKE128/256, cSHAKE128/256, and KMAC128/256) with HMAC.
Stars: ✭ 2,089 (+1765.18%)
Mutual labels:  hash, cryptography
Nsec
A modern and easy-to-use cryptographic library for .NET Core based on libsodium
Stars: ✭ 217 (+93.75%)
Mutual labels:  hash, cryptography
Password4j
Password4j is a user-friendly cryptographic library that supports Argon2, Bcrypt, Scrypt, PBKDF2 and various cryptographic hash functions.
Stars: ✭ 124 (+10.71%)
Mutual labels:  hash, cryptography
Open Crypto
🔑 Hashing (BCrypt, SHA2, HMAC), encryption (AES), public-key (RSA), and random data generation.
Stars: ✭ 115 (+2.68%)
Mutual labels:  hash, cryptography
Java Crypto Utils
Java Cryptographic, Encoding and Hash Utilities
Stars: ✭ 15 (-86.61%)
Mutual labels:  hash, cryptography
Chronicle
Public append-only ledger microservice built with Slim Framework
Stars: ✭ 429 (+283.04%)
Mutual labels:  hash, cryptography
Discohash
👯 Discohash - A super fast and simple hash. 5GB/s serial (depending on hardware). Also in NodeJS
Stars: ✭ 205 (+83.04%)
Mutual labels:  hash, cryptography
Beamsplitter
💎 Beamsplitter - A new (possibly universal) hash that passes SMHasher. Built mainly with a random 10x64 S-box. Also in NodeJS
Stars: ✭ 83 (-25.89%)
Mutual labels:  hash, cryptography
Securitydriven.inferno
✅ .NET crypto done right. Professionally audited.
Stars: ✭ 501 (+347.32%)
Mutual labels:  hash, cryptography
Bitcracker
BitCracker is the first open source password cracking tool for memory units encrypted with BitLocker
Stars: ✭ 463 (+313.39%)
Mutual labels:  hash, cryptography
Merkle Tools
Tools for creating Merkle trees, generating merkle proofs, and verification of merkle proofs.
Stars: ✭ 54 (-51.79%)
Mutual labels:  hash, cryptography
Siphash Js
A Javascript implementation of SipHash-2-4
Stars: ✭ 90 (-19.64%)
Mutual labels:  hash, cryptography
Easycrypt
Android cryptography library with SecureRandom patches.
Stars: ✭ 102 (-8.93%)
Mutual labels:  cryptography
Minperf
A Minimal Perfect Hash Function Library
Stars: ✭ 107 (-4.46%)
Mutual labels:  hash
Brightid
Reference mobile app for BrightID
Stars: ✭ 101 (-9.82%)
Mutual labels:  cryptography
Hs Jose
Haskell JOSE and JWT library
Stars: ✭ 100 (-10.71%)
Mutual labels:  cryptography
Pyce
Encrypted Python Execution
Stars: ✭ 111 (-0.89%)
Mutual labels:  cryptography
Xxhash cpp
Port of the xxhash library to C++17.
Stars: ✭ 106 (-5.36%)
Mutual labels:  hash
Pyjks
a pure python Java KeyStore file parser, including private key decryption
Stars: ✭ 100 (-10.71%)
Mutual labels:  cryptography
Desudesutalk
Steganography for imageboards
Stars: ✭ 100 (-10.71%)
Mutual labels:  cryptography

SHA-3 for JavaScript

Travis CI npm version npm downloads dependencies devDependencies license

A pure JavaScript implementation of the Keccak family of cryptographic hashing algorithms, most notably including Keccak and SHA3.

💡 Legacy Note: In previous versions of this library, the SHA3Hash object provided a Keccak hash, not what we currently know as a SHA-3 hash. For backwards-compatibility, this object is still exported. However, users are encouraged to switch to using the SHA3 or Keccak objects instead, which provide the SHA-3 and Keccak hashing algorithms, respectively.

Installation

Via npm:

$ npm install sha3

Via yarn:

$ yarn add sha3

Usage

You can use this library from Node.js, from web browsers, and/or using ES6 imports.

Node.js (CommonJS style)

// Standard FIPS 202 SHA-3 implementation
const { SHA3 } = require('sha3');

// The Keccak hash function is also available
const { Keccak } = require('sha3');

// The SHAKE extendable output function (XOF) is also available
const { SHAKE } = require('sha3');

ES6

// Standard FIPS 202 SHA-3 implementation
import { SHA3 } from 'sha3';

// The Keccak hash function is also available
import { Keccak } from 'sha3';

// The SHAKE extendable output function (XOF) is also available
import { SHAKE } from 'sha3';

What's in the box

FIPS-compatible interfaces for the following algorithms:

  • SHA3: The SHA3 algorithm.
  • Keccak: The Keccak algorithm.
  • SHAKE: The SHAKE XOF algorithm.

💡 Legacy Note: Savvy inspectors may notice that SHA3Hash is also provided. Prior to v2.0.0, this library only implemented an early version of the SHA3 algorithm. Since then, SHA3 has diverged from Keccak and is using a different padding scheme, but for compatibility, this alias is sticking around for a bit longer.

Examples

Generating a SHA3-512 hash

import { SHA3 } from 'sha3';

const hash = new SHA3(512);

hash.update('foo');
hash.digest('hex');

Generating a Keccak-256 hash

import { Keccak } from 'sha3';

const hash = new Keccak(256);

hash.update('foo');
hash.digest('hex');

Generating a SHAKE128 hash with 2048 bytes

import { SHAKE } from 'sha3';

const hash = new SHAKE(128);

hash.update('foo');
hash.digest({ buffer: Buffer.alloc(2048), format: 'hex' });

API Reference

All hash implementations provided by this library conform to the following API specification.

#constructor([size=512])

The constructor for each hash (e.g: Keccak, SHA3), expects the following parameters:

  • size (Number): Optional. The size of the hash to create, in bits. If provided, this must be one of 224, 256, 384, or 512. Defaults to 512.
Example
// Construct a new Keccak hash of size 256
const hash = new Keccak(256);

#update(data, [encoding='utf8'])

Updates the hash content with the given data. Returns the hash object itself.

  • data (Buffer|string): Required. The data to read into the hash.
  • encoding (string): Optional. The encoding of the given data, if of type string. Defaults to 'utf8'.

💡 See Buffers and Character Encodings for a list of allowed encodings.

Example
const hash = new Keccak(256);

hash.update('hello');

hash.update('we can also chain these').update('together');

#digest([encoding='binary'])

Digests the hash and returns the result. After calling this function, the hash may continue to receive input.

  • encoding (string): Optional. The encoding to use for the returned digest. Defaults to 'binary'.

If an encoding is provided and is a value other than 'binary', then this function returns a string. Otherwise, it returns a Buffer.

💡 See Buffers and Character Encodings for a list of allowed encodings.

Example
const hash = new Keccak(256);

hash.update('hello');

hash.digest('hex');
// => hash of 'hello' as a hex-encoded string

#digest([options={}])

Digests the hash and returns the result. After calling this function, the hash may continue to receive input.

Options include:

  • buffer (Buffer): Optional. A pre-allocated buffer to fill with output bytes. This is how XOF algorithms like SHAKE can be used to obtain an arbitrary number of hash bytes.
  • format (string): Optional. The encoding to use for the returned digest. Defaults to 'binary'. If buffer is also provided, this value will passed directly into Buffer#toString() on the given buffer.
  • padding (byte): Optional. Override the padding used to pad the input bytes to the algorithm's block size. Typically this should be omitted, but may be required if building additional cryptographic algorithms on top of this library.

If a format is provided and is a value other than 'binary', then this function returns a string. Otherwise, it returns a Buffer.

Example
const hash = new Keccak(256);

hash.update('hello');

hash.digest({ buffer: Buffer.alloc(32), format: 'hex' });
// => hash of 'hello' as a hex-encoded string

#reset()

Resets a hash to its initial state.

  • All input buffers are cleared from memory.
  • The hash object can safely be reused to compute another hash.
Example
const hash = new Keccak(256);

hash.update('hello');
hash.digest();
// => hash of 'hello'

hash.reset();

hash.update('world');
hash.digest();
// => hash of 'world'

Testing

Run yarn test for the full test suite.

Disclaimer

Cryptographic hashes provide integrity, but do not provide authenticity or confidentiality. Hash functions are one part of the cryptographic ecosystem, alongside other primitives like ciphers and MACs. If considering this library for the purpose of protecting passwords, you may actually be looking for a key derivation function, which can provide much better security guarantees for this use case.

Special Thanks

The following resources were invaluable to this implementation and deserve special thanks for work well done:

  • Keccak pseudocode: The Keccak team's excellent pseudo-code and technical descriptions.

  • mjosaarinen/tiny_sha3: Markku-Juhani O. Saarinen's compact, legible, and hackable implementation.

  • Phusion: For the initial release and maintenance of this project, and gracious hand-off to Twuni for continued development and maintenance.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].