Commit 61d10b30 authored by Roger Dingledine's avatar Roger Dingledine
Browse files

Folded cell.? into src/or

Removed more obsolete files


svn:r61
parent 926081ad
Loading
Loading
Loading
Loading
+3 −6
Changes for src/common/Makefile.am: 3 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -3,12 +3,9 @@ noinst_LIBRARIES = libor.a

#CFLAGS  = -Wall -Wpointer-arith -O2

libor_a_SOURCES = cell.c config.c key.c log.c opcell.c \
                     routent.c scheduler.c utils.c
libor_a_SOURCES = config.c key.c log.c utils.c

# ss.h is not used anywhere, distributing it just because

noinst_HEADERS = cell.h config.h key.h log.h opcell.h \
		     policies.h routent.h scheduler.h utils.h \
noinst_HEADERS = config.h key.h log.h \
		     policies.h utils.h \
                     ss.h version.h

src/common/cell.c

deleted100644 → 0
+0 −355
Changes for src/common/cell.c: 0 added lines, 355 removed lines.
Original line number Diff line number Diff line
/**
 * cell.c
 * Cell manipulation.
 *
 * Matej Pfajfar <mp292@cam.ac.uk>
 */

/*
 * Changes :
 * $Log$
 * Revision 1.1  2002/06/26 22:45:50  arma
 * Initial revision
 *
 * Revision 1.16  2002/06/14 20:41:19  mp292
 * Parameter checking error - thanks Roger.
 *
 * Revision 1.15  2002/04/02 14:27:11  badbytes
 * Final finishes.
 *
 * Revision 1.14  2002/04/02 10:19:37  badbytes
 * Stricter parameter checking.
 *
 * Revision 1.13  2002/03/12 23:30:19  mp292
 * Removed some memory overruns.
 *
 * Revision 1.12  2002/03/03 00:06:45  mp292
 * Modifications to support re-transmission.
 *
 * Revision 1.11  2002/02/03 22:41:45  mp292
 * Changes to cell size.
 *
 * Revision 1.10  2002/01/21 20:57:19  mp292
 * Reviewed according to Secure-Programs-HOWTO.
 *
 * Revision 1.9  2002/01/17 15:00:43  mp292
 * Fixed a bug which caused malloc() generate a seg fault.
 *
 * Revision 1.8  2002/01/16 23:01:54  mp292
 * First phase of system testing completed (main functionality).
 *
 * Revision 1.7  2002/01/14 13:05:37  badbytes
 * System testing in progress.
 *
 * Revision 1.6  2002/01/10 13:15:54  badbytes
 * Fixed ACI size from 32bits to 16bits.
 *
 * Revision 1.5  2002/01/07 13:06:06  badbytes
 * cell.ACI is now cell.aci
 *
 * Revision 1.4  2002/01/07 09:26:00  badbytes
 * Added pack_create() and pack_data().
 *
 * Revision 1.3  2002/01/07 07:48:34  badbytes
 * fixed new_create_cell()
 *
 * Revision 1.2  2002/01/04 12:11:54  badbytes
 * Syntax errors fixed.
 *
 * Revision 1.1  2002/01/04 12:08:34  badbytes
 * Added functions for cell creation.
 *
 */

#include <stdlib.h>
#include <string.h>
#include <netinet/in.h>
  
#include <openssl/rand.h>

#include "cell.h"
#include "log.h"

cell_t *new_padding_cell()
{
  cell_t *c = NULL;
  int retval;
  
  c = malloc(sizeof(cell_t));
  if (!c) /* malloc() error */
    return NULL;

  retval = RAND_pseudo_bytes((unsigned char *)c,sizeof(cell_t));
  if (retval == -1) /* RAND_pseudo_bytes() error */
  {
    free((void *)c);
    return NULL;
  } /* RAND_pseudo_bytes() error */

  c->command = CELL_PADDING;
  
  return c;
}

cell_t *new_destroy_cell(uint16_t aci)
{
  cell_t *c = NULL;
  int retval;

  if (aci) /* valid ACI */
  {
    c = (cell_t *)malloc(sizeof(cell_t));
    if (!c) /* malloc error */
      return NULL;
    
    retval = RAND_pseudo_bytes((unsigned char *)c+3,sizeof(cell_t)-3);
    if (retval == -1) /* RAND_pseudo_bytes() error */
    {
      free((void *)c);
      return NULL;
    } /* RAND_pseudo_bytes() error */
    
    c->aci = aci;
    c->command = CELL_DESTROY;
    
    return c;
  } /* valid ACI */
  else /* invalid ACI */
    return NULL;
}

cell_t *new_ack_cell(uint16_t aci)
{
  cell_t *c = NULL;
  int retval;
  
  if (aci) /* valid ACI */
  {
    c = (cell_t *)malloc(sizeof(cell_t));
    if (!c) /* malloc error */
      return NULL;
    
    retval = RAND_pseudo_bytes((unsigned char *)c+3,sizeof(cell_t)-3);
    if (retval == -1) /* RAND_pseudo_bytes() error */
    {
      free((void *)c);
      return NULL;
    } /* RAND_pseudo_bytes() error */
    
    c->aci = aci;
    c->command = CELL_ACK;
    
    return c;
  } /* valid ACI */
  else /* invalid ACI */
    return NULL;
}

cell_t *new_nack_cell(uint16_t aci)
{
  cell_t *c = NULL;
  int retval;
  
  if (aci) /* valid ACI */
  {
    c = (cell_t *)malloc(sizeof(cell_t));
    if (!c) /* malloc error */
      return NULL;
    
    retval = RAND_pseudo_bytes((unsigned char *)c+3,sizeof(cell_t)-3);
    if (retval == -1) /* RAND_pseudo_bytes() error */
    {
      free((void *)c);
      return NULL;
    } /* RAND_pseudo_bytes() error */
    
    c->aci = aci;
    c->command = CELL_NACK;
    
    return c;
  } /* valid ACI */
  else /* invalid ACI */
    return NULL;
}

cell_t *new_create_cell(uint16_t aci, unsigned char length, unsigned char *buf)
{
  cell_t *c = NULL;
  int retval;

  if ((aci) && (buf) && (length <= CELL_PAYLOAD_SIZE)) /* valid parameters */
  {
    c = (cell_t *)malloc(sizeof(cell_t));
    if (!c) /* malloc() error */
      return NULL;
    
    c->command = CELL_CREATE;
    c->aci = aci;
    c->length = length;
    c->seq = 0;
    
    memcpy((void *)c->payload, (void *)buf, length);
    retval = RAND_pseudo_bytes((unsigned char *)(c->payload+length),CELL_PAYLOAD_SIZE-length);
    if (retval == -1) /* RAND_pseudo_bytes() error */
    {
      free((void *)c);
      return NULL;
    } /* RAND_pseudo_bytes() error */
    
    return c;
  } /* valid parameters */
  else /* invalid parameters */
    return NULL;
}


cell_t *new_data_cell(uint16_t aci, unsigned char length, unsigned char *buf)
{
  cell_t *c = NULL;
  int retval;

  if ((aci) && (buf) && (length <= CELL_PAYLOAD_SIZE)) /* valid parameters */
  {
    c = malloc(sizeof(cell_t));
    if (!c) /* malloc() error */
      return NULL;
    
    c->command = CELL_DATA;
    c->aci = aci;
    c->length = length;
    c->seq = 0;
    
    memcpy((void *)c->payload, (void *)buf, length);
    retval = RAND_pseudo_bytes((unsigned char *)(c->payload+length),CELL_PAYLOAD_SIZE-length);
    if (retval == -1) /* RAND_pseudo_bytes() error */
    {
      free((void *)c);
      return NULL;
    } /* RAND_pseudo_bytes() error */
    
    return c;
  } /* valid parameters */
  else /* invalid parameters */
    return NULL;
}

int pack_create(uint16_t aci, unsigned char *onion, uint32_t onionlen, unsigned char **cellbuf, unsigned int *cellbuflen)
{
  cell_t *c;
  unsigned char *buf;
  unsigned int buflen;
  unsigned int cells;
  unsigned int dataleft;
  unsigned int i;
  
  if ((aci) && (onion) && (cellbuf) && (cellbuflen) && (onionlen)) /* valid parameters */
  {
    /* copy the onion into a buffer, prepend with onion length */
    buflen = onionlen+4;
    buf = (unsigned char *)malloc(buflen);
    if (!buf) /* malloc() error */
      return -1;
  
    log(LOG_DEBUG,"pack_create() : Setting onion length to %u.",onionlen);
    onionlen=htonl(onionlen);
    memcpy((void *)buf,(void *)&onionlen,4);
    onionlen=ntohl(onionlen);
    memcpy((void *)(buf+4),(void *)onion,onionlen);
  
    /* calculate number of cells required */
    if (buflen%CELL_PAYLOAD_SIZE == 0)
      cells = buflen/CELL_PAYLOAD_SIZE;
    else
      cells = buflen/CELL_PAYLOAD_SIZE+1;
  
    /* allocate memory for the cells */
    *cellbuflen = cells * sizeof(cell_t);
    *cellbuf = malloc(*cellbuflen);
    if (!*cellbuf) /* malloc() error */
      return -1;
    
    log(LOG_DEBUG,"pack_create() : Allocated memory for %u cells.",cells);
  
    /* create cells one by one */
    dataleft = buflen;
    for(i=0; i<cells; i++)
    {
      log(LOG_DEBUG,"pack_create() : Packing %u bytes of data.",dataleft);
      if (dataleft >= CELL_PAYLOAD_SIZE)
      {
	c = new_create_cell(aci,CELL_PAYLOAD_SIZE,buf+i*CELL_PAYLOAD_SIZE);
	dataleft -= CELL_PAYLOAD_SIZE;
      }
      else
	c = new_create_cell(aci,dataleft,buf+i*CELL_PAYLOAD_SIZE);
      
      if (!c) /* cell creation failed */
      {
	free((void *)*cellbuf);
	return -1;
      } /* cell creation failed */
      
      log(LOG_DEBUG,"pack_create() : new_create_cell succeeded; copying the cell into output buffer");
      /* cell has been created, now copy into buffer */
      memcpy((void *)(*cellbuf+i*sizeof(cell_t)),(void *)c,sizeof(cell_t));
      free((void *)c);
    }
  
    free(buf);
    return 0;
  } /* valid parameters */
  else /* invalid parameters */
    return -1;
}

int pack_data(uint16_t aci,unsigned char *buf, size_t buflen, unsigned char **cellbuf, unsigned int *cellbuflen)
{
  cell_t *c;
  unsigned int cells;
  unsigned int dataleft;
  unsigned int i;
  
  if ((aci) && (buf) && (cellbuf) && (cellbuflen) && (buflen)) /* valid parameters */
  {
    /* calculate number of cells required */
    if (buflen%CELL_PAYLOAD_SIZE == 0)
      cells = buflen/CELL_PAYLOAD_SIZE;
    else
      cells = buflen/CELL_PAYLOAD_SIZE+1;
  
    /* allocate memory for the cells */
    *cellbuf = malloc(cells * sizeof(cell_t));
    if (!*cellbuf) /* malloc() error */
      return -1;

    log(LOG_DEBUG,"pack_data() : Allocated memory for %u cells.",cells);
    /* create cells one by one */
    dataleft = buflen;
    for(i=0; i<cells; i++)
    {
      log(LOG_DEBUG,"pack_data() : Packing %u bytes of data.",dataleft);
      if (dataleft >= CELL_PAYLOAD_SIZE)
      {
	c = new_data_cell(aci,CELL_PAYLOAD_SIZE,buf+i*CELL_PAYLOAD_SIZE);
	dataleft -= CELL_PAYLOAD_SIZE;
      }
      else
	c = new_data_cell(aci,dataleft,buf+i*CELL_PAYLOAD_SIZE);

      if (!c) /* cell creation failed */
      {
	free((void *)*cellbuf);
	return -1;
      } /* cell creation failed */
      
      /* cell has been created, now copy into buffer */
      memcpy((void *)(*cellbuf+i*sizeof(cell_t)),(void *)c,sizeof(cell_t));
      free((void *)c);
    }
  
    *cellbuflen = cells * sizeof(cell_t);
    return 0;
  } /* valid parameters */
  else /* invalid parameters */
    return -1;
}

src/common/cell.h

deleted100644 → 0
+0 −99
Changes for src/common/cell.h: 0 added lines, 99 removed lines.
Original line number Diff line number Diff line
/**
 * cell.h 
 * Cell definition.
 *
 * Matej Pfajfar <mp292@cam.ac.uk>
 */

/*
 * Changes :
 * $Log$
 * Revision 1.2  2002/07/18 06:38:32  arma
 * changes to support sendme cells
 *
 * Revision 1.1.1.1  2002/06/26 22:45:50  arma
 * initial commit: current code
 *
 * Revision 1.14  2002/04/02 14:27:11  badbytes
 * Final finishes.
 *
 * Revision 1.13  2002/03/03 00:06:45  mp292
 * Modifications to support re-transmission.
 *
 * Revision 1.12  2002/02/09 17:51:52  mp292
 * CELL_ACK should be 4 not 3
 *
 * Revision 1.11  2002/02/03 22:41:45  mp292
 * Changes to cell size.
 *
 * Revision 1.10  2002/01/21 20:57:19  mp292
 * Reviewed according to Secure-Programs-HOWTO.
 *
 * Revision 1.9  2002/01/17 15:00:43  mp292
 * Fixed a bug which caused malloc() generate a seg fault.
 *
 * Revision 1.8  2002/01/14 13:05:37  badbytes
 * System testing in progress.
 *
 * Revision 1.7  2002/01/10 13:15:54  badbytes
 * Fixed ACI size from 32bits to 16bits.
 *
 * Revision 1.6  2002/01/09 08:10:32  badbytes
 * *** empty log message ***
 *
 * Revision 1.5  2002/01/07 13:03:28  badbytes
 * cell.ACI is now cell.aci
 *
 * Revision 1.4  2002/01/07 09:26:00  badbytes
 * Added pack_create() and pack_data().
 *
 * Revision 1.3  2002/01/07 07:48:34  badbytes
 * fixed new_create_cell()
 *
 * Revision 1.2  2002/01/04 12:08:34  badbytes
 * Added functions for cell creation.
 *
 * Revision 1.1  2002/01/04 10:02:07  badbytes
 * Added cell definition.
 *
 */

#ifndef __CELL_H

#include <unistd.h>
#include <stdint.h>

/* cell commands */
#define CELL_PADDING 0
#define CELL_CREATE 1
#define CELL_DATA 2
#define CELL_DESTROY 3
#define CELL_ACK 4
#define CELL_NACK 5
#define CELL_SENDME 6

#define CELL_PAYLOAD_SIZE 120

/* cell definition */
typedef struct 
{
  uint16_t aci; /* Anonymous Connection Identifier */
  unsigned char command;
  unsigned char length; /* of payload if data cell, else value of sendme */
  uint32_t seq; /* sequence number */
  unsigned char payload[120];
} cell_t;

cell_t *new_padding_cell(void);
cell_t *new_create_cell(uint16_t aci, unsigned char length, unsigned char *buf);
cell_t *new_destroy_cell(uint16_t aci);
cell_t *new_data_cell(uint16_t aci, unsigned char length, unsigned char *buf);
cell_t *new_ack_cell(uint16_t aci);
cell_t *new_nack_cell(uint16_t aci);

int pack_create(uint16_t aci, unsigned char *onion, uint32_t onionlen, unsigned char **cellbuf, unsigned int *cellbuflen);
int pack_data(uint16_t aci, unsigned char *buf, size_t buflen, unsigned char **cellbuf, unsigned int *cellbuflen);

#define __CELL_H
#endif

src/common/opcell.c

deleted100644 → 0
+0 −77
Changes for src/common/opcell.c: 0 added lines, 77 removed lines.
Original line number Diff line number Diff line
/**
 * opcell.c
 * Onion Proxy Cell
 *
 * Matej Pfajfar <mp292@cam.ac.uk>
 */

/*
 * Changes :
 * $Log$
 * Revision 1.1  2002/06/26 22:45:50  arma
 * Initial revision
 *
 * Revision 1.1  2002/03/03 12:08:18  mp292
 * Added a new type of cell - used for data going between the onion proxy and
 * the first or hop. Payload size identical to that of a normal cell.
 *
 */

#include <stdlib.h>
#include <string.h>
#include <netinet/in.h>
  
#include <openssl/rand.h>

#include "opcell.h"
#include "log.h"

opcell_t *new_padding_opcell()
{
  opcell_t *c = NULL;
  int retval;
  
  c = malloc(sizeof(opcell_t));
  if (!c) /* malloc() error */
    return NULL;

  retval = RAND_pseudo_bytes((unsigned char *)c,sizeof(opcell_t));
  if (retval == -1) /* RAND_pseudo_bytes() error */
  {
    free((void *)c);
    return NULL;
  } /* RAND_pseudo_bytes() error */

  c->command = OPCELL_PADDING;
  
  return c;
}

opcell_t *new_data_opcell(unsigned char length, unsigned char *buf)
{
  opcell_t *c = NULL;
  int retval;

  if ((length <= OPCELL_PAYLOAD_SIZE) && (buf)) /* valid parameters */
  {
    c = malloc(sizeof(opcell_t));
    if (!c) /* malloc() error */
      return NULL;
    
    c->command = OPCELL_DATA;
    c->length = length;
    
    memcpy((void *)c->payload, (void *)buf, length);
    retval = RAND_pseudo_bytes((unsigned char *)(c->payload+length),OPCELL_PAYLOAD_SIZE-length);
    if (retval == -1) /* RAND_pseudo_bytes() error */
    {
      free((void *)c);
      return NULL;
    } /* RAND_pseudo_bytes() error */
    
    return c;
  } /* valid parameters */
  else /* invalid parameters */
    return NULL;
}

src/common/opcell.h

deleted100644 → 0
+0 −44
Changes for src/common/opcell.h: 0 added lines, 44 removed lines.
Original line number Diff line number Diff line
/**
 * opcell.h 
 * Onion Proxy Cell.
 *
 * Matej Pfajfar <mp292@cam.ac.uk>
 */

/*
 * Changes :
 * $Log$
 * Revision 1.1  2002/06/26 22:45:50  arma
 * Initial revision
 *
 * Revision 1.1  2002/03/03 12:08:18  mp292
 * Added a new type of cell - used for data going between the onion proxy and
 * the first or hop. Payload size identical to that of a normal cell.
 *
 */

#ifndef __OPCELL_H

#include <stdint.h>

#include "cell.h"

#define OPCELL_PAYLOAD_SIZE CELL_PAYLOAD_SIZE

#define OPCELL_PADDING 0
#define OPCELL_DATA 1

/* cell definition */
typedef struct 
{
  unsigned char command;
  unsigned char length; /* of payload */
  unsigned char payload[OPCELL_PAYLOAD_SIZE];
} opcell_t;

opcell_t *new_data_opcell(unsigned char length, unsigned char *buf);
opcell_t *new_padding_opcell();

#define __OPCELL_H
#endif
Loading