nixpkgs/pkgs/tools/networking/cjdns/makekey.patch

65 lines
2.1 KiB
Diff
Raw Normal View History

diff --git a/contrib/c/makekey.c b/contrib/c/makekey.c
new file mode 100644
index 0000000..c7184e5
--- /dev/null
+++ b/contrib/c/makekey.c
@@ -0,0 +1,46 @@
+/* vim: set expandtab ts=4 sw=4: */
+/*
+ * You may redistribute this program and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "crypto/random/Random.h"
+#include "memory/MallocAllocator.h"
+#include "crypto/AddressCalc.h"
+#include "util/AddrTools.h"
+#include "util/Hex.h"
+
+#include "crypto_scalarmult_curve25519.h"
+
+#include <stdio.h>
+
+int main(int argc, char** argv)
+{
+ struct Allocator* alloc = MallocAllocator_new(1<<22);
+ struct Random* rand = Random_new(alloc, NULL, NULL);
+
+ uint8_t privateKey[32];
+ uint8_t publicKey[32];
+ uint8_t ip[16];
+ uint8_t hexPrivateKey[65];
+
+ for (;;) {
+ Random_bytes(rand, privateKey, 32);
+ crypto_scalarmult_curve25519_base(publicKey, privateKey);
+ if (AddressCalc_addressForPublicKey(ip, publicKey)) {
+ Hex_encode(hexPrivateKey, 65, privateKey, 32);
+ printf(hexPrivateKey);
+ return 0;
+ }
+ }
+ return 0;
+}
+
diff --git a/node_build/make.js b/node_build/make.js
index 5e51645..11465e3 100644
--- a/node_build/make.js
+++ b/node_build/make.js
@@ -339,6 +339,7 @@ Builder.configure({
builder.buildExecutable('contrib/c/privatetopublic.c');
builder.buildExecutable('contrib/c/sybilsim.c');
builder.buildExecutable('contrib/c/makekeys.c');
+ builder.buildExecutable('contrib/c/makekey.c');
builder.buildExecutable('crypto/random/randombytes.c');