void DH_free(DH *r) { DH_METHOD *meth; int i; if(r == NULL) return; if (r->p != NULL) BN_clear_free(r->p); if (r->g != NULL) BN_clear_free(r->g); if (r->q != NULL) BN_clear_free(r->q); if (r->j != NULL) BN_clear_free(r->j); if (r->seed) rtlglue_free(r->seed); if (r->counter != NULL) BN_clear_free(r->counter); if (r->pub_key != NULL) BN_clear_free(r->pub_key); if (r->priv_key != NULL) BN_clear_free(r->priv_key); rtlglue_free(r); }
RSA *RSA_new_method(RSA_METHOD *meth) { RSA *ret; ret=(RSA *)rtlglue_malloc(sizeof(RSA)); if (ret == NULL) return(NULL); if (meth == NULL) { if((ret->meth=RSA_PKCS1_SSLeay()) == NULL) { rtlglue_free(ret); return NULL; } } else ret->meth=meth; meth = ret->meth; ret->pad=0; ret->version=0; ret->n=NULL; ret->e=NULL; ret->d=NULL; ret->p=NULL; ret->q=NULL; ret->dmp1=NULL; ret->dmq1=NULL; ret->iqmp=NULL; ret->references=1; ret->_method_mod_n=NULL; ret->_method_mod_p=NULL; ret->_method_mod_q=NULL; ret->blinding=NULL; ret->bignum_data=NULL; ret->flags=meth->flags; if ((meth->init != NULL) && !meth->init(ret)) { rtlglue_free(ret); ret=NULL; } return(ret); }
void BN_RECP_CTX_free(BN_RECP_CTX *recp) { if(recp == NULL) return; BN_free(&(recp->N)); BN_free(&(recp->Nr)); if (recp->flags & BN_FLG_MALLOCED) rtlglue_free(recp); }
void BN_MONT_CTX_free(BN_MONT_CTX *mont) { if(mont == NULL) return; BN_free(&(mont->RR)); BN_free(&(mont->N)); BN_free(&(mont->Ni)); if (mont->flags & BN_FLG_MALLOCED) rtlglue_free(mont); }
void RSA_free(RSA *r) { RSA_METHOD *meth; if (r == NULL) return; meth = r->meth; if (meth->finish != NULL) meth->finish(r); if (r->n != NULL) BN_clear_free(r->n); if (r->e != NULL) BN_clear_free(r->e); if (r->d != NULL) BN_clear_free(r->d); if (r->p != NULL) BN_clear_free(r->p); if (r->q != NULL) BN_clear_free(r->q); if (r->dmp1 != NULL) BN_clear_free(r->dmp1); if (r->dmq1 != NULL) BN_clear_free(r->dmq1); if (r->iqmp != NULL) BN_clear_free(r->iqmp); if (r->blinding != NULL) BN_BLINDING_free(r->blinding); rtlglue_free(r); }
static void swNic_dumpPkthdrDescRing(void){ uint32 i, *temp= (uint32 *)rtlglue_malloc(sizeof(uint32)*totalRxPkthdr); uint32 value,asicIdx = ((uint32 *)REG32(CPURPDCR))-RxPkthdrRing; for(i=0;i<totalRxPkthdr;i++) temp[i]=RxPkthdrRing[i]; rtlglue_printf("Rx phdr ring starts at 0x%x\n",(uint32)RxPkthdrRing ); for(i=0;i<totalRxPkthdr;i++){ struct rtl_pktHdr *ph; struct rtl_mBuf *m; value=temp[i]; ph=(struct rtl_pktHdr *)(value &~0x3); rtlglue_printf("%03d.",(uint16)i); if(ph){ rtlglue_printf("p:%08x ",value &~0x3); m=ph->ph_mbuf; if(m) rtlglue_printf("m:%08x c:%08x d:%08x", (uint32)m, (uint32)m->m_extbuf, (uint32)m->m_data); else rtlglue_printf("No mbuf!! "); }else rtlglue_printf("No pkthdr!! "); rtlglue_printf("%s ", ((value & 1)== 0)?"(CPU)":"(SWC)"); if(asicIdx==i) rtlglue_printf("ASIC "); if(rxPhdrIndex==i) rtlglue_printf("Rx "); if(lastReclaim==i) rtlglue_printf("Reclaim "); if((value & 2)== 2){ rtlglue_printf("WRAP!!\n"); return; }else rtlglue_printf("\n"); } rtlglue_free(temp);
static int RSA_eay_public_encrypt(int flen, unsigned char *from, unsigned char *to, RSA *rsa, int padding) { const RSA_METHOD *meth; BIGNUM f,ret; int i,j,k,num=0,r= -1; unsigned char *buf=NULL; BN_CTX *ctx=NULL; meth = rsa->meth; BN_init(&f); BN_init(&ret); if ((ctx=BN_CTX_new()) == NULL) goto err; num=BN_num_bytes(rsa->n); if ((buf=(unsigned char *)rtlglue_malloc(num)) == NULL) goto err; switch (padding) { case RSA_PKCS1_PADDING: i=RSA_padding_add_PKCS1_type_2(buf,num,from,flen); break; case RSA_SSLV23_PADDING: i=RSA_padding_add_SSLv23(buf,num,from,flen); break; case RSA_NO_PADDING: i=RSA_padding_add_none(buf,num,from,flen); break; default: goto err; } if (i <= 0) goto err; if (BN_bin2bn(buf,num,&f) == NULL) goto err; if (BN_ucmp(&f, rsa->n) >= 0) goto err; if ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC)) { BN_MONT_CTX* bn_mont_ctx; if ((bn_mont_ctx=BN_MONT_CTX_new()) == NULL) goto err; if (!BN_MONT_CTX_set(bn_mont_ctx,rsa->n,ctx)) { BN_MONT_CTX_free(bn_mont_ctx); goto err; } if (rsa->_method_mod_n == NULL) /* other thread may have finished first */ { if (rsa->_method_mod_n == NULL) { rsa->_method_mod_n = bn_mont_ctx; bn_mont_ctx = NULL; } } if (bn_mont_ctx) BN_MONT_CTX_free(bn_mont_ctx); } if (!meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx, rsa->_method_mod_n)) goto err; /* put in leading 0 bytes if the number is less than the * length of the modulus */ j=BN_num_bytes(&ret); i=BN_bn2bin(&ret,&(to[num-j])); for (k=0; k<(num-i); k++) to[k]=0; r=num; err: if (ctx != NULL) BN_CTX_free(ctx); BN_clear_free(&f); BN_clear_free(&ret); if (buf != NULL) { memset(buf, 0, num); rtlglue_free(buf); } return(r); }