}
#define RC4_ALIGN 8
+struct stream_cipher {
+ RC4_KEY key;
+};
+
+/**
+ * Allocate and initialize a stream cipher structure.
+ *
+ * \param data The key.
+ * \param len The size of the key.
+ *
+ * \return A new stream cipher structure.
+ */
+struct stream_cipher *stream_cipher_new(const unsigned char *data, int len)
+{
+ struct stream_cipher *sc = para_malloc(sizeof(*sc));
+ RC4_set_key(&sc->key, len, data);
+ return sc;
+}
+
+/**
+ * Deallocate a stream cipher structure.
+ *
+ * \param sc A stream cipher previously obtained by stream_cipher_new().
+ */
+void stream_cipher_free(struct stream_cipher *sc)
+{
+ free(sc);
+}
/**
* Encrypt and send a buffer.
assert(len);
tmp = para_malloc(l2);
- RC4(&rc4c->send_key, l1, (const unsigned char *)buf, tmp);
+ RC4(&rc4c->send->key, l1, (const unsigned char *)buf, tmp);
if (len > l1) {
memcpy(remainder, buf + l1, len - l1);
- RC4(&rc4c->send_key, len - l1, remainder, tmp + l1);
+ RC4(&rc4c->send->key, len - l1, remainder, tmp + l1);
}
ret = write_all(rc4c->fd, (char *)tmp, &len);
free(tmp);
ssize_t ret = recv(rc4c->fd, tmp, size, 0);
if (ret > 0)
- RC4(&rc4c->recv_key, ret, tmp, (unsigned char *)buf);
+ RC4(&rc4c->recv->key, ret, tmp, (unsigned char *)buf);
else if (ret < 0)
ret = -ERRNO_TO_PARA_ERROR(errno);
free(tmp);