zblake2b

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 BLAKE2b-256 hash. It returns if the sum matches to the hash of b.

func EqualSum384

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

EqualSum384 compares BLAKE2b-384 hash. It returns if the sum matches to the hash of b.

func EqualSum512

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

EqualSum512 compares BLAKE2b-512 hash. It returns if the sum matches to the hash of b.

func HMACEqualSum256

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

HMACEqualSum256 compares HMAC-BLAKE2b-256 hash. It returns if the sum matches to the hash of msg.

func HMACEqualSum384

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

HMACEqualSum384 compares HMAC-BLAKE2b-384 hash. It returns if the sum matches to the hash of msg.

func HMACEqualSum512

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

HMACEqualSum512 compares HMAC-BLAKE2b-512 hash. It returns if the sum matches to the hash of msg.

func HMACSum256

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

HMACSum256 returns HMAC-BLAKE2b-256 hash. If the key length is grater than 64, it will be shorten to 64 bytes using sha512.Sum512. It uses golang.org/x/crypto/blake2b.New256.

Example
package main

import (
	"encoding/hex"
	"fmt"

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

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

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

32 58c69dd63e35195bbda689a35be453959e06e1b9a7de3bb9c41b7f392f80830a
`Hello Go!` match? true
`Bye Go!` match? false

func HMACSum384

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

HMACSum384 returns HMAC-BLAKE2b-384 hash. If the key length is grater than 64, it will be shorten to 64 bytes using sha512.Sum512. It uses golang.org/x/crypto/blake2b.New384.

Example
package main

import (
	"encoding/hex"
	"fmt"

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

func main() {
	// Calculate HMAC-BLAKE2b-384 hash.
	// Validation data can be generated with:
	// 	- https://emn178.github.io/online-tools/blake2b/
	// 	- https://toolkitbay.com/tkb/tool/BLAKE2b_384

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

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

func HMACSum512

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

HMACSum512 returns HMAC-BLAKE2b-512 hash. If the key length is grater than 64, it will be shorten to 64 bytes using sha512.Sum512. It uses golang.org/x/crypto/blake2b.New512.

Example
package main

import (
	"encoding/hex"
	"fmt"

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

func main() {
	// Calculate HMAC-BLAKE2b-512 hash.
	// Validation data can be generated with:
	// 	- https://emn178.github.io/online-tools/blake2b/
	// 	- https://toolkitbay.com/tkb/tool/BLAKE2b_512

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

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

func Sum256

func Sum256(b []byte) []byte

Sum256 returns BLAKE2b-256 hash. It uses golang.org/x/crypto/blake2b.New256.

Example
package main

import (
	"encoding/hex"
	"fmt"

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

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

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

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

func Sum384

func Sum384(b []byte) []byte

Sum384 returns BLAKE2b-384 hash. It uses golang.org/x/crypto/blake2b.New384.

Example
package main

import (
	"encoding/hex"
	"fmt"

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

func main() {
	// Calculate BLAKE2b-384 hash.
	// Validation data can be generated with:
	// 	- https://emn178.github.io/online-tools/blake2b/
	// 	- https://toolkitbay.com/tkb/tool/BLAKE2b_384

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

48 779700376f9b32c6b7843811a1116570d3ffdd599a7b587fe081aa920829d3ac65e8f6e0bf4d9bcd73eeb5f3f9906577
`Hello Go!` match? true
`Bye Go!` match? false

func Sum512

func Sum512(b []byte) []byte

Sum512 returns BLAKE2b-512 hash. It uses golang.org/x/crypto/blake2b.New512.

Example
package main

import (
	"encoding/hex"
	"fmt"

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

func main() {
	// Calculate BLAKE2b-512 hash.
	// Validation data can be generated with:
	// 	- https://emn178.github.io/online-tools/blake2b/
	// 	- https://toolkitbay.com/tkb/tool/BLAKE2b_512

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

64 02fcc96a71f7df80c2bf8046ef93d2deac992980cef3ea8f7bedd9d4c1e2f87596fb23d527508e8a1c7617510686801a5f714444070f5625572cad1b9fb51bab
`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