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

Fixed some compilation errors.

Rev: src/Makefile.in:1.3
Rev: src/bignum.c:1.2
Rev: src/bignum.h:1.2
Rev: src/debug.c:1.3
Rev: src/debug.h:1.2
Rev: src/decrypt.c:1.3
Rev: src/decrypt.h:1.2
Rev: src/encrypt.c:1.3
Rev: src/encrypt.h:1.2
Rev: src/format.c:1.3
Rev: src/format.h:1.2
Rev: src/packet_dispatch.c:1.2
Rev: src/packet_dispatch.h:1.2
Rev: src/pad.h:1.2
Rev: src/parse.c:1.3
Rev: src/parse.h:1.3
Rev: src/process_atoms:1.3
Rev: src/transport.h:1.4
Rev: src/unpad.h:1.2
parent 597f20c9
#### Start of system configuration section. ####
srcdir = @srcdir@
VPATH = $(srcdir)
CC = @CC@
SCHEME = @SCHEME@
@SET_MAKE@
# INSTALL = @INSTALL@
# INSTALL_PROGRAM = @INSTALL_PROGRAM@
# INSTALL_DATA = @INSTALL_DATA@
# MAKEINFO = makeinfo
# TEXI2DVI = texi2dvi
DEFS = @DEFS@
LIBS = @LIBS@
CFLAGS = -g -Wall # -O2 -fomit-frame-pointer
LDFLAGS = -g
CPPFLAGS =
prefix = @prefix@
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
infodir = $(prefix)/info
# Prefix to be prepended to each installed program, normally empty or `g'.
binprefix =
#### End of system configuration section. ####
SRCS = atoms.c bignum.c debug.c decrypt.c encrypt.c format.c packet_dispatch.c \
pad.c parse.c server_keyexchange.c transport.c unpad.c void.c werror.c \
xalloc.c
OBJS = $(SRCS:.c=.o)
all: $(OBJS)
.PHONY: all
.c.o:
$(CC) -c $(CPPFLAGS) $(DEFS) $(CFLAGS) $<
atoms_defines.h: atoms.in process_atoms
bash process_atoms header <atoms.in >atoms_defines.h
atoms_gperf.c: atoms.in process_atoms
bash process_atoms gperf <atoms.in |gperf -t -k1,7,$$ >atoms_gperf.c
bash process_atoms gperf <atoms.in |gperf -t -k1,7,$$ -N gperf_atom >atoms_gperf.c
atoms_table.c: atoms.in process_atoms
bash process_atoms table <atoms.in >atoms_table.c
clean:
rm -f *.o
very_clean: clean
rm *.d
%.d: %.c
$(SHELL) -ec '$(CC) -MM $(CPPFLAGS) $(DEFS) $< \
| sed '\''s/\($*\)\.o:/\1\.o $@ : /g'\'' > $@'
include $(SRCS:.c=.d)
#### Remaking the Makefile and configure scripts. ####
#${srcdir}/configure: configure.in aclocal.m4
${srcdir}/configure: configure.in
cd ${srcdir} && autoconf
# autoheader might not change config.h.in, so touch a stamp file.
${srcdir}/config.h.in: stamp-h.in
#${srcdir}/stamp-h.in: configure.in aclocal.m4 acconfig.h \
# config.h.top config.h.bot
${srcdir}/stamp-h.in: configure.in
cd ${srcdir} && autoheader
echo timestamp > ${srcdir}/stamp-h.in
config.h: stamp-h
stamp-h: config.h.in config.status
./config.status
Makefile: Makefile.in config.status
./config.status
config.status: configure
./config.status --recheck
......@@ -3,8 +3,9 @@
*/
#include "bignum.h"
#include "werror.h"
void parse_bignum(bignum n, UINT32 length, UINT8 *data)
void parse_bignum(bignum *n, UINT32 length, UINT8 *data)
{
int negative = length && (*data & 0x80);
int i;
......@@ -21,7 +22,7 @@ void parse_bignum(bignum n, UINT32 length, UINT8 *data)
if (negative)
{
mpz_set_ui(digit, 1);
mpz_mul2exp(digit, digit, length*8);
mpz_mul_2exp(digit, digit, length*8);
mpz_sub(n, n, digit);
}
mpz_clear(digit);
......@@ -45,7 +46,7 @@ int mpz_size_of_complement(mpz_t n)
}
/* This function should handle both positive and negative numbers */
UINT32 bignum_format_length(bignum n)
UINT32 bignum_format_length(bignum *n)
{
switch(mpz_sgn(n))
{
......@@ -54,18 +55,22 @@ UINT32 bignum_format_length(bignum n)
case 1:
return mpz_sizeinbase(n, 2)/8 + 1;
case -1:
return mpz_size_of_complement(mpz_t n)/8 + 1;
return mpz_size_of_complement(n)/8 + 1;
default:
fatal("Internal error");
}
}
void limbs_to_octets(n, length, UINT8 pad, UINT8 *data)
void limbs_to_octets(bignum *n, UINT32 length, UINT8 pad, UINT8 *data)
{
UINT32 *dst = data + length - 1;
UINT8 *dst = data + length - 1;
mp_limb_t *l = n->_md_d; /* Starts at the least significant limb */
int left = n->_mp_size;
mp_limb_t *l = n->_mp_d; /* Starts at the least significant limb */
int left;
while( (len > 0) && (left > 0) )
for (left = n->_mp_size;
(length > 0) && (left > 0);
left--)
{
int i;
mp_limb_t word = *l++;
......@@ -73,19 +78,19 @@ void limbs_to_octets(n, length, UINT8 pad, UINT8 *data)
{
*dst-- = word & 0xff;
word >>= 8;
len--;
if (!len)
length--;
if (!length)
break;
}
}
while (len > 0)
while (length > 0)
{
*dst-- = pad;
len--;
length--;
}
}
UINT32 bignum_format(bignum n, UINT8 *data)
UINT32 bignum_format(bignum *n, UINT8 *data)
{
switch(mpz_sgn(n))
{
......@@ -95,7 +100,7 @@ UINT32 bignum_format(bignum n, UINT8 *data)
{
int length = mpz_sizeinbase(n, 2)/8 + 1;
limbs_to_octets(n, length, 0, *data);
limbs_to_octets(n, length, 0, data);
return length;
}
case -1:
......@@ -108,16 +113,18 @@ UINT32 bignum_format(bignum n, UINT8 *data)
mpz_com(complement, n);
/* Note that mpz_sizeinbase(0) == 0.*/
length = sizeinbase(complement, 2)/8 + 1;
length = mpz_sizeinbase(complement, 2)/8 + 1;
for (i = 0; i<complement->_mp_size; i++)
complement->_mp_d[i] = ~complement->_mp_d[i];
limbs_to_octets(complement, length, 0xff, *data);
limbs_to_octets(complement, length, 0xff, data);
mpz_clear(complement);
return length;
}
default:
fatal("Internal error");
}
}
......
......@@ -7,11 +7,12 @@
#define LSH_BIGNUM_H_INCLUDED
#include <gmp.h>
#include "lsh_types.h"
#define bignum mpz_t
#define bignum MP_INT
void parse_bignum(bignum n, UINT32 length, UINT8 *data);
UINT32 bignum_format_length(bignum n);
void bignum_format(bignum n, UINT8 *data);
void parse_bignum(bignum *n, UINT32 length, UINT8 *data);
UINT32 bignum_format_length(bignum *n);
UINT32 bignum_format(bignum *n, UINT8 *data);
#endif /* LSH_BIGNUM_H_INCLUDED */
......@@ -2,13 +2,16 @@
*
*/
#include "debug.h"
#include "xalloc.h"
static int do_debug(struct debug_processor *closure,
struct simple_packet *packet)
{
UINT32 i;
fprintf(closure->output, "DEBUG: (packet size %d = 0x%x)\n",
packet->length);
packet->length, packet->length);
for(i=0; i<packet->length; i++)
{
......@@ -20,16 +23,16 @@ static int do_debug(struct debug_processor *closure,
fprintf(closure->output, "\n");
return apply_processor(closure->c->next, packet);
return apply_processor(closure->c.next, packet);
}
struct packet_processor *make_debug_processor(FILE *output,
packet_processor *continuation)
struct packet_processor *continuation)
{
struct debug_processor *closure = xalloc(sizeof(struct debug_processor));
closure->c->p->f = (raw_processor_function) do_debug;
closure->c->next = continuation;
closure->c.p.f = (raw_processor_function) do_debug;
closure->c.next = continuation;
closure->output = output;
return (struct packet_processor *) closure;
......
......@@ -7,15 +7,16 @@
#define LSH_DEBUG_H_INCLUDED
#include <stdio.h>
#include "transport.h"
struct debug_processor
{
struct chained_processor c;
FILE *output;
}
};
struct packet_processor *make_debug_processor(FILE *output,
packet_processor *continuation);
struct packet_processor *continuation);
#endif */ LSH_DEBUG_H_INCLUDED */
......@@ -2,13 +2,18 @@
*
*/
#include "decrypt.c"
#include "decrypt.h"
#include "werror.h"
#include "xalloc.h"
#define WAIT_HEADER 0
#define WAIT_CONTENTS 1
#define WAIT_MAC 2
static int do_decrypt(struct encrypt_processor *closure,
#define MIN(a, b) ( ((a)<(b)) ? (a) : (b) )
#define MAX(a, b) ( ((a)>(b)) ? (a) : (b) )
static int do_decrypt(struct decrypt_processor *closure,
struct simple_packet *packet)
{
/* Number of octets n the input packet that have been processed */
......@@ -36,10 +41,10 @@ static int do_decrypt(struct encrypt_processor *closure,
/* Decrypt the first block */
closure->decrypt_function(closure->decrypt_state,
block_size, closure->block_buffer,
closure->block_size, closure->block_buffer,
closure->block_buffer);
length = READ_INT32(closure->block_buffer);
length = READ_UINT32(closure->block_buffer);
if (length > closure->max_packet)
return 0;
......@@ -92,6 +97,7 @@ static int do_decrypt(struct encrypt_processor *closure,
closure->decrypt_function(closure->decrypt_state,
closure->recieved->length,
closure->recieved->data,
new->data + left_overs);
simple_packet_free(closure->recieved);
......@@ -135,7 +141,7 @@ static int do_decrypt(struct encrypt_processor *closure,
}
/* MAC was ok, pass packet on */
if (!apply_continuation(closure->next, closure->recieved))
if (!apply_processor(closure->c.next, closure->recieved))
return 0;
closure->recieved = NULL;
......@@ -151,20 +157,20 @@ static int do_decrypt(struct encrypt_processor *closure,
}
struct packet_processor *
make_encrypt_processor(struct packet_processor *continuation,
make_decrypt_processor(struct packet_processor *continuation,
UINT32 max_packet,
unsigned mac_size,
transform_function mac_function,
void *mac_state,
unsigned block_size,
transform_function encrypt_function,
void *encrypt_state)
transform_function decrypt_function,
void *decrypt_state)
{
struct pad_processor *closure = xalloc(sizeof(struct pad_processor)
struct decrypt_processor *closure = xalloc(sizeof(struct decrypt_processor)
+ MAX(block_size, mac_size) - 1);
closure->c->p->f = (raw_processor_function) do_encrypt;
closure->c->next = continuation;
closure->c.p.f = (raw_processor_function) do_decrypt;
closure->c.next = continuation;
/* state */
closure->state = WAIT_HEADER;
......@@ -177,8 +183,8 @@ make_encrypt_processor(struct packet_processor *continuation,
closure->mac_function = mac_function;
closure->mac_state = mac_state;
closure->block_size = block_size;
closure->encrypt_function = encrypt_function;
closure->encrypt_state = encrypt_state;
closure->decrypt_function = decrypt_function;
closure->decrypt_state = decrypt_state;
return (struct packet_processor *) closure;
}
......@@ -5,6 +5,9 @@
#ifndef LSH_DECRYPT_H_INCLUDED
#define LSH_DECRYPT_H_INCLUDED
#include "transport.h"
#include "crypto_common.h"
/* The input packets to this processor are arbitrary octet strings,
* for instance as returned by read(). The data is collected,
* decrypted, and the (padded) payload is passed on to the next packet
......
......@@ -3,6 +3,7 @@
*/
#include "encrypt.h"
#include "xalloc.h"
static int do_encrypt(struct encrypt_processor *closure,
struct simple_packet *packet)
......@@ -11,29 +12,31 @@ static int do_encrypt(struct encrypt_processor *closure,
= simple_packet_alloc(packet->length + closure->mac_size);
closure->encrypt_function(closure->encrypt_state,
packet->data, new->data, packet->length);
packet->length,
packet->data, new->data);
if (closure->mac_size)
closure->mac_function(closure->mac_state,
packet->length,
packet->data, new->data + packet->length);
simple_packet_free(packet);
return apply_processor(closure->c->next, new);
return apply_processor(closure->c.next, new);
}
struct packet_processor *
make_encrypt_processor(struct packet_processor *containing,
make_encrypt_processor(struct packet_processor *continuation,
unsigned mac_size,
transform_function mac_function,
void *mac_state,
transform_function encrypt_function,
void *encrypt_state)
{
struct pad_processor *closure = xalloc(sizeof(struct pad_processor));
struct encrypt_processor *closure = xalloc(sizeof(struct encrypt_processor));
closure->c->p->f = (raw_processor_function) do_encrypt;
closure->c->next = continuation;
closure->c.p.f = (raw_processor_function) do_encrypt;
closure->c.next = continuation;
closure->mac_size = mac_size;
closure->mac_function = mac_function;
closure->mac_state = mac_state;
......
......@@ -6,11 +6,8 @@
#ifndef LSH_ENCRYPT_H_INCLUDED
#define LSH_ENCRYPT_H_INCLUDED
/* FIXME: Perhaps cryptographic algoritms should be encapsulated into
* objects, to avoid passing a lot of extra state parameters? */
typedef (*transform_function)(void *state,
UINT32 size, UINT8 *src, UINT8 *dst);
#include "transport.h"
#include "crypto_common.h"
struct encrypt_processor
{
......
......@@ -3,6 +3,10 @@
*/
#include "format.h"
#include "werror.h"
#include <assert.h>
#include <string.h>
struct simple_packet *ssh_format(char *format, ...)
{
......@@ -23,7 +27,7 @@ struct simple_packet *ssh_format(char *format, ...)
return packet;
}
UINT32 *ssh_vformat_length(char *f, va_list args)
UINT32 ssh_vformat_length(char *f, va_list args)
{
UINT32 length = 0;
......@@ -60,9 +64,9 @@ UINT32 *ssh_vformat_length(char *f, va_list args)
case 's':
{
UINT32 length += va_arg(args, UINT32); /* String length */
length += va_arg(args, UINT32); /* String length */
(void) va_arg(args, UIN8 *); /* data */
(void) va_arg(args, UINT8 *); /* data */
f++;
......@@ -87,7 +91,7 @@ UINT32 *ssh_vformat_length(char *f, va_list args)
{
int atom;
while(atom = va_arg(args, int))
while ( (atom = va_arg(args, int)) )
length += get_atom_length(atom) + 1;
/* One ','-character less than the number of atoms */
......@@ -100,7 +104,7 @@ UINT32 *ssh_vformat_length(char *f, va_list args)
break;
case 'n':
{
bignum n = va_arg(args, bignum);
bignum *n = va_arg(args, bignum *);
/* Calculate length of written number */
length += bignum_format_length(n);
......@@ -121,7 +125,7 @@ UINT32 *ssh_vformat_length(char *f, va_list args)
return length;
}
void ssh_vformat(char *f, UINT *buffer, va_list args)
void ssh_vformat(char *f, UINT8 *buffer, va_list args)
{
while(*f)
{
......@@ -159,8 +163,8 @@ void ssh_vformat(char *f, UINT *buffer, va_list args)
break;
case 's':
{
UINT32 length += va_arg(args, UINT32);
UINT8 *data = va_arg(args, UIN8 *);
UINT32 length = va_arg(args, UINT32);
UINT8 *data = va_arg(args, UINT8 *);
if (!literal)
{
......@@ -175,11 +179,12 @@ void ssh_vformat(char *f, UINT *buffer, va_list args)
break;
case 'a':
{
UINT32 length;
int atom = va_arg(args, int);
assert(atom);
length += get_atom_length(atom);
length = get_atom_length(atom);
if (!literal)
{
......@@ -195,7 +200,6 @@ void ssh_vformat(char *f, UINT *buffer, va_list args)
case 'A':
{
int atom;
int first = 1;
UINT8 *start = buffer; /* Where to store the length */
if (!literal)
......@@ -208,7 +212,7 @@ void ssh_vformat(char *f, UINT *buffer, va_list args)
memcpy(buffer, get_atom_name(atom), length);
buffer += length;
while(atom = va_arg(args, int))
while ( (atom = va_arg(args, int)) )
{
*buffer++ = ',';
length = get_atom_length(atom);
......@@ -219,7 +223,7 @@ void ssh_vformat(char *f, UINT *buffer, va_list args)
if (!literal)
{
total = buffer - start - 4;
UINT32 total = buffer - start - 4;
WRITE_UINT32(start, total);
}
f++;
......@@ -227,7 +231,7 @@ void ssh_vformat(char *f, UINT *buffer, va_list args)
break;
case 'n':
{
bignum n = va_arg(args, bignum);
bignum *n = va_arg(args, bignum *);
UINT32 length = bignum_format(n, buffer);
buffer += length;
......
......@@ -8,6 +8,10 @@
#include <stdarg.h>
#include "atoms.h"
#include "bignum.h"
#include "transport.h"
/* Format strings can contain the following %-specifications:
*
* %% Insert a %-sign
......@@ -31,7 +35,7 @@
*/
UINT32 ssh_vformat_length(char *format, va_list args);
void ssh_vformat(char *format, UINT *buffer, va_list args);
void ssh_vformat(char *format, UINT8 *buffer, va_list args);
struct simple_packet *ssh_format(char *format, ...);
#endif /* LSH_FORMAT_H_INCLUDED */
......@@ -2,6 +2,10 @@
*
*/
#include "packet_dispatch.h"
#include "xalloc.h"
#include "werror.h"
static int do_dispatch(struct dispatch_processor *closure,
struct simple_packet *packet)
{
......@@ -14,8 +18,8 @@ static int do_dispatch(struct dispatch_processor *closure,
msg = packet->data[0];
/* Do a binary serch. The number of valid message types should be rather small.
*/
/* Do a binary serch. The number of valid message types should be
* rather small. */
start = 0;
end = closure->table_size;
......@@ -23,25 +27,25 @@ static int do_dispatch(struct dispatch_processor *closure,
while(1)
{
unsigned middle = (start + end) / 2;
unsigned middle_msg = closure->dispatch_table[middle]->msg;
unsigned middle_msg = closure->dispatch_table[middle].msg;
if (middle_msg == msg)
{
/* Found right method */
return apply_processor(closure->dispatch_table[middle]->f,
return apply_processor(closure->dispatch_table[middle].f,
packet);
}
if (middle == start)
/* Not found */
break;
if (middle_id < msg)
if (middle_msg < msg)
start = middle;
else
end = middle;
}
if (closure->default)
return apply_processor(closure->default, packet);
if (closure->other)
return apply_processor(closure->other, packet);
else
return 0;
}
......@@ -49,18 +53,19 @@ static int do_dispatch(struct dispatch_processor *closure,
struct packet_processor *
make_dispatch_processor(unsigned size,
struct dispatch_assoc *table,
struct packet_processor *default)
struct packet_processor *other)
{
struct dispatch_processor *closure = xalloc(sizeof(struct dispatch_processor));
struct dispatch_processor *closure
= xalloc(sizeof(struct dispatch_processor));
unsigned i;