/* assumes: out != NULL and points to a GF(2^n) value to receive the doubled value; in != NULL and points to a 16 byte GF(2^n) value to double; the in and out buffers do not overlap. effects: doubles the GF(2^n) value pointed to by "in" and places the result in the GF(2^n) value pointed to by "out."  */
void gf_double(uint8_t *out, uint8_t *in)
/* assumes: out != NULL and points to a GF(2^n) value to receive the doubled value; in != NULL and points to a 16 byte GF(2^n) value to double; the in and out buffers do not overlap. effects: doubles the GF(2^n) value pointed to by "in" and places the result in the GF(2^n) value pointed to by "out."  */
void gf_double(uint8_t *out, uint8_t *in)
{
	uint8_t *x = in + (TC_AES_BLOCK_SIZE - 1);
	uint8_t carry = (in[0] >> 7) ? gf_wrap : 0;
	out += (TC_AES_BLOCK_SIZE - 1);
	for (;;) {
		*out-- = (*x << 1) ^ carry;
		if (x == in) {
			break;
		}
		carry = *x-- >> 7;
	}
}