diff options
Diffstat (limited to 'src/common/opcell.c')
-rw-r--r-- | src/common/opcell.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/common/opcell.c b/src/common/opcell.c new file mode 100644 index 0000000000..288a355ce8 --- /dev/null +++ b/src/common/opcell.c @@ -0,0 +1,77 @@ +/** + * 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; +} + |