From 9a0d8730fa977f666b5c12e4c5901e7d0391e245 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Sat, 29 Jul 2023 14:32:06 +0100 Subject: Make various preparations for upcoming features A lot of this is random WIP from a while back, at least a month ago, and is being committed now to get it out of the way so that other patches can be brought in and integrated against it without causing headaches. Also rolled into this commit is a way to distinguish plugin_unload from exiting the game. This is required for another soon-to-be-integrated feature to avoid crashing on exit, and could in theory also be used to speed up unloading on exit in future. While we're at it, this also avoids the need to linearly scan through the plugin list to do the old branch unloading fix, because we can. Rough summary of the other smaller stuff I can remember doing: - Rework bitbuf a bit - Add some cryptographic nonsense in ac.c (not final at all) - Introduce the first couple of "chunklets" libraries as a sort-of subproject of this one - Tidy up random small bits and bobs - Add source for a small keypair generation tool - Rework democustom to be very marginally more useful --- tools/genkeypair.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tools/genkeypair.c (limited to 'tools/genkeypair.c') diff --git a/tools/genkeypair.c b/tools/genkeypair.c new file mode 100644 index 0000000..7db856b --- /dev/null +++ b/tools/genkeypair.c @@ -0,0 +1,42 @@ +// *SUPER* low effort x25519 keygen tool, for lack of better tool on hand. +// To compile: +// Unix: $CC -O2 -Dbool=_Bool -o.build/genkeypair tools/genkeypair.c +// Windows: clang-cl -fuse-ld=lld -O2 -Dbool=_Bool -Fe.build/genkeypair.exe tools/genkeypair.c /link advapi32.lib + +#include +#include + +#include "../src/3p/monocypher/monocypher.c" // yeah, we're doing this. +#include "../src/os.h" + +int main(void) { + unsigned char prv[32], pub[32]; + os_randombytes(prv, sizeof(prv)); + crypto_x25519_public_key(pub, prv); + // and now the worst string formatting code you've ever seen!!! + fputs("Private key: ", stdout); + for (int i = 0; i < sizeof(prv); i += 4) { + fprintf(stdout, "%.2X%.2X%.2X%.2X", + prv[i], prv[i + 1], prv[i + 2], prv[i + 3]); + } + fputs("\n{", stdout); + for (int i = 0; i < sizeof(prv) - 4; i += 4) { + fprintf(stdout, "0x%.2X, 0x%.2X, 0x%.2X, 0x%.2X, ", + prv[i], prv[i + 1], prv[i + 2], prv[i + 3]); + } + fprintf(stdout, "0x%.2X, 0x%.2X, 0x%.2X, 0x%.2X}\n\nPublic key: ", + prv[sizeof(prv) - 4], prv[sizeof(prv) - 3], + prv[sizeof(prv) - 2], prv[sizeof(prv) - 1]); + for (int i = 0; i < sizeof(pub); i += 4) { + fprintf(stdout, "%.2X%.2X%.2X%.2X", + pub[i], pub[i + 1], pub[i + 2], pub[i + 3]); + } + fputs("\n{", stdout); + for (int i = 0; i < sizeof(pub) - 4; i += 4) { + fprintf(stdout, "0x%.2X, 0x%.2X, 0x%.2X, 0x%.2X, ", + pub[i], pub[i + 1], pub[i + 2], pub[i + 3]); + } + fprintf(stdout, "0x%.2X, 0x%.2X, 0x%.2X, 0x%.2X}\n", + pub[sizeof(pub) - 4], pub[sizeof(pub) - 3], + pub[sizeof(pub) - 2], pub[sizeof(pub) - 1]); +} -- cgit v1.2.3