DiceKeys Seeded Cryptography Library
Recipe Class Reference

This class parses a recipe string on construction and then exposes the Recipe JSON Universal Fields as fields of this class. More...

#include <recipe.hpp>

Public Member Functions

 Recipe (const std::string &recipe, const RecipeJson::type typeRequired=RecipeJson::type::_INVALID_TYPE_)
 
const std::string recipeWithAllOptionalParametersSpecified (int indent=-1, const char indent_char=' ') const
 Return JSON with default parameters filled in. More...
 
const SodiumBuffer derivePrimarySecret (const std::string &seedString, const RecipeJson::type defaultType=RecipeJson::type::_INVALID_TYPE_) const
 This function derives the master secrets for SymmetricKey, for the SealingKey and UnsealingKey pair, for the SignatureVerificationKey and SigningKey pair, and for the general-purpose Secret class. More...
 

Static Public Member Functions

static const SodiumBuffer derivePrimarySecret (const std::string &seedString, const std::string &recipe, const RecipeJson::type typeRequired=RecipeJson::type::_INVALID_TYPE_, const size_t lengthInBytesRequired=0)
 This function derives the master secrets for SymmetricKey, for the SealingKey and UnsealingKey pair, for the SignatureVerificationKey and SigningKey pair, and for the general-purpose Secret class. More...
 

Public Attributes

RecipeJson::Algorithm algorithm
 Mirroring the JSON field in Recipe JSON Universal Fields.
 
const std::string recipe
 The original JSON string used to construct this object.
 
RecipeJson::type type
 Mirroring the JSON field in Recipe JSON Universal Fields.
 
unsigned int lengthInBytes = 0
 Mirroring the JSON field in Recipe JSON Universal Fields.
 
unsigned int lengthInBits = 0
 Mirroring the JSON field in Recipe JSON Universal Fields.
 
size_t lengthInChars = -1
 Mirroring the JSON field in Recipe JSON Universal Fields.
 
unsigned int lengthInWords = 0
 Mirroring the JSON field in Recipe JSON Universal Fields.
 
RecipeJson::WordList wordList = RecipeJson::WordList::_INVALID_WORD_LIST_
 Mirroring the JSON field in Recipe JSON Universal Fields.
 
size_t hashFunctionMemoryLimitInBytes
 Mirroring the JSON field in Recipe JSON Universal Fields.
 
size_t hashFunctionMemoryPasses
 Mirroring the JSON field in Recipe JSON Universal Fields.
 
RecipeJson::HashFunction hashFunction
 The name of the hash function specified in the Recipe JSON Universal Fields.
 

Detailed Description

This class parses a recipe string on construction and then exposes the Recipe JSON Universal Fields as fields of this class.

Constructor & Destructor Documentation

◆ Recipe()

Recipe::Recipe ( const std::string &  recipe,
const RecipeJson::type  typeRequired = RecipeJson::type::_INVALID_TYPE_ 
)

Create a Recipe class from the JSON representation of the key generation options.

Parameters
recipeThe JSON formatted recipe object to parse as specified by JSON Format for Recipes
typeRequiredThe required type, which will be the default if the JSON doesn't contain a type field and which will cause an exception to be thrown if the JSON has a conflicting type. If not set (default: RecipeJson::type::INVALID_TYPE) there is no required type and any type is allowed.
Exceptions
InvalidRecipeJsonException
InvalidRecipeValueException

Member Function Documentation

◆ derivePrimarySecret() [1/2]

const SodiumBuffer Recipe::derivePrimarySecret ( const std::string &  seedString,
const RecipeJson::type  defaultType = RecipeJson::type::_INVALID_TYPE_ 
) const

This function derives the master secrets for SymmetricKey, for the SealingKey and UnsealingKey pair, for the SignatureVerificationKey and SigningKey pair, and for the general-purpose Secret class.

It applies the hash function specified in the recipe to a preimage of the following form:

<seedString> + '\0' + <type> + <recipe>

where type is converted to a string in ["Secret", "SymmetricKey", "UnsealingKey", "SigningKey"], based on the value of the type parameter, defaultType if type is not set (INVALID_TYPE), or "" if neither is set (both are INVALID_TYPE).

  • For "Secret" and "Password", the generated secret is placed directly into the secretBytes field of the Secret class.
  • For "SymmetricKey", the generated secret becomes the keyBytes field of the SymmetricKey class.
  • For "UnsealingKey", the generated secret is the final parameter (input) to libsodium's crypto_box_seed_keypair function, which generates the key bytes for the UnsealingKey and SealingKey.
  • For "SigningKey", the generated secret is the final parameter (input) to libsodium's crypto_sign_seed_keypair function, which generates the key bytes for the SigningKey and SignatureVerificationKey..
Parameters
seedStringA seed value that is the primary salt for the hash function
defaultTypeIf the recipe has a type field, and that field specifies a value other than this typeRequired value, this function will throw an InvalidRecipeValueException.
Returns
const SodiumBuffer The derived secret, set to always be a const so that it is never modified directly.
Exceptions
InvalidRecipeValueException

◆ derivePrimarySecret() [2/2]

const SodiumBuffer Recipe::derivePrimarySecret ( const std::string &  seedString,
const std::string &  recipe,
const RecipeJson::type  typeRequired = RecipeJson::type::_INVALID_TYPE_,
const size_t  lengthInBytesRequired = 0 
)
static

This function derives the master secrets for SymmetricKey, for the SealingKey and UnsealingKey pair, for the SignatureVerificationKey and SigningKey pair, and for the general-purpose Secret class.

It applies the hash function specified in the recipe to a preimage of the following form:

<seedString> + '\0' + <typeRequired> + <recipe>

where typeRequired is converted to a string in ["Secret", "SymmetricKey", "UnsealingKey", "SigningKey"], based on the value of the typeRequired parameter.

  • For "Secret", the generated secret is placed directly into the secretBytes field of the Secret class.
  • For "SymmetricKey", the generated secret becomes the keyBytes field of the SymmetricKey class.
  • For "UnsealingKey", the generated secret is the final parameter (input) to libsodium's crypto_box_seed_keypair function, which generates the key bytes for the UnsealingKey and SealingKey.
  • For "SigningKey", the generated secret is the final parameter (input) to libsodium's crypto_sign_seed_keypair function, which generates the key bytes for the SigningKey and SignatureVerificationKey..
Parameters
seedStringA seed value that is the primary salt for the hash function
recipeThe recipe in JSON Format for Recipes.
typeRequiredIf the recipe has a type field, and that field specifies a value other than this typeRequired value, this function will throw an InvalidRecipeValueException.
lengthInBytesRequiredIf the recipe does not specify a lengthInBytes, generate a secret of this length. Throw an InvalidRecipeValueException is the lengthInBytes it specifies does not match this value.
Returns
const SodiumBuffer The derived secret, set to always be a const so that it is never modified directly.
Exceptions
InvalidRecipeValueException
InvalidRecipeJsonException

◆ recipeWithAllOptionalParametersSpecified()

const std::string Recipe::recipeWithAllOptionalParametersSpecified ( int  indent = -1,
const char  indent_char = ' ' 
) const

Return JSON with default parameters filled in.

Parameters
indentJSON indent depth
indent_charThe char used for JSON indenting

The documentation for this class was generated from the following files:
Recipe::type
RecipeJson::type type
Mirroring the JSON field in Recipe JSON Universal Fields.
Definition: recipe.hpp:44
Recipe::recipe
const std::string recipe
The original JSON string used to construct this object.
Definition: recipe.hpp:39