Beispiel #1
0
int elgv1vrfy(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s)
{
	register size_t size = p->size;
	register mpw* temp;

	if (mpz(r->size, r->data))
		return 0;

	if (mpgex(r->size, r->data, size, p->modl))
		return 0;

	if (mpz(s->size, s->data))
		return 0;

	if (mpgex(s->size, s->data, n->size, n->modl))
		return 0;

	temp = (mpw*) malloc((6*size+2)*sizeof(mpw));

	if (temp)
	{
		register int rc;

		/* compute u1 = y^r mod p */
		mpbpowmod_w(p, y->size, y->data, r->size, r->data, temp, temp+2*size);

		/* compute u2 = r^s mod p */
		mpbpowmod_w(p, r->size, r->data, s->size, s->data, temp+size, temp+2*size);

		/* compute v1 = u1*u2 mod p */
		mpbmulmod_w(p, size, temp, size, temp+size, temp+size, temp+2*size);

		/* compute v2 = g^h(m) mod p */
		mpbpowmod_w(p, g->size, g->data, hm->size, hm->data, temp, temp+2*size);

		rc = mpeq(size, temp, temp+size);

		free(temp);

		return rc;
	}
	return 0;
}
Beispiel #2
0
/*
 * needs workspace of (5*size+2) words
 */
int mppmilraba_w(const mpbarrett* p, const mpw* adata, int s, const mpw* rdata, const mpw* ndata, mpw* wksp)
{
	register size_t size = p->size;
	register int j = 0;

	mpbpowmod_w(p, size, adata, size, rdata, wksp, wksp+size);

	while (1)
	{
		if (mpisone(size, wksp))
			return (j == 0);

		if (mpeq(size, wksp, ndata))
			return 1;

		if (++j < s)
			mpbsqrmod_w(p, size, wksp, wksp, wksp+size);
		else
			return 0;
	}
}