[FIX] Windows and Mac OS X compatibility.
This commit is contained in:
@@ -483,11 +483,7 @@ static int drng_chacha20_rng_selftest(struct chacha20_drng *drng)
|
|||||||
static void drng_chacha20_dealloc(struct chacha20_drng *drng)
|
static void drng_chacha20_dealloc(struct chacha20_drng *drng)
|
||||||
{
|
{
|
||||||
memset_secure(drng, 0, sizeof(*drng));
|
memset_secure(drng, 0, sizeof(*drng));
|
||||||
#ifdef _WIN32
|
|
||||||
_aligned_free(drng);
|
|
||||||
#else
|
|
||||||
free(drng);
|
free(drng);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -595,7 +591,7 @@ int drng_chacha20_reseed(struct chacha20_drng *drng, const uint8_t *inbuf,
|
|||||||
DSO_PUBLIC
|
DSO_PUBLIC
|
||||||
void drng_chacha20_destroy(struct chacha20_drng *drng)
|
void drng_chacha20_destroy(struct chacha20_drng *drng)
|
||||||
{
|
{
|
||||||
drng_chacha20_dealloc(drng);
|
drng_chacha20_dealloc(drng);
|
||||||
}
|
}
|
||||||
|
|
||||||
DSO_PUBLIC
|
DSO_PUBLIC
|
||||||
|
|||||||
@@ -100,7 +100,6 @@ int generate_keys(const char *seckey_filename, const char *pubkey_filename,
|
|||||||
memcpy(privatekey_buffer + sizeof(curve25519_key), publickey,
|
memcpy(privatekey_buffer + sizeof(curve25519_key), publickey,
|
||||||
sizeof(curve25519_key));
|
sizeof(curve25519_key));
|
||||||
} else {
|
} else {
|
||||||
struct chacha20_drng *drng;
|
|
||||||
int ret = drng_chacha20_init(&drng);
|
int ret = drng_chacha20_init(&drng);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printf("Chacha20 allocation failed: %d\n", ret);
|
printf("Chacha20 allocation failed: %d\n", ret);
|
||||||
@@ -431,13 +430,13 @@ int get_pubkey(const char *keyfile, unsigned char *pkey) {
|
|||||||
const size_t file_data_len = 45;
|
const size_t file_data_len = 45;
|
||||||
unsigned char *file_data = malloc(file_data_len);
|
unsigned char *file_data = malloc(file_data_len);
|
||||||
|
|
||||||
|
int exitcode = 1;
|
||||||
|
|
||||||
if (file_data == NULL) {
|
if (file_data == NULL) {
|
||||||
printf("Malloc failed\n");
|
printf("Malloc failed\n");
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
int exitcode = 1;
|
|
||||||
|
|
||||||
fs = fopen(keyfile, "rb");
|
fs = fopen(keyfile, "rb");
|
||||||
if (fs == NULL) {
|
if (fs == NULL) {
|
||||||
printf("key file opening failed: %s.\n", strerror(errno));
|
printf("key file opening failed: %s.\n", strerror(errno));
|
||||||
@@ -774,14 +773,6 @@ int get_symmetrickeys(unsigned char *salt_out, unsigned char *seckey_out,
|
|||||||
|
|
||||||
int exitcode = 1;
|
int exitcode = 1;
|
||||||
|
|
||||||
password = malloc(password_maxlen);
|
|
||||||
password_verif = malloc(password_maxlen);
|
|
||||||
|
|
||||||
if (password == NULL || password_verif == NULL) {
|
|
||||||
printf("Malloc failed\n");
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ret = drng_chacha20_init(&drng);
|
int ret = drng_chacha20_init(&drng);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printf("Chacha20 allocation failed: %d\n", ret);
|
printf("Chacha20 allocation failed: %d\n", ret);
|
||||||
@@ -792,6 +783,14 @@ int get_symmetrickeys(unsigned char *salt_out, unsigned char *seckey_out,
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
password = malloc(password_maxlen);
|
||||||
|
password_verif = malloc(password_maxlen);
|
||||||
|
|
||||||
|
if (password == NULL || password_verif == NULL) {
|
||||||
|
printf("Malloc failed\n");
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
password_out = readpassphrase("Password : ", password, password_maxlen, 0);
|
password_out = readpassphrase("Password : ", password, password_maxlen, 0);
|
||||||
if (password_out != password) {
|
if (password_out != password) {
|
||||||
printf("password input failed.\n");
|
printf("password input failed.\n");
|
||||||
@@ -817,9 +816,9 @@ int get_symmetrickeys(unsigned char *salt_out, unsigned char *seckey_out,
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2res =
|
int a2res = argon2id_hash_raw(t_cost, m_cost, parallelism, password,
|
||||||
argon2id_hash_raw(t_cost, m_cost, parallelism, password, password_len,
|
password_len, salt_out, salt_len, seckey_out,
|
||||||
salt_out, salt_len, seckey_out, sizeof(curve25519_key));
|
sizeof(curve25519_key));
|
||||||
if (a2res != ARGON2_OK) {
|
if (a2res != ARGON2_OK) {
|
||||||
printf("argon2 failed.");
|
printf("argon2 failed.");
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|||||||
@@ -434,6 +434,7 @@ int main(int argc, char *argv[]) {
|
|||||||
unsigned char *secretkey = malloc(32);
|
unsigned char *secretkey = malloc(32);
|
||||||
unsigned char *publickey = malloc(32);
|
unsigned char *publickey = malloc(32);
|
||||||
unsigned char *salt = malloc(32);
|
unsigned char *salt = malloc(32);
|
||||||
|
|
||||||
if (secretkey == NULL || publickey == NULL || salt == NULL) {
|
if (secretkey == NULL || publickey == NULL || salt == NULL) {
|
||||||
printf("Malloc failed\n");
|
printf("Malloc failed\n");
|
||||||
exitcode = 1;
|
exitcode = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user