hash

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2020 License: MIT Imports: 7 Imported by: 0

README

Hash Functions

This package implements the hash functions specified in the noise protocol framework.

Built-in Hash Functions

Four hash functions are supported, as specified in the noise specs.

  1. SHA256
  2. SHA512
  3. BLAKE2b
  4. BLAKE2s

Customize Hash Functions

To create your own hash function, you'll need to implement the interface specified in hash.go. Once implemented, you need to register it using Register(Name, Hash).

Check examples/newhash, which implements SHA3, once implemented, Once implemented, it can be used via the protocol name,

// register SHA3
noiseHash.Register("SHA3", newSha3)

// Now "SHA3" is a valid hash name, and it can be used in the protocol name as,
p, _ := babble.NewProtocol("Noise_NN_25519_ChaChaPoly_SHA3", "Demo", true)

Documentation

Overview

Package hash implements the hash functions specified in the noise protocol.

It currently supports four hash functions: SHA256, SHA512, BLAKE2a, and BLAKE2s.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(s string, new NewHash)

Register updates the supported hashes used in package hash.

func SupportedHashes

func SupportedHashes() string

SupportedHashes gives the names of all the hashs registered. If no new hashs are registered, it returns a string as "AESGCM, ChaChaPoly", orders not preserved.

Types

type Hash

type Hash interface {
	fmt.Stringer

	// BlockLen returns a constant specifying the size in bytes that the hash
	// function uses internally to divide its input for iterative processing.
	// This is needed to use the hash function with HMAC.
	BlockLen() int

	// New returns the hash function used.
	New() hash.Hash

	// HashLen returns a constant specifying the size in bytes of the hash
	// output. Must be 32 or 64.
	HashLen() int

	// Reset resets the Hash to its initial state.
	Reset()
}

Hash defines a hash interface specified by the noise specs.

func FromString

func FromString(s string) (Hash, error)

FromString uses the provided hash name, s, to query a built-in hash.

Example
package main

import (
	"fmt"

	"github.com/yyforyongyu/babble/hash"
)

func main() {
	// load hash sha256
	sha256, _ := hash.FromString("SHA256")
	fmt.Println(sha256)

	// load hash sha512
	sha512, _ := hash.FromString("SHA512")
	fmt.Println(sha512)

	// load hash blake2s
	blake2s, _ := hash.FromString("BLAKE2s")
	fmt.Println(blake2s)

	// load hash blake2b
	blake2b, _ := hash.FromString("BLAKE2b")
	fmt.Println(blake2b)
}
Output:

type NewHash

type NewHash func() Hash

NewHash returns an instance of Hash.

Jump to

Keyboard shortcuts

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