crypto

package
v0.0.0-...-3aa76b9 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const AES256KeySize = 32

AES256KeySize key size for AES-256

Variables

View Source
var (
	ErrHashMissmatch = errors.New("hashes do not match")
	ErrInvalidKey    = errors.New("invalid key")
)

Common errors

View Source
var (
	ErrToShortCiphertext = errors.New("ciphertext too short")
)

Common encryption / decryption errors.

Functions

func GenerateAESKey

func GenerateAESKey() ([]byte, error)

GenerateAESKey generates a random AES-256 key.

func Hmac

func Hmac(message, key []byte) ([]byte, error)

Hmac computes a hmac using SHA-256.

func RandomBytes

func RandomBytes(n int) ([]byte, error)

RandomBytes generates an array of n random bytes.

Types

type AESCipher

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

AESCipher symetric cipher implementation using AES-GCM.

func NewAESCipher

func NewAESCipher(key []byte) *AESCipher

NewAESCipher creates a new AES-GCM cipher with the given key.

func (*AESCipher) Decrypt

func (c *AESCipher) Decrypt(ciphertext []byte) ([]byte, error)

Decrypt decrypts the provided ciphertexts with the chiphers key.

func (*AESCipher) Encrypt

func (c *AESCipher) Encrypt(plaintext []byte) ([]byte, error)

Encrypt encrypts the provided plaintext with the chiphers key.

type Argon2Hasher

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

Argon2Hasher hasher implementation using the Argon2id key derivation function.

func (*Argon2Hasher) Hash

func (h *Argon2Hasher) Hash(plaintext, salt []byte) ([]byte, error)

Hash derives a key using Argon2id.

func (*Argon2Hasher) Verify

func (h *Argon2Hasher) Verify(plaintext, salt, hashtext []byte) error

Verify verifies that the plaintext and salt hash to the given hashtext.

type Cipher

type Cipher interface {
	Encrypt(plaintext []byte) ([]byte, error)
	Decrypt(ciphertext []byte) ([]byte, error)
}

Cipher symetric chipher interface.

func NewCipher

func NewCipher(key []byte) Cipher

NewCipher creates a new cipher using the default implementation.

type Hasher

type Hasher interface {
	Hash(plaintext, salt []byte) ([]byte, error)
	Verify(plaintext, salt, hashtext []byte) error
}

Hasher interface for hashing and verifying hased values.

func DefaultArgon2Hasher

func DefaultArgon2Hasher() Hasher

func DefaultScryptHasher

func DefaultScryptHasher() Hasher

DefaultScryptHasher creates scrypt hasher with the default key parameters

func NewArgon2Hasher

func NewArgon2Hasher(time, memory, keyLen uint32, threads uint8) Hasher

NewArgon2Hasher creates a new Argon2id hasher

func NewScryptHasher

func NewScryptHasher(N, r, p, keyLen int) Hasher

NewScryptHasher creates a new scrypt hasher

type ScryptHasher

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

ScryptHasher hasher implementation using the SCRYPT key derivation function.

func (*ScryptHasher) Hash

func (h *ScryptHasher) Hash(plaintext, salt []byte) ([]byte, error)

func (*ScryptHasher) Verify

func (h *ScryptHasher) Verify(plaintext, salt, hashtext []byte) error

Verify verifies that plaintext and salt hash to the given hashtext.

type Sha256Hasher

type Sha256Hasher struct{}

Sha256Hasher hasher implementation using sha256 as a hash function.

func (*Sha256Hasher) Hash

func (h *Sha256Hasher) Hash(plaintext, salt []byte) ([]byte, error)

Hash computes hmac of plaintext and salt and calculates a SHA-256 hash on the output.

func (*Sha256Hasher) Verify

func (h *Sha256Hasher) Verify(plaintext, salt, hashtext []byte) error

Verify verifies that plaintext and salt hash to the given hashtext.

Jump to

Keyboard shortcuts

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