cipher

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: 7 Imported by: 0

Documentation

Overview

Package cipher provides the methods and structs to do encryptions for olm/megolm.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AESSha512BlockSize

func AESSha512BlockSize() int

AESSha512BlockSize resturns the blocksize of the cipher AESSHA256.

func Pickle

func Pickle(key, input []byte) ([]byte, error)

Pickle encrypts the input with the key and the cipher AESSHA256. The result is then encoded in base64.

func PickleBlockSize

func PickleBlockSize() int

PickleBlockSize returns the blocksize of the used cipher.

func Unpickle

func Unpickle(key, input []byte) ([]byte, error)

Unpickle decodes the input from base64 and decrypts the decoded input with the key and the cipher AESSHA256.

Types

type AESSHA256

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

AESSHA256 is a valid cipher using AES with CBC and HKDFSha256.

func NewAESSHA256

func NewAESSHA256(kdfInfo []byte) *AESSHA256

NewAESSHA256 returns a new AESSHA256 cipher with the key derive function info (kdfInfo).

func (AESSHA256) Decrypt

func (c AESSHA256) Decrypt(key, ciphertext []byte) (plaintext []byte, err error)

Decrypt decrypts the ciphertext with the key. The key is used to derive the actual encryption key (32 bytes) as well as the iv (16 bytes).

func (AESSHA256) Encrypt

func (c AESSHA256) Encrypt(key, plaintext []byte) (ciphertext []byte, err error)

Encrypt encrypts the plaintext with the key. The key is used to derive the actual encryption key (32 bytes) as well as the iv (16 bytes).

func (AESSHA256) MAC

func (c AESSHA256) MAC(key, message []byte) ([]byte, error)

MAC returns the MAC for the message using the key. The key is used to derive the actual mac key (32 bytes).

func (AESSHA256) Verify

func (c AESSHA256) Verify(key, message, givenMAC []byte) (bool, error)

Verify checks the MAC of the message using the key against the givenMAC. The key is used to derive the actual mac key (32 bytes).

type Cipher

type Cipher interface {
	// Encrypt encrypts the plaintext.
	Encrypt(key, plaintext []byte) (ciphertext []byte, err error)

	// Decrypt decrypts the ciphertext.
	Decrypt(key, ciphertext []byte) (plaintext []byte, err error)

	//MAC returns the MAC of the message calculated with the key.
	MAC(key, message []byte) ([]byte, error)

	//Verify checks the MAC of the message calculated with the key against the givenMAC.
	Verify(key, message, givenMAC []byte) (bool, error)
}

Cipher defines a valid cipher.

Jump to

Keyboard shortcuts

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