[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)
|
||||
{
|
||||
memset_secure(drng, 0, sizeof(*drng));
|
||||
#ifdef _WIN32
|
||||
_aligned_free(drng);
|
||||
#else
|
||||
free(drng);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -100,7 +100,6 @@ int generate_keys(const char *seckey_filename, const char *pubkey_filename,
|
||||
memcpy(privatekey_buffer + sizeof(curve25519_key), publickey,
|
||||
sizeof(curve25519_key));
|
||||
} else {
|
||||
struct chacha20_drng *drng;
|
||||
int ret = drng_chacha20_init(&drng);
|
||||
if (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;
|
||||
unsigned char *file_data = malloc(file_data_len);
|
||||
|
||||
int exitcode = 1;
|
||||
|
||||
if (file_data == NULL) {
|
||||
printf("Malloc failed\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
int exitcode = 1;
|
||||
|
||||
fs = fopen(keyfile, "rb");
|
||||
if (fs == NULL) {
|
||||
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;
|
||||
|
||||
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);
|
||||
if (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;
|
||||
}
|
||||
|
||||
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);
|
||||
if (password_out != password) {
|
||||
printf("password input failed.\n");
|
||||
@@ -817,9 +816,9 @@ int get_symmetrickeys(unsigned char *salt_out, unsigned char *seckey_out,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
int a2res =
|
||||
argon2id_hash_raw(t_cost, m_cost, parallelism, password, password_len,
|
||||
salt_out, salt_len, seckey_out, sizeof(curve25519_key));
|
||||
int a2res = argon2id_hash_raw(t_cost, m_cost, parallelism, password,
|
||||
password_len, salt_out, salt_len, seckey_out,
|
||||
sizeof(curve25519_key));
|
||||
if (a2res != ARGON2_OK) {
|
||||
printf("argon2 failed.");
|
||||
goto exit;
|
||||
|
||||
@@ -434,6 +434,7 @@ int main(int argc, char *argv[]) {
|
||||
unsigned char *secretkey = malloc(32);
|
||||
unsigned char *publickey = malloc(32);
|
||||
unsigned char *salt = malloc(32);
|
||||
|
||||
if (secretkey == NULL || publickey == NULL || salt == NULL) {
|
||||
printf("Malloc failed\n");
|
||||
exitcode = 1;
|
||||
|
||||
Reference in New Issue
Block a user