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