Darin Petkov | 823c47e | 2011-06-27 16:15:35 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS 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. |
| 4 | |
| 5 | #ifndef SHILL_CRYPTO_DES_CBC_ |
| 6 | #define SHILL_CRYPTO_DES_CBC_ |
| 7 | |
| 8 | #include <vector> |
| 9 | |
Darin Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 10 | #include <base/basictypes.h> |
Darin Petkov | 823c47e | 2011-06-27 16:15:35 -0700 | [diff] [blame] | 11 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 12 | |
| 13 | #include "shill/crypto_interface.h" |
| 14 | |
Paul Stewart | 5ad1606 | 2013-02-21 18:10:48 -0800 | [diff] [blame] | 15 | namespace base { |
| 16 | |
Darin Petkov | 823c47e | 2011-06-27 16:15:35 -0700 | [diff] [blame] | 17 | class FilePath; |
| 18 | |
Paul Stewart | 5ad1606 | 2013-02-21 18:10:48 -0800 | [diff] [blame] | 19 | } // namespace base |
| 20 | |
Darin Petkov | 823c47e | 2011-06-27 16:15:35 -0700 | [diff] [blame] | 21 | namespace shill { |
| 22 | |
| 23 | class GLib; |
| 24 | |
| 25 | // DES-CBC crypto module implementation. |
| 26 | class CryptoDESCBC : public CryptoInterface { |
| 27 | public: |
| 28 | static const char kID[]; |
| 29 | |
Darin Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 30 | explicit CryptoDESCBC(GLib *glib); |
Darin Petkov | 823c47e | 2011-06-27 16:15:35 -0700 | [diff] [blame] | 31 | |
| 32 | // Sets the DES key to the last |kBlockSize| bytes of |key_matter_path| and |
| 33 | // the DES initialization vector to the second to last |kBlockSize| bytes of |
| 34 | // |key_matter_path|. Returns true on success. |
Paul Stewart | 5ad1606 | 2013-02-21 18:10:48 -0800 | [diff] [blame] | 35 | bool LoadKeyMatter(const base::FilePath &path); |
Darin Petkov | 823c47e | 2011-06-27 16:15:35 -0700 | [diff] [blame] | 36 | |
| 37 | // Inherited from CryptoInterface. |
| 38 | virtual std::string GetID(); |
| 39 | virtual bool Encrypt(const std::string &plaintext, std::string *ciphertext); |
| 40 | virtual bool Decrypt(const std::string &ciphertext, std::string *plaintext); |
| 41 | |
| 42 | const std::vector<char> &key() const { return key_; } |
| 43 | const std::vector<char> &iv() const { return iv_; } |
| 44 | |
| 45 | private: |
| 46 | FRIEND_TEST(CryptoDESCBCTest, Decrypt); |
| 47 | FRIEND_TEST(CryptoDESCBCTest, Encrypt); |
| 48 | |
Eric Shienbrood | c74cf9c | 2012-03-02 15:00:35 -0500 | [diff] [blame] | 49 | static const unsigned int kBlockSize; |
Darin Petkov | 823c47e | 2011-06-27 16:15:35 -0700 | [diff] [blame] | 50 | static const char kSentinel[]; |
| 51 | static const char kVersion2Prefix[]; |
| 52 | |
| 53 | GLib *glib_; |
| 54 | std::vector<char> key_; |
| 55 | std::vector<char> iv_; |
Darin Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 56 | |
| 57 | DISALLOW_COPY_AND_ASSIGN(CryptoDESCBC); |
Darin Petkov | 823c47e | 2011-06-27 16:15:35 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | } // namespace shill |
| 61 | |
| 62 | #endif // SHILL_CRYPTO_DES_CBC_ |