diff --git a/assets/shadowsocks b/assets/shadowsocks index 507b7dff..557abd4b 100755 Binary files a/assets/shadowsocks and b/assets/shadowsocks differ diff --git a/jni/shadowsocks/encrypt.c b/jni/shadowsocks/encrypt.c index 379b42ab..788c4a0f 100755 --- a/jni/shadowsocks/encrypt.c +++ b/jni/shadowsocks/encrypt.c @@ -113,8 +113,9 @@ static void mergesort(uint8_t array[], int length) void encrypt(char *buf, int len) { if (_method == RC4_ENC) { + int outlen; unsigned char mybuf[BUF_SIZE]; - RC4(&rc4_key, len, (unsigned char *) buf, mybuf); + EVP_CipherUpdate(&ctx, mybuf, &outlen, (unsigned char*)buf, len); memcpy(buf, mybuf, len); } else { char *end = buf + len; @@ -127,8 +128,9 @@ void encrypt(char *buf, int len) { void decrypt(char *buf, int len) { if (_method == RC4_ENC) { + int outlen; unsigned char mybuf[BUF_SIZE]; - RC4(&rc4_key, len, (unsigned char *) buf, mybuf); + EVP_CipherUpdate(&ctx, mybuf, &outlen, (unsigned char*) buf, len); memcpy(buf, mybuf, len); } else { char *end = buf + len; @@ -154,13 +156,24 @@ int recv_decrypt(int sock, char *buf, int len, int flags) { return result; } -void get_table(const char* key) { +void get_table(const char* pass) { if (_method == RC4_ENC) { - RC4_set_key(&rc4_key, strlen(key), (unsigned char *) key); + unsigned char key[EVP_MAX_KEY_LENGTH]; + unsigned char iv[EVP_MAX_IV_LENGTH]; + int key_len = EVP_BytesToKey(EVP_rc4(), EVP_md5(), NULL, (unsigned char*) pass, + strlen(pass), 1, key, iv); + EVP_CIPHER_CTX_init(&ctx); + EVP_CipherInit_ex(&ctx, EVP_rc4(), NULL, NULL, NULL, 1); + if (!EVP_CIPHER_CTX_set_key_length(&ctx, key_len)) { + LOGE("Invalid key length: %d", key_len); + EVP_CIPHER_CTX_cleanup(&ctx); + exit(EXIT_FAILURE); + } + EVP_CipherInit_ex(&ctx, NULL, NULL, key, iv, 1); } else { uint8_t *table = encrypt_table; - uint8_t *tmp_hash = MD5((const uint8_t*)key, strlen(key), NULL); - _a = htole64(*(uint64_t *)tmp_hash); + uint8_t *tmp_hash = MD5((unsigned char *) pass, strlen(pass), NULL); + _a = htole64(*(uint64_t *) tmp_hash); uint32_t i; for(i = 0; i < 256; ++i) { diff --git a/jni/shadowsocks/encrypt.h b/jni/shadowsocks/encrypt.h index eb2ee1ff..84fa8880 100755 --- a/jni/shadowsocks/encrypt.h +++ b/jni/shadowsocks/encrypt.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #define BUF_SIZE 4096 @@ -15,7 +15,7 @@ unsigned char encrypt_table[256]; unsigned char decrypt_table[256]; -RC4_KEY rc4_key; +EVP_CIPHER_CTX ctx; void get_table(const char* key); void encrypt(char *buf, int len); diff --git a/libs/armeabi/pdnsd b/libs/armeabi/pdnsd index 6eab9734..d82c8ada 100755 Binary files a/libs/armeabi/pdnsd and b/libs/armeabi/pdnsd differ diff --git a/libs/armeabi/shadowsocks b/libs/armeabi/shadowsocks index 507b7dff..557abd4b 100755 Binary files a/libs/armeabi/shadowsocks and b/libs/armeabi/shadowsocks differ