n = malloc(plen * sizeof(unsigned short));
n = smalloc(plen * sizeof(unsigned short));
void bigmod(Bignum p, Bignum mod, Bignum result, Bignum quotient){    unsigned short *n, *m;    int mshift;    int plen, mlen, i, j;    /* Allocate m of size mlen, copy mod to m */    /* We use big endian internally */    mlen = mod[0];    m = malloc(mlen * sizeof(unsigned short));    for (j = 0; j < mlen; j++) m[j] = mod[mod[0] - j];    /* Shift m left to make msb bit set */    for (mshift = 0; mshift < 15; mshift++)	if ((m[0] << mshift) & 0x8000) break;    if (mshift) {	for (i = 0; i < mlen - 1; i++)	    m[i] = (m[i] << mshift) | (m[i+1] >> (16-mshift));	m[mlen-1] = m[mlen-1] << mshift;    }    plen = p[0];    /* Ensure plen > mlen */    if (plen <= mlen) plen = mlen+1;    /* Allocate n of size plen, copy p to n */    n = malloc(plen * sizeof(unsigned short));    for (j = 0; j < plen; j++) n[j] = 0;    for (j = 1; j <= p[0]; j++) n[plen-j] = p[j];    /* Main computation */    internal_mod(n, plen, m, mlen, quotient, mshift);    /* Fixup result in case the modulus was shifted */    if (mshift) {	for (i = plen - mlen - 1; i < plen - 1; i++)	    n[i] = (n[i] << mshift) | (n[i+1] >> (16-mshift));	n[plen-1] = n[plen-1] << mshift;	internal_mod(n, plen, m, mlen, quotient, 0);	for (i = plen - 1; i >= plen - mlen; i--)	    n[i] = (n[i] >> mshift) | (n[i-1] << (16-mshift));    }    /* Copy result to buffer */    for (i = 1; i <= result[0]; i++) {        int j = plen-i;        result[i] = j>=0 ? n[j] : 0;    }    /* Free temporary arrays */    for (i = 0; i < mlen; i++) m[i] = 0; free(m);    for (i = 0; i < plen; i++) n[i] = 0; free(n);}