Example #1
0
int main(int argc, char *argv[])
{
	uint64_t	a[4], b[4], c[8], r[4];
	uint64_t	R[12],S[12];

	//input
	a[3] = 0x32C4AE2C1F198119;
	a[2] = 0x5F9904466A39C994;
	a[1] = 0x8FE30BBFF2660BE1;
	a[0] = 0x715A4589334C74C7;

	b[3] = 0xBC3736A2F4F6779C;
	b[2] = 0x59BDCEE36B692153;
	b[1] = 0xD0A9877CC62A4740;
	b[0] = 0x02DF32E52139F0A0;

	S[3] = 0x32C4AE2C1F198119;
	S[2] = 0x5F9904466A39C994;
	S[1] = 0x8FE30BBFF2660BE1;
	S[0] = 0x715A4589334C74C7;

	S[7] = 0xBC3736A2F4F6779C;
	S[6] = 0x59BDCEE36B692153;
	S[5] = 0xD0A9877CC62A4740;
	S[4] = 0x02DF32E52139F0A0;

	S[11] = 0x0;
	S[10] = 0x0;
	S[9] = 0x0;
	S[8] = 0x1;

	//process
	mp_mul_256(c, a, b);//c = a * b
	mp_mod_sm2(r, c);//r = c mod p
	ec_double_sm2(R, S);
	
	//output
	hex_out(stdout, c, 8); fprintf(stdout, " c = a * b\n");
	hex_out(stdout, r, 4); fprintf(stdout, " r = c mod p\n");
	hex_out(stdout, R, 4); fprintf(stdout, " Rx\n");
	hex_out(stdout, R + 4, 4); fprintf(stdout, " Ry\n");
	hex_out(stdout, R + 8, 4); fprintf(stdout, " Rz\n");

	exit(EXIT_SUCCESS);
}
void traceBUFFER(int operation, HEADER* header,char* buffer, long count)
{
	HEADER hdr;
	memcpy(&hdr, header, sizeof(HEADER));

	if (operation == WRITE_REQUEST_FIRST)
	{
		if (header->swap == 'Y')
			HEADER_swap(&hdr);
		hex_out(   sizeof(HEADER), (char*)&hdr, "HEADER" );
	}
	else if (operation == READ_RESPONSE_FIRST)
	{
		hex_out(  sizeof(HEADER), (char*)&hdr, "HEADER" );
	}
	hex_out(  count, buffer, "DATA" );
	
}
extern "C" VOID SQL_API TraceDebugOut( unsigned int length, char* szBuffer, char* text, int format)
{
#ifndef DISABLE_TRACE
/*
 *  TraceReturn calls GrabErrors(). GrabErrors() goes in and gets diagnostics - now if there is
 *  any kind of debug tracing going on there TraceDebygOut gets called and 
 *  we could get into a problem with deadlocks.  To avoid that condition we will attempt to lock the mutex
 *  if the calling thread owns the lock, EDEADLK will be returned and we can proceed
 *  otherwise EBUSY is returned and we can call the normal lock and wait
 *
 */

	int status;
	int wasAlreadyLocked = false;

	status = g_csWrite.TryLock();

	if(status == EBUSY)
	   EnterCriticalSection2(&g_csWrite);
	else if(status == EDEADLK)
	  wasAlreadyLocked = true;

	if (g_fNoTrace)
	{
		if(!wasAlreadyLocked) 
		   LeaveCriticalSection2(&g_csWrite);
		return;
	}


	if (!fhTraceFile)
	{
		(void) TraceOpenLogFile((LPWSTR)szGlobalTraceFileName,NULL,0);
		if (!fhTraceFile)
		{
			if(!wasAlreadyLocked) 
		       LeaveCriticalSection2(&g_csWrite);
			return;
	}
	}

	if(FORMAT_TEXT==format)
	{
		text_out(szBuffer,text);
	}
	else if(FORMAT_DUMP==format)
	{
		hex_out(length, szBuffer, text);
	}
	fflush(fhTraceFile);

	if(!wasAlreadyLocked) 
	LeaveCriticalSection2(&g_csWrite);
#endif
}
Example #4
0
void do_hexdump (void)
{	char name[16];
	unsigned char *p,*end;
	int i=0,j;
	ULONG count=0;
	header *hd;
	scan_space(); scan_name(name); if (error) return;
	hd=searchvar(name);
	if (!hd) hd=searchudf(name);
	if (error || hd==0) return;
	p=(unsigned char *)hd; end=p+hd->size;
	output1("\n%5lx ",count);
	while (p<end)
	{	hex_out(*p++); i++; count++;
		if (i>=16) 
		{	i=0; string_out(p-16);
			output1("\n%5lx ",count);
			if (test_key()==escape) break;
		}
	}
	for (j=i; j<16; j++) output("   ");
	string_out(p-i);
	output("\n");
}
static void frmt_header(short maxlen, char* ibuffer, FILE* fp)
{
	int ip;
	char operation[40];
	char obuffer[1000];
	char* pbuffer = obuffer;
	HEADER hdr;
	memcpy(&hdr, ibuffer, sizeof(HEADER));
	if (hdr.signature != SIGNATURE)
		hex_out(  sizeof(HEADER), ibuffer, "UNKNOWN HEADER", fp );
	else
	{
		ip=sprintf(pbuffer,"\t<HEADER FORMAT>\n");
		operation[0] = 0;
		if (hdr.operation_id < AS_API_START )
			strcpy(operation,"UNKNOWN_API");
		else if (hdr.operation_id < CFG_API_START )
			FORMAT_AS_APIS(hdr.operation_id, operation);
		else if (hdr.operation_id < SRVR_API_START )
			FORMAT_CFG_APIS(hdr.operation_id, operation);
		else
			FORMAT_SRVR_APIS(hdr.operation_id, operation);
		pbuffer +=ip;ip=sprintf(pbuffer,"\t\t%15.15s\t\t=\t\t%s(%d)\n","operation_id",operation,hdr.operation_id);
		pbuffer +=ip;ip=sprintf(pbuffer,"\t\t%15.15s\t\t=\t\t%ld\n","dialogueId",hdr.dialogueId);
		pbuffer +=ip;ip=sprintf(pbuffer,"\t\t%15.15s\t\t=\t\t%u\n","total_length",hdr.total_length);
		pbuffer +=ip;ip=sprintf(pbuffer,"\t\t%15.15s\t\t=\t\t%u\n","cmp_length",hdr.cmp_length);
		pbuffer +=ip;ip=sprintf(pbuffer,"\t\t%15.15s\t\t=\t\t'%c'\n","compress_ind",hdr.compress_ind);
		pbuffer +=ip;ip=sprintf(pbuffer,"\t\t%15.15s\t\t=\t\t0x%02x\n","compress_type",hdr.compress_type);
		switch(hdr.hdr_type)
		{
		case WRITE_REQUEST_FIRST:
			pbuffer +=ip;ip=sprintf(pbuffer,"\t\t%15.15s\t\t=\t\tWRITE_REQUEST_FIRST(%d)\n","hdr_type",hdr.hdr_type);
			break;
		case WRITE_REQUEST_NEXT:
			pbuffer +=ip;ip=sprintf(pbuffer,"\t\t%15.15s\t\t=\t\tWRITE_REQUEST_NEXT(%d)\n","hdr_type",hdr.hdr_type);
			break;
		case READ_RESPONSE_FIRST:
			pbuffer +=ip;ip=sprintf(pbuffer,"\t\t%15.15s\t\t=\t\tREAD_RESPONSE_FIRST(%d)\n","hdr_type",hdr.hdr_type);
			break;
		case READ_RESPONSE_NEXT:
			pbuffer +=ip;ip=sprintf(pbuffer,"\t\t%15.15s\t\t=\t\tREAD_RESPONSE_NEXT(%d)\n","hdr_type",hdr.hdr_type);
			break;
		case CLEANUP:
			pbuffer +=ip;ip=sprintf(pbuffer,"\t\t%15.15s\t\t=\t\tCLEANUP(%d)\n","hdr_type",hdr.hdr_type);
			break;
		case SRVR_TRANSPORT_ERROR:
			pbuffer +=ip;ip=sprintf(pbuffer,"\t\t%15.15s\t\t=\t\tSRVR_TRANSPORT_ERROR(%d)\n","hdr_type",hdr.hdr_type);
			break;
		case CLOSE_TCPIP_SESSION:
			pbuffer +=ip;ip=sprintf(pbuffer,"\t\t%15.15s\t\t=\t\tCLOSE_TCPIP_SESSION(%d)\n","hdr_type",hdr.hdr_type);
			break;
		default:
			pbuffer +=ip;ip=sprintf(pbuffer,"\t\t%15.15s\t\t=\t\tUNKNOWN(%d)\n","hdr_type",hdr.hdr_type);
			break;
		}
		pbuffer +=ip;ip=sprintf(pbuffer,"\t\t%15.15s\t\t=\t\t%u\n","signature",hdr.signature);
		pbuffer +=ip;ip=sprintf(pbuffer,"\t\t%15.15s\t\t=\t\t%u\n","version",hdr.version);
		pbuffer +=ip;ip=sprintf(pbuffer,"\t\t%15.15s\t\t=\t\t'%c'\n","platform",hdr.platform);
		pbuffer +=ip;ip=sprintf(pbuffer,"\t\t%15.15s\t\t=\t\t'%c'\n","transport",hdr.transport);
		pbuffer +=ip;ip=sprintf(pbuffer,"\t\t%15.15s\t\t=\t\t'%c'\n","swap",hdr.swap);
		pbuffer +=ip;ip=sprintf(pbuffer,"\t\t%15.15s\t\t=\t\t%d\n","error",hdr.error);
		pbuffer +=ip;ip=sprintf(pbuffer,"\t\t%15.15s\t\t=\t\t%d\n","error_detail",hdr.error_detail);
		
		fwrite(obuffer, strlen(obuffer),1,fp);
		fwrite("\r\n",2,1,fp);
		fflush(fp);
	}

}
Example #6
0
static int _vprintf_f(putchar_f f, void *ctx, const char *fmt, va_list va)
{
	char c;
	int r = 0;
	int escaped = 0;
	unsigned int longs = 0;
	uint64_t v;

	while ((c = (*fmt++))) {
		if (escaped) {
			switch(c) {
				case '%':
					f(ctx, c);
					r++;
					break;
				case 'p':
					r += hex_out(f, ctx, (uintptr_t) va_arg(va, void *));
					break;
				case 'u':
				case 'd':
				case 'x':
					switch (longs) {
					default:
						v = va_arg(va, unsigned int);
						break;
					case 1:
						v = va_arg(va, long unsigned int);
						break;
					case 2:
						v = va_arg(va, long long unsigned int);
						break;
					}
					if (c == 'x') {
						r += hex_out(f, ctx, v);
					} else {
						r += dec_out(f, ctx, v);
					}
					break;
				case 'c':
					f(ctx, va_arg(va, int));
					r += 1;
					break;
				case 's':
					r += str_out(f, ctx, va_arg(va, char *));
					break;
				case 'z':
					continue;
				case 'l':
					longs++;
					continue;
				default:
					break;
			}
			escaped = 0;
			longs = 0;
		} else {
			if (c == '%') {
				escaped = 1;
			}
			else
				f(ctx, c);
		}
	}