summaryrefslogtreecommitdiff
path: root/ecp/util/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'ecp/util/util.c')
-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) {