blob: 079c0d93beed8bad7560b98f0c6b280131eaffbb [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
Paul Stewart5ad16062013-02-21 18:10:48 -080015namespace base {
16
Darin Petkov823c47e2011-06-27 16:15:35 -070017class FilePath;
18
Paul Stewart5ad16062013-02-21 18:10:48 -080019} // namespace base
20
Darin Petkov823c47e2011-06-27 16:15:35 -070021namespace shill {
22
23class GLib;
24
25// DES-CBC crypto module implementation.
26class CryptoDESCBC : public CryptoInterface {
27 public:
28 static const char kID[];
29
Darin Petkov86964e02011-06-29 13:49:28 -070030 explicit CryptoDESCBC(GLib *glib);
Darin Petkov823c47e2011-06-27 16:15:35 -070031
32 // Sets the DES key to the last |kBlockSize| bytes of |key_matter_path| and
33 // the DES initialization vector to the second to last |kBlockSize| bytes of
34 // |key_matter_path|. Returns true on success.
Paul Stewart5ad16062013-02-21 18:10:48 -080035 bool LoadKeyMatter(const base::FilePath &path);
Darin Petkov823c47e2011-06-27 16:15:35 -070036
37 // Inherited from CryptoInterface.
38 virtual std::string GetID();
39 virtual bool Encrypt(const std::string &plaintext, std::string *ciphertext);
40 virtual bool Decrypt(const std::string &ciphertext, std::string *plaintext);
41
42 const std::vector<char> &key() const { return key_; }
43 const std::vector<char> &iv() const { return iv_; }
44
45 private:
46 FRIEND_TEST(CryptoDESCBCTest, Decrypt);
47 FRIEND_TEST(CryptoDESCBCTest, Encrypt);
48
Eric Shienbroodc74cf9c2012-03-02 15:00:35 -050049 static const unsigned int kBlockSize;
Darin Petkov823c47e2011-06-27 16:15:35 -070050 static const char kSentinel[];
51 static const char kVersion2Prefix[];
52
53 GLib *glib_;
54 std::vector<char> key_;
55 std::vector<char> iv_;
Darin Petkov86964e02011-06-29 13:49:28 -070056
57 DISALLOW_COPY_AND_ASSIGN(CryptoDESCBC);
Darin Petkov823c47e2011-06-27 16:15:35 -070058};
59
60} // namespace shill
61
62#endif // SHILL_CRYPTO_DES_CBC_