cipherman

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: MIT Imports: 11 Imported by: 0

README

Cipherman

Godoc Release Build

A Golang library that provides various cipher implementations.

Usage

See chacha20poly1305_test.go, x25519xchacha20poly1305_test.go and ecdhxchacha20poly1305_test.go.

Test

# Run tests
make test

# Continuous testing
make test-ui

# Benchmarks
make test-benchmarks

Contributing

See CONTRIBUTING.md

License

Licensed under The MIT License (MIT)
For the full copyright and license information, please view the LICENSE.txt file.

Documentation

Overview

Package cipherman provides various cipher implementations.

Index

Constants

View Source
const (
	// ECDHHKDFInfoSK represents the derived key info for the shared key.
	ECDHHKDFInfoSK = "ECDH"
)
View Source
const (
	// X25519HKDFInfoSK represents the derived key info for the shared key.
	X25519HKDFInfoSK = "X25519"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block interface {
	// Encrypt encrypts plaintext by the given arguments and returns ciphertext.
	Encrypt(plaintext []byte, additionalData []byte, nonce []byte) ([]byte, error)
	// Decrypt decrypts ciphertext by the given arguments and returns plaintext.
	Decrypt(ciphertext []byte, additionalData []byte, nonce []byte) ([]byte, error)
}

Block is the interface that must be implemented by block ciphers.

type ChaCha20Poly1305

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

ChaCha20Poly1305 represents a ChaCha20Poly1305 cipher.

func NewChaCha20Poly1305

func NewChaCha20Poly1305(key []byte) (*ChaCha20Poly1305, error)

NewChaCha20Poly1305 creates a new ChaCha20Poly1305 cipher instance.

func NewXChaCha20Poly1305

func NewXChaCha20Poly1305(key []byte) (*ChaCha20Poly1305, error)

NewXChaCha20Poly1305 creates a new ChaCha20Poly1305 cipher instance which uses XChaCha20-Poly1305 variant.

func (*ChaCha20Poly1305) Decrypt

func (cc20p1305 *ChaCha20Poly1305) Decrypt(ciphertext, additionalData, nonce []byte) ([]byte, error)

Decrypt decrypts ciphertext by the given arguments and returns plaintext.

func (*ChaCha20Poly1305) Encrypt

func (cc20p1305 *ChaCha20Poly1305) Encrypt(plaintext, additionalData, nonce []byte) ([]byte, error)

Encrypt encrypts plaintext by the given arguments and returns ciphertext.

type ECDHP256XChaCha20Poly1305

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

ECDHP256XChaCha20Poly1305 represents an ECDHP256XChaCha20Poly1305 cipher.

func NewECDHP256XChaCha20Poly1305

func NewECDHP256XChaCha20Poly1305(privateKey, publicKey []byte, sharedKeyHandler func(peerKey []byte) (sharedKey, publicKey []byte, err error)) (*ECDHP256XChaCha20Poly1305, error)

NewECDHP256XChaCha20Poly1305 creates a new ECDHP256XChaCha20Poly1305 instance. By design (similar to ephemeral-static Diffie-Hellman) this cipher:

  1. Generates an ephemeral private key (instead of using the given private key) during encryption.
  2. Extracts public key from the ciphertext (instead of using the given public key).

Because the encryption always uses the given public key and the decryption always uses the given private key it doesn't require both keys to be present at the same time.

Optional sharedKeyHandler argument allows encryption and decryption without providing private and public keys. This is useful where the keys are not accessible to pass (i.e. hardware security key).

func (*ECDHP256XChaCha20Poly1305) Decrypt

func (ecdhcc20p1305 *ECDHP256XChaCha20Poly1305) Decrypt(ciphertext, additionalData, nonce []byte) ([]byte, error)

Decrypt decrypts ciphertext by the given arguments and returns plaintext.

func (*ECDHP256XChaCha20Poly1305) Encrypt

func (ecdhcc20p1305 *ECDHP256XChaCha20Poly1305) Encrypt(plaintext, additionalData, nonce []byte) ([]byte, error)

Encrypt encrypts plaintext by the given arguments and returns ciphertext.

type X25519XChaCha20Poly1305

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

X25519XChaCha20Poly1305 represents an X25519XChaCha20Poly1305 cipher.

func NewX25519XChaCha20Poly1305

func NewX25519XChaCha20Poly1305(privateKey, publicKey []byte) (*X25519XChaCha20Poly1305, error)

NewX25519XChaCha20Poly1305 creates a new X25519XChaCha20Poly1305 instance. By design (similar to ephemeral-static Diffie-Hellman) this cipher:

  1. Generates an ephemeral private key (instead of using the given private key) during encryption.
  2. Extracts public key from the ciphertext (instead of using the given public key).

Because the encryption always uses the given public key and the decryption always uses the given private key it doesn't require both keys to be present at the same time.

func (*X25519XChaCha20Poly1305) Decrypt

func (x25519cc20p1305 *X25519XChaCha20Poly1305) Decrypt(ciphertext, additionalData, nonce []byte) ([]byte, error)

Decrypt decrypts ciphertext by the given arguments and returns plaintext.

func (*X25519XChaCha20Poly1305) Encrypt

func (x25519cc20p1305 *X25519XChaCha20Poly1305) Encrypt(plaintext, additionalData, nonce []byte) ([]byte, error)

Encrypt encrypts plaintext by the given arguments and returns ciphertext.

Jump to

Keyboard shortcuts

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