sha3

Imports

Imports #

"crypto/internal/fips140/subtle"
"crypto/internal/fips140deps/cpu"
"crypto/internal/impl"
"bytes"
"crypto/internal/fips140"
"crypto/internal/fips140deps/byteorder"
"errors"
"math/bits"
"bytes"
"crypto/internal/fips140"
"errors"
"crypto/internal/fips140deps/byteorder"
"crypto/internal/fips140deps/cpu"
"math/bits"
"unsafe"
"crypto/internal/fips140"
"crypto/internal/fips140/subtle"
"errors"

Constants & Variables

dsbyteCShake const #

const dsbyteCShake = 0b00000100

dsbyteKeccak const #

const dsbyteKeccak = 0b00000001

dsbyteSHA3 const #

const dsbyteSHA3 = 0b00000110

dsbyteShake const #

const dsbyteShake = 0b00011111

magicCShake const #

const magicCShake = "sha\x0a"

magicKeccak const #

const magicKeccak = "sha\x0b"

magicSHA3 const #

const magicSHA3 = "sha\x08"

magicShake const #

const magicShake = "sha\x09"

marshaledSize const #

magic || rate || main state || n || sponge direction

const marshaledSize = *ast.BinaryExpr

nopad const #

const nopad = 0x100

rateK1024 const #

const rateK1024 = *ast.BinaryExpr

rateK256 const #

rateK[c] is the rate in bytes for Keccak[c] where c is the capacity in bits. Given the sponge size is 1600 bits, the rate is 1600 - c bits.

const rateK256 = *ast.BinaryExpr

rateK448 const #

const rateK448 = *ast.BinaryExpr

rateK512 const #

const rateK512 = *ast.BinaryExpr

rateK768 const #

const rateK768 = *ast.BinaryExpr

rc var #

rc stores the round constants for use in the ι step.

var rc = [24]uint64{...}

sha3_224 const #

Function codes for KIMD/KLMD, from Figure 7-207.

const sha3_224 code = 32

sha3_256 const #

const sha3_256 code = 33

sha3_384 const #

const sha3_384 code = 34

sha3_512 const #

const sha3_512 code = 35

shake_128 const #

const shake_128 code = 36

shake_256 const #

const shake_256 code = 37

spongeAbsorbing const #

spongeAbsorbing indicates that the sponge is absorbing input.

const spongeAbsorbing spongeDirection = iota

spongeSqueezing const #

spongeSqueezing indicates that the sponge is being squeezed.

const spongeSqueezing

useSHA3 var #

var useSHA3 = cpu.S390XHasSHA3

Type Aliases

code type #

codes represent 7-bit KIMD/KLMD function codes as defined in the Principles of Operation.

type code uint64

spongeDirection type #

spongeDirection indicates the direction bytes are flowing through the sponge.

type spongeDirection int

Structs

Digest struct #

type Digest struct {
a [*ast.BinaryExpr]byte
n int
rate int
dsbyte byte
outputLen int
state spongeDirection
}

SHAKE struct #

type SHAKE struct {
d Digest
initBlock []byte
}

Functions

AppendBinary method #

func (d *Digest) AppendBinary(b []byte) ([]byte, error)

AppendBinary method #

func (s *SHAKE) AppendBinary(b []byte) ([]byte, error)

BlockSize method #

BlockSize returns the rate of sponge underlying this hash function.

func (d *Digest) BlockSize() int

BlockSize method #

func (s *SHAKE) BlockSize() int

Clone method #

func (d *Digest) Clone() *Digest

Clone method #

Clone returns a copy of the SHAKE context in its current state.

func (s *SHAKE) Clone() *SHAKE

MarshalBinary method #

func (d *Digest) MarshalBinary() ([]byte, error)

MarshalBinary method #

func (s *SHAKE) MarshalBinary() ([]byte, error)

New224 function #

New224 returns a new Digest computing the SHA3-224 hash.

func New224() *Digest

New256 function #

New256 returns a new Digest computing the SHA3-256 hash.

func New256() *Digest

New384 function #

New384 returns a new Digest computing the SHA3-384 hash.

func New384() *Digest

New512 function #

New512 returns a new Digest computing the SHA3-512 hash.

func New512() *Digest

NewCShake128 function #

NewCShake128 creates a new cSHAKE128 XOF. N is used to define functions based on cSHAKE, it can be empty when plain cSHAKE is desired. S is a customization byte string used for domain separation. When N and S are both empty, this is equivalent to NewShake128.

func NewCShake128(N []byte, S []byte) *SHAKE

NewCShake256 function #

NewCShake256 creates a new cSHAKE256 XOF. N is used to define functions based on cSHAKE, it can be empty when plain cSHAKE is desired. S is a customization byte string used for domain separation. When N and S are both empty, this is equivalent to NewShake256.

func NewCShake256(N []byte, S []byte) *SHAKE

NewLegacyKeccak256 function #

NewLegacyKeccak256 returns a new Digest computing the legacy, non-standard Keccak-256 hash.

func NewLegacyKeccak256() *Digest

NewLegacyKeccak512 function #

NewLegacyKeccak512 returns a new Digest computing the legacy, non-standard Keccak-512 hash.

func NewLegacyKeccak512() *Digest

NewShake128 function #

NewShake128 creates a new SHAKE128 XOF.

func NewShake128() *SHAKE

NewShake256 function #

NewShake256 creates a new SHAKE256 XOF.

func NewShake256() *SHAKE

Read method #

func (s *SHAKE) Read(out []byte) (n int, err error)

Reset method #

Reset resets the Digest to its initial state.

func (d *Digest) Reset()

Reset method #

Reset resets the hash to initial state.

func (s *SHAKE) Reset()

Size method #

func (s *SHAKE) Size() int

Size method #

Size returns the output size of the hash function in bytes.

func (d *Digest) Size() int

Sum method #

Sum appends the current hash to b and returns the resulting slice. It does not change the underlying hash state.

func (d *Digest) Sum(b []byte) []byte

Sum method #

Sum appends a portion of output to b and returns the resulting slice. The output length is selected to provide full-strength generic security: 32 bytes for SHAKE128 and 64 bytes for SHAKE256. It does not change the underlying state. It panics if any output has already been read.

func (s *SHAKE) Sum(in []byte) []byte

UnmarshalBinary method #

func (s *SHAKE) UnmarshalBinary(b []byte) error

UnmarshalBinary method #

func (d *Digest) UnmarshalBinary(b []byte) error

Write method #

Write absorbs more data into the hash's state. It panics if any output has already been read.

func (s *SHAKE) Write(p []byte) (n int, err error)

Write method #

Write absorbs more data into the hash's state.

func (d *Digest) Write(p []byte) (n int, err error)

bytepad function #

func bytepad(data []byte, rate int) []byte

function method #

func (d *Digest) function() code

init function #

func init()

init function #

func init()

keccakF1600 function #

func keccakF1600(a *[200]byte)

keccakF1600 function #

go:noescape

func keccakF1600(a *[200]byte)

keccakF1600 function #

func keccakF1600(a *[200]byte)

keccakF1600Generic function #

keccakF1600Generic applies the Keccak permutation.

func keccakF1600Generic(da *[200]byte)

kimd function #

kimd is a wrapper for the 'compute intermediate message digest' instruction. src is absorbed into the sponge state a. len(src) must be a multiple of the rate for the given function code. go:noescape

func kimd(function code, a *[200]byte, src []byte)

klmd function #

klmd is a wrapper for the 'compute last message digest' instruction. src is padded and absorbed into the sponge state a. If the function is a SHAKE XOF, the sponge is then optionally squeezed into dst by first applying the permutation and then copying the output until dst runs out. If len(dst) is a multiple of rate (including zero), the final permutation is not applied. If the nopad bit of function is set and len(src) is zero, only squeezing is performed. go:noescape

func klmd(function code, a *[200]byte, dst []byte, src []byte)

leftEncode function #

func leftEncode(x uint64) []byte

newCShake function #

func newCShake(N []byte, S []byte, rate int, outputLen int, dsbyte byte) *SHAKE

padAndPermute method #

padAndPermute appends the domain separation bits in dsbyte, applies the multi-bitrate 10..1 padding rule, and permutes the state.

func (d *Digest) padAndPermute()

permute method #

permute applies the KeccakF-1600 permutation.

func (d *Digest) permute()

read method #

func (d *Digest) read(out []byte) (n int, err error)

read method #

func (d *Digest) read(out []byte) (n int, err error)

read method #

func (d *Digest) read(out []byte) (n int, err error)

readGeneric method #

read squeezes an arbitrary number of bytes from the sponge.

func (d *Digest) readGeneric(out []byte) (n int, err error)

sum method #

func (d *Digest) sum(b []byte) []byte

sum method #

func (d *Digest) sum(b []byte) []byte

sum method #

func (d *Digest) sum(b []byte) []byte

sumGeneric method #

func (d *Digest) sumGeneric(b []byte) []byte

write method #

func (d *Digest) write(p []byte) (n int, err error)

write method #

func (d *Digest) write(p []byte) (n int, err error)

write method #

func (d *Digest) write(p []byte) (n int, err error)

writeGeneric method #

func (d *Digest) writeGeneric(p []byte) (n int, err error)

Generated with Arrow