Documentation ¶
Overview ¶
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- func CRandBytes(numBytes int) []byte
- func CRandHex(numDigits int) string
- func CReader() io.Reader
- func CompressPubkey(pubkey *ecdsa.PublicKey) []byte
- func DecompressPubkey(pubkey []byte) (*ecdsa.PublicKey, error)
- func Ecrecover(hash, sig []byte) ([]byte, error)
- func FromECDSA(priv *ecdsa.PrivateKey) []byte
- func FromECDSAPub(pub *ecdsa.PublicKey) []byte
- func GenerateKey() (*ecdsa.PrivateKey, error)
- func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error)
- func Keccak256(data ...[]byte) []byte
- func Keccak256Hash(data ...[]byte) (h og_interface.Hash)
- func Keccak512(data ...[]byte) []byte
- func LoadECDSA(file string) (*ecdsa.PrivateKey, error)
- func MixEntropy(seedBytes []byte)
- func S256() elliptic.Curve
- func SaveECDSA(file string, key *ecdsa.PrivateKey) error
- func Sign(hash []byte, prv *ecdsa.PrivateKey) ([]byte, error)
- func ToECDSA(d []byte) (*ecdsa.PrivateKey, error)
- func ToECDSAUnsafe(d []byte) *ecdsa.PrivateKey
- func UnmarshalPubkey(pub []byte) (*ecdsa.PublicKey, error)
- func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool
- func VerifySignature(pubkey, hash, signature []byte) bool
- type SignerEd25519
- func (s *SignerEd25519) CanRecoverPubFromSig() bool
- func (s *SignerEd25519) Decrypt(p ogcrypto_interface.PrivateKey, ct []byte) (m []byte, err error)
- func (s *SignerEd25519) Encrypt(publicKey ogcrypto_interface.PublicKey, m []byte) (ct []byte, err error)
- func (s *SignerEd25519) GetCryptoType() ogcrypto_interface.CryptoType
- func (s *SignerEd25519) PubKey(privKey ogcrypto_interface.PrivateKey) ogcrypto_interface.PublicKey
- func (s *SignerEd25519) PublicKeyFromBytes(b []byte) ogcrypto_interface.PublicKey
- func (s *SignerEd25519) RandomKeyPair() (publicKey ogcrypto_interface.PublicKey, ...)
- func (s *SignerEd25519) Sign(privKey ogcrypto_interface.PrivateKey, msg []byte) ogcrypto_interface.Signature
- func (s *SignerEd25519) Verify(pubKey ogcrypto_interface.PublicKey, signature ogcrypto_interface.Signature, ...) bool
- type SignerSecp256k1
- func (s *SignerSecp256k1) CanRecoverPubFromSig() bool
- func (s *SignerSecp256k1) DealRecoverID(sig ogcrypto_interface.Signature) ogcrypto_interface.Signature
- func (s *SignerSecp256k1) Decrypt(p ogcrypto_interface.PrivateKey, ct []byte) (m []byte, err error)
- func (s *SignerSecp256k1) Encrypt(p ogcrypto_interface.PublicKey, m []byte) (ct []byte, err error)
- func (s *SignerSecp256k1) GetCryptoType() ogcrypto_interface.CryptoType
- func (s *SignerSecp256k1) PubKey(privKey ogcrypto_interface.PrivateKey) ogcrypto_interface.PublicKey
- func (s *SignerSecp256k1) PublicKeyFromBytes(b []byte) ogcrypto_interface.PublicKey
- func (s *SignerSecp256k1) RandomKeyPair() (publicKey ogcrypto_interface.PublicKey, ...)
- func (s *SignerSecp256k1) Sign(privKey ogcrypto_interface.PrivateKey, msg []byte) ogcrypto_interface.Signature
- func (s *SignerSecp256k1) Verify(pubKey ogcrypto_interface.PublicKey, signature ogcrypto_interface.Signature, ...) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompressPubkey ¶
CompressPubkey encodes a public key to the 33-byte compressed format.
func DecompressPubkey ¶
DecompressPubkey parses a public key in the 33-byte compressed format.
func FromECDSA ¶
func FromECDSA(priv *ecdsa.PrivateKey) []byte
FromECDSA exports a private key into a binary dump.
func FromECDSAPub ¶
func GenerateKey ¶
func GenerateKey() (*ecdsa.PrivateKey, error)
func HexToECDSA ¶
func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error)
HexToECDSA parses a secp256k1 private key.
func Keccak256Hash ¶
func Keccak256Hash(data ...[]byte) (h og_interface.Hash)
Keccak256Hash calculates and returns the Keccak256 hash of the input data, converting it to an internal Hash data structure.
func LoadECDSA ¶
func LoadECDSA(file string) (*ecdsa.PrivateKey, error)
LoadECDSA loads a secp256k1 private key from the given file.
func MixEntropy ¶
func MixEntropy(seedBytes []byte)
Mix additional bytes of randomness, e.g. from hardware, user-input, etc. It is OK to call it multiple times. It does not diminish security.
func SaveECDSA ¶
func SaveECDSA(file string, key *ecdsa.PrivateKey) error
SaveECDSA saves a secp256k1 private key to the given file with restrictive permissions. The key data is saved hex-encoded.
func Sign ¶
func Sign(hash []byte, prv *ecdsa.PrivateKey) ([]byte, error)
Sign calculates an ECDSA signature.
This function is susceptible to chosen plaintext attacks that can leak information about the private key that is used for signing. Callers must be aware that the given hash cannot be chosen by an adversery. Common solution is to hash any input before calculating the signature.
The produced signature is in the [R || S || V] format where V is 0 or 1.
func ToECDSA ¶
func ToECDSA(d []byte) (*ecdsa.PrivateKey, error)
ToECDSA creates a private key with the given D value.
func ToECDSAUnsafe ¶
func ToECDSAUnsafe(d []byte) *ecdsa.PrivateKey
ToECDSAUnsafe blindly converts a binary blob to a private key. It should almost never be used unless you are sure the input is valid and want to avoid hitting errors due to bad origin encoding (0 prefixes cut off).
func UnmarshalPubkey ¶
UnmarshalPubkey converts bytes to a secp256k1 public key.
func ValidateSignatureValues ¶
ValidateSignatureValues verifies whether the signature values are valid with the given chain rules. The v value is assumed to be either 0 or 1.
func VerifySignature ¶
VerifySignature checks that the given public key created signature over hash. The public key should be in compressed (33 bytes) or uncompressed (65 bytes) format. The signature should have the 64 byte [R || S] format.
Types ¶
type SignerEd25519 ¶
type SignerEd25519 struct { }
func (*SignerEd25519) CanRecoverPubFromSig ¶
func (s *SignerEd25519) CanRecoverPubFromSig() bool
func (*SignerEd25519) Decrypt ¶
func (s *SignerEd25519) Decrypt(p ogcrypto_interface.PrivateKey, ct []byte) (m []byte, err error)
func (*SignerEd25519) Encrypt ¶
func (s *SignerEd25519) Encrypt(publicKey ogcrypto_interface.PublicKey, m []byte) (ct []byte, err error)
func (*SignerEd25519) GetCryptoType ¶
func (s *SignerEd25519) GetCryptoType() ogcrypto_interface.CryptoType
func (*SignerEd25519) PubKey ¶
func (s *SignerEd25519) PubKey(privKey ogcrypto_interface.PrivateKey) ogcrypto_interface.PublicKey
func (*SignerEd25519) PublicKeyFromBytes ¶
func (s *SignerEd25519) PublicKeyFromBytes(b []byte) ogcrypto_interface.PublicKey
func (*SignerEd25519) RandomKeyPair ¶
func (s *SignerEd25519) RandomKeyPair() (publicKey ogcrypto_interface.PublicKey, privateKey ogcrypto_interface.PrivateKey)
func (*SignerEd25519) Sign ¶
func (s *SignerEd25519) Sign(privKey ogcrypto_interface.PrivateKey, msg []byte) ogcrypto_interface.Signature
func (*SignerEd25519) Verify ¶
func (s *SignerEd25519) Verify(pubKey ogcrypto_interface.PublicKey, signature ogcrypto_interface.Signature, msg []byte) bool
type SignerSecp256k1 ¶
type SignerSecp256k1 struct { }
func (*SignerSecp256k1) CanRecoverPubFromSig ¶
func (s *SignerSecp256k1) CanRecoverPubFromSig() bool
func (*SignerSecp256k1) DealRecoverID ¶
func (s *SignerSecp256k1) DealRecoverID(sig ogcrypto_interface.Signature) ogcrypto_interface.Signature
func (*SignerSecp256k1) Decrypt ¶
func (s *SignerSecp256k1) Decrypt(p ogcrypto_interface.PrivateKey, ct []byte) (m []byte, err error)
func (*SignerSecp256k1) Encrypt ¶
func (s *SignerSecp256k1) Encrypt(p ogcrypto_interface.PublicKey, m []byte) (ct []byte, err error)
func (*SignerSecp256k1) GetCryptoType ¶
func (s *SignerSecp256k1) GetCryptoType() ogcrypto_interface.CryptoType
func (*SignerSecp256k1) PubKey ¶
func (s *SignerSecp256k1) PubKey(privKey ogcrypto_interface.PrivateKey) ogcrypto_interface.PublicKey
func (*SignerSecp256k1) PublicKeyFromBytes ¶
func (s *SignerSecp256k1) PublicKeyFromBytes(b []byte) ogcrypto_interface.PublicKey
func (*SignerSecp256k1) RandomKeyPair ¶
func (s *SignerSecp256k1) RandomKeyPair() (publicKey ogcrypto_interface.PublicKey, privateKey ogcrypto_interface.PrivateKey)
func (*SignerSecp256k1) Sign ¶
func (s *SignerSecp256k1) Sign(privKey ogcrypto_interface.PrivateKey, msg []byte) ogcrypto_interface.Signature
func (*SignerSecp256k1) Verify ¶
func (s *SignerSecp256k1) Verify(pubKey ogcrypto_interface.PublicKey, signature ogcrypto_interface.Signature, msg []byte) bool
Directories ¶
Path | Synopsis |
---|---|
Package edwards25519 implements operations in GF(2**255-19) and on an Edwards curve that is isomorphic to curve25519.
|
Package edwards25519 implements operations in GF(2**255-19) and on an Edwards curve that is isomorphic to curve25519. |
Package secp256k1 wraps the bitcoin secp256k1 C library.
|
Package secp256k1 wraps the bitcoin secp256k1 C library. |