crypto

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

package crypto provides helper functions for an established set of crypto libraries (nacl, scrypt)

Index

Constants

This section is empty.

Variables

View Source
var DefaultScryptConfig = ScryptConfig{
	N: 1 << uint64(15),
	R: 8,
	P: 1,
}

requires 32MB RAM for under a second (i7).

Functions

func DecryptSbox

func DecryptSbox(key []byte, data []byte) ([]byte, error)

panics if key is nil

func Encrypt

func Encrypt(scryptConfig *ScryptConfig, password string, data []byte) ([]byte, error)

Encrypts given data with nacl/secretbox using a scrypt derived key. The first 24 bytes of the resulting byte slice contain the scrypt configuration. The following 32 bytes contain the scrypt salt. All remaining bytes represent the encrypted data.

func EncryptSbox

func EncryptSbox(key []byte, data []byte) ([]byte, error)

func GenerateScryptSalt

func GenerateScryptSalt() ([]byte, error)

Types

type ScryptConfig

type ScryptConfig struct {
	// CPU/memory cost parameter (logN)
	N uint64 `json:"n"`

	// block size parameter (octets)
	R uint64 `json:"r"`

	// parallelisation parameter (positive int)
	P uint64 `json:"p"`
}

func DecodeScryptConfig

func DecodeScryptConfig(data []byte) (ScryptConfig, error)

func Decrypt

func Decrypt(password string, data []byte) ([]byte, *ScryptConfig, error)

func (ScryptConfig) Derive

func (config ScryptConfig) Derive(salt []byte, keyLen int, password string) ([]byte, error)

func (ScryptConfig) Encode

func (config ScryptConfig) Encode() []byte

func (ScryptConfig) MemoryRequiredMB

func (config ScryptConfig) MemoryRequiredMB() int

func (ScryptConfig) TimeRequiredMS

func (config ScryptConfig) TimeRequiredMS() (int, error)

Jump to

Keyboard shortcuts

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