Ejemplo n.º 1
0
DH *DH_new_method(void)
	{
	DH_METHOD *meth;
	DH *ret;
	ret=(DH *)rtlglue_malloc(sizeof(DH));

	if (ret == NULL)
		return(NULL);

	ret->meth = DH_OpenSSL();
	meth = ret->meth;
	ret->pad=0;
	ret->version=0;
	ret->p=NULL;
	ret->g=NULL;
	ret->length=0;
	ret->pub_key=NULL;
	ret->priv_key=NULL;
	ret->q=NULL;
	ret->j=NULL;
	ret->seed = NULL;
	ret->seedlen = 0;
	ret->counter = NULL;
	ret->method_mont_p=NULL;
	ret->references = 1;
	ret->flags=meth->flags;
	return(ret);
	}
Ejemplo n.º 2
0
BN_RECP_CTX *BN_RECP_CTX_new(void)
	{
	BN_RECP_CTX *ret;

	if ((ret=(BN_RECP_CTX *)rtlglue_malloc(sizeof(BN_RECP_CTX))) == NULL)
		return(NULL);

	BN_RECP_CTX_init(ret);
	ret->flags=BN_FLG_MALLOCED;
	return(ret);
	}
Ejemplo n.º 3
0
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);
	}
Ejemplo n.º 4
0
/* signing */
static int RSA_eay_private_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;
	int local_blinding = 0;
	BN_BLINDING *blinding = 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_1(buf,num,from,flen);
		break;
	case RSA_NO_PADDING:
		i=RSA_padding_add_none(buf,num,from,flen);
		break;
	case RSA_SSLV23_PADDING:
	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;

	BLINDING_HELPER(rsa, ctx, goto err;);
Ejemplo n.º 5
0
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);
Ejemplo n.º 6
0
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);
	}