Introduced PRNG based on Hash_DRBG (NIST SP 800-90A)

This pseudo-random number generator solves problem with
platform-independent generation of randomized nonces.
Current implementation uses weak entropy, especially when
kernel.randomize_va_space = 0. But it can be improved by
adding new sources to xmpp_rand_reseed().

New internal API introduced:
  xmpp_rand_new
  xmpp_rand_free
  xmpp_rand
  xmpp_rand_bytes
  xmpp_rand_nonce
This commit is contained in:
Dmitry Podgorny
2014-09-08 15:05:51 +03:00
parent 75b1a633d6
commit 10656ead46
7 changed files with 366 additions and 28 deletions

43
src/rand.h Normal file
View File

@@ -0,0 +1,43 @@
/* rand.h
* strophe XMPP client library -- pseudo-random number generator
*
* Copyright (C) 2014 Dmitry Podgorny <pasis.ua@gmail.com>
*
* This software is provided AS-IS with no warranty, either express
* or implied.
*
* This software is distributed under license and may not be copied,
* modified or distributed except as expressly authorized under the
* terms of the license contained in the file LICENSE.txt in this
* distribution.
*/
/** @file
* Pseudo-random number generator.
*/
#ifndef __LIBSTROPHE_RAND_H__
#define __LIBSTROPHE_RAND_H__
#include "strophe.h"
#include "ostypes.h"
typedef struct _xmpp_rand_t xmpp_rand_t;
xmpp_rand_t *xmpp_rand_new(xmpp_ctx_t *ctx);
void xmpp_rand_free(xmpp_ctx_t *ctx, xmpp_rand_t *rand);
/** Analogue of rand(3). */
int xmpp_rand(xmpp_ctx_t *ctx);
/** Generates random bytes. */
void xmpp_rand_bytes(xmpp_ctx_t *ctx, uint8_t *output, size_t len);
/** Generates a nonce that is printable randomized string.
*
* @param len Number of bytes reserved for the output string, including
* end of line '\0'.
*/
void xmpp_rand_nonce(xmpp_ctx_t *ctx, char *output, size_t len);
#endif /* __LIBSTROPHE_RAND_H__ */