Documentation ¶
Index ¶
- Constants
- Variables
- func CalculateSegments(fileSize uint64) (numSegments uint64)
- func GenerateSignatureKeys() (sk SecretKey, pk PublicKey, err error)
- func NewHash() hash.Hash
- func NewTree() tree
- func VerifyHash(data Hash, pk PublicKey, sig Signature) (err error)
- func VerifySegment(base [SegmentSize]byte, hashSet []Hash, numSegments, proofIndex uint64, ...) bool
- type Ciphertext
- type Hash
- func BuildReaderProof(r io.Reader, proofIndex uint64) (base [SegmentSize]byte, hashSet []Hash, err error)
- func HashAll(objs ...interface{}) Hash
- func HashBytes(data []byte) Hash
- func HashObject(obj interface{}) Hash
- func MerkleRoot(leaves [][]byte) (h Hash)
- func ReaderMerkleRoot(r io.Reader) (h Hash, err error)
- type HashSlice
- type PublicKey
- type SecretKey
- type Signature
- type TwofishKey
Constants ¶
const ( PublicKeySize = ed25519.PublicKeySize SecretKeySize = ed25519.PrivateKeySize SignatureSize = ed25519.SignatureSize )
const (
HashSize = 32
)
const (
SegmentSize = 64 // number of bytes that are hashed to form each base leaf of the Merkle tree
)
Variables ¶
var ( ErrNilInput = errors.New("cannot use nil input") ErrInvalidSignature = errors.New("invalid signature") )
var (
ErrInsufficientLen = errors.New("supplied ciphertext is not long enough to contain a nonce")
)
Functions ¶
func CalculateSegments ¶ added in v0.3.0
Calculates the number of segments in the file when building a Merkle tree. Should probably be renamed to CountLeaves() or something.
func GenerateSignatureKeys ¶
GenerateKeyPair creates a public-secret keypair that can be used to sign and verify messages.
func VerifyHash ¶ added in v0.3.0
VerifyHash uses a public key and input data to verify a signature.
func VerifySegment ¶ added in v0.3.0
Types ¶
type Ciphertext ¶ added in v0.3.1
type Ciphertext []byte
type Hash ¶ added in v0.3.0
func BuildReaderProof ¶ added in v0.3.0
func HashAll ¶ added in v0.3.0
func HashAll(objs ...interface{}) Hash
HashAll takes a set of objects as input, encodes them all using the encoding package, and then hashes the result.
func HashObject ¶ added in v0.3.0
func HashObject(obj interface{}) Hash
HashObject takes an object as input, encodes it using the encoding package, and then hashes the result.
func MerkleRoot ¶ added in v0.3.0
MerkleRoot calculates the "root hash" formed by repeatedly concatenating and hashing a binary tree of hashes. If the number of leaves is not a power of 2, the orphan hash(es) are not rehashed. Examples:
┌───┴──┐ ┌────┴───┐ ┌─────┴─────┐ ┌──┴──┐ │ ┌──┴──┐ │ ┌──┴──┐ ┌──┴──┐ ┌─┴─┐ ┌─┴─┐ │ ┌─┴─┐ ┌─┴─┐ ┌─┴─┐ ┌─┴─┐ ┌─┴─┐ ┌─┴─┐ │ (5-leaf) (6-leaf) (7-leaf)
type HashSlice ¶ added in v0.3.0
type HashSlice []Hash
HashSlice is used for sorting
type PublicKey ¶
type PublicKey [ed25519.PublicKeySize]byte
type SecretKey ¶
type SecretKey [ed25519.PrivateKeySize]byte
type Signature ¶
type Signature [ed25519.SignatureSize]byte
type TwofishKey ¶ added in v0.3.0
type TwofishKey [32]byte
func GenerateTwofishKey ¶ added in v0.3.0
func GenerateTwofishKey() (key TwofishKey, err error)
GenerateEncryptionKey produces a key that can be used for encrypting and decrypting files.
func (TwofishKey) DecryptBytes ¶ added in v0.3.0
func (key TwofishKey) DecryptBytes(ct Ciphertext) ([]byte, error)
DecryptBytes decrypts the ciphertext created by EncryptBytes. The nonce is expected to be the first 12 bytes of the ciphertext.
func (TwofishKey) EncryptBytes ¶ added in v0.3.0
func (key TwofishKey) EncryptBytes(plaintext []byte) (Ciphertext, error)
EncryptBytes encrypts a []byte using the key. EncryptBytes uses GCM and prepends the nonce (12 bytes) to the ciphertext.
func (TwofishKey) NewCipher ¶ added in v0.3.2
func (key TwofishKey) NewCipher() cipher.Block
NewCipher creates a new Twofish cipher from the key.