mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-03 06:35:08 -04:00
compilation fix for openssl-1.1.0 (pqissl+authssl part)
This commit is contained in:
parent
57bbd15893
commit
5c95b88095
9 changed files with 190 additions and 52 deletions
|
@ -52,9 +52,8 @@ bool RsAES::aes_crypt_8_16(const uint8_t *input_data,uint32_t input_data_length,
|
|||
return false ;
|
||||
}
|
||||
|
||||
EVP_CIPHER_CTX e_ctx ;
|
||||
EVP_CIPHER_CTX_init(&e_ctx);
|
||||
EVP_EncryptInit_ex(&e_ctx, EVP_aes_256_cbc(), NULL, key, iv);
|
||||
EVP_CIPHER_CTX *e_ctx = EVP_CIPHER_CTX_new();
|
||||
EVP_EncryptInit_ex(e_ctx, EVP_aes_256_cbc(), NULL, key, iv);
|
||||
|
||||
/* max ciphertext len for a n bytes of plaintext is n + AES_BLOCK_SIZE -1 bytes */
|
||||
int c_len = input_data_length + AES_BLOCK_SIZE ;
|
||||
|
@ -62,31 +61,31 @@ bool RsAES::aes_crypt_8_16(const uint8_t *input_data,uint32_t input_data_length,
|
|||
|
||||
if(output_data_length < (uint32_t)c_len)
|
||||
{
|
||||
EVP_CIPHER_CTX_cleanup(&e_ctx) ;
|
||||
EVP_CIPHER_CTX_free(e_ctx) ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
/* update ciphertext, c_len is filled with the length of ciphertext generated,
|
||||
*len is the size of plaintext in bytes */
|
||||
|
||||
if(!EVP_EncryptUpdate(&e_ctx, output_data, &c_len, input_data, input_data_length))
|
||||
if(!EVP_EncryptUpdate(e_ctx, output_data, &c_len, input_data, input_data_length))
|
||||
{
|
||||
std::cerr << "RsAES: decryption failed at end. Check padding." << std::endl;
|
||||
EVP_CIPHER_CTX_cleanup(&e_ctx) ;
|
||||
EVP_CIPHER_CTX_free(e_ctx) ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
/* update ciphertext with the final remaining bytes */
|
||||
if(!EVP_EncryptFinal_ex(&e_ctx, output_data+c_len, &f_len))
|
||||
if(!EVP_EncryptFinal_ex(e_ctx, output_data+c_len, &f_len))
|
||||
{
|
||||
std::cerr << "RsAES: decryption failed at end. Check padding." << std::endl;
|
||||
EVP_CIPHER_CTX_cleanup(&e_ctx) ;
|
||||
EVP_CIPHER_CTX_free(e_ctx) ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
output_data_length = c_len + f_len;
|
||||
|
||||
EVP_CIPHER_CTX_cleanup(&e_ctx) ;
|
||||
EVP_CIPHER_CTX_free(e_ctx) ;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -108,9 +107,8 @@ bool RsAES::aes_decrypt_8_16(const uint8_t *input_data,uint32_t input_data_lengt
|
|||
return false ;
|
||||
}
|
||||
|
||||
EVP_CIPHER_CTX e_ctx ;
|
||||
EVP_CIPHER_CTX_init(&e_ctx);
|
||||
EVP_DecryptInit_ex(&e_ctx, EVP_aes_256_cbc(), NULL, key, iv);
|
||||
EVP_CIPHER_CTX *e_ctx = EVP_CIPHER_CTX_new();
|
||||
EVP_DecryptInit_ex(e_ctx, EVP_aes_256_cbc(), NULL, key, iv);
|
||||
|
||||
/* max ciphertext len for a n bytes of plaintext is n + AES_BLOCK_SIZE -1 bytes */
|
||||
int c_len = input_data_length + AES_BLOCK_SIZE ;
|
||||
|
@ -118,7 +116,7 @@ bool RsAES::aes_decrypt_8_16(const uint8_t *input_data,uint32_t input_data_lengt
|
|||
|
||||
if(output_data_length < (uint32_t)c_len)
|
||||
{
|
||||
EVP_CIPHER_CTX_cleanup(&e_ctx) ;
|
||||
EVP_CIPHER_CTX_free(e_ctx) ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
|
@ -127,24 +125,24 @@ bool RsAES::aes_decrypt_8_16(const uint8_t *input_data,uint32_t input_data_lengt
|
|||
/* update ciphertext, c_len is filled with the length of ciphertext generated,
|
||||
*len is the size of plaintext in bytes */
|
||||
|
||||
if(! EVP_DecryptUpdate(&e_ctx, output_data, &c_len, input_data, input_data_length))
|
||||
if(! EVP_DecryptUpdate(e_ctx, output_data, &c_len, input_data, input_data_length))
|
||||
{
|
||||
std::cerr << "RsAES: decryption failed." << std::endl;
|
||||
EVP_CIPHER_CTX_cleanup(&e_ctx) ;
|
||||
EVP_CIPHER_CTX_free(e_ctx) ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
/* update ciphertext with the final remaining bytes */
|
||||
if(!EVP_DecryptFinal_ex(&e_ctx, output_data+c_len, &f_len))
|
||||
if(!EVP_DecryptFinal_ex(e_ctx, output_data+c_len, &f_len))
|
||||
{
|
||||
std::cerr << "RsAES: decryption failed at end. Check padding." << std::endl;
|
||||
EVP_CIPHER_CTX_cleanup(&e_ctx) ;
|
||||
EVP_CIPHER_CTX_free(e_ctx) ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
output_data_length = c_len + f_len;
|
||||
|
||||
EVP_CIPHER_CTX_cleanup(&e_ctx) ;
|
||||
EVP_CIPHER_CTX_free(e_ctx) ;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "util/rsrecogn.h"
|
||||
#include "util/radix64.h"
|
||||
#include "util/rsstring.h"
|
||||
#include "util/rsdir.h"
|
||||
|
||||
#include "gxs/gxssecurity.h"
|
||||
|
||||
|
@ -507,9 +508,23 @@ bool RsRecogn::itemToRadix64(RsItem *item, std::string &radstr)
|
|||
|
||||
std::string RsRecogn::getRsaKeyId(RSA *pubkey)
|
||||
{
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
int len = BN_num_bytes(pubkey -> n);
|
||||
unsigned char tmp[len];
|
||||
BN_bn2bin(pubkey -> n, tmp);
|
||||
#else
|
||||
const BIGNUM *nn=NULL ;
|
||||
RSA_get0_key(pubkey,&nn,NULL,NULL) ;
|
||||
|
||||
int len = BN_num_bytes(nn);
|
||||
unsigned char tmp[len];
|
||||
BN_bn2bin(nn, tmp);
|
||||
#endif
|
||||
|
||||
return RsDirUtil::sha1sum(tmp,len).toStdString();
|
||||
|
||||
#ifdef OLD_VERSION_REMOVED
|
||||
// (cyril) I removed this because this is cryptographically insane, as it allows to easily forge a RSA key with the same ID.
|
||||
|
||||
// copy first CERTSIGNLEN bytes...
|
||||
if (len > CERTSIGNLEN)
|
||||
|
@ -524,6 +539,7 @@ std::string RsRecogn::getRsaKeyId(RSA *pubkey)
|
|||
}
|
||||
|
||||
return id;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue