Browse Source

use OpenSSL's RAND_bytes() instead of glibc's rand()

pull/11/head
clowwindy 11 years ago
parent
commit
bbb1462169
1 changed files with 2 additions and 3 deletions
  1. 5
      src/encrypt.c

5
src/encrypt.c

@ -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;

Loading…
Cancel
Save