crypto_des_cbc.h revision d887589550018383cf6aa09e4c5313b067651891
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_H_
6#define SHILL_CRYPTO_DES_CBC_H_
7
8#include <string>
9#include <vector>
10
11#include <base/macros.h>
12#include <gtest/gtest_prod.h>  // for FRIEND_TEST
13
14#include "shill/crypto_interface.h"
15
16namespace base {
17
18class FilePath;
19
20}  // namespace base
21
22namespace shill {
23
24// DES-CBC crypto module implementation.
25class CryptoDESCBC : public CryptoInterface {
26 public:
27  static const char kID[];
28
29  CryptoDESCBC();
30
31  // Sets the DES key to the last |kBlockSize| bytes of |key_matter_path| and
32  // the DES initialization vector to the second to last |kBlockSize| bytes of
33  // |key_matter_path|. Returns true on success.
34  bool LoadKeyMatter(const base::FilePath& path);
35
36  // Inherited from CryptoInterface.
37  virtual std::string GetID();
38  virtual bool Encrypt(const std::string& plaintext, std::string* ciphertext);
39  virtual bool Decrypt(const std::string& ciphertext, std::string* plaintext);
40
41  const std::vector<char>& key() const { return key_; }
42  const std::vector<char>& iv() const { return iv_; }
43
44 private:
45  FRIEND_TEST(CryptoDESCBCTest, Decrypt);
46  FRIEND_TEST(CryptoDESCBCTest, Encrypt);
47
48  static const unsigned int kBlockSize;
49  static const char kSentinel[];
50  static const char kVersion2Prefix[];
51
52  std::vector<char> key_;
53  std::vector<char> iv_;
54
55  DISALLOW_COPY_AND_ASSIGN(CryptoDESCBC);
56};
57
58}  // namespace shill
59
60#endif  // SHILL_CRYPTO_DES_CBC_H_
61