1c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//
2c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// Copyright (C) 2011 The Android Open Source Project
3c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//
4c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// Licensed under the Apache License, Version 2.0 (the "License");
5c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// you may not use this file except in compliance with the License.
6c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// You may obtain a copy of the License at
7c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//
8c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//      http://www.apache.org/licenses/LICENSE-2.0
9c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//
10c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// Unless required by applicable law or agreed to in writing, software
11c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// distributed under the License is distributed on an "AS IS" BASIS,
12c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// See the License for the specific language governing permissions and
14c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// limitations under the License.
15c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//
16823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov
17c45688bb3881f0c2216e6ec0e19ebda0be33e871Ben Chan#ifndef SHILL_CRYPTO_DES_CBC_H_
18c45688bb3881f0c2216e6ec0e19ebda0be33e871Ben Chan#define SHILL_CRYPTO_DES_CBC_H_
19823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov
208a5322984f2d81bcbfd8d44c59747a11bd9b904bAlex Vakulenko#include <string>
21823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov#include <vector>
22823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov
23cc67c52a2c00f90e877971d552208dd99825d84eBen Chan#include <base/macros.h>
24823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov#include <gtest/gtest_prod.h>  // for FRIEND_TEST
25823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov
26823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov#include "shill/crypto_interface.h"
27823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov
285ad1606ad8b3f74b2b7960a3003a2d1ca75d52b8Paul Stewartnamespace base {
295ad1606ad8b3f74b2b7960a3003a2d1ca75d52b8Paul Stewart
30823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkovclass FilePath;
31823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov
325ad1606ad8b3f74b2b7960a3003a2d1ca75d52b8Paul Stewart}  // namespace base
335ad1606ad8b3f74b2b7960a3003a2d1ca75d52b8Paul Stewart
34823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkovnamespace shill {
35823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov
36823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov// DES-CBC crypto module implementation.
37823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkovclass CryptoDESCBC : public CryptoInterface {
38823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov public:
39823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov  static const char kID[];
40823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov
41d887589550018383cf6aa09e4c5313b067651891mukesh agrawal  CryptoDESCBC();
42823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov
43823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov  // Sets the DES key to the last |kBlockSize| bytes of |key_matter_path| and
44823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov  // the DES initialization vector to the second to last |kBlockSize| bytes of
45823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov  // |key_matter_path|. Returns true on success.
46a794cd60a7339d576ea2eed263a4f0a20fb255afPaul Stewart  bool LoadKeyMatter(const base::FilePath& path);
47823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov
48823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov  // Inherited from CryptoInterface.
49823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov  virtual std::string GetID();
50a794cd60a7339d576ea2eed263a4f0a20fb255afPaul Stewart  virtual bool Encrypt(const std::string& plaintext, std::string* ciphertext);
51a794cd60a7339d576ea2eed263a4f0a20fb255afPaul Stewart  virtual bool Decrypt(const std::string& ciphertext, std::string* plaintext);
52823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov
53a794cd60a7339d576ea2eed263a4f0a20fb255afPaul Stewart  const std::vector<char>& key() const { return key_; }
54a794cd60a7339d576ea2eed263a4f0a20fb255afPaul Stewart  const std::vector<char>& iv() const { return iv_; }
55823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov
56823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov private:
57823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov  FRIEND_TEST(CryptoDESCBCTest, Decrypt);
58823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov  FRIEND_TEST(CryptoDESCBCTest, Encrypt);
59823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov
60c74cf9cb439ef518bc00210fe5cd3b121f3079b3Eric Shienbrood  static const unsigned int kBlockSize;
61823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov  static const char kSentinel[];
62823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov  static const char kVersion2Prefix[];
63823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov
64823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov  std::vector<char> key_;
65823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov  std::vector<char> iv_;
6686964e0bae1a38c6817243959026603b4b8c69b7Darin Petkov
6786964e0bae1a38c6817243959026603b4b8c69b7Darin Petkov  DISALLOW_COPY_AND_ASSIGN(CryptoDESCBC);
68823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov};
69823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov
70823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov}  // namespace shill
71823c47e9ce362e6ba66ab21b1aa889a1848e3c4cDarin Petkov
72c45688bb3881f0c2216e6ec0e19ebda0be33e871Ben Chan#endif  // SHILL_CRYPTO_DES_CBC_H_
73