WIP: FrostFS crypto library
Find a file
alexvanin 1461d7a248 rfc6979: Add leading zeros if r or s has less than 32 bytes
SignECDSA function returns two coordinates on elliptic curve.
Catenation of these coordinates is a 64 byte signature. If
one of these coordinates have less than 32 significant bytes, then
it should have leading zeros.
2020-03-01 16:50:38 +03:00
internal initial 2019-10-22 17:40:05 +03:00
test initial 2019-10-22 17:40:05 +03:00
ecdsa.go Fix point encoding for short X coordinate 2019-11-17 21:08:58 +03:00
ecdsa_test.go Fix point encoding for short X coordinate 2019-11-17 21:08:58 +03:00
go.mod Update RFC6979 to new release 2020-01-16 10:10:33 +03:00
go.sum Update RFC6979 to new release 2020-01-16 10:10:33 +03:00
LICENSE initial 2019-10-22 17:40:05 +03:00
load.go docs: add doc comment for LoadPrivateKey 2019-11-21 17:32:08 +03:00
load_test.go Add method to load PrivateKey 2019-11-21 17:24:36 +03:00
README.md docs: describe LoadPrivateKey in readme 2019-11-21 17:29:34 +03:00
rfc6979.go rfc6979: Add leading zeros if r or s has less than 32 bytes 2020-03-01 16:50:38 +03:00
rfc6979_test.go Change func Verify signature 2019-11-12 15:52:13 +03:00
wif.go Use consistent parameter names for Sign and Verify functions 2019-11-12 14:52:23 +03:00
wif_test.go initial 2019-10-22 17:40:05 +03:00

NeoFS Crypto library

This package contains useful methods to work with crypto-primitives, that used in NeoFS / NeoBlockchain.

Examples

Simple Marshal / Unmarshal ECDSA public key (PK):

// returns slice of 33 bytes marshaled public key
data := crypto.MarshalPublicKey(&sk.PublicKey)

// returns public key decoded from 33 bytes    
pk := crypto.UnmarshalPublicKey(data)

Simple Marshal / Unmarshal ECDSA private key (SK):

// returns slice of 32 bytes marshaled private key
data := crypto.MarshalPrivateKey(&sk)

// returns private key decoded from 32 bytes or error,
// if something whet wrong    
newSk, err := crypto.UnmarshalPrivateKey(data)

ECDSA Sign / Verify bytes using PK / SK

// Sign returns signature (slice of 65 bytes) of SK for passed message (slice of bytes),
// or error, if something went wrong:
signature, err := crypto.Sign(sk, message)

// Verify returns error message if PK is empty or
// passed wrong signature (slice of 65 bytes) for message (slice of bytes),
err := crypto.Verify(&sk.PublicKey, signature, message)  

RFC6979 Sign / Verify bytes using PK / SK

// Sign returns signature (slice of 65 bytes) of SK for passed message (slice of bytes),
// or error, if something went wrong:
signature, err := crypto.SignRFC6979(sk, message)

// Verify returns error message if PK is empty or
// passed wrong signature (slice of 65 bytes) for message (slice of bytes),
err := crypto.VerifyRFC6979(&sk.PublicKey, signature, message)  

WIF Encode / Decode private key (SK)

// WIFEncode encodes the given private key into a WIF string.
// if sk or sk.D is empty, returns error
wif, err := crypto.WIFEncode(sk)

// WIFDecode decoded the given WIF string into a private key.
// if something went wrong, returns error:
skFromWIF, err := crypto.WIFDecode(wif)

LoadPrivateKey

// Load private key from wif format
sk, err := crypto.LoadPrivateKey(wif_string)

// Load private key from hex string
sk, err := crypto.LoadPrivateKey(hex_string)

// Load private key from file
sk, err := crypto.LoadPrivateKey(file_path)