key_helpers

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const CounterSizeBytes = 4
View Source
const NonceSizeBytes = 12
View Source
const RandomSizeBytes = 8
View Source
const TagSizeBytes = 16

Variables

This section is empty.

Functions

func EncodePublicKey

func EncodePublicKey(key *ecdsa.PublicKey) ([]byte, error)

func EncryptPayload

func EncryptPayload(key [TagSizeBytes]byte, plaintext []byte, requestId [8]uint8, counterInitializationVector *CounterInitializationVector) (*EncryptedMessage, CryptoStatus)

func GenerateCertificate

func GenerateCertificate(key *ecdsa.PrivateKey, validitySeconds uint64) ([]byte, error)

func HKDF

func HKDF(secret []byte, salt []byte, requestId RequestId) []byte

func ParseCertificatePublicKey

func ParseCertificatePublicKey(der []byte) (*ecdsa.PublicKey, error)

func ParsePublicKey

func ParsePublicKey(der []byte) (*ecdsa.PublicKey, error)

Types

type CounterInitializationVector

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

func GenerateCounterInitializationVector

func GenerateCounterInitializationVector() *CounterInitializationVector

type CryptoStatus

type CryptoStatus uint64
const (
	CryptoStatusOk CryptoStatus = iota
	CryptoStatusError
	CryptoStatusInvalidCounter
)

func DecryptPayload

func DecryptPayload(key [16]byte, message EncryptedMessage, requestId [8]uint8, previousBlockCounter *uint32) ([]byte, CryptoStatus)

type ECDHState

type ECDHState struct {
	RemotePublicKey *ecdh.PublicKey
	PublicKey       *ecdh.PublicKey
	PrivateKey      *ecdh.PrivateKey
}

func (*ECDHState) GenerateKeyPair

func (e *ECDHState) GenerateKeyPair()

func (*ECDHState) GetSharedSecret

func (e *ECDHState) GetSharedSecret() []byte

func (*ECDHState) SetRemotePublicKey

func (e *ECDHState) SetRemotePublicKey(pubKey []byte)

type EncryptedMessage

type EncryptedMessage struct {
	/**
	Initialization Vector (IV) 12 bytes in length consisting of
	64 bits randomly generated + 32 bits counter in big endian also known as nonce.
	*/
	InitializationVector [NonceSizeBytes]byte

	/**
	Authentication tag 16 bytes in length
	also known as a message authentication code (MAC).
	*/
	AuthenticationTag [TagSizeBytes]byte

	/**
	Encrypted payload
	*/
	EncryptedPayload []byte
}

type RequestId

type RequestId [8]byte

Jump to

Keyboard shortcuts

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