mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-21 22:43:48 +00:00
Merge pull request #11 from clowwindy/master
Use OpenSSL's RAND_bytes() instead of glibc's rand()
This commit is contained in:
+2
-3
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <openssl/md5.h>
|
||||
#include <openssl/rand.h>
|
||||
|
||||
#include "encrypt.h"
|
||||
#include "utils.h"
|
||||
@@ -160,9 +161,7 @@ char* ss_encrypt(char *plaintext, ssize_t *len, struct enc_ctx *ctx) {
|
||||
int i;
|
||||
uint8_t iv[EVP_MAX_IV_LENGTH];
|
||||
iv_len = enc_iv_len;
|
||||
for (i = 0; i < iv_len; i++) {
|
||||
iv[i] = rand() % 256;
|
||||
}
|
||||
RAND_bytes(iv, iv_len);
|
||||
EVP_CipherInit_ex(&ctx->evp, NULL, NULL, enc_key, iv, 1);
|
||||
memcpy(ciphertext, iv, iv_len);
|
||||
ctx->init = 1;
|
||||
|
||||
Reference in New Issue
Block a user