about summary refs log tree commit diff
path: root/pkgs/tools/networking/cjdns/makekey.patch
blob: fcce5e3e728e38ffd367c473fbff6e8e7327d2ca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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');