Next | Previous

sha3

This module provide the generic Keccak class and functions for working with SHA3, Keccak and SHAKE hashes.

Like the hash module, this module exports quick and simple functions to compute SHA3/Keccak family of functions.

For example:

%> import sha3
%> 
%> sha3.sha3_256('hello')
'3338be694f50c5f338814986cdf0686453a888b84f424d792af4b9202398f392'

It also exports the generic Keccak class that you can customize to your preference.

For example:

%> import sha3
%> 
%> var h = sha3.Keccak(256, 1)
%> h.update('How are you?')
<class Keccak instance at 0x14010bf40>
%> h.digest('')
(97 bf fd e9 c7 30 76 73 58 99 84 84 1c cc c1 8c dc 28 90 d6  ...32)

You can use the bytes_to_hex() function in the convert module to get a hexadecimal string from the digest.

Functions

sha3.keccak_224(message)

Returns the Keccak-224 cryptographic hash of the given string or bytes.

  • @params:
    • string|bytes message
  • @returns: string
sha3.keccak_256(message)

Returns the Keccak-256 cryptographic hash of the given string or bytes.

  • @params:
    • string|bytes message
  • @returns: string
sha3.keccak_384(message)

Returns the Keccak-384 cryptographic hash of the given string or bytes.

  • @params:
    • string|bytes message
  • @returns: string
sha3.keccak_512(message)

Returns the Keccak-512 cryptographic hash of the given string or bytes.

  • @params:
    • string|bytes message
  • @returns: string
sha3.sha3_224(message)

Returns the SHA3-224 cryptographic hash of the given string or bytes.

  • @params:
    • string|bytes message
  • @returns: string
sha3.sha3_256(message)

Returns the SHA3-256 cryptographic hash of the given string or bytes.

  • @params:
    • string|bytes message
  • @returns: string
sha3.sha3_384(message)

Returns the SHA3-384 cryptographic hash of the given string or bytes.

  • @params:
    • string|bytes message
  • @returns: string
sha3.sha3_512(message)

Returns the SHA3-512 cryptographic hash of the given string or bytes.

  • @params:
    • string|bytes message
  • @returns: string
sha3.shake128(length, message)

Returns the SHAKE-128 cryptographic hash of the given string or bytes computed to the given length.

  • @params:
    • number length
    • string|bytes message
  • @returns: string
sha3.shake256(length, message)

Returns the SHAKE-256 cryptographic hash of the given string or bytes computed to the given length.

  • @params:
    • number length
    • string|bytes message
  • @returns: string

Classes

class Keccak

Keccak hash manipulation class.

.Keccak(bits, padding, length) ➝ Constructor

sha3.Keccak constructor

  • @params:
    • number bits Capacity

    • number padding Padding value - 1 for Keccak, 6 for SHA3 and 31 for SHAKE

    • number? length Optional length of the output hash in bits. If not given bits is taken as default.

.init()

Initializes the hash functionality and prepares it for a new round.

  • @returns: self
.update(message)

Update the hash with additional message data.

  • @params:
    • string|bytes message
  • @returns: self
.digest(message)

Finalize the hash with additional message data and returns the message digest.

  • @params:
    • string|bytes message
  • @returns: bytes
.hash(message)

All-in-one method to initialize a new round, update the message and generate the final hash digest.

  • @params:
    • string|bytes message
  • @returns: string