aboutsummaryrefslogtreecommitdiff
path: root/src/common/opcell.c
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2002-06-26 22:45:49 +0000
committerRoger Dingledine <arma@torproject.org>2002-06-26 22:45:49 +0000
commit9a928eeb1215f0d7c9b6d0bb9e4571d0a16ed79a (patch)
treefac560bf2dce8a8d2b82e296b71ff24f59ab1a7a /src/common/opcell.c
parent766a465a6043ac4e643c398feb14f708fd0d863f (diff)
downloadtor-9a928eeb1215f0d7c9b6d0bb9e4571d0a16ed79a.tar
tor-9a928eeb1215f0d7c9b6d0bb9e4571d0a16ed79a.tar.gz
Initial revision
svn:r2
Diffstat (limited to 'src/common/opcell.c')
-rw-r--r--src/common/opcell.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/common/opcell.c b/src/common/opcell.c
new file mode 100644
index 000000000..288a355ce
--- /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;
+}
+