[ad_1]
This Go package provides the necessary cryptography tools for the Flow blockchain. Most primitives and protocols can be used in other projects and are not specific to Flow.
Flow is an ongoing project, which means new features will always be added and changes will always be made to improve the security and performance of the crypto package.
Remarks:
The package was audited for security in January 2021 on this version. The package has had some improvements since. The package does not provide security against side-channel or default attacks. Import of parcels
Cloning the Flow repository and following the installation steps generates the tools needed to use Flow cryptography.
If you want to import only the Flow encryption package into your Go project, please follow these steps:
Get the Flow crypto package, go to github.com/onflow/crypto
or just import the package into your Go project
import “github.com/onflow/crypto”
This is enough to run the package code for many features. However, this is not enough if BLS signature related features are used. BLS functionality relies on an external C library (Relic) for lower-level mathematical operations. Building your project at this stage, including BLS features, would result in build errors related to missing “relic” files. For example:
fatal error: file ‘relic.h’ not found #include “relic.h” ^~~~~~~~~
An extra step is required to compile the external dependency (Relic) locally.
Install CMake, which is used to build the package. The build also requires Git and bash scripts. From the Go package directory in $GOPATH/pkg/mod/github.com/onflow/crypto@
Below is an example bash script to automate the above steps. The script can be copied to the root directory of your Go project. It extracts the imported package version from your project’s go.mod file and performs the remaining steps.
#!/bin/bash # crypto package PKG_NAME=”github.com/onflow/crypto” # fetch the package fetch ${PKG_NAME} # go.mod MOD_FILE=”./go.mod” # the onflow version /crypto used in the project is read from the go.mod file if [ -f “${MOD_FILE}” ]
then # extract file version go.mod VERSION=”$(grep ${PKG_NAME} < ${MOD_FILE} | cut -d' ' -f 2)" # using correct version, get package directory path PKG_DIR= "$(go env GOPATH)/pkg/mod/${PKG_NAME}@${VERSION}" else { echo "Could not find go.mod file - make sure the script is in the root directory of the project"; output 1; } fi # grant permissions if they don't exist if [[ ! -r ${PKG_DIR} || ! -w ${PKG_DIR} || ! -x ${PKG_DIR} ]]; then sudo chmod -R 755 "${PKG_DIR}" fi # navigate to package directory and set up external dependencies ( cd "${PKG_DIR}" || { echo "cd failed to GOPATH package folder"; exit 1 ; } go generate )
Finally, when building your project and including any BLS functionality, adding a Go build tag to include BLS files in the build is required. The tag is not required when the package is used without BLS functions. It was introduced to avoid build errors when BLS (and therefore Relic) is not needed.
Algorithms hash and message authentication code:
crypto/hash provides the hash and MAC algorithms required for Flow. All algorithms implement the generic Hasher interface. All digests are of the generic Hash type.
SHA-3: 256 and 384 output sizes Legacy Kaccak: 256 output sizes SHA-2: 256 and 384 output sizes KMAC: 128 variants Signature schemes
All signing schemes use the generic interfaces of PrivateKey and PublicKey. All signatures are of the generic type Signature.
ECDSA
the public keys are compressed or not. The ephemeral key is derived from the private key, hash, and external entropy using a CSPRNG (based on https://golang.org/pkg/crypto/ecdsa/). supports NIST P-256 (secp256r1) and secp256k1 curves.
BLS
supports BLS 12-381 curve. implements the minimum signature size variant: signatures in G1 and public keys in G2. the default configuration uses compressed G1/G2 points, but the uncompressed format is also supported. the hash to curve uses the map to simplified SWU curve. message expansion in the hash curve uses a cSHAKE-based KMAC128 with a domain separator tag. KMAC128 serves as an expand_message_xof function. this translates to the full cipher suite BLS_SIG_BLS12381G1_XOF:KMAC128_SSWU_RO_POP_ for signatures and BLS_POP_BLS12381G1_XOF:KMAC128_SSWU_RO_POP_ for proofs of possession. signature verification includes verification of signature adherence in G1. Verification of public key membership in G2 is provided apart from signature verification. membership check in G1 uses Bowe’s fast check, while membership check in G2 uses simple scalar multiplication by group order (both will be updated to use Scott’s method) aggregation no interactive signatures, public keys and private keys. multi-signature verification of an aggregated signature of a single message under multiple public keys. multi-signature verification of an aggregated signature of multiple messages under multiple public keys. batch verification of multiple signatures of the same message under multiple public keys: use a binary tree of aggregations to find invalid signatures. BLS-based SPoCK scheme: verifies that two signatures were generated from the same message unknown to the verifier.
Future features:
Membership checks in G1/G2 using Scotts method. support for minimum pub key size variants PRNG protocols Threshold signing Distributed key generation based on discrete log
All supported distributed key generation protocols are discrete log based and are implemented for the same BLS configuration on the BLS 12-381 curve. Protocols generate sets of keys for BLS-based threshold signing.
Feldman VSS simple verifiable secret sharing with a single reseller. the library does not implement communication channels between participants. Caller must implement PrivateSend (1-to-1 messaging) and Broadcast (1-to-n messaging) methods 1-to-1 messaging must be a private channel, caller must ensure that the channel preserves confidentiality and authenticates the sender. 1-to-n broadcast assumes that all recipient participants receive the same copy of the message. The channel must also authenticate the broadcaster. It is recommended that the two communication channels be unique per protocol instance. This could be achieved by appending messages to be sent/broadcasted with a unique protocol instance ID. Feldman VSS Qual. an extension of the simple Feldman VSS. implements a complaint mechanism to qualify/disqualify the reseller. Joint distributed generation Feldman (Pedersen). based on multiple parallel instances of Feldman VSS Qual with multiple dealerships. same assumptions about communication channels as in Feldman VSS.
|
Sources 2/ https://github.com/onflow/crypto The mention sources can contact us to remove/changing this article |
[ad_2]