From 7281ae7db4d9bc9eb2b59134e1dea1231013f1af Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 23 Jun 2023 19:15:49 +0200 Subject: Use libar2simplified instead of crypt as crypt has a verily limited imput size, and add -h to key2root-addkey, and add key2root-crypt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- key2root-crypt.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 key2root-crypt.c (limited to 'key2root-crypt.c') diff --git a/key2root-crypt.c b/key2root-crypt.c new file mode 100644 index 0000000..961e00c --- /dev/null +++ b/key2root-crypt.c @@ -0,0 +1,78 @@ +/* See LICENSE file for copyright and license details. */ +#include +#include +#include +#include +#include + +#include "arg.h" +#include "crypt.h" + + +char *argv0; + + +static void +usage(void) +{ + fprintf(stderr, "usage: %s [crypt-parameters]\n", argv0); + exit(1); +} + + +int +main(int argc, char *argv[]) +{ + const char *parameters; + char *key = NULL, *new; + size_t key_len = 0; + size_t key_size = 0; + char *hash; + ssize_t r; + + ARGBEGIN { + default: + usage(); + } ARGEND; + + if (argc > 1) + usage(); + + parameters = argv[0]; + + for (;;) { + if (key_len == key_size) { + new = malloc(1 + (key_size += 1024)); + if (!new) { + explicit_bzero(key, key_len); + fprintf(stderr, "%s: read : %s\n", argv0, strerror(errno)); + exit(1); + } + memcpy(new, key, key_len); + explicit_bzero(key, key_len); + free(key); + key = new; + } + r = read(STDIN_FILENO, &key[key_len], key_size - key_len); + if (r <= 0) { + if (!r) + break; + explicit_bzero(key, key_len); + fprintf(stderr, "%s: read : %s\n", argv0, strerror(errno)); + exit(1); + } + key_len += (size_t)r; + } + hash = key2root_crypt(key, key_len, parameters, 1); + if (!hash) + exit(1); + free(key); + printf("%s\n", hash); + free(hash); + + if (fflush(stdout) || ferror(stdout) || fclose(stdout)) { + fprintf(stderr, "%s: printf: %s\n", argv0, strerror(errno)); + exit(1); + } + return 0; +} -- cgit v1.2.3-70-g09d2