tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

enctool.h (2639B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #ifndef enctool_h__
      6 #define enctool_h__
      7 
      8 #include <string>
      9 #include <vector>
     10 #include "argparse.h"
     11 #include "nss_scoped_ptrs.h"
     12 #include "prerror.h"
     13 #include "tool.h"
     14 
     15 class EncTool : public Tool {
     16 public:
     17  bool Run(const std::vector<std::string>& arguments) override;
     18  void Usage() override;
     19 
     20 private:
     21  typedef bool (EncTool::*key_func_t)(const std::vector<uint8_t>& aad,
     22                                      ScopedSECItem& chacha_key,
     23                                      ScopedSECItem& params);
     24  void PrintBytes(const std::vector<uint8_t>& bytes, const std::string& txt);
     25  bool WriteBytes(const std::vector<uint8_t>& bytes, std::string out_file);
     26  void PrintError(const std::string& m, PRErrorCode err, size_t line_number);
     27  void PrintError(const std::string& m, size_t line_number);
     28  bool GetKey(const std::vector<uint8_t>& key_bytes, ScopedSECItem& key_item);
     29  bool GetAesGcmKey(const std::vector<uint8_t>& aad,
     30                    const std::vector<uint8_t>& iv_bytes,
     31                    const std::vector<uint8_t>& key_bytes,
     32                    ScopedSECItem& aes_key, ScopedSECItem& params);
     33  bool GetChachaKey(const std::vector<uint8_t>& aad,
     34                    const std::vector<uint8_t>& iv_bytes,
     35                    const std::vector<uint8_t>& key_bytes,
     36                    ScopedSECItem& chacha_key, ScopedSECItem& params);
     37  bool GenerateAesGcmKey(const std::vector<uint8_t>& aad,
     38                         ScopedSECItem& aes_key, ScopedSECItem& params);
     39  bool ReadAesGcmKey(const std::vector<uint8_t>& aad, ScopedSECItem& aes_key,
     40                     ScopedSECItem& params);
     41  std::vector<uint8_t> GenerateRandomness(size_t num_bytes);
     42  bool GenerateChachaKey(const std::vector<uint8_t>& aad,
     43                         ScopedSECItem& chacha_key, ScopedSECItem& params);
     44  bool ReadChachaKey(const std::vector<uint8_t>& aad, ScopedSECItem& chacha_key,
     45                     ScopedSECItem& params);
     46  bool DoCipher(std::string fileName, std::string outFile, bool encrypt,
     47                key_func_t get_params);
     48  size_t PrintFileSize(std::string fileName);
     49  bool IsValidCommand(ArgParser arguments);
     50 
     51  bool debug_ = false;
     52  bool write_key_ = true;
     53  bool write_iv_ = true;
     54  std::string key_file_ = "/tmp/key";
     55  std::string iv_file_ = "/tmp/iv";
     56  CK_MECHANISM_TYPE cipher_mech_;
     57 
     58  const std::string kAESCommand = "aes";
     59  const std::string kChaChaCommand = "chacha";
     60 };
     61 
     62 #endif  // enctool_h__