Documentation
¶
Overview ¶
Package triplesec implements the TripleSec v3 and v4 encryption and authentication scheme.
For details on TripleSec, go to https://keybase.io/triplesec/
Index ¶
Constants ¶
const ( SaltLen = 16 VersionBytesLen = 4 AESIVLen = 16 TwofishIVLen = 16 SalsaIVLen = 24 MacOutputLen = 64 MacKeyLen = 48 CipherKeyLen = 32 // MaxDeriveKeyExtra is the maximum number of additional bytes callers may // request from DeriveKey. Known production callers require at most 128 // bytes; the larger limit leaves room for future uses while bounding memory. MaxDeriveKeyExtra = 1024 )
Variables ¶
var MagicBytes = [4]byte{0x1c, 0x94, 0xd7, 0xde}
MagicBytes are the four bytes prefixed to every TripleSec ciphertext, 1c 94 d7 de.
Functions ¶
This section is empty.
Types ¶
type BadPassphraseError ¶
type BadPassphraseError struct{}
func (BadPassphraseError) Error ¶
func (e BadPassphraseError) Error() string
type Cipher ¶
type Cipher struct {
// contains filtered or unexported fields
}
func NewCipher ¶
NewCipher makes an instance of TripleSec using a particular key and a particular salt. It copies the passphrase and salt.
func NewCipherWithRng ¶
func NewCipherWithRng(passphrase []byte, salt []byte, version Version, rng RandomnessGenerator) (*Cipher, error)
NewCipherWithRng makes an instance of TripleSec using a particular key and a particular salt and uses a given randomness stream.
WARNING: The rng parameter must be a cryptographically secure random number generator (CSPRNG). Using a deterministic or low-entropy generator will destroy confidentiality due to IV reuse across the stream cipher layers. This parameter exists for deterministic test vectors only. Production code should use NewCipher, which correctly uses crypto/rand.
func (*Cipher) Decrypt ¶
Decrypt decrypts a TripleSec ciphertext using the Cipher passphrase. The dst buffer size must be at least len(src) - Overhead. dst and src can not overlap. src is left untouched.
Encrypt returns a error if the ciphertext is not recognized, if authentication fails or on memory failures.
func (*Cipher) Encrypt ¶
Encrypt encrypts and signs a plaintext message with TripleSec using the Cipher's salt and passphrase. If the Cipher was created without a salt, one is generated on its first use and retained for later calls. The dst buffer size must be at least len(src) + Overhead. dst and src can not overlap. src is left untouched.
Encrypt returns a error on memory or RNG failures.
func (*Cipher) GetSalt ¶
GetSalt returns a copy of the Cipher's salt. If the Cipher has no salt, it generates and stores one before returning the copy.
func (*Cipher) Scrub ¶
func (c *Cipher) Scrub()
Scrub zeros out sensitive key material in the Cipher.
Callers should defer this after creating a Cipher to ensure key material is cleared from memory:
c, _ := NewCipher(passphrase, nil, version) defer c.Scrub()
Note: Due to Go's garbage collector and stack copying, this is best-effort and cannot guarantee that all copies of key material are removed from memory.
type CorruptionError ¶
type CorruptionError struct {
// contains filtered or unexported fields
}
func (CorruptionError) Error ¶
func (e CorruptionError) Error() string
func (CorruptionError) Unwrap ¶
func (e CorruptionError) Unwrap() error
type CryptoRandGenerator ¶
type CryptoRandGenerator struct{}
func NewCryptoRandGenerator ¶
func NewCryptoRandGenerator() CryptoRandGenerator
type RandomTapeGenerator ¶
type RandomTapeGenerator struct {
// contains filtered or unexported fields
}
func NewRandomTapeGenerator ¶
func NewRandomTapeGenerator(randomTape []byte) RandomTapeGenerator
type RandomnessGenerator ¶
type VersionError ¶
type VersionError struct {
// contains filtered or unexported fields
}
func (VersionError) Error ¶
func (e VersionError) Error() string