Documentation
¶
Overview ¶
Package ecdh implements the Diffie-Hellman key exchange using elliptic curves (ECDH). It directly provides ECDH implementations for the NIST curves P224, P256, P384, and Bernstein's Cruve25519.
For generic curves this implementation of ECDH only uses the x-coordinate as the computed secret.
Index ¶
- Constants
- func New() wcom.WalletBizPolicy
- func NewMixTable(kvdb db.KV) *table.Table
- type CurveParams
- type KeyExchange
- type MixRow
- type MixSignPrivateKey
- type MixSignPublicKey
- type MixSignZkSnark
- func (r *MixSignZkSnark) GenKey() (crypto.PrivKey, error)
- func (r *MixSignZkSnark) PrivKeyFromBytes(b []byte) (crypto.PrivKey, error)
- func (r *MixSignZkSnark) PubKeyFromBytes(b []byte) (crypto.PubKey, error)
- func (r *MixSignZkSnark) SignatureFromBytes(b []byte) (crypto.Signature, error)
- func (r *MixSignZkSnark) Validate(msg, pub, sig []byte) error
- type MixSignature
Examples ¶
Constants ¶
const ( // PrivacyDBVersion 隐私交易运行过程中,需要使用到钱包数据库存储的数据库版本信息的KEY值 MixDBVersion = prefix + "DBVersion" // Privacy4Addr 存储隐私交易保存账户的隐私公钥对信息的KEY值 // KEY值格式为 Privacy4Addr-账号地址 // VALUE值格式为 types.WalletAccountPrivacy, 存储隐私公钥对 Mix4Addr = prefix + "Addr" // MixPrivacyEnable = prefix + "PrivacyEnable" //current rescan notes status MixRescanStatus = prefix + "RescanStatus" MixCommitHash = prefix + "CommitHash" MixNullifier = prefix + "Nullifier" )
const ( MixSignName = "mixZkSnark" MixSignID = 6 )
const CECBLOCKSIZE = 32
const LENNULLKEY = 10
空的公钥字符为“0”,不是空,这里多设置了长度
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CurveParams ¶
type CurveParams struct { Name string // the canonical name of the curve BitSize int // the size of the underlying field }
CurveParams contains the parameters of an elliptic curve.
type KeyExchange ¶
type KeyExchange interface { // GenerateKey generates a private/public key pair using entropy from rand. // If rand is nil, crypto/rand.Reader will be used. GenerateKey(rand io.Reader) (private crypto.PrivateKey, public crypto.PublicKey, err error) // Params returns the curve parameters - like the field size. Params() CurveParams // PublicKey returns the public key corresponding to the given private one. PublicKey(private crypto.PrivateKey) (public crypto.PublicKey) // Check returns a non-nil error if the peers public key cannot used for the // key exchange - for instance the public key isn't a point on the elliptic curve. // It's recommended to check peer's public key before computing the secret. Check(peersPublic crypto.PublicKey) (err error) // ComputeSecret returns the secret value computed from the given private key // and the peers public key. ComputeSecret(private crypto.PrivateKey, peersPublic crypto.PublicKey) (secret []byte) }
KeyExchange is the interface defining all functions necessary for ECDH.
func X25519 ¶
func X25519() KeyExchange
X25519 creates a new ecdh.KeyExchange with the elliptic curve Curve25519.
Example ¶
An example for the ECDH key-exchange using Curve25519.
c25519 := X25519() privateAlice, publicAlice, err := c25519.GenerateKey(rand.Reader) if err != nil { fmt.Printf("Failed to generate Alice's private/public key pair: %s\n", err) } privateBob, publicBob, err := c25519.GenerateKey(rand.Reader) if err != nil { fmt.Printf("Failed to generate Bob's private/public key pair: %s\n", err) } if err := c25519.Check(publicBob); err != nil { fmt.Printf("Bob's public key is not on the curve: %s\n", err) } secretAlice := c25519.ComputeSecret(privateAlice, publicBob) if err := c25519.Check(publicAlice); err != nil { fmt.Printf("Alice's public key is not on the curve: %s\n", err) } secretBob := c25519.ComputeSecret(privateBob, publicAlice) if !bytes.Equal(secretAlice, secretBob) { fmt.Printf("key exchange failed - secret X coordinates not equal\n") }
Output:
type MixRow ¶
type MixRow struct {
*mix.WalletDbMixInfo
}
MixRow table meta 结构
type MixSignPrivateKey ¶
type MixSignPrivateKey struct {
// contains filtered or unexported fields
}
RingSignPrivateKey 环签名中对于crypto.PrivKey接口实现
func (*MixSignPrivateKey) Bytes ¶
func (privkey *MixSignPrivateKey) Bytes() []byte
Bytes convert key to bytest
func (*MixSignPrivateKey) Equals ¶
func (privkey *MixSignPrivateKey) Equals(other crypto.PrivKey) bool
Equals check key equal
func (*MixSignPrivateKey) PubKey ¶
func (privkey *MixSignPrivateKey) PubKey() crypto.PubKey
PubKey convert to public key
type MixSignPublicKey ¶
type MixSignPublicKey struct {
// contains filtered or unexported fields
}
RingSignPublicKey 环签名中对于crypto.PubKey接口实现
func (*MixSignPublicKey) Bytes ¶
func (pubkey *MixSignPublicKey) Bytes() []byte
Bytes convert key to bytes
func (*MixSignPublicKey) Equals ¶
func (pubkey *MixSignPublicKey) Equals(other crypto.PubKey) bool
Equals check key is equal
func (*MixSignPublicKey) KeyString ¶
func (pubkey *MixSignPublicKey) KeyString() string
KeyString convert key to string
func (*MixSignPublicKey) VerifyBytes ¶
func (pubkey *MixSignPublicKey) VerifyBytes(msg []byte, sign crypto.Signature) bool
VerifyBytes verify bytes
type MixSignZkSnark ¶
type MixSignZkSnark struct { }
MixSignZkSnark 对应crypto.Crypto的接口实现
func (*MixSignZkSnark) GenKey ¶
func (r *MixSignZkSnark) GenKey() (crypto.PrivKey, error)
GenKey create privacy key
func (*MixSignZkSnark) PrivKeyFromBytes ¶
func (r *MixSignZkSnark) PrivKeyFromBytes(b []byte) (crypto.PrivKey, error)
PrivKeyFromBytes create private key from bytes
func (*MixSignZkSnark) PubKeyFromBytes ¶
func (r *MixSignZkSnark) PubKeyFromBytes(b []byte) (crypto.PubKey, error)
PubKeyFromBytes create publick key from bytes
func (*MixSignZkSnark) SignatureFromBytes ¶
func (r *MixSignZkSnark) SignatureFromBytes(b []byte) (crypto.Signature, error)
SignatureFromBytes create signature from bytes
func (*MixSignZkSnark) Validate ¶
func (r *MixSignZkSnark) Validate(msg, pub, sig []byte) error
Validate validate msg and signature
type MixSignature ¶
type MixSignature struct {
// contains filtered or unexported fields
}
MixSignature mix签名中对于crypto.Signature接口实现