cryptoutil

package
v2.454.2 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2023 License: Apache-2.0, MIT Imports: 34 Imported by: 0

Documentation

Overview

Package cryptoutil contains generic & stateless crypto helpers.

Index

Constants

View Source
const (
	KeySize          = 32 // Key size required by box
	NonceSize        = 24 // Nonce size required by box
	ScryptIterations = 1 << 15
	ScryptR          = 8
	ScryptP          = 1
	ScryptKeyLen     = 32
)
View Source
const NamespaceGroupDatastore = "account_groups_datastore"
View Source
const PushSecretNamespace = "push_secret_ref" // nolint:gosec

Variables

This section is empty.

Functions

func AESCTRStream added in v2.231.0

func AESCTRStream(key, iv []byte) (cipher.Stream, error)

AESCTRStream returns a CTR stream that can be used to produce ciphertext without padding.

func AESGCMDecrypt added in v2.231.0

func AESGCMDecrypt(key, data []byte) ([]byte, error)

AESGCMDecrypt uses AES+GCM to decrypt plaintext data.

func AESGCMEncrypt added in v2.231.0

func AESGCMEncrypt(key, data []byte) ([]byte, error)

AESGCMEncrypt use AES+GCM to encrypt plaintext data.

The generated output will be longer than the original plaintext input.

func ComputeLinkKey added in v2.318.0

func ComputeLinkKey(publicKey, secret []byte) (*[KeySize]byte, error)

func ConcatAndHashSha256 added in v2.33.0

func ConcatAndHashSha256(slices ...[]byte) *[sha256.Size]byte

func CreatePushGroupReference added in v2.321.0

func CreatePushGroupReference(sender []byte, counter uint64, secret []byte) ([]byte, error)

func DeriveKey added in v2.231.0

func DeriveKey(passphrase, salt []byte) ([]byte, []byte, error)

DeriveKey takes a passphrase of any length and returns a key of fixed size.

If no salt is provided, a new one will be created and returned.

func EdwardsToMontgomery

func EdwardsToMontgomery(privKey crypto.PrivKey, pubKey crypto.PubKey) (*[32]byte, *[32]byte, error)

EdwardsToMontgomery converts ed25519 priv/pub keys to X25519 keys.

func EdwardsToMontgomeryPriv added in v2.33.0

func EdwardsToMontgomeryPriv(privKey crypto.PrivKey) (*[KeySize]byte, error)

EdwardsToMontgomeryPriv converts ed25519 priv key to X25519 priv key.

func EdwardsToMontgomeryPub added in v2.33.0

func EdwardsToMontgomeryPub(pubKey crypto.PubKey) (*[KeySize]byte, error)

EdwardsToMontgomeryPub converts ed25519 pub key to X25519 pub key.

func GenerateNonce added in v2.33.0

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

func GenerateNonceSize added in v2.231.0

func GenerateNonceSize(size int) ([]byte, error)

func GetGroupForAccount added in v2.308.0

func GetGroupForAccount(priv, signing crypto.PrivKey) (*protocoltypes.Group, error)

func GetGroupForContact added in v2.308.0

func GetGroupForContact(contactPairSK crypto.PrivKey) (*protocoltypes.Group, error)

func GetGroupPushSecret added in v2.321.0

func GetGroupPushSecret(m GroupWithSecret) ([]byte, error)

func GetKeysForGroupOfContact added in v2.308.0

func GetKeysForGroupOfContact(contactPairSK crypto.PrivKey) (crypto.PrivKey, crypto.PrivKey, error)

func GetLinkKeyArray added in v2.318.0

func GetLinkKeyArray(m GroupWithLinkKey) (*[KeySize]byte, error)

func GetSharedSecret added in v2.318.0

func GetSharedSecret(m GroupWithLinkKey) *[KeySize]byte

func KeySliceToArray added in v2.33.0

func KeySliceToArray(keySlice []byte) (*[KeySize]byte, error)

func NewDeviceSecret added in v2.308.0

func NewDeviceSecret() (*protocoltypes.DeviceSecret, error)

func NonceSliceToArray added in v2.33.0

func NonceSliceToArray(nonceSlice []byte) (*[NonceSize]byte, error)

func OpenEnvelopeHeaders added in v2.308.0

func SealEnvelope added in v2.308.0

func SealEnvelope(payload []byte, ds *protocoltypes.DeviceSecret, deviceSK crypto.PrivKey, g *protocoltypes.Group) ([]byte, error)

func SealPayload added in v2.308.0

func SealPayload(payload []byte, ds *protocoltypes.DeviceSecret, deviceSK crypto.PrivKey, g *protocoltypes.Group) ([]byte, []byte, error)

func SeedFromEd25519PrivateKey

func SeedFromEd25519PrivateKey(key crypto.PrivKey) ([]byte, error)

Types

type DecryptInfo added in v2.308.0

type DecryptInfo struct {
	NewlyDecrypted bool
	MK             *[32]byte
	Cid            cid.Cid
}

type DeviceKeystore added in v2.308.0

type DeviceKeystore interface {
	AccountPrivKey() (crypto.PrivKey, error)
	AccountProofPrivKey() (crypto.PrivKey, error)
	DevicePrivKey() (crypto.PrivKey, error)
	ContactGroupPrivKey(pk crypto.PubKey) (crypto.PrivKey, error)
	MemberDeviceForGroup(g *protocoltypes.Group) (*OwnMemberDevice, error)
	RestoreAccountKeys(accountKey crypto.PrivKey, accountProofKey crypto.PrivKey) error
}

func NewDeviceKeystore added in v2.308.0

func NewDeviceKeystore(ks keystore.Keystore, opts *DeviceKeystoreOpts) DeviceKeystore

NewDeviceKeystore creates a new deviceKeystore instance, if the keystore does not hold an deviceKeystore key, one will be created when required

func NewWithExistingKeys added in v2.308.0

func NewWithExistingKeys(ks keystore.Keystore, sk crypto.PrivKey, proofSK crypto.PrivKey) (DeviceKeystore, error)

NewWithExistingKeys creates a new deviceKeystore instance and registers the supplied secret key, useful when migrating deviceKeystore to another device

type DeviceKeystoreOpts added in v2.326.0

type DeviceKeystoreOpts struct {
	Logger *zap.Logger
}

type GroupDatastore added in v2.308.0

type GroupDatastore struct {
	// contains filtered or unexported fields
}

func NewGroupDatastore added in v2.308.0

func NewGroupDatastore(ds datastore.Datastore) (*GroupDatastore, error)

func (*GroupDatastore) Delete added in v2.308.0

func (gd *GroupDatastore) Delete(ctx context.Context, pk crypto.PubKey) error

func (*GroupDatastore) Get added in v2.308.0

func (*GroupDatastore) Has added in v2.308.0

func (gd *GroupDatastore) Has(ctx context.Context, key crypto.PubKey) (bool, error)

func (*GroupDatastore) Put added in v2.308.0

func (*GroupDatastore) PutForContactPK added in v2.308.0

func (gd *GroupDatastore) PutForContactPK(ctx context.Context, pk crypto.PubKey, deviceKeystore DeviceKeystore) error

type GroupDatastoreReadOnly added in v2.308.0

type GroupDatastoreReadOnly interface {
	Has(ctx context.Context, key crypto.PubKey) (bool, error)
	Get(ctx context.Context, key crypto.PubKey) (*protocoltypes.Group, error)
}

type GroupWithLinkKey added in v2.318.0

type GroupWithLinkKey interface {
	GroupWithSecret
	GetLinkKey() []byte
}

type GroupWithSecret added in v2.321.0

type GroupWithSecret interface {
	GetPublicKey() []byte
	GetSecret() []byte
}

type MemberDevice added in v2.308.0

type MemberDevice struct {
	Member crypto.PubKey
	Device crypto.PubKey
}

MemberDevice is a remote Device part of a group

type MessageKeystore added in v2.308.0

type MessageKeystore struct {
	// contains filtered or unexported fields
}

func NewInMemMessageKeystore added in v2.308.0

func NewInMemMessageKeystore() (*MessageKeystore, func())

nolint:deadcode,unused // NewInMemMessageKeystore instantiate a new MessageKeystore, useful for testing

func NewMessageKeystore added in v2.308.0

func NewMessageKeystore(s datastore.Datastore) *MessageKeystore

NewMessageKeystore instantiate a new MessageKeystore

func (*MessageKeystore) DeriveDeviceSecret added in v2.308.0

func (m *MessageKeystore) DeriveDeviceSecret(ctx context.Context, g *protocoltypes.Group, deviceSK crypto.PrivKey) error

func (*MessageKeystore) GetByPushGroupReference added in v2.321.0

func (m *MessageKeystore) GetByPushGroupReference(ctx context.Context, ref []byte) ([]byte, error)

func (*MessageKeystore) GetDeviceChainKey added in v2.308.0

func (m *MessageKeystore) GetDeviceChainKey(ctx context.Context, groupPK, pk crypto.PubKey) (*protocoltypes.DeviceSecret, error)

func (*MessageKeystore) GetDeviceSecret added in v2.308.0

func (*MessageKeystore) GetKeyForCID added in v2.308.0

func (m *MessageKeystore) GetKeyForCID(ctx context.Context, id cid.Cid) (*[32]byte, error)

func (*MessageKeystore) GetPrecomputedKeyExpectedCount added in v2.308.0

func (m *MessageKeystore) GetPrecomputedKeyExpectedCount() int

func (*MessageKeystore) HasSecretForRawDevicePK added in v2.369.0

func (m *MessageKeystore) HasSecretForRawDevicePK(ctx context.Context, groupPK, devicePK []byte) (has bool)

func (*MessageKeystore) OpenEnvelope added in v2.308.0

func (*MessageKeystore) OpenEnvelopePayload added in v2.369.0

func (*MessageKeystore) OpenOutOfStoreMessage added in v2.308.0

func (m *MessageKeystore) OpenOutOfStoreMessage(ctx context.Context, envelope *protocoltypes.OutOfStoreMessage, groupPublicKey []byte) ([]byte, bool, error)

func (*MessageKeystore) OpenPayload added in v2.308.0

func (m *MessageKeystore) OpenPayload(ctx context.Context, id cid.Cid, groupPK crypto.PubKey, payload []byte, headers *protocoltypes.MessageHeaders) ([]byte, *DecryptInfo, error)

func (*MessageKeystore) PostDecryptActions added in v2.308.0

func (m *MessageKeystore) PostDecryptActions(ctx context.Context, di *DecryptInfo, g *protocoltypes.Group, ownPK crypto.PubKey, headers *protocoltypes.MessageHeaders) error

func (*MessageKeystore) RegisterChainKey added in v2.308.0

func (m *MessageKeystore) RegisterChainKey(ctx context.Context, g *protocoltypes.Group, devicePK crypto.PubKey, ds *protocoltypes.DeviceSecret, isOwnPK bool) error

func (*MessageKeystore) SealEnvelope added in v2.308.0

func (m *MessageKeystore) SealEnvelope(ctx context.Context, g *protocoltypes.Group, deviceSK crypto.PrivKey, payload []byte) ([]byte, error)

func (*MessageKeystore) UpdatePushGroupReferences added in v2.321.0

func (m *MessageKeystore) UpdatePushGroupReferences(ctx context.Context, devicePK []byte, first uint64, group GroupWithSecret) error

type OwnMemberDevice added in v2.308.0

type OwnMemberDevice struct {
	// contains filtered or unexported fields
}

OwnMemberDevice is own local Device part of a group

func NewOwnMemberDevice added in v2.308.0

func NewOwnMemberDevice(member crypto.PrivKey, device crypto.PrivKey) *OwnMemberDevice

func (*OwnMemberDevice) PrivateDevice added in v2.308.0

func (d *OwnMemberDevice) PrivateDevice() crypto.PrivKey

func (*OwnMemberDevice) PrivateMember added in v2.308.0

func (d *OwnMemberDevice) PrivateMember() crypto.PrivKey

func (*OwnMemberDevice) Public added in v2.308.0

func (d *OwnMemberDevice) Public() *MemberDevice

Jump to

Keyboard shortcuts

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