cjdns/cjdns.sodium.patch

232 lines
7.2 KiB
Diff
Raw Normal View History

diff -up ./client/cjdroute2.c.sodium ./client/cjdroute2.c
2020-12-16 19:29:47 +00:00
--- ./client/cjdroute2.c.sodium 2020-12-16 14:14:51.140783237 -0500
+++ ./client/cjdroute2.c 2020-12-16 14:14:51.146783327 -0500
2020-09-29 14:53:35 +00:00
@@ -64,6 +64,7 @@
#include <string.h>
#include <time.h>
#include <stdlib.h>
+#include <sodium.h>
#define DEFAULT_TUN_DEV "tun0"
2020-12-16 19:29:47 +00:00
@@ -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
2020-12-16 19:29:47 +00:00
--- ./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
2020-09-29 14:53:35 +00:00
@@ -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
2020-12-16 19:29:47 +00:00
--- ./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
2020-12-16 19:29:47 +00:00
--- ./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;
+ }
2018-02-21 18:58:17 +00:00
Hex_decode(privateKey, 32, privateKeyHexIn, 64);
crypto_scalarmult_curve25519_base(address.key, privateKey);
diff -up ./contrib/c/publictoip6.c.sodium ./contrib/c/publictoip6.c
2020-12-16 19:29:47 +00:00
--- ./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
2020-12-16 19:29:47 +00:00
--- ./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
2020-12-16 19:29:47 +00:00
--- ./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);
2016-10-12 20:36:47 +00:00
diff -up ./node_build/make.js.sodium ./node_build/make.js
2020-12-16 19:29:47 +00:00
--- ./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({
2016-04-18 20:23:46 +00:00
}).nThen(function (waitFor) {
- builder.config.libs.push(dependencyDir + '/cnacl/jsbuild/libnacl.a');
- builder.config.includeDirs.push(dependencyDir + '/cnacl/jsbuild/include/');
-
2016-10-12 20:36:47 +00:00
- // needed for Sign.c which pulls in crypto_int32.h
- builder.config.includeDirs.push(dependencyDir + '/cnacl/jsbuild/include_internal/');
-
2016-04-18 20:23:46 +00:00
- 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/');
-
2020-12-16 19:29:47 +00:00
- // $FlowFixMe non-static require
2016-04-18 20:23:46 +00:00
- var NaCl = require(process.cwd() + '/node_build/make.js');
- NaCl.build(function (args, callback) {
- if (builder.config.systemName !== 'win32') {
- args.unshift('-fPIC');
- }
-
2020-12-16 19:29:47 +00:00
- args.unshift(optimizeLevel, '-fomit-frame-pointer');
2016-04-18 20:23:46 +00:00
-
2020-12-16 19:29:47 +00:00
- if (!/^\-O0$/.test(optimizeLevel)) {
2018-02-21 18:58:17 +00:00
- args.unshift('-D_FORTIFY_SOURCE=2');
- }
-
2016-04-18 20:23:46 +00:00
- if (CFLAGS) {
- [].push.apply(args, CFLAGS.split(' '));
- }
-
- if (!builder.config.crossCompiling) {
2018-02-21 18:58:17 +00:00
- if (NO_MARCH_FLAG.indexOf(process.arch) == -1) {
- args.unshift('-march=native');
2016-04-18 20:23:46 +00:00
- }
- }
-
- 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) {
2020-12-16 19:29:47 +00:00
@@ -440,7 +399,7 @@ Builder.configure({
2016-04-18 20:23:46 +00:00
builder.buildExecutable('crypto/random/randombytes.c');
builder.lintFiles(function (fileName, file, callback) {
2020-09-29 14:53:35 +00:00
- if (/dependencies/.test(fileName) || /crypto\/sign/.test(fileName)) {
+ if (/(dependencies|\/usr\/include)/.test(fileName) || /crypto\/sign/.test(fileName)) {
2016-04-18 20:23:46 +00:00
callback('', false);
return;
}
2020-12-16 19:29:47 +00:00
@@ -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
2020-12-16 19:29:47 +00:00
--- ./test/testcjdroute.c.sodium 2020-10-05 17:46:19.000000000 -0400
+++ ./test/testcjdroute.c 2020-12-16 14:14:51.148783357 -0500
2020-09-29 14:53:35 +00:00
@@ -26,6 +26,7 @@
#include <stdio.h>
2020-09-29 14:53:35 +00:00
#include <unistd.h>
#include <fcntl.h>
+#include <sodium.h>
#ifdef SUBNODE
#define testcjdroute_SUBNODE 1
2020-12-16 19:29:47 +00:00
@@ -269,6 +270,9 @@ static int main2(int argc, char** argv,
int main(int argc, char** argv)
{
+ if (sodium_init() == -1) {
+ return 1;
+ }
2020-09-29 14:53:35 +00:00
struct Allocator* alloc = MallocAllocator_new(1<<24);
struct RandomSeed* rs = DeterminentRandomSeed_new(alloc, RANDOM_SEED);
struct Random* detRand = Random_newWithSeed(alloc, NULL, rs, NULL);