/* The temporary buffer (t) must have room for at least 4 integers of the size of p.  */
static uint32_t invert_pubexp(uint16_t *d, const uint16_t *m, uint32_t e, uint16_t *t)
/* The temporary buffer (t) must have room for at least 4 integers of the size of p.  */
static uint32_t invert_pubexp(uint16_t *d, const uint16_t *m, uint32_t e, uint16_t *t)
{
	uint16_t *f;
	uint32_t r;
	f = t;
	t += 1 + ((m[0] + 15) >> 4);
	br_i15_zero(d, m[0]);
	d[1] = 1;
	br_i15_zero(f, m[0]);
	f[1] = e & 0x7FFF;
	f[2] = (e >> 15) & 0x7FFF;
	f[3] = e >> 30;
	r = br_i15_moddiv(d, f, m, br_i15_ninv15(m[1]), t);
	br_i15_add(d, m, (uint32_t)(1 - (d[1] & 1)));
	return r;
}