1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef SYNC_UTIL_NIGORI_H_
6 #define SYNC_UTIL_NIGORI_H_
10 #include "base/memory/scoped_ptr.h"
18 // A (partial) implementation of Nigori, a protocol to securely store secrets in
19 // the cloud. This implementation does not support server authentication or
20 // assisted key derivation.
22 // To store secrets securely, use the |Permute| method to derive a lookup name
23 // for your secret (basically a map key), and |Encrypt| and |Decrypt| to store
24 // and retrieve the secret.
36 // Initialize the client with the given |hostname|, |username| and |password|.
37 bool InitByDerivation(const std::string
& hostname
,
38 const std::string
& username
,
39 const std::string
& password
);
41 // Initialize the client by importing the given keys instead of deriving new
43 bool InitByImport(const std::string
& user_key
,
44 const std::string
& encryption_key
,
45 const std::string
& mac_key
);
47 // Derives a secure lookup name from |type| and |name|. If |hostname|,
48 // |username| and |password| are kept constant, a given |type| and |name| pair
49 // always yields the same |permuted| value. Note that |permuted| will be
51 bool Permute(Type type
, const std::string
& name
, std::string
* permuted
) const;
53 // Encrypts |value|. Note that on success, |encrypted| will be Base64
55 bool Encrypt(const std::string
& value
, std::string
* encrypted
) const;
57 // Decrypts |value| into |decrypted|. It is assumed that |value| is Base64
59 bool Decrypt(const std::string
& value
, std::string
* decrypted
) const;
61 // Exports the raw derived keys.
62 bool ExportKeys(std::string
* user_key
,
63 std::string
* encryption_key
,
64 std::string
* mac_key
) const;
66 static const char kSaltSalt
[]; // The salt used to derive the user salt.
67 static const size_t kSaltKeySizeInBits
= 128;
68 static const size_t kDerivedKeySizeInBits
= 128;
69 static const size_t kIvSize
= 16;
70 static const size_t kHashSize
= 32;
72 static const size_t kSaltIterations
= 1001;
73 static const size_t kUserIterations
= 1002;
74 static const size_t kEncryptionIterations
= 1003;
75 static const size_t kSigningIterations
= 1004;
78 scoped_ptr
<crypto::SymmetricKey
> user_key_
;
79 scoped_ptr
<crypto::SymmetricKey
> encryption_key_
;
80 scoped_ptr
<crypto::SymmetricKey
> mac_key_
;
85 #endif // SYNC_UTIL_NIGORI_H_