summaryrefslogtreecommitdiff
path: root/ecp/util
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2022-02-02 08:14:56 +0100
committerUros Majstorovic <majstor@majstor.org>2022-02-02 08:14:56 +0100
commitd359dd9981f4137e8873a7a571e5c54c5b2449c4 (patch)
treeabfe99bcbce4324c71bd03f68581bdd605d13ec9 /ecp/util
parente215377e5b1440f8ec0842712f2e559e82de2f03 (diff)
linux and freebsd compatibility
Diffstat (limited to 'ecp/util')
-rw-r--r--ecp/util/util.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/ecp/util/util.c b/ecp/util/util.c
index 4f4adc2..7ce8da5 100644
--- a/ecp/util/util.c
+++ b/ecp/util/util.c
@@ -1,6 +1,7 @@
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
+#include <sys/stat.h>
#include "core.h"
#include "cr.h"
@@ -9,7 +10,7 @@
int ecp_util_key_save(ECPContext *ctx, ECPDHKey *key, char *filename) {
int fd;
ssize_t rv;
-
+
if ((fd = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR)) < 0) return ECP_ERR;
rv = write(fd, ecp_cr_dh_pub_get_buf(&key->public), ECP_ECDH_SIZE_KEY);
if (rv != ECP_ECDH_SIZE_KEY) {
@@ -29,7 +30,7 @@ int ecp_util_key_load(ECPContext *ctx, ECPDHKey *key, char *filename) {
int fd;
ssize_t rv;
unsigned char buf[ECP_ECDH_SIZE_KEY];
-
+
if ((fd = open(filename, O_RDONLY)) < 0) return ECP_ERR;
rv = read(fd, buf, ECP_ECDH_SIZE_KEY);
if (rv != ECP_ECDH_SIZE_KEY) {
@@ -44,7 +45,7 @@ int ecp_util_key_load(ECPContext *ctx, ECPDHKey *key, char *filename) {
close(fd);
ecp_cr_dh_pub_from_buf(&key->public, buf);
-
+
key->valid = 1;
return ECP_OK;
}
@@ -52,7 +53,7 @@ int ecp_util_key_load(ECPContext *ctx, ECPDHKey *key, char *filename) {
int ecp_util_node_save(ECPContext *ctx, ECPNode *node, char *filename) {
int fd;
ssize_t rv;
-
+
if ((fd = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR)) < 0) return ECP_ERR;
rv = write(fd, ecp_cr_dh_pub_get_buf(&node->public), ECP_ECDH_SIZE_KEY);
if (rv != ECP_ECDH_SIZE_KEY) {
@@ -72,7 +73,7 @@ int ecp_util_node_load(ECPContext *ctx, ECPNode *node, char *filename) {
int fd;
ssize_t rv;
unsigned char buf[ECP_ECDH_SIZE_KEY];
-
+
if ((fd = open(filename, O_RDONLY)) < 0) return ECP_ERR;
rv = read(fd, buf, ECP_ECDH_SIZE_KEY);
if (rv != ECP_ECDH_SIZE_KEY) {