diff options
author | mniknami@chromium.org <mniknami@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-02 20:22:25 +0000 |
---|---|---|
committer | mniknami@chromium.org <mniknami@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-02 20:22:25 +0000 |
commit | 9b2057825d45aab8c753c5764228f8e8a069e470 (patch) | |
tree | 5a64a7de6c123f4548b9ee7e3cb312db8dfa7779 /sync/util | |
parent | bebe1d02eb8b14a6e7db2cce1a6d13f556a5390f (diff) | |
download | chromium_src-9b2057825d45aab8c753c5764228f8e8a069e470.zip chromium_src-9b2057825d45aab8c753c5764228f8e8a069e470.tar.gz chromium_src-9b2057825d45aab8c753c5764228f8e8a069e470.tar.bz2 |
Added crypto random-number generator
Added a cryptographic random-number generator to crypto/.
Modified sync to use this function instead.
May also be used by Cloud Print in the future.
Review URL: https://chromiumcodereview.appspot.com/10698177
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149689 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/util')
-rw-r--r-- | sync/util/nigori.cc | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/sync/util/nigori.cc b/sync/util/nigori.cc index f2ee83d..60fc895 100644 --- a/sync/util/nigori.cc +++ b/sync/util/nigori.cc @@ -9,16 +9,15 @@ #include "base/base64.h" #include "base/logging.h" -#include "base/rand_util.h" #include "base/string_util.h" #include "base/sys_byteorder.h" #include "crypto/encryptor.h" #include "crypto/hmac.h" +#include "crypto/random.h" #include "crypto/symmetric_key.h" using base::Base64Encode; using base::Base64Decode; -using base::RandInt; using crypto::Encryptor; using crypto::HMAC; using crypto::SymmetricKey; @@ -154,20 +153,13 @@ bool Nigori::Permute(Type type, const std::string& name, return Base64Encode(output, permuted); } -std::string GenerateRandomString(size_t size) { - // TODO(albertb): Use a secure random function. - std::string random(size, 0); - for (size_t i = 0; i < size; ++i) - random[i] = RandInt(0, 0xff); - return random; -} - // Enc[Kenc,Kmac](value) bool Nigori::Encrypt(const std::string& value, std::string* encrypted) const { if (0U >= value.size()) return false; - std::string iv = GenerateRandomString(kIvSize); + std::string iv; + crypto::RandBytes(WriteInto(&iv, kIvSize + 1), kIvSize); Encryptor encryptor; if (!encryptor.Init(encryption_key_.get(), Encryptor::CBC, iv)) |