Standard library / crypto

crypto.RegisterHash()

Register a constructor for an identifier. Intended for hash implementation initialization, not routine application code. This isolated example re-registers the same SHA-256 constructor; do not replace trusted implementations or modify registration concurrently. Expected stdout: '32\n'.

Formal Syntax & Structure

go syntaxgo
func RegisterHash(h Hash, f func() hash.Hash)

Parameters & Attributes

NameTypeDescription
hHashAlgorithm identifier.
ffunc() hash.HashConstructor returning a fresh implementation.

Working Example

Example Snippetgo
package main
import (  "crypto"  "crypto/sha256"  "fmt")
func main() { crypto.RegisterHash(crypto.SHA256, sha256.New); fmt.Println(crypto.SHA256.New().Size()) }
Go Reference