keys

package
v0.0.0-...-e52790e Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2025 License: Unlicense Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PKSize = 29
	SKSize = 32
)
View Source
const (
	PubStart = "copub:"
	SecStart = "cosec:" // lel

)
View Source
const AddressLen = 16

Variables

View Source
var (
	ZeroSK = new([32]byte)
	ZeroPK = func() (publicKey *[32]byte) {
		publicKey = new([32]byte)

		curve25519.ScalarBaseMult(publicKey, ZeroSK)
		return
	}()
)

ephemeral 32 keypair that everyone knows

View Source
var ZeroNonce = new([24]byte)

Who needs nonces anyway? Every request is idempotent becaue every computation is deterministic. Exactly-once delivery 4 tha win

Functions

func KeyWorker

func KeyWorker(found chan<- Keypair, stop <-chan struct{})

Types

type Address

type Address [AddressLen]byte // can be whatever (probably an ipv6 lel)

type KeyType

type KeyType uint8
const (
	Public KeyType = iota
	Secret
)

type Keypair

type Keypair struct {
	Pk PK
	Sk SK
}

func GenerateKeys

func GenerateKeys(threads uint8, stop <-chan struct{}) Keypair

func KeypairSK

func KeypairSK(sk [32]byte) (kp Keypair, err error)

func (Keypair) Decrypt

func (kp Keypair) Decrypt(emsg []byte) (from Peer, msg []byte, err error)

todo: version cyphertexts

type PK

type PK [PKSize]byte

func DecodePK

func DecodePK(key string) (bs PK, err error)

Takes a string representation of a public key and returns the byte representation of it

func (PK) Encode

func (s PK) Encode() string

Takes a public key and returns a string representation of it using a custom alphabet

func (PK) Verify

func (pk PK) Verify(sig []byte) (msg []byte, ok bool)

type Peer

type Peer struct {
	Pk        PK
	Addresses []Address
	LastSeen  time.Time
}

func (Peer) Equals

func (p Peer) Equals(p2 Peer) bool

type SK

type SK [SKSize]byte

func DecodeSK

func DecodeSK(key string) (bs SK, err error)

Takes a string representation of a secret key and returns the byte representation of it

func (SK) Encode

func (s SK) Encode() string

Takes a secret key and returns a string representation of it using a custom alphabet

func (SK) Sign

func (sk SK) Sign(msg []byte) []byte

type ThisPeer

type ThisPeer struct {
	Peer
	Kp Keypair
}

func (ThisPeer) Encrypt

func (p ThisPeer) Encrypt(msg []byte, to PK) (out []byte, err error)

chunks are chunked because not having to hold the whole thing in memory at the same time (?) we cold do larger chunks but messages larger than 64k will probably be rare (apart from file transfers? large responses? I'll get to tis when I do gateway implementation soon)

Jump to

Keyboard shortcuts

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