Kagome
Polkadot Runtime Engine in C++17
kagome::crypto Namespace Reference

Namespaces

 bip39
 
 constants
 
 secp256k1
 

Classes

class  Bip39Provider
 
class  Bip39ProviderImpl
 
struct  blake2b_ctx
 
struct  blake2s_ctx
 
struct  blake2s_ctx_full
 
class  CryptoStore
 
class  CryptoStoreImpl
 
struct  CryptoSuite
 
class  DevMnemonicPhrase
 
struct  EcdsaKeypair
 
struct  EcdsaKeypairAndSeed
 
class  EcdsaProvider
 
class  EcdsaProviderImpl
 
class  EcdsaSuite
 
struct  Ed25519Keypair
 
struct  Ed25519KeypairAndSeed
 
class  Ed25519Provider
 
class  Ed25519ProviderImpl
 
class  Ed25519Suite
 
class  Hasher
 
class  HasherImpl
 
class  KeyCache
 
class  KeyFileStorage
 
class  Pbkdf2Provider
 
class  Pbkdf2ProviderImpl
 
class  Secp256k1Provider
 
class  Secp256k1ProviderImpl
 
class  SessionKeys
 
struct  Sr25519Keypair
 
struct  Sr25519KeypairAndSeed
 
class  Sr25519Provider
 
class  Sr25519ProviderImpl
 
class  Sr25519Suite
 
struct  VRFOutput
 
class  VRFProvider
 
class  VRFProviderImpl
 
struct  VRFVerifyOutput
 

Typedefs

using KeyTypeId = uint32_t
 Key type identifier. More...
 
using EcdsaSignature = std::vector< uint8_t >
 
using EcdsaSeed = common::Blob< constants::ecdsa::SEED_SIZE >
 
using EcdsaPrehashedMessage = libp2p::crypto::ecdsa::PrehashedMessage
 
using BoostRandomGenerator = libp2p::crypto::random::BoostRandomGenerator
 
using CSPRNG = libp2p::crypto::random::CSPRNG
 
using RandomGenerator = libp2p::crypto::random::RandomGenerator
 
using VRFPreOutput = std::array< uint8_t, constants::sr25519::vrf::OUTPUT_SIZE >
 
using VRFThreshold = boost::multiprecision::uint128_t
 
using VRFProof = std::array< uint8_t, constants::sr25519::vrf::PROOF_SIZE >
 

Enumerations

enum  CryptoStoreError {
  CryptoStoreError::UNSUPPORTED_KEY_TYPE = 1, CryptoStoreError::UNSUPPORTED_CRYPTO_TYPE, CryptoStoreError::WRONG_SEED_SIZE, CryptoStoreError::KEY_NOT_FOUND,
  CryptoStoreError::BABE_ALREADY_EXIST, CryptoStoreError::GRAN_ALREADY_EXIST, CryptoStoreError::AUDI_ALREADY_EXIST, CryptoStoreError::WRONG_PUBLIC_KEY
}
 
enum  KeyTypeError { KeyTypeError::UNSUPPORTED_KEY_TYPE = 1, KeyTypeError::UNSUPPORTED_KEY_TYPE_ID }
 
enum  KnownKeyTypeId : KeyTypeId {
  KEY_TYPE_BABE = 0x65626162u, KEY_TYPE_GRAN = 0x6e617267u, KEY_TYPE_ACCO = 0x6f636361u, KEY_TYPE_IMON = 0x6e6f6d69u,
  KEY_TYPE_AUDI = 0x69647561u, KEY_TYPE_LP2P = 0x7032706cu, KEY_TYPE_ASGN = 0x6e677361u, KEY_TYPE_PARA = 0x61726170u
}
 
enum  Pbkdf2ProviderError { Pbkdf2ProviderError::KEY_DERIVATION_FAILED = 1 }
 
enum  Secp256k1ProviderError {
  Secp256k1ProviderError::INVALID_ARGUMENT = 1, Secp256k1ProviderError::INVALID_V_VALUE, Secp256k1ProviderError::INVALID_R_OR_S_VALUE, Secp256k1ProviderError::INVALID_SIGNATURE,
  Secp256k1ProviderError::RECOVERY_FAILED
}
 
enum  Sr25519ProviderError { Sr25519ProviderError::SIGN_UNKNOWN_ERROR = 1, Sr25519ProviderError::VERIFY_UNKNOWN_ERROR }
 

Functions

static void blake2b_compress (blake2b_ctx *ctx, int last)
 
int blake2b_init (blake2b_ctx *ctx, size_t outlen, const void *key, size_t keylen)
 
void blake2b_update (blake2b_ctx *ctx, const void *in, size_t inlen)
 
void blake2b_final (blake2b_ctx *ctx, void *out)
 
int blake2b (void *out, size_t outlen, const void *key, size_t keylen, const void *in, size_t inlen)
 
static void blake2s_compress (blake2s_ctx_full *ctx, int last)
 
void blake2s_update (blake2s_ctx *ctx, const void *in, size_t inlen)
 Update context with incoming bytes. More...
 
void blake2s_final (blake2s_ctx *ctx, void *out)
 Finalize hash calculation. More...
 
int blake2s_init (blake2s_ctx *ctx, size_t outlen, const void *key, size_t keylen)
 Generic blake2s init function. More...
 
int blake2s (void *out, size_t outlen, const void *key, size_t keylen, const void *in, size_t inlen)
 All in one blake2s hashing function. More...
 
void blake2s_256_init (blake2s_ctx *ctx)
 Initialize hash context. More...
 
void blake2s_256 (void *out, const void *in, size_t inlen)
 One-shot convenience function to calculate blake2s_256 hash. More...
 
libp2p::crypto::KeyPair ed25519KeyToLibp2pKeypair (const Ed25519Keypair &kp)
 
bool isSupportedKeyType (KeyTypeId k)
 checks whether key type value is supported More...
 
std::string encodeKeyTypeIdToStr (KeyTypeId key_type_id)
 makes string representation of KeyTypeId More...
 
KeyTypeId decodeKeyTypeIdFromStr (std::string_view str)
 restores KeyTypeId from its string representation More...
 
outcome::result< int > validateRecoveryId (int v)
 
common::Hash256 sha256 (std::string_view input)
 
common::Hash256 sha256 (gsl::span< const uint8_t > input)
 
void make_twox64 (const uint8_t *in, uint32_t len, uint8_t *out)
 
common::Hash64 make_twox64 (gsl::span< const uint8_t > buf)
 
void make_twox128 (const uint8_t *in, uint32_t len, uint8_t *out)
 
common::Hash128 make_twox128 (gsl::span< const uint8_t > buf)
 
void make_twox256 (const uint8_t *in, uint32_t len, uint8_t *out)
 
common::Hash256 make_twox256 (gsl::span< const uint8_t > buf)
 

Variables

static const uint64_t blake2b_iv [8]
 
static const uint32_t blake2s_iv [8]
 
constexpr KnownKeyTypeId polkadot_key_order [6]
 

Detailed Description

Copyright Soramitsu Co., Ltd. All Rights Reserved. SPDX-License-Identifier: Apache-2.0


Class Documentation

struct kagome::crypto::blake2b_ctx

Definition at line 18 of file blake2b.h.

Collaboration diagram for kagome::crypto::blake2b_ctx:
Class Members
uint8_t b[128]
size_t c
uint64_t h[8]
size_t outlen
uint64_t t[2]
struct kagome::crypto::blake2s_ctx

Definition at line 16 of file blake2s.h.

Collaboration diagram for kagome::crypto::blake2s_ctx:
Class Members
unsigned char opaque[128]
struct kagome::crypto::blake2s_ctx_full

Definition at line 29 of file blake2s.cpp.

Collaboration diagram for kagome::crypto::blake2s_ctx_full:
Class Members
uint8_t b[64]
size_t c
uint32_t h[8]
size_t outlen
uint32_t t[2]
struct kagome::crypto::VRFVerifyOutput

Output of a verifiable random function verification.

Definition at line 67 of file sr25519_types.hpp.

Collaboration diagram for kagome::crypto::VRFVerifyOutput:
Class Members
bool is_less
bool is_valid

Typedef Documentation

using kagome::crypto::BoostRandomGenerator = typedef libp2p::crypto::random::BoostRandomGenerator

Definition at line 13 of file boost_generator.hpp.

typedef libp2p::crypto::random::CSPRNG kagome::crypto::CSPRNG

Definition at line 14 of file boost_generator.hpp.

using kagome::crypto::EcdsaPrehashedMessage = typedef libp2p::crypto::ecdsa::PrehashedMessage

Definition at line 45 of file ecdsa_types.hpp.

using kagome::crypto::EcdsaSignature = typedef std::vector<uint8_t>

Definition at line 43 of file ecdsa_types.hpp.

using kagome::crypto::KeyTypeId = typedef uint32_t

Key type identifier.

Definition at line 21 of file key_type.hpp.

using kagome::crypto::RandomGenerator = typedef libp2p::crypto::random::RandomGenerator

Definition at line 12 of file random_generator.hpp.

Definition at line 45 of file sr25519_types.hpp.

using kagome::crypto::VRFProof = typedef std::array<uint8_t, constants::sr25519::vrf::PROOF_SIZE>

Definition at line 47 of file sr25519_types.hpp.

using kagome::crypto::VRFThreshold = typedef boost::multiprecision::uint128_t

Definition at line 46 of file sr25519_types.hpp.

Enumeration Type Documentation

Enumerator
UNSUPPORTED_KEY_TYPE 
UNSUPPORTED_CRYPTO_TYPE 
WRONG_SEED_SIZE 
KEY_NOT_FOUND 
BABE_ALREADY_EXIST 
GRAN_ALREADY_EXIST 
AUDI_ALREADY_EXIST 
WRONG_PUBLIC_KEY 

Definition at line 26 of file crypto_store_impl.hpp.

Enumerator
UNSUPPORTED_KEY_TYPE 
UNSUPPORTED_KEY_TYPE_ID 

Definition at line 13 of file key_type.hpp.

Types are 32bit integers, which represent encoded 4-char strings Little-endian byte order is used

Enumerator
KEY_TYPE_BABE 
KEY_TYPE_GRAN 
KEY_TYPE_ACCO 
KEY_TYPE_IMON 
KEY_TYPE_AUDI 
KEY_TYPE_LP2P 
KEY_TYPE_ASGN 
KEY_TYPE_PARA 

Definition at line 27 of file key_type.hpp.

Enumerator
KEY_DERIVATION_FAILED 

Definition at line 15 of file pbkdf2_provider.hpp.

Enumerator
INVALID_ARGUMENT 
INVALID_V_VALUE 
INVALID_R_OR_S_VALUE 
INVALID_SIGNATURE 
RECOVERY_FAILED 

Definition at line 15 of file secp256k1_provider_impl.hpp.

sr25519 provider error codes

Enumerator
SIGN_UNKNOWN_ERROR 
VERIFY_UNKNOWN_ERROR 

Definition at line 18 of file sr25519_provider.hpp.

Function Documentation

int kagome::crypto::blake2b ( void *  out,
size_t  outlen,
const void *  key,
size_t  keylen,
const void *  in,
size_t  inlen 
)

Definition at line 190 of file blake2b.cpp.

static void kagome::crypto::blake2b_compress ( blake2b_ctx ctx,
int  last 
)
static

Definition at line 60 of file blake2b.cpp.

void kagome::crypto::blake2b_final ( blake2b_ctx ctx,
void *  out 
)

Definition at line 169 of file blake2b.cpp.

int kagome::crypto::blake2b_init ( blake2b_ctx ctx,
size_t  outlen,
const void *  key,
size_t  keylen 
)

Definition at line 113 of file blake2b.cpp.

void kagome::crypto::blake2b_update ( blake2b_ctx ctx,
const void *  in,
size_t  inlen 
)

Definition at line 147 of file blake2b.cpp.

int kagome::crypto::blake2s ( void *  out,
size_t  outlen,
const void *  key,
size_t  keylen,
const void *  in,
size_t  inlen 
)

All in one blake2s hashing function.

Parameters
outoutput buffer
outlensize of {
out}
keyoptional key
keylensize of {
key}.Pass 0 to indicate that key is not provided.
indata to be hashed
inlensize of {
in}
Returns
-1 in case of wrong input arguments; 0 in case of success

Definition at line 194 of file blake2s.cpp.

void kagome::crypto::blake2s_256 ( void *  out,
const void *  in,
size_t  inlen 
)

One-shot convenience function to calculate blake2s_256 hash.

Parameters
out32-byte buffer
in{
inlen}bytes input buffer
inlensize of the input buffer
Returns

Definition at line 216 of file blake2s.cpp.

void kagome::crypto::blake2s_256_init ( blake2s_ctx ctx)

Initialize hash context.

Parameters
ctxcontext

Definition at line 212 of file blake2s.cpp.

static void kagome::crypto::blake2s_compress ( blake2s_ctx_full ctx,
int  last 
)
static

Definition at line 69 of file blake2s.cpp.

void kagome::crypto::blake2s_final ( blake2s_ctx ctx,
void *  out 
)

Finalize hash calculation.

Parameters
ctxcontext
out32-byte output
Returns

Definition at line 138 of file blake2s.cpp.

int kagome::crypto::blake2s_init ( blake2s_ctx ctx,
size_t  outlen,
const void *  key,
size_t  keylen 
)

Generic blake2s init function.

Parameters
ctxcontext
outlen1..32 bytes of output buffer size
keyoptional key
keylenlength of {
key}in bytes. Pass 0 to indicate that key is not provided.
Returns
-1 in case of wrong input arguments; 0 in case of success.

Definition at line 159 of file blake2s.cpp.

void kagome::crypto::blake2s_update ( blake2s_ctx ctx,
const void *  in,
size_t  inlen 
)

Update context with incoming bytes.

Parameters
ctxcontext
in{
inlen}byte array
inlensize of {
in}

Definition at line 117 of file blake2s.cpp.

KeyTypeId kagome::crypto::decodeKeyTypeIdFromStr ( std::string_view  str)

restores KeyTypeId from its string representation

Parameters
paramstring representation of key type
Returns
KeyTypeId

Definition at line 35 of file key_type.cpp.

libp2p::crypto::KeyPair kagome::crypto::ed25519KeyToLibp2pKeypair ( const Ed25519Keypair kp)

Definition at line 243 of file crypto_store_impl.cpp.

std::string kagome::crypto::encodeKeyTypeIdToStr ( KeyTypeId  key_type_id)

makes string representation of KeyTypeId

Parameters
key_type_idKeyTypeId
Returns
string representation of KeyTypeId

Definition at line 29 of file key_type.cpp.

bool kagome::crypto::isSupportedKeyType ( KeyTypeId  k)

checks whether key type value is supported

Parameters
kkey type value
Returns
true if supported, false otherwise

Definition at line 14 of file key_type.cpp.

void kagome::crypto::make_twox128 ( const uint8_t *  in,
uint32_t  len,
uint8_t *  out 
)

Definition at line 25 of file twox.cpp.

common::Hash128 kagome::crypto::make_twox128 ( gsl::span< const uint8_t >  buf)

Definition at line 34 of file twox.cpp.

void kagome::crypto::make_twox256 ( const uint8_t *  in,
uint32_t  len,
uint8_t *  out 
)

Definition at line 40 of file twox.cpp.

common::Hash256 kagome::crypto::make_twox256 ( gsl::span< const uint8_t >  buf)

Definition at line 53 of file twox.cpp.

void kagome::crypto::make_twox64 ( const uint8_t *  in,
uint32_t  len,
uint8_t *  out 
)

Definition at line 12 of file twox.cpp.

common::Hash64 kagome::crypto::make_twox64 ( gsl::span< const uint8_t >  buf)

Definition at line 19 of file twox.cpp.

common::Hash256 kagome::crypto::sha256 ( std::string_view  input)

Take a SHA-256 hash from string

Parameters
inputto be hashed
Returns
hashed bytes

Definition at line 11 of file sha256.cpp.

common::Hash256 kagome::crypto::sha256 ( gsl::span< const uint8_t >  input)

Take a SHA-256 hash from bytes

Parameters
inputto be hashed
Returns
hashed bytes

Definition at line 17 of file sha256.cpp.

outcome::result<int> kagome::crypto::validateRecoveryId ( int  v)

Definition at line 57 of file secp256k1_provider_impl.cpp.

Variable Documentation

const uint64_t kagome::crypto::blake2b_iv[8]
static
Initial value:
= {0x6A09E667F3BCC908,
0xBB67AE8584CAA73B,
0x3C6EF372FE94F82B,
0xA54FF53A5F1D36F1,
0x510E527FADE682D1,
0x9B05688C2B3E6C1F,
0x1F83D9ABFB41BD6B,
0x5BE0CD19137E2179}

Definition at line 49 of file blake2b.cpp.

const uint32_t kagome::crypto::blake2s_iv[8]
static
Initial value:
= {0x6A09E667,
0xBB67AE85,
0x3C6EF372,
0xA54FF53A,
0x510E527F,
0x9B05688C,
0x1F83D9AB,
0x5BE0CD19}

Definition at line 58 of file blake2s.cpp.