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

New files

Rev: src/algorithms.c:1.1
Rev: src/algorithms.h:1.1
Rev: src/lsh.h:1.1
parent 941948a4
/* algorithms.c
*
* Translate algorithm identifiers (or names) to algorithm objects.
*
* $Id$ */
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1998 Niels Mller
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "algorithms.h"
#include "atoms.h"
#include "compress.h"
#include "crypto.h"
#include "publickey_crypto.h"
#include <stdarg.h>
struct alist *many_algorithms(unsigned n, ...)
{
va_list args;
struct alist *a
= make_alist(5
#ifdef WITH_CAST
+1
#endif
#ifdef WITH_IDEA
+1
#endif
#ifdef WITH_ZLIB
+1
#endif
,
ATOM_ARCFOUR, &crypto_arcfour_algorithm,
ATOM_BLOWFISH_CBC, crypto_cbc(make_blowfish()),
ATOM_3DES_CBC, crypto_cbc(make_des3()),
#ifdef WITH_CAST
ATOM_CAST128_CBC, crypto_cbc(make_cast()),
#endif
#ifdef WITH_IDEA
ATOM_IDEA_CBC, crypto_cbc(&idea_algorithm),
#endif
ATOM_HMAC_SHA1, make_hmac_algorithm(&sha_algorithm),
ATOM_HMAC_MD5, make_hmac_algorithm(&md5_algorithm),
#ifdef WITH_ZLIB
ATOM_ZLIB, make_zlib(),
#endif
-1);
va_start(args, n);
alist_addv(a, n, args);
va_end(args);
return a;
}
/* This is not really efficient, but it doesn't matter. */
static int strcmp_list(char *name, ...)
{
va_list args;
char *s;
int res = 0;
va_start(args, name);
while ( (s = va_arg(args, char *)) )
{
if (!strcmp(name, s))
{
res = 1;
break;
}
}
va_end(args);
return res;
}
int lookup_crypto(struct alist *algorithms, char *name)
{
int atom;
if (!strcmp(name, "none"))
return ATOM_NONE;
if (strcmp_list(name, "arcfour", NULL))
atom = ATOM_ARCFOUR;
else if (strcmp_list(name, "blowfish-cbc", "blowfish", NULL))
atom = ATOM_BLOWFISH_CBC;
else if (strcmp_list(name, "3des-cbc", "3des", NULL))
atom = ATOM_3DES_CBC;
else if (strcmp_list(name, "idea-cbc", "idea", NULL))
atom = ATOM_IDEA_CBC;
else if (strcmp_list(name, "cast128-cbc", "cast", "cast-cbc", "cast128", NULL))
atom = ATOM_CAST128_CBC;
else
return 0;
/* Is this crypto supported? */
if (ALIST_GET(algorithms, atom))
return atom;
else
return 0;
}
int lookup_mac(struct alist *algorithms, char *name)
{
int atom;
if (!strcmp(name, "none"))
return ATOM_NONE;
if (strcmp_list(name, "hmac-sha1", "sha", "hmac-sha", "sha1", NULL))
atom = ATOM_HMAC_SHA1;
else if (strcmp_list(name, "hmac-md5", "md5", NULL))
atom = ATOM_HMAC_MD5;
else
return 0;
/* Is this mac supported? */
if (ALIST_GET(algorithms, atom))
return atom;
else
return 0;
}
int lookup_compression(struct alist *algorithms, char *name)
{
int atom;
if (!strcmp(name, "none"))
return ATOM_NONE;
if (strcmp_list(name, "zlib", "z", NULL))
atom = ATOM_ZLIB;
else
return 0;
/* Is this compression algorithm supported? */
if (ALIST_GET(algorithms, atom))
return atom;
else
return 0;
}
struct int_list *default_crypto_algorithms(void)
{
return make_int_list(3, ATOM_3DES_CBC, ATOM_BLOWFISH_CBC, ATOM_ARCFOUR, -1);
}
struct int_list *default_mac_algorithms(void)
{
return make_int_list(2, ATOM_HMAC_SHA1, ATOM_HMAC_MD5, -1);
}
struct int_list *default_compression_algorithms(void)
{
#if WITH_ZLIB
return make_int_list(2, ATOM_NONE, ATOM_ZLIB, -1);
#else /* !WITH_ZLIB */
return make_int_list(1, ATOM_NONE, -1);
#endif
}
/* algorithms.c
*
* Translate algorithm identifiers (or names) to algorithm objects.
*
* $Id$ */
#ifndef LSH_ALGORITHMS_H_INCLUDED
#define LSH_ALGORITHMS_H_INCLUDED
#include "alist.h"
#include "randomness.h"
struct alist *many_algorithms(unsigned count, ...);
int lookup_crypto(struct alist *algorithms, char *name);
int lookup_mac(struct alist *algorithms, char *name);
int lookup_compression(struct alist *algorithms, char *name);
struct int_list *default_crypto_algorithms(void);
struct int_list *default_mac_algorithms(void);
struct int_list *default_compression_algorithms(void);
#endif */ LSH_ALGORITHMS_H_INCLUDED */
/* lsh.h
*
* $Id$ */
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1998 Niels Möller
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef LSH_H_INCLUDED
#define LSH_H_INCLUDED
#include "lsh_types.h"
#include <stdlib.h>
/* Generic object */
#define LSH_ALLOC_HEAP 0
#define LSH_ALLOC_STATIC 1
#define LSH_ALLOC_STACK 2
struct lsh_class;
struct lsh_object
{
/* Objects are chained together, for the sweep phase of the gc. */
struct lsh_object *next;
struct lsh_class *isa;
char alloc_method;
char marked;
char dead;
};
/* NOTE: Static objects have a NULL isa-pointer, and can therefore not
* contain any references to non-static objects. This could be fixed,
* by using an argument to the STATIC_HEADER macro, but then one must
* use some class for lsh_class objects... */
#define STATIC_HEADER { NULL, NULL, LSH_ALLOC_STATIC, 0, 0 }
#define STACK_HEADER { NULL, NULL, LSH_ALLOC_STACK, 0, 0 }
struct lsh_class
{
struct lsh_object super;
struct lsh_class *super_class;
char *name; /* For debugging */
size_t size;
void (*mark_instance)(struct lsh_object *instance,
void (*mark)(struct lsh_object *o));
void (*free_instance)(struct lsh_object *instance);
/* Particular classes may add their own methods here */
};
#define MARK_INSTANCE(c, i, f) ((c)->mark_instance((i), (f)))
#define FREE_INSTANCE(c, i) ((c)->free_instance((i)))
#define CLASS(c) (c##_class)
#ifdef DEBUG_ALLOC
struct lsh_string_header
{
int magic; /* For a sentinel value */
};
#else /* !DEBUG_ALLOC */
struct lsh_string_header {};
#endif /* !DEBUG_ALLOC */
struct lsh_string
{
struct lsh_string_header header;
UINT32 sequence_number;
/* NOTE: The allocated size may be larger than the string length. */
UINT32 length;
UINT8 data[1];
};
/* A closed function with no arguments */
struct callback;
typedef int (*callback_f)(struct callback *closure);
struct callback
{
struct lsh_object header;
int (*f)(struct callback *closure);
};
#define CALLBACK(c) ((c)->f(c))
/* Return values.
*
* Every handler should return one or more of these values, or-ed together.
* Zero means everything is ok.
*/
/* Success/fail indication. LSH_FAIL should always be combined with
* LSH_DIE or LSH_CLOSE. */
#define LSH_OK 0
#define LSH_FAIL 1
#define LSH_FAILUREP(x) ((x) & 1)
/* Everything is ok */
#define LSH_GOON 0
/* Close the associated connection, after flushing buffers. May be
* combined with LSH_FAIL. */
#define LSH_CLOSE 2
/* Close connection immediately. This is usually combined with
* LSH_FAIL, but not always. For instance, when forking, the parent
* process will return this flag in order to have its copy of the
* filedescriptor closed. */
#define LSH_DIE 4
/* Close all other filedescriptors immediately. MAinly used when forking.
* Can be combined with LSH_FAIL or LSH_DIE or both. */
#define LSH_KILL_OTHERS 8
/* Not used by the main loop, but is returned by authentication
* handlers to indicate that the client's authentication was rejected.
* This can result either in a fatal protocol failure, or in a request
* to the client to try again. */
#define LSH_AUTH_FAILED 0x10
/* Returned by a read handler when it is (temporarily) not able to
* read more data. Used for flow control. */
#define LSH_HOLD 0x20
/* Returned by channel callback functions when the channel is closed. */
#define LSH_CHANNEL_FINISHED 0x40
/* Indicates that the connection should be closed once all active
* channels are closed. */
#define LSH_CHANNEL_PENDING_CLOSE 0x80
/* Indicates that a channel is ready to receive remote data */
#define LSH_CHANNEL_READY_REC 0x100
/* Indicates that a channel is ready to send data to the remote end. */
#define LSH_CHANNEL_READY_SEND 0x200
/* Syntax error (used in the sexp parser) */
#define LSH_SYNTAX 0x400
/* Used to indicate that an sexp have been parsed successfully */
#define LSH_PARSED_OBJECT 0x800
/* Non-zero if no messages can be sent over the connection. Used when
* processing error codes from in the middle of the processing a
* messages. If this is true, processing should stop, and most likely
* return LSH_FAIL (ored together with the intermediate error code). */
#define LSH_CLOSEDP(x) (x & (LSH_FAIL | LSH_CLOSE | LSH_DIE) )
/* If non-zero, return to main-loop is preferred */
#define LSH_ACTIONP(x) ((x) & (LSH_FAIL | LSH_CLOSE | LSH_DIE | LSH_KILL_OTHERS) )
#endif /* LSH_H_INCLUDED */
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