ampoule

package module
v0.0.0-...-93d267d Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2025 License: MIT Imports: 11 Imported by: 0

README

Ampoule

alternative to cheese with auth-HPKE

Because it's supposedly easy.

todo:

  • double check that it's one of the allowed HPKE auth schemes
  • maybe swap it to a 256 mode
  • marshall the context safely somehow
  • unmarshall the context safely somehow
  • KCI attacks?
    • sign-encrypt-sign? separate EC key than the KEM public key?
    • prepend sender.pub|recipient.pub to message, then encrypt?

file formats

some documentation on the formats:

private key

  • argon2id encoded with salt & passphrase
  • cipher is AESGCM with a nonce.
  • file is {prefix}base64(salt[8]|nonce[12]|ciphertext[x])
  • prefix: "AMPOULE-PRIVATE-KEY-
  • context: kem private key

public key

  • prefix: "ampoule-public-key-"
  • base64 encoded kem public key

messages

3 lines:

  • base64(encapsulated key)
  • base64(ciphertext)
  • base64(additional authenticated data)

Usage

Here's a basic cli.

go install codeberg.org/risottobias/ampoule/ampoule-cli@latest

if you cloned the repo:

make

(note, the binary in that case is named "ampoule")

Generating

ampoule-cli -cmd gen -from alice # your name

on their machine, they'll make:

ampoule-cli -cmd gen -from bob 

share each other's .pub's

Sending

ampoule-cli -cmd send -from alice -to bob -src secret.txt -dst item.msg

send bob your item.msg

Receiving

ampoule-cli -cmd recv -from alice -to bob -src item.msg -dst res.txt

Documentation

Overview

Package ampoule is a demo auth-HPKE file format.

It's similar to pgp I suppose.

The alternative is Cheese - https://codeberg.org/risottobias/cheese

Index

Constants

View Source
const (
	// Not sure about this KEM
	KemID = hpke.KEM_P384_HKDF_SHA384
	// *shrug* I dunno
	KdfID  = hpke.KDF_HKDF_SHA384
	AeadID = hpke.AEAD_AES256GCM
)

Fixing the auth type and scheme (could change to a P256...)

Variables

View Source
var AmpouleSuite hpke.Suite

Not positive about this suite. it's from the demo code.

View Source
var PublicInfo []byte

PublicInfo could encode the version string. who knows. For now, a self-referential string.

Functions

func Gen

func Gen() (kem.PublicKey, kem.PrivateKey, error)

Gen returns a new Auth-HPKE keypair

func KeyToLine

func KeyToLine(k []byte, t keytype) ([]byte, error)

KeyToLine takes key bytes and returns an ampoule key string

func LineToKey

func LineToKey(k []byte, t keytype) ([]byte, error)

LineToKey takes an ampule key string and returns the original bytes

func LoadPrivate

func LoadPrivate(lbytes []byte, passphrase string) (kem.PrivateKey, error)

LoadPrivate reads a kem.PrivateKey from a string

func LoadPrivateFile

func LoadPrivateFile(ident, passphrase string) (kem.PrivateKey, error)

LoadPrivateFile reads a kem.PrivateKey from {ident}.key (wraps LoadPrivate)

func LoadPublic

func LoadPublic(fbytes []byte) (kem.PublicKey, error)

LoadPublic reads a kem.PublicKey from a string

func LoadPublicFile

func LoadPublicFile(ident string) (kem.PublicKey, error)

LoadPublicFile reads a kem.PublicKey from {ident}.pub (wraps LoadPublic)

func Recv

func Recv(message []byte, from kem.PublicKey, to kem.PrivateKey) ([]byte, error)

Recv checks an auth-HPKE message (3 lines base64) and returns the plaintext

func SavePrivate

func SavePrivate(priv kem.PrivateKey, passphrase string) ([]byte, error)

SavePrivate encrypts a kem to a safe line and returns that string

func SavePrivateFile

func SavePrivateFile(priv kem.PrivateKey, ident, passphrase string) error

SavePrivateFile writes a kem.PrivateKey to {ident}.key (wraps SavePrivate)

func SavePublic

func SavePublic(pub kem.PublicKey) ([]byte, error)

SavePublic writes a kem.PublicKey to string

func SavePublicFile

func SavePublicFile(pub kem.PublicKey, ident string) error

SavePublic writes a kem.PublicKey to {ident}.pub (wraps SavePublic)

func Send

func Send(message []byte, from kem.PrivateKey, to kem.PublicKey) ([]byte, error)

Send generates a 3 line base64 auth-hpke message

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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