Exemplo n.º 1
0
Arquivo: ec.c Projeto: Arikado/SCEkrit
int ecdsa_set_curve(u32 type)
{
	if (ecdsa_get_params(type, ec_p, ec_a, ec_b, ec_N, ec_G.x, ec_G.y) < 0)
		return -1;

	bn_to_mon(ec_a, ec_p, 20);
	bn_to_mon(ec_b, ec_p, 20);

	point_to_mon(&ec_G);

	return 0;
}
Exemplo n.º 2
0
Arquivo: ec.c Projeto: lyvius/ps3tools
int ecdsa_set_curve(u32 type)
{
	if (ecdsa_get_params(type, ec_p, ec_a, ec_b, ec_N, ec_G.x, ec_G.y) < 0)
		return -1;
	bn_print("p", ec_p, 20);
	bn_print("a", ec_a, 20);
	bn_print("b", ec_b, 20);
	bn_print("N", ec_N, 21);
	bn_print("Gx", ec_G.x, 20);
	bn_print("Gy", ec_G.y, 20);

	bn_to_mon(ec_a, ec_p, 20);
	bn_to_mon(ec_b, ec_p, 20);

	point_to_mon(&ec_G);

	return 0;
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
	if (argc != 3)
		fail("usage: scesekrit signedfile1 signedfile2");

	ptr1 = mmap_file(argv[1]);
	ptr2 = mmap_file(argv[2]);

	type = be16(ptr1 + 0x0a);
	if (type != be16(ptr2 + 0x0a))
		fail("Files must be the same type");
	
	if (type == 1) {
		read_self_header(ptr1, &info1);
	} else if(type == 3) {
		read_pkg_header(ptr1, &info1);
	} else
		fail("Unknown type: %d", type);

	if ((info1.flags) & 0x8000)
		fail("devkit file; nothing to verify");

	if (klist == NULL)
		fail("no key found");

	decrypt(ptr1);
	
	if (type == 1) {
		read_self_header(ptr2, &info2);
	} else if(type == 3) {
		read_pkg_header(ptr2, &info2);
	} else
		fail("Unknown type: %d", type);

	if ((info2.flags) & 0x8000)
		fail("devkit file; nothing to verify");

	if (klist == NULL)
		fail("no key found");

	decrypt(ptr2);

	u8* s1;
	u8* s2;
	u8 z1[21];
	u8 z2[21];
	u8* r1;
	u8* r2;
	u8 ec[21];
	u8 n[21];
	z1[0] = 0;
	z2[0] = 0;
	
	ecdsa_get_params(klist->keys[keyid].ctype, ec, ec, ec, n, ec, ec);

	printf("%s ", argv[1]);
	verify_signature(ptr1, &info1, z1 + 1, &s1, &r1);
	printf("%s ", argv[2]);
	verify_signature(ptr2, &info2, z2 + 1, &s2, &r2);

	if (memcmp(r1, r2, 21))
		fail("Both files must share the same r signature value.");

	const char* dA = calculate_private_key(s1, s2, z1, z2, n, r1);

	int len = strlen(dA);
	int i;
	printf("Private Key: ");
	for (i = len / 2; i < 21; i++)
		printf("00");
	printf("%s\n", dA);

	return 0;
}