CCF
Loading...
Searching...
No Matches
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
ccf::crypto Namespace Reference

Namespaces

namespace  OpenSSL
 
namespace  sharing
 

Classes

struct  Base64_openssl
 
class  COSECertVerifier_OpenSSL
 
struct  COSEEndorsementValidity
 
class  COSEKeyVerifier_OpenSSL
 
class  COSEMapIntKey
 
class  COSEMapKey
 
class  COSEMapStringKey
 
class  COSEParametersFactory
 
class  COSEParametersMap
 
class  COSEParametersPair
 
struct  COSESignError
 
class  COSEVerifier
 
class  COSEVerifier_OpenSSL
 
class  EdDSAKeyPair
 
class  EdDSAKeyPair_OpenSSL
 
class  EdDSAPublicKey
 
class  EdDSAPublicKey_OpenSSL
 
class  Entropy
 
class  Entropy_OpenSSL
 
struct  FixedSizeGcmHeader
 
struct  GcmCipher
 
struct  GcmHeader
 
class  HashProvider
 
class  ISha256Hash
 
class  ISha256OpenSSL
 
struct  JsonWebKey
 
struct  JsonWebKeyData
 
struct  JsonWebKeyECPrivate
 
struct  JsonWebKeyECPublic
 
struct  JsonWebKeyEdDSAPrivate
 
struct  JsonWebKeyEdDSAPublic
 
struct  JsonWebKeyRSAPrivate
 
struct  JsonWebKeyRSAPublic
 
class  KeyAesGcm
 
class  KeyAesGcm_OpenSSL
 
class  KeyPair
 
class  KeyPair_OpenSSL
 
class  OpenSSLHashProvider
 
class  Pem
 
class  PublicKey
 
class  PublicKey_OpenSSL
 
class  RSAKeyPair
 
class  RSAKeyPair_OpenSSL
 
class  RSAPublicKey
 
class  RSAPublicKey_OpenSSL
 
class  Sha256Hash
 
struct  SubjectAltName
 
class  Verifier
 
class  Verifier_OpenSSL
 

Typedefs

using COSEVerifierUniquePtr = std::unique_ptr< COSEVerifier >
 
using EdDSAPublicKeyPtr = std::shared_ptr< EdDSAPublicKey >
 
using EdDSAKeyPairPtr = std::shared_ptr< EdDSAKeyPair >
 
using EntropyPtr = std::shared_ptr< Entropy >
 
using HashBytes = std::vector< uint8_t >
 
using PublicKeyPtr = std::shared_ptr< PublicKey >
 
using KeyPairPtr = std::shared_ptr< KeyPair >
 
using RSAPublicKeyPtr = std::shared_ptr< RSAPublicKey >
 
using RSAKeyPairPtr = std::shared_ptr< RSAKeyPair >
 
using StandardGcmHeader = FixedSizeGcmHeader< 12 >
 
using VerifierPtr = std::shared_ptr< Verifier >
 
using VerifierUniquePtr = std::unique_ptr< Verifier >
 
using Base64Impl = Base64_openssl
 
using PublicKeyImpl = EdDSAPublicKey_OpenSSL
 
using KeyPairImpl = EdDSAKeyPair_OpenSSL
 
using COSEHeadersArray = std::vector< std::shared_ptr< ccf::crypto::COSEParametersFactory > >
 
using RSAPublicKeyImpl = RSAPublicKey_OpenSSL
 
using RSAKeyPairImpl = RSAKeyPair_OpenSSL
 

Enumerations

enum class  CurveID {
  NONE = 0 , SECP384R1 , SECP256R1 , CURVE25519 ,
  X25519
}
 
enum class  JsonWebKeyType { EC = 0 , RSA = 1 , OKP = 2 }
 
enum class  JsonWebKeyECCurve { P256 = 0 , P384 = 1 , P521 = 2 }
 
enum class  JsonWebKeyEdDSACurve { ED25519 = 0 , X25519 = 1 }
 
enum class  MDType {
  NONE = 0 , SHA1 , SHA256 , SHA384 ,
  SHA512
}
 

Functions

std::vector< uint8_t > raw_from_b64 (const std::string_view &b64_string)
 
std::vector< uint8_t > raw_from_b64url (const std::string_view &b64url_string)
 
std::string b64_from_raw (const uint8_t *data, size_t size)
 
std::string b64_from_raw (const std::vector< uint8_t > &data)
 
std::string b64url_from_raw (const uint8_t *data, size_t size, bool with_padding=true)
 
std::string b64url_from_raw (const std::vector< uint8_t > &data, bool with_padding=true)
 
COSEVerifierUniquePtr make_cose_verifier_from_cert (const std::vector< uint8_t > &cert)
 
COSEVerifierUniquePtr make_cose_verifier_from_key (const Pem &public_key)
 
COSEEndorsementValidity extract_cose_endorsement_validity (std::span< const uint8_t > cose_msg)
 
 DECLARE_JSON_ENUM (CurveID, {{CurveID::NONE, "None"}, {CurveID::SECP384R1, "Secp384R1"}, {CurveID::SECP256R1, "Secp256R1"}, {CurveID::CURVE25519, "Curve25519"}, {CurveID::X25519, "X25519"}})
 
MDType get_md_for_ec (CurveID ec)
 
std::vector< uint8_t > ecdsa_sig_from_r_s (const uint8_t *r, size_t r_size, const uint8_t *s, size_t s_size, bool big_endian=true)
 
std::vector< uint8_t > ecdsa_sig_p1363_to_der (std::span< const uint8_t > signature)
 
std::vector< uint8_t > ecdsa_sig_der_to_p1363 (const std::vector< uint8_t > &signature, CurveID curveId)
 
EdDSAPublicKeyPtr make_eddsa_public_key (const Pem &pem)
 
EdDSAPublicKeyPtr make_eddsa_public_key (const JsonWebKeyEdDSAPublic &jwk)
 
EdDSAKeyPairPtr make_eddsa_key_pair (CurveID curve_id=CurveID::CURVE25519)
 
EdDSAKeyPairPtr make_eddsa_key_pair (const Pem &pem)
 
EdDSAKeyPairPtr make_eddsa_key_pair (const JsonWebKeyEdDSAPrivate &jwk)
 
EntropyPtr get_entropy ()
 
std::shared_ptr< HashProvidermake_hash_provider ()
 
std::shared_ptr< ISha256Hashmake_incremental_sha256 ()
 
std::vector< uint8_t > hkdf (MDType md_type, size_t length, const std::span< const uint8_t > &ikm, const std::span< const uint8_t > &salt={}, const std::span< const uint8_t > &info={})
 
HashBytes hmac (MDType type, const std::vector< uint8_t > &key, const std::vector< uint8_t > &data)
 
 DECLARE_JSON_ENUM (JsonWebKeyType, {{JsonWebKeyType::EC, "EC"}, {JsonWebKeyType::RSA, "RSA"}, {JsonWebKeyType::OKP, "OKP"}})
 
 DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS (JsonWebKey)
 
 DECLARE_JSON_REQUIRED_FIELDS (JsonWebKey, kty)
 
 DECLARE_JSON_OPTIONAL_FIELDS (JsonWebKey, kid, x5c)
 
 DECLARE_JSON_ENUM (JsonWebKeyECCurve, {{JsonWebKeyECCurve::P256, "P-256"}, {JsonWebKeyECCurve::P384, "P-384"}, {JsonWebKeyECCurve::P521, "P-521"}})
 
 DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS (JsonWebKeyData)
 
 DECLARE_JSON_REQUIRED_FIELDS (JsonWebKeyData, kty)
 
 DECLARE_JSON_OPTIONAL_FIELDS (JsonWebKeyData, kid, x5c, n, e, x, y, crv, issuer)
 
 DECLARE_JSON_ENUM (JsonWebKeyEdDSACurve, {{JsonWebKeyEdDSACurve::ED25519, "Ed25519"}, {JsonWebKeyEdDSACurve::X25519, "X25519"}})
 
 DECLARE_JSON_TYPE_WITH_BASE (JsonWebKeyECPublic, JsonWebKey)
 
 DECLARE_JSON_REQUIRED_FIELDS (JsonWebKeyECPublic, crv, x, y)
 
 DECLARE_JSON_TYPE_WITH_BASE (JsonWebKeyECPrivate, JsonWebKeyECPublic)
 
 DECLARE_JSON_REQUIRED_FIELDS (JsonWebKeyECPrivate, d)
 
 DECLARE_JSON_TYPE_WITH_BASE (JsonWebKeyRSAPublic, JsonWebKey)
 
 DECLARE_JSON_REQUIRED_FIELDS (JsonWebKeyRSAPublic, n, e)
 
 DECLARE_JSON_TYPE_WITH_BASE (JsonWebKeyRSAPrivate, JsonWebKeyRSAPublic)
 
 DECLARE_JSON_REQUIRED_FIELDS (JsonWebKeyRSAPrivate, d, p, q, dp, dq, qi)
 
 DECLARE_JSON_TYPE_WITH_BASE (JsonWebKeyEdDSAPublic, JsonWebKey)
 
 DECLARE_JSON_REQUIRED_FIELDS (JsonWebKeyEdDSAPublic, crv, x)
 
 DECLARE_JSON_TYPE_WITH_BASE (JsonWebKeyEdDSAPrivate, JsonWebKeyEdDSAPublic)
 
 DECLARE_JSON_REQUIRED_FIELDS (JsonWebKeyEdDSAPrivate, d)
 
PublicKeyPtr make_public_key (const Pem &pem)
 
PublicKeyPtr make_public_key (const std::vector< uint8_t > &der)
 
PublicKeyPtr make_public_key (const JsonWebKeyECPublic &jwk)
 
KeyPairPtr make_key_pair (CurveID curve_id=service_identity_curve_choice)
 
KeyPairPtr make_key_pair (const Pem &pem)
 
KeyPairPtr make_key_pair (const JsonWebKeyECPrivate &jwk)
 
std::vector< uint8_t > ckm_rsa_pkcs_oaep_wrap (RSAPublicKeyPtr wrapping_key, const std::vector< uint8_t > &unwrapped, const std::optional< std::vector< uint8_t > > &label={})
 
std::vector< uint8_t > ckm_rsa_pkcs_oaep_wrap (const Pem &wrapping_key, const std::vector< uint8_t > &unwrapped, const std::optional< std::vector< uint8_t > > &label={})
 
std::vector< uint8_t > ckm_rsa_pkcs_oaep_unwrap (RSAKeyPairPtr wrapping_key, const std::vector< uint8_t > &wrapped, const std::optional< std::vector< uint8_t > > &label={})
 
std::vector< uint8_t > ckm_rsa_pkcs_oaep_unwrap (const Pem &wrapping_key, const std::vector< uint8_t > &wrapped, const std::optional< std::vector< uint8_t > > &label={})
 
std::vector< uint8_t > ckm_aes_key_wrap_pad (const std::vector< uint8_t > &wrapping_key, const std::vector< uint8_t > &unwrapped)
 
std::vector< uint8_t > ckm_aes_key_unwrap_pad (const std::vector< uint8_t > &wrapping_key, const std::vector< uint8_t > &wrapped)
 
std::vector< uint8_t > ckm_rsa_aes_key_wrap (size_t aes_key_size, RSAPublicKeyPtr wrapping_key, const std::vector< uint8_t > &unwrapped, const std::optional< std::vector< uint8_t > > &label={})
 
std::vector< uint8_t > ckm_rsa_aes_key_wrap (size_t aes_key_size, const Pem &wrapping_key, const std::vector< uint8_t > &unwrapped, const std::optional< std::vector< uint8_t > > &label={})
 
std::vector< uint8_t > ckm_rsa_aes_key_unwrap (RSAKeyPairPtr wrapping_key, const std::vector< uint8_t > &wrapped, const std::optional< std::vector< uint8_t > > &label={})
 
std::vector< uint8_t > ckm_rsa_aes_key_unwrap (const Pem &wrapping_key, const std::vector< uint8_t > &wrapped, const std::optional< std::vector< uint8_t > > &label={})
 
 DECLARE_JSON_ENUM (MDType, {{MDType::NONE, "NONE"}, {MDType::SHA1, "SHA1"}, {MDType::SHA256, "SHA256"}, {MDType::SHA384, "SHA384"}, {MDType::SHA512, "SHA512"}})
 
void openssl_sha256_init ()
 
void openssl_sha256_shutdown ()
 
void to_json (nlohmann::json &j, const Pem &p)
 
void from_json (const nlohmann::json &j, Pem &p)
 
std::string schema_name (const Pem *)
 
std::vector< ccf::crypto::Pemsplit_x509_cert_bundle (const std::string_view &pem)
 
void fill_json_schema (nlohmann::json &schema, const Pem *)
 
RSAPublicKeyPtr make_rsa_public_key (const Pem &pem)
 
RSAPublicKeyPtr make_rsa_public_key (const std::vector< uint8_t > &der)
 
RSAPublicKeyPtr make_rsa_public_key (const JsonWebKeyRSAPublic &jwk)
 
RSAPublicKeyPtr make_rsa_public_key (const uint8_t *data, size_t size)
 
RSAKeyPairPtr make_rsa_key_pair (size_t public_key_size=RSAKeyPair::default_public_key_size, size_t public_exponent=RSAKeyPair::default_public_exponent)
 
RSAKeyPairPtr make_rsa_key_pair (const Pem &pem)
 
RSAKeyPairPtr make_rsa_key_pair (const JsonWebKeyRSAPrivate &jwk)
 
 DECLARE_JSON_TYPE (SubjectAltName)
 
 DECLARE_JSON_REQUIRED_FIELDS (SubjectAltName, san, is_ip)
 
HashBytes sha256 (const std::span< uint8_t const > &data)
 
HashBytes sha256 (const uint8_t *data, size_t len)
 
void to_json (nlohmann::json &j, const Sha256Hash &hash)
 
void from_json (const nlohmann::json &j, Sha256Hash &hash)
 
std::string schema_name (const Sha256Hash *)
 
void fill_json_schema (nlohmann::json &schema, const Sha256Hash *)
 
bool operator== (const Sha256Hash &lhs, const Sha256Hash &rhs)
 
bool operator!= (const Sha256Hash &lhs, const Sha256Hash &rhs)
 
std::unique_ptr< KeyAesGcmmake_key_aes_gcm (std::span< const uint8_t > rawKey)
 Free function implementation.
 
void check_supported_aes_key_size (size_t num_bits)
 
std::vector< uint8_t > aes_gcm_encrypt (std::span< const uint8_t > key, std::span< const uint8_t > plaintext, const std::vector< uint8_t > &iv=default_iv, const std::vector< uint8_t > &aad={})
 
std::vector< uint8_t > aes_gcm_decrypt (std::span< const uint8_t > key, std::span< const uint8_t > ciphertext, const std::vector< uint8_t > &iv=default_iv, const std::vector< uint8_t > &aad={})
 
VerifierUniquePtr make_unique_verifier (const std::vector< uint8_t > &cert)
 
VerifierPtr make_verifier (const std::vector< uint8_t > &cert)
 
VerifierUniquePtr make_unique_verifier (const Pem &pem)
 
VerifierPtr make_verifier (const Pem &pem)
 
ccf::crypto::Pem cert_der_to_pem (const std::vector< uint8_t > &der)
 
std::vector< uint8_t > cert_pem_to_der (const Pem &pem)
 
std::vector< uint8_t > public_key_der_from_cert (const std::vector< uint8_t > &der)
 
ccf::crypto::Pem public_key_pem_from_cert (const std::vector< uint8_t > &der)
 
std::string get_subject_name (const Pem &cert)
 
Pem public_key_pem_from_csr (const Pem &signing_request)
 
void default_sha256 (const std::span< const uint8_t > &data, uint8_t *h)
 
std::vector< uint8_t > sha256 (const std::vector< uint8_t > &data)
 
std::optional< int > key_to_cose_alg_id (const ccf::crypto::PublicKey_OpenSSL &key)
 
std::shared_ptr< COSEParametersFactorycose_params_int_int (int64_t key, int64_t value)
 
std::shared_ptr< COSEParametersFactorycose_params_int_string (int64_t key, const std::string &value)
 
std::shared_ptr< COSEParametersFactorycose_params_string_int (const std::string &key, int64_t value)
 
std::shared_ptr< COSEParametersFactorycose_params_string_string (const std::string &key, const std::string &value)
 
std::shared_ptr< COSEParametersFactorycose_params_int_bytes (int64_t key, std::span< const uint8_t > value)
 
std::shared_ptr< COSEParametersFactorycose_params_string_bytes (const std::string &key, std::span< const uint8_t > value)
 
std::vector< uint8_t > cose_sign1 (const KeyPair_OpenSSL &key, const std::vector< std::shared_ptr< COSEParametersFactory > > &protected_headers, std::span< const uint8_t > payload, bool detached_payload)
 
void openssl_sha256 (const std::span< const uint8_t > &data, uint8_t *h)
 
std::pair< Unique_BIGNUM, Unique_BIGNUMget_components (const JsonWebKeyECPublic &jwk)
 
Unique_PKEY key_from_raw_ec_point (const std::vector< uint8_t > &raw, int nid)
 
std::pair< Unique_BIGNUM, Unique_BIGNUMget_modulus_and_exponent (const JsonWebKeyRSAPublic &jwk)
 
std::ostream & operator<< (std::ostream &os, const ccf::crypto::Sha256Hash &h)
 

Variables

constexpr size_t GCM_DEFAULT_KEY_SIZE = 32
 
constexpr size_t GCM_SIZE_TAG = 16
 

Typedef Documentation

◆ Base64Impl

◆ COSEHeadersArray

using ccf::crypto::COSEHeadersArray = typedef std::vector<std::shared_ptr<ccf::crypto::COSEParametersFactory> >

◆ COSEVerifierUniquePtr

using ccf::crypto::COSEVerifierUniquePtr = typedef std::unique_ptr<COSEVerifier>

◆ EdDSAKeyPairPtr

using ccf::crypto::EdDSAKeyPairPtr = typedef std::shared_ptr<EdDSAKeyPair>

◆ EdDSAPublicKeyPtr

using ccf::crypto::EdDSAPublicKeyPtr = typedef std::shared_ptr<EdDSAPublicKey>

◆ EntropyPtr

using ccf::crypto::EntropyPtr = typedef std::shared_ptr<Entropy>

◆ HashBytes

using ccf::crypto::HashBytes = typedef std::vector<uint8_t>

◆ KeyPairImpl

◆ KeyPairPtr

using ccf::crypto::KeyPairPtr = typedef std::shared_ptr<KeyPair>

◆ PublicKeyImpl

◆ PublicKeyPtr

using ccf::crypto::PublicKeyPtr = typedef std::shared_ptr<PublicKey>

◆ RSAKeyPairImpl

◆ RSAKeyPairPtr

using ccf::crypto::RSAKeyPairPtr = typedef std::shared_ptr<RSAKeyPair>

◆ RSAPublicKeyImpl

◆ RSAPublicKeyPtr

using ccf::crypto::RSAPublicKeyPtr = typedef std::shared_ptr<RSAPublicKey>

◆ StandardGcmHeader

◆ VerifierPtr

typedef std::shared_ptr< Verifier > ccf::crypto::VerifierPtr

◆ VerifierUniquePtr

typedef std::unique_ptr< Verifier > ccf::crypto::VerifierUniquePtr

Enumeration Type Documentation

◆ CurveID

enum class ccf::crypto::CurveID
strong
Enumerator
NONE 

No curve.

SECP384R1 

The SECP384R1 curve.

SECP256R1 

The SECP256R1 curve.

CURVE25519 

The CURVE25519 curve.

X25519 

◆ JsonWebKeyECCurve

enum class ccf::crypto::JsonWebKeyECCurve
strong
Enumerator
P256 
P384 
P521 

◆ JsonWebKeyEdDSACurve

Enumerator
ED25519 
X25519 

◆ JsonWebKeyType

enum class ccf::crypto::JsonWebKeyType
strong
Enumerator
EC 
RSA 
OKP 

◆ MDType

enum class ccf::crypto::MDType
strong
Enumerator
NONE 
SHA1 
SHA256 
SHA384 
SHA512 

Function Documentation

◆ aes_gcm_decrypt()

std::vector< uint8_t > ccf::crypto::aes_gcm_decrypt ( std::span< const uint8_t >  key,
std::span< const uint8_t >  ciphertext,
const std::vector< uint8_t > &  iv = default_iv,
const std::vector< uint8_t > &  aad = {} 
)

AES-GCM Decryption with key of data

Parameters
keyThe key
ciphertextThe (encrypted) data
ivInitialization vector
aadAdditional authenticated data
Returns
plaintext

◆ aes_gcm_encrypt()

std::vector< uint8_t > ccf::crypto::aes_gcm_encrypt ( std::span< const uint8_t >  key,
std::span< const uint8_t >  plaintext,
const std::vector< uint8_t > &  iv = default_iv,
const std::vector< uint8_t > &  aad = {} 
)

AES-GCM Encryption with key of data

Parameters
keyThe key
plaintextThe data
ivIntialization vector
aadAdditional authenticated data
Returns
ciphertext

◆ b64_from_raw() [1/2]

std::string ccf::crypto::b64_from_raw ( const std::vector< uint8_t > &  data)

◆ b64_from_raw() [2/2]

std::string ccf::crypto::b64_from_raw ( const uint8_t *  data,
size_t  size 
)

◆ b64url_from_raw() [1/2]

std::string ccf::crypto::b64url_from_raw ( const std::vector< uint8_t > &  data,
bool  with_padding = true 
)

◆ b64url_from_raw() [2/2]

std::string ccf::crypto::b64url_from_raw ( const uint8_t *  data,
size_t  size,
bool  with_padding = true 
)

◆ cert_der_to_pem()

ccf::crypto::Pem ccf::crypto::cert_der_to_pem ( const std::vector< uint8_t > &  der)

◆ cert_pem_to_der()

std::vector< uint8_t > ccf::crypto::cert_pem_to_der ( const Pem pem)

◆ check_supported_aes_key_size()

void ccf::crypto::check_supported_aes_key_size ( size_t  num_bits)
inline

Check for unsupported AES key sizes num_bits Key size in bits

◆ ckm_aes_key_unwrap_pad()

std::vector< uint8_t > ccf::crypto::ckm_aes_key_unwrap_pad ( const std::vector< uint8_t > &  wrapping_key,
const std::vector< uint8_t > &  wrapped 
)

PKCS11 2.14.3 CKM_AES_KEY_WRAP_PAD unwrap

Parameters
wrapping_keyThe wrapping (encryption) key
wrappedThe wrapped key to unwrap
Returns
Unwrapped key

◆ ckm_aes_key_wrap_pad()

std::vector< uint8_t > ccf::crypto::ckm_aes_key_wrap_pad ( const std::vector< uint8_t > &  wrapping_key,
const std::vector< uint8_t > &  unwrapped 
)

PKCS11 2.14.3 CKM_AES_KEY_WRAP_PAD wrap

Parameters
wrapping_keyThe wrapping (encryption) key
unwrappedThe unwrapped key to be wrapped
Returns
Wrapped key

◆ ckm_rsa_aes_key_unwrap() [1/2]

std::vector< uint8_t > ccf::crypto::ckm_rsa_aes_key_unwrap ( const Pem wrapping_key,
const std::vector< uint8_t > &  wrapped,
const std::optional< std::vector< uint8_t > > &  label = {} 
)

PKCS11 2.1.21 CKM_RSA_AES_KEY_WRAP unwrap

Parameters
wrapping_keyThe wrapping (encryption) key
wrappedThe wrapped key to unwrap
labelOptional label
Returns
Unwrapped key

◆ ckm_rsa_aes_key_unwrap() [2/2]

std::vector< uint8_t > ccf::crypto::ckm_rsa_aes_key_unwrap ( RSAKeyPairPtr  wrapping_key,
const std::vector< uint8_t > &  wrapped,
const std::optional< std::vector< uint8_t > > &  label = {} 
)

PKCS11 2.1.21 CKM_RSA_AES_KEY_WRAP unwrap

Parameters
wrapping_keyThe wrapping (encryption) key
wrappedThe wrapped key to unwrap
labelOptional label
Returns
Unwrapped key

◆ ckm_rsa_aes_key_wrap() [1/2]

std::vector< uint8_t > ccf::crypto::ckm_rsa_aes_key_wrap ( size_t  aes_key_size,
const Pem wrapping_key,
const std::vector< uint8_t > &  unwrapped,
const std::optional< std::vector< uint8_t > > &  label = {} 
)

PKCS11 2.1.21 CKM_RSA_AES_KEY_WRAP wrap

Parameters
aes_key_sizeKey size 128, 192 or 256.
wrapping_keyThe wrapping (encryption) key
unwrappedThe key to wrap
labelOptional label
Returns
Wrapped key

◆ ckm_rsa_aes_key_wrap() [2/2]

std::vector< uint8_t > ccf::crypto::ckm_rsa_aes_key_wrap ( size_t  aes_key_size,
RSAPublicKeyPtr  wrapping_key,
const std::vector< uint8_t > &  unwrapped,
const std::optional< std::vector< uint8_t > > &  label = {} 
)

PKCS11 2.1.21 CKM_RSA_AES_KEY_WRAP wrap

Parameters
aes_key_sizeKey size 128, 192 or 256.
wrapping_keyThe wrapping (encryption) key
unwrappedThe key to wrap
labelOptional label
Returns
Wrapped key

◆ ckm_rsa_pkcs_oaep_unwrap() [1/2]

std::vector< uint8_t > ccf::crypto::ckm_rsa_pkcs_oaep_unwrap ( const Pem wrapping_key,
const std::vector< uint8_t > &  wrapped,
const std::optional< std::vector< uint8_t > > &  label = {} 
)

PKCS11 2.1.8 CKM_RSA_PKCS_OAEP

Parameters
wrapping_keyThe wrapping (encryption) key
wrappedThe wrapped key to unwrap
labelOptional label
Returns
Unwrapped key

◆ ckm_rsa_pkcs_oaep_unwrap() [2/2]

std::vector< uint8_t > ccf::crypto::ckm_rsa_pkcs_oaep_unwrap ( RSAKeyPairPtr  wrapping_key,
const std::vector< uint8_t > &  wrapped,
const std::optional< std::vector< uint8_t > > &  label = {} 
)

PKCS11 2.1.8 CKM_RSA_PKCS_OAEP unwrap

Parameters
wrapping_keyThe wrapping (encryption) key
wrappedThe wrapped key to unwrap
labelOptional label
Returns
Unwrapped key

◆ ckm_rsa_pkcs_oaep_wrap() [1/2]

std::vector< uint8_t > ccf::crypto::ckm_rsa_pkcs_oaep_wrap ( const Pem wrapping_key,
const std::vector< uint8_t > &  unwrapped,
const std::optional< std::vector< uint8_t > > &  label = {} 
)

PKCS11 2.1.8 CKM_RSA_PKCS_OAEP

Parameters
wrapping_keyThe wrapping (encryption) key
unwrappedThe unwrapped key to be wrapped
labelOptional label
Returns
Wrapped key

◆ ckm_rsa_pkcs_oaep_wrap() [2/2]

std::vector< uint8_t > ccf::crypto::ckm_rsa_pkcs_oaep_wrap ( RSAPublicKeyPtr  wrapping_key,
const std::vector< uint8_t > &  unwrapped,
const std::optional< std::vector< uint8_t > > &  label = {} 
)

PKCS11 2.1.8 CKM_RSA_PKCS_OAEP wrap

Parameters
wrapping_keyThe wrapping (encryption) key
unwrappedThe unwrapped key to be wrapped
labelOptional label
Returns
Wrapped key

◆ cose_params_int_bytes()

std::shared_ptr< COSEParametersFactory > ccf::crypto::cose_params_int_bytes ( int64_t  key,
std::span< const uint8_t >  value 
)

◆ cose_params_int_int()

std::shared_ptr< COSEParametersFactory > ccf::crypto::cose_params_int_int ( int64_t  key,
int64_t  value 
)

◆ cose_params_int_string()

std::shared_ptr< COSEParametersFactory > ccf::crypto::cose_params_int_string ( int64_t  key,
const std::string &  value 
)

◆ cose_params_string_bytes()

std::shared_ptr< COSEParametersFactory > ccf::crypto::cose_params_string_bytes ( const std::string &  key,
std::span< const uint8_t >  value 
)

◆ cose_params_string_int()

std::shared_ptr< COSEParametersFactory > ccf::crypto::cose_params_string_int ( const std::string &  key,
int64_t  value 
)

◆ cose_params_string_string()

std::shared_ptr< COSEParametersFactory > ccf::crypto::cose_params_string_string ( const std::string &  key,
const std::string &  value 
)

◆ cose_sign1()

std::vector< uint8_t > ccf::crypto::cose_sign1 ( const KeyPair_OpenSSL key,
const std::vector< std::shared_ptr< COSEParametersFactory > > &  protected_headers,
std::span< const uint8_t >  payload,
bool  detached_payload 
)

◆ DECLARE_JSON_ENUM() [1/5]

ccf::crypto::DECLARE_JSON_ENUM ( CurveID  ,
{{CurveID::NONE, "None"}, {CurveID::SECP384R1, "Secp384R1"}, {CurveID::SECP256R1, "Secp256R1"}, {CurveID::CURVE25519, "Curve25519"}, {CurveID::X25519, "X25519"}}   
)

◆ DECLARE_JSON_ENUM() [2/5]

ccf::crypto::DECLARE_JSON_ENUM ( JsonWebKeyECCurve  ,
{{JsonWebKeyECCurve::P256, "P-256"}, {JsonWebKeyECCurve::P384, "P-384"}, {JsonWebKeyECCurve::P521, "P-521"}}   
)

◆ DECLARE_JSON_ENUM() [3/5]

ccf::crypto::DECLARE_JSON_ENUM ( JsonWebKeyEdDSACurve  ,
{{JsonWebKeyEdDSACurve::ED25519, "Ed25519"}, {JsonWebKeyEdDSACurve::X25519, "X25519"}}   
)

◆ DECLARE_JSON_ENUM() [4/5]

ccf::crypto::DECLARE_JSON_ENUM ( JsonWebKeyType  ,
{{JsonWebKeyType::EC, "EC"}, {JsonWebKeyType::RSA, "RSA"}, {JsonWebKeyType::OKP, "OKP"}}   
)

◆ DECLARE_JSON_ENUM() [5/5]

ccf::crypto::DECLARE_JSON_ENUM ( MDType  ,
{{MDType::NONE, "NONE"}, {MDType::SHA1, "SHA1"}, {MDType::SHA256, "SHA256"}, {MDType::SHA384, "SHA384"}, {MDType::SHA512, "SHA512"}}   
)

◆ DECLARE_JSON_OPTIONAL_FIELDS() [1/2]

ccf::crypto::DECLARE_JSON_OPTIONAL_FIELDS ( JsonWebKey  ,
kid  ,
x5c   
)

◆ DECLARE_JSON_OPTIONAL_FIELDS() [2/2]

ccf::crypto::DECLARE_JSON_OPTIONAL_FIELDS ( JsonWebKeyData  ,
kid  ,
x5c  ,
,
,
,
,
crv  ,
issuer   
)

◆ DECLARE_JSON_REQUIRED_FIELDS() [1/9]

ccf::crypto::DECLARE_JSON_REQUIRED_FIELDS ( JsonWebKey  ,
kty   
)

◆ DECLARE_JSON_REQUIRED_FIELDS() [2/9]

ccf::crypto::DECLARE_JSON_REQUIRED_FIELDS ( JsonWebKeyData  ,
kty   
)

◆ DECLARE_JSON_REQUIRED_FIELDS() [3/9]

ccf::crypto::DECLARE_JSON_REQUIRED_FIELDS ( JsonWebKeyECPrivate  ,
 
)

◆ DECLARE_JSON_REQUIRED_FIELDS() [4/9]

ccf::crypto::DECLARE_JSON_REQUIRED_FIELDS ( JsonWebKeyECPublic  ,
crv  ,
,
 
)

◆ DECLARE_JSON_REQUIRED_FIELDS() [5/9]

ccf::crypto::DECLARE_JSON_REQUIRED_FIELDS ( JsonWebKeyEdDSAPrivate  ,
 
)

◆ DECLARE_JSON_REQUIRED_FIELDS() [6/9]

ccf::crypto::DECLARE_JSON_REQUIRED_FIELDS ( JsonWebKeyEdDSAPublic  ,
crv  ,
 
)

◆ DECLARE_JSON_REQUIRED_FIELDS() [7/9]

ccf::crypto::DECLARE_JSON_REQUIRED_FIELDS ( JsonWebKeyRSAPrivate  ,
,
,
,
dp  ,
dq  ,
qi   
)

◆ DECLARE_JSON_REQUIRED_FIELDS() [8/9]

ccf::crypto::DECLARE_JSON_REQUIRED_FIELDS ( JsonWebKeyRSAPublic  ,
,
 
)

◆ DECLARE_JSON_REQUIRED_FIELDS() [9/9]

ccf::crypto::DECLARE_JSON_REQUIRED_FIELDS ( SubjectAltName  ,
san  ,
is_ip   
)

◆ DECLARE_JSON_TYPE()

ccf::crypto::DECLARE_JSON_TYPE ( SubjectAltName  )

◆ DECLARE_JSON_TYPE_WITH_BASE() [1/6]

ccf::crypto::DECLARE_JSON_TYPE_WITH_BASE ( JsonWebKeyECPrivate  ,
JsonWebKeyECPublic   
)

◆ DECLARE_JSON_TYPE_WITH_BASE() [2/6]

ccf::crypto::DECLARE_JSON_TYPE_WITH_BASE ( JsonWebKeyECPublic  ,
JsonWebKey   
)

◆ DECLARE_JSON_TYPE_WITH_BASE() [3/6]

ccf::crypto::DECLARE_JSON_TYPE_WITH_BASE ( JsonWebKeyEdDSAPrivate  ,
JsonWebKeyEdDSAPublic   
)

◆ DECLARE_JSON_TYPE_WITH_BASE() [4/6]

ccf::crypto::DECLARE_JSON_TYPE_WITH_BASE ( JsonWebKeyEdDSAPublic  ,
JsonWebKey   
)

◆ DECLARE_JSON_TYPE_WITH_BASE() [5/6]

ccf::crypto::DECLARE_JSON_TYPE_WITH_BASE ( JsonWebKeyRSAPrivate  ,
JsonWebKeyRSAPublic   
)

◆ DECLARE_JSON_TYPE_WITH_BASE() [6/6]

ccf::crypto::DECLARE_JSON_TYPE_WITH_BASE ( JsonWebKeyRSAPublic  ,
JsonWebKey   
)

◆ DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS() [1/2]

ccf::crypto::DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS ( JsonWebKey  )

◆ DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS() [2/2]

ccf::crypto::DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS ( JsonWebKeyData  )

◆ default_sha256()

void ccf::crypto::default_sha256 ( const std::span< const uint8_t > &  data,
uint8_t *  h 
)

◆ ecdsa_sig_der_to_p1363()

std::vector< uint8_t > ccf::crypto::ecdsa_sig_der_to_p1363 ( const std::vector< uint8_t > &  signature,
CurveID  curveId 
)

◆ ecdsa_sig_from_r_s()

std::vector< uint8_t > ccf::crypto::ecdsa_sig_from_r_s ( const uint8_t *  r,
size_t  r_size,
const uint8_t *  s,
size_t  s_size,
bool  big_endian = true 
)

Converts R and S signature parameters to RFC 3279 DER encoding.

Parameters
rThe raw r signature parameter
r_sizeThe size of the r signature parameter
sThe raw s signature parameter
s_sizeThe size of the s signature parameter
big_endianTrue if the parameters are big endian, else False

◆ ecdsa_sig_p1363_to_der()

std::vector< uint8_t > ccf::crypto::ecdsa_sig_p1363_to_der ( std::span< const uint8_t >  signature)

Converts an ECDSA signature in IEEE P1363 encoding to RFC 3279 DER encoding.

Parameters
signatureThe signature in IEEE P1363 encoding

◆ extract_cose_endorsement_validity()

COSEEndorsementValidity ccf::crypto::extract_cose_endorsement_validity ( std::span< const uint8_t >  cose_msg)

◆ fill_json_schema() [1/2]

void ccf::crypto::fill_json_schema ( nlohmann::json &  schema,
const Pem  
)
inline

◆ fill_json_schema() [2/2]

void ccf::crypto::fill_json_schema ( nlohmann::json &  schema,
const Sha256Hash hash 
)

◆ from_json() [1/2]

void ccf::crypto::from_json ( const nlohmann::json &  j,
Pem p 
)
inline

◆ from_json() [2/2]

void ccf::crypto::from_json ( const nlohmann::json &  j,
Sha256Hash hash 
)

◆ get_components()

std::pair< Unique_BIGNUM, Unique_BIGNUM > ccf::crypto::get_components ( const JsonWebKeyECPublic jwk)

◆ get_entropy()

EntropyPtr ccf::crypto::get_entropy ( )

◆ get_md_for_ec()

MDType ccf::crypto::get_md_for_ec ( CurveID  ec)
inline

◆ get_modulus_and_exponent()

std::pair< Unique_BIGNUM, Unique_BIGNUM > ccf::crypto::get_modulus_and_exponent ( const JsonWebKeyRSAPublic jwk)

◆ get_subject_name()

std::string ccf::crypto::get_subject_name ( const Pem cert)

◆ hkdf()

std::vector< uint8_t > ccf::crypto::hkdf ( MDType  md_type,
size_t  length,
const std::span< const uint8_t > &  ikm,
const std::span< const uint8_t > &  salt = {},
const std::span< const uint8_t > &  info = {} 
)

Perform HKDF key derivation

◆ hmac()

HashBytes ccf::crypto::hmac ( MDType  type,
const std::vector< uint8_t > &  key,
const std::vector< uint8_t > &  data 
)

Compute the HMAC of key and data

◆ key_from_raw_ec_point()

OpenSSL::Unique_PKEY ccf::crypto::key_from_raw_ec_point ( const std::vector< uint8_t > &  raw,
int  nid 
)

◆ key_to_cose_alg_id()

std::optional< int > ccf::crypto::key_to_cose_alg_id ( const ccf::crypto::PublicKey_OpenSSL key)

◆ make_cose_verifier_from_cert()

COSEVerifierUniquePtr ccf::crypto::make_cose_verifier_from_cert ( const std::vector< uint8_t > &  cert)

◆ make_cose_verifier_from_key()

COSEVerifierUniquePtr ccf::crypto::make_cose_verifier_from_key ( const Pem public_key)

◆ make_eddsa_key_pair() [1/3]

EdDSAKeyPairPtr ccf::crypto::make_eddsa_key_pair ( const JsonWebKeyEdDSAPrivate jwk)

Create a public / private EdDSA key pair from existing JsonWebKeyEdDSAPrivate object

Currently only Curve25519 is supported.

◆ make_eddsa_key_pair() [2/3]

EdDSAKeyPairPtr ccf::crypto::make_eddsa_key_pair ( const Pem pem)

Create a public / private EdDSA key pair from existing private key data

Currently only Curve25519 is supported.

◆ make_eddsa_key_pair() [3/3]

EdDSAKeyPairPtr ccf::crypto::make_eddsa_key_pair ( CurveID  curve_id = CurveID::CURVE25519)

Create a new public / private EdDSA key pair on specified curve and implementation

Parameters
curve_idElliptic curve to use. Currently only CURVE25519 is supported.
Returns
Key pair

◆ make_eddsa_public_key() [1/2]

EdDSAPublicKeyPtr ccf::crypto::make_eddsa_public_key ( const JsonWebKeyEdDSAPublic jwk)

Create a public / private EdDSA public key from existing JsonWebKeyEdDSAPublic object

Currently only Curve25519 is supported.

◆ make_eddsa_public_key() [2/2]

EdDSAPublicKeyPtr ccf::crypto::make_eddsa_public_key ( const Pem pem)

Create a public / private EdDSA public key from existing public key data

Currently only Curve25519 is supported.

◆ make_hash_provider()

std::shared_ptr< HashProvider > ccf::crypto::make_hash_provider ( )

Create a default hash provider

◆ make_incremental_sha256()

std::shared_ptr< ISha256Hash > ccf::crypto::make_incremental_sha256 ( )

Create a default incremental SHA256 hash provider

◆ make_key_aes_gcm()

std::unique_ptr< KeyAesGcm > ccf::crypto::make_key_aes_gcm ( std::span< const uint8_t >  rawKey)

Free function implementation.

◆ make_key_pair() [1/3]

KeyPairPtr ccf::crypto::make_key_pair ( const JsonWebKeyECPrivate jwk)

Construct a new public / private ECDSA key pair from a JsonWebKeyECPrivate object

Parameters
jwkJsonWebKeyECPrivate object
Returns
Key pair

◆ make_key_pair() [2/3]

KeyPairPtr ccf::crypto::make_key_pair ( const Pem pem)

Create a public / private ECDSA key pair from existing private key data

Parameters
pemPEM key to load
Returns
Key pair

◆ make_key_pair() [3/3]

KeyPairPtr ccf::crypto::make_key_pair ( CurveID  curve_id = service_identity_curve_choice)

Create a new public / private ECDSA key pair on specified curve and implementation

Parameters
curve_idElliptic curve to use
Returns
Key pair

◆ make_public_key() [1/3]

PublicKeyPtr ccf::crypto::make_public_key ( const JsonWebKeyECPublic jwk)

Construct PublicKey from a JsonWebKeyECPublic object

Parameters
jwkJsonWebKeyECPublic object
Returns
Public key

◆ make_public_key() [2/3]

PublicKeyPtr ccf::crypto::make_public_key ( const Pem pem)

Construct PublicKey from a raw public key in PEM format

Parameters
pemSequence of bytes containing the key in PEM format
Returns
Public key

◆ make_public_key() [3/3]

PublicKeyPtr ccf::crypto::make_public_key ( const std::vector< uint8_t > &  der)

Construct PublicKey from a raw public key in DER format

Parameters
derSequence of bytes containing the key in DER format
Returns
Public key

◆ make_rsa_key_pair() [1/3]

RSAKeyPairPtr ccf::crypto::make_rsa_key_pair ( const JsonWebKeyRSAPrivate jwk)

Create a public / private RSA key pair from existing JsonWebKeyRSAPrivate object

◆ make_rsa_key_pair() [2/3]

RSAKeyPairPtr ccf::crypto::make_rsa_key_pair ( const Pem pem)

Create a public / private RSA key pair from existing private key data

◆ make_rsa_key_pair() [3/3]

RSAKeyPairPtr ccf::crypto::make_rsa_key_pair ( size_t  public_key_size = RSAKeyPair::default_public_key_size,
size_t  public_exponent = RSAKeyPair::default_public_exponent 
)

Create a new public / private RSA key pair with specified size and exponent

◆ make_rsa_public_key() [1/4]

RSAPublicKeyPtr ccf::crypto::make_rsa_public_key ( const JsonWebKeyRSAPublic jwk)

◆ make_rsa_public_key() [2/4]

RSAPublicKeyPtr ccf::crypto::make_rsa_public_key ( const Pem pem)

◆ make_rsa_public_key() [3/4]

RSAPublicKeyPtr ccf::crypto::make_rsa_public_key ( const std::vector< uint8_t > &  der)

◆ make_rsa_public_key() [4/4]

RSAPublicKeyPtr ccf::crypto::make_rsa_public_key ( const uint8_t *  data,
size_t  size 
)

◆ make_unique_verifier() [1/2]

VerifierUniquePtr ccf::crypto::make_unique_verifier ( const Pem pem)

Construct Verifier from a certificate in PEM format

Parameters
pemThe certificate containing a public key

◆ make_unique_verifier() [2/2]

VerifierUniquePtr ccf::crypto::make_unique_verifier ( const std::vector< uint8_t > &  cert)

Construct Verifier from a certificate in DER or PEM format

Parameters
certThe certificate containing a public key

◆ make_verifier() [1/2]

VerifierPtr ccf::crypto::make_verifier ( const Pem pem)

Construct Verifier from a certificate in PEM format

Parameters
pemThe certificate containing a public key

◆ make_verifier() [2/2]

VerifierPtr ccf::crypto::make_verifier ( const std::vector< uint8_t > &  cert)

Construct a certificate verifier

Parameters
certThe certificate containing a public key
Returns
A verifier

◆ openssl_sha256()

void ccf::crypto::openssl_sha256 ( const std::span< const uint8_t > &  data,
uint8_t *  h 
)

◆ openssl_sha256_init()

void ccf::crypto::openssl_sha256_init ( )

To be called once per thread, before calling the ccf::crypto::sha256 functions (sha256.h) or calling internal CCF code making use of them.

Typical CCF application code does NOT need to make these calls, they are exposed for unit tests that use ccfcrypto.a directly and skip typical initialization and shutdown.

These calls exist to create and cache an EVP_MD_CTX per thread and amortise creation costs that can be substantial fraction of the total hashing time for small messages.

◆ openssl_sha256_shutdown()

void ccf::crypto::openssl_sha256_shutdown ( )

◆ operator!=()

bool ccf::crypto::operator!= ( const Sha256Hash lhs,
const Sha256Hash rhs 
)

◆ operator<<()

std::ostream & ccf::crypto::operator<< ( std::ostream &  os,
const ccf::crypto::Sha256Hash h 
)

◆ operator==()

bool ccf::crypto::operator== ( const Sha256Hash lhs,
const Sha256Hash rhs 
)

◆ public_key_der_from_cert()

std::vector< uint8_t > ccf::crypto::public_key_der_from_cert ( const std::vector< uint8_t > &  der)

◆ public_key_pem_from_cert()

ccf::crypto::Pem ccf::crypto::public_key_pem_from_cert ( const std::vector< uint8_t > &  der)

◆ public_key_pem_from_csr()

Pem ccf::crypto::public_key_pem_from_csr ( const Pem signing_request)

Extracts the public key from a certificate signing request (CSR).

Parameters
signing_requestCSR to extract the public key from
Returns
extracted public key

◆ raw_from_b64()

std::vector< uint8_t > ccf::crypto::raw_from_b64 ( const std::string_view &  b64_string)

◆ raw_from_b64url()

std::vector< uint8_t > ccf::crypto::raw_from_b64url ( const std::string_view &  b64url_string)

◆ schema_name() [1/2]

std::string ccf::crypto::schema_name ( const Pem )
inline

◆ schema_name() [2/2]

std::string ccf::crypto::schema_name ( const Sha256Hash hash)

◆ sha256() [1/3]

std::vector< uint8_t > ccf::crypto::sha256 ( const std::span< uint8_t const > &  data)

Compute the SHA256 hash of data

Parameters
dataThe data to compute the hash of
Returns
hashed value

◆ sha256() [2/3]

std::vector< uint8_t > ccf::crypto::sha256 ( const std::vector< uint8_t > &  data)

◆ sha256() [3/3]

std::vector< uint8_t > ccf::crypto::sha256 ( const uint8_t *  data,
size_t  len 
)

Compute the SHA256 hash of data

Parameters
dataThe data to compute the hash of
lenLength of the data
Returns
hashed value

◆ split_x509_cert_bundle()

std::vector< ccf::crypto::Pem > ccf::crypto::split_x509_cert_bundle ( const std::string_view &  pem)

◆ to_json() [1/2]

void ccf::crypto::to_json ( nlohmann::json &  j,
const Pem p 
)
inline

◆ to_json() [2/2]

void ccf::crypto::to_json ( nlohmann::json &  j,
const Sha256Hash hash 
)

Variable Documentation

◆ GCM_DEFAULT_KEY_SIZE

constexpr size_t ccf::crypto::GCM_DEFAULT_KEY_SIZE = 32
constexpr

◆ GCM_SIZE_TAG

constexpr size_t ccf::crypto::GCM_SIZE_TAG = 16
constexpr