Add more error checks to RSA_do_sign().

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@539 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
Andreas Schneider
2009-04-18 09:44:50 +00:00
parent 4308bb559c
commit 038e6411da

View File

@@ -1080,28 +1080,37 @@ void signature_free(SIGNATURE *sign) {
} }
#ifdef HAVE_LIBCRYPTO #ifdef HAVE_LIBCRYPTO
/* maybe the missing function from libcrypto */ /*
/* i think now, maybe it's a bad idea to name it has it should have be named in libcrypto */ * Maybe the missing function from libcrypto
static STRING *RSA_do_sign(void *payload,int len,RSA *privkey){ *
STRING *sign; * I think now, maybe it's a bad idea to name it has it should have be
void *buffer; * named in libcrypto
unsigned int size; */
int err; static STRING *RSA_do_sign(const unsigned char *payload, int len, RSA *privkey) {
STRING *sign = NULL;
unsigned char *buffer = NULL;
unsigned int size;
buffer = malloc(RSA_size(privkey)); buffer = malloc(RSA_size(privkey));
if (buffer == NULL) { if (buffer == NULL) {
return NULL; return NULL;
} }
err=RSA_sign(NID_sha1,payload,len,buffer,&size,privkey); if (RSA_sign(NID_sha1, payload, len, buffer, &size, privkey) == 0) {
if(!err){ SAFE_FREE(buffer);
free(buffer); return NULL;
return NULL; }
}
sign=string_new(size); sign = string_new(size);
string_fill(sign,buffer,size); if (sign == NULL) {
free(buffer); SAFE_FREE(buffer);
return sign; return NULL;
}
string_fill(sign, buffer, size);
SAFE_FREE(buffer);
return sign;
} }
#endif #endif