hashing

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package hashing contains simple hashing functionality. This is NOT meant for passwords, but rather for simply verifying the integrity of a message using a secret.

Note this does not allow for any other party to verify authenticity of a message, as the secret should not be shared.

Index

Constants

View Source
const HMACKeySize = 64

HMACKeySize is the expected size of an HMAC hashing key.

Variables

This section is empty.

Functions

This section is empty.

Types

type HMACKey

type HMACKey [HMACKeySize]byte

HMACKey is a secret key used for message hashing using HMAC+SHA256.

I've chosen to use HMAC+SHA256 instead of ed25519 due to the fact that it's more standard and mostly equivalent in other ways for a "secret key hashing" use case. This is for when don't need a public key setup to allow others to verify the identity of the hasher, just for us to verify that we created the message.

func NewHMACKey

func NewHMACKey() HMACKey

NewHMACKey creates a new cryptographically random HMAC key with HMACKeySize bytes.

You typically will want to store the output of this (the generated key) and use it repeatedly, hashing messages that you send out and checking validity when returned to you.

func (*HMACKey) Hash

func (key *HMACKey) Hash(msg string) []byte

Hash returns the SHA256 hash of the bytes in the given message, calculated using our key.

func (*HMACKey) IsValid

func (key *HMACKey) IsValid(msg string, givenMac []byte) bool

IsValid returns true if the givenMac bytes are a valid hash of the bytes in msg, calculated using our key.

Jump to

Keyboard shortcuts

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