blob: 80169fe317397579e26946214fdbaaca7689e19a [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
Darin Petkov86964e02011-06-29 13:49:28 -070010#include <base/basictypes.h>
Darin Petkov823c47e2011-06-27 16:15:35 -070011#include <gtest/gtest_prod.h> // for FRIEND_TEST
12
13#include "shill/crypto_interface.h"
14
15class FilePath;
16
17namespace shill {
18
19class GLib;
20
21// DES-CBC crypto module implementation.
22class CryptoDESCBC : public CryptoInterface {
23 public:
24 static const char kID[];
25
Darin Petkov86964e02011-06-29 13:49:28 -070026 explicit CryptoDESCBC(GLib *glib);
Darin Petkov823c47e2011-06-27 16:15:35 -070027
28 // Sets the DES key to the last |kBlockSize| bytes of |key_matter_path| and
29 // the DES initialization vector to the second to last |kBlockSize| bytes of
30 // |key_matter_path|. Returns true on success.
31 bool LoadKeyMatter(const FilePath &path);
32
33 // Inherited from CryptoInterface.
34 virtual std::string GetID();
35 virtual bool Encrypt(const std::string &plaintext, std::string *ciphertext);
36 virtual bool Decrypt(const std::string &ciphertext, std::string *plaintext);
37
38 const std::vector<char> &key() const { return key_; }
39 const std::vector<char> &iv() const { return iv_; }
40
41 private:
42 FRIEND_TEST(CryptoDESCBCTest, Decrypt);
43 FRIEND_TEST(CryptoDESCBCTest, Encrypt);
44
Eric Shienbroodc74cf9c2012-03-02 15:00:35 -050045 static const unsigned int kBlockSize;
Darin Petkov823c47e2011-06-27 16:15:35 -070046 static const char kSentinel[];
47 static const char kVersion2Prefix[];
48
49 GLib *glib_;
50 std::vector<char> key_;
51 std::vector<char> iv_;
Darin Petkov86964e02011-06-29 13:49:28 -070052
53 DISALLOW_COPY_AND_ASSIGN(CryptoDESCBC);
Darin Petkov823c47e2011-06-27 16:15:35 -070054};
55
56} // namespace shill
57
58#endif // SHILL_CRYPTO_DES_CBC_