crypto

package
v0.0.0-...-f0f197f Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2022 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DigestSize = sha512.Size256

DigestSize is the number of bytes in the preferred hash Digest used here.

Variables

This section is empty.

Functions

func HashRep

func HashRep(h Hashable) []byte

HashRep appends the correct hashid before the message to be hashed.

func NewHash

func NewHash() hash.Hash

NewHash returns a sha512-256 object to do the same operation as Hash()

func VrfKeygen

func VrfKeygen() (pub VrfPubkey, priv VrfPrivkey)

VrfKeygen generates a random VRF keypair.

func VrfKeygenFromSeed

func VrfKeygenFromSeed(seed [32]byte) (pub VrfPubkey, priv VrfPrivkey)

VrfKeygenFromSeed deterministically generates a VRF keypair from 32 bytes of (secret) entropy.

Types

type Digest

type Digest [DigestSize]byte

Digest represents a 32-byte value holding the 256-bit Hash digest.

func DigestFromString

func DigestFromString(str string) (d Digest, err error)

DigestFromString converts a string to a Digest

func Hash

func Hash(data []byte) Digest

Hash computes the SHASum512_256 hash of an array of bytes

func HashObj

func HashObj(h Hashable) Digest

HashObj computes a hash of a Hashable object and its type

func (Digest) IsZero

func (d Digest) IsZero() bool

IsZero return true if the digest contains only zeros, false otherwise

func (Digest) String

func (d Digest) String() string

String returns the digest in a human-readable Base32 string

func (Digest) ToSlice

func (d Digest) ToSlice() []byte

ToSlice converts Digest to slice, is used by bookkeeping.PaysetCommit

func (Digest) TrimUint64

func (d Digest) TrimUint64() uint64

TrimUint64 returns the top 64 bits of the digest and converts to uint64

type HashID

type HashID string

HashID is a domain separation prefix for an object type that might be hashed This ensures, for example, the hash of a transaction will never collide with the hash of a vote

const (
	AppIndex HashID = "appID"

	// ARCReserved is used to reserve prefixes starting with `arc` to
	// ARCs-related hashes https://github.com/algorandfoundation/ARCs
	// The prefix for ARC-XXXX should start with:
	// "arcXXXX" (where "XXXX" is the 0-padded number of the ARC)
	// For example ARC-0003 can use any prefix starting with "arc0003"
	ARCReserved HashID = "arc"

	AuctionBid        HashID = "aB"
	AuctionDeposit    HashID = "aD"
	AuctionOutcomes   HashID = "aO"
	AuctionParams     HashID = "aP"
	AuctionSettlement HashID = "aS"

	AgreementSelector                HashID = "AS"
	BlockHeader256                   HashID = "B256"
	BlockHeader                      HashID = "BH"
	BalanceRecord                    HashID = "BR"
	Credential                       HashID = "CR"
	Genesis                          HashID = "GE"
	KeysInMSS                        HashID = "KP"
	MerkleArrayNode                  HashID = "MA"
	MerkleVectorCommitmentBottomLeaf HashID = "MB"
	Message                          HashID = "MX"
	NetPrioResponse                  HashID = "NPR"
	OneTimeSigKey1                   HashID = "OT1"
	OneTimeSigKey2                   HashID = "OT2"
	PaysetFlat                       HashID = "PF"
	Payload                          HashID = "PL"
	Program                          HashID = "Program"
	ProgramData                      HashID = "ProgData"
	ProposerSeed                     HashID = "PS"
	ParticipationKeys                HashID = "PK"
	Seed                             HashID = "SD"
	SpecialAddr                      HashID = "SpecialAddr"
	SignedTxnInBlock                 HashID = "STIB"

	StateProofCoin    HashID = "spc"
	StateProofMessage HashID = "spm"
	StateProofPart    HashID = "spp"
	StateProofSig     HashID = "sps"

	TestHashable  HashID = "TE"
	TxGroup       HashID = "TG"
	TxnMerkleLeaf HashID = "TL"
	Transaction   HashID = "TX"
	Vote          HashID = "VO"
	RequestHash   HashID = "RH"
)

Hash IDs for specific object types, in lexicographic order. Hash IDs must be PREFIX-FREE (no hash ID is a prefix of another).

type Hashable

type Hashable interface {
	ToBeHashed() (HashID, []byte)
}

Hashable is an interface implemented by an object that can be represented with a sequence of bytes to be hashed or signed, together with a type ID to distinguish different types of objects.

type VRFProof

type VRFProof = VrfProof

VRFProof is a deprecated name for VrfProof

type VRFSecrets

type VRFSecrets struct {
	PK VrfPubkey
	SK VrfPrivkey
	// contains filtered or unexported fields
}

VRFSecrets is a wrapper for a VRF keypair. Use *VrfPrivkey instead

func GenerateVRFSecrets

func GenerateVRFSecrets() *VRFSecrets

GenerateVRFSecrets is deprecated, use VrfKeygen or VrfKeygenFromSeed instead

type VRFVerifier

type VRFVerifier = VrfPubkey

VRFVerifier is a deprecated name for VrfPubkey

type VrfOutput

type VrfOutput [64]byte

VrfOutput is a 64-byte pseudorandom value that can be computed from a VrfProof. The VRF scheme guarantees that such output will be unique

type VrfPrivkey

type VrfPrivkey [64]byte

A VrfPrivkey is a private key used for producing VRF proofs. Specifically, we use a 64-byte ed25519 private key (the latter 32-bytes are the precomputed public key)

func (VrfPrivkey) Prove

func (sk VrfPrivkey) Prove(message Hashable) (proof VrfProof, ok bool)

Prove constructs a VRF Proof for a given Hashable. ok will be false if the private key is malformed.

func (VrfPrivkey) Pubkey

func (sk VrfPrivkey) Pubkey() (pk VrfPubkey)

Pubkey returns the public key that corresponds to the given private key.

type VrfProof

type VrfProof [80]byte

A VrfProof for a message can be generated with a secret key and verified against a public key, like a signature. Proofs are malleable, however, for a given message and public key, the VRF output that can be computed from a proof is unique.

func (VrfProof) Hash

func (proof VrfProof) Hash() (hash VrfOutput, ok bool)

Hash converts a VRF proof to a VRF output without verifying the proof. TODO: Consider removing so that we don't accidentally hash an unverified proof

type VrfPubkey

type VrfPubkey [32]byte

A VrfPubkey is a public key that can be used to verify VRF proofs.

func VrfPubkeyFromHexString

func VrfPubkeyFromHexString(s string) (VrfPubkey, error)

func (VrfPubkey) ToHexString

func (pk VrfPubkey) ToHexString() string

func (VrfPubkey) Verify

func (pk VrfPubkey) Verify(p VrfProof, message Hashable) (bool, VrfOutput)

Verify checks a VRF proof of a given Hashable. If the proof is valid the pseudorandom VrfOutput will be returned. For a given public key and message, there are potentially multiple valid proofs. However, given a public key and message, all valid proofs will yield the same output. Moreover, the output is indistinguishable from random to anyone without the proof or the secret key.

Jump to

Keyboard shortcuts

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