/*
* Define by analogy with desCBCencrypt; AES modes are not standardized yet.
* Because of the way that non-multiple-of-16 buffers are handled,
* the decryptor must be fed buffers of the same size as the encryptor.
*/
void
aesCBCencrypt(uchar *p, int len, AESstate *s)
{
uchar *ip, *eip;
if(((p-(uchar*)0) & 3) == 0){
for(; len >= AESbsize; len -= AESbsize){
ip = s->ivec;
((u32int*)ip)[0] ^= ((u32int*)p)[0];
((u32int*)ip)[1] ^= ((u32int*)p)[1];
((u32int*)ip)[2] ^= ((u32int*)p)[2];
((u32int*)ip)[3] ^= ((u32int*)p)[3];
aes_encrypt(s->ekey, s->rounds, ip, ip);
((u32int*)p)[0] = ((u32int*)ip)[0];
((u32int*)p)[1] = ((u32int*)ip)[1];
((u32int*)p)[2] = ((u32int*)ip)[2];
((u32int*)p)[3] = ((u32int*)ip)[3];
p += AESbsize;
}
} else {
for(; len >= AESbsize; len -= AESbsize){
ip = s->ivec;
for(eip = ip+AESbsize; ip < eip; )
*ip++ ^= *p++;
aes_encrypt(s->ekey, s->rounds, s->ivec, s->ivec);
memmove(p - AESbsize, s->ivec, AESbsize);
}
}