crypto

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2021 License: AGPL-3.0 Imports: 1 Imported by: 4

Documentation

Overview

Package crypto contains cryptographic interfaces used in the vocdoni project. They are a simpler version of similar interfaces found in the standard library, such as hash.Hash and crypto.Signer.

The implementations should all use crypto/rand.Reader as their source of secure randomness. Constructors are not covered by the interfaces, but KeyPair implementations will generally expose a top-level function of the form:

FromHex(privHex string) (*T, error)

These interfaces are meant to encrypt, sign, or hash small chunks of bytes. Working with []byte directly can be simpler. However, be careful to not use chunks of bytes larger than a few megabytes, as that could significantly increase the memory and cpu overhead.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SortedMarshalJSON

func SortedMarshalJSON(v1 interface{}) ([]byte, error)

SortedMarshalJSON is similar to json.Marshal, but it also enforces all struct fields to be sorted when marshaling, just like json.Marshal does for maps.

Note that this function has an added cost. It should only matter when all keys need to be sorted at all times.

Types

type Cipher

type Cipher interface {
	PrivateKey

	// Encrypt encrypts message for a given recipient. If recipient is nil,
	// the message is encrypted for the encryption key itself.
	Encrypt(message []byte, recipient PublicKey) ([]byte, error)

	// Decrypt decryptes a message, assuming that it was encrypted for this
	// key.
	Decrypt(cipher []byte) ([]byte, error)
}

Cipher represents a private key which can encrypt and decrypt messages.

type Hash

type Hash interface {
	Hash(message []byte) []byte
}

Hash represents cryptographic hash algorihms.

type PrivateKey

type PrivateKey interface {
	// Bytes represents a private key as a byte slice, which can be useful to
	// then print it in hex or base64.
	Bytes() []byte

	// Public returns the public key that was derived from this private key.
	Public() PublicKey
}

PrivateKey represents a single private key, along with its derived public key. Note that the public key is derived when the private key is created.

type PublicKey

type PublicKey interface {
	// Bytes represents a public key as a byte slice, which can be useful to
	// then print it in hex or base64.
	Bytes() []byte
}

PublicKey represents a single public key.

type Signer

type Signer interface {
	PrivateKey

	Sign(message []byte) ([]byte, error)
}

Cipher represents a private key which can sign messages.

type Verifier

type Verifier interface {
	PublicKey

	Verify(message, signature []byte) error
}

Verifier represents a public key which can verify signed messages.

Directories

Path Synopsis
Package ethereum provides cryptographic operations used in go-dvote related to ethereum.
Package ethereum provides cryptographic operations used in go-dvote related to ethereum.
internal
Package nacl implements encryption and decryption using anonymous sealed boxes, depending on golang.org/x/crypto/nacl/box.
Package nacl implements encryption and decryption using anonymous sealed boxes, depending on golang.org/x/crypto/nacl/box.

Jump to

Keyboard shortcuts

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