Browse Source

Fix MinGW PolarSSL build and update readme

pull/22/head
Linus Yang 11 years ago
parent
commit
71c30b31f3
6 changed files with 50 additions and 9 deletions
  1. 30
      README.md
  2. 2
      configure
  3. 2
      configure.ac
  4. 19
      src/encrypt.c
  5. 4
      src/encrypt.h
  6. 2
      src/utils.c

30
README.md

@ -55,7 +55,7 @@ Features
Shadowsocks-libev is writen in pure C and only depends on Shadowsocks-libev is writen in pure C and only depends on
[libev](http://software.schmorp.de/pkg/libev.html) and [libev](http://software.schmorp.de/pkg/libev.html) and
[openssl](http://www.openssl.org/).
[openssl](http://www.openssl.org/) or [polarssl](https://polarssl.org/).
In normal usage, the memory consumption is about 600KB and the CPU utilization is In normal usage, the memory consumption is about 600KB and the CPU utilization is
no more than 5% on a low-end router (Buffalo WHR-G300N V2 with a 400MHz MIPS CPU, no more than 5% on a low-end router (Buffalo WHR-G300N V2 with a 400MHz MIPS CPU,
@ -64,6 +64,10 @@ no more than 5% on a low-end router (Buffalo WHR-G300N V2 with a 400MHz MIPS CPU
Installation Installation
------------ ------------
__Note__: Default crypto library is OpenSSL. To build against PolarSSL,
specify `--with-crypto-library=polarssl` and `--with-polarssl=/path/to/polarssl`
when running `./configure`.
### Linux ### Linux
For Unix-like systems, especially Debian-based systems, For Unix-like systems, especially Debian-based systems,
@ -129,9 +133,11 @@ make V=99 package/shadowsocks-libev/openwrt/compile
For Windows, use either MinGW (msys) or Cygwin to build. For Windows, use either MinGW (msys) or Cygwin to build.
At the moment, only `ss-local` is supported to build against MinGW (msys). At the moment, only `ss-local` is supported to build against MinGW (msys).
If you are using MinGW (msys), please download OpenSSL source tarball
If you are using MinGW (msys), please download OpenSSL or PolarSSL source tarball
to the home directory of msys, and build it like this (may take a few minutes): to the home directory of msys, and build it like this (may take a few minutes):
* OpenSSL
```bash ```bash
tar zxf openssl-1.0.1e.tar.gz tar zxf openssl-1.0.1e.tar.gz
cd openssl-1.0.1e cd openssl-1.0.1e
@ -139,14 +145,32 @@ cd openssl-1.0.1e
make && make install make && make install
``` ```
* PolarSSL
```bash
tar zxf polarssl-1.3.2-gpl.tgz
cd polarssl-1.3.2
make lib WINDOWS=1
make install DESTDIR="$HOME/prebuilt"
```
Then, build the binary using the commands below, and all `.exe` files Then, build the binary using the commands below, and all `.exe` files
will be built at `$HOME/ss/bin`: will be built at `$HOME/ss/bin`:
* OpenSSL
```bash ```bash
./configure --prefix="$HOME/ss" --with-openssl="$HOME/prebuilt" ./configure --prefix="$HOME/ss" --with-openssl="$HOME/prebuilt"
make && make install make && make install
``` ```
* PolarSSL
```bash
./configure --prefix="$HOME/ss" --with-crypto-library=polarssl --with-polarssl=$HOME/prebuilt
make && make install
```
Usage Usage
----- -----
@ -156,7 +180,7 @@ usage:
ss-[local|redir|server] ss-[local|redir|server]
-s <server_host> host name or ip address of your remote server -s <server_host> host name or ip address of your remote server
-p <server_port> port number of your remote server -p <server_port> port number of your remote server
-l <local_port>> port number of your local server
-l <local_port> port number of your local server
-k <password> password of your remote server -k <password> password of your remote server
[-m <encrypt_method>] encrypt method, supporting table, rc4, [-m <encrypt_method>] encrypt method, supporting table, rc4,

2
configure

@ -12740,7 +12740,7 @@ fi
case $host in case $host in
*-mingw*) *-mingw*)
LIBS="$LIBS -lgdi32 -lws2_32"
LIBS="$LIBS -lgdi32 -lws2_32 -lcrypt32"
;; ;;
*) *)
;; ;;

2
configure.ac

@ -37,7 +37,7 @@ m4_include([libev/libev.m4])
dnl Add library for mingw dnl Add library for mingw
case $host in case $host in
*-mingw*) *-mingw*)
LIBS="$LIBS -lgdi32 -lws2_32"
LIBS="$LIBS -lgdi32 -lws2_32 -lcrypt32"
;; ;;
*) *)
;; ;;

19
src/encrypt.c

@ -3,19 +3,26 @@
#endif #endif
#include <stdint.h> #include <stdint.h>
#if defined(USE_CRYPTO_OPENSSL) #if defined(USE_CRYPTO_OPENSSL)
#include <openssl/md5.h> #include <openssl/md5.h>
#include <openssl/rand.h> #include <openssl/rand.h>
#elif defined(USE_CRYPTO_POLARSSL) #elif defined(USE_CRYPTO_POLARSSL)
#include <polarssl/md5.h> #include <polarssl/md5.h>
#include <polarssl/entropy.h> #include <polarssl/entropy.h>
#include <polarssl/ctr_drbg.h> #include <polarssl/ctr_drbg.h>
#include <polarssl/version.h>
#define CIPHER_UNSUPPORTED "unsupported" #define CIPHER_UNSUPPORTED "unsupported"
#endif #endif
#include <time.h> #include <time.h>
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
#include <wincrypt.h>
#else #else
#include <stdio.h> #include <stdio.h>
#endif #endif
@ -371,7 +378,9 @@ int rand_bytes(uint8_t *output, int len)
#endif #endif
entropy_init(&ec); entropy_init(&ec);
if (ctr_drbg_init(&cd_ctx, entropy_func, &ec, (const unsigned char *) rand_buffer.buffer, 8) != 0) { if (ctr_drbg_init(&cd_ctx, entropy_func, &ec, (const unsigned char *) rand_buffer.buffer, 8) != 0) {
#if POLARSSL_VERSION_NUMBER >= 0x01030000
entropy_free(&ec); entropy_free(&ec);
#endif
FATAL("Failed to initialize random generator"); FATAL("Failed to initialize random generator");
} }
rand_initialised = 1; rand_initialised = 1;
@ -460,9 +469,6 @@ void cipher_context_init(cipher_ctx_t *evp, int method, int enc)
if (cipher_init_ctx(evp, cipher) != 0) { if (cipher_init_ctx(evp, cipher) != 0) {
FATAL("Cannot initialize PolarSSL cipher context"); FATAL("Cannot initialize PolarSSL cipher context");
} }
if (method > RC4) {
cipher_set_padding_mode(evp, POLARSSL_PADDING_PKCS7);
}
#endif #endif
} }
@ -485,6 +491,7 @@ void cipher_context_set_iv(cipher_ctx_t *evp, uint8_t *iv, size_t iv_len, int en
cipher_free_ctx(evp); cipher_free_ctx(evp);
FATAL("Cannot set PolarSSL cipher key"); FATAL("Cannot set PolarSSL cipher key");
} }
#if POLARSSL_VERSION_NUMBER >= 0x01030000
if (cipher_set_iv(evp, iv, iv_len) != 0) { if (cipher_set_iv(evp, iv, iv_len) != 0) {
cipher_free_ctx(evp); cipher_free_ctx(evp);
FATAL("Cannot set PolarSSL cipher IV"); FATAL("Cannot set PolarSSL cipher IV");
@ -493,6 +500,12 @@ void cipher_context_set_iv(cipher_ctx_t *evp, uint8_t *iv, size_t iv_len, int en
cipher_free_ctx(evp); cipher_free_ctx(evp);
FATAL("Cannot finalize PolarSSL cipher context"); FATAL("Cannot finalize PolarSSL cipher context");
} }
#else
if(cipher_reset(evp, iv) != 0) {
cipher_free_ctx(evp);
FATAL("Cannot set PolarSSL cipher IV");
}
#endif
#endif #endif
#ifdef DEBUG #ifdef DEBUG
dump("IV", iv); dump("IV", iv);

4
src/encrypt.h

@ -22,6 +22,7 @@
#include <stdio.h> #include <stdio.h>
#if defined(USE_CRYPTO_OPENSSL) #if defined(USE_CRYPTO_OPENSSL)
#include <openssl/evp.h> #include <openssl/evp.h>
typedef EVP_CIPHER cipher_kt_t; typedef EVP_CIPHER cipher_kt_t;
typedef EVP_CIPHER_CTX cipher_ctx_t; typedef EVP_CIPHER_CTX cipher_ctx_t;
@ -29,7 +30,9 @@ typedef EVP_MD digest_type_t;
#define MAX_KEY_LENGTH EVP_MAX_KEY_LENGTH #define MAX_KEY_LENGTH EVP_MAX_KEY_LENGTH
#define MAX_IV_LENGTH EVP_MAX_IV_LENGTH #define MAX_IV_LENGTH EVP_MAX_IV_LENGTH
#define MAX_MD_SIZE EVP_MAX_MD_SIZE #define MAX_MD_SIZE EVP_MAX_MD_SIZE
#elif defined(USE_CRYPTO_POLARSSL) #elif defined(USE_CRYPTO_POLARSSL)
#include <polarssl/cipher.h> #include <polarssl/cipher.h>
#include <polarssl/md.h> #include <polarssl/md.h>
typedef cipher_info_t cipher_kt_t; typedef cipher_info_t cipher_kt_t;
@ -38,6 +41,7 @@ typedef md_info_t digest_type_t;
#define MAX_KEY_LENGTH 64 #define MAX_KEY_LENGTH 64
#define MAX_IV_LENGTH POLARSSL_MAX_IV_LENGTH #define MAX_IV_LENGTH POLARSSL_MAX_IV_LENGTH
#define MAX_MD_SIZE POLARSSL_MD_MAX_SIZE #define MAX_MD_SIZE POLARSSL_MD_MAX_SIZE
#endif #endif
#ifdef HAVE_STDINT_H #ifdef HAVE_STDINT_H

2
src/utils.c

@ -83,7 +83,7 @@ void usage()
printf(" ss-[local|redir|server]\n"); printf(" ss-[local|redir|server]\n");
printf(" -s <server_host> host name or ip address of your remote server\n"); printf(" -s <server_host> host name or ip address of your remote server\n");
printf(" -p <server_port> port number of your remote server\n"); printf(" -p <server_port> port number of your remote server\n");
printf(" -l <local_port>> port number of your local server\n");
printf(" -l <local_port> port number of your local server\n");
printf(" -k <password> password of your remote server\n"); printf(" -k <password> password of your remote server\n");
printf("\n"); printf("\n");
printf(" [-m <encrypt_method>] encrypt method, supporting table, rc4,\n"); printf(" [-m <encrypt_method>] encrypt method, supporting table, rc4,\n");

Loading…
Cancel
Save