fasthmacsha

package module
v0.0.0-...-35d63e3 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2019 License: MIT Imports: 7 Imported by: 0

README

fasthmacsha-go

"fasthmacsha-go" ports the golang native hmac + shax but zero allocate

go test -v -benchmem -run="^$" ./... -bench ^Benchmark
goos: darwin
goarch: amd64
pkg: github.com/detailyang/fasthmacsha-go
BenchmarkHmacHighway256-8          	 3000000	       548 ns/op	1865.94 MB/s	     416 B/op	       2 allocs/op
BenchmarkDefaultHmacHighway256-8   	 3000000	       500 ns/op	2047.19 MB/s	       0 B/op	       0 allocs/op
BenchmarkFastHMACSHA1-8            	 1000000	      2144 ns/op	 477.44 MB/s	       0 B/op	       0 allocs/op
BenchmarkGoHMACSHA1-8              	  500000	      2522 ns/op	 406.02 MB/s	     484 B/op	       7 allocs/op
BenchmarkFastHMACSHA256-8          	  300000	      4125 ns/op	 248.23 MB/s	       0 B/op	       0 allocs/op
BenchmarkGoHMACSHA256-8            	  300000	      4689 ns/op	 218.37 MB/s	     516 B/op	       7 allocs/op
BenchmarkFastHMACSHA512-8          	  500000	      3729 ns/op	 274.53 MB/s	       0 B/op	       0 allocs/op
BenchmarkGoHMACSHA512-8            	  300000	      4228 ns/op	 242.19 MB/s	     868 B/op	       7 allocs/op
PASSp

Documentation

Overview

Package fasthmacsha implements the Keyed-Hash Message Authentication Code (HMAC) as defined in U.S. Federal Information Processing Standards Publication 198. An HMAC is a cryptographic hash that uses a key to sign a message. The receiver verifies the hash by recomputing it using the same key.

Receivers should be careful to use Equal to compare MACs in order to avoid timing side-channels:

// ValidMAC reports whether messageMAC is a valid HMAC tag for message.
func ValidMAC(message, messageMAC, key []byte) bool {
	mac := hmac.New(sha256.New, key)
	mac.Write(message)
	expectedMAC := mac.Sum(nil)
	return hmac.Equal(messageMAC, expectedMAC)
}

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultHighwayhash256Salt holds the default salt
	DefaultHighwayhash256Salt = [32]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
		17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
)

Functions

func AcquireDefaultHighway256

func AcquireDefaultHighway256() hash.Hash

func AcquireSHA1

func AcquireSHA1() *sha1.Digest

AcquireSHA1 acquires *sha1.Digest

func AcquireSHA1Tuple

func AcquireSHA1Tuple() *[2]*sha1.Digest

AcquireSHA1Tuple acquires [2]*sha1.Digest

func AcquireSHA256

func AcquireSHA256() *sha256.Digest

AcquireSHA256 acquires *sha256.Digest

func AcquireSHA256Tuple

func AcquireSHA256Tuple() *[2]*sha256.Digest

AcquireSHA256Tuple acquires [2]*sha256.Digest

func AcquireSHA512

func AcquireSHA512() *sha512.Digest

AcquireSHA512 acquires *sha512.Digest

func AcquireSHA512Tuple

func AcquireSHA512Tuple() *[2]*sha512.Digest

AcquireSHA512Tuple acquires [2]*sha512.Digest

func Equal

func Equal(mac1, mac2 []byte) bool

Equal compares two MACs for equality without leaking timing information.

func HMACHighway256

func HMACHighway256(salt, key, in, out []byte) ([]byte, error)

HMACHighway256 does hmac + highway256

func HMACHighway256DefaultSalt

func HMACHighway256DefaultSalt(key, in, out []byte) ([]byte, error)

HMACHighway256DefaultSalt does hmac + highwayhash256 but use default salt

func HMACSHA1

func HMACSHA1(key, in, out []byte) ([]byte, error)

HMACSHA1 does hmac + sha1

func HMACSHA256

func HMACSHA256(key, in, out []byte) ([]byte, error)

HMACSHA256 does hmac + sha256

func HMACSHA512

func HMACSHA512(key, in, out []byte) ([]byte, error)

HMACSHA512 does hmac + sha512

func New

func New(h func() hash.Hash, key []byte) hash.Hash

New returns a new HMAC hash using the given hash.Hash type and key. Note that unlike other hash implementations in the standard library, the returned Hash does not implement encoding.BinaryMarshaler or encoding.BinaryUnmarshaler.

func ReleaseDefaultHighway256

func ReleaseDefaultHighway256(h hash.Hash)

func ReleaseSHA1

func ReleaseSHA1(d *sha1.Digest)

ReleaseSHA1 releases *sha1.Digest

func ReleaseSHA1Tuple

func ReleaseSHA1Tuple(d *[2]*sha1.Digest)

ReleaseSHA1Tuple releases [2]*sha1.Digest

func ReleaseSHA256

func ReleaseSHA256(d *sha256.Digest)

ReleaseSHA256 releases *sha256.Digest

func ReleaseSHA256Tuple

func ReleaseSHA256Tuple(d *[2]*sha256.Digest)

ReleaseSHA256Tuple releases [2]*sha256.Digest

func ReleaseSHA512

func ReleaseSHA512(d *sha512.Digest)

ReleaseSHA512 releases *sha512.Digest

func ReleaseSHA512Tuple

func ReleaseSHA512Tuple(d *[2]*sha512.Digest)

ReleaseSHA512Tuple releases [2]*sha512.Digest

Types

This section is empty.

Directories

Path Synopsis
Package sha1 implements the SHA-1 hash algorithm as defined in RFC 3174.
Package sha1 implements the SHA-1 hash algorithm as defined in RFC 3174.
Package sha256 implements the SHA224 and SHA256 hash algorithms as defined in FIPS 180-4.
Package sha256 implements the SHA224 and SHA256 hash algorithms as defined in FIPS 180-4.
Package sha512 implements the SHA-384, SHA-512, SHA-512/224, and SHA-512/256 hash algorithms as defined in FIPS 180-4.
Package sha512 implements the SHA-384, SHA-512, SHA-512/224, and SHA-512/256 hash algorithms as defined in FIPS 180-4.

Jump to

Keyboard shortcuts

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