crypto

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: Apache-2.0 Imports: 6 Imported by: 13

README

Crypto

Basically, see the Tendermint v0.34 Crypto spec.

Documentation

Index

Examples

Constants

View Source
const (
	// AddressSize is the size of a pubkey address.
	AddressSize = tmhash.TruncatedSize
)
View Source
const Version = "0.9.0-dev"

Variables

This section is empty.

Functions

func CRandBytes

func CRandBytes(numBytes int) []byte

This only uses the OS's randomness

func CRandHex

func CRandHex(numDigits int) string

CRandHex returns a hex encoded string that's floor(numDigits/2) * 2 long.

Note: CRandHex(24) gives 96 bits of randomness that are usually strong enough for most purposes.

func CReader

func CReader() io.Reader

Returns a crand.Reader.

func Sha256

func Sha256(bytes []byte) []byte
Example
package main

import (
	"fmt"

	"github.com/Finschia/ostracon/crypto"
)

func main() {
	sum := crypto.Sha256([]byte("This is Ostracon"))
	fmt.Printf("%x\n", sum)
}
Output:

e4f6b8545bd63b92f12936eccde66e48cc26895e8e67297ff97cc31c833a38d4

Types

type Address

type Address = bytes.HexBytes

An address is a []byte, but hex-encoded even in JSON. []byte leaves us the option to change the address length. Use an alias so Unmarshal methods (with ptr receivers) are available too.

func AddressHash

func AddressHash(bz []byte) Address

type Output

type Output []byte

type PrivKey

type PrivKey interface {
	Bytes() []byte
	Sign(msg []byte) ([]byte, error)
	VRFProve(seed []byte) (Proof, error)
	PubKey() PubKey
	Equals(PrivKey) bool
	Type() string
}

type Proof

type Proof []byte

Proof represents the VRF Proof. It should be defined separately from Ed25519 VRF Proof to avoid circular import.

type PubKey

type PubKey interface {
	Address() Address
	Bytes() []byte
	VerifySignature(msg []byte, sig []byte) bool
	VRFVerify(proof []byte, message []byte) (Output, error)
	Equals(PubKey) bool
	Type() string
}

type Symmetric

type Symmetric interface {
	Keygen() []byte
	Encrypt(plaintext []byte, secret []byte) (ciphertext []byte)
	Decrypt(ciphertext []byte, secret []byte) (plaintext []byte, err error)
}

Directories

Path Synopsis
internal
Package merkle computes a deterministic minimal height Merkle tree hash.
Package merkle computes a deterministic minimal height Merkle tree hash.
Package xchacha20poly1305 creates an AEAD using hchacha, chacha, and poly1305 This allows for randomized nonces to be used in conjunction with chacha.
Package xchacha20poly1305 creates an AEAD using hchacha, chacha, and poly1305 This allows for randomized nonces to be used in conjunction with chacha.

Jump to

Keyboard shortcuts

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