diff --git a/bare_minimum_crypto/cpp/bmc_test.cpp b/bare_minimum_crypto/cpp/bmc_test.cpp index 2f2d199..71e4ddd 100644 --- a/bare_minimum_crypto/cpp/bmc_test.cpp +++ b/bare_minimum_crypto/cpp/bmc_test.cpp @@ -19,9 +19,46 @@ using namespace std; using nlohmann::json; using namespace BareMinimumCrypto; +string get_passphrase_from_user () { + // In prod this would NOT be hard-coded. + return "Correct Horse Battery Staple"; +} + int happy_path () { // We generate a root key and keep it somewhere safe // (offline, hopefully) + + // Passphrases are mandatory for root keys, and BMC also generates + // a salt to maximize entropy. + const auto passphrase = get_passphrase_from_user (); + vector seed; + seed.resize (crypto_sign_SEEDBYTES); + + vector salt; + salt.resize (crypto_pwhash_SALTBYTES); + randombytes_buf (salt.data (), salt.size ()); + + if (crypto_pwhash ( + seed.data (), seed.size (), + passphrase.data (), passphrase.size (), + salt.data (), + crypto_pwhash_OPSLIMIT_INTERACTIVE, crypto_pwhash_MEMLIMIT_INTERACTIVE, + crypto_pwhash_ALG_DEFAULT + ) != 0) { + return 1; + } + + vector pk; + pk.resize (crypto_sign_PUBLICKEYBYTES); + vector sk; + sk.resize (crypto_sign_SECRETKEYBYTES); + + if (crypto_sign_seed_keypair (pk.data (), sk.data (), seed.data ()) != 0) { + return 1; + } + + cerr << "Passphrased root pub key " << base64_encode (pk) << endl; + SigningKey root_key; cerr << "Root pub key " << base64_encode (root_key.pubkey ()) << endl; diff --git a/bare_minimum_crypto/cpp/signing_key.h b/bare_minimum_crypto/cpp/signing_key.h index 6c85f78..6f9f9d2 100644 --- a/bare_minimum_crypto/cpp/signing_key.h +++ b/bare_minimum_crypto/cpp/signing_key.h @@ -17,6 +17,8 @@ namespace BareMinimumCrypto { public: SigningKey (); + //static optional generate_to_file + vector pubkey () const; vector pub_to_msgpack () const;