Skip to content

Commit

Permalink
DeriveSigningKeysFromSeed now requires info so we can derive keys for…
Browse files Browse the repository at this point in the history
… different purposes with same seed
  • Loading branch information
darkdh committed Jun 9, 2020
1 parent 4275aef commit 0a9b7e6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
5 changes: 3 additions & 2 deletions components/brave_sync/crypto/crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ std::vector<uint8_t> HKDFSha512(const std::vector<uint8_t>& ikm,

void DeriveSigningKeysFromSeed(const std::vector<uint8_t>& seed,
const std::vector<uint8_t>* salt,
const std::vector<uint8_t>* info,
std::vector<uint8_t>* public_key,
std::vector<uint8_t>* private_key) {
DCHECK(public_key);
DCHECK(private_key);
const std::vector<uint8_t> info = {0};
DCHECK(info);
std::vector<uint8_t> output =
HKDFSha512(seed, salt, &info, DEFAULT_SEED_SIZE);
HKDFSha512(seed, salt, info, DEFAULT_SEED_SIZE);
public_key->resize(ED25519_PUBLIC_KEY_LEN);
private_key->resize(ED25519_PRIVATE_KEY_LEN);
ED25519_keypair_from_seed(public_key->data(), private_key->data(),
Expand Down
1 change: 1 addition & 0 deletions components/brave_sync/crypto/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ std::vector<uint8_t> HKDFSha512(const std::vector<uint8_t>& ikm,
// Derives an Ed25519 keypair given a random seed and an optional HKDF salt
void DeriveSigningKeysFromSeed(const std::vector<uint8_t>& seed,
const std::vector<uint8_t>* salt,
const std::vector<uint8_t>* info,
std::vector<uint8_t>* public_key,
std::vector<uint8_t>* private_key);

Expand Down
3 changes: 2 additions & 1 deletion components/brave_sync/crypto/crypto_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ TEST(CryptoTest, Ed25519KeyDerivation) {
&seed);
std::vector<uint8_t> public_key = {};
std::vector<uint8_t> private_key = {};
DeriveSigningKeysFromSeed(seed, &HKDF_SALT, &public_key, &private_key);
std::vector<uint8_t> info = {0};
DeriveSigningKeysFromSeed(seed, &HKDF_SALT, &info, &public_key, &private_key);
EXPECT_EQ("f58ca446f0c33ee7e8e9874466da442b2e764afd77ad46034bdff9e01f9b87d4",
base::ToLowerASCII(
base::HexEncode(public_key.data(), public_key.size())));
Expand Down
4 changes: 3 additions & 1 deletion components/sync/driver/brave_sync_auth_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ void BraveSyncAuthManager::DeriveSigningKeys(const std::string& seed) {
212, 239, 225, 52, 192, 219, 145, 40, 95, 19, 142, 98};
std::vector<uint8_t> seed_bytes;
brave_sync::crypto::PassphraseToBytes32(seed, &seed_bytes);
brave_sync::crypto::DeriveSigningKeysFromSeed(seed_bytes, &HKDF_SALT,
const std::string info_str = "sync-auth-key";
std::vector<uint8_t> info(info_str.begin(), info_str.end());
brave_sync::crypto::DeriveSigningKeysFromSeed(seed_bytes, &HKDF_SALT, &info,
&public_key_, &private_key_);
if (registered_for_auth_notifications_)
UpdateSyncAccountIfNecessary();
Expand Down
10 changes: 5 additions & 5 deletions components/sync/driver/brave_sync_auth_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ const char kSyncCode[] =
"proud cabbage fee slow economy wage final fox cancel";

const char kAccessToken[] =
"MzEzMjMzMzQzNTM2Mzd8RDM0NDYyREVBNzAwQzg0QkVDNjEzMTlCRTk3QTMwOENGMzI2ODM2RD"
"UxM0Y1QjJCODU5RkM3RkU1REJGQjNDQTI2OTFCN0JCODA5NDM5NTgwQzQxNzlCQzYwQzk5Njk5"
"OTdEREMwRTIyRkU1NzQ2ODFFNUQ2QzIyNjkxM0M3MDJ8Rjk5NzNBNzdDQTlDRTRENzhGNDU2ND"
"kwMjUwMEM5NjY3NEQxOEU2QTM3QUU3NjJGODUzRUM5RkZGRDIyNzU1OQ==";
"MzEzMjMzMzQzNTM2Mzd8MDBGNkExNjgxODkxQzU5RDZGMEYwNkVDQ0VGQzBFMTQ3QjA2NDE2RD"
"EzNzE0QkQ3MzE3ODJGRjE1NUZFNjMxMTNBNTE2Qzk2NTFFM0ZGQTEyRDhDMzcyQTcyNUZEMzZG"
"RjE3QUIxMDRDNDVBNTcyMDVCRkIwNjUwRjgxQ0MyMDl8NTAyMDQyMjcwQzgxNDUyNDdFRDcwQT"
"E4Rjg3MDIyQTM5ODg2OTAwQUIzNkYyRkZGNjU1NjM1REJFNTE2NzY1RQ==";

const char kAccountId[] =
"F9973A77CA9CE4D78F4564902500C96674D18E6A37AE762F853EC9FFFD227559";
"502042270C8145247ED70A18F87022A39886900AB36F2FFF655635DBE516765E";

class BraveSyncAuthManagerTest : public testing::Test {
protected:
Expand Down

1 comment on commit 0a9b7e6

@diracdeltas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Please sign in to comment.