Disk ARchive 2.3.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 : dar.linux@free.fr 00020 /*********************************************************************/ 00021 // $Id: crypto.hpp,v 1.8.2.3 2008/05/09 20:58:27 edrusb Rel $ 00022 // 00023 /*********************************************************************/ 00024 // 00025 00028 00029 #ifndef CRYPTO_HPP 00030 #define CRYPTO_HPP 00031 00032 extern "C" 00033 { 00034 #if HAVE_OPENSSL_BLOWFISH_H 00035 #include <openssl/blowfish.h> 00036 #endif 00037 } 00038 00039 #include "../my_config.h" 00040 #include <string> 00041 00042 #include "tronconneuse.hpp" 00043 #include "header_version.hpp" 00044 00045 namespace libdar 00046 { 00047 00049 00052 enum crypto_algo 00053 { 00054 crypto_none, 00055 crypto_scrambling, 00056 crypto_blowfish, 00057 crypto_blowfish_weak 00058 }; 00059 00060 extern void crypto_split_algo_pass(const std::string & all, crypto_algo & algo, std::string & pass); 00061 00063 00066 class blowfish : public tronconneuse 00067 { 00068 public: 00069 blowfish(user_interaction & dialog, U_32 block_size, const std::string & password, generic_file & encrypted_side, 00070 const dar_version & reading_ver, bool weak_mode); 00071 // destructor does not seems to be required for BF_KEY 00072 00073 protected: 00074 U_32 encrypted_block_size_for(U_32 clear_block_size); 00075 U_32 clear_block_allocated_size_for(U_32 clear_block_size); 00076 U_32 encrypt_data(const infinint & block_num, 00077 const char *clear_buf, const U_32 clear_size, const U_32 clear_allocated, 00078 char *crypt_buf, U_32 crypt_size); 00079 U_32 decrypt_data(const infinint & block_num, 00080 const char *crypt_buf, const U_32 crypt_size, 00081 char *clear_buf, U_32 clear_size); 00082 00083 private: 00084 #if HAVE_OPENSSL_BLOWFISH_H 00085 BF_KEY clef; //< used to encrypt/decrypt the data 00086 BF_KEY essiv_clef; //< used to build the Initialization Vector 00087 #endif 00088 bool x_weak_mode; 00089 dar_version reading_version; 00090 00091 void make_ivec(const infinint & ref, unsigned char ivec[8]); 00092 std::string pkcs5_pass2key(const std::string & password, //< human provided password 00093 const std::string & salt, //< salt string 00094 U_I iteration_count, //< number of time to shake the melange 00095 U_I output_length); //< length of the string to return 00096 void dar_set_key(const std::string & key); //< assign both keys from the given (hash) string 00097 void self_test(void); 00098 }; 00099 00100 } // end of namespace 00101 00102 #endif