00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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;
00085 BF_KEY essiv_clef;
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,
00091 const std::string & salt,
00092 U_I iteration_count,
00093 U_I output_length);
00094 void dar_set_key(const std::string & key);
00095 void self_test(void);
00096 };
00097
00098 }
00099
00100 #endif