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