# HG changeset patch # User Ivo Smits # Date 1298843331 -3600 # Node ID c1e5af9329f13e129b2bd2da2484a7502f083e66 # Parent d2b0f399a9aae66845072f69767436904e03d8d5 Removed some redundant files diff -r d2b0f399a9aa -r c1e5af9329f1 include/crypto_box_curve25519salsa20hmacsha512.h --- a/include/crypto_box_curve25519salsa20hmacsha512.h Sun Feb 27 22:47:22 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -#ifndef crypto_box_curve25519salsa20hmacsha512_H -#define crypto_box_curve25519salsa20hmacsha512_H - -#define crypto_box_curve25519salsa20hmacsha512_ref_PUBLICKEYBYTES 32 -#define crypto_box_curve25519salsa20hmacsha512_ref_SECRETKEYBYTES 32 -#define crypto_box_curve25519salsa20hmacsha512_ref_BEFORENMBYTES 32 -#define crypto_box_curve25519salsa20hmacsha512_ref_NONCEBYTES 8 -#define crypto_box_curve25519salsa20hmacsha512_ref_ZEROBYTES 32 -#define crypto_box_curve25519salsa20hmacsha512_ref_BOXZEROBYTES 0 -#ifdef __cplusplus -extern "C" { -#endif -extern int crypto_box_curve25519salsa20hmacsha512_ref(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *,const unsigned char *); -extern int crypto_box_curve25519salsa20hmacsha512_ref_open(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *,const unsigned char *); -extern int crypto_box_curve25519salsa20hmacsha512_ref_keypair(unsigned char *,unsigned char *); -extern int crypto_box_curve25519salsa20hmacsha512_ref_beforenm(unsigned char *,const unsigned char *,const unsigned char *); -extern int crypto_box_curve25519salsa20hmacsha512_ref_afternm(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *); -extern int crypto_box_curve25519salsa20hmacsha512_ref_open_afternm(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *); -#ifdef __cplusplus -} -#endif - -#define crypto_box_curve25519salsa20hmacsha512 crypto_box_curve25519salsa20hmacsha512_ref -#define crypto_box_curve25519salsa20hmacsha512_open crypto_box_curve25519salsa20hmacsha512_ref_open -#define crypto_box_curve25519salsa20hmacsha512_keypair crypto_box_curve25519salsa20hmacsha512_ref_keypair -#define crypto_box_curve25519salsa20hmacsha512_beforenm crypto_box_curve25519salsa20hmacsha512_ref_beforenm -#define crypto_box_curve25519salsa20hmacsha512_afternm crypto_box_curve25519salsa20hmacsha512_ref_afternm -#define crypto_box_curve25519salsa20hmacsha512_open_afternm crypto_box_curve25519salsa20hmacsha512_ref_open_afternm -#define crypto_box_curve25519salsa20hmacsha512_PUBLICKEYBYTES crypto_box_curve25519salsa20hmacsha512_ref_PUBLICKEYBYTES -#define crypto_box_curve25519salsa20hmacsha512_SECRETKEYBYTES crypto_box_curve25519salsa20hmacsha512_ref_SECRETKEYBYTES -#define crypto_box_curve25519salsa20hmacsha512_BEFORENMBYTES crypto_box_curve25519salsa20hmacsha512_ref_BEFORENMBYTES -#define crypto_box_curve25519salsa20hmacsha512_NONCEBYTES crypto_box_curve25519salsa20hmacsha512_ref_NONCEBYTES -#define crypto_box_curve25519salsa20hmacsha512_ZEROBYTES crypto_box_curve25519salsa20hmacsha512_ref_ZEROBYTES -#define crypto_box_curve25519salsa20hmacsha512_BOXZEROBYTES crypto_box_curve25519salsa20hmacsha512_ref_BOXZEROBYTES -#define crypto_box_curve25519salsa20hmacsha512_IMPLEMENTATION "crypto_box/curve25519salsa20hmacsha512/ref" -#ifndef crypto_box_curve25519salsa20hmacsha512_ref_VERSION -#define crypto_box_curve25519salsa20hmacsha512_ref_VERSION "-" -#endif -#define crypto_box_curve25519salsa20hmacsha512_VERSION crypto_box_curve25519salsa20hmacsha512_ref_VERSION - -#endif diff -r d2b0f399a9aa -r c1e5af9329f1 src/crypto_scalarmult_curve25519.c --- a/src/crypto_scalarmult_curve25519.c Sun Feb 27 22:47:22 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,265 +0,0 @@ -/* -version 20081011 -Matthew Dempsky -Public domain. -Derived from public domain code by D. J. Bernstein. -*/ - -//#include "crypto_scalarmult.h" - -static void add(unsigned int out[32],const unsigned int a[32],const unsigned int b[32]) -{ - unsigned int j; - unsigned int u; - u = 0; - for (j = 0;j < 31;++j) { u += a[j] + b[j]; out[j] = u & 255; u >>= 8; } - u += a[31] + b[31]; out[31] = u; -} - -static void sub(unsigned int out[32],const unsigned int a[32],const unsigned int b[32]) -{ - unsigned int j; - unsigned int u; - u = 218; - for (j = 0;j < 31;++j) { - u += a[j] + 65280 - b[j]; - out[j] = u & 255; - u >>= 8; - } - u += a[31] - b[31]; - out[31] = u; -} - -static void squeeze(unsigned int a[32]) -{ - unsigned int j; - unsigned int u; - u = 0; - for (j = 0;j < 31;++j) { u += a[j]; a[j] = u & 255; u >>= 8; } - u += a[31]; a[31] = u & 127; - u = 19 * (u >> 7); - for (j = 0;j < 31;++j) { u += a[j]; a[j] = u & 255; u >>= 8; } - u += a[31]; a[31] = u; -} - -static const unsigned int minusp[32] = { - 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128 -} ; - -static void freeze(unsigned int a[32]) -{ - unsigned int aorig[32]; - unsigned int j; - unsigned int negative; - - for (j = 0;j < 32;++j) aorig[j] = a[j]; - add(a,a,minusp); - negative = -((a[31] >> 7) & 1); - for (j = 0;j < 32;++j) a[j] ^= negative & (aorig[j] ^ a[j]); -} - -static void mult(unsigned int out[32],const unsigned int a[32],const unsigned int b[32]) -{ - unsigned int i; - unsigned int j; - unsigned int u; - - for (i = 0;i < 32;++i) { - u = 0; - for (j = 0;j <= i;++j) u += a[j] * b[i - j]; - for (j = i + 1;j < 32;++j) u += 38 * a[j] * b[i + 32 - j]; - out[i] = u; - } - squeeze(out); -} - -static void mult121665(unsigned int out[32],const unsigned int a[32]) -{ - unsigned int j; - unsigned int u; - - u = 0; - for (j = 0;j < 31;++j) { u += 121665 * a[j]; out[j] = u & 255; u >>= 8; } - u += 121665 * a[31]; out[31] = u & 127; - u = 19 * (u >> 7); - for (j = 0;j < 31;++j) { u += out[j]; out[j] = u & 255; u >>= 8; } - u += out[j]; out[j] = u; -} - -static void square(unsigned int out[32],const unsigned int a[32]) -{ - unsigned int i; - unsigned int j; - unsigned int u; - - for (i = 0;i < 32;++i) { - u = 0; - for (j = 0;j < i - j;++j) u += a[j] * a[i - j]; - for (j = i + 1;j < i + 32 - j;++j) u += 38 * a[j] * a[i + 32 - j]; - u *= 2; - if ((i & 1) == 0) { - u += a[i / 2] * a[i / 2]; - u += 38 * a[i / 2 + 16] * a[i / 2 + 16]; - } - out[i] = u; - } - squeeze(out); -} - -static void select(unsigned int p[64],unsigned int q[64],const unsigned int r[64],const unsigned int s[64],unsigned int b) -{ - unsigned int j; - unsigned int t; - unsigned int bminus1; - - bminus1 = b - 1; - for (j = 0;j < 64;++j) { - t = bminus1 & (r[j] ^ s[j]); - p[j] = s[j] ^ t; - q[j] = r[j] ^ t; - } -} - -static void mainloop(unsigned int work[64],const unsigned char e[32]) -{ - unsigned int xzm1[64]; - unsigned int xzm[64]; - unsigned int xzmb[64]; - unsigned int xzm1b[64]; - unsigned int xznb[64]; - unsigned int xzn1b[64]; - unsigned int a0[64]; - unsigned int a1[64]; - unsigned int b0[64]; - unsigned int b1[64]; - unsigned int c1[64]; - unsigned int r[32]; - unsigned int s[32]; - unsigned int t[32]; - unsigned int u[32]; - unsigned int i; - unsigned int j; - unsigned int b; - int pos; - - for (j = 0;j < 32;++j) xzm1[j] = work[j]; - xzm1[32] = 1; - for (j = 33;j < 64;++j) xzm1[j] = 0; - - xzm[0] = 1; - for (j = 1;j < 64;++j) xzm[j] = 0; - - for (pos = 254;pos >= 0;--pos) { - b = e[pos / 8] >> (pos & 7); - b &= 1; - select(xzmb,xzm1b,xzm,xzm1,b); - add(a0,xzmb,xzmb + 32); - sub(a0 + 32,xzmb,xzmb + 32); - add(a1,xzm1b,xzm1b + 32); - sub(a1 + 32,xzm1b,xzm1b + 32); - square(b0,a0); - square(b0 + 32,a0 + 32); - mult(b1,a1,a0 + 32); - mult(b1 + 32,a1 + 32,a0); - add(c1,b1,b1 + 32); - sub(c1 + 32,b1,b1 + 32); - square(r,c1 + 32); - sub(s,b0,b0 + 32); - mult121665(t,s); - add(u,t,b0); - mult(xznb,b0,b0 + 32); - mult(xznb + 32,s,u); - square(xzn1b,c1); - mult(xzn1b + 32,r,work); - select(xzm,xzm1,xznb,xzn1b,b); - } - - for (j = 0;j < 64;++j) work[j] = xzm[j]; -} - -static void recip(unsigned int out[32],const unsigned int z[32]) -{ - unsigned int z2[32]; - unsigned int z9[32]; - unsigned int z11[32]; - unsigned int z2_5_0[32]; - unsigned int z2_10_0[32]; - unsigned int z2_20_0[32]; - unsigned int z2_50_0[32]; - unsigned int z2_100_0[32]; - unsigned int t0[32]; - unsigned int t1[32]; - int i; - - /* 2 */ square(z2,z); - /* 4 */ square(t1,z2); - /* 8 */ square(t0,t1); - /* 9 */ mult(z9,t0,z); - /* 11 */ mult(z11,z9,z2); - /* 22 */ square(t0,z11); - /* 2^5 - 2^0 = 31 */ mult(z2_5_0,t0,z9); - - /* 2^6 - 2^1 */ square(t0,z2_5_0); - /* 2^7 - 2^2 */ square(t1,t0); - /* 2^8 - 2^3 */ square(t0,t1); - /* 2^9 - 2^4 */ square(t1,t0); - /* 2^10 - 2^5 */ square(t0,t1); - /* 2^10 - 2^0 */ mult(z2_10_0,t0,z2_5_0); - - /* 2^11 - 2^1 */ square(t0,z2_10_0); - /* 2^12 - 2^2 */ square(t1,t0); - /* 2^20 - 2^10 */ for (i = 2;i < 10;i += 2) { square(t0,t1); square(t1,t0); } - /* 2^20 - 2^0 */ mult(z2_20_0,t1,z2_10_0); - - /* 2^21 - 2^1 */ square(t0,z2_20_0); - /* 2^22 - 2^2 */ square(t1,t0); - /* 2^40 - 2^20 */ for (i = 2;i < 20;i += 2) { square(t0,t1); square(t1,t0); } - /* 2^40 - 2^0 */ mult(t0,t1,z2_20_0); - - /* 2^41 - 2^1 */ square(t1,t0); - /* 2^42 - 2^2 */ square(t0,t1); - /* 2^50 - 2^10 */ for (i = 2;i < 10;i += 2) { square(t1,t0); square(t0,t1); } - /* 2^50 - 2^0 */ mult(z2_50_0,t0,z2_10_0); - - /* 2^51 - 2^1 */ square(t0,z2_50_0); - /* 2^52 - 2^2 */ square(t1,t0); - /* 2^100 - 2^50 */ for (i = 2;i < 50;i += 2) { square(t0,t1); square(t1,t0); } - /* 2^100 - 2^0 */ mult(z2_100_0,t1,z2_50_0); - - /* 2^101 - 2^1 */ square(t1,z2_100_0); - /* 2^102 - 2^2 */ square(t0,t1); - /* 2^200 - 2^100 */ for (i = 2;i < 100;i += 2) { square(t1,t0); square(t0,t1); } - /* 2^200 - 2^0 */ mult(t1,t0,z2_100_0); - - /* 2^201 - 2^1 */ square(t0,t1); - /* 2^202 - 2^2 */ square(t1,t0); - /* 2^250 - 2^50 */ for (i = 2;i < 50;i += 2) { square(t0,t1); square(t1,t0); } - /* 2^250 - 2^0 */ mult(t0,t1,z2_50_0); - - /* 2^251 - 2^1 */ square(t1,t0); - /* 2^252 - 2^2 */ square(t0,t1); - /* 2^253 - 2^3 */ square(t1,t0); - /* 2^254 - 2^4 */ square(t0,t1); - /* 2^255 - 2^5 */ square(t1,t0); - /* 2^255 - 21 */ mult(out,t1,z11); -} - -int crypto_scalarmult(unsigned char *q, - const unsigned char *n, - const unsigned char *p) -{ - unsigned int work[96]; - unsigned char e[32]; - unsigned int i; - for (i = 0;i < 32;++i) e[i] = n[i]; - e[0] &= 248; - e[31] &= 127; - e[31] |= 64; - for (i = 0;i < 32;++i) work[i] = p[i]; - mainloop(work,e); - recip(work + 32,work + 32); - mult(work + 64,work,work + 32); - freeze(work + 64); - for (i = 0;i < 32;++i) q[i] = work[64 + i]; - return 0; -} diff -r d2b0f399a9aa -r c1e5af9329f1 src/nacltest.c --- a/src/nacltest.c Sun Feb 27 22:47:22 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -#include "crypto_box.h" - -int main() { - unsigned char n[crypto_box_NONCEBYTES]; - unsigned char m[32+crypto_box_ZEROBYTES]; - unsigned char c[32+crypto_box_ZEROBYTES]; - - unsigned char pk[crypto_box_PUBLICKEYBYTES]; - unsigned char sk[crypto_box_SECRETKEYBYTES]; - //crypto_box_keypair(pk, sk); - //randombytes(sk,32); - sk[0]=1; - crypto_scalarmult_curve25519_base(pk,sk); - - - int r; - - unsigned char* buffer1offset = m + crypto_box_ZEROBYTES; - - strcpy(buffer1offset, "hello world"); - printf("in=$s\n", buffer1offset); - memset(m, 0, crypto_box_ZEROBYTES); - r=crypto_box(c, m, 32+crypto_box_ZEROBYTES, n, pk, sk); - printf("ret=%d\n", r); - - memset(c, 0, crypto_box_BOXZEROBYTES); - r=crypto_box_open(m, c, 32+crypto_box_ZEROBYTES, n, pk, sk); - printf("ret=%d\n", r); - printf("out=$s\n", buffer1offset); -} diff -r d2b0f399a9aa -r c1e5af9329f1 src/run.debian.c --- a/src/run.debian.c Sun Feb 27 22:47:22 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -/* Copyright 2010 Ivo Smits . All rights reserved. - Redistribution and use in source and binary forms, with or without modification, are - permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, this list of - conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, this list - of conditions and the following disclaimer in the documentation and/or other materials - provided with the distribution. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED - WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - The views and conclusions contained in the software and documentation are those of the - authors and should not be interpreted as representing official policies, either expressed - or implied, of Ivo Smits.*/ - -#include -#include -#include -#include -#include - -char* getenvdeb(const char* name) { - char tmp[1024] = "IF_QT_"; - if (strcmp(name, "INTERFACE") == 0) return getenv("IFACE"); - /*if (strlen(tmp) + strlen(name) >= 1024) { - fprintf(stderr, "Error: prefixed environment variable name is too long"); - return NULL; - }*/ - strncat(tmp, name, 1024 - 6 - 1); - return getenv(tmp); -} - -int main() { - /* Header */ - printf("UCIS QuickTun (c) 2010 Ivo Smits \n"); - printf("More information: http://wiki.qontrol.nl/QuickTun\n"); - - char* lib = NULL; - if (getenvdeb("PRIVATE_KEY")) { - lib = "libquicltun.nacl0"; - } else { - lib = "libquicltun.raw"; - } - - void* dl = dlopen(lib, RTLD_LAZY); - if (!dl) { - fprintf(stderr, "Error: library %s not found: %s\n", lib, dlerror()); - return -1; - } - void** getconfig = dlsym(dl, "getconf"); - if (!dl) { - fprintf(stderr, "Error: symbol getconf not found: %s\n", dlerror()); - return -1; - } - void* tunmain = dlsym(dl, "tunmain"); - if (!dl) { - fprintf(stderr, "Error: symbol tunmain not found: %s\n", dlerror()); - return -1; - } - - *getconfig = (void*)getenvdeb; - ((void (*)())tunmain)(); -}