- size_t len = src->iov_len, l1, l2;
- RC4_KEY *key = &sc->key;
-
- assert(len > 0);
- assert(len < ((typeof(src->iov_len))-1) / 2);
- l1 = ROUND_DOWN(len, RC4_ALIGN);
- l2 = ROUND_UP(len, RC4_ALIGN);
-
- *dst = (typeof(*dst)) {
- /* Add one for the terminating zero byte. */
- .iov_base = para_malloc(l2 + 1),
- .iov_len = len
- };
- RC4(key, l1, src->iov_base, dst->iov_base);
- if (len > l1) {
- unsigned char remainder[RC4_ALIGN] = "";
- memcpy(remainder, src->iov_base + l1, len - l1);
- RC4(key, len - l1, remainder, dst->iov_base + l1);
- }
- ((char *)dst->iov_base)[len] = '\0';