コード例 #1
0
ファイル: usart.c プロジェクト: ChrisDD11/SkyDrop
void USART0_SendData (unsigned char data[], unsigned char length) {
	
	unsigned char i;
	
	for(i=0; i<length; i++) {
		USART0_SendByte(data[i]);
	}
}
コード例 #2
0
ファイル: rsa.c プロジェクト: benxh/Digital-signature
void getLargePrime(uint8_t* arr,uint32_t to){
#if RSADEBUG0==1
	USART0_SendStr("Attempt: ");
#endif
	uint32_t k=0;
	do{
		++k;
		bigRandomTo(arr,to);
		arr[0]|=1;
#if RSADEBUG0==1
		USART0_SendNum(k);
		if(k%20==0)
			USART0_SendStr("\n");
		else
			USART0_SendByte(' ');
		USART0_SendByte('\n');
		bigPrint(arr);
#endif
	}while(!isPrime(arr));
#if RSADEBUG0==1
	USART0_SendStr("\n");
#endif

}
コード例 #3
0
ファイル: rsa.c プロジェクト: benxh/Digital-signature
int32_t millerRabin(uint8_t* n){
	//Most memory requirement part. mem=8*NUMLEN
#if RSADEBUG==1
	USART0_SendStr("Start MR test:\n");
#endif
	if(n[0]&1==0)
		return 0;
	uint32_t t=0;
	int32_t i=0,k;
	uint8_t temp;
	uint8_t s[NUMLEN];
	uint8_t a[NUMLEN];
	int32_t next=0;
	
	bigCopy(s,n);
	s[0]^=1;//s=s-1
	while(!s[i]){
		++i;
		t+=8;
	}	
	temp=s[i];
	while((temp&1)==0){
		++t;
		temp>>=1;
	}
	bigRShift(s,t);
	
	k=0;
	while(k<MILLER_RABIN_K){
#if RSADEBUG==1
		USART0_SendByte('.');
#endif
		n[0]|=1;
		bigRandom(a,n);		
		bigExp(a,s,n);//a=a**s mod n
		n[0]^=1;
		if(!(bigIsOne(a)||bigEqual(a,n))){
			next=0;
			for(i=0;(i<t-1)&&!next;++i){
				n[0]|=1;
				bigMul(a,a,n);
				if(bigIsOne(a)){
#if RSADEBUG==1
					USART0_SendByte(' ');
#endif
					return 0;
				}
				n[0]^=1;
				if(bigEqual(a,n))
					next=1;
			}
			if(!next){
#if RSADEBUG==1
				USART0_SendByte(' ');
#endif
				return 0;
			}
		}
		k+=2;
	}
#if RSADEBUG==1
	USART0_SendStr("\n");
#endif
	n[0]|=1;
	return 1;
}