Пример #1
0
int main(int argc, char *argv[])
{
	progname = argv[0];

	/* initialize list of moduli */
	init_crypto();

	if (argc > 1)
		pk_verbose_execute = 1;

	vulcanpk_mapping = mapvulcanpk();
	/* initialize chip */
	vulcanpk_init(vulcanpk_mapping);

	calc_dh_shared = calc_dh_shared_vulcanpk;

	perform_t2_test();

	/* shut down */
	unmapvulcanpk(vulcanpk_mapping);

	exit(0);
}
Пример #2
0
int main(int argc, char *argv[])
{
	u_int8_t *mapping;
	u_int8_t aModExpOperandA_l[192];
	u_int8_t aModExpOperandB_l[192];
	u_int8_t aModExpExpectedRes_l[192];
	u_int8_t aModulus_l[192];
	u_int8_t aReciprocal_l[192];
	u_int8_t gtothex[192];
	struct pkprogram expModP;
	
	memset(&expModP, 0, sizeof(expModP));

	progname = argv[0];

	mapping = mapvulcanpk();

	/* initialize chip */
	vulcanpk_init(mapping);

	memcpy(aModExpOperandA_l, aModExpOperandA, 192);
	bigendianize((u_int32_t *)aModExpOperandA_l, 192/sizeof(u_int32_t));

	memcpy(aModExpOperandB_l, aModExpOperandB, 192);
	bigendianize((u_int32_t *)aModExpOperandB_l, 192/sizeof(u_int32_t));

	memcpy(aModExpExpectedRes_l, aModExpExpectedRes, 192);
	bigendianize((u_int32_t *)aModExpExpectedRes_l, 192/sizeof(u_int32_t));

	memcpy(aModulus_l, aModulus, 192);
	bigendianize((u_int32_t *)aModulus_l, 192/sizeof(u_int32_t));

	memcpy(aReciprocal_l, aReciprocal, 192);
	bigendianize((u_int32_t *)aReciprocal_l, 192/sizeof(u_int32_t));

	expModP.valuesLittleEndian = FALSE;

	/* g-value */
	expModP.aValues[0]  = aModExpOperandA_l;
	expModP.aValueLen[0]= 192;

	/* ^x-value */
	expModP.aValues[2]  = aModExpOperandB_l;
	expModP.aValueLen[2]= 192;

	/* register 2 is result. */
	/* register 3 is scratch */
	
	/* M = modulus */
	expModP.aValues[8]  = aModulus_l;
	expModP.aValueLen[8]= 192;

	/* reciprocal M(1) */
	expModP.aValues[9]  = aReciprocal_l;
	expModP.aValueLen[9]= 192;

	/* registers 6,7,8 is M(2),M(3),M(4), scratch */

	expModP.chunksize = 3;  /* *64 = 192 bytes/chunk */
	expModP.oOffset   = 3;  /* B(1) is result */
	expModP.oValue    = gtothex;
	expModP.oValueLen = sizeof(gtothex);

	/* ask to have the exponentiation done now! */
	expModP.pk_program[0]=/* sizes are ModLen=48(*32=1536),
				 EXP_len=1535+1, RED_len=0 */
		(0<<24)|(1535<<8)|(48);
	expModP.pk_program[1]=/* opcode 1100=0xC (mod-exp),
				 with A=0, B=2(6),M=8(24)*/
		(0xC<<24)|(24<<16)|(6<<8)|(0<<0);

	expModP.pk_proglen=2;
	execute_pkprogram(mapping, &expModP);

	printf("got: \n");
	hexdump(gtothex, 0, 192);

	printf("expected: \n");
	hexdump(aModExpExpectedRes_l, 0, 192);

	if(memcmp(gtothex, aModExpExpectedRes_l, 192)==0) {
		printf("SUCCESS\n");
	}

	exit(0);
}