mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
removed asserts and did proper error handling in crypto.c
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7061 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
a8feff606e
commit
257d865804
@ -57,10 +57,20 @@ int ops_decrypt_and_unencode_mpi(unsigned char *buf, unsigned buflen,
|
|||||||
|
|
||||||
mpisize=BN_num_bytes(encmpi);
|
mpisize=BN_num_bytes(encmpi);
|
||||||
/* MPI can't be more than 65,536 */
|
/* MPI can't be more than 65,536 */
|
||||||
assert(mpisize <= sizeof encmpibuf);
|
|
||||||
|
if(!(mpisize <= sizeof encmpibuf)) // ASSERT(mpisize <= sizeof encmpibuf);
|
||||||
|
{
|
||||||
|
fprintf(stderr,"ops_decrypt_and_unencode_mpi: number size too large (%d bytes!).\n",mpisize) ;
|
||||||
|
return -1 ;
|
||||||
|
}
|
||||||
|
|
||||||
BN_bn2bin(encmpi, encmpibuf);
|
BN_bn2bin(encmpi, encmpibuf);
|
||||||
|
|
||||||
assert(skey->public_key.algorithm == OPS_PKA_RSA);
|
if(!(skey->public_key.algorithm == OPS_PKA_RSA)) // ASSERT(skey->public_key.algorithm == OPS_PKA_RSA);
|
||||||
|
{
|
||||||
|
fprintf(stderr,"ops_decrypt_and_unencode_mpi: encryption algorithm %02x is not supported. Sorry.\n",skey->public_key.algorithm) ;
|
||||||
|
return -1 ;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
fprintf(stderr,"\nDECRYPTING\n");
|
fprintf(stderr,"\nDECRYPTING\n");
|
||||||
@ -72,7 +82,9 @@ int ops_decrypt_and_unencode_mpi(unsigned char *buf, unsigned buflen,
|
|||||||
|
|
||||||
n=ops_rsa_private_decrypt(mpibuf, encmpibuf, (BN_num_bits(encmpi)+7)/8,
|
n=ops_rsa_private_decrypt(mpibuf, encmpibuf, (BN_num_bits(encmpi)+7)/8,
|
||||||
&skey->key.rsa, &skey->public_key.key.rsa);
|
&skey->key.rsa, &skey->public_key.key.rsa);
|
||||||
assert(n != -1);
|
|
||||||
|
// if(n == -1) // assert(n != -1);
|
||||||
|
// return ops_false ;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
fprintf(stderr,"decrypted encoded m buf : ");
|
fprintf(stderr,"decrypted encoded m buf : ");
|
||||||
@ -129,14 +141,16 @@ ops_boolean_t ops_rsa_encrypt_mpi(const unsigned char *encoded_m_buf,
|
|||||||
const ops_public_key_t *pkey,
|
const ops_public_key_t *pkey,
|
||||||
ops_pk_session_key_parameters_t *skp)
|
ops_pk_session_key_parameters_t *skp)
|
||||||
{
|
{
|
||||||
assert(sz_encoded_m_buf==(size_t) BN_num_bytes(pkey->key.rsa.n));
|
if(!(sz_encoded_m_buf==(size_t) BN_num_bytes(pkey->key.rsa.n))) // ASSERT(sz_encoded_m_buf==(size_t) BN_num_bytes(pkey->key.rsa.n));
|
||||||
|
return ops_false ;
|
||||||
|
|
||||||
unsigned char encmpibuf[8192];
|
unsigned char encmpibuf[8192];
|
||||||
int n=0;
|
int n=0;
|
||||||
|
|
||||||
n=ops_rsa_public_encrypt(encmpibuf, encoded_m_buf, sz_encoded_m_buf,
|
n=ops_rsa_public_encrypt(encmpibuf, encoded_m_buf, sz_encoded_m_buf, &pkey->key.rsa);
|
||||||
&pkey->key.rsa);
|
|
||||||
assert(n!=-1);
|
//if(!(n!=-1)) // ASSERT(n!=-1);
|
||||||
|
// return ops_false ;
|
||||||
|
|
||||||
if(n <= 0)
|
if(n <= 0)
|
||||||
return ops_false;
|
return ops_false;
|
||||||
@ -213,7 +227,9 @@ ops_boolean_t ops_encrypt_file(const char* input_filename,
|
|||||||
n=read(fd_in, buffer, sizeof buffer);
|
n=read(fd_in, buffer, sizeof buffer);
|
||||||
if (!n)
|
if (!n)
|
||||||
break;
|
break;
|
||||||
assert(n >= 0);
|
|
||||||
|
if(n < 0)
|
||||||
|
return ops_false ;
|
||||||
|
|
||||||
// FIXME: apparently writing can't fail.
|
// FIXME: apparently writing can't fail.
|
||||||
ops_write(buffer, n, cinfo);
|
ops_write(buffer, n, cinfo);
|
||||||
@ -540,7 +556,6 @@ callback_write_parsed(const ops_parser_content_t *content_,
|
|||||||
break;
|
break;
|
||||||
// fprintf(stderr,"Unexpected packet tag=%d (0x%x)\n",content_->tag,
|
// fprintf(stderr,"Unexpected packet tag=%d (0x%x)\n",content_->tag,
|
||||||
// content_->tag);
|
// content_->tag);
|
||||||
// assert(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return OPS_RELEASE_MEMORY;
|
return OPS_RELEASE_MEMORY;
|
||||||
|
Loading…
Reference in New Issue
Block a user