cipher

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2022 License: GPL-3.0 Imports: 9 Imported by: 3

Documentation

Index

Constants

View Source
const (
	DefaultNonceSize = 12 // 12 bytes
	DefaultOverhead  = 16 // 16 bytes
	DefaultKeyLen    = 32 // 256 bits
)

Variables

This section is empty.

Functions

func HashPassword

func HashPassword(rawPassword, uniqueValue []byte) []byte

HashPassword generates a hashed password from the raw password and a unique value that decorates the password.

Types

type AESGCMBlockCipher

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

AESGCMBlockCipher implements BlockCipher interface with AES-GCM algorithm.

func (*AESGCMBlockCipher) BlockSize

func (*AESGCMBlockCipher) BlockSize() int

BlockSize returns the block size of cipher.

func (*AESGCMBlockCipher) Clone added in v1.4.0

func (c *AESGCMBlockCipher) Clone() BlockCipher

func (*AESGCMBlockCipher) Decrypt

func (c *AESGCMBlockCipher) Decrypt(ciphertext []byte) ([]byte, error)

func (*AESGCMBlockCipher) Encrypt

func (c *AESGCMBlockCipher) Encrypt(plaintext []byte) ([]byte, error)

func (*AESGCMBlockCipher) ImplicitNonce added in v1.4.0

func (c *AESGCMBlockCipher) ImplicitNonce() []byte

ImplicitNonce returns the implicit nonce used by the block cipher.

func (*AESGCMBlockCipher) IsStateless added in v1.4.0

func (c *AESGCMBlockCipher) IsStateless() bool

func (*AESGCMBlockCipher) NonceSize

func (c *AESGCMBlockCipher) NonceSize() int

NonceSize returns the number of bytes used by nonce.

func (*AESGCMBlockCipher) Overhead

func (c *AESGCMBlockCipher) Overhead() int

func (*AESGCMBlockCipher) SetImplicitNonceMode added in v1.4.0

func (c *AESGCMBlockCipher) SetImplicitNonceMode(enable bool)

type BlockCipher

type BlockCipher interface {
	// Encrypt method adds the nonce in the dst, then encryptes the src.
	Encrypt(plaintext []byte) ([]byte, error)

	// Decrypt method removes the nonce in the src, then decryptes the src.
	Decrypt(ciphertext []byte) ([]byte, error)

	NonceSize() int

	Overhead() int

	// Clone method creates a deep copy of block cipher itself.
	// Panic if this operation fails.
	Clone() BlockCipher

	// SetImplicitNonceMode enables or disables implicit nonce mode.
	// Under implicit nonce mode, the nonce is set exactly once on the first
	// Encrypt() or Decrypt() call. After that, all Encrypt() or Decrypt()
	// calls will not look up nonce in the data. Each Encrypt() or Decrypt()
	// will cause the nonce value to be increased by 1.
	//
	// Implicit nonce mode is disabled by default.
	//
	// Disabling implicit nonce mode removes the implicit nonce (state)
	// from the block cipher.
	SetImplicitNonceMode(enable bool)

	// IsStateless returns true if the BlockCipher can do arbitrary Encrypt()
	// and Decrypt() in any sequence.
	IsStateless() bool
}

BlockCipher is an interface of block encryption and decryption.

func BlockCipherFromPassword

func BlockCipherFromPassword(password []byte, stateless bool) (BlockCipher, error)

BlockCipherFromPassword creates a BlockCipher object from the password with the default settings.

func BlockCipherListFromPassword

func BlockCipherListFromPassword(password []byte, stateless bool) ([]BlockCipher, error)

BlockCipherListFromPassword creates three BlockCipher objects using different salts from the password with the default settings.

func CloneBlockCiphers added in v1.4.0

func CloneBlockCiphers(blocks []BlockCipher) []BlockCipher

CloneBlockCiphers clones a slice of block ciphers.

func SelectDecrypt added in v1.4.0

func SelectDecrypt(data []byte, blocks []BlockCipher) (BlockCipher, []byte, error)

SelectDecrypt returns the appropriate cipher block that can decrypt the data, as well as the decrypted result.

func TryDecrypt added in v1.4.0

func TryDecrypt(data, password []byte, stateless bool) (BlockCipher, []byte, error)

TryDecrypt tries to decrypt the data with all possible keys generated from the password. If successful, returns the block cipher as well as the decrypted results.

Jump to

Keyboard shortcuts

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