Documentation ¶
Overview ¶
Package crypto offers some functions that are often used in our code.
hash.go provides some utilities regarding the hashing of bytes, files or stream. The most common way to use it is to call: `HashStream(sha256.New(),stream)`. It will stream the input into the hash function by chunks and output the final hash.
schnorr.go provides some crypto-shortcuts: Schnorr signature and a Hash-function. See https://en.wikipedia.org/wiki/Schnorr_signature
It provides a way to sign a message using a private key and to verify the signature using the public counter part.
Index ¶
- Constants
- func CheckLocalProofs(newHash HashFunc, root HashID, leaves []HashID, proofs []Proof) bool
- func Hash(hash h.Hash, buff []byte) ([]byte, error)
- func HashArgs(hash h.Hash, args ...encoding.BinaryMarshaler) ([]byte, error)
- func HashArgsSuite(suite abstract.Suite, args ...encoding.BinaryMarshaler) ([]byte, error)
- func HashBytes(hash h.Hash, b []byte) ([]byte, error)
- func HashFile(hash h.Hash, file string) ([]byte, error)
- func HashFileChunk(hash h.Hash, file string, chunkSize int) ([]byte, error)
- func HashFileSuite(suite abstract.Suite, file string) ([]byte, error)
- func HashStream(hash h.Hash, stream io.Reader) ([]byte, error)
- func HashStreamChunk(hash h.Hash, stream io.Reader, chunkSize int) ([]byte, error)
- func HashStreamSuite(suite abstract.Suite, stream io.Reader) ([]byte, error)
- func MerkleGet(suite abstract.Suite, root []byte, path MerklePath, ctx HashGet) ([]byte, error)
- func PrintProofs(proofs []Proof)
- func ProofTree(newHash func() gohash.Hash, leaves []HashID) (HashID, []Proof)
- func PubHex(suite abstract.Suite, point abstract.Point) (string, error)
- func ReadPub64(suite abstract.Suite, r io.Reader) (abstract.Point, error)
- func ReadPubHex(suite abstract.Suite, s string) (abstract.Point, error)
- func ReadSecret64(suite abstract.Suite, r io.Reader) (abstract.Secret, error)
- func ReadSecretHex(suite abstract.Suite, str string) (abstract.Secret, error)
- func SecretHex(suite abstract.Suite, secret abstract.Secret) (string, error)
- func VerifySchnorr(suite abstract.Suite, public abstract.Point, msg []byte, sig SchnorrSig) error
- func WritePub64(suite abstract.Suite, w io.Writer, point abstract.Point) error
- func WriteSecret64(suite abstract.Suite, w io.Writer, secret abstract.Secret) error
- type ByHashID
- type HashFunc
- type HashGet
- type HashID
- type HashMap
- type LevelProof
- type MerklePath
- type Proof
- type SchnorrSig
Constants ¶
const DefaultChunkSize = 1024
DefaultChunkSize is the size of the chunk used to read a stream
Variables ¶
This section is empty.
Functions ¶
func CheckLocalProofs ¶
CheckLocalProofs does something unknonw
func HashArgs ¶
HashArgs takes all args and returns the hash. Every arg has to implement BinaryMarshaler or will be added using fmt.Sprint
func HashArgsSuite ¶
HashArgsSuite makes a new hash from the suite and calls HashArgs
func HashFile ¶
HashFile will hash the file using the streaming approach with DefaultChunkSize size of chunks
func HashFileChunk ¶
HashFileChunk is similar to HashFile but using a chunkSize size of chunks for reading.
func HashFileSuite ¶
HashFileSuite returns the hash of a file using the hashing function of the suite given.
func HashStream ¶
HashStream returns the hash of the stream reading from it chunk by chunk of size DefaultChunkSize
func HashStreamChunk ¶
HashStreamChunk will hash the stream using chunks of size chunkSize
func HashStreamSuite ¶
HashStreamSuite will hash the stream using the hashing function of the suite
func MerkleGet ¶
MerkleGet - Retrieves an object in a Merkle tree, validating the entire path in the process. Returns a slice of a buffer obtained from HashGet.Get(), which might be shared and should be considered read-only.
func ProofTree ¶
ProofTree - Generates a Merkle proof tree for the given list of leaves, yielding one output proof per leaf.
func ReadPubHex ¶
ReadPubHex reads a hexadecimal representation of a public point and convert it to the right struct
func ReadSecret64 ¶
ReadSecret64 takes a Base64-encoded secret and returns that secret, optionally an error
func ReadSecretHex ¶
ReadSecretHex reads a secret in hexadecimal from string
func VerifySchnorr ¶
VerifySchnorr verifies a given Schnorr signature. It returns nil iff the given signature is valid.
func WritePub64 ¶
WritePub64 writes a public point to a base64 representation
Types ¶
type ByHashID ¶
type ByHashID []HashID
ByHashID is for sorting arrays of HashIds
type HashGet ¶
type HashGet interface { // Get lookups and returns the binary blob for a given content HashId. // Checks and returns an error if the hash doesn't match the content; // the caller doesn't need to check this correspondence. Get(id HashID) ([]byte, error) }
HashGet is the context for looking up content blobs by self-certifying HashId. Implementations can be either local (same-node) or remote (cross-node).
type HashMap ¶
HashMap is a simple local-only, map-based implementation of HashGet interface
type LevelProof ¶
type LevelProof []HashID
LevelProof is used for the Big Merkle Tree (computed from server commits) A []LevelProof from root to server is sufficient proof
type MerklePath ¶
type MerklePath struct { Ptr []int // Offsets of hash-pointers at each intermediate level Ofs int // Offset of relevant object in last-level blob Len int // Length of relevant object in last-level blob }
MerklePath represents a downward path from a (root) node in a Merkle tree to a given (interior or leaf) descendant node, including all the data necessary to validate and extract the descendant. It is assumed the caller has a valid hash-pointer to the root/starting node, and that all nodes in the path can be retrieved via self-certifying hash-ID.
type Proof ¶
type Proof []HashID
Proof is used for Local Merkle Trees (computed based on messages from clients) One Proof sufficient for one leaf in a Local Merkle Tree
func (Proof) Calc ¶
Calc - Given a Proof and the hash of the leaf, compute the hash of the root. If the Proof is of length 0, simply returns leaf.
type SchnorrSig ¶
SchnorrSig is a signature created using the Schnorr Signature scheme.
func SignSchnorr ¶
SignSchnorr creates a Schnorr signature from a msg and a private key
func (*SchnorrSig) MarshalBinary ¶
func (ss *SchnorrSig) MarshalBinary() ([]byte, error)
MarshalBinary is used for example in hashing