siacrypto

package
v0.0.0-...-058445b Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2014 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Sia uses a specific set of cryptographic functions across the entire project. All of those functions are defined and implemented within the siacrypto package to maintain consistency.

Currently, siacrypto is in a state of 'hotfix', meaning we intend to swap out the existing functions for NaCl or libsodium.

Index

Constants

View Source
const (
	PublicKeySize = 32
	SecretKeySize = 64
	SignatureSize = 64
)

Public keys, secret keys, and signatures all use a byte slice for their underlying representation. These sizes are the lengths of those types, in bytes.

View Source
const (
	// HashSize is the size of a Hash in bytes
	HashSize int = 32
)

Variables

This section is empty.

Functions

func CreateKeyPair

func CreateKeyPair() (pubKey PublicKey, secKey SecretKey, err error)

CreateKeyPair needs no input, produces a public key and secret key as output

func RandomByte

func RandomByte() byte

RandomByte returns a random byte

func RandomByteSlice

func RandomByteSlice(numBytes int) (randomBytes []byte)

RandomByteSlice returns a slice of random bytes

func RandomInt

func RandomInt(ceiling int) int

RandomInt generates a random int [0, ceiling)

func RandomUint16

func RandomUint16() uint16

RandomUint16 returns a random uint16. It accomplishes this by feeding 2 bytes of random data to a binary decoder.

func RandomUint64

func RandomUint64() (randInt uint64)

RandomUint64 returns a random uint64. It uses the same process as RandomUint16.

Types

type Hash

type Hash [HashSize]byte

A Hash is the first 32 bytes of a sha512 checksum.

func HashBytes

func HashBytes(data []byte) (h Hash)

HashBytes returns the first 32 bytes of the sha512 checksum of the input.

func HashObject

func HashObject(obj interface{}) (h Hash, err error)

HashObject converts an object to a byte slice and returns the hash of the byte slice.

func (Hash) String

func (h Hash) String() string

String returns a Hash formatted as a sequence of hex digits.

type PublicKey

type PublicKey [PublicKeySize]byte

A PublicKey is the binary representation of an ECC public key.

func (PublicKey) Verify

func (pk PublicKey) Verify(sig Signature, message []byte) bool

Verify returns whether a message was signed by the public key 'pk'.

func (PublicKey) VerifyObject

func (pk PublicKey) VerifyObject(sig Signature, obj interface{}) (verified bool, err error)

VerifyObject returns whether an object was signed by the public key 'pk'. It does so by marshalling the object, and then passing it to Verify().

type SecretKey

type SecretKey [SecretKeySize]byte

A SecretKey is the binary representation of an ECC secret key.

func (SecretKey) Sign

func (sk SecretKey) Sign(message []byte) (sig Signature, err error)

Sign returns the signature of a byte slice.

func (SecretKey) SignObject

func (sk SecretKey) SignObject(obj interface{}) (sig Signature, err error)

SignObject returns the signature of an object's hash.

type Signature

type Signature [SignatureSize]byte

A Signature is the binary representation of an ECC signature.

Jump to

Keyboard shortcuts

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