tEnsure key filepath are not overwritten - sick - sign and check files using ed25519
(HTM) git clone git://z3bra.org/sick
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 9966ebe114dfc63ffb8a38ff032654a13253cb17
(DIR) parent 3ea829018da240f2d59c156db537bbbbf06b9d7f
(HTM) Author: Willy Goiffon <contact@z3bra.org>
Date: Fri, 25 Aug 2023 08:16:45 +0200
Ensure key filepath are not overwritten
Diffstat:
M crypto_api.h | 6 +++++-
M sick.c | 4 ++--
2 files changed, 7 insertions(+), 3 deletions(-)
---
(DIR) diff --git a/crypto_api.h b/crypto_api.h
t@@ -7,14 +7,18 @@
#include <stdint.h>
#include <stdlib.h>
-#include <sys/random.h>
#define crypto_hash_sha512_BYTES 64U
#define crypto_sign_ed25519_SECRETKEYBYTES 64U
#define crypto_sign_ed25519_PUBLICKEYBYTES 32U
#define crypto_sign_ed25519_BYTES 64U
+#ifdef __OpenBSD__
+#define randombytes(buf, buf_len) arc4random_buf((buf), (buf_len))
+#else
+#include <sys/random.h>
#define randombytes(buf, buf_len) getrandom((buf), (buf_len), GRND_RANDOM)
+#endif
typedef int32_t crypto_int32;
typedef uint32_t crypto_uint32;
(DIR) diff --git a/sick.c b/sick.c
t@@ -213,7 +213,7 @@ createkeypair(const char *alias)
memset(base64, 0, sizeof(base64));
/* write public key to "<alias>.pub" */
- sprintf(fn, "%s.pub", alias);
+ snprintf(fn, sizeof(fn) - 4, "%s.pub", alias);
if (verbose)
fprintf(stderr, "Creating public key %s\n", fn);
if ((fp = fopen(fn, "w")) == NULL) {
t@@ -232,7 +232,7 @@ createkeypair(const char *alias)
free(buf);
/* write private key to "<alias>.key" */
- sprintf(fn, "%s.key", alias);
+ snprintf(fn, sizeof(fn) - 4, "%s.key", alias);
if (verbose)
fprintf(stderr, "Creating private key %s\n", fn);
if ((fp = fopen(fn, "w")) == NULL) {