OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/crypto/symmetric_key.h" | 5 #include "base/crypto/symmetric_key.h" |
6 | 6 |
7 #include <openssl/evp.h> | 7 #include <openssl/evp.h> |
8 #include <openssl/rand.h> | 8 #include <openssl/rand.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/openssl_util.h" | 14 #include "base/openssl_util.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 | 16 |
17 namespace base { | 17 namespace crypto { |
18 | 18 |
19 SymmetricKey::~SymmetricKey() { | 19 SymmetricKey::~SymmetricKey() { |
20 std::fill(key_.begin(), key_.end(), '\0'); // Zero out the confidential key. | 20 std::fill(key_.begin(), key_.end(), '\0'); // Zero out the confidential key. |
21 } | 21 } |
22 | 22 |
23 // static | 23 // static |
24 SymmetricKey* SymmetricKey::GenerateRandomKey(Algorithm algorithm, | 24 SymmetricKey* SymmetricKey::GenerateRandomKey(Algorithm algorithm, |
25 size_t key_size_in_bits) { | 25 size_t key_size_in_bits) { |
26 DCHECK_EQ(AES, algorithm); | 26 DCHECK_EQ(AES, algorithm); |
27 int key_size_in_bytes = key_size_in_bits / 8; | 27 int key_size_in_bytes = key_size_in_bits / 8; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 scoped_ptr<SymmetricKey> key(new SymmetricKey); | 66 scoped_ptr<SymmetricKey> key(new SymmetricKey); |
67 key->key_ = raw_key; | 67 key->key_ = raw_key; |
68 return key.release(); | 68 return key.release(); |
69 } | 69 } |
70 | 70 |
71 bool SymmetricKey::GetRawKey(std::string* raw_key) { | 71 bool SymmetricKey::GetRawKey(std::string* raw_key) { |
72 *raw_key = key_; | 72 *raw_key = key_; |
73 return true; | 73 return true; |
74 } | 74 } |
75 | 75 |
76 } // namespace base | 76 } // namespace crypto |
OLD | NEW |