Disk ARchive  2.4.21
crypto.hpp
Go to the documentation of this file.
1 //*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2052 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21 
25 
26 #ifndef CRYPTO_HPP
27 #define CRYPTO_HPP
28 
29 extern "C"
30 {
31 #if HAVE_GCRYPT_H
32 #ifndef GCRYPT_NO_DEPRECATED
33 #define GCRYPT_NO_DEPRECATED
34 #endif
35 #include <gcrypt.h>
36 #endif
37 }
38 
39 #include "../my_config.h"
40 #include <string>
41 
42 #include "tronconneuse.hpp"
43 #include "header_version.hpp"
44 #include "secu_string.hpp"
45 
46 namespace libdar
47 {
48 
50 
54  {
62  };
63 
66 
67  extern void crypto_split_algo_pass(const secu_string & all, crypto_algo & algo, secu_string & pass);
68  inline bool crypto_min_ver_libgcrypt_no_bug()
69  {
70 #if CRYPTO_AVAILABLE
71  return gcry_check_version(MIN_VERSION_GCRYPT_HASH_BUG);
72 #else
73  return true;
74 #endif
75  }
76 
78  //
79  //
80 
83  class crypto_sym : public tronconneuse
84  {
85  public:
86  crypto_sym(U_32 block_size,
87  const secu_string & password,
88  generic_file & encrypted_side,
89  bool no_initial_shift,
90  const archive_version & reading_ver,
91  crypto_algo algo); //< must be a symetrical algo (else an exception is thrown)
92  ~crypto_sym() { detruit(); };
93 
94  protected:
95  U_32 encrypted_block_size_for(U_32 clear_block_size);
96  U_32 clear_block_allocated_size_for(U_32 clear_block_size);
97  U_32 encrypt_data(const infinint & block_num,
98  const char *clear_buf, const U_32 clear_size, const U_32 clear_allocated,
99  char *crypt_buf, U_32 crypt_size);
100  U_32 decrypt_data(const infinint & block_num,
101  const char *crypt_buf, const U_32 crypt_size,
102  char *clear_buf, U_32 clear_size);
103 
104  private:
105 #if CRYPTO_AVAILABLE
106  gcry_cipher_hd_t clef; //< used to encrypt/decrypt the data
107  gcry_cipher_hd_t essiv_clef; //< used to build the Initialization Vector
108 #endif
109  size_t algo_block_size; //< the block size of the algorithm (main key)
110  unsigned char *ivec; //< algo_block_size allocated in secure memory to be used as Initial Vector
111  U_I algo_id; //< algo ID in libgcrypt
112  archive_version reading_version;
113 
114  secu_string pkcs5_pass2key(const secu_string & password, //< human provided password
115  const std::string & salt, //< salt string
116  U_I iteration_count, //< number of time to shake the melange
117  U_I output_length); //< length of the string to return
118  void dar_set_essiv(const secu_string & key, //< assign essiv from the given (hash) string
119  crypto_algo main_cipher); //< the choice of the algo for essiv depends on the cipher used for the main key
120  void make_ivec(const infinint & ref, unsigned char *ivec, U_I size);
121  void self_test(void);
122  void detruit();
123  };
124 
126 
127 } // end of namespace
128 
129 #endif
this is a partial implementation of the generic_file interface to cypher/decypher data block by block...
the deleted file entry
Definition: catalogue.hpp:912
twofish 256 strong encryption
Definition: crypto.hpp:59
camellia 256 strong encryption
Definition: crypto.hpp:61
archive global header structure is defined here
crypto_algo
the different cypher available for encryption (strong or weak)
Definition: crypto.hpp:53
serpent 256 strong encryption
Definition: crypto.hpp:60
implementation of encryption using symetrical cryptography used in libgcrypt (among which is blowfish...
Definition: crypto.hpp:83
U_32 encrypted_block_size_for(U_32 clear_block_size)
defines the size necessary to encrypt a given amount of clear data
class secu_string
Definition: secu_string.hpp:57
this is the interface class from which all other data transfer classes inherit
U_32 decrypt_data(const infinint &block_num, const char *crypt_buf, const U_32 crypt_size, char *clear_buf, U_32 clear_size)
this method decyphers data
no encryption
Definition: crypto.hpp:55
blowfish strong encryption
Definition: crypto.hpp:57
U_32 clear_block_allocated_size_for(U_32 clear_block_size)
it may be necessary by the inherited class have few more bytes allocated after the clear data given f...
defines a block structured file.Mainly used for strong encryption.
the arbitrary large positive integer class
scrambling weak encryption
Definition: crypto.hpp:56
U_32 encrypt_data(const infinint &block_num, const char *clear_buf, const U_32 clear_size, const U_32 clear_allocated, char *crypt_buf, U_32 crypt_size)
this method encrypts the clear data given
AES 256 strong encryption.
Definition: crypto.hpp:58
this file contains the definition of secu_string class, a std::string like class but allocated in sec...
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:43