

ExSha3 — ex\_sha3 v0.1.4

 try {

 var settings = JSON.parse(localStorage.getItem('ex\_doc:settings') || '{}');

 if (settings.theme === 'dark' ||

 ((settings.theme === 'system' || settings.theme == null) &&

 window.matchMedia('(prefers-color-scheme: dark)').matches)

 ) {

 document.body.classList.add('dark')

 }

 } catch (error) { }

 

Settings

[View Source](https://github.com/dominicletz/exsha3/blob/main/lib/ex_sha3.ex#L4 "View Source")

ExSha3

(ex\_sha3 v0.1.4)

====================================================================================================================================

 ExSha3 supports the three hash algorithms:

```

\* KECCAK1600-f the original pre-fips version as used in Ethereum

\* SHA3 the fips-202 approved final hash

\* SHAKE

```

 Keccak and SHA3 produce fixed length strings corresponding to their

 bit length, while shake produces an arbitary length output according

 to the provided outlen parameter.

[Link to this section](#summary)

 Summary

==========================================

[Functions](#functions)

------------------------

[calc(args \\ [])](#calc/1)

[calc(record, args)](#calc/2)

[keccak\_224(source)](#keccak_224/1)

[keccak\_256(source)](#keccak_256/1)

[keccak\_384(source)](#keccak_384/1)

[keccak\_512(source)](#keccak_512/1)

[sha3\_224(source)](#sha3_224/1)

[sha3\_256(source)](#sha3_256/1)

[sha3\_384(source)](#sha3_384/1)

[sha3\_512(source)](#sha3_512/1)

[shake\_128(source, outlen)](#shake_128/2)

[shake\_256(source, outlen)](#shake_256/2)

[xor(a, b)](#xor/2)

[Link to this section](#functions)

Functions

=============================================

[Link to this macro](#calc/1 "Link to this macro")

calc(args \\ [])

================

[View Source](https://github.com/dominicletz/exsha3/blob/main/lib/ex_sha3.ex#L80 "View Source")

(macro)

[Link to this macro](#calc/2 "Link to this macro")

calc(record, args)

==================

[View Source](https://github.com/dominicletz/exsha3/blob/main/lib/ex_sha3.ex#L80 "View Source")

(macro)

[Link to this function](#keccak_224/1 "Link to this function")

keccak\_224(source)

===================

[View Source](https://github.com/dominicletz/exsha3/blob/main/lib/ex_sha3.ex#L236 "View Source")

```

@spec keccak_224([binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()) :: [binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

[Link to this function](#keccak_256/1 "Link to this function")

keccak\_256(source)

===================

[View Source](https://github.com/dominicletz/exsha3/blob/main/lib/ex_sha3.ex#L238 "View Source")

```

@spec keccak_256([binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()) :: [binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

[Link to this function](#keccak_384/1 "Link to this function")

keccak\_384(source)

===================

[View Source](https://github.com/dominicletz/exsha3/blob/main/lib/ex_sha3.ex#L240 "View Source")

```

@spec keccak_384([binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()) :: [binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

[Link to this function](#keccak_512/1 "Link to this function")

keccak\_512(source)

===================

[View Source](https://github.com/dominicletz/exsha3/blob/main/lib/ex_sha3.ex#L242 "View Source")

```

@spec keccak_512([binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()) :: [binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

[Link to this function](#sha3_224/1 "Link to this function")

sha3\_224(source)

=================

[View Source](https://github.com/dominicletz/exsha3/blob/main/lib/ex_sha3.ex#L226 "View Source")

```

@spec sha3_224([binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()) :: [binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

[Link to this function](#sha3_256/1 "Link to this function")

sha3\_256(source)

=================

[View Source](https://github.com/dominicletz/exsha3/blob/main/lib/ex_sha3.ex#L228 "View Source")

```

@spec sha3_256([binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()) :: [binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

[Link to this function](#sha3_384/1 "Link to this function")

sha3\_384(source)

=================

[View Source](https://github.com/dominicletz/exsha3/blob/main/lib/ex_sha3.ex#L230 "View Source")

```

@spec sha3_384([binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()) :: [binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

[Link to this function](#sha3_512/1 "Link to this function")

sha3\_512(source)

=================

[View Source](https://github.com/dominicletz/exsha3/blob/main/lib/ex_sha3.ex#L232 "View Source")

```

@spec sha3_512([binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()) :: [binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

[Link to this function](#shake_128/2 "Link to this function")

shake\_128(source, outlen)

==========================

[View Source](https://github.com/dominicletz/exsha3/blob/main/lib/ex_sha3.ex#L220 "View Source")

```

@spec shake_128([binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)(), [number](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()) :: [binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

[Link to this function](#shake_256/2 "Link to this function")

shake\_256(source, outlen)

==========================

[View Source](https://github.com/dominicletz/exsha3/blob/main/lib/ex_sha3.ex#L222 "View Source")

```

@spec shake_256([binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)(), [number](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()) :: [binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

[Link to this function](#xor/2 "Link to this function")

xor(a, b)

=========

[View Source](https://github.com/dominicletz/exsha3/blob/main/lib/ex_sha3.ex#L71 "View Source")





ExSha3 — ex\_sha3 v0.1.4

 try {

 var settings = JSON.parse(localStorage.getItem('ex\_doc:settings') || '{}');

 if (settings.theme === 'dark' ||

 ((settings.theme === 'system' || settings.theme == null) &&

 window.matchMedia('(prefers-color-scheme: dark)').matches)

 ) {

 document.body.classList.add('dark')

 }

 } catch (error) { }

 

Settings

[View Source](https://github.com/dominicletz/exsha3/blob/main/README.md#L1 "View Source")

ExSha3

=============================================================================================================

Pure Elixir implemtation of Keccak, SHA-3 (FIPS-202) and shake. The provided code is an experiment in porting the c-algorithm to Elixir. While it should be correct don't expect native performance.

The Elixir code is a port from: 

<https://github.com/status-im/nim-keccak-tiny/blob/master/keccak_tiny/keccak-tiny.c>

[installation](#installation)

 Installation

--------------------------------------------

The package can be installed by adding `exsha3` to your list of dependencies in `mix.exs`:

```

def deps do

 [

 {:exsha3, "~> 0.1"}

 ]

end

```

[this-is-slow](#this-is-slow)

 This Is Slow

--------------------------------------------

This is a proof of concept, and while is correct it is also really slow. Have a look at these numbers from the included benchmark script:

```

> ./benchmark.sh

=========== emu\_flavor = jit ===========

Operating System: Linux

CPU Information: AMD Ryzen 7 3700U with Radeon Vega Mobile Gfx

Number of Available Cores: 8

Available memory: 15.45 GB

Elixir 1.11.4

Erlang 24.0-rc1

Benchmark suite executing with the following configuration:

warmup: 2 s

time: 5 s

memory time: 0 ns

parallel: 1

inputs: long string, short string

Estimated total run time: 28 s

Benchmarking ex\_sha3\_256 with input long string...

Benchmarking ex\_sha3\_256 with input short string...

Benchmarking nif\_sha3\_256 with input long string...

Benchmarking nif\_sha3\_256 with input short string...

##### With input long string #####

Name ips average deviation median 99th %

 nif\_sha3\_256 4.24 K 0.24 ms ±24.26% 0.21 ms 0.48 ms

 ex\_sha3\_256 0.00989 K 101.15 ms ±5.02% 99.30 ms 121.34 ms

Comparison: 

 nif\_sha3\_256 4.24 K

 ex\_sha3\_256 0.00989 K - 428.71x slower +100.91 ms

##### With input short string #####

Name ips average deviation median 99th %

 nif\_sha3\_256 283.57 K 3.53 μs ±499.14% 3.28 μs 8.17 μs

 ex\_sha3\_256 1.61 K 621.56 μs ±18.51% 600.85 μs 1285.68 μs

Comparison: 

 nif\_sha3\_256 283.57 K

 ex\_sha3\_256 1.61 K - 176.26x slower +618.04 μs

```

[← Previous Page

 

API Reference](api-reference.html)

