Home Reference Source Test
public class | source

Snefru

Extends:

src/hasher/hasher32be.js~Hasher32be → Snefru

Calculates Snefru v2.0 (2 rounds 128, 4 rounds 256), Snefru v2.5 (8 rounds) hash

Example:

Calculates Snefru128/8 hash from string "message" - ES6 style
import Snefru from "crypto-api/src/hasher/snefru";
import {toHex} from "crypto-api/src/encoder/hex";

let hasher = new Snefru();
hasher.update('message');
console.log(toHex(hasher.finalize()));
Calculates Snefru128/8 hash from UTF string "message" - ES6 style
import Snefru from "crypto-api/src/hasher/snefru";
import {toHex} from "crypto-api/src/encoder/hex";
import {fromUtf} from "crypto-api/src/encoder/utf";

let hasher = new Snefru();
hasher.update(fromUtf('message'));
console.log(toHex(hasher.finalize()));
Calculates Snefru128/8 hash from string "message" - ES5 style
<script src="https://nf404.github.io/crypto-api/crypto-api.min.js"></script>
<script>
  var hasher = CryptoApi.getHasher('snefru');
  hasher.update('message');
  console.log(CryptoApi.encoder.toHex(hasher.finalize()));
</script>
Calculates Snefru128/8 hash from UTF string "message" - ES5 style
<script src="https://nf404.github.io/crypto-api/crypto-api.min.js"></script>
<script>
  console.log(CryptoApi.hash('snefru', 'message'));
</script>

Test:

Constructor Summary

Public Constructor
public

constructor(options: Object)

Method Summary

Public Methods
public

finalize(): string

Finalize hash and return result

public

reset()

Reset hasher to initial state

Public Constructors

public constructor(options: Object) source

Params:

NameTypeAttributeDescription
options Object
  • optional
Hash type Length Rounds
snefru128/2 128 2
snefru256/4 256 4
snefru128/8 128 8
snefru256/8 256 8
options.rounds number
  • optional
  • default: 8

Number of rounds (Can be from 2 to 8)

options.length number
  • optional
  • default: 128

Length of hash result (Can be from 32 to 480 with step 32). Be careful, increasing of length will cause a reduction of the block size

Public Methods

public finalize(): string source

Finalize hash and return result

Return:

string

public reset() source

Reset hasher to initial state