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 | |
| 15 | class FilePath; |
| 16 | |
| 17 | namespace shill { |
| 18 | |
| 19 | class GLib; |
| 20 | |
| 21 | // DES-CBC crypto module implementation. |
| 22 | class CryptoDESCBC : public CryptoInterface { |
| 23 | public: |
| 24 | static const char kID[]; |
| 25 | |
Darin Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 26 | explicit CryptoDESCBC(GLib *glib); |
Darin Petkov | 823c47e | 2011-06-27 16:15:35 -0700 | [diff] [blame] | 27 | |
| 28 | // Sets the DES key to the last |kBlockSize| bytes of |key_matter_path| and |
| 29 | // the DES initialization vector to the second to last |kBlockSize| bytes of |
| 30 | // |key_matter_path|. Returns true on success. |
| 31 | bool LoadKeyMatter(const FilePath &path); |
| 32 | |
| 33 | // Inherited from CryptoInterface. |
| 34 | virtual std::string GetID(); |
| 35 | virtual bool Encrypt(const std::string &plaintext, std::string *ciphertext); |
| 36 | virtual bool Decrypt(const std::string &ciphertext, std::string *plaintext); |
| 37 | |
| 38 | const std::vector<char> &key() const { return key_; } |
| 39 | const std::vector<char> &iv() const { return iv_; } |
| 40 | |
| 41 | private: |
| 42 | FRIEND_TEST(CryptoDESCBCTest, Decrypt); |
| 43 | FRIEND_TEST(CryptoDESCBCTest, Encrypt); |
| 44 | |
| 45 | static const int kBlockSize; |
| 46 | static const char kSentinel[]; |
| 47 | static const char kVersion2Prefix[]; |
| 48 | |
| 49 | GLib *glib_; |
| 50 | std::vector<char> key_; |
| 51 | std::vector<char> iv_; |
Darin Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 52 | |
| 53 | DISALLOW_COPY_AND_ASSIGN(CryptoDESCBC); |
Darin Petkov | 823c47e | 2011-06-27 16:15:35 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | } // namespace shill |
| 57 | |
| 58 | #endif // SHILL_CRYPTO_DES_CBC_ |