signalplus

package module
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2021 License: MIT Imports: 12 Imported by: 0

README

signalplus

Implements the Signal protocol with extensions enabling the double ratchet to occur after N messages or a time window. Uses the NACL crypto library.

Documentation

Index

Constants

View Source
const (
	KeySize   = 32
	NonceSize = 24
)

KeySize and NonceSize : constants used for all encryption functions

View Source
const (
	VLowSec int = 0 + iota
	LowSec
	MedSec
	HighSec
	VHighSec
)

VLowSec : security level enumerations for scrypt N

View Source
const MaxSkip = 100

MaxSkip :

Variables

This section is empty.

Functions

func AddKeyRing

func AddKeyRing(state *Signalstate, key *[KeySize]byte, ratchetnum uint64)

AddKeyRing :

func DHRatchet

func DHRatchet(state *Signalstate, head Mesghead) error

DHRatchet :

func Decrypt

func Decrypt(encrypted []byte, key *[KeySize]byte) ([]byte, error)

Decrypt : extracts the nonce from the ciphertext and decrypts with symmetric key cryptography

func Encrypt

func Encrypt(message []byte, key *[KeySize]byte) ([]byte, error)

Encrypt : encrypted message is the size original message plus overhead bytes and encrypted with symmetric key cryptography

func Hash64

func Hash64(value []byte) uint64

Hash64 : convert byte slice to 64bit hash

func KdfCk

func KdfCk(chainkey *[KeySize]byte, rparam *Ratchetparam) (*[KeySize]byte, *[KeySize]byte, error)

KdfCk : New chain key derivation function - returns new chain key and new message key

func KdfRk

func KdfRk(rootkey *[KeySize]byte, dhout *[KeySize]byte, rparam *Ratchetparam) (*[KeySize]byte, *[KeySize]byte, error)

KdfRk : New root key derivation function - returns new root key and new chain key

func Key

func Key() (*[KeySize]byte, error)

Key : create a random secret key.

func KeyPair

func KeyPair() (*[KeySize]byte, *[KeySize]byte, error)

KeyPair : generate a public key cryptography asymmetric key pair (pub, pri, err)

func KeyToHex

func KeyToHex(k *[KeySize]byte) string

KeyToHex :

func Level

func Level(level string) (int, error)

Level : return the level for a string level

func NewDh

func NewDh(pair Keypair, pubkey *[KeySize]byte) *[KeySize]byte

NewDh : New elliptic curve Diffie-Hellman

func Nonce

func Nonce() (*[NonceSize]byte, error)

Nonce : create a random nonce.

func Open

func Open(encrypted []byte, senderPublicKey *[KeySize]byte, recipientPrivateKey *[KeySize]byte) ([]byte, bool)

Open : decrypt a message with public key cryptography

func PasswordKey

func PasswordKey(password []byte, salt []byte) (*[KeySize]byte, error)

PasswordKey : generate a symmetric key from a passphrase and salt.

func Ratchet

func Ratchet(state *Signalstate) bool

Ratchet : test and return if ratchet is needed

func RatchetDecrypt

func RatchetDecrypt(state *Signalstate, head Mesghead, ciphertext []byte) ([]byte, error)

RatchetDecrypt :

func RatchetInitReceiver

func RatchetInitReceiver(state *Signalstate, symkey *[KeySize]byte, recvkp Keypair)

RatchetInitReceiver :

func RatchetInitSender

func RatchetInitSender(state *Signalstate, symkey *[KeySize]byte, rpubkey *[KeySize]byte) error

RatchetInitSender :

func ScryptN

func ScryptN(state *Signalstate) int

ScryptN : return the scrypt KDF algorithm 'N' value

func Seal

func Seal(message []byte, recipientPublicKey *[KeySize]byte, senderPrivateKey *[KeySize]byte) ([]byte, error)

Seal : encrypt a message with public key cryptography

func SetRatchet

func SetRatchet(state *Signalstate, count int, period int, level int) error

SetRatchet : set ratchet parameters, message count between ratchets, period in hours between ratchets, security level

func SetScryptN

func SetScryptN(state *Signalstate, scryptn int)

SetScryptN : set the scrypt KDF algorithm 'N' value

func SkipMessageKeys

func SkipMessageKeys(state *Signalstate, until uint64) error

SkipMessageKeys :

func TryKeyRing

func TryKeyRing(ciphertext []byte, state *Signalstate, ratchetnum uint64) ([]byte, error)

TryKeyRing :

func TrySkippedMessageKeys

func TrySkippedMessageKeys(state *Signalstate, head Mesghead, ciphertext []byte) ([]byte, error)

TrySkippedMessageKeys :

func Zero

func Zero(data []byte)

Zero : zero out a byte array with sensitive data

Types

type Keypair

type Keypair struct {
	Prikey *[KeySize]byte
	Pubkey *[KeySize]byte
}

Keypair :

func GenerateDh

func GenerateDh() (Keypair, error)

GenerateDh :

type Mesghead

type Mesghead struct {
	Pubkey  *[KeySize]byte
	Nummesg uint64
	Sendnum uint64
}

Mesghead :

func GetHeader

func GetHeader(state *Signalstate) Mesghead

GetHeader :

func Header(pair Keypair, nummesg uint64, sendnum uint64) Mesghead

Header :

func RatchetEncrypt

func RatchetEncrypt(state *Signalstate, plaintext []byte) (Mesghead, []byte, error)

RatchetEncrypt :

type Ratchetparam

type Ratchetparam struct {
	ScryptN int
	Count   int
	Period  int
	Last    int
	Ltime   time.Time
}

Ratchetparam :

type Signalstate

type Signalstate struct {
	Mesgkey *[KeySize]byte //Current message key
	// contains filtered or unexported fields
}

Signalstate :

Jump to

Keyboard shortcuts

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