[BACK]Return to randoms.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Annotation of src/usr.bin/ssh/randoms.h, Revision 1.1

1.1     ! deraadt     1: /*
        !             2:
        !             3: random.h
        !             4:
        !             5: Author: Tatu Ylonen <ylo@cs.hut.fi>
        !             6:
        !             7: Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
        !             8:                    All rights reserved
        !             9:
        !            10: Created: Sat Mar  4 14:49:05 1995 ylo
        !            11:
        !            12: Cryptographically strong random number generator.
        !            13:
        !            14: */
        !            15:
        !            16: /* RCSID("$Id: randoms.h,v 1.3 1999/05/04 11:58:59 bg Exp $"); */
        !            17:
        !            18: #ifndef RANDOM_H
        !            19: #define RANDOM_H
        !            20:
        !            21: #include "ssh_md5.h"
        !            22:
        !            23: #define RANDOM_STATE_BITS      8192
        !            24: #define RANDOM_STATE_BYTES     (RANDOM_STATE_BITS / 8)
        !            25:
        !            26: /* Structure for the random state. */
        !            27: typedef struct
        !            28: {
        !            29:   unsigned char state[RANDOM_STATE_BYTES];/* Pool of random data. */
        !            30:   unsigned char stir_key[64];          /* Extra data for next stirring. */
        !            31:   unsigned int next_available_byte;    /* Index of next available byte. */
        !            32:   unsigned int add_position;           /* Index to add noise. */
        !            33: } RandomState;
        !            34:
        !            35: /* Initializes the random number generator, loads any random information
        !            36:    from the given file, and acquires as much environmental noise as it
        !            37:    can to initialize the random number generator.  More noise can be
        !            38:    acquired later by calling random_add_noise + random_stir, or by
        !            39:    calling random_get_environmental_noise again later when the environmental
        !            40:    situation has changed. */
        !            41: void random_initialize(RandomState *state, const char *filename);
        !            42:
        !            43: /* Acquires as much environmental noise as it can.  This is probably quite
        !            44:    sufficient on a unix machine, but might be grossly inadequate on a
        !            45:    single-user PC or a Macintosh.  This call random_stir automatically.
        !            46:    This call may take many seconds to complete on a busy system. */
        !            47: void random_acquire_environmental_noise(RandomState *state);
        !            48:
        !            49: /* Acquires easily available noise from the environment. */
        !            50: void random_acquire_light_environmental_noise(RandomState *state);
        !            51:
        !            52: /* Executes the given command, and processes its output as noise.
        !            53:    random_stir should be called after this. */
        !            54: void random_get_noise_from_command(RandomState *state, const char *cmd);
        !            55:
        !            56: /* Adds the contents of the buffer as noise.  random_stir should be called
        !            57:    after this. */
        !            58: void random_add_noise(RandomState *state, const void *buf, unsigned int bytes);
        !            59:
        !            60: /* Stirs the random pool to consume any newly acquired noise or to get more
        !            61:    random numbers.  This should be called after adding noise to properly
        !            62:    mix the noise into the random pool. */
        !            63: void random_stir(RandomState *state);
        !            64:
        !            65: /* Returns a random byte.  Stirs the random pool if necessary.  Acquires
        !            66:    new environmental noise approximately every five minutes. */
        !            67: unsigned int random_get_byte(RandomState *state);
        !            68:
        !            69: /* Saves some random bits in the file so that it can be used as a source
        !            70:    of randomness for later runs. */
        !            71: void random_save(RandomState *state, const char *filename);
        !            72:
        !            73: /* Zeroes and frees any data structures associated with the random number
        !            74:    generator. */
        !            75: void random_clear(RandomState *state);
        !            76:
        !            77: #endif /* RANDOM_H */