Implement internally opaque bn access from rsa
Reviewed-by: Tim Hudson <tjh@openssl.org>
This commit is contained in:
@@ -60,7 +60,7 @@
|
||||
#include <openssl/crypto.h>
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/lhash.h>
|
||||
#include <openssl/bn.h>
|
||||
#include "internal/bn_int.h"
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/rand.h>
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
@@ -290,27 +290,27 @@ int RSA_memory_lock(RSA *r)
|
||||
t[3]= &r->dmp1;
|
||||
t[4]= &r->dmq1;
|
||||
t[5]= &r->iqmp;
|
||||
k=sizeof(BIGNUM)*6;
|
||||
k=bn_sizeof_BIGNUM()*6;
|
||||
off=k/sizeof(BN_ULONG)+1;
|
||||
j=1;
|
||||
for (i=0; i<6; i++)
|
||||
j+= (*t[i])->top;
|
||||
j+= bn_get_top(*t[i]);
|
||||
if ((p=OPENSSL_malloc_locked((off+j)*sizeof(BN_ULONG))) == NULL)
|
||||
{
|
||||
RSAerr(RSA_F_RSA_MEMORY_LOCK,ERR_R_MALLOC_FAILURE);
|
||||
return(0);
|
||||
}
|
||||
memset(p, 0, (off+j)*sizeof(BN_ULONG));
|
||||
bn=(BIGNUM *)p;
|
||||
ul=(BN_ULONG *)&(p[off]);
|
||||
for (i=0; i<6; i++)
|
||||
{
|
||||
b= *(t[i]);
|
||||
*(t[i])= &(bn[i]);
|
||||
memcpy((char *)&(bn[i]),(char *)b,sizeof(BIGNUM));
|
||||
bn[i].flags=BN_FLG_STATIC_DATA;
|
||||
bn[i].d=ul;
|
||||
memcpy((char *)ul,b->d,sizeof(BN_ULONG)*b->top);
|
||||
ul+=b->top;
|
||||
*(t[i])= bn_array_el(bn, i);
|
||||
memcpy((char *)bn_array_el(bn, i),(char *)b,bn_sizeof_BIGNUM());
|
||||
memcpy((char *)ul,bn_get_words(b),sizeof(BN_ULONG)*bn_get_top(b));
|
||||
bn_set_static_words(bn_array_el(bn, i), ul, bn_get_top(b));
|
||||
ul+=bn_get_top(b);
|
||||
BN_clear_free(b);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user