crypto

package
v1.9.11 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 20 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// SEED_TEST_STRING ...
	SEED_TEST_STRING = "e5dcc2bdf7310ea3abc82a3580621bd0a487c181113d889d0775d3f8eba21e84"

	// IDKEY_TEST_STRING ...
	IDKEY_TEST_STRING = "68403eeafc1431eb85aabd250480752b3950f50463023a42f4d4d3b301544451"

	// PATH_1_STRING ...
	PATH_1_STRING = "m/0'/0/0"

	// PUBLIC_DECOMPRESSED_KEY_1_STRING ...
	PUBLIC_DECOMPRESSED_KEY_1_STRING = "" /* 130-byte string literal not displayed */

	// PUBLIC_COMPRESSED_KEY_1_STRING ...
	PUBLIC_COMPRESSED_KEY_1_STRING = "03e315a987bd79b9f49d3a1c8bd1ef5a401a242820d52a3f22505da81dfcd992cc"

	// SECRET_KEY_1_STRING ...
	SECRET_KEY_1_STRING = "b9fc3b425d6c1745b9c963c97e6e1d4c1db7a093a36e0cf7c0bf85dc1130b8a0"
)

Variables

This section is empty.

Functions

func Check

func Check(signature []byte, msg []byte, decompressedPublicKey []byte) bool

Check verifies the validity of the signature of a given content with a public key.

It takes the signature, the content that was signed and the decompressed public key to use as arguments and returns true if it checks out. It's the verifying counterpart of the Sig() function. Therefore, as of the latest version, it takes an ECDSA signature in 64-byte [R||S] format and its associated decompressed public key in byte array and hashes the content message with the system's Hash() function before using it.

func Decrypt

func Decrypt(ciphered, privateKey, decompressedPublicKey []byte) ([]byte, error)

Decrypt recovers data encrypted with ECIES algorithm using the private key and the decompressed public key TODO Try not to use the public key, only the private

func ECDSAPrivateKeyFrom

func ECDSAPrivateKeyFrom(privateKeyBytes, publicKeyBytes []byte) (sk ecdsa.PrivateKey, err error)

ECDSAPrivateKeyFrom ...

func ECDSAPublicKeyFrom

func ECDSAPublicKeyFrom(publicKeyBytes []byte) (pk ecdsa.PublicKey, err error)

ECDSAPublicKeyFrom ...

func ECIESKeyPairFrom

func ECIESKeyPairFrom(ecdsaPublicKBytes, ecdsaPrivateKBytes []byte) (pubkey ecies.PublicKey, privkey ecies.PrivateKey, err error)

ECIESKeyPairFrom transforms an ECDSA keypair in byte array to its ECIES counterparts.

It takes a keypair in byte array and returns the ECIES PublicKey and PrivateKey objects, and an error if something went wrong. Keys generated through the GenerateKeyPair() function should be compatible.

func Encrypt

func Encrypt(msg, decompressedPublicKey []byte) ([]byte, error)

Encrypt uses ECIES algorithm to encrypt a message with a decompressed public key

func GenerateKeyPair

func GenerateKeyPair(seed []byte, path Path) (pubkey, privkey []byte, err error)

GenerateKeyPair is the function that should be used whenever a keypair is needed in the Rooot project.

It takes a seed (ie. the master key in Rooot) and a BIP-32 path, and returns a keypair in byte array, decompressed public and private, and an error if any. As of the latest version in the system, this keypair operates on Bitcoin's secp256k1 elliptic curve. It shall be used for either signing with ECDSA or encrypting/decrypting with ECIES. One should use the utils.ToHex() utility method to save any of these byte arrays as their hexadecimal string representation if needed.

func GenerateRandomKeyPair

func GenerateRandomKeyPair() (pubkey, privkey []byte, err error)

GenerateRandomKeyPair generates a random keypair

func Hash

func Hash(input []byte) ([]byte, error)

Hash is the hashing function that should be used whenever hashing in the Rooot™ project.

It takes a byte array as argument and returns a byte array and an error if any. As of the latest version of the system, it double-hashes any input string with the SHA256 standard algorithm. One should use the utils.ToHex() utility method to save the byte array as its hexadecimal string representation.

func ImportSignature

func ImportSignature(input []byte) (signature []byte, err error)

ImportSignature parses a DER ECDSA signature as in `ecies-geth` JavaScript module to produce the appropriate 64-byte [R||S] signature @see https://github.com/cryptocoinjs/secp256k1-node/blob/90a04a2e1127f4c1bfd7015aa5a7b22d08edb811/lib/elliptic.js

func IsCompatibleKeyPair

func IsCompatibleKeyPair(pk, sk []byte) bool

IsCompatibleKeyPair tests whether a decompressed public key and a private key form an actual valid keypair.

func IsHashedValue

func IsHashedValue(str string) bool

IsHashedValue ...

func ParsePrivateKey

func ParsePrivateKey(base58PrivateKey string) (pubkey []byte, err error)

ParsePrivateKey ...

func ParsePublicKey

func ParsePublicKey(base58PublicKey string) (pubkey []byte, err error)

ParsePublicKey ...

func ParsePublicKeyFromCompressed

func ParsePublicKeyFromCompressed(str string) (pubkey []byte, err error)

ParsePublicKeyFromCompressed ...

func SSHPublicKey2String added in v1.4.12

func SSHPublicKey2String(pk ssh.PublicKey) string

SSHPublicKey2String returns the stringified version of the passed SSH public key

func Sign

func Sign(msg []byte, secretKey []byte) ([]byte, error)

Sign signs a content using secp256k1 elliptic curve.

It takes the content to sign and the secret key to use as arguments and returns the signature and an error if any. As of the latest version of the system, it first hashes the content message with the system's Hash() function, then signs it using Bitcoin's secp256k1 elliptic curve that returns a recoverable ECDSA signature in 65-byte [R||S||V] format, and finally gets rid of the recovery 65th byte (the V).

Types

type Account

type Account struct {
	Number   uint32
	Hardened bool
}

Account ...

type BIP32PrivateKey added in v1.8.0

type BIP32PrivateKey struct {
	BIP32PublicKey
	Data    []byte
	Version []byte
}

BIP32PrivateKey houses all the information of an extended private key.

type BIP32PublicKey added in v1.8.0

type BIP32PublicKey struct {
	ChainCode  []byte
	ChildIndex uint32 // this is the Index-th child of its parent
	Data       []byte // the serialized data in the compressed form
	Level      uint8  // name so to avoid conflict with method Depth()
	ParentFP   []byte
	Version    []byte
}

BIP32PublicKey is the structure layout for an extended public key.

type Indices

type Indices struct {
	Account  Account
	Scope    uint32
	KeyIndex uint32
}

Indices ...

type Path

type Path string

Path is the string representation of a BIP32 path, eg. `m/0'/0/0`. NB: For compatibility reasons with browsers, the account number and the scope mustn't be greater than 2^16 - 1 and the key index not greater than 2^21 - 1.

func (Path) Bytes added in v1.3.10

func (p Path) Bytes() []byte

Bytes ...

func (Path) IsEmpty added in v1.3.10

func (p Path) IsEmpty() bool

IsEmpty ...

func (Path) Next added in v1.3.10

func (p Path) Next() (newPath Path, err error)

Next builds the next path, eventually moving up the account number and/or the scope, eg.

Path("m/0'/65535/2097151").Next() = Path("m/1'/0/0")

func (Path) NonEmpty added in v1.3.10

func (p Path) NonEmpty() bool

IsEmpty ...

func (Path) Parse

func (p Path) Parse() (i Indices, err error)

Parse ...

func (Path) String added in v1.3.10

func (p Path) String() string

String ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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