Replace direct use of RC4 by stream cipher abstraction.
[paraslash.git] / command.c
index 5217f9b487cd260aebe5d5a986f4fd8e957b0270..2c9d29dfca3c6202d61e222a1934b9d21e1357bf 100644 (file)
--- a/command.c
+++ b/command.c
@@ -11,7 +11,6 @@
 #include <sys/time.h>
 #include <sys/types.h>
 #include <dirent.h>
-#include <openssl/rc4.h>
 #include <osl.h>
 #include <stdbool.h>
 
@@ -768,7 +767,7 @@ __noreturn void handle_connect(int fd, const char *peername)
        u = lookup_user(p);
        if (u) {
                get_random_bytes_or_die(rand_buf, sizeof(rand_buf));
-               ret = para_encrypt_buffer(u->rsa, rand_buf, sizeof(rand_buf),
+               ret = pub_encrypt(u->pubkey, rand_buf, sizeof(rand_buf),
                        (unsigned char *)buf);
                if (ret < 0)
                        goto net_err;
@@ -809,10 +808,10 @@ __noreturn void handle_connect(int fd, const char *peername)
        /* auth successful */
        alarm(0);
        PARA_INFO_LOG("good auth for %s\n", u->name);
-       /* init rc4 keys with the second part of the random buffer */
-       RC4_set_key(&rc4c.recv_key, RC4_KEY_LEN, rand_buf + CHALLENGE_SIZE);
-       RC4_set_key(&rc4c.send_key, RC4_KEY_LEN, rand_buf + CHALLENGE_SIZE
-               RC4_KEY_LEN);
+       /* init stream cipher keys with the second part of the random buffer */
+       rc4c.recv = stream_cipher_new(rand_buf + CHALLENGE_SIZE, RC4_KEY_LEN);
+       rc4c.send = stream_cipher_new(rand_buf + CHALLENGE_SIZE + RC4_KEY_LEN,
+               RC4_KEY_LEN);
        ret = rc4_send_buffer(&rc4c, PROCEED_MSG);
        if (ret < 0)
                goto net_err;
@@ -849,6 +848,8 @@ net_err:
        PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
 out:
        free(command);
+       stream_cipher_free(rc4c.recv);
+       stream_cipher_free(rc4c.send);
        mutex_lock(mmd_mutex);
        if (cmd && (cmd->perms & AFS_WRITE) && ret >= 0)
                mmd->events++;