- int nb = len >> 4;
-
- while(nb--) {
- lp32(iv)[0] ^= lp32(src)[0];
- lp32(iv)[1] ^= lp32(src)[1];
- lp32(iv)[2] ^= lp32(src)[2];
- lp32(iv)[3] ^= lp32(src)[3];
- aes_encrypt(iv, iv, &((AesContext *)context)->enc);
- memcpy(dst, iv, 16);
- src += 16;
- dst += 16;
+ AesContext *aes = context;
+ memset(aes, 0, sizeof(*aes));
+ silc_free(aes);
+}
+
+/* Encrypts with the cipher. Source and destination buffers maybe one and
+ same. */
+
+SILC_CIPHER_API_ENCRYPT(aes)
+{
+ AesContext *aes = context;
+ int i;
+
+ switch (ops->mode) {
+ case SILC_CIPHER_MODE_CTR:
+ SILC_CTR_MSB_128_8(iv, cipher->block, aes->u.enc.inf.b[2], src, dst,
+ aes_encrypt(iv, cipher->block, &aes->u.enc));
+ break;
+
+ case SILC_CIPHER_MODE_ECB:
+ {
+ SilcUInt32 nb = len >> 4;
+
+ while (nb--) {
+ aes_encrypt(src, dst, &aes->u.enc);
+ src += 16;
+ dst += 16;
+ }
+ }
+ break;
+
+ case SILC_CIPHER_MODE_CBC:
+ {
+ SilcUInt32 nb = len >> 4;
+
+ SILC_ASSERT((len & (16 - 1)) == 0);
+ if (len & (16 - 1))
+ return FALSE;
+
+ while(nb--) {
+ lp32(iv)[0] ^= lp32(src)[0];
+ lp32(iv)[1] ^= lp32(src)[1];
+ lp32(iv)[2] ^= lp32(src)[2];
+ lp32(iv)[3] ^= lp32(src)[3];
+ aes_encrypt(iv, iv, &aes->u.enc);
+ memcpy(dst, iv, 16);
+ src += 16;
+ dst += 16;
+ }
+ }
+ break;
+
+ case SILC_CIPHER_MODE_CFB:
+ SILC_CFB_ENC_MSB_128_8(iv, aes->u.enc.inf.b[2], src, dst,
+ aes_encrypt(iv, iv, &aes->u.enc));
+ break;
+
+ default:
+ return FALSE;