66 static void ctr128_inc(
unsigned char *counter) {
79 #if !defined(OPENSSL_SMALL_FOOTPRINT)
80 static void ctr128_inc_aligned(
unsigned char *counter) {
82 const union {
long one;
char little; } is_endian = {1};
84 if (is_endian.little) {
89 data = (
size_t *)counter;
90 n = 16/
sizeof(size_t);
115 size_t len,
const void *
key,
116 unsigned char ivec[16],
unsigned char ecount_buf[16],
122 assert(in && out && key && ecount_buf && num);
127 #if !defined(OPENSSL_SMALL_FOOTPRINT)
128 if (16%
sizeof(
size_t) == 0)
do {
130 *(out++) = *(in++) ^ ecount_buf[n];
135 #if defined(STRICT_ALIGNMENT)
136 if (((
size_t)in|(size_t)out|(
size_t)ivec)%
sizeof(
size_t) != 0)
140 (*block)(ivec, ecount_buf,
key);
141 ctr128_inc_aligned(ivec);
142 for (; n<16; n+=
sizeof(size_t))
144 *(
size_t *)(in+n) ^ *(
size_t *)(ecount_buf+n);
151 (*block)(ivec, ecount_buf,
key);
152 ctr128_inc_aligned(ivec);
154 out[n] = in[n] ^ ecount_buf[n];
165 (*block)(ivec, ecount_buf,
key);
168 out[l] = in[l] ^ ecount_buf[n];
177 static void ctr96_inc(
unsigned char *counter) {
191 size_t len,
const void *
key,
192 unsigned char ivec[16],
unsigned char ecount_buf[16],
195 unsigned int n,ctr32;
197 assert(in && out && key && ecount_buf && num);
203 *(out++) = *(in++) ^ ecount_buf[n];
210 size_t blocks = len/16;
216 if (
sizeof(
size_t)>
sizeof(
unsigned int) && blocks>(1U<<28))
224 ctr32 += (
u32)blocks;
225 if (ctr32 < blocks) {
229 (*func)(in,out,blocks,
key,ivec);
233 if (ctr32 == 0) ctr96_inc(ivec);
240 memset(ecount_buf,0,16);
241 (*func)(ecount_buf,ecount_buf,1,
key,ivec);
244 if (ctr32 == 0) ctr96_inc(ivec);
246 out[n] = in[n] ^ ecount_buf[n];