zsha3

package
v0.0.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2025 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func EqualSum224

func EqualSum224(b []byte, sum []byte) bool

EqualSum224 compares SHA3/224 hash. It returns if the sum matches to the hash of b.

func EqualSum256

func EqualSum256(b []byte, sum []byte) bool

EqualSum256 compares SHA3/256 hash. It returns if the sum matches to the hash of b.

func EqualSum384

func EqualSum384(b []byte, sum []byte) bool

EqualSum384 compares SHA3/384 hash. It returns if the sum matches to the hash of b.

func EqualSum512

func EqualSum512(b []byte, sum []byte) bool

EqualSum512 compares SHA3/512 hash. It returns if the sum matches to the hash of b.

func EqualSumShake128

func EqualSumShake128(b []byte, sum []byte) bool

EqualSumShake128 compares SHAKE128 hash. It returns if the sum matches to the hash of b.

func EqualSumShake256

func EqualSumShake256(b []byte, sum []byte) bool

EqualSumShake256 compares SHAKE256 hash. It returns if the sum matches to the hash of b.

func HMACEqualSum224

func HMACEqualSum224(msg, key, sum []byte) bool

HMACEqualSum224 compares HMAC-SHA3/224 hash. It returns if the sum matches to the hash of b.

func HMACEqualSum256

func HMACEqualSum256(msg, key, sum []byte) bool

HMACEqualSum256 compares HMAC-SHA3/256 hash. It returns if the sum matches to the hash of b.

func HMACEqualSum384

func HMACEqualSum384(msg, key, sum []byte) bool

HMACEqualSum384 compares HMAC-SHA3/384 hash. It returns if the sum matches to the hash of b.

func HMACEqualSum512

func HMACEqualSum512(msg, key, sum []byte) bool

HMACEqualSum512 compares HMAC-SHA3/512 hash. It returns if the sum matches to the hash of b.

func HMACSum224

func HMACSum224(msg, key []byte) []byte

HMACSum224 returns HMAC-SHA3/224 hash. It uses crypto/sha3.New224.

Example
package main

import (
	"encoding/hex"
	"fmt"

	"github.com/aileron-projects/go/zcrypto/zsha3"
)

func main() {
	// Calculate HMAC-SHA3/224 hash.
	// Validation data can be generated with:
	// 	- echo -n "Hello Go!" | openssl dgst -hmac "secret-key" -sha3-224

	key := []byte("secret-key")
	sum := zsha3.HMACSum224([]byte("Hello Go!"), key)
	encoded := hex.EncodeToString(sum)
	fmt.Println(len(sum), encoded)
	fmt.Println("`Hello Go!` match?", zsha3.HMACEqualSum224([]byte("Hello Go!"), key, sum))
	fmt.Println("`Bye Go!` match?", zsha3.HMACEqualSum224([]byte("Bye Go!"), key, sum))
}
Output:

28 d68000ecd1481e7f8ee9e1695a6a92cbe0d6395c046b42a61ff53b77
`Hello Go!` match? true
`Bye Go!` match? false

func HMACSum256

func HMACSum256(msg, key []byte) []byte

HMACSum256 returns HMAC-SHA3/256 hash. It uses crypto/sha3.New256.

Example
package main

import (
	"encoding/hex"
	"fmt"

	"github.com/aileron-projects/go/zcrypto/zsha3"
)

func main() {
	// Calculate HMAC-SHA3/256 hash.
	// Validation data can be generated with:
	// 	- echo -n "Hello Go!" | openssl dgst -hmac "secret-key" -sha3-256

	key := []byte("secret-key")
	sum := zsha3.HMACSum256([]byte("Hello Go!"), key)
	encoded := hex.EncodeToString(sum)
	fmt.Println(len(sum), encoded)
	fmt.Println("`Hello Go!` match?", zsha3.HMACEqualSum256([]byte("Hello Go!"), key, sum))
	fmt.Println("`Bye Go!` match?", zsha3.HMACEqualSum256([]byte("Bye Go!"), key, sum))
}
Output:

32 efdfb3b8f5075ce6d3ca8dc2dbd38cb345e2287fdeb9282d2bb6a4178f688a40
`Hello Go!` match? true
`Bye Go!` match? false

func HMACSum384

func HMACSum384(msg, key []byte) []byte

HMACSum384 returns HMAC-SHA3/384 hash. It uses crypto/sha3.New384.

Example
package main

import (
	"encoding/hex"
	"fmt"

	"github.com/aileron-projects/go/zcrypto/zsha3"
)

func main() {
	// Calculate HMAC-SHA3/384 hash.
	// Validation data can be generated with:
	// 	- echo -n "Hello Go!" | openssl dgst -hmac "secret-key" -sha3-384

	key := []byte("secret-key")
	sum := zsha3.HMACSum384([]byte("Hello Go!"), key)
	encoded := hex.EncodeToString(sum)
	fmt.Println(len(sum), encoded)
	fmt.Println("`Hello Go!` match?", zsha3.HMACEqualSum384([]byte("Hello Go!"), key, sum))
	fmt.Println("`Bye Go!` match?", zsha3.HMACEqualSum384([]byte("Bye Go!"), key, sum))
}
Output:

48 d94e646a24894579d228743fa0474f338ddfc127c689c125d31df209d7428e9427ed7a7a9d376e11f93e6c9043d3317d
`Hello Go!` match? true
`Bye Go!` match? false

func HMACSum512

func HMACSum512(msg, key []byte) []byte

HMACSum512 returns HMAC-SHA3/512 hash. It uses crypto/sha3.New512.

Example
package main

import (
	"encoding/hex"
	"fmt"

	"github.com/aileron-projects/go/zcrypto/zsha3"
)

func main() {
	// Calculate HMAC-SHA3/512 hash.
	// Validation data can be generated with:
	// 	- echo -n "Hello Go!" | openssl dgst -hmac "secret-key" -sha3-512

	key := []byte("secret-key")
	sum := zsha3.HMACSum512([]byte("Hello Go!"), key)
	encoded := hex.EncodeToString(sum)
	fmt.Println(len(sum), encoded)
	fmt.Println("`Hello Go!` match?", zsha3.HMACEqualSum512([]byte("Hello Go!"), key, sum))
	fmt.Println("`Bye Go!` match?", zsha3.HMACEqualSum512([]byte("Bye Go!"), key, sum))
}
Output:

64 aceaa099f2c7c8bc17ef485bcdab407d4f23de9b312494a99b637ca90dd176c05897417a2b066f7dd4a003b554b15bf2cb8403f43c1b39ef20f74892f45f6129
`Hello Go!` match? true
`Bye Go!` match? false

func Sum224

func Sum224(b []byte) []byte

Sum224 returns SHA3/224 hash. It uses crypto/sha3.New224.

Example
package main

import (
	"encoding/hex"
	"fmt"

	"github.com/aileron-projects/go/zcrypto/zsha3"
)

func main() {
	// Calculate SHA3/224 hash.
	// Validation data can be generated with:
	// 	- echo -n "Hello Go!" | openssl dgst -sha3-224

	sum := zsha3.Sum224([]byte("Hello Go!"))
	encoded := hex.EncodeToString(sum)
	fmt.Println(len(sum), encoded)
	fmt.Println("`Hello Go!` match?", zsha3.EqualSum224([]byte("Hello Go!"), sum))
	fmt.Println("`Bye Go!` match?", zsha3.EqualSum224([]byte("Bye Go!"), sum))
}
Output:

28 ff3a0dcb416052d683762cc81b8c6cdabb2946a32fc36760708daa3d
`Hello Go!` match? true
`Bye Go!` match? false

func Sum256

func Sum256(b []byte) []byte

Sum256 returns SHA3/256 hash. It uses crypto/sha3.New256.

Example
package main

import (
	"encoding/hex"
	"fmt"

	"github.com/aileron-projects/go/zcrypto/zsha3"
)

func main() {
	// Calculate SHA3/256 hash.
	// Validation data can be generated with:
	// 	- echo -n "Hello Go!" | openssl dgst -sha3-256

	sum := zsha3.Sum256([]byte("Hello Go!"))
	encoded := hex.EncodeToString(sum)
	fmt.Println(len(sum), encoded)
	fmt.Println("`Hello Go!` match?", zsha3.EqualSum256([]byte("Hello Go!"), sum))
	fmt.Println("`Bye Go!` match?", zsha3.EqualSum256([]byte("Bye Go!"), sum))
}
Output:

32 762e68ba83959cee8da6f2255c7e6df0b1d3875b073e692d9f649dc8db4d43bc
`Hello Go!` match? true
`Bye Go!` match? false

func Sum384

func Sum384(b []byte) []byte

Sum384 returns SHA3/384 hash. It uses crypto/sha3.New384.

Example
package main

import (
	"encoding/hex"
	"fmt"

	"github.com/aileron-projects/go/zcrypto/zsha3"
)

func main() {
	// Calculate SHA3/384 hash.
	// Validation data can be generated with:
	// 	- echo -n "Hello Go!" | openssl dgst -sha3-384

	sum := zsha3.Sum384([]byte("Hello Go!"))
	encoded := hex.EncodeToString(sum)
	fmt.Println(len(sum), encoded)
	fmt.Println("`Hello Go!` match?", zsha3.EqualSum384([]byte("Hello Go!"), sum))
	fmt.Println("`Bye Go!` match?", zsha3.EqualSum384([]byte("Bye Go!"), sum))
}
Output:

48 64cb4df91df2fe72861eb7e86361a1d2ab76618442410ab671f4b3712c0376c7cb29a0b26bed63c109a30194402e883c
`Hello Go!` match? true
`Bye Go!` match? false

func Sum512

func Sum512(b []byte) []byte

Sum512 returns SHA3/512 hash. It uses crypto/sha3.New512.

Example
package main

import (
	"encoding/hex"
	"fmt"

	"github.com/aileron-projects/go/zcrypto/zsha3"
)

func main() {
	// Calculate SHA3/512 hash.
	// Validation data can be generated with:
	// 	- echo -n "Hello Go!" | openssl dgst -sha3-512

	sum := zsha3.Sum512([]byte("Hello Go!"))
	encoded := hex.EncodeToString(sum)
	fmt.Println(len(sum), encoded)
	fmt.Println("`Hello Go!` match?", zsha3.EqualSum512([]byte("Hello Go!"), sum))
	fmt.Println("`Bye Go!` match?", zsha3.EqualSum512([]byte("Bye Go!"), sum))
}
Output:

64 1ceb2a3b4536c1fc950273ea0c5c208f87ca444b41f2726b3c9bd7c25e5421f851b87162a7e3bc39eac0335faf8e27eb1eb42d419894dde64b3c6e877f7666d3
`Hello Go!` match? true
`Bye Go!` match? false

func SumShake128

func SumShake128(b []byte) []byte

SumShake128 returns SHAKE128 hash. Digest size is fixed to 256 bit. Use crypto/sha3.ShakeHash directory if variable length digest are necessary. It uses crypto/sha3.NewShake128.

Example
package main

import (
	"encoding/hex"
	"fmt"

	"github.com/aileron-projects/go/zcrypto/zsha3"
)

func main() {
	// Calculate SHAKE128 hash.
	// Validation data can be generated with(-oflen option requires openssl v3):
	// 	- echo -n "Hello Go!" | openssl dgst -shake128 -xoflen 32
	// 	- https://www.cryptool.org/en/cto/openssl/

	sum := zsha3.SumShake128([]byte("Hello Go!"))
	encoded := hex.EncodeToString(sum)
	fmt.Println(len(sum), encoded)
	fmt.Println("`Hello Go!` match?", zsha3.EqualSumShake128([]byte("Hello Go!"), sum))
	fmt.Println("`Bye Go!` match?", zsha3.EqualSumShake128([]byte("Bye Go!"), sum))
}
Output:

32 d52544db366d156a3ed524fc3d928d489d49a85c10cd268c64c6f0055dce4a5b
`Hello Go!` match? true
`Bye Go!` match? false

func SumShake256

func SumShake256(b []byte) []byte

SumShake256 returns SHAKE256 hash. Digest size is fixed to 512 bit. Use crypto/sha3.ShakeHash directory if variable length digest are necessary. It uses crypto/sha3.NewShake256.

Example
package main

import (
	"encoding/hex"
	"fmt"

	"github.com/aileron-projects/go/zcrypto/zsha3"
)

func main() {
	// Calculate SHAKE256 hash.
	// Validation data can be generated with:
	// Validation data can be generated with(-oflen option requires openssl v3):
	// 	- echo -n "Hello Go!" | openssl dgst -shake256 -xoflen 64
	// 	- https://www.cryptool.org/en/cto/openssl/

	sum := zsha3.SumShake256([]byte("Hello Go!"))
	encoded := hex.EncodeToString(sum)
	fmt.Println(len(sum), encoded)
	fmt.Println("`Hello Go!` match?", zsha3.EqualSumShake256([]byte("Hello Go!"), sum))
	fmt.Println("`Bye Go!` match?", zsha3.EqualSumShake256([]byte("Bye Go!"), sum))
}
Output:

64 755bb7002e7cbd7282cd87f4a702ba9d98573de35378fd78451bcb6a41ebf138c4035ab9b92e4d6f1041c604d0348d6d0009f1db3419560b745f3c31e6bfc463
`Hello Go!` match? true
`Bye Go!` match? false

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL