crypto

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package crpyto provides the nessesary encryption methods for olm/megolm

Index

Constants

View Source
const (
	Curve25519KeyLength = curve25519.ScalarSize //The length of the private key.

)
View Source
const (
	ED25519SignatureSize = ed25519.SignatureSize //The length of a signature
)

Variables

This section is empty.

Functions

func HKDFSHA256

func HKDFSHA256(input, salt, info []byte) io.Reader

HKDFSHA256 is the key deivation function based on HMAC and returns a reader based on input. salt and info can both be nil. The reader can be used to read an arbitary length of bytes which are based on all parameters.

func HMACSHA256

func HMACSHA256(key, input []byte) []byte

HMACSHA256 returns the hash message authentication code with SHA-256 of the input with the key.

func SHA256

func SHA256(value []byte) []byte

SHA256 return the SHA-256 of the value.

Types

type Curve25519KeyPair

type Curve25519KeyPair struct {
	PrivateKey Curve25519PrivateKey `json:"private,omitempty"`
	PublicKey  Curve25519PublicKey  `json:"public,omitempty"`
}

Curve25519KeyPair stores both parts of a curve25519 key.

func Curve25519GenerateFromPrivate

func Curve25519GenerateFromPrivate(private Curve25519PrivateKey) (Curve25519KeyPair, error)

Curve25519GenerateFromPrivate creates a new curve25519 key pair with the private key given.

func Curve25519GenerateKey

func Curve25519GenerateKey(reader io.Reader) (Curve25519KeyPair, error)

Curve25519GenerateKey creates a new curve25519 key pair. If reader is nil, the random data is taken from crypto/rand.

func (Curve25519KeyPair) B64Encoded

func (c Curve25519KeyPair) B64Encoded() id.Curve25519

B64Encoded returns a base64 encoded string of the public key.

func (Curve25519KeyPair) PickleLen

func (c Curve25519KeyPair) PickleLen() int

PickleLen returns the number of bytes the pickled key pair will have.

func (Curve25519KeyPair) PickleLibOlm

func (c Curve25519KeyPair) PickleLibOlm(target []byte) (int, error)

PickleLibOlm encodes the key pair into target. target has to have a size of at least PickleLen() and is written to from index 0. It returns the number of bytes written.

func (Curve25519KeyPair) SharedSecret

func (c Curve25519KeyPair) SharedSecret(pubKey Curve25519PublicKey) ([]byte, error)

SharedSecret returns the shared secret between the key pair and the given public key.

func (*Curve25519KeyPair) UnpickleLibOlm

func (c *Curve25519KeyPair) UnpickleLibOlm(value []byte) (int, error)

UnpickleLibOlm decodes the unencryted value and populates the key pair accordingly. It returns the number of bytes read.

type Curve25519PrivateKey

type Curve25519PrivateKey []byte

Curve25519PrivateKey represents the private key for curve25519 usage

func (Curve25519PrivateKey) Equal

Equal compares the private key to the given private key.

func (Curve25519PrivateKey) PubKey

PubKey returns the public key derived from the private key.

func (Curve25519PrivateKey) SharedSecret

func (c Curve25519PrivateKey) SharedSecret(pubKey Curve25519PublicKey) ([]byte, error)

SharedSecret returns the shared secret between the private key and the given public key.

type Curve25519PublicKey

type Curve25519PublicKey []byte

Curve25519PublicKey represents the public key for curve25519 usage

func (Curve25519PublicKey) B64Encoded

func (c Curve25519PublicKey) B64Encoded() id.Curve25519

B64Encoded returns a base64 encoded string of the public key.

func (Curve25519PublicKey) Equal

Equal compares the public key to the given public key.

func (Curve25519PublicKey) PickleLen

func (c Curve25519PublicKey) PickleLen() int

PickleLen returns the number of bytes the pickled public key will have.

func (Curve25519PublicKey) PickleLibOlm

func (c Curve25519PublicKey) PickleLibOlm(target []byte) (int, error)

PickleLibOlm encodes the public key into target. target has to have a size of at least PickleLen() and is written to from index 0. It returns the number of bytes written.

func (*Curve25519PublicKey) UnpickleLibOlm

func (c *Curve25519PublicKey) UnpickleLibOlm(value []byte) (int, error)

UnpickleLibOlm decodes the unencryted value and populates the public key accordingly. It returns the number of bytes read.

type Ed25519KeyPair

type Ed25519KeyPair struct {
	PrivateKey Ed25519PrivateKey `json:"private,omitempty"`
	PublicKey  Ed25519PublicKey  `json:"public,omitempty"`
}

Ed25519KeyPair stores both parts of a ed25519 key.

func Ed25519GenerateFromPrivate

func Ed25519GenerateFromPrivate(privKey Ed25519PrivateKey) Ed25519KeyPair

Ed25519GenerateFromPrivate creates a new ed25519 key pair with the private key given.

func Ed25519GenerateFromSeed

func Ed25519GenerateFromSeed(seed []byte) Ed25519KeyPair

Ed25519GenerateFromSeed creates a new ed25519 key pair with a given seed.

func Ed25519GenerateKey

func Ed25519GenerateKey(reader io.Reader) (Ed25519KeyPair, error)

Ed25519GenerateKey creates a new ed25519 key pair. If reader is nil, the random data is taken from crypto/rand.

func (Ed25519KeyPair) B64Encoded

func (c Ed25519KeyPair) B64Encoded() id.Ed25519

B64Encoded returns a base64 encoded string of the public key.

func (Ed25519KeyPair) PickleLen

func (c Ed25519KeyPair) PickleLen() int

PickleLen returns the number of bytes the pickled key pair will have.

func (Ed25519KeyPair) PickleLibOlm

func (c Ed25519KeyPair) PickleLibOlm(target []byte) (int, error)

PickleLibOlm encodes the key pair into target. target has to have a size of at least PickleLen() and is written to from index 0. It returns the number of bytes written.

func (Ed25519KeyPair) Sign

func (c Ed25519KeyPair) Sign(message []byte) []byte

Sign returns the signature for the message.

func (*Ed25519KeyPair) UnpickleLibOlm

func (c *Ed25519KeyPair) UnpickleLibOlm(value []byte) (int, error)

UnpickleLibOlm decodes the unencryted value and populates the key pair accordingly. It returns the number of bytes read.

func (Ed25519KeyPair) Verify

func (c Ed25519KeyPair) Verify(message, givenSignature []byte) bool

Verify checks the signature of the message against the givenSignature

type Ed25519PrivateKey

type Ed25519PrivateKey ed25519.PrivateKey

Curve25519PrivateKey represents the private key for ed25519 usage. This is just a wrapper.

func (Ed25519PrivateKey) Equal

Equal compares the private key to the given private key.

func (Ed25519PrivateKey) PubKey

PubKey returns the public key derived from the private key.

func (Ed25519PrivateKey) Sign

func (c Ed25519PrivateKey) Sign(message []byte) []byte

Sign returns the signature for the message.

type Ed25519PublicKey

type Ed25519PublicKey ed25519.PublicKey

Ed25519PublicKey represents the public key for ed25519 usage. This is just a wrapper.

func (Ed25519PublicKey) B64Encoded

func (c Ed25519PublicKey) B64Encoded() id.Curve25519

B64Encoded returns a base64 encoded string of the public key.

func (Ed25519PublicKey) Equal

Equal compares the public key to the given public key.

func (Ed25519PublicKey) PickleLen

func (c Ed25519PublicKey) PickleLen() int

PickleLen returns the number of bytes the pickled public key will have.

func (Ed25519PublicKey) PickleLibOlm

func (c Ed25519PublicKey) PickleLibOlm(target []byte) (int, error)

PickleLibOlm encodes the public key into target. target has to have a size of at least PickleLen() and is written to from index 0. It returns the number of bytes written.

func (*Ed25519PublicKey) UnpickleLibOlm

func (c *Ed25519PublicKey) UnpickleLibOlm(value []byte) (int, error)

UnpickleLibOlm decodes the unencryted value and populates the public key accordingly. It returns the number of bytes read.

func (Ed25519PublicKey) Verify

func (c Ed25519PublicKey) Verify(message, givenSignature []byte) bool

Verify checks the signature of the message against the givenSignature

type OneTimeKey

type OneTimeKey struct {
	ID        uint32            `json:"id"`
	Published bool              `json:"published"`
	Key       Curve25519KeyPair `json:"key,omitempty"`
}

OneTimeKey stores the information about a one time key.

func (OneTimeKey) Equal

func (otk OneTimeKey) Equal(s OneTimeKey) bool

Equal compares the one time key to the given one.

func (OneTimeKey) KeyIDEncoded

func (c OneTimeKey) KeyIDEncoded() string

KeyIDEncoded returns the base64 encoded id.

func (OneTimeKey) PickleLen

func (c OneTimeKey) PickleLen() int

PickleLen returns the number of bytes the pickled OneTimeKey will have.

func (OneTimeKey) PickleLibOlm

func (c OneTimeKey) PickleLibOlm(target []byte) (int, error)

PickleLibOlm encodes the key pair into target. target has to have a size of at least PickleLen() and is written to from index 0. It returns the number of bytes written.

func (OneTimeKey) PublicKeyEncoded

func (c OneTimeKey) PublicKeyEncoded() id.Curve25519

PublicKeyEncoded returns the base64 encoded public key

func (*OneTimeKey) UnpickleLibOlm

func (c *OneTimeKey) UnpickleLibOlm(value []byte) (int, error)

UnpickleLibOlm decodes the unencryted value and populates the OneTimeKey accordingly. It returns the number of bytes read.

Jump to

Keyboard shortcuts

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