argon2

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package argon2 provides argon2id hash function which satisfies the hash.Hash interface

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ID

func ID(salt []byte) hash.Hash

ID creates a new Argon2ID hash.Hash

It uses Argon2's recommended defaults. if you want to use custom argon parameters use argon2.New()

Example
package main

import (
	"fmt"

	"github.com/go-compile/rome/argon2"
)

func main() {
	// import "github.com/go-compile/rome/argon2"

	salt := []byte("dangerous-example-salt")
	// Here is a real world example of what you should do instead

	// salt := make([]byte, 16)
	// _, err := rand.Read(salt)
	// if err != nil {
	// 	panic(err)
	// }

	h := argon2.ID(salt)
	h.Write([]byte("12345"))
	h.Write([]byte("....."))

	digest := h.Sum(nil)

	// if your salt isn't constant make sure to prepend it to the
	// digest
	fmt.Printf("%x\n", digest)
}
Output:

9e200b0b4a7eb363be8f314733da18b2e7d9afa552a30e1bf57869786faf4125

func NewID

func NewID(salt []byte, time uint32, memory uint32, threads uint8, keyLen uint32) hash.Hash

NewID creates a hash.Hash for Argon2ID

Example
package main

import (
	"fmt"

	"github.com/go-compile/rome/argon2"
)

func main() {
	// import "github.com/go-compile/rome/argon2"

	salt := []byte("dangerous-example-salt")
	// Here is a real world example of what you should do instead

	// salt := make([]byte, 16)
	// _, err := rand.Read(salt)
	// if err != nil {
	// 	panic(err)
	// }

	// specify your own argon2id parameters
	h := argon2.NewID(salt, 1, 20, 1, 64)
	h.Write([]byte("12345"))
	h.Write([]byte("....."))

	digest := h.Sum(nil)

	// if your salt isn't constant make sure to prepend it to the
	// digest
	fmt.Printf("%x\n", digest)
}
Output:

13ecf23484ce58153dc0dbae3a0a1f034596abe353a60f68f9441f39952178adab4c85e14704edf73d4910b7027f7565210c28e00832293cea524fe66a5b9137

Types

type Argon2id

type Argon2id struct {
	// contains filtered or unexported fields
}

Argon2id is a hash.Hash

func (*Argon2id) BlockSize

func (h *Argon2id) BlockSize() int

BlockSize returns the hash's underlying block size. The Write method must be able to accept any amount of data, but it may operate more efficiently if all writes are a multiple of the block size.

func (*Argon2id) Reset

func (h *Argon2id) Reset()

Reset resets the Hash to its initial state.

func (*Argon2id) Size

func (h *Argon2id) Size() int

Size returns the number of bytes Sum will return.

func (*Argon2id) Sum

func (h *Argon2id) Sum(b []byte) []byte

Sum appends the current hash to b and returns the resulting slice. It does not change the underlying hash state.

func (*Argon2id) Write

func (h *Argon2id) Write(buf []byte) (int, error)

Write (via the embedded io.Writer interface) adds more data to the running hash. It never returns an error.

Jump to

Keyboard shortcuts

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