|
Disk ARchive
2.4.12
|
00001 //*********************************************************************/ 00002 // dar - disk archive - a backup/restoration program 00003 // Copyright (C) 2002-2052 Denis Corbin 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 // 00019 // to contact the author : http://dar.linux.free.fr/email.html 00020 /*********************************************************************/ 00021 00025 00026 #ifndef CRYPTO_HPP 00027 #define CRYPTO_HPP 00028 00029 extern "C" 00030 { 00031 #if HAVE_GCRYPT_H 00032 #include <gcrypt.h> 00033 #endif 00034 } 00035 00036 #include "../my_config.h" 00037 #include <string> 00038 00039 #include "tronconneuse.hpp" 00040 #include "header_version.hpp" 00041 #include "secu_string.hpp" 00042 00043 namespace libdar 00044 { 00045 00047 00050 enum crypto_algo 00051 { 00052 crypto_none, 00053 crypto_scrambling, 00054 crypto_blowfish, 00055 crypto_aes256, 00056 crypto_twofish256, 00057 crypto_serpent256, 00058 crypto_camellia256 00059 }; 00060 00063 00064 extern void crypto_split_algo_pass(const secu_string & all, crypto_algo & algo, secu_string & pass); 00065 00066 00068 // 00069 // 00070 00073 class crypto_sym : public tronconneuse 00074 { 00075 public: 00076 crypto_sym(U_32 block_size, 00077 const secu_string & password, 00078 generic_file & encrypted_side, 00079 bool no_initial_shift, 00080 const archive_version & reading_ver, 00081 crypto_algo algo); //< must be a symetrical algo (else an exception is thrown) 00082 ~crypto_sym() { detruit(); }; 00083 00084 protected: 00085 U_32 encrypted_block_size_for(U_32 clear_block_size); 00086 U_32 clear_block_allocated_size_for(U_32 clear_block_size); 00087 U_32 encrypt_data(const infinint & block_num, 00088 const char *clear_buf, const U_32 clear_size, const U_32 clear_allocated, 00089 char *crypt_buf, U_32 crypt_size); 00090 U_32 decrypt_data(const infinint & block_num, 00091 const char *crypt_buf, const U_32 crypt_size, 00092 char *clear_buf, U_32 clear_size); 00093 00094 private: 00095 #if CRYPTO_AVAILABLE 00096 gcry_cipher_hd_t clef; //< used to encrypt/decrypt the data 00097 gcry_cipher_hd_t essiv_clef; //< used to build the Initialization Vector 00098 #endif 00099 size_t algo_block_size; //< the block size of the algorithm 00100 unsigned char *ivec; //< algo_block_size allocated in secure memory to be used as Initial Vector 00101 U_I algo_id; //< algo ID in libgcrypt 00102 archive_version reading_version; 00103 00104 secu_string pkcs5_pass2key(const secu_string & password, //< human provided password 00105 const std::string & salt, //< salt string 00106 U_I iteration_count, //< number of time to shake the melange 00107 U_I output_length); //< length of the string to return 00108 void dar_set_essiv(const secu_string & key); //< assign essiv from the given (hash) string 00109 void make_ivec(const infinint & ref, unsigned char *ivec, U_I size); 00110 void self_test(void); 00111 void detruit(); 00112 }; 00113 00115 00116 } // end of namespace 00117 00118 #endif
1.7.6.1