crypto.hpp
Go to the documentation of this file.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 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
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;
00086 BF_KEY essiv_clef;
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,
00093 const std::string & salt,
00094 U_I iteration_count,
00095 U_I output_length);
00096 void dar_set_key(const std::string & key);
00097 void self_test(void);
00098 };
00099
00100 }
00101
00102 #endif