Disk ARchive  2.4.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
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 #include <gcrypt.h>
33 #endif
34 }
35 
36 #include "../my_config.h"
37 #include <string>
38 
39 #include "tronconneuse.hpp"
40 #include "header_version.hpp"
41 #include "secu_string.hpp"
42 
43 namespace libdar
44 {
45 
47 
51  {
59  };
60 
63 
64  extern void crypto_split_algo_pass(const secu_string & all, crypto_algo & algo, secu_string & pass);
65 
66 
68  //
69  //
70 
73  class crypto_sym : public tronconneuse
74  {
75  public:
76  crypto_sym(U_32 block_size,
77  const secu_string & password,
78  generic_file & encrypted_side,
79  bool no_initial_shift,
80  const archive_version & reading_ver,
81  crypto_algo algo); //< must be a symetrical algo (else an exception is thrown)
82  ~crypto_sym() { detruit(); };
83 
84  protected:
85  U_32 encrypted_block_size_for(U_32 clear_block_size);
86  U_32 clear_block_allocated_size_for(U_32 clear_block_size);
87  U_32 encrypt_data(const infinint & block_num,
88  const char *clear_buf, const U_32 clear_size, const U_32 clear_allocated,
89  char *crypt_buf, U_32 crypt_size);
90  U_32 decrypt_data(const infinint & block_num,
91  const char *crypt_buf, const U_32 crypt_size,
92  char *clear_buf, U_32 clear_size);
93 
94  private:
95 #if CRYPTO_AVAILABLE
96  gcry_cipher_hd_t clef; //< used to encrypt/decrypt the data
97  gcry_cipher_hd_t essiv_clef; //< used to build the Initialization Vector
98 #endif
99  size_t algo_block_size; //< the block size of the algorithm
100  unsigned char *ivec; //< algo_block_size allocated in secure memory to be used as Initial Vector
101  U_I algo_id; //< algo ID in libgcrypt
102  archive_version reading_version;
103 
104  secu_string pkcs5_pass2key(const secu_string & password, //< human provided password
105  const std::string & salt, //< salt string
106  U_I iteration_count, //< number of time to shake the melange
107  U_I output_length); //< length of the string to return
108  void dar_set_essiv(const secu_string & key); //< assign essiv from the given (hash) string
109  void make_ivec(const infinint & ref, unsigned char *ivec, U_I size);
110  void self_test(void);
111  void detruit();
112  };
113 
115 
116 } // end of namespace
117 
118 #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:905
twofish 256 strong encryption
Definition: crypto.hpp:56
void crypto_split_algo_pass(const secu_string &all, crypto_algo &algo, secu_string &pass)
camellia 256 strong encryption
Definition: crypto.hpp:58
archive global header structure is defined here
crypto_algo
the different cypher available for encryption (strong or weak)
Definition: crypto.hpp:50
serpent 256 strong encryption
Definition: crypto.hpp:57
implementation of encryption using symetrical cryptography used in libgcrypt (among which is blowfish...
Definition: crypto.hpp:73
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:52
blowfish strong encryption
Definition: crypto.hpp:54
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
class archive_version manages the version of the archive format
scrambling weak encryption
Definition: crypto.hpp:53
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:55
this file contains the definition of secu_string class, a std::string like class but allocated in sec...