oracle

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 18 Imported by: 4

README

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 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 NicknameFromPublicKey

func NicknameFromPublicKey(sPub ed25519.PublicKey) string

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"`
	Peers []map[string]string `toml:"peer"`
}

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) (Message, error)
	Decrypt(ed25519.PrivateKey) (Message, error)
	PlainText() ([]byte, error)
	CipherText() ([]byte, error)
}

type Oracle

type Oracle struct {
	EncryptionPrivateKey *ecdh.PrivateKey
	EncryptionPublicKey  *ecdh.PublicKey

	SigningPrivateKey ed25519.PrivateKey
	SigningPublicKey  ed25519.PublicKey

	Peers map[string]Peer
	// contains filtered or unexported fields
}

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.

func (*Oracle) AddPeer

func (o *Oracle) AddPeer(p Peer) error

Make an Oracle aware of a Peer, so it can encrypt messages or validate signatures

func (*Oracle) AsPeer

func (o *Oracle) AsPeer() *Peer

Export the Oracle as a Peer, ensuring only public information is exported

func (*Oracle) Compose added in v0.1.0

func (o *Oracle) Compose(subject string, body []byte, recipient *Peer) *PlainText

compose a message intended for a peer

func (*Oracle) Decrypt

func (o *Oracle) Decrypt(ct *CipherText, sender *Peer) (*PlainText, error)

decrypt CipherText, returning PlainText

func (*Oracle) Encrypt

func (o *Oracle) Encrypt(rand io.Reader, pt *PlainText, recipient *Peer) (*CipherText, error)

encrypt PlaintText, returning CipherText

func (*Oracle) Export

func (o *Oracle) Export(w io.Writer) error

write an Oracle as a Config to an io.Writer @warning: includes Private key. This should be considered secret

func (*Oracle) GenerateKeys

func (o *Oracle) GenerateKeys(rand io.Reader) error

func (*Oracle) Load

func (o *Oracle) Load(r io.Reader) error

Load an oracle from a Config

func (*Oracle) Nickname

func (o *Oracle) Nickname() string

an easy way to uniquely identify a Peer. Nickname is dereived from PublicKey

func (*Oracle) Peer

func (o *Oracle) Peer(nick string) (*Peer, error)

get a Peer from its Nickname

func (*Oracle) Public

func (o *Oracle) Public() crypto.PublicKey

func (*Oracle) PublicKeyAsHex

func (o *Oracle) PublicKeyAsHex() []byte

func (*Oracle) Sign

func (o *Oracle) Sign(pt *PlainText) error

func (*Oracle) Verify

func (o *Oracle) Verify(pt *PlainText, sender *Peer) bool

type Peer

type Peer struct {
	EncryptionPublicKey *ecdh.PublicKey   `toml:"ePub"`
	SigningPublicKey    ed25519.PublicKey `toml:"sPub"`
	Nickname            string            `toml:"Nickname"`
}

a Peer is a representation of an entity with a PublicKey, and some optional props. It must be fully [de]serializable

func PeerFromHex

func PeerFromHex(ePubHex, sPubHex string) Peer

a Peer can be hydrated from two public keys

func PeerFromPublicKeys added in v0.1.0

func PeerFromPublicKeys(ePub *ecdh.PublicKey, sPub ed25519.PublicKey) Peer

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 Principal added in v0.1.0

type Principal interface {
	PrivateSigningKey() ed25519.PrivateKey
	PublicSigningKey() ed25519.PublicKey
	PrivateEncryptionKey() *ecdh.PrivateKey
	PublicEncryptionKey() *ecdh.PublicKey
	Sign(Message) error
	Verify(Message, ed25519.PublicKey) bool
	Encrypt(Message, ecdh.PublicKey) Message
	Decrypt(Message) (Message, error)
	Export(io.Writer) error
	Import(Config) error
	Randomness() io.Reader
}

type Self

type Self struct {
	EncryptionPrivateKey string `toml:"ePriv"`
	EncryptionPublicKey  string `toml:"ePub"`
	SigningPrivateKey    string `toml:"sPriv"`
	SigningPublicKey     string `toml:"sPub"`
	Nickname             string `toml:"Nickname"`
}

Directories

Path Synopsis
cmd
goracle command

Jump to

Keyboard shortcuts

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