basic

package
v0.0.0-...-f6cce11 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: BSD-3-Clause Imports: 4 Imported by: 29

Documentation

Overview

Package basic is a basic implementation of a saltpack key/keyring configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EphemeralKeyCreator

type EphemeralKeyCreator struct{}

EphemeralKeyCreator creates random ephemeral keys.

func (EphemeralKeyCreator) CreateEphemeralKey

func (c EphemeralKeyCreator) CreateEphemeralKey() (saltpack.BoxSecretKey, error)

CreateEphemeralKey creates a random ephemeral key.

type Keyring

type Keyring struct {
	EphemeralKeyCreator
	// contains filtered or unexported fields
}

Keyring holds signing and box secret/public keypairs.

func NewKeyring

func NewKeyring() *Keyring

NewKeyring makes an empty new basic keyring.

func (*Keyring) GenerateBoxKey

func (k *Keyring) GenerateBoxKey() (*SecretKey, error)

GenerateBoxKey generates a new Box secret key and imports it into the keyring.

func (*Keyring) GenerateSigningKey

func (k *Keyring) GenerateSigningKey() (*SigningSecretKey, error)

GenerateSigningKey generates a signing key and import it into the keyring.

func (*Keyring) GetAllBoxSecretKeys

func (k *Keyring) GetAllBoxSecretKeys() []saltpack.BoxSecretKey

GetAllBoxSecretKeys returns all secret Box keys in the keyring.

func (*Keyring) ImportBoxEphemeralKey

func (k *Keyring) ImportBoxEphemeralKey(kid []byte) saltpack.BoxPublicKey

ImportBoxEphemeralKey takes a key ID and returns a public key useful for encryption/decryption.

func (*Keyring) ImportBoxKey

func (k *Keyring) ImportBoxKey(pub, sec *[32]byte)

ImportBoxKey imports an existing Box key into this keyring, from a raw byte arrays, first the public, and then the secret key halves.

func (*Keyring) ImportSigningKey

func (k *Keyring) ImportSigningKey(pub *[ed25519.PublicKeySize]byte, sec *[ed25519.PrivateKeySize]byte)

ImportSigningKey imports the raw signing key into the keyring.

func (*Keyring) LookupBoxPublicKey

func (k *Keyring) LookupBoxPublicKey(kid []byte) saltpack.BoxPublicKey

LookupBoxPublicKey returns the public key that corresponds to the given key ID (or "kid")

func (*Keyring) LookupBoxSecretKey

func (k *Keyring) LookupBoxSecretKey(kids [][]byte) (int, saltpack.BoxSecretKey)

LookupBoxSecretKey tries to find one of the secret keys in its keyring given the possible key IDs. It returns the index and the key, if found, and -1 and nil otherwise.

func (*Keyring) LookupSigningPublicKey

func (k *Keyring) LookupSigningPublicKey(kid []byte) saltpack.SigningPublicKey

LookupSigningPublicKey turns the given key ID ("kid") into a corresponding signing public key.

type PrecomputedSharedKey

type PrecomputedSharedKey saltpack.RawBoxKey

PrecomputedSharedKey is a basic implementation of a saltpack precomputed shared key, computed from a BasicPublicKey and a BasicPrivateKey

func (PrecomputedSharedKey) Box

func (k PrecomputedSharedKey) Box(nonce saltpack.Nonce, msg []byte) []byte

Box runs the box computation given a precomputed key.

func (PrecomputedSharedKey) Unbox

func (k PrecomputedSharedKey) Unbox(nonce saltpack.Nonce, msg []byte) ([]byte, error)

Unbox runs the unbox computation given a precomputed key.

type PublicKey

type PublicKey struct {
	EphemeralKeyCreator
	saltpack.RawBoxKey
}

PublicKey is a basic implementation of a saltpack public key

func (PublicKey) HideIdentity

func (k PublicKey) HideIdentity() bool

HideIdentity says not to hide the identity of this key.

func (PublicKey) ToKID

func (k PublicKey) ToKID() []byte

ToKID takes a Publickey and returns a "key ID" or a KID, which is just the key itself in this implementation. It can be used to identify the key.

func (PublicKey) ToRawBoxKeyPointer

func (k PublicKey) ToRawBoxKeyPointer() *saltpack.RawBoxKey

ToRawBoxKeyPointer returns a RawBoxKey from a given public key. A RawBoxKey is just a bunch of bytes that can be used in the lower-level Box libraries.

type SecretKey

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

SecretKey is a basic implementation of a saltpack private key

func NewSecretKey

func NewSecretKey(pub, sec *[32]byte) SecretKey

NewSecretKey makes a new SecretKey from the raw 32-byte arrays the represent Box public and secret keys.

func (SecretKey) Box

func (k SecretKey) Box(receiver saltpack.BoxPublicKey, nonce saltpack.Nonce, msg []byte) []byte

Box runs the NaCl box for the given sender and receiver key.

func (SecretKey) GetPublicKey

func (k SecretKey) GetPublicKey() saltpack.BoxPublicKey

GetPublicKey returns the public key that corresponds to this secret key.

func (SecretKey) GetRawPublicKey

func (k SecretKey) GetRawPublicKey() *[32]byte

GetRawPublicKey returns the raw public key that corresponds to this secret key.

func (SecretKey) GetRawSecretKey

func (k SecretKey) GetRawSecretKey() *[32]byte

GetRawSecretKey returns the raw secret key.

func (SecretKey) Precompute

Precompute computes a shared key with the passed public key.

func (SecretKey) Unbox

func (k SecretKey) Unbox(sender saltpack.BoxPublicKey, nonce saltpack.Nonce, msg []byte) ([]byte, error)

Unbox runs the NaCl unbox operation on the given ciphertext and nonce, using the receiver as the secret key.

type SigningPublicKey

type SigningPublicKey saltpack.RawBoxKey

SigningPublicKey is a basic public key used for verifying signatures. It's just a wrapper around an array of bytes.

func NewSigningPublicKey

func NewSigningPublicKey(pub *[ed25519.PublicKeySize]byte) SigningPublicKey

NewSigningPublicKey creates a new public signing key from a byte array.

func (SigningPublicKey) ToKID

func (k SigningPublicKey) ToKID() []byte

ToKID returns the key id for this signing key. It just returns the key itself.

func (SigningPublicKey) Verify

func (k SigningPublicKey) Verify(msg []byte, sig []byte) error

Verify runs the NaCl verification routine on the given msg / sig input.

type SigningSecretKey

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

SigningSecretKey is a basic secret key used for creating signatures and also for verifying signatures. It's a wrapper around an array of bytes and also the corresponding public key.

func NewSigningSecretKey

func NewSigningSecretKey(pub *[ed25519.PublicKeySize]byte, sec *[ed25519.PrivateKeySize]byte) SigningSecretKey

NewSigningSecretKey creates a new basic signing key from byte arrays.

func (SigningSecretKey) GetPublicKey

func (k SigningSecretKey) GetPublicKey() saltpack.SigningPublicKey

GetPublicKey gets the public key that corresponds to this secret signing key

func (SigningSecretKey) GetRawPublicKey

func (k SigningSecretKey) GetRawPublicKey() *[ed25519.PublicKeySize]byte

GetRawPublicKey returns the raw public key that corresponds to this secret key.

func (SigningSecretKey) GetRawSecretKey

func (k SigningSecretKey) GetRawSecretKey() *[ed25519.PrivateKeySize]byte

GetRawSecretKey returns the raw secret key.

func (SigningSecretKey) Sign

func (k SigningSecretKey) Sign(msg []byte) (ret []byte, err error)

Sign runs the NaCl signature scheme on the input message, returning a signature.

Jump to

Keyboard shortcuts

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