Example #1
0
bool emv_pk_verify(const struct emv_pk *pk)
{
	struct crypto_hash *ch = crypto_hash_open(pk->hash_algo);
	if (!ch)
		return false;

	crypto_hash_write(ch, pk->rid, sizeof(pk->rid));
	crypto_hash_write(ch, &pk->index, 1);
	crypto_hash_write(ch, pk->modulus, pk->mlen);
	crypto_hash_write(ch, pk->exp, pk->elen);

	unsigned char *h = crypto_hash_read(ch);
	if (!h)
		return false;

	bool r = memcmp(h, pk->hash, 20) ? false : true;

	crypto_hash_close(ch);

	return r;
}
Example #2
0
bool emv_pk_verify(const struct emv_pk *pk)
{
	struct crypto_hash *ch = crypto_hash_open(pk->hash_algo);
	if (!ch)
		return false;

	crypto_hash_write(ch, pk->rid, sizeof(pk->rid));
	crypto_hash_write(ch, &pk->index, 1);
	crypto_hash_write(ch, pk->modulus, pk->mlen);
	crypto_hash_write(ch, pk->exp, pk->elen);

	unsigned char *h = crypto_hash_read(ch);
	if (!h) {
		crypto_hash_close(ch);
		return false;
	}

	size_t hsize = crypto_hash_get_size(ch);
	bool r = hsize && !memcmp(h, pk->hash, hsize) ? true : false;

	crypto_hash_close(ch);

	return r;
}
Example #3
0
static int sda_test_raw(void)
{
	const struct emv_pk *pk = &vsdc_01;

	struct crypto_pk *kcp = crypto_pk_open(PK_RSA,
			pk->modulus, pk->mlen,
			pk->exp, pk->elen);
	if (!kcp)
		return 1;

	unsigned char *ipk_data;
	size_t ipk_data_len;
	ipk_data = crypto_pk_encrypt(kcp, issuer_cert, sizeof(issuer_cert), &ipk_data_len);
	crypto_pk_close(kcp);

	if (!ipk_data)
		return 1;

	dump_buffer(ipk_data, ipk_data_len, stdout);

	size_t ipk_pk_len = ipk_data[13];
	unsigned char *ipk_pk = malloc(ipk_pk_len);
	memcpy(ipk_pk, ipk_data + 15, ipk_data_len - 36);
	memcpy(ipk_pk + ipk_data_len - 36, issuer_rem, sizeof(issuer_rem));

	struct crypto_hash *ch;
	ch = crypto_hash_open(HASH_SHA_1);
	if (!ch) {
		free(ipk_pk);
		free(ipk_data);
		return 1;
	}

	crypto_hash_write(ch, ipk_data + 1, 14);
	crypto_hash_write(ch, ipk_pk, ipk_pk_len);
	crypto_hash_write(ch, issuer_exp, sizeof(issuer_exp));

	unsigned char *h = crypto_hash_read(ch);
	if (!h) {
		crypto_hash_close(ch);
		free(ipk_pk);
		free(ipk_data);
		return 1;
	}

	dump_buffer(h, 20, stdout);

	if (memcmp(ipk_data + ipk_data_len - 21, h, 20)) {
		crypto_hash_close(ch);
		free(ipk_pk);
		free(ipk_data);
		return 1;
	}

	crypto_hash_close(ch);
	free(ipk_data);

	struct crypto_pk *ikcp = crypto_pk_open(PK_RSA, ipk_pk, (int) ipk_pk_len,
			issuer_exp, (int) sizeof(issuer_exp));
	free(ipk_pk);
	if (!ikcp)
		return 1;

	size_t ssad_len;
	unsigned char *ssad = crypto_pk_encrypt(ikcp, ssad_cr, sizeof(ssad_cr), &ssad_len);
	crypto_pk_close(ikcp);
	if (!ssad)
		return 1;

	dump_buffer(ssad, ssad_len, stdout);

	ch = crypto_hash_open(HASH_SHA_1);
	if (!ch) {
		free(ssad);
		return 1;
	}

	crypto_hash_write(ch, ssad + 1, ssad_len - 22);
	crypto_hash_write(ch, ssd1, sizeof(ssd1));

	unsigned char *h2 = crypto_hash_read(ch);
	if (!h2) {
		crypto_hash_close(ch);
		free(ssad);
		return 1;
	}

	dump_buffer(h2, 20, stdout);

	crypto_hash_close(ch);

	free(ssad);

	return 0;
}