1 // SPDX-License-Identifier: GPL-2.0 OR MIT
3 * Copyright (C) 2015-2020 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
9 #include "curve25519.h"
11 #include "subcommands.h"
14 int pubkey_main(int argc, const char *argv[])
16 uint8_t key[WG_KEY_LEN] __attribute__((aligned(sizeof(uintptr_t))));
17 char base64[WG_KEY_LEN_BASE64];
21 fprintf(stderr, "Usage: %s %s\n", PROG_NAME, argv[0]);
25 if (fread(base64, 1, sizeof(base64) - 1, stdin) != sizeof(base64) - 1) {
27 fprintf(stderr, "%s: Key is not the correct length or format\n", PROG_NAME);
30 base64[WG_KEY_LEN_BASE64 - 1] = '\0';
33 trailing_char = getc(stdin);
34 if (!trailing_char || char_is_space(trailing_char))
36 if (trailing_char == EOF)
38 fprintf(stderr, "%s: Trailing characters found after key\n", PROG_NAME);
42 if (!key_from_base64(key, base64)) {
43 fprintf(stderr, "%s: Key is not the correct length or format\n", PROG_NAME);
46 curve25519_generate_public(key, key);
47 key_to_base64(base64, key);