encrypt: fixed RAND_bytes call

currntly it returns 1 on success so not only 0 is success
This commit is contained in:
Martin Pulec
2022-11-02 13:54:46 +01:00
parent 6c88f3b971
commit 5ca097c4eb
2 changed files with 6 additions and 2 deletions

View File

@@ -51,6 +51,8 @@
#include <openssl/aes.h>
#include <openssl/rand.h>
#define MOD_NAME "[encrypt] "
struct openssl_encrypt {
AES_KEY key;
@@ -76,8 +78,9 @@ static int openssl_encrypt_init(struct openssl_encrypt **state, const char *pass
MD5Final(hash, &context);
AES_set_encrypt_key(hash, 128, &s->key);
if (!RAND_bytes(s->ivec, 8)) {
if (RAND_bytes(s->ivec, 8) < 0) {
free(s);
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Cannot generate random bytes!\n");
return -1;
}
s->mode = mode;

View File

@@ -88,6 +88,7 @@
#include <iostream>
#include <vector>
#define MOD_NAME "[transmit] "
#define TRANSMIT_MAGIC 0xe80ab15f
#define FEC_MAX_MULT 10
@@ -243,7 +244,7 @@ struct tx *tx_init(struct module *parent, unsigned mtu, enum tx_media_type media
}
if (tx->enc_funcs->init(&tx->encryption,
encryption, DEFAULT_CIPHER_MODE) != 0) {
fprintf(stderr, "Unable to initialize encryption\n");
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Unable to initialize encryption\n");
module_done(&tx->mod);
return NULL;
}