...

Package crypto

import "vminko.org/dscuss/crypto"
Overview
Index

Overview ▾

type PowFinder

PowFinder implements proof-of-work algorithm (also known as Hashcash). Proof-of-work is used in Dscuss to protect against Sybil attack.

type PowFinder struct {
    // contains filtered or unexported fields
}

func NewPowFinder

func NewPowFinder(data []byte) *PowFinder

func (*PowFinder) Find

func (pf *PowFinder) Find() ProofOfWork

func (*PowFinder) Validate

func (pf *PowFinder) Validate(nonce ProofOfWork) bool

type PrivateKey

type PrivateKey ecdsa.PrivateKey

func NewPrivateKey

func NewPrivateKey() (*PrivateKey, error)

NewPrivateKey generates a random P-224 ECDSA private key.

func ParsePrivateKeyFromDER

func ParsePrivateKeyFromDER(der []byte) (*PrivateKey, error)

ParsePrivateKeyFromDER decodes a PEM-encoded ECDSA private key.

func ParsePrivateKeyFromPEM

func ParsePrivateKeyFromPEM(encodedKey []byte) (*PrivateKey, error)

ParsePrivateKeyFromPEM decodes a PEM-encoded ECDSA private key.

func (*PrivateKey) EncodeToDER

func (key *PrivateKey) EncodeToDER() []byte

EncodeToDER encodes an ECDSA private key to DER format.

func (*PrivateKey) EncodeToPEM

func (key *PrivateKey) EncodeToPEM() []byte

EncodeToPEM encodes an ECDSA private key to PEM format.

func (*PrivateKey) Public

func (key *PrivateKey) Public() *PublicKey

public returns the public key corresponding to the private key.

type ProofOfWork

type ProofOfWork uint64

type PublicKey

type PublicKey ecdsa.PublicKey

func ParsePublicKeyFromDER

func ParsePublicKeyFromDER(encodedKey []byte) (*PublicKey, error)

ParsePublicKeyFromDER decodes a DER-encoded ECDSA public key.

func ParsePublicKeyFromPEM

func ParsePublicKeyFromPEM(encodedKey []byte) (*PublicKey, error)

ParsePublicKeyFromPEM decodes a PEM-encoded ECDSA public key.

func (*PublicKey) EncodeToDER

func (key *PublicKey) EncodeToDER() []byte

EncodeToDER encodes an ECDSA public key to DER format.

func (*PublicKey) EncodeToPEM

func (key *PublicKey) EncodeToPEM() []byte

EncodeToPEM encodes an ECDSA public key to PEM format.

func (*PublicKey) MarshalJSON

func (key *PublicKey) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoded key.

func (*PublicKey) UnmarshalJSON

func (key *PublicKey) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes b and sets result to *key.

func (*PublicKey) Verify

func (key *PublicKey) Verify(data []byte, sig Signature) bool

Verify checks whether the sig of the data corresponds the public key.

type Signature

type Signature []byte

func ParseSignature

func ParseSignature(b64sig []byte) (Signature, error)

ParseSignature decodes an ECDSA signature according to https://tools.ietf.org/html/rfc7515#appendix-A.3.1

func (Signature) Encode

func (sig Signature) Encode() string

Encode encodes an ECDSA signature according to https://tools.ietf.org/html/rfc7515#appendix-A.3.1

func (Signature) MarshalJSON

func (sig Signature) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON-encoded key.

func (*Signature) UnmarshalJSON

func (sig *Signature) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes b and sets result to *sig.

type Signer

Signer hides private key from caller and offers simple interface for signing data.

type Signer struct {
    // contains filtered or unexported fields
}

func NewSigner

func NewSigner(privkey *PrivateKey) *Signer

func (*Signer) Public

func (s *Signer) Public() *PublicKey

func (*Signer) Sign

func (s *Signer) Sign(data []byte) (Signature, error)

Sign creates a signature for the data using the Signer's private key.