cjdns/cjdns.sodium.patch

232 lines
7.2 KiB
Diff

diff -up ./client/cjdroute2.c.sodium ./client/cjdroute2.c
--- ./client/cjdroute2.c.sodium 2020-12-16 14:14:51.140783237 -0500
+++ ./client/cjdroute2.c 2020-12-16 14:14:51.146783327 -0500
@@ -64,6 +64,7 @@
#include <string.h>
#include <time.h>
#include <stdlib.h>
+#include <sodium.h>
#define DEFAULT_TUN_DEV "tun0"
@@ -597,6 +598,9 @@ static String* getPipePath(Dict* config,
int main(int argc, char** argv)
{
+ if (sodium_init() == -1) {
+ return 1;
+ }
#ifdef Log_KEYS
fprintf(stderr, "Log_LEVEL = KEYS, EXPECT TO SEE PRIVATE KEYS IN YOUR LOGS!\n");
#endif
diff -up ./contrib/c/makekeys.c.sodium ./contrib/c/makekeys.c
--- ./contrib/c/makekeys.c.sodium 2020-10-05 17:46:19.000000000 -0400
+++ ./contrib/c/makekeys.c 2020-12-16 14:14:51.147783342 -0500
@@ -22,9 +22,13 @@
#include <signal.h>
#include <stdio.h>
+#include <sodium.h>
int main(int argc, char** argv)
{
+ if (sodium_init() == -1) {
+ return 1;
+ }
struct Allocator* alloc = MallocAllocator_new(1<<22);
struct Random* rand = Random_new(alloc, NULL, NULL);
diff -up ./contrib/c/mkpasswd.c.sodium ./contrib/c/mkpasswd.c
--- ./contrib/c/mkpasswd.c.sodium 2020-10-05 17:46:19.000000000 -0400
+++ ./contrib/c/mkpasswd.c 2020-12-16 14:14:51.147783342 -0500
@@ -18,9 +18,13 @@
#include <stdio.h>
#include <unistd.h>
+#include <sodium.h>
int main()
{
+ if (sodium_init() == -1) {
+ return 1;
+ }
struct Allocator* alloc = MallocAllocator_new(1<<22);
struct Random* rand = Random_new(alloc, NULL, NULL);
diff -up ./contrib/c/privatetopublic.c.sodium ./contrib/c/privatetopublic.c
--- ./contrib/c/privatetopublic.c.sodium 2020-10-05 17:46:19.000000000 -0400
+++ ./contrib/c/privatetopublic.c 2020-12-16 14:14:51.147783342 -0500
@@ -23,6 +23,7 @@
#include <stdio.h>
#include <errno.h>
#include <string.h>
+#include <sodium.h>
static int usage(char* appName)
{
@@ -67,6 +68,9 @@ int main(int argc, char** argv)
break;
}
}
+ if (sodium_init() == -1) {
+ return 1;
+ }
Hex_decode(privateKey, 32, privateKeyHexIn, 64);
crypto_scalarmult_curve25519_base(address.key, privateKey);
diff -up ./contrib/c/publictoip6.c.sodium ./contrib/c/publictoip6.c
--- ./contrib/c/publictoip6.c.sodium 2020-10-05 17:46:19.000000000 -0400
+++ ./contrib/c/publictoip6.c 2020-12-16 14:14:51.147783342 -0500
@@ -16,6 +16,7 @@
#include "util/AddrTools.h"
#include "util/CString.h"
#include <stdio.h>
+#include <sodium.h>
static int usage(char* appName)
{
@@ -36,6 +37,9 @@ int main(int argc, char** argv)
uint8_t keyBytes[32];
uint8_t ip6Bytes[16];
String key = { .bytes = argv[1], .len = CString_strlen(argv[1]) };
+ if (sodium_init() == -1) {
+ return 1;
+ }
int ret = Key_parse(&key, keyBytes, ip6Bytes);
switch (ret) {
diff -up ./contrib/c/sybilsim.c.sodium ./contrib/c/sybilsim.c
--- ./contrib/c/sybilsim.c.sodium 2020-10-05 17:46:19.000000000 -0400
+++ ./contrib/c/sybilsim.c 2020-12-16 14:14:51.148783357 -0500
@@ -42,6 +42,7 @@
#include "crypto_scalarmult_curve25519.h"
#include <unistd.h> // isatty()
+#include <sodium.h> // isatty()
struct NodeContext {
struct Sockaddr* boundAddr;
@@ -441,6 +442,9 @@ int main(int argc, char** argv)
if (isatty(STDIN_FILENO)) {
return usage(argv[0]);
}
+ if (sodium_init() == -1) {
+ return 1;
+ }
struct Allocator* alloc = MallocAllocator_new(1LL<<31);
diff -up ./crypto/random/randombytes.c.sodium ./crypto/random/randombytes.c
--- ./crypto/random/randombytes.c.sodium 2020-10-05 17:46:19.000000000 -0400
+++ ./crypto/random/randombytes.c 2020-12-16 14:14:51.148783357 -0500
@@ -17,6 +17,7 @@
#include "memory/MallocAllocator.h"
#include <unistd.h>
+#include <sodium.h>
int main()
{
@@ -29,6 +30,9 @@ int main()
} str;
size_t out = 0;
+ if (sodium_init() == -1) {
+ return 1;
+ }
for (;;) {
Random_bytes(rand, str.buff, 4096);
out = write(STDOUT_FILENO, str.buff, 4096);
diff -up ./node_build/make.js.sodium ./node_build/make.js
--- ./node_build/make.js.sodium 2020-10-05 17:46:19.000000000 -0400
+++ ./node_build/make.js 2020-12-16 14:15:59.646810621 -0500
@@ -251,49 +251,8 @@ Builder.configure({
}).nThen(function (waitFor) {
- builder.config.libs.push(dependencyDir + '/cnacl/jsbuild/libnacl.a');
- builder.config.includeDirs.push(dependencyDir + '/cnacl/jsbuild/include/');
-
- // needed for Sign.c which pulls in crypto_int32.h
- builder.config.includeDirs.push(dependencyDir + '/cnacl/jsbuild/include_internal/');
-
- Fs.exists(dependencyDir + '/cnacl/jsbuild/libnacl.a', waitFor(function (exists) {
- if (exists) { return; }
-
- console.log("Build NaCl");
- var cwd = process.cwd();
- process.chdir(dependencyDir + '/cnacl/');
-
- // $FlowFixMe non-static require
- var NaCl = require(process.cwd() + '/node_build/make.js');
- NaCl.build(function (args, callback) {
- if (builder.config.systemName !== 'win32') {
- args.unshift('-fPIC');
- }
-
- args.unshift(optimizeLevel, '-fomit-frame-pointer');
-
- if (!/^\-O0$/.test(optimizeLevel)) {
- args.unshift('-D_FORTIFY_SOURCE=2');
- }
-
- if (CFLAGS) {
- [].push.apply(args, CFLAGS.split(' '));
- }
-
- if (!builder.config.crossCompiling) {
- if (NO_MARCH_FLAG.indexOf(process.arch) == -1) {
- args.unshift('-march=native');
- }
- }
-
- builder.cc(args, callback);
- },
- builder.config,
- waitFor(function () {
- process.chdir(cwd);
- }));
- }));
+ builder.config.libs.push('-lsodium');
+ builder.config.includeDirs.push('/usr/include/sodium/');
}).nThen(function (waitFor) {
@@ -440,7 +399,7 @@ Builder.configure({
builder.buildExecutable('crypto/random/randombytes.c');
builder.lintFiles(function (fileName, file, callback) {
- if (/dependencies/.test(fileName) || /crypto\/sign/.test(fileName)) {
+ if (/(dependencies|\/usr\/include)/.test(fileName) || /crypto\/sign/.test(fileName)) {
callback('', false);
return;
}
@@ -471,4 +430,4 @@ Builder.configure({
console.log('\x1b[1;31mFailed to build cjdns.\x1b[0m');
process.exit(1);
-});
\ No newline at end of file
+});
diff -up ./test/testcjdroute.c.sodium ./test/testcjdroute.c
--- ./test/testcjdroute.c.sodium 2020-10-05 17:46:19.000000000 -0400
+++ ./test/testcjdroute.c 2020-12-16 14:14:51.148783357 -0500
@@ -26,6 +26,7 @@
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
+#include <sodium.h>
#ifdef SUBNODE
#define testcjdroute_SUBNODE 1
@@ -269,6 +270,9 @@ static int main2(int argc, char** argv,
int main(int argc, char** argv)
{
+ if (sodium_init() == -1) {
+ return 1;
+ }
struct Allocator* alloc = MallocAllocator_new(1<<24);
struct RandomSeed* rs = DeterminentRandomSeed_new(alloc, RANDOM_SEED);
struct Random* detRand = Random_newWithSeed(alloc, NULL, rs, NULL);