Commit b04eb460 authored by Niels Möller's avatar Niels Möller
Browse files

Random hacking

Rev: src/blocking_write.c:1.2
Rev: src/debug.c:1.4
Rev: src/debug.h:1.3
Rev: src/decrypt.c:1.4
Rev: src/decrypt.h:1.3
Rev: src/encrypt.c:1.4
Rev: src/encrypt.h:1.3
Rev: src/format.h:1.3
Rev: src/lsh_types.h:1.2
Rev: src/packet_dispatch.c:1.3
Rev: src/pad.c:1.5
Rev: src/pad.h:1.4
Rev: src/transport.c:1.3
Rev: src/transport.h:1.5
Rev: src/unpad.c:1.3
Rev: src/unpad.h:1.4
Rev: src/void.c:1.3
Rev: src/zlib.c:1.3
Rev: src/zlib.h:1.2
parent b49e4d3c
......@@ -7,7 +7,7 @@
#endif
static int do_write(struct pad_processor *closure,
struct simple_packet *packet)
struct lsh_string *packet)
{
UINT32 left = packet->length;
UINT8 *p = packet->data;
......@@ -27,19 +27,19 @@ static int do_write(struct pad_processor *closure,
p += written;
}
simple_packet_free(packet);
lsh_string_free(packet);
return 1;
}
struct packet_processor *make_blocking_write_procesor(int fd)
struct abstract_write *make_blocking_write_procesor(int fd)
{
struct blocking_write_processor *closure
= xalloc(sizeof(struct blocking_write_processor_processor));
closure->p->f = (raw_processor_function) do_write;
closure->p->f = (abstract_write_f) do_write;
closure->fd = fd;
return (struct packet_processor *) closure;
return (struct abstract_write *) closure;
}
......@@ -6,7 +6,7 @@
#include "xalloc.h"
static int do_debug(struct debug_processor *closure,
struct simple_packet *packet)
struct lsh_string *packet)
{
UINT32 i;
......@@ -26,16 +26,16 @@ static int do_debug(struct debug_processor *closure,
return apply_processor(closure->c.next, packet);
}
struct packet_processor *make_debug_processor(FILE *output,
struct packet_processor *continuation)
struct abstract_write *make_debug_processor(FILE *output,
struct abstract_write *continuation)
{
struct debug_processor *closure = xalloc(sizeof(struct debug_processor));
closure->c.p.f = (raw_processor_function) do_debug;
closure->c.p.f = (abstract_write_f) do_debug;
closure->c.next = continuation;
closure->output = output;
return (struct packet_processor *) closure;
return (struct abstract_write *) closure;
}
......@@ -11,7 +11,7 @@
struct debug_processor
{
struct chained_processor c;
struct abstract_write_pipe c;
FILE *output;
};
......
......@@ -14,7 +14,7 @@
#define MAX(a, b) ( ((a)>(b)) ? (a) : (b) )
static int do_decrypt(struct decrypt_processor *closure,
struct simple_packet *packet)
struct lsh_string *packet)
{
/* Number of octets n the input packet that have been processed */
UINT32 pos = 0;
......@@ -58,7 +58,7 @@ static int do_decrypt(struct decrypt_processor *closure,
* already decrypted, block contains some of the
* decypted payload. */
closure->recieved
= simple_packet_alloc(length
= lsh_string_alloc(length
- (closure->block_size - 4));
closure->pos = 0;
......@@ -88,8 +88,8 @@ static int do_decrypt(struct decrypt_processor *closure,
UINT32 left_overs = closure->block_size - 4;
/* Full packet (including left-overs from the first block) */
struct simple_packet *new
= simple_packet_alloc(closure->recieved->length
struct lsh_string *new
= lsh_string_alloc(closure->recieved->length
+ left_overs);
memcpy(new->data, closure->block_buffer + 4,
......@@ -100,7 +100,7 @@ static int do_decrypt(struct decrypt_processor *closure,
closure->recieved->data,
new->data + left_overs);
simple_packet_free(closure->recieved);
lsh_string_free(closure->recieved);
closure->recieved = new;
if (closure->mac_size)
......@@ -156,8 +156,8 @@ static int do_decrypt(struct decrypt_processor *closure,
return 1;
}
struct packet_processor *
make_decrypt_processor(struct packet_processor *continuation,
struct abstract_write *
make_decrypt_processor(struct abstract_write *continuation,
UINT32 max_packet,
unsigned mac_size,
transform_function mac_function,
......@@ -169,7 +169,7 @@ make_decrypt_processor(struct packet_processor *continuation,
struct decrypt_processor *closure = xalloc(sizeof(struct decrypt_processor)
+ MAX(block_size, mac_size) - 1);
closure->c.p.f = (raw_processor_function) do_decrypt;
closure->c.p.f = (abstract_write_f) do_decrypt;
closure->c.next = continuation;
/* state */
......@@ -186,5 +186,5 @@ make_decrypt_processor(struct packet_processor *continuation,
closure->decrypt_function = decrypt_function;
closure->decrypt_state = decrypt_state;
return (struct packet_processor *) closure;
return (struct abstract_write *) closure;
}
......@@ -14,14 +14,14 @@
* processor, as soon as a complete packet has been read. */
struct decrypt_processor
{
struct chained_processor c;
struct abstract_write_pipe c;
int state;
UINT32 pos;
UINT32 max_packet;
struct simple_packet *recieved;
struct lsh_string *recieved;
unsigned mac_size;
......
......@@ -8,8 +8,9 @@
static int do_encrypt(struct encrypt_processor *closure,
struct simple_packet *packet)
{
/* FIXME: Use ssh_format() */
struct simple_packet *new
= simple_packet_alloc(packet->length + closure->mac_size);
= lsh_string_alloc(packet->length + closure->mac_size);
closure->encrypt_function(closure->encrypt_state,
packet->length,
......@@ -20,7 +21,7 @@ static int do_encrypt(struct encrypt_processor *closure,
packet->length,
packet->data, new->data + packet->length);
simple_packet_free(packet);
lsh_string_free(packet);
return apply_processor(closure->c.next, new);
}
......@@ -35,7 +36,7 @@ make_encrypt_processor(struct packet_processor *continuation,
{
struct encrypt_processor *closure = xalloc(sizeof(struct encrypt_processor));
closure->c.p.f = (raw_processor_function) do_encrypt;
closure->c.p.f = (abstract_write_f) do_encrypt;
closure->c.next = continuation;
closure->mac_size = mac_size;
closure->mac_function = mac_function;
......
......@@ -11,7 +11,7 @@
struct encrypt_processor
{
struct chained_processor c;
struct abstract_write_pipe c;
unsigned mac_size;
......
......@@ -36,6 +36,6 @@
UINT32 ssh_vformat_length(char *format, va_list args);
void ssh_vformat(char *format, UINT8 *buffer, va_list args);
struct simple_packet *ssh_format(char *format, ...);
struct lsh_string *ssh_format(char *format, ...);
#endif /* LSH_FORMAT_H_INCLUDED */
......@@ -20,4 +20,22 @@
#define UINT8 unsigned char
/* Generic packet */
struct lsh_string
{
UINT32 sequence_number;
UINT32 length;
UINT8 data[1];
};
/* A closed function with no arguments */
struct callback;
typedef int (*callback_f)(struct callback *closure);
struct callback
{
callback_f f;
};
#define CALLBACK(c) ((c)->f(c))
#endif /* LSH_TYPS_H_INCLUDED */
......@@ -7,7 +7,7 @@
#include "werror.h"
static int do_dispatch(struct dispatch_processor *closure,
struct simple_packet *packet)
struct lsh_string *packet)
{
unsigned start;
unsigned end;
......@@ -50,10 +50,10 @@ static int do_dispatch(struct dispatch_processor *closure,
return 0;
}
struct packet_processor *
struct abstract_write *
make_dispatch_processor(unsigned size,
struct dispatch_assoc *table,
struct packet_processor *other)
struct abstract_write *other)
{
struct dispatch_processor *closure
= xalloc(sizeof(struct dispatch_processor));
......@@ -64,12 +64,12 @@ make_dispatch_processor(unsigned size,
if (table[i].msg >= table[i+1].msg)
fatal("make_dispatch_processor: Table out of order");
closure->p.f = (raw_processor_function) do_dispatch;
closure->p.f = (abstract_write_f) do_dispatch;
closure->other = other;
closure->table_size = size;
closure->dispatch_table = table;
return (struct packet_processor *) closure;
return (struct abstract_write *) closure;
}
......
......@@ -7,12 +7,12 @@
#include <assert.h>
static int do_pad(struct pad_processor *closure,
struct simple_packet *packet)
struct lsh_string *packet)
{
UINT32 new_size;
UINT8 padding;
struct simple_packet *new;
struct lsh_string *new;
#if 0
struct ssh_packet *ssh;
......@@ -23,8 +23,9 @@ static int do_pad(struct pad_processor *closure,
padding = new_size - packet->length - 5;
assert(padding >= 4);
new = simple_packet_alloc(new_size);
/* FIXME: Use ssh_format() */
new = lsh_string_alloc(new_size);
#if 0
ssh = (struct ssh_packet *) new->data;
......@@ -38,25 +39,25 @@ static int do_pad(struct pad_processor *closure,
memcpy(new->data + 5, packet->data, packet->length);
closure->random(closure->state, padding, new->data + 5 + packet->length);
simple_packet_free(packet);
lsh_string_free(packet);
return apply_processor(closure->c.next, new);
}
struct packet_processor *
make_pad_processor(struct packet_processor *continuation,
struct abstract_write *
make_pad_processor(struct abstract_write *continuation,
unsigned block_size,
random_function random,
void *state)
{
struct pad_processor *closure = xalloc(sizeof(struct pad_processor));
closure->c.p.f = (raw_processor_function) do_pad;
closure->c.p.f = (abstract_write_f) do_pad;
closure->c.next = continuation;
closure->block_size = block_size;
closure->random = random;
closure->state = state;
return (struct packet_processor *) closure;
return (struct abstract_write *) closure;
}
......@@ -15,7 +15,7 @@ typedef void (*random_function)(void *state, UINT32 length, UINT8 *dst);
* etc). */
struct pad_processor
{
struct chained_processor c;
struct abstract_write_pipe c;
unsigned block_size; /* At least 8, even for stream ciphers */
......@@ -35,7 +35,7 @@ make_pad_processor(struct packet_processor *continuation,
* etc). No padding is done. */
struct format_processor
{
struct chained_processor c;
struct abstract_write_pipe c;
};
struct packet_processor *make_pad_processor(packet_processor *continuation);
......
......@@ -5,15 +5,15 @@
#include "transport.h"
#include "xalloc.h"
struct simple_packet *simple_packet_alloc(UINT32 length)
struct lsh_string *lsh_string_alloc(UINT32 length)
{
struct simple_packet *packet
= xalloc(sizeof(struct simple_packet) - 1 + length);
struct lsh_string *packet
= xalloc(sizeof(struct lsh_string) - 1 + length);
packet->length = length;
return packet;
}
void simple_packet_free(struct simple_packet *packet)
void lsh_string_free(struct lsh_string *packet)
{
free(packet);
}
......@@ -43,8 +43,8 @@ UINT32 simple_buffer_avail(struct simple_buffer *buffer)
}
#endif
int apply_processor(struct packet_processor *closure,
struct simple_packet *packet)
int apply_processor(struct abstract_write *closure,
struct lsh_string *packet)
{
return closure->f(closure, packet);
}
......@@ -23,13 +23,6 @@ do { \
(p)[0] = (i) & 0xff; \
} while(0)
/* Generic packet */
struct simple_packet
{
UINT32 length;
UINT8 data[1];
};
#if 0
struct ssh_packet
{
......@@ -57,9 +50,10 @@ struct ssh_packet
/* Size is the maximum amount of payload + padding that will be stored
* in the packet. */
struct simple_packet *simple_packet_alloc(UINT32 size);
void simple_packet_free(struct simple_packet *packet);
struct lsh_string *lsh_string_alloc(UINT32 size);
void lsh_string_free(struct lsh_string *packet);
#if 0
/* A packet processing function.
*
* Typically, real processors will extend this struct, with fields
......@@ -72,23 +66,25 @@ struct packet_processor; /* Forward declaration */
* (implying immediate shutdown of (this direction of) a connection.
* Otherwise returns 1. */
typedef int (*raw_processor_function)(struct packet_processor *context,
struct simple_packet *packet);
struct lsh_string *packet);
struct packet_processor
{
raw_processor_function f;
};
int apply_processor(struct packet_processor *closure,
struct simple_packet *packet);
struct lsh_string *packet);
#endif
/* A processor that passes its result on to another processor */
struct chained_processor
struct abstract_write_pipe
{
struct packet_processor p;
struct packet_processor *next;
struct abstract_write p;
struct abstract_write *next;
};
#if 0
/* error codes, returned from packet processors. zero means ok,
* negative means a fatal protocol failure, and positive values are
* errors that should be reported to the otrher end. */
......@@ -96,5 +92,6 @@ struct chained_processor
#define LSH_ERR_TOO_LARGE_PACKET -1
#define LSH_ERR_BAD_LENGTH -2
#define LSH_ERR_BAD_MAC -3
#endif
#endif /* LSH_TRANSPORT_H_INCLUDED */
......@@ -6,11 +6,11 @@
#include "xalloc.h"
static int do_unpad(struct unpad_processor *closure,
struct simple_packet *packet)
struct lsh_string *packet)
{
UINT8 padding_length;
UINT32 payload_length;
struct simple_packet *new;
struct lsh_string *new;
if (packet->length < 1)
return 0;
......@@ -23,11 +23,12 @@ static int do_unpad(struct unpad_processor *closure,
payload_length = packet->length - 1 - padding_length;
new = simple_packet_alloc(payload_length);
/* FIXME: Use ssh_format() */
new = lsh_string_alloc(payload_length);
memcpy(new->data, packet->data + 1, payload_length);
simple_packet_free(packet);
lsh_string_free(packet);
return apply_processor(closure->c.next, new);
}
......@@ -37,7 +38,7 @@ make_unpad_processor(struct packet_processor *continuation)
{
struct unpad_processor *closure = xalloc(sizeof(struct unpad_processor));
closure->c.p.f = (raw_processor_function) do_unpad;
closure->c.p.f = (abstract_write_f) do_unpad;
closure->c.next = continuation;
return (struct packet_processor *) closure;
......
......@@ -11,7 +11,7 @@
/* Input to the processor is a padded payload. */
struct unpad_processor
{
struct chained_processor c;
struct abstract_write_pipe c;
};
struct packet_processor *
......
......@@ -6,9 +6,9 @@
#include "xalloc.h"
static int do_ignore(struct void_processor *closure,
struct simple_packet *packet)
struct lsh_string *packet)
{
free(packet);
lsh_string_free(packet);
return 1;
}
......@@ -16,7 +16,7 @@ struct packet_processor *make_void_processor()
{
struct void_processor *closure = xalloc(sizeof(struct void_processor));
closure->p.f = (raw_processor_function) do_ignore;
closure->p.f = (abstract_write_f) do_ignore;
return (struct packet_processor *) closure;
}
......@@ -6,14 +6,14 @@
#define
static int do_deflate(struct zlib_processor *closure,
struct simple_packet *packet)
struct lsh_string *packet)
{
struct simple_packet *new;
struct lsh_string *new;
/* call deflate, copy into new packet */
new = simple_packet_alloc(...);
simple_packet_free(packet);
new = lsh_string_alloc(...);
lsh_string_free(packet);
return apply_processor(closure->c->next, new);
}
......@@ -23,7 +23,7 @@ struct packet_processor *make_zlib_processor(packet_processor *continuation,
{
struct debug_processor *closure = xalloc(sizeof(struct zlib_processor));
closure->c->p->f = (raw_processor_function) do_deflate;
closure->c->p->f = (abstract_write_f) do_deflate;
closure->c->next = continuation;
/* inititialize closure->zstream */
......
......@@ -9,7 +9,7 @@
/* The input to the compressor should be a packet with payload only. */
struct zlib_processor
{
struct chained_processor c;
struct abstract_write_pipe c;
z_stream state;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment