+static void aes_ctr128_crypt(struct aes_ctr_128_context *aes, struct iovec *src,
+ struct iovec *dst)
+{
+ size_t len = src->iov_len;
+
+ *dst = (typeof(*dst)) {
+ /* Add one for the terminating zero byte. */
+ .iov_base = para_malloc(len + 1),
+ .iov_len = len
+ };
+ AES_ctr128_encrypt(src->iov_base, dst->iov_base, len,
+ &aes->key, aes->ivec, aes->ecount, &aes->num);
+ ((char *)dst->iov_base)[len] = '\0';
+}
+
+void sc_crypt(struct stream_cipher *sc, struct iovec *src, struct iovec *dst)
+{
+ if (sc->use_aes)
+ return aes_ctr128_crypt(&sc->context.aes, src, dst);
+ return rc4_crypt(&sc->context.rc4_key, src, dst);
+}
+