Skip to content
This repository has been archived by the owner on Apr 24, 2022. It is now read-only.

Use Improved Key Reuse Procedure #15

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions encrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,21 @@ void make_encryptor(struct encryptor *tpl, struct encryptor *enc, uint8_t method
} else {
assert(!key);
assert(tpl->key);
enc->key = tpl->key;
enc->rc4_en = (struct rc4_state *)malloc(sizeof(struct rc4_state));
enc->rc4_de = (struct rc4_state *)malloc(sizeof(struct rc4_state));

if (!tpl->rc4_en) {
// initialize rc4 keystream
tpl->rc4_en = malloc(sizeof(*tpl->rc4_en));
if (!tpl->rc4_en)
FATAL("malloc() failed!");
rc4_init(tpl->rc4_en, tpl->key, MD5_LEN);
}
enc->rc4_en = malloc(sizeof(*enc->rc4_en));
enc->rc4_de = malloc(sizeof(*enc->rc4_de));
if (!(enc->rc4_en && enc->rc4_de))
FATAL("malloc() failed!");
rc4_init(enc->rc4_en, enc->key, MD5_LEN);
rc4_init(enc->rc4_de, enc->key, MD5_LEN);
// Copy the initial rc4 key stream.
*enc->rc4_en = *tpl->rc4_en;
*enc->rc4_de = *tpl->rc4_en;
}
}
}
Expand All @@ -215,6 +223,7 @@ void destroy_encryptor(struct encryptor *enc)
if (enc->rc4_en) {
free(enc->rc4_en);
free(enc->rc4_de);
enc->rc4_en = NULL;
enc->rc4_de = NULL;
}

}
1 change: 1 addition & 0 deletions rc4.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
*
* $FreeBSD: src/sys/crypto/rc4/rc4.c,v 1.2.2.1 2000/04/18 04:48:31 archie Exp $
*/
#include <string.h>
#include <stdint.h>
#include "rc4.h"

Expand Down
3 changes: 2 additions & 1 deletion server.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,10 @@ int main(int argc, char *argv[])
else if (!strcmp("shadow", optarg))
crypt_method = METHOD_SHADOWCRYPT;
break;
case 'h':
default:
fprintf(stderr, USAGE, newargv[0]);
abort();
exit(1);
}
}

Expand Down
3 changes: 2 additions & 1 deletion server.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
" -p : Override the listening port\n"\
" -k : Override the listening password\n"\
" -f : Override the pidfile path\n"\
" -m : Override the encryption method\n\n"
" -m : Override the encryption method\n"\
" -h : Print this message\n\n"
#define PROCESS_TITLE "shadowsocks on port:%d"
#define PROCESS_TITLE_LENGTH 26
#define ADDRTYPE_IPV4 1
Expand Down