67 size_t len,
const void *
key,
68 unsigned char ivec[16],
int *
num,
74 assert(in && out && key && ivec && num);
79 #if !defined(OPENSSL_SMALL_FOOTPRINT)
80 if (16%
sizeof(
size_t) == 0)
do {
82 *(out++) = ivec[n] ^= *(in++);
86 #if defined(STRICT_ALIGNMENT)
87 if (((
size_t)in|(size_t)out|(
size_t)ivec)%
sizeof(
size_t) != 0)
91 (*block)(ivec, ivec,
key);
92 for (; n<16; n+=
sizeof(size_t)) {
94 *(
size_t*)(ivec+n) ^= *(
size_t*)(in+n);
102 (*block)(ivec, ivec,
key);
104 out[n] = ivec[n] ^= in[n];
115 (*block)(ivec, ivec,
key);
117 out[l] = ivec[n] ^= in[l];
123 #if !defined(OPENSSL_SMALL_FOOTPRINT)
124 if (16%
sizeof(
size_t) == 0)
do {
127 *(out++) = ivec[n] ^ (c = *(in++)); ivec[n] = c;
131 #if defined(STRICT_ALIGNMENT)
132 if (((
size_t)in|(size_t)out|(
size_t)ivec)%
sizeof(
size_t) != 0)
136 (*block)(ivec, ivec,
key);
137 for (; n<16; n+=
sizeof(size_t)) {
138 size_t t = *(
size_t*)(in+n);
139 *(
size_t*)(out+n) = *(
size_t*)(ivec+n) ^
t;
140 *(
size_t*)(ivec+n) =
t;
148 (*block)(ivec, ivec,
key);
151 out[n] = ivec[n] ^ (c = in[n]); ivec[n] = c;
163 (*block)(ivec, ivec,
key);
165 out[l] = ivec[n] ^ (c = in[l]); ivec[n] = c;
175 static void cfbr_encrypt_block(
const unsigned char *in,
unsigned char *out,
176 int nbits,
const void *
key,
177 unsigned char ivec[16],
int enc,
181 unsigned char ovec[16*2 + 1];
183 if (nbits<=0 || nbits>128)
return;
186 memcpy(ovec,ivec,16);
188 (*block)(ivec,ivec,
key);
191 for(n=0 ; n <
num ; ++n)
192 out[n] = (ovec[16+n] = in[n] ^ ivec[n]);
194 for(n=0 ; n <
num ; ++n)
195 out[n] = (ovec[16+n] = in[n]) ^ ivec[n];
200 memcpy(ivec,ovec+num,16);
202 for(n=0 ; n < 16 ; ++n)
203 ivec[n] = ovec[n+num]<<rem | ovec[n+num+1]>>(8-rem);
210 size_t bits,
const void *key,
211 unsigned char ivec[16],
int *num,
215 unsigned char c[1],d[1];
217 assert(in && out && key && ivec && num);
220 for(n=0 ; n<
bits ; ++n)
222 c[0]=(in[n/8]&(1 << (7-n%8))) ? 0x80 : 0;
223 cfbr_encrypt_block(c,d,1,key,ivec,enc,block);
224 out[n/8]=(out[n/8]&~(1 << (
unsigned int)(7-n%8))) |
225 ((d[0]&0x80) >> (
unsigned int)(n%8));
230 size_t length,
const void *key,
231 unsigned char ivec[16],
int *num,
236 assert(in && out && key && ivec && num);
240 cfbr_encrypt_block(&in[n],&out[n],8,key,ivec,enc,block);