xcrypto

package
v0.0.0-...-d2b8996 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2019 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PrvKeyBytesLen -- defines the length in bytes of a serialized private key.
	PrvKeyBytesLen = 32
)

Variables

This section is empty.

Functions

func BytesToBigInt

func BytesToBigInt(b []byte) *big.Int

BytesToBigInt -- returns big int for the b bytes represents.

func DoubleSha256

func DoubleSha256(data []byte) []byte

DoubleSha256 -- returns sha256(sha256) bytes.

func EcdsaSign

func EcdsaSign(prv *PrvKey, hash []byte) ([]byte, error)

EcdsaSign -- used get the ecdsa signature.

func EcdsaVerify

func EcdsaVerify(pub *PubKey, hash []byte, sign []byte) error

EcdsaVerify -- used to verify the ecdsa signature.

func Hash160

func Hash160(data []byte) []byte

Hash160 -- returns ripemd160(sha256) bytes.

func Ripemd160

func Ripemd160(data []byte) []byte

Ripemd160 -- returns ripemd160 bytes.

func Ripemd160Size

func Ripemd160Size() int

Ripemd160Size -- Size of the ripemd160.

func SchnorrSign

func SchnorrSign(prv *PrvKey, hash []byte) ([]byte, error)

SchnorrSign -- used get the schnorr signature.

func SchnorrVerify

func SchnorrVerify(pub *PubKey, hash []byte, sign []byte) error

SchnorrVerify -- used to verify the schnorr signature.

func Sha256

func Sha256(data []byte) []byte

Sha256 -- returns sha256 bytes.

Types

type EcdsaAlice

type EcdsaAlice struct {
	*EcdsaParty
}

EcdsaAlice --

func NewEcdsaAlice

func NewEcdsaAlice(prv *PrvKey) *EcdsaAlice

NewEcdsaAlice -- creates new EcdsaAlice.

func (*EcdsaAlice) ScriptlessPhase1

func (alice *EcdsaAlice) ScriptlessPhase1(pub2 *PubKey) *PubKey

ScriptlessPhase1 -- used to generate final pubkey of parties.

func (*EcdsaAlice) ScriptlessPhase2

func (alice *EcdsaAlice) ScriptlessPhase2(hash []byte) (*big.Int, *paillier.PubKey, *secp256k1.Scalar)

ScriptlessPhase2 -- used to generate k, kinv, scalarR.

func (*EcdsaAlice) ScriptlessPhase3

func (alice *EcdsaAlice) ScriptlessPhase3(r2 *secp256k1.Scalar) *secp256k1.Scalar

ScriptlessPhase3 -- return the shared R.

func (*EcdsaAlice) ScriptlessPhase4

func (alice *EcdsaAlice) ScriptlessPhase4(encpk2 *big.Int, encpub2 *paillier.PubKey, shareR *secp256k1.Scalar) (*big.Int, error)

ScriptlessPhase4 -- return the homomorphic ciphertext.

func (*EcdsaAlice) ScriptlessPhase5

func (alice *EcdsaAlice) ScriptlessPhase5(shareR *secp256k1.Scalar, sign2 *big.Int) (*big.Int, error)

ScriptlessPhase5 -- return the partial signature of alice party.

func (*EcdsaAlice) ScriptlessPhase6

func (alice *EcdsaAlice) ScriptlessPhase6(alicesig *big.Int, bobsig *big.Int) *big.Int

ScriptlessPhase6 -- get the secret T.

type EcdsaBob

type EcdsaBob struct {
	*EcdsaParty
	// contains filtered or unexported fields
}

EcdsaBob --

func NewEcdsaBob

func NewEcdsaBob(prv *PrvKey, secret *big.Int) *EcdsaBob

NewEcdsaBob -- creates new EcdsaBob with a secret.

func (*EcdsaBob) ScriptlessPhase1

func (bob *EcdsaBob) ScriptlessPhase1(pub2 *PubKey) *PubKey

ScriptlessPhase1 -- used to generate final pubkey of parties.

func (*EcdsaBob) ScriptlessPhase2

func (bob *EcdsaBob) ScriptlessPhase2(hash []byte) (*big.Int, *paillier.PubKey, *secp256k1.Scalar)

ScriptlessPhase2 -- used to generate k, kinv, scalarR. R=bobR*secret

func (*EcdsaBob) ScriptlessPhase3

func (bob *EcdsaBob) ScriptlessPhase3(r2 *secp256k1.Scalar) *secp256k1.Scalar

ScriptlessPhase3 -- return the shared R.

func (*EcdsaBob) ScriptlessPhase4

func (bob *EcdsaBob) ScriptlessPhase4(encpk2 *big.Int, encpub2 *paillier.PubKey, shareR *secp256k1.Scalar) (*big.Int, error)

ScriptlessPhase4 -- return the homomorphic ciphertext.

func (*EcdsaBob) ScriptlessPhase5

func (bob *EcdsaBob) ScriptlessPhase5(shareR *secp256k1.Scalar, sign2 *big.Int) (*big.Int, error)

ScriptlessPhase5 -- return the final signature of two party.

func (*EcdsaBob) ScriptlessPhase6

func (bob *EcdsaBob) ScriptlessPhase6(shareR *secp256k1.Scalar, sig *big.Int) ([]byte, error)

ScriptlessPhase6 -- returns the DER signature.

type EcdsaParty

type EcdsaParty struct {
	N *big.Int
	// contains filtered or unexported fields
}

EcdsaParty -- ECDSA party struct.

func NewEcdsaParty

func NewEcdsaParty(prv *PrvKey) *EcdsaParty

NewEcdsaParty -- creates new EcdsaParty.

func (*EcdsaParty) Close

func (party *EcdsaParty) Close()

Close -- used to cleanup the secret.

func (*EcdsaParty) Phase1

func (party *EcdsaParty) Phase1(pub2 *PubKey) *PubKey

Phase1 -- used to generate final pubkey of parties. Return the shared PubKey.

func (*EcdsaParty) Phase2

func (party *EcdsaParty) Phase2(hash []byte) (*big.Int, *paillier.PubKey, *secp256k1.Scalar)

Phase2 -- used to generate k, kinv, scalarR. Return the party scalar R.

func (*EcdsaParty) Phase3

func (party *EcdsaParty) Phase3(r2 *secp256k1.Scalar) *secp256k1.Scalar

Phase3 -- set party2's r2 to this party. Return the shared R.

func (*EcdsaParty) Phase4

func (party *EcdsaParty) Phase4(encpk2 *big.Int, encpub2 *paillier.PubKey, shareR *secp256k1.Scalar) (*big.Int, error)

Phase4 -- generate the homomorphic encryption signature of this party. Return the homomorphic ciphertext.

func (*EcdsaParty) Phase5

func (party *EcdsaParty) Phase5(shareR *secp256k1.Scalar, sign2 *big.Int) ([]byte, error)

Phase5 -- generate the final signature of two party. Return the final signature.

type Merkle

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

Merkle --

func NewMerkle

func NewMerkle(hashs [][]byte) *Merkle

NewMerkle -- create new Merkle. children nodes. A diagram depicting how this works for bitcoin transactions where h(x) is a double sha256 follows:

         root = h1234 = h(h12 + h34)
        /                           \
  h12 = h(h1 + h2)            h34 = h(h3 + h4)
   /            \              /            \
h1 = h(tx1)  h2 = h(tx2)    h3 = h(tx3)  h4 = h(tx4)

If the right is nil(the size is not power of 2), hashed with itself.

func (*Merkle) Proofs

func (m *Merkle) Proofs(leaf []byte) []Node

Proofs -- gets the proof path for this leaf.

func (*Merkle) Root

func (m *Merkle) Root() []byte

Root -- returns the merkle root.

func (*Merkle) Verify

func (m *Merkle) Verify(leaf []byte, root []byte, path []Node) bool

Verify -- used to verify the leaf contained in the merkle tree.

type Node

type Node struct {
	Hash     []byte
	Parent   []byte
	Position string
}

Node -- node for prove.

type PrvKey

type PrvKey ecdsa.PrivateKey

PrvKey --

func PrvKeyFromBytes

func PrvKeyFromBytes(key []byte) *PrvKey

PrvKeyFromBytes -- returns a private and public key for secp256k1 curve.

func (*PrvKey) Add

func (p *PrvKey) Add(n2 []byte) *PrvKey

Add -- add n2 to PrvKey. k3 = (k1 + k2) mod N

func (*PrvKey) PubKey

func (p *PrvKey) PubKey() *PubKey

PubKey -- returns ecdsa public key.

func (*PrvKey) Serialize

func (p *PrvKey) Serialize() []byte

Serialize -- returns the private key number d as a big-endian binary-encoded number, padded to a length of 32 bytes.

type PubKey

type PubKey ecdsa.PublicKey

PubKey -- an ecdsa.PubKey with additional functions to serialize in uncompressed, compressed, and hybrid formats.

func PubKeyFromBytes

func PubKeyFromBytes(key []byte) (*PubKey, error)

PubKeyFromBytes -- parse bytes to public key.

func (*PubKey) Add

func (p *PubKey) Add(p2 *PubKey) *PubKey

Add -- add p2 to PubKey.

func (*PubKey) Hash160

func (p *PubKey) Hash160() []byte

Hash160 -- returns the Hash160 of the compressed public key.

func (*PubKey) Serialize

func (p *PubKey) Serialize() []byte

Serialize -- returns the compressed endcoding.

func (*PubKey) SerializeCompressed

func (p *PubKey) SerializeCompressed() []byte

SerializeCompressed -- encoding a public key in a 33-byte compressed foramt.

func (*PubKey) SerializeHybrid

func (p *PubKey) SerializeHybrid() []byte

SerializeHybrid -- encoding a public key in a 65-byte hybrid format.

func (*PubKey) SerializeUncompressed

func (p *PubKey) SerializeUncompressed() []byte

SerializeUncompressed -- encoding public key in a 65-byte uncompressed format.

func (*PubKey) XBytes

func (p *PubKey) XBytes() []byte

XBytes -- returns the x coord bytes.

func (*PubKey) YBytes

func (p *PubKey) YBytes() []byte

YBytes -- returns the y coord bytes.

type SchnorrParty

type SchnorrParty struct {
	N *big.Int
	// contains filtered or unexported fields
}

SchnorrParty -- Schnorr party struct.

func NewSchnorrParty

func NewSchnorrParty(prv *PrvKey) (*SchnorrParty, error)

NewSchnorrParty -- creates new SchnorrParty.

func (*SchnorrParty) Close

func (party *SchnorrParty) Close()

Close -- close the party.

func (*SchnorrParty) Phase1

func (party *SchnorrParty) Phase1(pub2 *PubKey) *PubKey

Phase1 -- used to generate final pubkey of parties. Return the shared PubKey.

func (*SchnorrParty) Phase2

func (party *SchnorrParty) Phase2(hash []byte) *secp256k1.Scalar

Phase2 -- used to generate k, kinv, scalarR. Return the party scalar R.

func (*SchnorrParty) Phase3

func (party *SchnorrParty) Phase3(r2 *secp256k1.Scalar) *secp256k1.Scalar

Phase3 -- return shared scalar R.

func (*SchnorrParty) Phase4

func (party *SchnorrParty) Phase4(sharePub *PubKey, shareR *secp256k1.Scalar) ([]byte, error)

Phase4 -- return the signature of this party.

func (*SchnorrParty) Phase5

func (party *SchnorrParty) Phase5(shareR *secp256k1.Scalar, sigs ...[]byte) ([]byte, error)

Phase5 -- return the final signature.

type SignatureEcdsa

type SignatureEcdsa struct {
	R *big.Int
	S *big.Int
}

SignatureEcdsa -- a type representing an ECDSA signature.

func NewSignatureEcdsa

func NewSignatureEcdsa() *SignatureEcdsa

NewSignatureEcdsa -- create new SignatureEcdsa.

func (*SignatureEcdsa) Deserialize

func (sig *SignatureEcdsa) Deserialize(sign []byte) error

Deserialize -- used to deserialize the signature to struct.

func (*SignatureEcdsa) Serialize

func (sig *SignatureEcdsa) Serialize() ([]byte, error)

Serialize -- used to serialize the struct to signature.

type SignatureSchnorr

type SignatureSchnorr struct {
	R *big.Int
	S *big.Int
}

SignatureSchnorr -- a type representing an schnorr signature.

func NewSignatureSchnorr

func NewSignatureSchnorr() *SignatureSchnorr

NewSignatureSchnorr -- create new SignatureSchnorr.

func (*SignatureSchnorr) Deserialize

func (sig *SignatureSchnorr) Deserialize(sign []byte) error

Deserialize -- used to deserialize the signature to struct.

func (*SignatureSchnorr) Serialize

func (sig *SignatureSchnorr) Serialize() ([]byte, error)

Serialize -- used to serialize the struct to signature.

Directories

Path Synopsis
Package ripemd160 implements the RIPEMD-160 hash algorithm.
Package ripemd160 implements the RIPEMD-160 hash algorithm.

Jump to

Keyboard shortcuts

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