Documentation ¶
Overview ¶
Package crypto defines the cryptographic functions used in E4
Index ¶
- Constants
- Variables
- func Decrypt(key, ad, ct []byte) ([]byte, error)
- func DeriveSymKey(pwd string) ([]byte, error)
- func Encrypt(key, ad, pt []byte) ([]byte, error)
- func HashIDAlias(idalias string) []byte
- func HashTopic(topic string) []byte
- func ProtectSymKey(payload, key []byte) ([]byte, error)
- func RandomDelta16() uint16
- func RandomID() []byte
- func RandomKey() []byte
- func Sha3Sum256(data []byte) []byte
- func Sign(signerID []byte, privateKey Ed25519PrivateKey, timestamp []byte, ...) ([]byte, error)
- func UnprotectSymKey(protected, key []byte) ([]byte, error)
- func ValidateCurve25519PrivKey(key []byte) error
- func ValidateCurve25519PubKey(key []byte) error
- func ValidateEd25519PrivKey(key []byte) error
- func ValidateEd25519PubKey(key []byte) error
- func ValidateID(id []byte) error
- func ValidateName(name string) error
- func ValidatePassword(password string) error
- func ValidateSymKey(key []byte) error
- func ValidateTimestamp(timestamp []byte) error
- func ValidateTimestampKey(timestamp []byte) error
- func ValidateTopic(topic string) error
- func ValidateTopicHash(topicHash []byte) error
- type Curve25519PrivateKey
- type Curve25519PublicKey
- type Ed25519PrivateKey
- type Ed25519PublicKey
Constants ¶
const ( // IDLen is the length of an E4 ID IDLen = 16 // KeyLen is the length of a symmetric key KeyLen = 32 // TagLen is the length of the authentication tag appended to the cipher TagLen = 16 // HashLen is the length of a hashed topic HashLen = 16 // TimestampLen is the length of the timestamp TimestampLen = 8 // MaxTopicLen is the maximum length of a topic MaxTopicLen = 512 // MaxDelayDuration is the validity time of a protected message MaxDelayDuration = 10 * time.Minute // MaxDelayKeyTransition is the validity time of an old topic key once updated MaxDelayKeyTransition = 60 * time.Minute // IDLenHex is the length of a hexadecimal encoded ID IDLenHex = IDLen * 2 // KeyLenHex is the length of a hexadecimal encoded key KeyLenHex = KeyLen * 2 // Curve25519PubKeyLen is the length of a curve25519 public key Curve25519PubKeyLen = 32 // Curve25519PrivKeyLen is the length of a curve25519 private key Curve25519PrivKeyLen = 32 )
List of global e4 constants
const ( // PasswordMinLength defines the minimum size accepted for a password PasswordMinLength = 16 // NameMinLen is the minimum length of a name NameMinLen = 1 // NameMaxLen is the maximum length of a name NameMaxLen = 255 )
Variables ¶
var ( // ErrInvalidProtectedLen occurs when the protected message is not of the expected length ErrInvalidProtectedLen = errors.New("invalid length of protected message") // ErrTooShortCiphertext occurs when trying to unprotect a ciphertext shorter than TimestampLen ErrTooShortCiphertext = errors.New("ciphertext too short") // ErrTimestampInFuture occurs when the cipher timestamp is in the future ErrTimestampInFuture = errors.New("timestamp received is in the future") // ErrTimestampTooOld occurs when the cipher timestamp is older than MaxDelayDuration from now ErrTimestampTooOld = errors.New("timestamp too old") // ErrInvalidSignature occurs when a signature verification fails ErrInvalidSignature = errors.New("invalid signature") // ErrInvalidSignerID occurs when trying to sign with an invalid ID ErrInvalidSignerID = errors.New("invalid signer ID") // ErrInvalidTimestamp occurs when trying to sign with an invalid timestamp ErrInvalidTimestamp = errors.New("invalid timestamp") )
Functions ¶
func DeriveSymKey ¶
DeriveSymKey derives a symmetric key from a password using Argon2 (Replaces HashPwd)
func HashIDAlias ¶
HashIDAlias creates an ID from an ID alias string
func ProtectSymKey ¶
ProtectSymKey attempt to encrypt payload using given symmetric key
func RandomDelta16 ¶
func RandomDelta16() uint16
RandomDelta16 produces a random 16-bit integer to allow us to vary key sizes, plaintext sizes etc
func RandomKey ¶
func RandomKey() []byte
RandomKey generates a random KeyLen-byte key usable by Encrypt and Decrypt
func Sign ¶
func Sign(signerID []byte, privateKey Ed25519PrivateKey, timestamp []byte, payload []byte) ([]byte, error)
Sign will sign the given payload using the given privateKey, producing an output composed of: timestamp + signedID + payload + signature
func UnprotectSymKey ¶
UnprotectSymKey attempt to decrypt protected bytes, using given symmetric key
func ValidateCurve25519PrivKey ¶
ValidateCurve25519PrivKey checks that a key is of the expected length and not all zero
func ValidateCurve25519PubKey ¶
ValidateCurve25519PubKey checks that a key is of the expected length and not all zero
func ValidateEd25519PrivKey ¶
ValidateEd25519PrivKey checks that a key is of the expected length and not all zero
func ValidateEd25519PubKey ¶
ValidateEd25519PubKey checks that a key is of the expected length and not all zero
func ValidateID ¶
ValidateID checks that an id is of the expected length
func ValidateName ¶
ValidateName is used to validate names match given constraints since we hash these in the protocol, those constraints are quite liberal, but for correctness we check any string is valid UTF-8
func ValidatePassword ¶
ValidatePassword checks given password is an utf8 string of at least PasswordMinLength characters
func ValidateSymKey ¶
ValidateSymKey checks that a key is of the expected length and not filled with zero
func ValidateTimestamp ¶
ValidateTimestamp checks that given timestamp bytes are a valid LittleEndian encoded timestamp, not in the future and not older than MaxDelayDuration
func ValidateTimestampKey ¶
ValidateTimestampKey checks that given timestamp bytes are a valid LittleEndian encoded timestamp, not in the future and not older than MaxDelayKeyTransition
func ValidateTopic ¶
ValidateTopic checks if a topic is not too large or empty
func ValidateTopicHash ¶
ValidateTopicHash checks that a topic hash is of the expected length
Types ¶
type Curve25519PrivateKey ¶
type Curve25519PrivateKey = []byte
Curve25519PrivateKey defines an alias for curve 25519 private keys
func PrivateEd25519KeyToCurve25519 ¶
func PrivateEd25519KeyToCurve25519(edPrivKey Ed25519PrivateKey) Curve25519PrivateKey
PrivateEd25519KeyToCurve25519 convert an Ed25519PrivateKey to a Curve25519PrivateKey.
type Curve25519PublicKey ¶
type Curve25519PublicKey = []byte
Curve25519PublicKey defines an alias for curve 25519 public keys
func PublicEd25519KeyToCurve25519 ¶
func PublicEd25519KeyToCurve25519(edPubKey Ed25519PublicKey) Curve25519PublicKey
PublicEd25519KeyToCurve25519 convert an Ed25519PublicKey to a Curve25519PublicKey.
type Ed25519PrivateKey ¶ added in v1.0.1
type Ed25519PrivateKey = []byte
Ed25519PrivateKey defines an alias for Ed25519 private keys
func Ed25519PrivateKeyFromPassword ¶
func Ed25519PrivateKeyFromPassword(password string) (Ed25519PrivateKey, error)
Ed25519PrivateKeyFromPassword creates a ed25519.PrivateKey from a password
type Ed25519PublicKey ¶ added in v1.0.1
type Ed25519PublicKey = []byte
Ed25519PublicKey defines an alias for Ed25519 public keys