crypto.hpp

Go to the documentation of this file.
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.1 2007/06/21 19:40:37 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     };
00058 
00059     extern void crypto_split_algo_pass(const std::string & all, crypto_algo & algo, std::string & pass);
00060 
00062 
00065     class blowfish : public tronconneuse
00066     {
00067     public:
00068         blowfish(user_interaction & dialog, U_32 block_size, const std::string & password, generic_file & encrypted_side,
00069                  const dar_version & reading_ver);
00070             // destructor does not seems to be required for BF_KEY
00071 
00072     protected:
00073         U_32 encrypted_block_size_for(U_32 clear_block_size);
00074         U_32 clear_block_allocated_size_for(U_32 clear_block_size);
00075         U_32 encrypt_data(const infinint & block_num,
00076                           const char *clear_buf, const U_32 clear_size, const U_32 clear_allocated,
00077                           char *crypt_buf, U_32 crypt_size);
00078         U_32 decrypt_data(const infinint & block_num,
00079                           const char *crypt_buf, const U_32 crypt_size,
00080                           char *clear_buf, U_32 clear_size);
00081 
00082     private:
00083 #if HAVE_OPENSSL_BLOWFISH_H
00084         BF_KEY clef;       //< used to encrypt/decrypt the data
00085         BF_KEY essiv_clef; //< used to build the Initialization Vector
00086 #endif
00087         dar_version x_reading_ver;
00088 
00089         void make_ivec(const infinint & ref, unsigned char ivec[8]);
00090         std::string pkcs5_pass2key(const std::string & password,         //< human provided password
00091                                    const std::string & salt,             //< salt string
00092                                    U_I iteration_count,                  //< number of time to shake the melange
00093                                    U_I output_length);                   //< length of the string to return
00094         void dar_set_key(const std::string & key);                       //< assign both keys from the given (hash) string
00095         void self_test(void);
00096     };
00097 
00098 } // end of namespace
00099 
00100 #endif

Generated on Sun Jul 1 00:07:07 2007 for Disk ARchive by  doxygen 1.4.7