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

* src/lsh_string.c (lsh_string_random): Adapted to new randomness

interface, and deleted randomness argument.
(lsh_string_write_random): Likewise.

* src/keyexchange.h (class make_kexinit): Deleted randomness
argument from the make method.
(MAKE_KEXINIT): Deleted macro.

* src/keyexchange.c (do_make_simple_kexinit): Adapted to new
randomness interface, and deleted randomness argument.

* src/randomness.h: Deleted randomness class. New interface using
plain functions random_generate and random_add.

Rev: src/keyexchange.c:1.101
Rev: src/keyexchange.h:1.62
Rev: src/lsh_string.c:1.9
Rev: src/lsh_string.h:1.7
Rev: src/randomness.h:1.18
parent c2cea0a2
......@@ -31,7 +31,6 @@
#include "keyexchange.h"
#include "alist.h"
#include "command.h"
#include "format.h"
#include "io.h"
#include "lsh_string.h"
......@@ -299,13 +298,12 @@ handle_kexinit(struct kexinit_state *self,
*/
static struct kexinit *
do_make_simple_kexinit(struct make_kexinit *c, struct randomness *random)
do_make_simple_kexinit(struct make_kexinit *c)
{
CAST(simple_kexinit, closure, c);
NEW(kexinit, kex);
assert(random->quality == RANDOM_GOOD);
RANDOM(random, sizeof(kex->cookie), kex->cookie);
random_generate(sizeof(kex->cookie), kex->cookie);
kex->kex_algorithms = closure->kex_algorithms;
kex->server_hostkey_algorithms = closure->hostkey_algorithms;
......
......@@ -139,15 +139,15 @@ handle_kexinit(struct kexinit_state *self,
*
* If a speculative packet follows, it is stored in the last field. */
/* FIXME: We don't need this abstract class, merge with simple_kexinit
and a plain function for generating kexinits. */
/* GABA:
(class
(name make_kexinit)
(vars
(make method (object kexinit) "struct randomness *random")))
(make method (object kexinit))))
*/
#define MAKE_KEXINIT(s, r) ((s)->make((s), (r)))
struct make_kexinit *
make_simple_kexinit(struct int_list *kex_algorithms,
struct int_list *hostkey_algorithms,
......
......@@ -87,10 +87,10 @@ lsh_string_write_string(struct lsh_string *s, uint32_t pos,
#ifndef LSH_MINIMAL
struct lsh_string *
lsh_string_random(struct randomness *r, uint32_t length)
lsh_string_random(uint32_t length)
{
struct lsh_string *s = lsh_string_alloc(length);
lsh_string_write_random(s, 0, r, length);
lsh_string_write_random(s, 0, length);
return s;
}
......@@ -528,11 +528,11 @@ lsh_string_write_hmac(struct lsh_string *s, uint32_t start,
}
void
lsh_string_write_random(struct lsh_string *s, uint32_t start,
struct randomness *r, uint32_t length)
lsh_string_write_random(struct lsh_string *s,
uint32_t start, uint32_t length)
{
ASSERT_ROOM(s, start, length);
RANDOM(r, length, s->data + start);
random_generate(length, s->data + start);
assert(!s->data[s->length]);
}
......
......@@ -167,11 +167,11 @@ lsh_string_write_hmac(struct lsh_string *s, uint32_t start,
const void *outer, const void *inner, void *state);
void
lsh_string_write_random(struct lsh_string *s, uint32_t start,
struct randomness *r, uint32_t length);
lsh_string_write_random(struct lsh_string *s,
uint32_t start, uint32_t length);
struct lsh_string *
lsh_string_random(struct randomness *r, uint32_t length);
lsh_string_random(uint32_t length);
struct lsh_string *
lsh_string_ntop(int family, uint32_t length, const void *addr);
......
......@@ -42,46 +42,26 @@ enum random_source_type
RANDOM_NSOURCES
};
/* Randomness that is for "pad only" should be used only for iv:s and
* random padding. */
enum randomness_quality { RANDOM_GOOD, RANDOM_PAD_ONLY };
#define GABA_DECLARE
#include "randomness.h.x"
#undef GABA_DECLARE
/* GABA:
(class
(name randomness)
(vars
(quality . "enum randomness_quality")
(random method void "uint32_t length" "uint8_t *dst")
; To be used only for SOURCE_REMOTE and SOURCE_SECRET
(add method void "enum random_source_type"
"uint32_t length" "const uint8_t *data")))
*/
void
random_generate(uint32_t length, uint8_t *dst);
#define RANDOM(r, length, dst) ((r)->random((r), (length), (dst)))
#define RANDOM_ADD(r, t, length, data) ((r)->add((r), (t), (length), (dst)))
void
random_add(enum random_source_type type, uint32_t length,
const uint8_t *data);
/* This is not really a constructor, as the randomness collector uses
* global state. */
struct randomness *
random_init(struct lsh_string *seed_file_name);
/* Creates a more efficient but less secure generator by buffering
* another generator. */
struct randomness *
make_buffered_random(struct randomness *);
int
random_init(const struct lsh_string *seed_file_name);
struct randomness *
make_user_random(const char *home);
int
random_init_user(const char *home);
struct randomness *
make_system_random(void);
int
random_init_system(void);
/* Randomness function matching nettle's expectations. */
void
lsh_random(void *x, unsigned length, uint8_t *data);
lsh_random(void *ctx, unsigned length, uint8_t *data);
#endif /* LSH_RANDOMNESS_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