ogcrypto

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2020 License: Apache-2.0 Imports: 28 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CRandBytes

func CRandBytes(numBytes int) []byte

This uses the OS and the Seed(s).

func CRandHex

func CRandHex(numDigits int) string

RandHex(24) gives 96 bits of randomness, strong enough for most purposes.

func CReader

func CReader() io.Reader

Returns a crand.Reader mixed with user-supplied entropy

func CompressPubkey

func CompressPubkey(pubkey *ecdsa.PublicKey) []byte

CompressPubkey encodes a public key to the 33-byte compressed format.

func DecompressPubkey

func DecompressPubkey(pubkey []byte) (*ecdsa.PublicKey, error)

DecompressPubkey parses a public key in the 33-byte compressed format.

func Ecrecover

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

Ecrecover returns the uncompressed public key that created the given signature.

func FromECDSA

func FromECDSA(priv *ecdsa.PrivateKey) []byte

FromECDSA exports a private key into a binary dump.

func FromECDSAPub

func FromECDSAPub(pub *ecdsa.PublicKey) []byte

func GenerateKey

func GenerateKey() (*ecdsa.PrivateKey, error)

func HexToECDSA

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

HexToECDSA parses a secp256k1 private key.

func Keccak256

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

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

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 Keccak512

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

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

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 S256

func S256() elliptic.Curve

S256 returns an instance of the secp256k1 curve.

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

func UnmarshalPubkey(pub []byte) (*ecdsa.PublicKey, error)

UnmarshalPubkey converts bytes to a secp256k1 public key.

func ValidateSignatureValues

func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool

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

func VerifySignature(pubkey, hash, signature []byte) bool

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 (*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 (*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 (*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 (*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 (*SignerSecp256k1) Verify

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.

Jump to

Keyboard shortcuts

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