crypto

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package crypto implements basic crypto primitives used in the project

Index

Constants

View Source
const (
	KeyLength = 32
)

Variables

This section is empty.

Functions

func Float64 added in v0.6.2

func Float64() float64

Float64 is a shortcut for generating a random float between 0 and 1 using crypto/rand.

func GetRandomString added in v0.6.0

func GetRandomString(n int, runes string) (string, error)

GetRandomString generates a random string for cryptographic usage.

func GetRandomValueFromInterval added in v0.6.2

func GetRandomValueFromInterval[V ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | float32 | float64](randomizationFactor float64, currentInterval V) V

Returns a random value from the following interval:

[currentInterval - randomizationFactor * currentInterval, currentInterval + randomizationFactor * currentInterval].

func Intn added in v0.6.2

func Intn(maxi int64) int64

Intn is a shortcut for generating a random integer between 0 and max using crypto/rand.

Types

type Key

type Key [KeyLength]byte //nolint:recvcheck

func GenerateKey

func GenerateKey() (Key, error)

func GenerateKeyFromPassword

func GenerateKeyFromPassword(pw string) Key

func GeneratePrivateKey

func GeneratePrivateKey() (Key, error)

func ParseKey

func ParseKey(str string) (Key, error)

func ParseKeyBytes

func ParseKeyBytes(buf []byte) (Key, error)

func (Key) Bytes

func (k Key) Bytes() []byte

func (Key) IPAddress

func (k Key) IPAddress(p net.IPNet) net.IPNet

func (Key) IsSet

func (k Key) IsSet() bool

Checks if the key is not zero.

func (Key) MarshalText

func (k Key) MarshalText() ([]byte, error)

func (Key) PublicKey

func (k Key) PublicKey() Key

func (Key) String

func (k Key) String() string

func (*Key) UnmarshalText

func (k *Key) UnmarshalText(text []byte) error

type KeyPair

type KeyPair struct {
	Ours   Key `json:"ours"`
	Theirs Key `json:"theirs"`
}

func (KeyPair) Public

func (kp KeyPair) Public() PublicKeyPair

func (KeyPair) Shared

func (kp KeyPair) Shared() Key

type KeyPassphrase

type KeyPassphrase Key

A key which uses GenerateKeyFromPassword() for UnmarshalText().

func (*KeyPassphrase) UnmarshalText

func (k *KeyPassphrase) UnmarshalText(text []byte) error

type Nonce

type Nonce []byte

func GetNonce

func GetNonce(length int) (Nonce, error)

type PublicKeyPair

type PublicKeyPair KeyPair

Directories

Path Synopsis
Package siphash implements SipHash-2-4, a fast short-input PRF created by Jean-Philippe Aumasson and Daniel J. Bernstein.
Package siphash implements SipHash-2-4, a fast short-input PRF created by Jean-Philippe Aumasson and Daniel J. Bernstein.

Jump to

Keyboard shortcuts

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