• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2011 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef SHILL_CRYPTO_DES_CBC_H_
18 #define SHILL_CRYPTO_DES_CBC_H_
19 
20 #include <string>
21 #include <vector>
22 
23 #include <base/macros.h>
24 #include <gtest/gtest_prod.h>  // for FRIEND_TEST
25 
26 #include "shill/crypto_interface.h"
27 
28 namespace base {
29 
30 class FilePath;
31 
32 }  // namespace base
33 
34 namespace shill {
35 
36 // DES-CBC crypto module implementation.
37 class CryptoDESCBC : public CryptoInterface {
38  public:
39   static const char kID[];
40 
41   CryptoDESCBC();
42 
43   // Sets the DES key to the last |kBlockSize| bytes of |key_matter_path| and
44   // the DES initialization vector to the second to last |kBlockSize| bytes of
45   // |key_matter_path|. Returns true on success.
46   bool LoadKeyMatter(const base::FilePath& path);
47 
48   // Inherited from CryptoInterface.
49   virtual std::string GetID();
50   virtual bool Encrypt(const std::string& plaintext, std::string* ciphertext);
51   virtual bool Decrypt(const std::string& ciphertext, std::string* plaintext);
52 
key()53   const std::vector<char>& key() const { return key_; }
iv()54   const std::vector<char>& iv() const { return iv_; }
55 
56  private:
57   FRIEND_TEST(CryptoDESCBCTest, Decrypt);
58   FRIEND_TEST(CryptoDESCBCTest, Encrypt);
59 
60   static const unsigned int kBlockSize;
61   static const char kSentinel[];
62   static const char kVersion2Prefix[];
63 
64   std::vector<char> key_;
65   std::vector<char> iv_;
66 
67   DISALLOW_COPY_AND_ASSIGN(CryptoDESCBC);
68 };
69 
70 }  // namespace shill
71 
72 #endif  // SHILL_CRYPTO_DES_CBC_H_
73