blob: 1d95a8a01ae68e249f2d8d4cf7943956f58a6da4 [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
Ben Chanc45688b2014-07-02 23:50:45 -07005#ifndef SHILL_CRYPTO_DES_CBC_H_
6#define SHILL_CRYPTO_DES_CBC_H_
Darin Petkov823c47e2011-06-27 16:15:35 -07007
Alex Vakulenko8a532292014-06-16 17:18:44 -07008#include <string>
Darin Petkov823c47e2011-06-27 16:15:35 -07009#include <vector>
10
Ben Chancc67c522014-09-03 07:19:18 -070011#include <base/macros.h>
Darin Petkov823c47e2011-06-27 16:15:35 -070012#include <gtest/gtest_prod.h> // for FRIEND_TEST
13
14#include "shill/crypto_interface.h"
15
Paul Stewart5ad16062013-02-21 18:10:48 -080016namespace base {
17
Darin Petkov823c47e2011-06-27 16:15:35 -070018class FilePath;
19
Paul Stewart5ad16062013-02-21 18:10:48 -080020} // namespace base
21
Darin Petkov823c47e2011-06-27 16:15:35 -070022namespace shill {
23
24class GLib;
25
26// DES-CBC crypto module implementation.
27class CryptoDESCBC : public CryptoInterface {
28 public:
29 static const char kID[];
30
Paul Stewarta794cd62015-06-16 13:13:10 -070031 explicit CryptoDESCBC(GLib* glib);
Darin Petkov823c47e2011-06-27 16:15:35 -070032
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.
Paul Stewarta794cd62015-06-16 13:13:10 -070036 bool LoadKeyMatter(const base::FilePath& path);
Darin Petkov823c47e2011-06-27 16:15:35 -070037
38 // Inherited from CryptoInterface.
39 virtual std::string GetID();
Paul Stewarta794cd62015-06-16 13:13:10 -070040 virtual bool Encrypt(const std::string& plaintext, std::string* ciphertext);
41 virtual bool Decrypt(const std::string& ciphertext, std::string* plaintext);
Darin Petkov823c47e2011-06-27 16:15:35 -070042
Paul Stewarta794cd62015-06-16 13:13:10 -070043 const std::vector<char>& key() const { return key_; }
44 const std::vector<char>& iv() const { return iv_; }
Darin Petkov823c47e2011-06-27 16:15:35 -070045
46 private:
47 FRIEND_TEST(CryptoDESCBCTest, Decrypt);
48 FRIEND_TEST(CryptoDESCBCTest, Encrypt);
49
Eric Shienbroodc74cf9c2012-03-02 15:00:35 -050050 static const unsigned int kBlockSize;
Darin Petkov823c47e2011-06-27 16:15:35 -070051 static const char kSentinel[];
52 static const char kVersion2Prefix[];
53
Paul Stewarta794cd62015-06-16 13:13:10 -070054 GLib* glib_;
Darin Petkov823c47e2011-06-27 16:15:35 -070055 std::vector<char> key_;
56 std::vector<char> iv_;
Darin Petkov86964e02011-06-29 13:49:28 -070057
58 DISALLOW_COPY_AND_ASSIGN(CryptoDESCBC);
Darin Petkov823c47e2011-06-27 16:15:35 -070059};
60
61} // namespace shill
62
Ben Chanc45688b2014-07-02 23:50:45 -070063#endif // SHILL_CRYPTO_DES_CBC_H_