crypto.sha3 #
Copyright (c) 2023 Kim Shrier. All rights reserved. Use of this source code is governed by an MIT license that can be found in the LICENSE file. Package sha3 implements the 512, 384, 256, and 224 bit hash algorithms and the 128 and 256 bit extended output functions as defined in https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf. Last updated: August 2015
Constants #
const size_224 = 28
size_224 is the size, in bytes, of a sha3 sum224 checksum.
const size_256 = 32
size_256 is the size, in bytes, of a sha3 sum256 checksum.
const size_384 = 48
size_384 is the size, in bytes, of a sha3 sum384 checksum.
const size_512 = 64
size_512 is the size, in bytes, of a sha3 sum512 checksum.
const rate_224 = 144
rate_224 is the rate, in bytes, absorbed into the sponge on every permutation
const rate_256 = 136
rate_256 is the rate, in bytes, absorbed into the sponge on every permutation
const rate_384 = 104
rate_384 is the rate, in bytes, absorbed into the sponge on every permutation
const rate_512 = 72
rate_512 is the rate, in bytes, absorbed into the sponge on every permutation
const xof_rate_128 = 168
xof_rate_128 is the capacity, in bytes, of a 128 bit extended output function sponge
const xof_rate_256 = 136
xof_rate_256 is the capacity, in bytes, of a 256 bit extended output function sponge
fn keccak256 #
fn keccak256(data []u8) []u8
keccak256 returns the keccak 256 bit checksum of the data.
fn keccak512 #
fn keccak512(data []u8) []u8
keccak512 returns the keccak 512 bit checksum of the data.
fn new128xof #
fn new128xof(output_len int) !&Digest
new128_xof initializes the digest structure for a sha3 128 bit extended output function
fn new224 #
fn new224() !&Digest
new224 initializes the digest structure for a sha3 224 bit hash
fn new256 #
fn new256() !&Digest
new256 initializes the digest structure for a sha3 256 bit hash
fn new256keccak #
fn new256keccak() !&Digest
new256keccak initializes the digest structure for a keccak 256 bit hash
fn new256xof #
fn new256xof(output_len int) !&Digest
new256_xof initializes the digest structure for a sha3 256 bit extended output function
fn new384 #
fn new384() !&Digest
new384 initializes the digest structure for a sha3 384 bit hash
fn new512 #
fn new512() !&Digest
new512 initializes the digest structure for a sha3 512 bit hash
fn new512keccak #
fn new512keccak() !&Digest
new512keccak initializes the digest structure for a keccak 512 bit hash
fn new_digest #
fn new_digest(absorption_rate int, hash_size int, config PaddingConfig) !&Digest
new_digest creates an initialized digest structure based on the hash size.
absorption_rate is the number of bytes to be absorbed into the sponge per permutation.
hash_size - the number if bytes in the generated hash. Legal values are 224, 256, 384, and 512.
config - the padding setting for hash generation. .sha3 should be used for FIPS PUB 202 compliant SHA3-224, SHA3-256, SHA3-384 and SHA3-512. Use .keccak if you want a legacy Keccak-224, Keccak-256, Keccak-384 or Keccak-512 algorithm. .xof is for extended output functions.
fn new_shake128 #
fn new_shake128() &Shake
new_shake128 returns a new Shake instance for SHAKE-128 extended output function.
fn new_shake256 #
fn new_shake256() &Shake
new_shake256 returns a new Shake instance for SHAKE-256 extended output function.
fn new_xof_digest #
fn new_xof_digest(absorption_rate int, hash_size int) !&Digest
new_xof_digest creates an initialized digest structure based on the absorption rate and how many bytes of output you need
absorption_rate is the number of bytes to be absorbed into the sponge per permutation. Legal values are xof_rate_128 and xof_rate_256.
hash_size - the number if bytes in the generated hash. Legal values are positive integers.
fn shake128 #
fn shake128(data []u8, output_len int) []u8
shake128 returns the sha3 shake128 bit extended output
fn shake256 #
fn shake256(data []u8, output_len int) []u8
shake256 returns the sha3 shake256 bit extended output
fn sum224 #
fn sum224(data []u8) []u8
sum224 returns the sha3 224 bit checksum of the data.
fn sum256 #
fn sum256(data []u8) []u8
sum256 returns the sha3 256 bit checksum of the data.
fn sum384 #
fn sum384(data []u8) []u8
sum384 returns the sha3 384 bit checksum of the data.
fn sum512 #
fn sum512(data []u8) []u8
sum512 returns the sha3 512 bit checksum of the data.
fn (Digest) write #
fn (mut d Digest) write(data []u8) !
write adds bytes to the sponge.
This is the absorption phase of the computation.
fn (Digest) checksum #
fn (mut d Digest) checksum() []u8
checksum finalizes the hash and returns the generated bytes.
enum Padding #
enum Padding as u8 {
keccak = 0x01
sha3 = 0x06
xof = 0x1f
}
the low order pad bits for a hash function
struct PaddingConfig #
struct PaddingConfig {
pub:
padding Padding = .sha3
}
struct Shake #
struct Shake {
rate int // bytes per permutation (168 for shake-128, 136 for shake-256)
mut:
s State
input_buffer []u8
finalized bool
squeeze_buf []u8
}
fn (Shake) write #
fn (mut s Shake) write(data []u8)
write absorbs more data into the sponge state. Panics if called after read.
fn (Shake) read #
fn (mut s Shake) read(out_len int) []u8
read squeezes out_len bytes from the sponge state. Finalizes the sponge on first call; further calls to write will panic.
fn (Shake) reset #
fn (mut s Shake) reset()
reset clears the sponge state, allowing the Shake instance to be reused.
- README
- Constants
- fn keccak256
- fn keccak512
- fn new128xof
- fn new224
- fn new256
- fn new256keccak
- fn new256xof
- fn new384
- fn new512
- fn new512keccak
- fn new_digest
- fn new_shake128
- fn new_shake256
- fn new_xof_digest
- fn shake128
- fn shake256
- fn sum224
- fn sum256
- fn sum384
- fn sum512
- type Digest
- enum Padding
- struct PaddingConfig
- struct Shake