From 118087f2a161831573f7a4df3ba171420cd3c923 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Tue, 1 Feb 2022 12:45:44 +0100 Subject: [PATCH] make RNG API (officially) public Fixes #189 Signed-off-by: Steffen Jaeckel --- src/auth.c | 1 - src/common.h | 1 - src/rand.c | 2 -- src/rand.h | 71 ------------------------------------------- src/sasl.c | 1 - src/uuid.c | 1 - strophe.h | 52 +++++++++++++++++++++++++++++++ tests/test_resolver.c | 1 - 8 files changed, 52 insertions(+), 78 deletions(-) delete mode 100644 src/rand.h diff --git a/src/auth.c b/src/auth.c index e3e8543..6b8e091 100644 --- a/src/auth.c +++ b/src/auth.c @@ -21,7 +21,6 @@ #include "common.h" #include "sasl.h" #include "sha1.h" -#include "rand.h" #ifdef _MSC_VER #define strcasecmp _stricmp diff --git a/src/common.h b/src/common.h index 4941831..2d008f0 100644 --- a/src/common.h +++ b/src/common.h @@ -26,7 +26,6 @@ #include "hash.h" #include "util.h" #include "parser.h" -#include "rand.h" #include "snprintf.h" /** handlers **/ diff --git a/src/rand.c b/src/rand.c index 4f56a43..01547fd 100644 --- a/src/rand.c +++ b/src/rand.c @@ -35,8 +35,6 @@ #include "common.h" /* xmpp_alloc, xmpp_free */ #include "ostypes.h" /* uint8_t, uint32_t, size_t */ -#include "rand.h" /* xmpp_rand_t */ - #ifndef USE_GETRANDOM #include "sha1.h" diff --git a/src/rand.h b/src/rand.h deleted file mode 100644 index 59d37ad..0000000 --- a/src/rand.h +++ /dev/null @@ -1,71 +0,0 @@ -/* rand.h - * strophe XMPP client library -- pseudo-random number generator - * - * Copyright (C) 2014 Dmitry Podgorny - * - * This software is provided AS-IS with no warranty, either express - * or implied. - * - * This program is dual licensed under the MIT and GPLv3 licenses. - */ - -/** @file - * Pseudo-random number generator. - */ - -#ifndef __LIBSTROPHE_RAND_H__ -#define __LIBSTROPHE_RAND_H__ - -#include /* size_t */ -#include "strophe.h" /* xmpp_ctx_t */ - -typedef struct _xmpp_rand_t xmpp_rand_t; - -/** Create new xmpp_rand_t object. - * - * @param ctx A Strophe context object - * - * @ingroup Random - */ -xmpp_rand_t *xmpp_rand_new(xmpp_ctx_t *ctx); -/** Destroy an xmpp_rand_t object. - * - * @param ctx A Strophe context object - * @param rand A xmpp_rand_t object - * - * @ingroup Random - */ -void xmpp_rand_free(xmpp_ctx_t *ctx, xmpp_rand_t *rand); - -/** Generate random integer. - * Analogue of rand(3). - * - * @ingroup Random - */ -int xmpp_rand(xmpp_rand_t *rand); - -/** Generate random bytes. - * Generates len bytes and stores them to the output buffer. - * - * @param rand A xmpp_rand_t object - * @param output A buffer where a len random bytes will be placed. - * @param len Number of bytes reserved for the output.. - * - * @ingroup Random - */ -void xmpp_rand_bytes(xmpp_rand_t *rand, unsigned char *output, size_t len); - -/** Generate a nonce that is printable randomized string. - * This function doesn't allocate memory and doesn't fail. - * - * @param rand A xmpp_rand_t object - * @param output A buffer where a NULL-terminated string will be placed. - * The string will contain len-1 printable symbols. - * @param len Number of bytes reserved for the output string, including - * end of line '\0'. - * - * @ingroup Random - */ -void xmpp_rand_nonce(xmpp_rand_t *rand, char *output, size_t len); - -#endif /* __LIBSTROPHE_RAND_H__ */ diff --git a/src/sasl.c b/src/sasl.c index 0a6eccc..69a0c05 100644 --- a/src/sasl.c +++ b/src/sasl.c @@ -22,7 +22,6 @@ #include "sasl.h" #include "md5.h" #include "scram.h" -#include "rand.h" #include "util.h" /* strtok_s() has appeared in visual studio 2005. diff --git a/src/uuid.c b/src/uuid.c index 3df1425..94865a2 100644 --- a/src/uuid.c +++ b/src/uuid.c @@ -15,7 +15,6 @@ #include "strophe.h" #include "common.h" -#include "rand.h" /** @def XMPP_UUID_LEN * UUID length in string representation excluding '\0'. diff --git a/strophe.h b/strophe.h index eed6d8d..71ae1d7 100644 --- a/strophe.h +++ b/strophe.h @@ -535,6 +535,58 @@ void xmpp_base64_decode_bin(xmpp_ctx_t *ctx, unsigned char **out, size_t *outlen); +/* RNG */ + +typedef struct _xmpp_rand_t xmpp_rand_t; + +/** Create new xmpp_rand_t object. + * + * @param ctx A Strophe context object + * + * @ingroup Random + */ +xmpp_rand_t *xmpp_rand_new(xmpp_ctx_t *ctx); + +/** Destroy an xmpp_rand_t object. + * + * @param ctx A Strophe context object + * @param rand A xmpp_rand_t object + * + * @ingroup Random + */ +void xmpp_rand_free(xmpp_ctx_t *ctx, xmpp_rand_t *rand); + +/** Generate random integer. + * Analogue of rand(3). + * + * @ingroup Random + */ +int xmpp_rand(xmpp_rand_t *rand); + +/** Generate random bytes. + * Generates len bytes and stores them to the output buffer. + * + * @param rand A xmpp_rand_t object + * @param output A buffer where a len random bytes will be placed. + * @param len Number of bytes reserved for the output.. + * + * @ingroup Random + */ +void xmpp_rand_bytes(xmpp_rand_t *rand, unsigned char *output, size_t len); + +/** Generate a nonce that is printable randomized string. + * This function doesn't allocate memory and doesn't fail. + * + * @param rand A xmpp_rand_t object + * @param output A buffer where a NULL-terminated string will be placed. + * The string will contain len-1 printable symbols. + * @param len Number of bytes reserved for the output string, including + * end of line '\0'. + * + * @ingroup Random + */ +void xmpp_rand_nonce(xmpp_rand_t *rand, char *output, size_t len); + #ifdef __cplusplus } #endif diff --git a/tests/test_resolver.c b/tests/test_resolver.c index 59b9ed7..55e35e9 100644 --- a/tests/test_resolver.c +++ b/tests/test_resolver.c @@ -13,7 +13,6 @@ #include #include "strophe.h" -#include "rand.h" #include "resolver.h" #include "test.h"