crypto

package
v0.8.8 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2017 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HashSize represents the hash length
	HashSize = 32
)
View Source
const (
	// SignatureSize represents the signature length
	SignatureSize = 65
)

Variables

View Source
var (
	// N is secp256k1 N
	N = S256().Params().N
)

Functions

func AesCTRXOR

func AesCTRXOR(key, inText, iv []byte) ([]byte, error)

AesCTRXOR encrypts data with CTRXOR

func AesDecrypt

func AesDecrypt(crypted, key []byte) ([]byte, error)

AesDecrypt decrypts data using the specified key

func AesEncrypt

func AesEncrypt(origData, key []byte) ([]byte, error)

AesEncrypt encrypts data using the specified key

func Ecrecover

func Ecrecover(hash, sig []byte) ([]byte, error)

Ecrecover recovers publick key

func Keccak256

func Keccak256(data ...[]byte) []byte

Keccak256 calculates and returns the Keccak256 hash of the input data.

func PKCS5Padding

func PKCS5Padding(ciphertext []byte, blockSize int) []byte

PKCS5Padding padding data

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) []byte

PKCS5UnPadding unpadding data

func Ripemd160

func Ripemd160(data []byte) []byte

Ripemd160 calculates the returns ripemd160 hash of the input data

func S256

func S256() elliptic.Curve

S256 returns an instance of the secp256k1 curve

func ZeroKey

func ZeroKey(k *PrivateKey)

ZeroKey clean private key

Types

type Hash

type Hash [HashSize]byte

Hash represents the 32 byte hash of arbitrary data

func CalcHash

func CalcHash(a, b Hash) Hash

CalcHash calculates and returns the hash of the a + b

func ComputeMerkleHash

func ComputeMerkleHash(data []Hash) []Hash

ComputeMerkleHash returns the merkle root hash of the hash lists

func DoubleSha256

func DoubleSha256(data []byte) Hash

DoubleSha256 calculates and returns double sha256 hash of the input data

func GetMerkleHash

func GetMerkleHash(data []Hash) Hash

GetMerkleHash returns the final hash

func HexToHash

func HexToHash(s string) Hash

HexToHash coverts string `s` to hash

func NewHash

func NewHash(data []byte) Hash

NewHash constructs a hash use the giving bytes

func Sha256

func Sha256(data []byte) Hash

Sha256 calculates and returns sha256 hash of the input data

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes returns the bytes respresentation of the hash

func (Hash) Equal

func (h Hash) Equal(h1 Hash) bool

Equal reports whether h1 equal h

func (Hash) MarshalText

func (h Hash) MarshalText() ([]byte, error)

MarshalText returns the hex representation of h.

func (Hash) PrefixLen

func (h Hash) PrefixLen() int

PrefixLen returns the length of the zero prefix

func (*Hash) Reverse

func (h *Hash) Reverse() Hash

Reverse sets self byte-reversed hash

func (*Hash) SetBytes

func (h *Hash) SetBytes(b []byte)

SetBytes sets the hash to the value of b

func (*Hash) SetString

func (h *Hash) SetString(s string)

SetString set string `s` to h

func (Hash) String

func (h Hash) String() string

String returns the string respresentation of the hash

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

func (Hash) Xor

func (h Hash) Xor(h1 Hash) Hash

Xor calculates the h ^ h1. returns resulting hash

type PrivateKey

type PrivateKey ecdsa.PrivateKey

PrivateKey represents the ecdsa privatekey

func GenerateKey

func GenerateKey() (*PrivateKey, error)

GenerateKey returns a random PrivateKey

func HexToECDSA

func HexToECDSA(hexkey string) (*PrivateKey, error)

HexToECDSA parses a secp256k1 private key

func LoadECDSA

func LoadECDSA(file string) (*PrivateKey, error)

LoadECDSA loads a private key from the given file

func ToECDSA

func ToECDSA(prv []byte) *PrivateKey

ToECDSA creates a private key with the given D value.

func (*PrivateKey) Public

func (priv *PrivateKey) Public() *PublicKey

Public returns the public key corresponding to priv.

func (*PrivateKey) SaveECDSA

func (priv *PrivateKey) SaveECDSA(file string) error

SaveECDSA saves a private key to the given file

func (*PrivateKey) SecretBytes

func (priv *PrivateKey) SecretBytes() []byte

SecretBytes returns the actual bytes of ecdsa privatekey

func (*PrivateKey) Sign

func (priv *PrivateKey) Sign(hash []byte) (sig *Signature, err error)

Sign signs the hash and returns the signature

type PublicKey

type PublicKey ecdsa.PublicKey

PublicKey represents the ecdsa publickey

func SigToPub

func SigToPub(hash, sig []byte) (*PublicKey, error)

SigToPub recovers public key from the input data to the ecdsa public key

func ToECDSAPub

func ToECDSAPub(pub []byte) *PublicKey

ToECDSAPub returns ecdsa public key according the input data

func (*PublicKey) Bytes

func (pub *PublicKey) Bytes() []byte

Bytes returns the ecdsa PublickKey to bytes

type Signature

type Signature [SignatureSize]byte

Signature represents the ecdsa_signcompact signature data format [r - s - v]

func (*Signature) Bytes

func (sig *Signature) Bytes() []byte

Bytes returns the bytes of the signature

func (*Signature) Ecrecover

func (sig *Signature) Ecrecover(hash []byte) ([]byte, error)

Ecrecover recovers publick key

func (Signature) MarshalText

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

MarshalText returns the hex representation of h.

func (*Signature) RecoverPublicKey

func (sig *Signature) RecoverPublicKey(hash []byte) (*PublicKey, error)

RecoverPublicKey recovers public key and also verifys the signature

func (*Signature) SetBytes

func (sig *Signature) SetBytes(data []byte, compressed bool)

SetBytes returns a format signature according the raw signature

func (*Signature) UnmarshalText

func (sig *Signature) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

func (*Signature) VRS

func (sig *Signature) VRS() (v byte, r, s *big.Int)

VRS returns the v r s values

func (*Signature) Validate

func (sig *Signature) Validate() bool

Validate validates whether the signature values are valid

func (*Signature) Verify

func (sig *Signature) Verify(hash []byte, pub *PublicKey) bool

Verify verifys the signature with public key

Jump to

Keyboard shortcuts

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