oracle

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 20 Imported by: 0

README

Oracle

go oracle

Oracle is a go library that provides the following cryptographic functions:

  • generate key-pairs
  • encrypt messages
  • decrypt messages
  • sign messages
  • validate messages

Oracle is the basic object that can perform these functions. It also has the concept of a Peer, which is public key. Useful for validating and encrypting.

Keys are Curve25519.

Documentation

Index

Constants

View Source
const GLOBAL_SALT = "oracle/v1"

Variables

View Source
var ErrInvalidConfig = errors.New("invalid config")
View Source
var ErrKeysAlreadyExist = errors.New("crypto keys already exists")
View Source
var ErrNoEphemeralKey = errors.New("no ephemeral key")
View Source
var ErrNotInitialized = errors.New("oracle has not been initialized")
View Source
var UniversalNonce []byte = make([]byte, chacha20poly1305.NonceSize)
View Source
var ZeroPrivateKey *ecdh.PrivateKey = new(ecdh.PrivateKey)
View Source
var ZeroPublicKey *ecdh.PublicKey = new(ecdh.PublicKey)

Functions

func PublicKeyFromHex

func PublicKeyFromHex(hexData []byte) (*ecdh.PublicKey, error)

Types

type CipherText

type CipherText struct {
	Type               string            `json:"type" ion:"type"`
	Headers            map[string]string `json:"headers" ion:"headers"`
	AdditionalData     []byte            `json:"aad" ion:"aad"`
	CipherTextData     []byte            `json:"ciphertext" ion:"ciphertext"`
	Signature          []byte            `json:"signature" ion:"signature"`
	Nonce              []byte            `json:"nonce" ion:"nonce"`
	EphemeralPublicKey []byte            `json:"ephpub" ion:"ephpub"`
	// contains filtered or unexported fields
}

CipherText includes payload and metadata for receiving and decrypting

func (*CipherText) Clone added in v0.1.0

func (c1 *CipherText) Clone(c2 *CipherText)

func (*CipherText) From added in v0.1.0

func (ct *CipherText) From(pt *PlainText)

create CipherText from PlainText This does _not_ peform encryption. you must handle PlainTextData and CipherTextData fields seperately.

func (*CipherText) GenerateSharedSecret added in v0.1.0

func (ct *CipherText) GenerateSharedSecret(randomness io.Reader) error

func (*CipherText) MarshalIon added in v0.1.0

func (ct *CipherText) MarshalIon() ([]byte, error)

func (*CipherText) MarshalPEM

func (ct *CipherText) MarshalPEM() ([]byte, error)

func (*CipherText) UnmarshalIon added in v0.1.0

func (ct *CipherText) UnmarshalIon(bin []byte) error

func (*CipherText) UnmarshalPEM

func (ct *CipherText) UnmarshalPEM(data []byte) error

type Config

type Config struct {
	Self  Self                `toml:"self" json:"self"`
	Peers []map[string]string `toml:"peer" json:"peer"`
}
var ZeroConf Config

func ConfigFrom added in v0.1.2

func ConfigFrom(r io.Reader) (Config, error)

func (Config) String added in v0.1.2

func (c Config) String() string

func (Config) Valid added in v0.1.2

func (c Config) Valid() bool

type Flarg added in v0.1.2

type Flarg struct {
	Subcommand   string
	ConfigFile   *os.File
	Format       string
	InputStream  io.Reader
	OutputStream io.Writer
}

Flarg represents all the args and flags after normalization and validation

var NoFlarg Flarg

The NoFlarg Flarg is used in error conditions

type Message added in v0.1.0

type Message interface {
	Digest() ([]byte, error)
	//Validate() error
	Sign(io.Reader, ed25519.PrivateKey)
	Verify(ed25519.PublicKey) bool
	Encrypt(io.Reader, ed25519.PublicKey) (*CipherText, error)
	Decrypt(ed25519.PrivateKey) (*PlainText, error)
	PlainText() ([]byte, error)
	CipherText() ([]byte, error)
}

type Oracle

type Oracle interface {
	PrivateSigningKey() ed25519.PrivateKey
	PublicSigningKey() ed25519.PublicKey
	PrivateEncryptionKey() *ecdh.PrivateKey
	PublicEncryptionKey() *ecdh.PublicKey
	Compose(string, []byte) *PlainText
	Sign(*PlainText) error
	Verify(*PlainText, Peer) bool
	Encrypt(*PlainText, Peer) (*CipherText, error)
	Decrypt(*CipherText) (*PlainText, error)
	Export(io.Writer) error
	//Import(Config) error
	Randomness() io.Reader
	AddPeer(Peer) error
	AsPeer() Peer
	Peer(string) (Peer, error)
	Peers() map[string]Peer
}

func From

func From(r io.Reader) (Oracle, error)

load an Oracle from a file or other io.Reader

func FromFile added in v0.1.0

func FromFile(path string) (Oracle, error)

func New

func New(rand io.Reader) Oracle

create a new Oracle with new key-pairs.

type Peer

type Peer interface {
	crypto.PublicKey
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler
	json.Marshaler
	json.Unmarshaler
	//toml.Marshaler
	//toml.Unmarshaler
	MarshalHex() ([]byte, error)
	UnmarshalHex(data []byte) error
	Bytes() []byte
	Public() crypto.PublicKey // returns signing key
	SigningKey() ed25519.PublicKey
	EncryptionKey() *ecdh.PublicKey
	Nickname() string
	AsMap() map[string]string
}

func NewPeer added in v0.1.1

func NewPeer(seed []byte) Peer

func PeerFromHex

func PeerFromHex(hexData []byte) (Peer, error)

type PlainText

type PlainText struct {
	Type               string            `json:"type" ion:"type"`
	Headers            map[string]string `json:"headers" ion:"headers"`
	AdditionalData     []byte            `json:"aad" ion:"aad"`
	PlainTextData      []byte            `json:"plaintext" ion:"plaintext"`
	Signature          []byte            `json:"signature" ion:"signature"`
	Nonce              []byte            `json:"nonce" ion:"nonce"`
	EphemeralPublicKey []byte            `json:"ephpub" ion:"ephpub"`
	// contains filtered or unexported fields
}

PlainText includes payload and metadata for encrypting and sending

func (*PlainText) CipherText added in v0.1.0

func (pt *PlainText) CipherText() ([]byte, error)

func (*PlainText) Clone added in v0.1.0

func (pt *PlainText) Clone(p2 *PlainText)

func (*PlainText) Digest added in v0.1.0

func (pt *PlainText) Digest() ([]byte, error)

func (*PlainText) From added in v0.1.0

func (pt *PlainText) From(ct *CipherText)

func (*PlainText) MarshalIon added in v0.1.0

func (pt *PlainText) MarshalIon() ([]byte, error)

func (*PlainText) MarshalPEM added in v0.1.0

func (pt *PlainText) MarshalPEM() ([]byte, error)

func (*PlainText) PlainText added in v0.1.0

func (pt *PlainText) PlainText() ([]byte, error)

func (*PlainText) Sign added in v0.1.0

func (pt *PlainText) Sign(randy io.Reader, priv ed25519.PrivateKey) error

func (*PlainText) String

func (pt *PlainText) String() string

func (*PlainText) UnmarshalIon added in v0.1.0

func (pt *PlainText) UnmarshalIon(bin []byte) error

func (*PlainText) UnmarshalPEM added in v0.1.0

func (pt *PlainText) UnmarshalPEM(data []byte) error

func (*PlainText) Verify added in v0.1.0

func (pt *PlainText) Verify(pub ed25519.PublicKey) bool

type Self

type Self struct {
	PrivateKey string `toml:"priv" json:"priv"`
	PublicKey  string `toml:"pub" json:"pub"`
	Nickname   string `toml:"nick" json:"nick"`
}

func (Self) Valid added in v0.1.2

func (s Self) Valid() bool

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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