mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-08 11:05:49 -05:00
change ssl binary encryption to aes
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5.0@2535 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
acaeeff4a4
commit
2abed326bd
@ -1633,20 +1633,20 @@ bool AuthSSL::encrypt(void *&out, int &outlen, const void *in, int inlen, std
|
|||||||
out = malloc(inlen + 2048);
|
out = malloc(inlen + 2048);
|
||||||
|
|
||||||
/// ** from demos/maurice/example1.c of openssl V1.0 *** ///
|
/// ** from demos/maurice/example1.c of openssl V1.0 *** ///
|
||||||
unsigned char * iv = new unsigned char [EVP_MAX_IV_LENGTH];
|
unsigned char * iv = new unsigned char [16];
|
||||||
memset(iv, '\0', sizeof(iv));
|
memset(iv, '\0', 16);
|
||||||
unsigned char * ek = new unsigned char [EVP_PKEY_size(public_key) + 1024];
|
unsigned char * ek = new unsigned char [EVP_PKEY_size(public_key) + 1024];
|
||||||
uint32_t ekl, net_ekl;
|
uint32_t ekl, net_ekl;
|
||||||
unsigned char * cryptBuff = new unsigned char [inlen + 1024];
|
unsigned char * cryptBuff = new unsigned char [inlen + 16];
|
||||||
memset(cryptBuff, '\0', sizeof(cryptBuff));
|
memset(cryptBuff, '\0', sizeof(cryptBuff));
|
||||||
int cryptBuffL = 0;
|
int cryptBuffL = 0;
|
||||||
unsigned char key[EVP_MAX_KEY_LENGTH];
|
unsigned char key[256];
|
||||||
|
|
||||||
/// ** copied implementation of EVP_SealInit of openssl V1.0 *** ///;
|
/// ** copied implementation of EVP_SealInit of openssl V1.0 *** ///;
|
||||||
EVP_CIPHER_CTX cipher_ctx;
|
EVP_CIPHER_CTX cipher_ctx;
|
||||||
EVP_CIPHER_CTX_init(&cipher_ctx);
|
EVP_CIPHER_CTX_init(&cipher_ctx);
|
||||||
|
|
||||||
if(!EVP_EncryptInit_ex(&cipher_ctx,EVP_des_ede3_cbc(),NULL,NULL,NULL)) {
|
if(!EVP_EncryptInit_ex(&cipher_ctx,EVP_aes_256_cbc(),NULL,NULL,NULL)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1673,8 +1673,8 @@ bool AuthSSL::encrypt(void *&out, int &outlen, const void *in, int inlen, std
|
|||||||
memcpy((void*)((unsigned long int)out + (unsigned long int)out_offset), ek, ekl);
|
memcpy((void*)((unsigned long int)out + (unsigned long int)out_offset), ek, ekl);
|
||||||
out_offset += ekl;
|
out_offset += ekl;
|
||||||
|
|
||||||
memcpy((void*)((unsigned long int)out + (unsigned long int)out_offset), iv, sizeof(iv));
|
memcpy((void*)((unsigned long int)out + (unsigned long int)out_offset), iv, 16);
|
||||||
out_offset += sizeof(iv);
|
out_offset += 16;
|
||||||
|
|
||||||
EVP_EncryptUpdate(&cipher_ctx, cryptBuff, &cryptBuffL, (unsigned char*)in, inlen);
|
EVP_EncryptUpdate(&cipher_ctx, cryptBuff, &cryptBuffL, (unsigned char*)in, inlen);
|
||||||
memcpy((void*)((unsigned long int)out + (unsigned long int)out_offset), cryptBuff, cryptBuffL);
|
memcpy((void*)((unsigned long int)out + (unsigned long int)out_offset), cryptBuff, cryptBuffL);
|
||||||
@ -1712,14 +1712,14 @@ bool AuthSSL::decrypt(void *&out, int &outlen, const void *in, int inlen)
|
|||||||
// out = malloc(inlen);
|
// out = malloc(inlen);
|
||||||
// memcpy(out, in, inlen);
|
// memcpy(out, in, inlen);
|
||||||
// outlen = inlen;
|
// outlen = inlen;
|
||||||
out = malloc(inlen + 2048);
|
out = malloc(inlen + 16);
|
||||||
int in_offset = 0;
|
int in_offset = 0;
|
||||||
unsigned char * buf = new unsigned char [inlen + 1024];
|
unsigned char * buf = new unsigned char [inlen + 16];
|
||||||
memset(buf, '\0', sizeof(buf));
|
memset(buf, '\0', sizeof(buf));
|
||||||
int buflen = 0;
|
int buflen = 0;
|
||||||
EVP_CIPHER_CTX ectx;
|
EVP_CIPHER_CTX ectx;
|
||||||
unsigned char * iv = new unsigned char [EVP_MAX_IV_LENGTH];
|
unsigned char * iv = new unsigned char [16];
|
||||||
memset(iv, '\0', sizeof(iv));
|
memset(iv, '\0', 16);
|
||||||
unsigned char *encryptKey;
|
unsigned char *encryptKey;
|
||||||
unsigned int ekeylen;
|
unsigned int ekeylen;
|
||||||
|
|
||||||
@ -1740,8 +1740,8 @@ bool AuthSSL::decrypt(void *&out, int &outlen, const void *in, int inlen)
|
|||||||
memcpy(encryptKey, (void*)((unsigned long int)in + (unsigned long int)in_offset), ekeylen);
|
memcpy(encryptKey, (void*)((unsigned long int)in + (unsigned long int)in_offset), ekeylen);
|
||||||
in_offset += ekeylen;
|
in_offset += ekeylen;
|
||||||
|
|
||||||
memcpy(iv, (void*)((unsigned long int)in + (unsigned long int)in_offset), sizeof(iv));
|
memcpy(iv, (void*)((unsigned long int)in + (unsigned long int)in_offset), 16);
|
||||||
in_offset += sizeof(iv);
|
in_offset += 16;
|
||||||
|
|
||||||
// EVP_OpenInit(&ectx,
|
// EVP_OpenInit(&ectx,
|
||||||
// EVP_des_ede3_cbc(),
|
// EVP_des_ede3_cbc(),
|
||||||
@ -1752,18 +1752,17 @@ bool AuthSSL::decrypt(void *&out, int &outlen, const void *in, int inlen)
|
|||||||
/// ** copied implementation of EVP_SealInit of openssl V1.0 *** ///;
|
/// ** copied implementation of EVP_SealInit of openssl V1.0 *** ///;
|
||||||
|
|
||||||
unsigned char *key=NULL;
|
unsigned char *key=NULL;
|
||||||
int i,size=0;
|
int i=0;
|
||||||
|
|
||||||
EVP_CIPHER_CTX_init(&ectx);
|
EVP_CIPHER_CTX_init(&ectx);
|
||||||
if(!EVP_DecryptInit_ex(&ectx,EVP_des_ede3_cbc(),NULL, NULL,NULL)) return false;
|
if(!EVP_DecryptInit_ex(&ectx,EVP_aes_256_cbc(),NULL, NULL,NULL)) return false;
|
||||||
|
|
||||||
if (own_private_key->type != EVP_PKEY_RSA)
|
if (own_private_key->type != EVP_PKEY_RSA)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
size=RSA_size(own_private_key->pkey.rsa);
|
key=(unsigned char *)OPENSSL_malloc(256);
|
||||||
key=(unsigned char *)OPENSSL_malloc(size+2);
|
|
||||||
if (key == NULL)
|
if (key == NULL)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user