void CRYPTO_ctr128_encrypt_ctr32(const unsigned char *in, unsigned char *out,
			size_t len, const void *key,
			unsigned char ivec[16], unsigned char ecount_buf[16],
			unsigned int *num, ctr128_f func)
{
	unsigned int n,ctr32;
	assert(in && out && key && ecount_buf && num);
	assert(*num < 16);
	n = *num;
	while (n && len) {
		*(out++) = *(in++) ^ ecount_buf[n];
		--len;
		n = (n+1) % 16;
	}
	ctr32 = GETU32(ivec+12);
	while (len>=16) {
		size_t blocks = len/16;
		if (sizeof(size_t)>sizeof(unsigned int) && blocks>(1U<<28))
			blocks = (1U<<28);
		ctr32 += (u32)blocks;
		if (ctr32 < blocks) {
			blocks -= ctr32;
			ctr32   = 0;
		}
		(*func)(in,out,blocks,key,ivec);
		PUTU32(ivec+12,ctr32);
		if (ctr32 == 0)	ctr96_inc(ivec);
		blocks *= 16;
		len -= blocks;
		out += blocks;
		in  += blocks;
	}
	if (len) {
		memset(ecount_buf,0,16);
		(*func)(ecount_buf,ecount_buf,1,key,ivec);
		++ctr32;
		PUTU32(ivec+12,ctr32);
		if (ctr32 == 0)	ctr96_inc(ivec);
		while (len--) {
			out[n] = in[n] ^ ecount_buf[n];
			++n;
		}
	}
	*num=n;
}
['void CRYPTO_ctr128_encrypt_ctr32(const unsigned char *in, unsigned char *out,\n\t\t\tsize_t len, const void *key,\n\t\t\tunsigned char ivec[16], unsigned char ecount_buf[16],\n\t\t\tunsigned int *num, ctr128_f func)\n{\n\tunsigned int n,ctr32;\n\tassert(in && out && key && ecount_buf && num);\n\tassert(*num < 16);\n\tn = *num;\n\twhile (n && len) {\n\t\t*(out++) = *(in++) ^ ecount_buf[n];\n\t\t--len;\n\t\tn = (n+1) % 16;\n\t}\n\tctr32 = GETU32(ivec+12);\n\twhile (len>=16) {\n\t\tsize_t blocks = len/16;\n\t\tif (sizeof(size_t)>sizeof(unsigned int) && blocks>(1U<<28))\n\t\t\tblocks = (1U<<28);\n\t\tctr32 += (u32)blocks;\n\t\tif (ctr32 < blocks) {\n\t\t\tblocks -= ctr32;\n\t\t\tctr32   = 0;\n\t\t}\n\t\t(*func)(in,out,blocks,key,ivec);\n\t\tPUTU32(ivec+12,ctr32);\n\t\tif (ctr32 == 0)\tctr96_inc(ivec);\n\t\tblocks *= 16;\n\t\tlen -= blocks;\n\t\tout += blocks;\n\t\tin  += blocks;\n\t}\n\tif (len) {\n\t\tmemset(ecount_buf,0,16);\n\t\t(*func)(ecount_buf,ecount_buf,1,key,ivec);\n\t\t++ctr32;\n\t\tPUTU32(ivec+12,ctr32);\n\t\tif (ctr32 == 0)\tctr96_inc(ivec);\n\t\twhile (len--) {\n\t\t\tout[n] = in[n] ^ ecount_buf[n];\n\t\t\t++n;\n\t\t}\n\t}\n\t*num=n;\n}']