zblake2s

package
v0.0.0-alpha.14 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func EqualSum256

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

EqualSum256 compares BLAKE2s-256 hash. It returns if the sum matches to the hash of b.

func HMACEqualSum256

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

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

func HMACSum256

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

HMACSum256 returns HMAC-BLAKE2s/256 hash. If the key length is grater than 32, it will be shorten to 32 bytes using sha256.Sum256. It uses golang.org/x/crypto/blake2s.New256.

Example
package main

import (
	"encoding/hex"
	"fmt"

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

func main() {
	// Calculate HMAC-BLAKE2s-256 hash.
	// Validation data can be generated with:
	// 	- https://emn178.github.io/online-tools/blake2s/
	// 	- https://toolkitbay.com/tkb/tool/BLAKE2s_256

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

32 3f010ec9bff3d4f9d0f6d020dcacfe9e2a2da397bce893b3bdfdb038d628875d
`Hello Go!` match? true
`Bye Go!` match? false

func Sum256

func Sum256(b []byte) []byte

Sum256 returns BLAKE2s-256 hash. It uses golang.org/x/crypto/blake2s.New256.

Example
package main

import (
	"encoding/hex"
	"fmt"

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

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

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

32 0eb35c8350638fdb21de90833229bad5b19a0d3a9e61cc307c3c9b59859ea24c
`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