Documentation ¶
Overview ¶
Package cipherman provides various cipher implementations.
Index ¶
Constants ¶
const (
// ECDHHKDFInfoSK represents the derived key info for the shared key.
ECDHHKDFInfoSK = "ECDH"
)
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.
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:
- Generates an ephemeral private key (instead of using the given private key) during encryption.
- 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).
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:
- Generates an ephemeral private key (instead of using the given private key) during encryption.
- 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.