crypto_des_cbc.h revision 8a5322984f2d81bcbfd8d44c59747a11bd9b904b
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 <string>
9#include <vector>
10
11#include <base/basictypes.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
24class GLib;
25
26// DES-CBC crypto module implementation.
27class CryptoDESCBC : public CryptoInterface {
28 public:
29  static const char kID[];
30
31  explicit CryptoDESCBC(GLib *glib);
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.
36  bool LoadKeyMatter(const base::FilePath &path);
37
38  // Inherited from CryptoInterface.
39  virtual std::string GetID();
40  virtual bool Encrypt(const std::string &plaintext, std::string *ciphertext);
41  virtual bool Decrypt(const std::string &ciphertext, std::string *plaintext);
42
43  const std::vector<char> &key() const { return key_; }
44  const std::vector<char> &iv() const { return iv_; }
45
46 private:
47  FRIEND_TEST(CryptoDESCBCTest, Decrypt);
48  FRIEND_TEST(CryptoDESCBCTest, Encrypt);
49
50  static const unsigned int kBlockSize;
51  static const char kSentinel[];
52  static const char kVersion2Prefix[];
53
54  GLib *glib_;
55  std::vector<char> key_;
56  std::vector<char> iv_;
57
58  DISALLOW_COPY_AND_ASSIGN(CryptoDESCBC);
59};
60
61}  // namespace shill
62
63#endif  // SHILL_CRYPTO_DES_CBC_
64