/usr/include/dar/crypto.hpp is in libdar-dev 2.4.15-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | //*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2052 Denis Corbin
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// to contact the author : http://dar.linux.free.fr/email.html
/*********************************************************************/
/// \file crypto.hpp
/// \brief the crypto algoritm definition
/// \ingroup Private
#ifndef CRYPTO_HPP
#define CRYPTO_HPP
extern "C"
{
#if LIBDAR_HAS_GCRYPT_H
#ifndef GCRYPT_NO_DEPRECATED
#define GCRYPT_NO_DEPRECATED
#endif
#include <gcrypt.h>
#endif
}
#include "/usr/include/dar/libdar_my_config.h"
#include <string>
#include "/usr/include/dar/tronconneuse.hpp"
#include "/usr/include/dar/header_version.hpp"
#include "/usr/include/dar/secu_string.hpp"
namespace libdar
{
/// the different cypher available for encryption (strong or weak)
/// values to be used as argument of libdar API calls
/// \ingroup API
enum crypto_algo
{
crypto_none, ///< no encryption
crypto_scrambling, ///< scrambling weak encryption
crypto_blowfish, ///< blowfish strong encryption
crypto_aes256, ///< AES 256 strong encryption
crypto_twofish256, ///< twofish 256 strong encryption
crypto_serpent256, ///< serpent 256 strong encryption
crypto_camellia256 ///< camellia 256 strong encryption
};
/// \ingroup Private
/// @}
extern void crypto_split_algo_pass(const secu_string & all, crypto_algo & algo, secu_string & pass);
inline bool crypto_min_ver_libgcrypt_no_bug()
{
#if CRYPTO_AVAILABLE_FOR_LIBDAR
return gcry_check_version(MIN_LIBDAR_VERSION_GCRYPT_HASH_BUG);
#else
return true;
#endif
}
/// implementation of encryption using symetrical cryptography used in libgcrypt (among which is blowfish)
//
//
/// inherited class from tronconneuse class
/// \ingroup Private
class crypto_sym : public tronconneuse
{
public:
crypto_sym(U_32 block_size,
const secu_string & password,
generic_file & encrypted_side,
bool no_initial_shift,
const archive_version & reading_ver,
crypto_algo algo); //< must be a symetrical algo (else an exception is thrown)
~crypto_sym() { detruit(); };
protected:
U_32 encrypted_block_size_for(U_32 clear_block_size);
U_32 clear_block_allocated_size_for(U_32 clear_block_size);
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);
U_32 decrypt_data(const infinint & block_num,
const char *crypt_buf, const U_32 crypt_size,
char *clear_buf, U_32 clear_size);
private:
#if CRYPTO_AVAILABLE_FOR_LIBDAR
gcry_cipher_hd_t clef; //< used to encrypt/decrypt the data
gcry_cipher_hd_t essiv_clef; //< used to build the Initialization Vector
#endif
size_t algo_block_size; //< the block size of the algorithm
unsigned char *ivec; //< algo_block_size allocated in secure memory to be used as Initial Vector
U_I algo_id; //< algo ID in libgcrypt
archive_version reading_version;
secu_string pkcs5_pass2key(const secu_string & password, //< human provided password
const std::string & salt, //< salt string
U_I iteration_count, //< number of time to shake the melange
U_I output_length); //< length of the string to return
void dar_set_essiv(const secu_string & key); //< assign essiv from the given (hash) string
void make_ivec(const infinint & ref, unsigned char *ivec, U_I size);
void self_test(void);
void detruit();
};
/// @}
} // end of namespace
#endif
|