[Verse-cvs] [verse] SVN commit:[4536] WIP: Removed encryption from verse.
Jiri Hnidek
jiri.hnidek at tul.cz
Fri Aug 22 14:30:16 CEST 2008
Revision: 4536
https://svn.blender.org//revision/?rev=4536&view=rev
Author: jiri
Date: 2008-08-22 14:30:15 +0200 (Fri, 22 Aug 2008)
Log Message:
-----------
WIP: Removed encryption from verse. Nathan requested this, because he wants to test his Verse.NET with my branch. I have plans to add DTLS encryption.
Modified Paths:
--------------
branches/verse-pam-branch/SConstruct
branches/verse-pam-branch/examples/list-nodes.c
branches/verse-pam-branch/v_cmd_def_s.c
branches/verse-pam-branch/v_connect.c
branches/verse-pam-branch/v_connection.c
branches/verse-pam-branch/v_connection.h
branches/verse-pam-branch/v_func_storage.c
branches/verse-pam-branch/v_man_pack_node.c
branches/verse-pam-branch/v_network_in_que.c
branches/verse-pam-branch/v_network_out_que.c
branches/verse-pam-branch/verse_header.h
branches/verse-pam-branch/vs_main.c
branches/verse-pam-branch/vs_node_storage.c
Removed Paths:
-------------
branches/verse-pam-branch/v_bignum.c
branches/verse-pam-branch/v_bignum.h
branches/verse-pam-branch/v_encryption.c
branches/verse-pam-branch/v_encryption.h
branches/verse-pam-branch/v_prime.c
branches/verse-pam-branch/v_randgen.c
branches/verse-pam-branch/v_randgen.h
Modified: branches/verse-pam-branch/SConstruct
===================================================================
--- branches/verse-pam-branch/SConstruct 2008-08-19 13:36:28 UTC (rev 4535)
+++ branches/verse-pam-branch/SConstruct 2008-08-22 12:30:15 UTC (rev 4536)
@@ -148,7 +148,6 @@
lib_source_files = (['v_cmd_buf.c',
'v_connect.c',
'v_connection.c',
- 'v_encryption.c',
'v_func_storage.c',
'v_man_pack_node.c',
'v_network.c',
@@ -156,10 +155,7 @@
'v_network_out_que.c',
'v_pack.c',
'v_pack_method.c',
- 'v_prime.c',
- 'v_randgen.c',
'v_util.c',
- 'v_bignum.c'
])
lib_source_files.extend(cmd_gen_deps)
Modified: branches/verse-pam-branch/examples/list-nodes.c
===================================================================
--- branches/verse-pam-branch/examples/list-nodes.c 2008-08-19 13:36:28 UTC (rev 4535)
+++ branches/verse-pam-branch/examples/list-nodes.c 2008-08-22 12:30:15 UTC (rev 4536)
@@ -79,7 +79,7 @@
if(pass!=NULL) {
/* Kick off program by connecting to Verse host on local machine. */
- verse_send_connect(username, pass, hostname, NULL);
+ verse_send_connect(username, pass, hostname);
while(TRUE)
verse_callback_update(10000); /* Listen to network, get callbacks. */
Deleted: branches/verse-pam-branch/v_bignum.c
===================================================================
--- branches/verse-pam-branch/v_bignum.c 2008-08-19 13:36:28 UTC (rev 4535)
+++ branches/verse-pam-branch/v_bignum.c 2008-08-22 12:30:15 UTC (rev 4536)
@@ -1,894 +0,0 @@
-/*
- * $Id$
- *
- * ***** BEGIN BSD LICENSE BLOCK *****
- *
- * Copyright (c) 2005-2008, The Uni-Verse Consortium.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * 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 BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER
- * 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.
- *
- * ***** END BSD LICENSE BLOCK *****
- *
- */
-
-/*
- * Routines for big (thousands of bits) unsigned integers, and
- * doing simple maths operations on them. Written by Emil Brink.
- *
- * Part of the Verse core, see license details elsewhere.
- *
- * Bignums are represented as vectors of VBigDig (unsigned short),
- * where the first element holds the length of the number in such
- * digits. So a 32-bit number would be { 2, low, high }; digits are
- * in little-endian format.
- *
- * Verse's uint16 and uint32 types are *not* used, since there is no
- * need to limit the bits. If your machine has 32-bit shorts and 64-
- * bit ints, this code should cope.
- *
- * By using unsigned shorts, which are assumed to be half the size of
- * an unsigned int, we can easily do intermediary steps in int-sized
- * variables, and thus get space for manual carry-management.
- *
- * This is the second incarnation of this code, the first one used
- * a fixed 2,048-bit VBigNum structure passed by value. It had to be
- * replaced since it was too weak for the desired functionality. Now,
- * there's roughly 1,5 weeks of time gone into this code, which still
- * means it's optimized for simplicity rather than speed.
- *
- * There has been neither time nor interest to meditate over FFTs and
- * Karatsubas. Reasonable improvements are of course welcome, although
- * this code *should* not be a bottleneck. Famous last words...
- *
- * In general, these routines do not do a lot of error checking, they
- * assume you know what you're doing. Numbers must have >0 digits.
- * Shifts should not be overly large (1e3 bits: safe, ~2e9+: avoid).
-*/
-
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "v_randgen.h"
-
-#include "v_bignum.h"
-
-#define MAX_DIG ((1UL << V_BIGBITS) - 1)
-
-/* ----------------------------------------------------------------------------------------- */
-
-/* Some routines need temporary storage to hold a term or two (the multi-
- * plier, for instance). Since we don't want to use malloc()/free(), let's
- * just have a bunch of digits that it's possible to allocate from in a
- * stack-like manner.
-*/
-static VBigDig heap[2048 + 32];
-static unsigned int heap_pos;
-
-/* Allocate a number of <n> digits, returning it un-initialized. */
-static VBigDig * bignum_alloc(unsigned int n)
-{
- VBigDig *y;
-
- if(heap_pos + n > sizeof heap / sizeof *heap)
- {
- printf("Out of memory in bignum heap -- unbalanced calls?\n");
- return NULL;
- }
- y = heap + heap_pos;
- heap_pos += n + 1;
- *y = n;
- return y;
-}
-
-/* Free a number previously allocated by bignum_allow() above. MUST match in sequences. */
-static void bignum_free(const VBigDig *x)
-{
- heap_pos -= *x + 1;
-}
-
-/* ----------------------------------------------------------------------------------------- */
-
-/* Set x from bits. External representation is big-endian byte array. */
-void v_bignum_raw_import(VBigDig *x, const void *bits)
-{
- const unsigned char *bytes = bits;
- int i;
-
- for(i = *x++ - 1; i >= 0; i--)
- {
- x[i] = ((VBigDig) *bytes++) << 8;
- x[i] |= *bytes++;
- }
-}
-
-/* Set bits to value of x. External representation is big-endian byte array. */
-void v_bignum_raw_export(const VBigDig *x, void *bits)
-{
- unsigned char *bytes = bits;
- int i;
-
- for(i = *x++ - 1; i >= 0; i--)
- {
- *bytes++ = x[i] >> 8;
- *bytes++ = (unsigned char) x[i];
- }
-}
-
-/* ----------------------------------------------------------------------------------------- */
-
-/* Assigns x = 0. */
-void v_bignum_set_zero(VBigDig *x)
-{
- memset(x + 1, 0, *x * sizeof *x);
-}
-
-/* Assigns x = 1. */
-void v_bignum_set_one(VBigDig *x)
-{
- int i;
-
- for(i = *x++ - 1, *x++ = 1; i > 0; i--)
- *x++ = 0;
-}
-
-/* Assigns x = y. */
-void v_bignum_set_digit(VBigDig *x, VBigDig y)
-{
- v_bignum_set_zero(x);
- x[1] = y;
-}
-
-/* Assigns x = <string>, with string in decimal ASCII. Kind of slow. */
-void v_bignum_set_string(VBigDig *x, const char *string)
-{
- unsigned int d;
-
- v_bignum_set_zero(x);
- for(; *string && isdigit(*string); string++)
- {
- v_bignum_mul_digit(x, 10);
- d = *string - '0';
- v_bignum_add_digit(x, d);
- }
-}
-
-/* Assigns x = <string>, with string in hexadecimal ASCII. */
-void v_bignum_set_string_hex(VBigDig *x, const char *string)
-{
- unsigned int d;
-
- if(string[0] == '0' && (string[1] == 'x' || string[1] == 'X'))
- string += 2;
- v_bignum_set_zero(x);
- for(; *string && isxdigit(*string); string++)
- {
- v_bignum_bit_shift_left(x, 4);
- d = tolower(*string) - '0';
- if(d > 9)
- d -= ('a' - '0') - 10;
- x[1] |= (d & 0xF);
- }
-}
-
-/* Performs x = y, taking care to handle different precisions correctly by truncating. */
-void v_bignum_set_bignum(VBigDig *x, const VBigDig *y)
-{
- int xs, ys, i, s;
-
- xs = x[0];
- ys = y[0];
- if(xs == ys) /* For same sizes, just memcpy() and be done. */
- {
- memcpy(x + 1, y + 1, xs * sizeof *x);
- return;
- }
- else if(ys > xs)
- s = xs;
- else
- s = ys;
- /* Copy as many digits as will fit, and clear any remaining high digits. */
- for(i = 1; i <= s; i++)
- x[i] = y[i];
- for(; i <= xs; i++)
- x[i] = 0;
-}
-
-/* Performs x = y[msb:msb-bits], right-adjusting the result. */
-void v_bignum_set_bignum_part(VBigDig *x, const VBigDig *y, unsigned int msb, unsigned int bits)
-{
- unsigned int i, bit;
-
- v_bignum_set_zero(x);
- if(y == NULL || msb > (y[0] * (CHAR_BIT * sizeof *x)))
- return;
- for(i = 0; i < bits; i++)
- {
- bit = msb - (bits - 1) + i;
- if(v_bignum_bit_test(y, bit))
- v_bignum_bit_set(x, i);
- }
-}
-
-/* Set x to a random bunch of bits. Should use a real random source. */
-void v_bignum_set_random(VBigDig *x, VRandGen *gen)
-{
- unsigned int s = *x++;
-
- if(gen != NULL)
- v_randgen_get(gen, x, s * sizeof *x);
- else
- {
- fprintf(stderr, "** Warning: Calling v_bignum_set_random() without VRandGen is potentially expensive\n");
- if((gen = v_randgen_new()) != NULL)
- {
- v_randgen_get(gen, x, s * sizeof *x);
- v_randgen_destroy(gen);
- }
- else
- fprintf(stderr, __FILE__ ": Couldn't create random number generator\n");
- }
-}
-
-/* Print x in hexadecimal, with 0x prefix but no linefeed. */
-void v_bignum_print_hex(const VBigDig *x)
-{
- int i, s = *x;
-
- printf("0x");
- for(i = 0; i < s; i++)
- printf("%04X", x[s - i]);
-}
-
-/* Print x in hexadecimal, with linefeed. */
-void v_bignum_print_hex_lf(const VBigDig *x)
-{
- v_bignum_print_hex(x);
- printf("\n");
-}
-
-/* ----------------------------------------------------------------------------------------- */
-
-/* x = ~x. */
-void v_bignum_not(VBigDig *x)
-{
- unsigned int i, s = *x++;
-
- for(i = 0; i < s; i++)
- x[i] = ~x[i];
-}
-
-int v_bignum_bit_test(const VBigDig *x, unsigned int bit)
-{
- unsigned int slot = bit / (CHAR_BIT * sizeof *x), m = 1 << (bit % (CHAR_BIT * sizeof *x));
-
- if(slot < x[0])
- return (x[slot + 1] & m) != 0;
- return 0;
-}
-
-/* Compute x |= (1 << bit). */
-void v_bignum_bit_set(VBigDig *x, unsigned int bit)
-{
- unsigned int slot, m;
-
- if(bit >= (*x * (CHAR_BIT * sizeof *x)))
- return;
- slot = bit / (CHAR_BIT * sizeof *x);
- m = 1 << (bit % (CHAR_BIT * sizeof *x));
- x[1 + slot] |= m;
-}
-
-/* Returns index of most signifant '1' bit of x, or -1 if x == 0. */
-int v_bignum_bit_msb(const VBigDig *x)
-{
- int i;
- unsigned int s = *x++;
-
- for(i = s - 1; i >= 0; i--)
- {
- if(x[i] != 0)
- {
- int bit = (i + 1) * (CHAR_BIT * sizeof *x) - 1;
- VBigDig d = x[i], mask;
-
- for(mask = 1 << (CHAR_BIT * sizeof *x - 1); mask != 0; mask >>= 1, bit--)
- {
- if(d & mask)
- return bit;
- }
- }
- }
- return -1;
-}
-
-int v_bignum_bit_size(const VBigDig *x)
-{
- return *x * V_BIGBITS;
-}
-
-/* Perform x <<= count. */
-void v_bignum_bit_shift_left(VBigDig *x, unsigned int count)
-{
- unsigned int t, carry, s = *x++;
- register int i;
-
- if(count >= CHAR_BIT * sizeof *x) /* Shift whole digits. */
- {
- unsigned int places = count / (CHAR_BIT * sizeof *x);
-
- for(i = s - 1; i >= (int) places; i--)
- x[i] = x[i - places];
- for(; i >= 0; i--) /* Clear out the LSBs. */
- x[i] = 0;
- count -= places * (CHAR_BIT * sizeof *x);
- if(count == 0)
- return;
- }
- /* Shift bits. */
- for(i = carry = 0; i < (int) s; i++)
- {
- t = (x[i] << count) | carry;
- x[i] = t;
- carry = t >> (CHAR_BIT * sizeof *x);
- }
-}
-
-/* Perform x <<= 1. This is a frequent operation so it can have its own function. */
-void v_bignum_bit_shift_left_1(VBigDig *x)
-{
- register unsigned int t, carry, s = *x++, i;
-
- /* Shift bits. */
- for(i = carry = 0; i < s; i++)
- {
- t = (x[i] << 1) | carry;
- x[i] = t;
- carry = t >> (CHAR_BIT * sizeof *x);
- }
-}
-
-/* Perform x >>= count. */
-void v_bignum_bit_shift_right(VBigDig *x, unsigned int count)
-{
- unsigned int t, carry, s = *x++;
- int i;
-
- /* Shift entire digits first. */
- if(count >= CHAR_BIT * sizeof *x)
- {
- unsigned int places = count / (CHAR_BIT * sizeof *x);
-
- if(places > s)
- {
- memset(x, 0, s * sizeof *x);
- return;
- }
- for(i = 0; i < (int) (s - places); i++)
- x[i] = x[i + places];
- for(; i < (int) s; i++)
- x[i] = 0;
- count -= places * CHAR_BIT * sizeof *x;
- if(count == 0)
- return;
- }
- /* Shift any remaining bits. */
- for(i = s - 1, carry = 0; i >= 0; i--)
- {
- t = x[i] << (CHAR_BIT * sizeof *x);
- t >>= count;
- t |= carry;
- carry = (t & MAX_DIG) << (CHAR_BIT * sizeof *x);
- x[i] = t >> (CHAR_BIT * sizeof *x);
- }
-}
-
-/* ----------------------------------------------------------------------------------------- */
-
-/* Return x == 0. */
-int v_bignum_eq_zero(const VBigDig *x)
-{
- unsigned int i, s = *x++;
-
- for(i = 0; i < s; i++)
- if(x[i])
- return 0;
- return 1;
-}
-
-/* Return x == 1. */
-int v_bignum_eq_one(const VBigDig *x)
-{
- unsigned int i, s = *x++;
-
- if(x[0] != 1)
- return 0;
- for(i = 1; i < s; i++)
- if(x[i])
- return 0;
- return 1;
-}
-
-/* Returns x == y, handling different lengths properly. */
-int v_bignum_eq(const VBigDig *x, const VBigDig *y)
-{
- unsigned int i, xs, ys, cs;
-
- if(x == y) /* Quick test thanks to pointer representation. */
- return 1;
- xs = *x++;
- ys = *y++;
-
- if(xs == ys) /* Same size? Then let's be quick about this. */
- return memcmp(x, y, xs * sizeof *x) == 0;
- else
- {
- cs = xs < ys ? xs : ys; /* Common size. */
- if(memcmp(x, y, cs * sizeof *x) == 0)
- {
- const VBigDig *l;
-
- if(cs == xs) /* y is longer. */
- l = y, i = ys - 1;
- else
- l = x, i = xs - 1;
- for(; i > cs; i--)
- if(l[i])
- return 0;
- return 1;
- }
- }
- return 0;
-}
-
-/* Returns x >= y. */
-int v_bignum_gte(const VBigDig *x, const VBigDig *y)
-{
- unsigned int xs, ys;
- int i, j, k;
-
- if(x == y)
- return 1;
- /* Find indexes of highest-most used digit in each of the numbers. */
- xs = *x++;
- ys = *y++;
- for(i = xs - 1; i >= 0; i--)
- if(x[i] != 0)
- break;
- for(j = ys - 1; j >= 0; j--)
- if(y[j] != 0)
- break;
- /* Both zero? */
- if(i < 0 && j < 0)
- return 1;
- /* Quick answers exists for different-sized numbers. Find them. */
- if(i < j)
- return 0;
- if(i > j)
- return 1;
- /* Compare digit by digit. */
- for(k = i; k >= 0; k--)
- {
- if(x[k] < y[k])
- return 0;
- if(x[k] > y[k])
- return 1;
- }
- return x[k] >= y[k];
-}
-
-/* ----------------------------------------------------------------------------------------- */
-
-/* Computes x += y. */
-void v_bignum_add_digit(VBigDig *x, VBigDig y)
-{
- unsigned int i, s = *x++, t;
-
- t = x[0] + y;
- x[0] = t;
- if(t > MAX_DIG)
- {
- for(i = 1; i < s; i++)
- {
- if(++x[i])
- break;
- }
- }
-}
-
-/* Computes x -= y. */
-void v_bignum_sub_digit(VBigDig *x, VBigDig y)
-{
- unsigned int i, s = *x++, t;
-
- t = x[0] - y;
- x[0] = t;
- if(t > MAX_DIG)
- {
- for(i = 1; i < s; i++)
- {
- x[i]--;
- if(x[i] < MAX_DIG)
- break;
- }
- }
-}
-
-/* Computes x *= y. */
-void v_bignum_mul_digit(VBigDig *x, VBigDig y)
-{
- unsigned int i, s = *x++, carry, t;
-
- for(i = carry = 0; i < s; i++)
- {
- t = x[i] * y + carry;
- x[i] = t;
- carry = t >> (CHAR_BIT * sizeof *x);
- }
-}
-
-/* ----------------------------------------------------------------------------------------- */
-
-/* Computes x += y. */
-void v_bignum_add(VBigDig *x, const VBigDig *y)
-{
- unsigned int i, xs = *x++, ys = *y++, s, carry, t;
-
- s = xs < ys ? xs : ys;
- for(i = carry = 0; i < s; i++)
- {
- t = x[i] + y[i] + carry;
- x[i] = t;
- carry = t > MAX_DIG;
- }
- for(; carry && i < xs; i++)
- {
- t = x[i] + carry;
- x[i] = t;
- carry = t > MAX_DIG;
- }
-}
-
-/* Computes x -= y. */
-void v_bignum_sub(VBigDig *x, const VBigDig *y)
-{
- unsigned int i, xs = *x++, ys = *y++, s, carry, t;
-
- if(x == y)
- {
- v_bignum_set_zero(x - 1);
- return;
- }
- s = xs < ys ? xs : ys;
- for(i = carry = 0; i < s; i++)
- {
- t = x[i] - y[i] - carry;
- x[i] = t;
- carry = t > MAX_DIG;
- }
- for(; carry && i < xs; i++)
- {
- t = x[i] - carry;
- x[i] = t;
- carry = t > MAX_DIG;
- }
-}
-
-/* Compute x *= y, using as many digits as is necessary, then truncating the
- * result down. This is Algorithm 14.12 from "Handbook of Applied Cryptography".
-*/
-void v_bignum_mul(VBigDig *x, const VBigDig *y)
-{
- int n = *x, t = *y, i, j;
- VBigDigs uv = 0, c, w[2048];
-
- memset(w, 0, (n + t + 1) * sizeof *w);
- for(i = 0; i < t; i++)
- {
- c = 0;
- for(j = 0; j < n; j++)
- {
- uv = w[i + j] + x[1 + j] * y[1 + i] + c;
- w[i + j] = uv & ((1 << V_BIGBITS) - 1);
- c = uv >> V_BIGBITS;
- }
- w[i + n + 1] = uv >> V_BIGBITS;
- }
- /* Write low words of w back into x. */
- for(i = 0; i < *x; i++)
- x[1 + i] = w[i];
-}
-
-/* Computes x /= y and remainder = x % y. */
-void v_bignum_div(VBigDig *x, const VBigDig *y, VBigDig *remainder)
-{
- VBigDig *q, *work;
- int msbx = v_bignum_bit_msb(x), msby = v_bignum_bit_msb(y), next;
-
- /* Compare magnitudes of inputs, allows quick exits. */
- if(msby > msbx)
- {
- if(remainder != NULL)
- v_bignum_set_bignum(remainder, x);
- v_bignum_set_zero(x);
- return;
- }
- if(msby < 0)
- {
- v_bignum_set_zero(x);
- return;
- }
- q = bignum_alloc(*x);
- v_bignum_set_zero(q);
- work = bignum_alloc(*x);
- v_bignum_set_bignum_part(work, x, msbx, msby + 1);
-
- for(next = msbx - (msby + 1); next >= -1; next--)
- {
- v_bignum_bit_shift_left_1(q);
- if(v_bignum_gte(work, y))
- {
- q[1] |= 1;
- v_bignum_sub(work, y);
- }
- v_bignum_bit_shift_left_1(work);
- if(v_bignum_bit_test(x, next))
- work[1] |= 1;
- }
- v_bignum_bit_shift_right(work, 1); /* Undo the last shift (when next==-1). */
-
- if(remainder != NULL)
- {
-/* printf("div() got remainder ");
- v_bignum_print_hex_lf(work);
-*/
- v_bignum_set_bignum(remainder, work);
- }
- bignum_free(work);
- v_bignum_set_bignum(x, q);
- bignum_free(q);
-}
-
-/* Computes x %= y. */
-void v_bignum_mod(VBigDig *x, const VBigDig *y)
-{
- int digs;
- VBigDig *tmp;
-
-/* printf("computing ");
- v_bignum_print_hex(x);
- printf("L %% ");
- v_bignum_print_hex(y);
-*/
- digs = *x > *y ? *x : *y;
- tmp = bignum_alloc(digs);
- v_bignum_div(x, y, tmp);
- v_bignum_set_bignum(x, tmp);
- bignum_free(tmp);
-/* printf("L = ");
- v_bignum_print_hex_lf(x);
-*/
-}
-
-/* Initialize Barrett reduction by computing the "mu" helper value. Defined in
- * Handbook of Applied Cryptography algorithm 14.42 as floor(b^2k / m).
-*/
-const VBigDig * v_bignum_reduce_begin(const VBigDig *m)
-{
- VBigDig *mu;
- int k;
-
- for(k = *m; m[k] == 0; k--)
- ;
-/* printf("k=%d -> digits are 0..%u\n", k, k - 1);
- printf("computing mu=floor(65536^%d/", 2 * k);
- v_bignum_print_hex(m);
- printf(")\n");
-*/ mu = bignum_alloc(2 * k + 1);
- /* b ^ 2k is just 65536 << 2k, i.e. set bit 16 * 2k. */
- v_bignum_set_zero(mu);
- v_bignum_bit_set(mu, V_BIGBITS * 2 * k);
-/* v_bignum_print_hex_lf(mu);*/
- v_bignum_div(mu, m, NULL);
-
- return mu;
-}
-
-void v_bignum_reduce_end(const VBigDig *mu)
-{
- bignum_free(mu);
-}
-
-/* Compute x % m, using mu as the helper quantity mu, precomputed by the
- * routine above.
-*/
-void v_bignum_reduce(VBigDig *x, const VBigDig *m, const VBigDig *mu)
-{
- VBigDig *q, *r1, *r2, *r;
- int i, k;
-
- for(k = *m; m[k] == 0; k--)
- ;
- /* Step 1, compute the q helper. */
- q = bignum_alloc(*x + *mu - (k - 1)); /* Tighter bound number length (was 2 * *x). */
- v_bignum_set_bignum(q, x);
- v_bignum_bit_shift_right(q, V_BIGBITS * (k - 1));
- v_bignum_mul(q, mu);
- v_bignum_bit_shift_right(q, V_BIGBITS * (k + 1));
-
- /* Step 2, initialize. */
- r1 = bignum_alloc(*x);
- r2 = bignum_alloc(*x);
- v_bignum_set_bignum(r1, x);
- for(i = k + 1; i < *r1; i++)
- r1[i + 1] = 0;
- v_bignum_set_bignum(r2, q);
- v_bignum_mul(r2, m);
- for(i = k + 1; i < *r2; i++)
- r2[i + 1] = 0;
- r = x;
- v_bignum_set_bignum(r, r1);
- v_bignum_sub(r, r2);
- /* Step 3, make sure r is positive. */
- if(v_bignum_bit_test(r, V_BIGBITS * *r - 1))
- {
- VBigDig *term;
-
- term = bignum_alloc(k + 1 * V_BIGBITS);
- v_bignum_set_zero(term);
- v_bignum_bit_set(term, V_BIGBITS * (k + 1));
- v_bignum_add(r, term);
- bignum_free(term);
- }
- /* Step 4, loop. */
- while(v_bignum_gte(r, m))
- v_bignum_sub(r, m);
-
- bignum_free(r2);
- bignum_free(r1);
- bignum_free(q);
-}
-
-/* Compute x * x using the algorithm 14.16 from "Handbook of Applied Cryptography".
- * Note that since 'w' needs to be double-precision (i.e., 32-bit), we cannot allocate
- * it using bignum_alloc() cleanly. Thus the static limit, which should be enough here.
- * NOTE: This very much assumes V_BIGBITS == 16.
-*/
-void v_bignum_square_half(VBigDig *x)
-{
- VBigDigs w[256], uv, c, ouv;
- int t = *x / 2, i, j, high;
-
- if(t == 0)
- return;
- for(; x[t] == 0; t--)
- ;
- memset(w, 0, 2 * t * sizeof *w); /* Clear digits of w. */
-/* printf("print %lu, ", ++count);
- v_bignum_print_hex(x);
- printf("*");
- v_bignum_print_hex(x);
-*/ for(i = 0; i < t; i++)
- {
-/* printf("computing w[%d]: %lX + %lX * %lX\n", 2 * i, w[2 * i], x[1 + i], x[1 + i]);*/
- uv = w[2 * i] + x[1 + i] * x[1 + i];
-/* printf("setting w[%d]=%X [before]\n", 2 * i, uv & 0xffff);*/
- w[2 * i] = uv & 0xffff;
- c = uv >> V_BIGBITS;
-/* printf("uv before=%X, c=%X\n", uv, c);*/
- high = 0;
- for(j = i + 1; j < t; j++)
- {
-/* printf("computing uv=%X+2*%X*%X+%X\n", w[i + j], x[1 + j], x[1 + i], c);*/
- uv = ((VBigDigs) x[1 + j]) * ((VBigDigs) x[1 + i]);
- high = (uv & 0x80000000) != 0;
- uv *= 2;
- ouv = uv; /* Addition below might wrap and generate high bit. */
- uv += w[i + j] + c;
-/* printf("ouv=0x%lX uv=0x%lX\n", ouv, uv);*/
- high |= uv < ouv;
-/* printf("setting w[%d]=%lX [inner] uv=%lX high=%d c=%X\n", i + j, uv & 0xffff, uv, high, c);*/
- w[i + j] = uv & 0xffff;
- c = (uv >> V_BIGBITS) | (high << V_BIGBITS);
- }
-/* printf("setting w[%d] to %X [after]\n", i + t, (uv >> 16) | (high << 16));*/
- w[i + t] = (uv >> V_BIGBITS) | (high << V_BIGBITS);
- }
-/* printf("w=0x");
- for(i = *x - 1; i >= 0; i--)
- printf("%04X.", w[i]);
- printf("\n");
-*/ /* Write low words of w back into x, trashing it with the square. */
- for(i = 0; i < 2 * t; i++)
- x[1 + i] = w[i];
- for(; i < *x; i++)
- x[1 + i] = 0;
-/* printf("==");
- v_bignum_print_hex_lf(x);
-*/
-}
-
-/* Computes x = (x^y) % n, where ^ denotes exponentiation. */
-void v_bignum_pow_mod(VBigDig *x, const VBigDig *y, const VBigDig *n)
-{
- VBigDig *tmp;
- const VBigDig *mu;
- int i, k;
-
-/* printf("computing pow(");
- v_bignum_print_hex(x);
- printf("L,");
- v_bignum_print_hex(y);
- printf("L,");
- v_bignum_print_hex(n);
- printf("L)\n");
-*/
- tmp = bignum_alloc(2 * *x); /* Squaring needs twice the bits, or lossage occurs. */
- v_bignum_set_bignum(tmp, x);
- k = v_bignum_bit_msb(y);
- mu = v_bignum_reduce_begin(n);
- for(i = k - 1; i >= 0; i--)
- {
- v_bignum_square_half(tmp);
- v_bignum_reduce(tmp, n, mu);
- if(v_bignum_bit_test(y, i))
- {
- v_bignum_mul(tmp, x);
- v_bignum_reduce(tmp, n, mu);
- }
- }
- v_bignum_set_bignum(x, tmp);
- v_bignum_reduce_end(mu);
- bignum_free(tmp);
-}
-
-/* ----------------------------------------------------------------------------------------- */
-
-#if defined STANDALONE
-
-int main(void)
-{
- VBigDig VBIGNUM(x, 3648), VBIGNUM(y, 128), VBIGNUM(z, 128);
-
- printf("MAX_DIG=%u\n", MAX_DIG);
-
- v_bignum_set_string_hex(x, "0x433864FE0F8FAC180FF1BC3A5BFD0C5566F6B11679E27294EDCC43056EB73EE118415E0CD6E6519509476EB21341ED0328BA7B14E0ED80D5E100A4549C5202B57B4CF17A74987631B6BA896C0DBA2095A7EDE5B9C4B4EEFCD1B9EF8474BCB7FBD0F64B549625D444847ED1FCB7F8050EB4F22794F694A0FAC6DFFB781C264B227966840185F9216484F6A7954741CB11FC14DEC2937EAD2CE640FD9A4339706BDB5BC355079C2F2F7994669DFA5B20C50D957A676E67C86835037078323A0BDAD3686B8E638749F327A7AD433C0D18BCD2FC970D125914C7FBEE061290A0F0F3572E207");
- v_bignum_set_bignum(y, x);
- v_bignum_set_digit(z, 77);
-
- printf("x:");
- v_bignum_print_hex_lf(x);
- printf("y:");
- v_bignum_print_hex_lf(y);
- printf("z:");
- v_bignum_print_hex_lf(z);
- v_bignum_pow_mod(x, y, z);
- printf(" =");
- v_bignum_print_hex_lf(x);
-
- return 0;
-}
-
-#endif /* STANDALONE */
Deleted: branches/verse-pam-branch/v_bignum.h
===================================================================
--- branches/verse-pam-branch/v_bignum.h 2008-08-19 13:36:28 UTC (rev 4535)
+++ branches/verse-pam-branch/v_bignum.h 2008-08-22 12:30:15 UTC (rev 4536)
@@ -1,123 +0,0 @@
-/*
- * $Id$
- *
- * ***** BEGIN BSD LICENSE BLOCK *****
- *
- * Copyright (c) 2005-2008, The Uni-Verse Consortium.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * 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 BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER
- * 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.
- *
- * ***** END BSD LICENSE BLOCK *****
- *
- */
-
-/*
- * Verse routines for big integer operations.
- * Handy in heavy encryption done during connect.
-*/
-
-#include <limits.h>
-
-#include "v_randgen.h"
-
-/* ----------------------------------------------------------------------------------------- */
-
-typedef unsigned short VBigDig; /* Type used to hold one digit of a bignum. */
-typedef unsigned int VBigDigs; /* Should hold precisely two digits. */
-
-#define V_BIGBITS (CHAR_BIT * sizeof (VBigDig))
-
-/* Use this macro to initialize big number variables, like so:
- * VBigDig BIGNUM(foo, 128), BIGNUM(bar, 256);
- * Creates automatic variables 'foo' of 128 bits, and 'bar' of 256.
- *
- * Note that 'bits' must be a multiple of V_BIGBITS, completely
- * arbitrary number sizes are not supported by this module.
-*/
-#define VBIGNUM(n, bits) n[1 + (bits / V_BIGBITS)] = { bits / V_BIGBITS }
-
-/* ----------------------------------------------------------------------------------------- */
-
-/* Import/export numbers from raw bits. The number x must have been allocated
- * with the desired number of bits to read/write.
-*/
-extern void v_bignum_raw_import(VBigDig *x, const void *bits);
-extern void v_bignum_raw_export(const VBigDig *x, void *bits);
-
-/* Initializers. */
-extern void v_bignum_set_zero(VBigDig *x);
-extern void v_bignum_set_one(VBigDig *x);
-extern void v_bignum_set_digit(VBigDig *x, VBigDig y);
-extern void v_bignum_set_string(VBigDig *x, const char *string); /* Decimal. */
-extern void v_bignum_set_string_hex(VBigDig *x, const char *string);
-extern void v_bignum_set_bignum(VBigDig *x, const VBigDig *y);
-/* x = <bits> most significant <bits> bits of <y>, starting at <msb>. Right-
- * adjusted in x, so that e.g. y=0xcafebabec001 msb=47 bits=16 gives x=0xcafe.
-*/
-extern void v_bignum_set_bignum_part(VBigDig *x, const VBigDig *y,
- unsigned int msb, unsigned int bits);
-extern void v_bignum_set_random(VBigDig *x, VRandGen *gen);
-
-/* Handy during debugging. */
-extern void v_bignum_print_hex(const VBigDig *x);
-extern void v_bignum_print_hex_lf(const VBigDig *x);
-
-/* Bit operators. */
-extern void v_bignum_not(VBigDig *x);
-extern int v_bignum_bit_test(const VBigDig *x, unsigned int bit);
-extern void v_bignum_bit_set(VBigDig *x, unsigned int bit);
-extern int v_bignum_bit_msb(const VBigDig *x);
-extern int v_bignum_bit_size(const VBigDig *x);
-extern void v_bignum_bit_shift_left(VBigDig *x, unsigned int count);
-extern void v_bignum_bit_shift_left_1(VBigDig *x);
-extern void v_bignum_bit_shift_right(VBigDig *x, unsigned int count);
-
-/* Comparators. */
-extern int v_bignum_eq_zero(const VBigDig *x); /* x == 0. */
-extern int v_bignum_eq_one(const VBigDig *x); /* x == 1. */
-extern int v_bignum_eq(const VBigDig *x, const VBigDig *y); /* x == y. */
-extern int v_bignum_gte(const VBigDig *x, const VBigDig *y); /* x >= y. */
-
-/* Number vs single-digit arithmetic. */
-extern void v_bignum_add_digit(VBigDig *x, VBigDig y); /* x += y. */
-extern void v_bignum_sub_digit(VBigDig *x, VBigDig y); /* x -= y. */
-extern void v_bignum_mul_digit(VBigDig *x, VBigDig y); /* x *= y. */
-
-/* Arithmetic. */
-extern void v_bignum_add(VBigDig *x, const VBigDig *y); /* x += y. */
-extern void v_bignum_sub(VBigDig *x, const VBigDig *y); /* x -= y. */
-extern void v_bignum_mul(VBigDig *x, const VBigDig *y); /* x *= y. */
-extern void v_bignum_div(VBigDig *x, const VBigDig *y, VBigDig *remainder);
-extern void v_bignum_mod(VBigDig *x, const VBigDig *y); /* x %= y. */
-
-/* Barrett reducer for fast x % m computation. Requires precalcing step. */
-extern const VBigDig * v_bignum_reduce_begin(const VBigDig *m);
-extern void v_bignum_reduce(VBigDig *x, const VBigDig *m, const VBigDig *mu);
-extern void v_bignum_reduce_end(const VBigDig *mu);
-
-/* Compute x *= x, assuming x only uses half of its actual size. */
-extern void v_bignum_square_half(VBigDig *x);
-
-/* Compute pow(x, y, n) == (x raised to the y:th power) modulo n. */
-extern void v_bignum_pow_mod(VBigDig *x, const VBigDig *y, const VBigDig *n);
Modified: branches/verse-pam-branch/v_cmd_def_s.c
===================================================================
--- branches/verse-pam-branch/v_cmd_def_s.c 2008-08-19 13:36:28 UTC (rev 4535)
+++ branches/verse-pam-branch/v_cmd_def_s.c 2008-08-22 12:30:15 UTC (rev 4536)
@@ -42,9 +42,9 @@
void v_gen_system_cmd_def(void)
{
- v_cg_new_manual_cmd(0, "connect", "VSession verse_send_connect(const char *name, const char *pass, const char *address, const uint8 *expected_host_id)", NULL, NULL);
+ v_cg_new_manual_cmd(0, "connect", "VSession verse_send_connect(const char *name, const char *pass, const char *address)", NULL, NULL);
- v_cg_new_manual_cmd(1, "connect_accept", "VSession verse_send_connect_accept(VNodeID avatar, const char *address, uint8 *host_id)", NULL, NULL);
+ v_cg_new_manual_cmd(1, "connect_accept", "VSession verse_send_connect_accept(VNodeID avatar, const char *address)", NULL, NULL);
v_cg_new_manual_cmd(2, "connect_terminate", "void verse_send_connect_terminate(const char *address, const char *bye)", NULL, NULL);
Modified: branches/verse-pam-branch/v_connect.c
===================================================================
--- branches/verse-pam-branch/v_connect.c 2008-08-19 13:36:28 UTC (rev 4535)
+++ branches/verse-pam-branch/v_connect.c 2008-08-22 12:30:15 UTC (rev 4536)
@@ -46,106 +46,86 @@
#include "v_network_out_que.h"
#include "v_network.h"
#include "v_connection.h"
-#include "v_encryption.h"
#include "v_util.h"
extern void verse_send_packet_ack(uint32 packet_id);
-static void v_send_hidden_connect_contact(void) /* Stage 0: Clinets inital call to connect to host */
+/* Stage 0: Clinets inital call to connect to host */
+static void v_send_hidden_connect_contact(void)
{
- uint8 buf[V_ENCRYPTION_LOGIN_KEY_HALF_SIZE + 4 + 1 + 1], *key;
+ uint8 buf[1500];
unsigned int i, buffer_pos = 0;
- buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], 0);/* Packing the packet id */
- buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 0);/* Packing the command */
- buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], V_CS_IDLE);/* Stage 0 */
+ buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], 0); /* Packing the packet id */
+ buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 0); /* Packing the command */
+ buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], V_CS_IDLE); /* Stage 0 */
- key = v_con_get_my_key();
- for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_SIZE; i++)
- buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], key[V_ENCRYPTION_LOGIN_PUBLIC_START + i]);/* Packing the command */
- for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_SIZE; i++)
- buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], key[V_ENCRYPTION_LOGIN_N_START + i]);/* Packing the command */
-
v_n_send_data(v_con_get_network_address(), buf, buffer_pos);
}
-static void v_send_hidden_connect_send_key(void) /* Stage 1: Hosts reply to any atempt to connect */
+/* Stage 1: Hosts reply to any atempt to connect */
+static void v_send_hidden_connect_send_key(void)
{
- uint8 buf[V_ENCRYPTION_LOGIN_KEY_SIZE * 3 + 4 + 1 + 1 + 1 + 4 + 4], *host_id;
+ uint8 buf[1500];
unsigned int i, buffer_pos = 0, s, f;
- buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], 0);/* Packing the packet id */
- buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 0);/* Packing the command */
- buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], V_CS_CONTACT);/* Stage 1 */
- buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], V_RELEASE_NUMBER);/* version */
+ buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], 0); /* Packing the packet id */
+ buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 0); /* Packing the command */
+ buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], V_CS_CONTACT); /* Packing Stage 1 */
+ buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], V_RELEASE_NUMBER); /* Packing version number */
v_n_get_current_time(&s, &f);
- buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], s);/* time, seconds */
- buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], f);/* time, fraction */
- host_id = v_con_get_host_id();
- for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_SIZE; i++)
- buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], host_id[V_ENCRYPTION_LOGIN_PUBLIC_START + i]);
- for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_SIZE; i++)
- buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], host_id[V_ENCRYPTION_LOGIN_N_START + i]);
+ buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], s); /* Packing time (seconds) */
+ buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], f); /* Packing time (fraction) */
v_n_send_data(v_con_get_network_address(), buf, buffer_pos);
}
-static void v_send_hidden_connect_login(void) /* Stage 2: clients sends encrypted name and password */
+/* Stage 2: clients sends name and password */
+static void v_send_hidden_connect_login(void)
{
- uint8 buf[1500], *key, name_pass[V_ENCRYPTION_LOGIN_KEY_SIZE], encrypted_key[V_ENCRYPTION_LOGIN_KEY_SIZE];
+ uint8 buf[1500];
const char *name, *pass;
unsigned int buffer_pos = 0, i;
- buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], 1);/* Packing the packet id */
- buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 0);/* Packing the command */
- buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], V_CS_CONTACTED);/* Stage 2 */
+ buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], 1); /* Packing the packet id */
+ buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 0); /* Packing the command */
+ buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], V_CS_CONTACTED); /* Packing Stage 2 */
name = v_con_get_name();
- /* Pad data area with randomness. */
- for(i = 0; i < sizeof name_pass; i++)
- name_pass[i] = rand() >> 13;
- v_strlcpy(name_pass, name, V_ENCRYPTION_LOGIN_KEY_SIZE / 2);
+ buffer_pos += vnp_raw_pack_string(&buf[buffer_pos], name, 32); /* Packing name */
pass = v_con_get_pass();
- v_strlcpy(name_pass + V_ENCRYPTION_LOGIN_KEY_SIZE / 2, pass, V_ENCRYPTION_LOGIN_KEY_SIZE / 2);
- /* Make sure last (MSB) byte is clear, to guarantee that data < key for RSA math. */
- name_pass[sizeof name_pass - 1] = 0;
- key = v_con_get_other_key();
- v_e_connect_encrypt(encrypted_key, name_pass, &key[V_ENCRYPTION_LOGIN_PUBLIC_START], &key[V_ENCRYPTION_LOGIN_N_START]);
+ buffer_pos += vnp_raw_pack_string(&buf[buffer_pos], pass, 32); /* Packing password */
- for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_SIZE; i++)
- buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], encrypted_key[i]);
v_n_send_data(v_con_get_network_address(), buf, buffer_pos);
}
-static void v_send_hidden_connect_accept(void) /* Host accepts Clients connectionatempt and sends over data encryption key */
+/* Host accepts Clients connectionatempt */
+static void v_send_hidden_connect_accept(void)
{
- uint8 buf[1500], *client_key, encrypted[V_ENCRYPTION_DATA_KEY_SIZE];
- unsigned int i, buffer_pos = 0;
+ uint8 buf[1500];
+ unsigned int buffer_pos = 0;
- buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], 1);/* Packing the packet id */
- buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 1);/* Packing the command */
- buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], verse_session_get_avatar());
- client_key = v_con_get_other_key();
- v_e_connect_encrypt(encrypted, v_con_get_data_key(), &client_key[V_ENCRYPTION_LOGIN_PUBLIC_START], &client_key[V_ENCRYPTION_LOGIN_N_START]);
- for(i = 0; i < V_ENCRYPTION_DATA_KEY_SIZE; i++)
- buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], encrypted[i]);
+ buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], 1); /* Packing the packet id */
+ buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 1); /* Packing the command */
+ buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], verse_session_get_avatar()); /* Packing avatar ID */
+
v_n_send_data(v_con_get_network_address(), buf, buffer_pos);
}
-static void v_send_hidden_connect_terminate(VNetworkAddress *address, unsigned int packet_id, const char *bye) /* Host accepts Clients connectionatempt and sends over data encryption key */
+/* Host send bye bye command */
+static void v_send_hidden_connect_terminate(VNetworkAddress *address, unsigned int packet_id, const char *bye)
{
uint8 buf[1500];
unsigned int buffer_pos = 0;
- buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], packet_id);/* Packing the packet id */
- buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 2);/* Packing the command */
- buffer_pos += vnp_raw_pack_string(&buf[buffer_pos], bye, 512); /* pack message */
- v_e_data_encrypt_command(buf, sizeof (uint32), buf + sizeof (uint32), buffer_pos, v_con_get_data_key());
+ buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], packet_id); /* Packing the packet id */
+ buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 2); /* Packing the command */
+ buffer_pos += vnp_raw_pack_string(&buf[buffer_pos], bye, 512); /* Packing bye bye message */
+
v_n_send_data(address, buf, buffer_pos);
}
-VSession verse_send_connect(const char *name, const char *pass, const char *address, const uint8 *expected_key)
+VSession verse_send_connect(const char *name, const char *pass, const char *address)
{
- uint8 *my_key, *key = NULL;
- unsigned int i;
VNetworkAddress a;
VSession *session;
+
if(v_n_set_network_address(&a, address))
{
#if defined(V_PRINT_SEND_COMMANDS)
@@ -154,18 +134,10 @@
session = v_con_connect(&a, V_CS_CONTACT);
#if defined(V_PRINT_SEND_COMMANDS)
v_n_get_address_string(&a, ip_string);
- printf("send: %p = verse_send_connect(name = %s, pass = %s, address = %s (%s), expected_key = %p)\n", session, name, pass, address, ip_string, expected_key);
+ printf("send: %p = verse_send_connect(name = %s, pass = %s, address = %s (%s)\n",
+ session, name, pass, address, ip_string);
#endif
v_con_set_name_pass(name, pass);
- if(expected_key != NULL)
- {
- key = malloc((sizeof *key) * V_ENCRYPTION_LOGIN_KEY_HALF_SIZE);
- for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_HALF_SIZE; i++)
- key[i] = expected_key[i];
- *v_con_get_expected_key() = key;
- }
- my_key = v_con_get_my_key();
- v_e_connect_create_key(&my_key[V_ENCRYPTION_LOGIN_PRIVATE_START], &my_key[V_ENCRYPTION_LOGIN_PUBLIC_START], &my_key[V_ENCRYPTION_LOGIN_N_START]);
v_send_hidden_connect_contact();
v_con_inqueue_timer_update(); /* Reset timer in connection's in queue, above takes a while. */
return session;
@@ -173,16 +145,18 @@
else
{
#if defined(V_PRINT_SEND_COMMANDS)
- printf("send: NULL = verse_send_connect(name = %s, pass = %s, address = %s (Unressolved DNS), key = %p);\n", name, pass, address, key);
+ printf("send: NULL = verse_send_connect(name = %s, pass = %s, address = %s (Unressolved DNS));\n",
+ name, pass, address);
#endif
return NULL;
}
}
+/* Connection handshake, sending connection commands */
void v_update_connection_pending(boolean resend)
{
- VSession (* func_connect)(void *user_data, const char *name, const char *pass, const char *address, const uint8 *key) = NULL;
- VSession (* func_connect_accept)(void *user_data, VNodeID avatar, char *address, uint8 *host_id);
+ VSession (* func_connect)(void *user_data, const char *name, const char *pass, const char *address) = NULL;
+ VSession (* func_connect_accept)(void *user_data, VNodeID avatar, char *address);
void (* func_connect_terminate)(void *user_data, char *address, const char *bye);
char address_string[32];
@@ -205,28 +179,30 @@
func_connect = v_fs_get_user_func(0);
v_n_get_address_string(v_con_get_network_address(), address_string);
#if defined(V_PRINT_RECEIVE_COMMANDS)
- printf("receive: verse_send_connect(address = %s, name = %s, pass = %s, key = NULL); callback = %p\n", address_string, v_con_get_name(), v_con_get_pass(), func_connect);
+ printf("receive: verse_send_connect(address = %s, name = %s, pass = %s); callback = %p\n",
+ address_string, v_con_get_name(), v_con_get_pass(), func_connect);
#endif
if(func_connect != 0)
- func_connect(v_fs_get_user_data(0), v_con_get_name(), v_con_get_pass(), address_string, NULL);
+ func_connect(v_fs_get_user_data(0), v_con_get_name(), v_con_get_pass(), address_string);
break;
case V_CS_PENDING_CLIENT_CALLBACK_ACCEPT : /* Host got login waits for accept connect callback */
v_con_set_connect_stage(V_CS_CONNECTED);
func_connect_accept = v_fs_get_user_func(1);
v_n_get_address_string(v_con_get_network_address(), address_string);
#if defined(V_PRINT_RECEIVE_COMMANDS)
- printf("receive: func_connect_accept(avatar = %u, address = %s, name = %s, pass = %s, key = NULL); callback = %p\n",
+ printf("receive: func_connect_accept(avatar = %u, address = %s, name = %s, pass = %s); callback = %p\n",
verse_session_get_avatar(), address_string, v_con_get_name(), v_con_get_pass(), func_connect);
#endif
if(func_connect_accept != 0)
- func_connect_accept(v_fs_get_user_data(1), verse_session_get_avatar(), address_string, NULL);
+ func_connect_accept(v_fs_get_user_data(1), verse_session_get_avatar(), address_string);
break;
case V_CS_PENDING_CLIENT_CALLBACK_TERMINATE : /* Host got login waits for accept connect callback */
v_con_set_connect_stage(V_CS_CONNECTED);
func_connect_terminate = v_fs_get_user_func(2);
v_n_get_address_string(v_con_get_network_address(), address_string);
#if defined(V_PRINT_RECEIVE_COMMANDS)
- printf("receive: func_connect_terminate(address = %s, bye = %s); callback = %p\n", address_string, "no message", func_connect);
+ printf("receive: func_connect_terminate(address = %s, bye = %s); callback = %p\n",
+ address_string, "no message", func_connect);
#endif
if(func_connect_terminate != 0)
func_connect_terminate(v_fs_get_user_data(2), address_string, "no message");
@@ -236,136 +212,90 @@
}
}
-void v_unpack_connection(const char *buf, unsigned int buffer_length) /* un packing all stages of connect command */
+/* Connection Handshake, unpacking all of connect command */
+void v_unpack_connection(const char *buf, unsigned int buffer_length)
{
- unsigned int buffer_pos, i, pack_id;
- uint32 seconds, fractions, pre;
- uint8 /*key[V_ENCRYPTION_LOGIN_KEY_SIZE], */stage, cmd_id, version;
+ unsigned int buffer_pos, pack_id;
+ uint32 seconds, fractions;
+ uint8 stage, cmd_id, version;
+ /* WHY??!! */
if(buffer_length < 5)
return;
- buffer_pos = vnp_raw_unpack_uint32(buf, &pack_id);
- buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &cmd_id);
- pre = v_con_get_connect_stage();
+ buffer_pos = vnp_raw_unpack_uint32(buf, &pack_id); /* Unpacking packet ID */
+ buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &cmd_id); /* Unpacking command ID */
+
if(cmd_id == 0)
{
- buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &stage);
+ buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &stage); /* Unpacking stage */
+
printf(" Handling connection, stage %u\n", stage);
- if(stage == V_CS_IDLE && V_CS_IDLE == v_con_get_connect_stage()) /* reseved by host */
+
+ if(stage == V_CS_IDLE && V_CS_IDLE == v_con_get_connect_stage()) /* Reseved by host */
{
- uint8 *other_key, *my_key;
+ verse_send_packet_ack(pack_id); /* Sending ACK command */
+ v_con_set_connect_stage(V_CS_CONTACTED); /* Set stage */
+ v_send_hidden_connect_send_key(); /* TODO: Rename ... we don't send any key anymore */
- verse_send_packet_ack(pack_id);
- my_key = v_con_get_my_key();
- v_con_set_data_key(v_e_data_create_key());
- other_key = v_con_get_other_key();
- for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_SIZE; i++)
- buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &other_key[V_ENCRYPTION_LOGIN_PUBLIC_START + i]);/* Packing the command */
- for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_SIZE; i++)
- buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &other_key[V_ENCRYPTION_LOGIN_N_START + i]);/* Packing the command */
- v_con_set_connect_stage(V_CS_CONTACTED);
- v_send_hidden_connect_send_key();
return;
}
if(stage == V_CS_CONTACT && V_CS_CONTACT == v_con_get_connect_stage())
{
- uint8 *other_key; /* *host_id, *my_key, a[V_ENCRYPTION_LOGIN_KEY_SIZE], b[V_ENCRYPTION_LOGIN_KEY_SIZE];*/
- verse_send_packet_ack(pack_id);
- buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &version);
+ verse_send_packet_ack(pack_id); /* Sending ACK command */
+ buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &version); /* Unpacking version of protocol */
+
if(version != V_RELEASE_NUMBER)
{
- /* char error_message[128];
- func_connect_deny = v_fs_get_user_func(2);
- #if defined(V_PRINT_RECEIVE_COMMANDS)
- printf("receive: verse_send_connect_deny(Host is running version %u you are running version %u); callback = %p\n", (uint32)version, (uint32)V_RELEASE_NUMBER func_connect_deny);
- #endif
- if(func_connect_deny != NULL)
- {
- sprintf(error_message, "Host is running version %u you are running version %u", (uint32)version, (uint32)V_RELEASE_NUMBER);
- func_connect_deny(v_fs_get_user_data(2), error_message);
- }*/
+ fprintf(stderr, "Versions of client and server aren't the same\n");
return;
}
- buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &seconds);
- buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &fractions);
- v_con_set_time(seconds, fractions);
-
- other_key = v_con_get_other_key();
- for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_SIZE; i++)
- buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &other_key[V_ENCRYPTION_LOGIN_PUBLIC_START + i]);
- for(i = 0; i < V_ENCRYPTION_DATA_KEY_SIZE; i++)
- buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &other_key[V_ENCRYPTION_LOGIN_N_START + i]);
-
- v_con_set_connect_stage(V_CS_PENDING_ACCEPT);
- v_send_hidden_connect_login();
+ buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &seconds); /* Unpacking time (seconds) */
+ buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &fractions); /* Unpacking time (fractions) */
+ v_con_set_time(seconds, fractions); /* Set time */
+ v_con_set_connect_stage(V_CS_PENDING_ACCEPT); /* Set stage */
+ v_send_hidden_connect_login(); /* Sending CONNECT command */
return;
}
-#if 0
- for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_HALF_SIZE && encrypted_key[i] == 0; i++);
- if(i < 0)
- {
- other_key = v_con_get_my_key();
- v_e_connect_encrypt(decrypted_key, encrypted_key, &other_key[V_ENCRYPTION_LOGIN_PUBLIC_START + i], &other_key[V_ENCRYPTION_LOGIN_N_START + i]);
- for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_HALF_SIZE && my_key[V_ENCRYPTION_LOGIN_PUBLIC_START + i] == decrypted_key[i]; i++);
- if(i < 0) /* Host is not who it appers top be */
- {
- func_connect_deny = v_fs_get_user_func(2);
-#if defined(V_PRINT_RECEIVE_COMMANDS)
- printf("receive: verse_send_connect_deny(Host failed identity check); callback = %p\n", func_connect_deny);
-#endif
- if(func_connect_deny != NULL)
- func_connect_deny(v_fs_get_user_data(2), "Host failed identity check");
- return;
- }
- }
-#endif
- if(stage == V_CS_CONTACTED && V_CS_CONTACTED == v_con_get_connect_stage()) /* reseved by host */
+ if(stage == V_CS_CONTACTED && V_CS_CONTACTED == v_con_get_connect_stage()) /* Reseved by host */
{
- char *host_id, unpack[V_ENCRYPTION_LOGIN_KEY_SIZE], data[V_ENCRYPTION_LOGIN_KEY_SIZE];
- VNetworkAddress *address;
- verse_send_packet_ack(pack_id);
- address = v_con_get_network_address();
- for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_SIZE; i++)
- buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &data[i]);
- host_id = v_con_get_host_id();
- v_e_connect_encrypt(unpack, data, &host_id[V_ENCRYPTION_LOGIN_PRIVATE_START], &host_id[V_ENCRYPTION_LOGIN_N_START]);
- v_con_set_name_pass(unpack, &unpack[V_ENCRYPTION_LOGIN_KEY_SIZE / 2]);
- v_con_set_connect_stage(V_CS_PENDING_HOST_CALLBACK);
+ char name[32], pass[32];
+
+ verse_send_packet_ack(pack_id); /* Sending ACK command */
+ buffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], name, 32, 32); /* Unpacking name */
+ buffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], pass, 32, 32); /* Unpacking password */
+ v_con_set_name_pass(name, pass); /* Set name and pass */
+ v_con_set_connect_stage(V_CS_PENDING_HOST_CALLBACK); /* Set stage */
return;
}
}
- if(cmd_id == 1 && V_CS_PENDING_ACCEPT == v_con_get_connect_stage()) /* reseved by client */
+ if(cmd_id == 1 && V_CS_PENDING_ACCEPT == v_con_get_connect_stage()) /* Reseved by client */
{
- uint8 *my_key, key[V_ENCRYPTION_DATA_KEY_SIZE], decrypted[V_ENCRYPTION_DATA_KEY_SIZE];
uint32 avatar;
- verse_send_packet_ack(pack_id);
- buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &avatar);
- v_con_set_avatar(avatar);
- for(i = 0; i < V_ENCRYPTION_DATA_KEY_SIZE; i++)
- buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &key[i]);
- my_key = v_con_get_my_key();
- v_e_connect_encrypt(decrypted, key, &my_key[V_ENCRYPTION_LOGIN_PRIVATE_START], &my_key[V_ENCRYPTION_LOGIN_N_START]);
- v_con_set_data_key(decrypted);
- v_con_set_connect_stage(V_CS_PENDING_CLIENT_CALLBACK_ACCEPT);
- v_send_hidden_connect_send_key();
+
+ verse_send_packet_ack(pack_id); /* Sending ACK command */
+ buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &avatar); /* Unpacking avatar ID */
+ v_con_set_avatar(avatar); /* Set avatar ID*/
+ v_con_set_connect_stage(V_CS_PENDING_CLIENT_CALLBACK_ACCEPT); /* Set stage */
+ v_send_hidden_connect_send_key(); /* TODO: rename ... we don't send any key anymore */
return;
}
if(cmd_id == 2 && V_CS_PENDING_ACCEPT == v_con_get_connect_stage()) /* reseved by client */
{
verse_send_packet_ack(pack_id);
- /* buffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], name, 512, buffer_length - buffer_pos);
- */ v_con_set_connect_stage(V_CS_PENDING_CLIENT_CALLBACK_TERMINATE);
+ /* TODO: do somethink with this string */
+ /* buffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], name, 512, buffer_length - buffer_pos); */
+ v_con_set_connect_stage(V_CS_PENDING_CLIENT_CALLBACK_TERMINATE);
return;
}
}
-VSession verse_send_connect_accept(VNodeID avatar, const char *address, uint8 *host_id)
+VSession verse_send_connect_accept(VNodeID avatar, const char *address)
{
VNetworkAddress a;
#if defined(V_PRINT_SEND_COMMANDS)
- printf("send: verse_send_connect_accept(avatar = %u, address = %s, host_id = NULL);\n", avatar, address);
+ printf("send: verse_send_connect_accept(avatar = %u, address = %s);\n", avatar, address);
#endif
if(!v_n_set_network_address(&a, address))
@@ -391,7 +321,8 @@
func_connect_terminate = v_fs_get_user_func(2);
v_n_get_address_string(v_con_get_network_address(), address_string);
#if defined(V_PRINT_RECEIVE_COMMANDS)
- printf("receive: verse_send_connect_terminate(address = %s, bye = %s); callback = %p\n", address_string, bye, func_connect_terminate);
+ printf("receive: verse_send_connect_terminate(address = %s, bye = %s); callback = %p\n",
+ address_string, bye, func_connect_terminate);
#endif
if(func_connect_terminate != 0)
func_connect_terminate(v_fs_get_user_data(2), address_string, bye);
@@ -401,7 +332,8 @@
{
VNetworkAddress a;
#if defined(V_PRINT_RECEIVE_COMMANDS)
- printf("send: verse_send_connect_terminate(address = %s, bye = %s);\n", address, bye);
+ printf("send: verse_send_connect_terminate(address = %s, bye = %s);\n",
+ address, bye);
#endif
if(address == NULL)
@@ -426,8 +358,10 @@
uint8 buf[1500];
buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], 0);/* Packing the Packet id */
buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 5);/* Packing the command */
+
#if defined V_PRINT_SEND_COMMANDS
- printf("send: verse_send_ping(address = %s text = %s);\n", address, message);
+ printf("send: verse_send_ping(address = %s text = %s);\n",
+ address, message);
#endif
buffer_pos += vnp_raw_pack_string(&buf[buffer_pos], message, 1400);
v_n_send_data(&a, buf, buffer_pos);
Modified: branches/verse-pam-branch/v_connection.c
===================================================================
--- branches/verse-pam-branch/v_connection.c 2008-08-19 13:36:28 UTC (rev 4535)
+++ branches/verse-pam-branch/v_connection.c 2008-08-22 12:30:15 UTC (rev 4536)
@@ -41,7 +41,6 @@
#include "v_network_out_que.h"
#include "v_cmd_gen.h"
#include "v_connection.h"
-#include "v_encryption.h"
#include "v_util.h"
#if !defined(V_GENERATE_FUNC_MODE)
@@ -59,19 +58,14 @@
VNetworkAddress network_address;
boolean connected;
unsigned int avatar;
-/* unsigned int packet_id;*/
int32 timedelta_s;
uint32 timedelta_f;
boolean destroy_flag;
void *ordered_storage;
- char name[V_ENCRYPTION_LOGIN_KEY_SIZE / 2];
- char pass[V_ENCRYPTION_LOGIN_KEY_SIZE / 2];
+ char name[32];
+ char pass[32];
VConnectStage connect_stage;
unsigned int stage_atempts;
- uint8 key_my[V_ENCRYPTION_LOGIN_KEY_FULL_SIZE];
- uint8 key_other[V_ENCRYPTION_LOGIN_KEY_FULL_SIZE];
- uint8 key_data[V_ENCRYPTION_DATA_KEY_SIZE];
- uint8 *expected_key;
} VConnection;
static struct {
@@ -82,7 +76,6 @@
void *unified_func_storage;
uint16 connect_port;
unsigned int pending_packets;
- uint8 host_id[V_ENCRYPTION_LOGIN_KEY_FULL_SIZE];
} VConData;
extern void cmd_buf_init(void);
@@ -99,9 +92,6 @@
memset(VConData.con, 0, CONNECTION_CHUNK_SIZE * sizeof *VConData.con); /* Clear the memory. */
VConData.con_count = 0;
VConData.pending_packets = 0;
-/* v_e_connect_create_key(&VConData.host_id[V_ENCRYPTION_LOGIN_PRIVATE_START],
- &VConData.host_id[V_ENCRYPTION_LOGIN_PUBLIC_START],
- &VConData.host_id[V_ENCRYPTION_LOGIN_N_START]);*/ /* default host id if none is set by user */
}
void verse_set_protocol(uint32 protocol)
@@ -114,17 +104,6 @@
v_n_set_port(port);
}
-void verse_host_id_create(uint8 *id)
-{
- v_e_connect_create_key(&id[V_ENCRYPTION_LOGIN_PRIVATE_START],
- &id[V_ENCRYPTION_LOGIN_PUBLIC_START], &id[V_ENCRYPTION_LOGIN_N_START]);
-}
-
-void verse_host_id_set(uint8 *id)
-{
- memcpy(VConData.host_id, id, V_ENCRYPTION_LOGIN_KEY_FULL_SIZE);
-}
-
extern void *v_fs_create_func_storage(void);
extern void *v_create_ordered_storage(void);
extern void v_destroy_ordered_storage(void *data);
@@ -148,7 +127,6 @@
VConData.con[VConData.con_count].stage_atempts = 0; /* each stage in the connection prosess is atempted multiple times to avoid failiure if packets get lost*/
VConData.con[VConData.con_count].timedelta_s = 0; /* number of seconds since last incomming packet to the connection*/
VConData.con[VConData.con_count].timedelta_f = 0; /* number of fractions of a second since last incomming packet to the connection*/
- VConData.con[VConData.con_count].expected_key = NULL; /* expected hist id if this is a client */
VConData.current_connection = VConData.con_count; /* set the new connection to the current*/
++VConData.con_count; /* add one to the number of connections*/
return VConData.con[VConData.current_connection].out_queue;
@@ -244,11 +222,6 @@
}
}
-/*
-extern void v_fs_buf_unpack(const uint8 *data, unsigned int length);
-extern void v_fs_buf_store_pack(uint8 *data, unsigned int length);
-extern boolean v_fs_buf_unpack_stored(void);
-*/
extern void v_unpack_connection(const char *buf, unsigned int buffer_length);
extern void verse_send_packet_nak(uint32 packet_id);
@@ -261,7 +234,8 @@
boolean v_con_network_listen(void)
{
VNetworkAddress address;
- uint8 buf[V_MAX_CONNECT_PACKET_SIZE], *store;
+ uint8 *store;
+ uint8 buf[V_MAX_CONNECT_PACKET_SIZE];
int size = 0;
unsigned int connection;
uint32 packet_id;
@@ -270,21 +244,26 @@
v_con_init(); /* Init if needed. */
connection = VConData.current_connection; /* Store current connection in a local variable so that we can restore it later. */
size = v_n_receive_data(&address, buf, sizeof buf); /* Ask for incoming data from the network. */
+
while(size != -1 && size != 0) /* Did we get any data? */
{
VConData.current_connection = v_co_find_connection(&address); /* Is there a connection matching the IP and port? */
vnp_raw_unpack_uint32(buf, &packet_id); /* Unpack the ID of the packet. */
-/* printf("got packet ID %u, %d bytes, connection %u\n", packet_id, size, VConData.current_connection);*/
+ /* printf("got packet ID %u, %d bytes, connection %u\n", packet_id, size, VConData.current_connection); */
+
+ /* If this isn't a packet from an existing connection, disregard it. */
if(VConData.current_connection < VConData.con_count &&
- !(VConData.con[VConData.current_connection].connect_stage == V_CS_CONNECTED && packet_id == 0)) /* If this isn't a packet from an existing connection, disregard it. */
+ !(VConData.con[VConData.current_connection].connect_stage == V_CS_CONNECTED && packet_id == 0))
{
- if(VConData.con[VConData.current_connection].connect_stage == V_CS_CONNECTED) /* Is this connection initialized? */
+ /* Is this connection initialized? */
+ if(VConData.con[VConData.current_connection].connect_stage == V_CS_CONNECTED)
{
store = v_niq_store(&VConData.con[VConData.current_connection].in_queue, size, packet_id); /* Store the packet. */
if(store != NULL)
{
+ int i;
VConData.pending_packets++; /* We now have one more packet pending unpack. */
- v_e_data_decrypt_packet(store, buf, size, VConData.con[VConData.current_connection].key_data); /* Decrypt the packet. */
+ for(i=0; i<size; i++) store[i] = buf[i]; /* Copy content of packet to queue */
v_fs_unpack_beginning(store, size);
}
}
@@ -298,8 +277,9 @@
;
else if(v_fs_func_accept_connections()) /* Do we accept connection-attempts? */
{
+ /* Is it a new client, or an old client that we haven't heard form in some time? */
if(VConData.current_connection >= VConData.con_count ||
- V_RE_CONNECTON_TIME_OUT < v_niq_time_out(&VConData.con[VConData.current_connection].in_queue)) /* Is it a new client, or an old client that we haven't heard form in some time? */
+ V_RE_CONNECTON_TIME_OUT < v_niq_time_out(&VConData.con[VConData.current_connection].in_queue))
{
if(VConData.current_connection < VConData.con_count)
{
@@ -381,8 +361,6 @@
v_noq_destroy_network_queue(VConData.con[VConData.current_connection].out_queue);
VConData.pending_packets -= v_niq_free(&VConData.con[VConData.current_connection].in_queue);
v_destroy_ordered_storage(VConData.con[VConData.current_connection].ordered_storage);
- if(VConData.con[VConData.current_connection].expected_key != NULL)
- free(VConData.con[VConData.current_connection].expected_key);
if(VConData.con_count - 1 != VConData.current_connection)
VConData.con[VConData.current_connection] = VConData.con[VConData.con_count - 1];
VConData.con_count--;
@@ -465,36 +443,6 @@
return VConData.con[VConData.current_connection].connect_stage;
}
-uint8 *v_con_get_my_key(void)
-{
- return VConData.con[VConData.current_connection].key_my;
-}
-
-uint8 *v_con_get_other_key(void)
-{
- return VConData.con[VConData.current_connection].key_other;
-}
-
-uint8 **v_con_get_expected_key(void)
-{
- return &VConData.con[VConData.current_connection].expected_key;
-}
-
-uint8 * v_con_get_host_id(void)
-{
- return VConData.host_id;
-}
-
-void v_con_set_data_key(const uint8 *key)
-{
- memcpy(VConData.con[VConData.current_connection].key_data, key, V_ENCRYPTION_DATA_KEY_SIZE);
-}
-
-const uint8 * v_con_get_data_key(void)
-{
- return VConData.con[VConData.current_connection].key_data;
-}
-
void * v_con_get_network_queue(void)
{
return VConData.con[VConData.current_connection].out_queue;
Modified: branches/verse-pam-branch/v_connection.h
===================================================================
--- branches/verse-pam-branch/v_connection.h 2008-08-19 13:36:28 UTC (rev 4535)
+++ branches/verse-pam-branch/v_connection.h 2008-08-22 12:30:15 UTC (rev 4536)
@@ -67,16 +67,6 @@
extern void v_con_set_connect_stage(VConnectStage stage);
extern VConnectStage v_con_get_connect_stage(void);
-
-extern uint8 *v_con_get_my_key(void);
-extern uint8 *v_con_get_other_key(void);
-extern uint8 *v_con_get_host_id(void);
-extern uint8 **v_con_get_expected_key(void);
-
-extern void v_con_set_data_key(const uint8 *key);
-extern const uint8 * v_con_get_data_key(void);
-
-
extern void * v_con_get_network_queue(void);
extern VNetworkAddress *v_con_get_network_address(void);
extern void * v_con_get_network_address_id(unsigned int id);
Deleted: branches/verse-pam-branch/v_encryption.c
===================================================================
--- branches/verse-pam-branch/v_encryption.c 2008-08-19 13:36:28 UTC (rev 4535)
+++ branches/verse-pam-branch/v_encryption.c 2008-08-22 12:30:15 UTC (rev 4536)
@@ -1,289 +0,0 @@
-/*
- * $Id$
- *
- * ***** BEGIN BSD LICENSE BLOCK *****
- *
- * Copyright (c) 2005-2008, The Uni-Verse Consortium.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * 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 BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER
- * 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.
- *
- * ***** END BSD LICENSE BLOCK *****
- *
- */
-
-/*
- * Verse encryption routines. Implements RSA encryption/decryption plus fast XORx.
-*/
-
-#if !defined(V_GENERATE_FUNC_MODE)
-
-#include <ctype.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "verse.h"
-#include "v_pack.h"
-#include "v_bignum.h"
-#include "v_encryption.h"
-
-#define BITS V_ENCRYPTION_LOGIN_KEY_BITS /* Save some typing. */
-
-extern void v_prime_set_random(VBigDig *x);
-extern void v_prime_set_table(VBigDig *x, int i);
-
-const uint8 * v_e_data_create_key(void) /* possibly the worst key gen ever */
-{
- static unsigned int counter = 0;
- static uint8 buffer[V_ENCRYPTION_DATA_KEY_SIZE];
- unsigned int i, temp;
-
- for(i = 0; i < V_ENCRYPTION_DATA_KEY_SIZE; i++)
- {
- counter++;
- temp = (counter << 13) ^ counter;
- temp = (temp * (temp * temp * 15731 + 789221) + 1376312589) & 0x7fffffff;
- buffer[i] = temp;
- }
- /* FIXME: This really isn't very pretty. */
- buffer[0] &= 0x3f; /* Make sure top word is... Low. For RSA compatibility. */
-
-/* memset(buffer, 0, sizeof buffer);
- fprintf(stderr, "**WARNING: XOR data encryption disabled\n");
-*/
- return buffer;
-}
-
-void v_e_data_encrypt_command(uint8 *packet, size_t packet_size, const uint8 *command, size_t command_size, const uint8 *key)
-{
- uint32 pos, i;
-
- vnp_raw_unpack_uint32(packet, &pos);
-/* printf("encrypting packet %u", pos);*/
- pos = key[pos % V_ENCRYPTION_DATA_KEY_SIZE] + packet_size;
-/* printf(" -> pos=%u (size %u)", pos, packet_size);
- printf(", key begins: [");
- for(i = 0; i < 16; i++)
- printf(" %02X", key[(pos + i) % V_ENCRYPTION_DATA_KEY_SIZE]);
- printf(" ]\n");
-*/
- for(i = 0; i < command_size; i++)
- packet[packet_size + i] = command[i] ^ key[(i + pos) % V_ENCRYPTION_DATA_KEY_SIZE];
-}
-
-void v_e_data_decrypt_packet(uint8 *to, const uint8 *from, size_t size, const uint8 *key)
-{
- uint32 pos, i;
-
- vnp_raw_unpack_uint32(from, &pos);
-/* printf("decrypting packet %u", pos);*/
- pos = key[pos % V_ENCRYPTION_DATA_KEY_SIZE];
-/* printf(" -> pos=%u", pos);
- printf(", key begins: [");
- for(i = 0; i < 16; i++)
- printf(" %02X", key[(i + pos) % V_ENCRYPTION_DATA_KEY_SIZE]);
- printf(" ]\n");
-*/ for(i = 0; i < 4; i++)
- to[i] = from[i];
- for(i = 4; i < size; i++)
- to[i] = from[i] ^ key[(i + pos) % V_ENCRYPTION_DATA_KEY_SIZE];
-}
-
-#endif
-
-/* From Knuth. Computes multiplicative inverse of u, modulo v. */
-void v_e_math_inv(VBigDig *inv, const VBigDig *u, const VBigDig *v)
-{
- VBigDig VBIGNUM(u1, 2*BITS), VBIGNUM(u3, 2*BITS), VBIGNUM(v1, 2*BITS), VBIGNUM(v3, 2 *BITS),
- VBIGNUM(t1, 2*BITS), VBIGNUM(t3, 2*BITS), VBIGNUM(q, 2*BITS), VBIGNUM(w, 2*BITS);
- int iter = 1;
-
- v_bignum_set_one(u1);
- v_bignum_set_bignum(u3, u);
- v_bignum_set_zero(v1);
- v_bignum_set_bignum(v3, v);
-
- while(!v_bignum_eq_zero(v3))
- {
- v_bignum_set_bignum(q, u3);
- v_bignum_div(q, v3, t3);
- v_bignum_set_bignum(w, q);
- v_bignum_mul(w, v1);
- v_bignum_set_bignum(t1, u1);
- v_bignum_add(t1, w);
-
- v_bignum_set_bignum(u1, v1);
- v_bignum_set_bignum(v1, t1);
- v_bignum_set_bignum(u3, v3);
- v_bignum_set_bignum(v3, t3);
- iter = -iter;
- }
- if(iter < 0)
- {
- v_bignum_set_bignum(inv, v);
- v_bignum_sub(inv, u1);
- }
- else
- v_bignum_set_bignum(inv, u1);
-}
-
-void v_e_connect_create_key(uint8 *private_key, uint8 *public_key, uint8 *n)
-{
- VBigDig VBIGNUM(p, BITS / 2), VBIGNUM(q, BITS / 2), VBIGNUM(qmo, BITS / 2), VBIGNUM(phi, BITS),
- VBIGNUM(pub, BITS), VBIGNUM(priv, BITS), VBIGNUM(mod, BITS);
-
-#if !defined _WIN32
- /* FIXME: This is a security backdoor. Intent is simply to save time during testing. */
- if(getenv("VERSE_NORSA") != NULL)
- {
- printf("VERSE: Found the NORSA envvar, using constant keys\n");
- v_prime_set_table(p, 0);
- v_prime_set_table(q, 1);
- goto compute_phi;
- }
-#endif
-/* printf("find prime p\n");*/
- v_prime_set_random(p);
-/* printf("find prime q\n");*/
- v_prime_set_random(q);
-compute_phi:
-/* printf("done, computing key\n");*/
-/* printf("p=");
- v_bignum_print_hex_lf(p);
- printf("q=");
- v_bignum_print_hex_lf(q);
-*/ v_bignum_set_bignum(phi, p);
- v_bignum_sub_digit(phi, 1);
- v_bignum_set_bignum(qmo, q);
- v_bignum_sub_digit(qmo, 1);
- v_bignum_mul(phi, qmo);
-/* printf("phi=");
- v_bignum_print_hex_lf(phi);
-*/ v_bignum_set_string_hex(pub, "0x10001");
- v_e_math_inv(priv, pub, phi);
-/* printf(" pub=");
- v_bignum_print_hex_lf(pub);
- printf("priv=");
- v_bignum_print_hex_lf(priv);
-*/
- v_bignum_set_bignum(mod, p);
- v_bignum_mul(mod, q);
-/* printf(" mod=");
- v_bignum_print_hex_lf(mod);
- printf("key-creation finished\n");
-*/ /* Write out the keys. */
- v_bignum_raw_export(pub, public_key);
- v_bignum_raw_export(priv, private_key);
- v_bignum_raw_export(mod, n);
-}
-
-void v_e_connect_encrypt(uint8 *output, const uint8 *data, const uint8 *key, const uint8 *key_n)
-{
- VBigDig VBIGNUM(packet, BITS), VBIGNUM(expo, BITS), VBIGNUM(mod, BITS);
-
- v_bignum_raw_import(packet, data);
- v_bignum_raw_import(expo, key);
- v_bignum_raw_import(mod, key_n);
-
- /* Verify that data is less than the modulo, this is a prerequisite for encryption. */
- if(!v_bignum_gte(mod, packet))
- {
- printf("*** WARNING. Data is not less than modulo, as it should be--encryption will break!\n");
- printf(" RSA modulo: ");
- v_bignum_print_hex_lf(mod);
- printf(" RSA data: ");
- v_bignum_print_hex_lf(packet);
- }
-/* printf("RSA key: ");
- v_bignum_print_hex_lf(expo);
- printf("RSA mod: ");
- v_bignum_print_hex_lf(mod);
- printf("RSA in: ");
- v_bignum_print_hex_lf(packet);
- printf("bits in packet: %d, ", v_bignum_bit_msb(packet) + 1);
- printf("bits in modulo: %d\n", v_bignum_bit_msb(mod) + 1);
-*/ v_bignum_pow_mod(packet, expo, mod); /* Blam. */
-/* printf("RSA out: ");
- v_bignum_print_hex_lf(packet);
-*/ v_bignum_raw_export(packet, output);
-}
-
-#if defined CRYPTALONE
-void v_encrypt_test(void)
-{
- uint8 k_priv[BITS / 8], k_pub[BITS / 8], k_n[BITS / 8], cipher[BITS / 8], plain[BITS / 8], decode[BITS / 8], i;
-
- printf("testing RSA-crypto\n");
- v_e_connect_create_key(k_pub, k_priv, k_n);
-/* exit(0);*/
- printf("key pair generated, encrypting something\n");
- memset(plain, 0, sizeof plain);
- strcpy(plain, "This is some text to encrypt, to give it something to chew on.");
- printf("plain: %02X (%u)\n", plain[0], strlen(plain));
- v_e_connect_encrypt(cipher, plain, k_pub, k_n);
- printf("plain: %02X, cipher: %02X\n", plain[0], cipher[0]);
- v_e_connect_encrypt(decode, cipher, k_priv, k_n);
- printf("decoded: %02X: '", decode[0]);
- for(i = 0; decode[i] != 0; i++)
- putchar(decode[i]);
- printf("'\n");
-/* printf("\npublic key: ");
- v_bignum_print_hex_lf(k_public);
- printf("private key: ");
- v_bignum_print_hex_lf(k_private);
- v_bignum_set_string(msg, "123");
- gettimeofday(&t1, NULL);
- v_bignum_pow_mod(msg, k_private, k_n);
- gettimeofday(&t2, NULL);
- printf("encrypted: ");
- v_bignum_print_hex_lf(msg);
- printf("encrypted %u bits in %g s\n", BITS, t2.tv_sec - t1.tv_sec + 1.0E-6 * (t2.tv_usec - t1.tv_usec));
-
- gettimeofday(&t1, NULL);
- v_bignum_pow_mod(msg, k_public, k_n);
- gettimeofday(&t2, NULL);
- printf("decrypted: ");
- v_bignum_print_hex_lf(msg);
- printf("decrypted %u bits in %g s\n", BITS, t2.tv_sec - t1.tv_sec + 1.0E-6 * (t2.tv_usec - t1.tv_usec));
- exit(0);
-*//* v_e_encrypt(cipher, plain, &k_private, &k_n);
- printf("encrypted data: ");
- for(i = 0; i < sizeof cipher; i++)
- printf("%c", isalnum(cipher[i]) ? cipher[i] : '?');
- printf("\n\n");
- printf("decrypting\n");
- v_e_encrypt(decode, cipher, &k_public, &k_n);
- printf("decrypted data: ");
- for(i = 0; i < sizeof cipher; i++)
- printf("%c", isalnum(decode[i]) ? decode[i] : '?');
- printf("\n\n");
-*/
-}
-
-int main(void)
-{
- v_encrypt_test();
-
- return 0;
-}
-#endif
Deleted: branches/verse-pam-branch/v_encryption.h
===================================================================
--- branches/verse-pam-branch/v_encryption.h 2008-08-19 13:36:28 UTC (rev 4535)
+++ branches/verse-pam-branch/v_encryption.h 2008-08-22 12:30:15 UTC (rev 4536)
@@ -1,66 +0,0 @@
-/*
- * $Id$
- *
- * ***** BEGIN BSD LICENSE BLOCK *****
- *
- * Copyright (c) 2005-2008, The Uni-Verse Consortium.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * 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 BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER
- * 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.
- *
- * ***** END BSD LICENSE BLOCK *****
- *
- */
-
-/*
- * Verse encryption routines. There are two distinct flavors of encryption
- * in use: one "heavy" for login/connection establishment security, and
- * a far lighter symmetrical one that is applied to each data packet after
- * the key has been exchanged during connection.
-*/
-
-#include "verse.h"
-
-/* Internal key size definitions. *MUST* be kept in sync with V_HOST_ID_SIZE in verse_header.h! */
-#define V_ENCRYPTION_LOGIN_KEY_BITS 512
-#define V_ENCRYPTION_LOGIN_KEY_SIZE (V_ENCRYPTION_LOGIN_KEY_BITS / 8)
-#define V_ENCRYPTION_LOGIN_KEY_FULL_SIZE (3 * V_ENCRYPTION_LOGIN_KEY_SIZE)
-#define V_ENCRYPTION_LOGIN_KEY_HALF_SIZE (2 * V_ENCRYPTION_LOGIN_KEY_SIZE)
-
-#define V_ENCRYPTION_LOGIN_PUBLIC_START (0 * V_ENCRYPTION_LOGIN_KEY_SIZE)
-#define V_ENCRYPTION_LOGIN_PRIVATE_START (1 * V_ENCRYPTION_LOGIN_KEY_SIZE)
-#define V_ENCRYPTION_LOGIN_N_START (2 * V_ENCRYPTION_LOGIN_KEY_SIZE)
-
-#define V_ENCRYPTION_DATA_KEY_SIZE (V_ENCRYPTION_LOGIN_KEY_BITS / 8)
-
-/* Connection encryption. Heavy, and symmetrical, so encrypt() does both encryption
- * and decryption given the proper key. Current algorithm used is RSA.
-*/
-extern void v_e_connect_create_key(uint8 *private_key, uint8 *public_key, uint8 *n);
-extern void v_e_connect_encrypt(uint8 *output, const uint8 *data, const uint8 *key, const uint8 *key_n);
-
-/* Actual data traffic encryption. Also symmetrical, with a single key. Uses XOR. */
-extern const uint8 * v_e_data_create_key(void);
-extern void v_e_data_encrypt_command(uint8 *packet, size_t packet_length,
- const uint8 *command, size_t command_length, const uint8 *key);
-extern void v_e_data_decrypt_packet(uint8 *to, const uint8 *from, size_t size, const uint8 *key);
Modified: branches/verse-pam-branch/v_func_storage.c
===================================================================
--- branches/verse-pam-branch/v_func_storage.c 2008-08-19 13:36:28 UTC (rev 4535)
+++ branches/verse-pam-branch/v_func_storage.c 2008-08-22 12:30:15 UTC (rev 4536)
@@ -175,13 +175,16 @@
uint32 i, output, pack_id;
uint8 cmd_id, last = 255;
- i = vnp_raw_unpack_uint32(data, &pack_id); /* each packet starts with a 32 bit id */
- vnp_raw_unpack_uint8(&data[i], &cmd_id);
+ i = vnp_raw_unpack_uint32(data, &pack_id); /* Each packet starts with a 32 bit id */
+ vnp_raw_unpack_uint8(&data[i], &cmd_id); /* Then follows command ID */
+
+ /* Skiping of ack_nak commands at begining? */
while(i < length && (cmd_id == 7 || cmd_id == 8))
{
i += 5;
vnp_raw_unpack_uint8(&data[i], &cmd_id);
}
+
while(i < length)
{
i += vnp_raw_unpack_uint8(&data[i], &cmd_id);
@@ -192,7 +195,7 @@
if(output == (unsigned int) -1) /* Can this happen? Should be size_t or int, depending. */
{
printf("** Aborting decode, command %u unpacker returned failure\n", cmd_id);
-/* verse_send_packet_nak(pack_id);*/
+ /* verse_send_packet_nak(pack_id); */
return;
}
last = cmd_id;
Modified: branches/verse-pam-branch/v_man_pack_node.c
===================================================================
--- branches/verse-pam-branch/v_man_pack_node.c 2008-08-19 13:36:28 UTC (rev 4535)
+++ branches/verse-pam-branch/v_man_pack_node.c 2008-08-22 12:30:15 UTC (rev 4536)
@@ -45,7 +45,6 @@
#include "v_network_out_que.h"
#include "v_network.h"
#include "v_connection.h"
-#include "v_encryption.h"
unsigned int v_unpack_connect(const char *buf, unsigned int buffer_length)
{
Modified: branches/verse-pam-branch/v_network_in_que.c
===================================================================
--- branches/verse-pam-branch/v_network_in_que.c 2008-08-19 13:36:28 UTC (rev 4535)
+++ branches/verse-pam-branch/v_network_in_que.c 2008-08-22 12:30:15 UTC (rev 4536)
@@ -133,18 +133,27 @@
v_niq_timer_update(queue);
+ /* We have already received packet with this ID */
if(packet_id < queue->packet_id)
return NULL;
-
+
+ /* We expect packet with 'queue->packet_id', but we received
+ * packet with 'packet_id'. We have to send NAK commands for
+ * all not received (probably lost packets) with ID smaller
+ * then 'packet_id'. */
while(queue->packet_id != packet_id)
{
verse_send_packet_nak(queue->packet_id++);
if(queue->packet_id == 0)
queue->packet_id++;
}
+
+ /* ID of next expected packet */
queue->packet_id++;
if(queue->packet_id == 0)
queue->packet_id++;
+
+ /* Send ACK command for successfuly received packet */
verse_send_packet_ack(packet_id);
if(v_niq_temp == NULL)
Modified: branches/verse-pam-branch/v_network_out_que.c
===================================================================
--- branches/verse-pam-branch/v_network_out_que.c 2008-08-19 13:36:28 UTC (rev 4535)
+++ branches/verse-pam-branch/v_network_out_que.c 2008-08-22 12:30:15 UTC (rev 4536)
@@ -43,7 +43,6 @@
#include "v_connection.h"
#include "v_network.h"
#include "v_pack.h"
-#include "v_encryption.h"
#include "v_network_out_que.h"
#include "v_util.h"
@@ -203,22 +202,20 @@
void v_noq_send_buf(VNetOutQueue *queue, VCMDBufHead *buf)
{
static int count = 0;
-/* if(queue->unsent_comands > V_NOQ_MAX_SORTED_COMMANDS)
+
+ if(queue->unsorted == NULL)
{
+ queue->unsorted_end = buf;
+ queue->unsorted = buf;
+ } else
+ {
+ queue->unsorted_end->next = buf;
+ queue->unsorted_end = buf;
+ }
+
+ queue->unsorted_count++;
+ count = (count + 1) % 30; /* Magix number again!!! */
-*/ if(queue->unsorted == NULL)
- {
- queue->unsorted_end = buf;
- queue->unsorted = buf;
- }else
- {
- queue->unsorted_end->next = buf;
- queue->unsorted_end = buf;
- }
- queue->unsorted_count++;
-/* }else
- v_noq_sort_and_colapse_buf(queue, buf);
-*/ count = (count + 1) % 30;
if(count == 0)
{
v_con_network_listen();
@@ -247,53 +244,60 @@
}
}
+/* Pack some data from sending queue to packet and send it. */
boolean v_noq_send_queue(VNetOutQueue *queue, void *address)
{
- static unsigned int my_counter = 0;
VCMDBufHead *buf;
unsigned int size;
uint8 *data;
uint32 seconds, fractions;
double delta;
+ int i;
data = queue->packet_buffer;
v_n_get_current_time(&seconds, &fractions);
+
+ /* Delta time of previous sending from this queue */
delta = seconds - queue->seconds + (fractions - queue->fractions) / (double) 0xffffffff;
+ /* Sort commands in sending queue (how?). */
if(queue->unsorted != NULL)
v_noq_sort_unsorted(queue);
+ /* No data to send? */
if(queue->unsent_size == 0 && delta < 1.0 && (queue->ack_nak == NULL || queue->ack_nak->next == NULL))
return FALSE;
+ /* Send data from packet buffer. */
if(delta > 3.0 && queue->unsent_size == 0 && queue->ack_nak == NULL && queue->packet_buffer_use != 0)
{
-/* printf("A) re-sending last delta=%g\n", delta);*/
v_n_send_data(address, data, queue->packet_buffer_use);
queue->seconds = seconds;
queue->fractions = fractions;
return TRUE;
}
- size = 4;
+ /* Packet ID is at beginning of packet */
+ vnp_raw_pack_uint32(data, queue->packet_id);
+ size = 4; /* 4 is size of unit32 (packet_id) */
buf = queue->ack_nak;
while(buf != NULL && size + buf->size < V_NOQ_MAX_PACKET_SIZE)
{
- vnp_raw_pack_uint32(data, queue->packet_id);
queue->ack_nak = buf->next;
buf->next = queue->history[queue->slot];
queue->history[queue->slot] = buf;
buf->packet = queue->packet_id;
- v_e_data_encrypt_command(data, size, ((VCMDBuffer1500 *)buf)->buf, buf->size, v_con_get_data_key());
+ for(i=0; i < buf->size; i++) data[size+i] = ((VCMDBuffer1500 *)buf)->buf[i];
size += buf->size;
queue->sent_size += buf->size;
buf = queue->ack_nak;
}
+
+ /* Send data, when we can't send more. */
if(queue->unsent_size == 0 || queue->sent_size >= V_NOQ_WINDOW_SIZE)
{
if(size > 5)
{
-/* printf("ACK: sending actual size=%u id=%u\n", size, queue->packet_id);*/
v_n_send_data(address, data, size);
queue->packet_buffer_use = size;
queue->seconds = seconds;
@@ -301,40 +305,36 @@
queue->packet_id++;
return TRUE;
}
-/* printf("returning FALSE from send_queue()\n");*/
return FALSE;
}
-/* if(queue->sent_size < V_NOQ_WINDOW_SIZE && queue->unsent_size != 0)*/
+
+ /* Try to add something more to this packet. */
+ while(queue->unsent_size != 0)
{
- vnp_raw_pack_uint32(data, queue->packet_id);
- while(queue->unsent_size != 0)
+ queue->slot = ((1 + queue->slot) % V_NOQ_OPTIMIZATION_SLOTS);
+ buf = queue->unsent[queue->slot];
+ if(buf != NULL)
{
- queue->slot = ((1 + queue->slot) % V_NOQ_OPTIMIZATION_SLOTS);
- buf = queue->unsent[queue->slot];
- if(buf != NULL)
- {
- if(buf->size + size > V_NOQ_MAX_PACKET_SIZE)
- break;
- queue->unsent[queue->slot] = buf->next;
- buf->next = queue->history[queue->slot];
- queue->history[queue->slot] = buf;
- buf->packet = queue->packet_id;
-
- v_e_data_encrypt_command(data, size, ((VCMDBuffer1500 *)buf)->buf, buf->size, v_con_get_data_key());
- size += buf->size;
- queue->unsent_comands--;
- queue->unsent_size -= buf->size;
- queue->sent_size += buf->size;
- my_counter++;
- }
+ if(buf->size + size > V_NOQ_MAX_PACKET_SIZE)
+ break;
+ queue->unsent[queue->slot] = buf->next;
+ buf->next = queue->history[queue->slot];
+ queue->history[queue->slot] = buf;
+ buf->packet = queue->packet_id;
+ for(i=0; i < buf->size; i++) data[size+i] = ((VCMDBuffer1500 *)buf)->buf[i];
+ size += buf->size;
+ queue->unsent_comands--;
+ queue->unsent_size -= buf->size;
+ queue->sent_size += buf->size;
}
- v_n_send_data(address, data, size);
- queue->packet_buffer_use = size;
- queue->packet_id++;
-/* size = vnp_raw_pack_uint32(data, queue->packet_id);*/
- queue->seconds = seconds;
- queue->fractions = fractions;
}
+
+ v_n_send_data(address, data, size);
+ queue->packet_buffer_use = size;
+ queue->packet_id++;
+ queue->seconds = seconds;
+ queue->fractions = fractions;
+
return TRUE;
}
Deleted: branches/verse-pam-branch/v_prime.c
===================================================================
--- branches/verse-pam-branch/v_prime.c 2008-08-19 13:36:28 UTC (rev 4535)
+++ branches/verse-pam-branch/v_prime.c 2008-08-22 12:30:15 UTC (rev 4536)
@@ -1,199 +0,0 @@
-/*
- * $Id$
- *
- * ***** BEGIN BSD LICENSE BLOCK *****
- *
- * Copyright (c) 2005-2008, The Uni-Verse Consortium.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * 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 BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER
- * 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.
- *
- * ***** END BSD LICENSE BLOCK *****
- *
- */
-
-/*
- * Program to generate primes of the form p = 2 * q + 1,
- * where p and q are both primes.
- *
- * Originally written by Pontus Nyman <f97-pny at nada.kth.se>,
- * ported to Verse's bignums and rewritten from scratch by
- * Emil Brink.
- */
-
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "v_bignum.h"
-#include "v_encryption.h"
-#include "verse_header.h"
-
-#define BITS V_ENCRYPTION_LOGIN_KEY_BITS /* Save some typing. */
-
-#define CYCLES 10 /* Number of times to apply Miller-Rabin test. */
-
-/* Test divisibility of <n> against table of small known primes. Returns 1 if n looks prime, 0 if it IS not. */
-static int quick_filter(const VBigDig *n)
-{
- VBigDig VBIGNUM(m, 16), VBIGNUM(tmp, BITS / 2);
- const unsigned int prime[] = { 3, 5, 7, 11, 13, 17, 19, 23, 39, 31, 37, 41, 43, 47, 53 };
- unsigned int i;
-
- for(i = 0; i < sizeof prime / sizeof *prime; i++)
- {
- v_bignum_set_bignum(tmp, n);
- v_bignum_set_digit(m, prime[i]);
- v_bignum_mod(tmp, m);
- if(v_bignum_eq_zero(tmp))
- return 0;
- }
- return 1;
-}
-
-/* The Miller-Rabin primality test. Returns 1 if the candidate looks prime, 0 if
- * it IS NOT prime. Assumes that n is BITS / 2 bits, so that its square fits in BITS.
-*/
-static int miller_rabin(const VBigDig *n, VRandGen *gen)
-{
- int i, k;
- VBigDig VBIGNUM(a, BITS / 2), VBIGNUM(d, BITS), VBIGNUM(nmo, BITS / 2), VBIGNUM(x, BITS);
- const VBigDig *mu;
-
- mu = v_bignum_reduce_begin(n);
-
- /* Pick a "witness", a number in the [1, n) range. */
- v_bignum_set_random(a, gen);
- v_bignum_reduce(a, n, mu);
-
- v_bignum_set_one(d);
- v_bignum_set_bignum(nmo, n);
- v_bignum_sub_digit(nmo, 1); /* nmo = n - 1 (say it). */
- k = v_bignum_bit_msb(nmo);
- for(i = k; i >= 0; i--)
- {
- v_bignum_set_bignum(x, d);
- v_bignum_square_half(d);
- v_bignum_reduce(d, n, mu);
- if(v_bignum_eq_one(d) && !v_bignum_eq_one(x) && !v_bignum_eq(x, nmo))
- {
- v_bignum_reduce_end(mu);
- return 0; /* Composite found. */
- }
- if(v_bignum_bit_test(nmo, i))
- {
- v_bignum_mul(d, a);
- v_bignum_reduce(d, n, mu);
- }
- }
- v_bignum_reduce_end(mu);
- return v_bignum_eq_one(d); /* It might be prime. */
-}
-
-/* Test q for primality, returning 1 if it seems prime, 0 if it certainly IS not. */
-int v_prime_test(const VBigDig *q, VRandGen *gen)
-{
- int i;
-
- if(!quick_filter(q))
- return 0;
-
- for(i = 0; i < CYCLES; i++)
- {
- if(!miller_rabin(q, gen))
- return 0;
- }
- return 1;
-}
-
-void v_prime_set_random(VBigDig *x)
-{
- int bits = v_bignum_bit_size(x);
- VRandGen *gen;
-
- gen = v_randgen_new();
- do
- {
- /* Create candidate, making sure it's both odd and non-zero. */
- v_bignum_set_random(x, gen);
- /* Set topmost two bits, makes sure products are big. */
- v_bignum_bit_set(x, bits - 1);
- v_bignum_bit_set(x, bits - 2);
- /* Set lowermost bit, makes sure it is odd (better prime candidate that way). */
- v_bignum_bit_set(x, 0);
- } while(!v_prime_test(x, gen));
-/* printf("Prime found after %d iterations: ", count);
- v_bignum_print_hex_lf(x);
-*/
- v_randgen_destroy(gen);
-}
-
-/* Big (small?) primes from <http://www.utm.edu/research/primes/lists/small/small3.html#300>. */
-void v_prime_set_table(VBigDig *x, unsigned int i)
-{
- if(i == 0)
- v_bignum_set_string_hex(x, "0xCBC2C5536E3D6283FDAF36B1D0F91C3EAAB1D12892B961B866907930F6471851");
- else if(i == 1)
- v_bignum_set_string_hex(x, "0xC14F93E7A1543BD57C1DFBE98C29F9E4C13077FD27A0FEC05CCBC913CD213F19");
- else
- v_bignum_set_string(x, "65537"); /* It ain't big, but it's prime. */
-}
-
-#if PRIMEALONE
-#include <sys/time.h>
-
-#define REPS 300
-
-static double elapsed(const struct timeval *t1, const struct timeval *t2)
-{
- return t2->tv_sec - t1->tv_sec + 1E-6 * (t2->tv_usec - t1->tv_usec);
-}
-
-int main(void)
-{
- struct timeval now, then;
- VBigDig VBIGNUM(x, BITS / 2);
- int i;
-
- srand(clock());
-
-/* gettimeofday(&then, NULL);
- for(i = 0; i < REPS; i++)
- {
- v_prime_set_random_incr(x);
- }
- gettimeofday(&now, NULL);
- printf("incr: %g\n", elapsed(&then, &now));
-*/
- gettimeofday(&then, NULL);
- for(i = 0; i < REPS; i++)
- {
- v_prime_set_random(x);
- }
- gettimeofday(&now, NULL);
- printf("rand: %g\n", elapsed(&then, &now));
-
- return EXIT_SUCCESS;
-}
-
-#endif
Deleted: branches/verse-pam-branch/v_randgen.c
===================================================================
--- branches/verse-pam-branch/v_randgen.c 2008-08-19 13:36:28 UTC (rev 4535)
+++ branches/verse-pam-branch/v_randgen.c 2008-08-22 12:30:15 UTC (rev 4536)
@@ -1,135 +0,0 @@
-/*
- * $Id$
- *
- * ***** BEGIN BSD LICENSE BLOCK *****
- *
- * Copyright (c) 2005-2008, The Uni-Verse Consortium.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * 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 BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER
- * 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.
- *
- * ***** END BSD LICENSE BLOCK *****
- *
- */
-
-/*
- * Random number generator module. Defines a simple API to allocate, use and
- * destroy a generator of randomness. Relies on platform-specific APIs.
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "v_randgen.h"
-
-#if defined _WIN32
-
-/* This is a fall-back to the old style of simply using rand(). It should
- * be replaced by something using the proper Win32 cryptography APIs.
- * The CryptAcquireContext() and CryptGenRandom() calls sound interesting.
- *
- * FIXME: Replace ASAP.
-*/
-
-VRandGen * v_randgen_new(void)
-{
- return (VRandGen *) 1; /* Anything that isn't NULL. */
-}
-
-void v_randgen_get(VRandGen *gen, void *bytes, size_t num)
-{
- if(gen != NULL && bytes != NULL)
- {
- unsigned char *put = bytes, *get;
- size_t i;
- int x;
-
- while(num > 0)
- {
- x = rand();
- get = (unsigned char *) &x;
- for(i = 0; i < sizeof x && num > 0; i++, num--)
- *put++ = *get++;
- }
- }
-}
-
-void v_randgen_destroy(VRandGen *gen)
-{
- /* Nothing to do here. */
-}
-
-#else
-
-/* On non-Win32 platforms (which is Linux and Darwin, at the moment), we
- * read random data from a file, which is assumed to be one of the kernel's
- * virtual files.
-*/
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-struct VRandGen {
- int fd;
-};
-
-#define SOURCE "/dev/urandom" /* Name of file to read random bits from. */
-
-VRandGen * v_randgen_new(void)
-{
- VRandGen *gen;
-
- if((gen = malloc(sizeof *gen)) != NULL)
- {
- gen->fd = open(SOURCE, O_RDONLY);
- if(gen->fd < 0)
- {
- fprintf(stderr, __FILE__ ": Couldn't open " SOURCE " for reading\n");
- free(gen);
- gen = NULL;
- }
- }
- return gen;
-}
-
-void v_randgen_get(VRandGen *gen, void *bytes, size_t num)
-{
- if(gen != NULL && bytes != NULL)
- {
- if(read(gen->fd, bytes, num) != (int) num)
- fprintf(stderr, __FILE__ ": Failed to read %u bytes of random data from " SOURCE "\n", (unsigned int) num);
- }
-}
-
-void v_randgen_destroy(VRandGen *gen)
-{
- if(gen != NULL)
- {
- close(gen->fd);
- free(gen);
- }
-}
-
-#endif
Deleted: branches/verse-pam-branch/v_randgen.h
===================================================================
--- branches/verse-pam-branch/v_randgen.h 2008-08-19 13:36:28 UTC (rev 4535)
+++ branches/verse-pam-branch/v_randgen.h 2008-08-22 12:30:15 UTC (rev 4536)
@@ -1,48 +0,0 @@
-/*
- * $Id$
- *
- * ***** BEGIN BSD LICENSE BLOCK *****
- *
- * Copyright (c) 2005-2008, The Uni-Verse Consortium.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * 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 BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER
- * 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.
- *
- * ***** END BSD LICENSE BLOCK *****
- *
- */
-
-/*
- * Random number generator API. A way to improve over rand().
-*/
-
-#if !defined V_RANDGEN_H
-#define V_RANDGEN_H
-
-typedef struct VRandGen VRandGen;
-
-extern VRandGen * v_randgen_new(void);
-extern void v_randgen_get(VRandGen *gen, void *bytes, size_t num);
-extern void v_randgen_destroy(VRandGen *gen);
-
-#endif /* V_RANDGEN_H */
Modified: branches/verse-pam-branch/verse_header.h
===================================================================
--- branches/verse-pam-branch/verse_header.h 2008-08-19 13:36:28 UTC (rev 4535)
+++ branches/verse-pam-branch/verse_header.h 2008-08-22 12:30:15 UTC (rev 4536)
@@ -422,8 +422,6 @@
extern void verse_set_port(uint16 port);
extern void verse_set_protocol(uint32 protocol);
-extern void verse_host_id_create(uint8 *id);
-extern void verse_host_id_set(uint8 *id);
extern void verse_callback_set(void *send_func, void *callback, void *user_data);
extern void verse_callback_update(uint32 microseconds);
extern void verse_session_set(VSession session);
Modified: branches/verse-pam-branch/vs_main.c
===================================================================
--- branches/verse-pam-branch/vs_main.c 2008-08-19 13:36:28 UTC (rev 4535)
+++ branches/verse-pam-branch/vs_main.c 2008-08-22 12:30:15 UTC (rev 4536)
@@ -190,7 +190,7 @@
#endif
-static void callback_send_connect(void *user, const char *name, const char *pass, const char *address, const uint8 *host_id)
+static void callback_send_connect(void *user, const char *name, const char *pass, const char *address)
{
VNodeID avatar;
VSession *session;
@@ -204,9 +204,8 @@
{
printf("OK\n");
avatar = vs_node_create(~0, V_NT_OBJECT);
- session = verse_send_connect_accept(avatar, address, NULL);
+ session = verse_send_connect_accept(avatar, address);
vs_add_new_connection(session, name, pass, avatar);
-/* vs_avatar_init(avatar, name);*/
}
else
{
@@ -224,37 +223,6 @@
vs_remove_connection();
}
-static void vs_load_host_id(const char *file_name)
-{
- FILE *f;
- uint8 id[V_HOST_ID_SIZE];
- size_t got;
-
- /* Attempt to read key from given filename. Fails silently. */
- if((f = fopen(file_name, "rb")) != NULL)
- {
- if((got = fread(id, 1, sizeof id, f)) > 0)
- {
- printf("Loaded %u-bit host ID key successfully\n", 8 * (got / 3));
- verse_host_id_set(id);
- }
- fclose(f);
- if(got)
- return;
- }
- /* If file didn't open, or reading failed, generate a new key and write it out. */
- verse_host_id_create(id);
- verse_host_id_set(id);
- if((f = fopen(file_name, "wb")) != NULL)
- {
- if(fwrite(id, sizeof id, 1, f) != 1)
- fprintf(stderr, "Warning: Couldn't write host ID to \"%s\"\n", file_name);
- fclose(f);
- }
- else
- fprintf(stderr, "Warning: Couldn't open \"%s\" for host ID writing\n", file_name);
-}
-
static void cb_sigint_handler(int sig)
{
if(sig == SIGINT)
@@ -332,11 +300,6 @@
verse_set_protocol(protocol); /* Set used protocol (IPv4 or IPv6) */
printf(" Listening on port %d\n", port);
- /* Seed the random number generator. Still rather too weak for crypto, I guess. */
- v_n_get_current_time(&seconds, &fractions);
- srand(seconds ^ fractions);
-
- vs_load_host_id("host_id.rsa");
vs_init_node_storage();
vs_o_callback_init();
vs_g_callback_init();
Modified: branches/verse-pam-branch/vs_node_storage.c
===================================================================
--- branches/verse-pam-branch/vs_node_storage.c 2008-08-19 13:36:28 UTC (rev 4535)
+++ branches/verse-pam-branch/vs_node_storage.c 2008-08-22 12:30:15 UTC (rev 4536)
@@ -172,13 +172,6 @@
return node_id;
}
-/* Initialize an object node into being an avatar. */
-void vs_avatar_init(VNodeID id, const char *name)
-{
- callback_send_tag_group_create(NULL, id, (short) ~0u, "avatar");
- /* FIXME: Populate the group, too. */
-}
-
void vs_reset_owner(VNodeID owner_id)
{
unsigned int i;
More information about the Verse-cvs
mailing list