OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
8.6 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../csprng/0001-configure-add-option-to-disable-http-rng.patch
  5. # Copyright (C) 2013 The OpenSDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This patch file is dual-licensed. It is available under the license the
  10. # patched project is licensed under, as long as it is an OpenSource license
  11. # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
  12. # of the GNU General Public License as published by the Free Software
  13. # Foundation; either version 2 of the License, or (at your option) any later
  14. # version.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. From 1ff114f41520671408445e18835b34a756e29650 Mon Sep 17 00:00:00 2001
  17. From: Christian Wiese <chris@opensde.org>
  18. Date: Wed, 4 Sep 2013 22:39:09 +0200
  19. Subject: [PATCH] configure: add option to disable http rng
  20. ---
  21. configure.ac | 17 +++++++++++++++++
  22. src/Makefile.am | 15 ++++++++++-----
  23. src/csprng.c | 12 ++++++++++++
  24. test/Makefile.am | 5 ++++-
  25. utils/csprng-generate.c | 6 ++++++
  26. 5 files changed, 49 insertions(+), 6 deletions(-)
  27. diff --git a/configure.ac b/configure.ac
  28. index 40dfaa4..12fd277 100755
  29. --- a/configure.ac
  30. +++ b/configure.ac
  31. @@ -55,6 +55,23 @@ AC_FUNC_SELECT_ARGTYPES
  32. AC_TYPE_SIGNAL
  33. AC_CHECK_FUNCS([floor gettimeofday memset pow select sqrt clock_gettime])
  34. +#### disable http rng feature (default: enabled)
  35. +AC_ARG_ENABLE([http-rng],
  36. + AS_HELP_STRING([--disable-http-rng], [Disable feature to fetch random data via http from random.irb.hr]))
  37. +
  38. +AS_IF([test "x$enable_http_rng" != "xno"], [
  39. + dnl Do the stuff needed for enabling the feature
  40. + DISABLE_HTTP_RNG="yes"
  41. +])
  42. +
  43. +AM_CONDITIONAL([ENABLE_HTTP_RNG], [test "x$DISABLE_HTTP_RNG" = "xyes"])
  44. +
  45. +# Define HTTP_RNG in config.h if we're going to compile against it
  46. +if test "x$DISABLE_HTTP_RNG" = "xyes"; then
  47. + AC_DEFINE([ENABLE_HTTP_RNG], 1, ["Define to 1 if you want to enable http rng feature."])
  48. + AC_MSG_NOTICE([disable http rng])
  49. +fi
  50. +
  51. #### Find OpenSSL
  52. AC_MSG_CHECKING([for --with-openssl])
  53. AC_ARG_WITH(
  54. diff --git a/src/Makefile.am b/src/Makefile.am
  55. index 8e1a2bb..fb0ff98 100644
  56. --- a/src/Makefile.am
  57. +++ b/src/Makefile.am
  58. @@ -16,6 +16,14 @@ libcsprng_la_LIBADD =
  59. libcsprng_la_CPPFLAGS = -I$(top_srcdir)/include
  60. libcsprng_la_LDFLAGS = -version-number @CSPRNG_LT_VERSION@
  61. +if ENABLE_HTTP_RNG
  62. +HTTP_RNG_SOURCES = \
  63. + QRBG.h \
  64. + QRBG.cpp \
  65. + qrbg-c.cpp \
  66. + http_rng.c
  67. +endif
  68. +
  69. # Sources
  70. # The shell script is the easy way to do this, by far. But it may not
  71. # be sufficiently portable.
  72. @@ -29,11 +37,8 @@ libcsprng_la_SOURCES = \
  73. csprng.c \
  74. memt19937ar-JH.c \
  75. sha1_rng.c \
  76. - fips.c \
  77. - QRBG.h \
  78. - QRBG.cpp \
  79. - qrbg-c.cpp \
  80. - http_rng.c
  81. + $(HTTP_RNG_SOURCES) \
  82. + fips.c
  83. MAINTAINERCLEANFILES = Makefile.in
  84. diff --git a/src/csprng.c b/src/csprng.c
  85. index 76823e2..89dedad 100644
  86. --- a/src/csprng.c
  87. +++ b/src/csprng.c
  88. @@ -38,7 +38,9 @@ along with CSRNG. If not, see <http://www.gnu.org/licenses/>.
  89. #include <csprng/nist_ctr_drbg.h>
  90. #include <csprng/memt19937ar-JH.h>
  91. #include <csprng/sha1_rng.h>
  92. +#if defined(ENABLE_HTTP_RNG)
  93. #include <csprng/http_rng.h>
  94. +#endif
  95. #include <csprng/csprng.h>
  96. #include <csprng/fips.h>
  97. @@ -282,6 +284,7 @@ static void fill_buffer_using_SHA ( rng_buf_type* data )
  98. }
  99. //}}}
  100. +#if defined(ENABLE_HTTP_RNG)
  101. //{{{ static void fill_buffer_using_HTTP ( rng_buf_type* data )
  102. static void fill_buffer_using_HTTP ( rng_buf_type* data )
  103. {
  104. @@ -332,6 +335,7 @@ static void fill_buffer_using_HTTP ( rng_buf_type* data )
  105. return;
  106. }
  107. //}}}
  108. +#endif
  109. //{{{ static void fill_buffer_using_MT_RNG ( rng_buf_type* data )
  110. static void fill_buffer_using_MT_RNG ( rng_buf_type* data )
  111. @@ -380,9 +384,11 @@ static const unsigned char* get_data_from_RNG_buffer ( rng_buf_type* data, unsig
  112. case SHA1_RNG:
  113. fill_buffer_using_SHA (data);
  114. break;
  115. +#if defined(ENABLE_HTTP_RNG)
  116. case HTTP_RNG:
  117. fill_buffer_using_HTTP (data);
  118. break;
  119. +#endif
  120. case MT_RNG:
  121. fill_buffer_using_MT_RNG (data);
  122. break;
  123. @@ -906,9 +912,11 @@ csprng_state_type* csprng_initialize( const mode_of_operation_type* mode_of_oper
  124. unsigned int allocated_size; //Number of bytes allocated for seed.
  125. rng_state_type rng_state;
  126. csprng_state_type* csprng_state;
  127. +#if defined(ENABLE_HTTP_RNG)
  128. char* QRBG_RNG_login_name; //User name for random.irb.hr
  129. char* QRBG_RNG_passwd; //Password for random.irb.hr
  130. char HTTP_source_bitmask; //source bitmask for http_random_init
  131. +#endif
  132. //{{{ Init csprng_state, do sanity checks
  133. assert ( mode_of_operation->entropy_source < SOURCES_COUNT );
  134. @@ -1072,6 +1080,7 @@ csprng_state_type* csprng_initialize( const mode_of_operation_type* mode_of_oper
  135. }
  136. //}}}
  137. +#if defined(ENABLE_HTTP_RNG)
  138. //{{{ Check if need HTTP_RNG and init it
  139. if ( csprng_state->mode.entropy_source == HTTP_RNG || csprng_state->mode.add_input_source == HTTP_RNG ) {
  140. QRBG_RNG_login_name = getenv("QRBG_USER");
  141. @@ -1097,6 +1106,7 @@ csprng_state_type* csprng_initialize( const mode_of_operation_type* mode_of_oper
  142. if ( unsetenv("QRBG_PASSWD") ) fprintf(stderr, "WARNING: unsetenv(\"QRBG_PASSWD\") failed with %s.\n", strerror(errno));
  143. }
  144. //}}}
  145. +#endif
  146. //{{{ Check if need HAVEGE and init it
  147. if ( csprng_state->mode.entropy_source == HAVEGE || csprng_state->mode.add_input_source == HAVEGE ) {
  148. @@ -1485,9 +1495,11 @@ csprng_destroy ( csprng_state_type* csprng_state )
  149. destroy_buffer( csprng_state->entropy_buf );
  150. }
  151. +#if defined(ENABLE_HTTP_RNG)
  152. if ( csprng_state->http != NULL ) {
  153. http_random_destroy( csprng_state->http );
  154. }
  155. +#endif
  156. if ( csprng_state->sha != NULL ) {
  157. destroy_SHA1( csprng_state->sha );
  158. diff --git a/test/Makefile.am b/test/Makefile.am
  159. index d3e045e..023ded7 100644
  160. --- a/test/Makefile.am
  161. +++ b/test/Makefile.am
  162. @@ -4,7 +4,10 @@ include $(top_srcdir)/common.mk
  163. #bin_PROGRAMS = openssl-rand sha1_main memt qrbg_main http_main ctr_drbg_test
  164. #TODO - link static does not work for qrbg_main.c => move it to C++ ??
  165. -bin_PROGRAMS = openssl-rand_main sha1_main memt_main qrbg_main http_main ctr_drbg_test havege_main
  166. +bin_PROGRAMS = openssl-rand_main sha1_main memt_main ctr_drbg_test havege_main
  167. +if ENABLE_HTTP_RNG
  168. + bin_PROGRAMS += qrbg_main http_main
  169. +endif
  170. if HAVE_LIBTESTU01
  171. bin_PROGRAMS += TestU01_raw_stdin_input_with_log
  172. endif
  173. diff --git a/utils/csprng-generate.c b/utils/csprng-generate.c
  174. index f9207fb..7a1928a 100644
  175. --- a/utils/csprng-generate.c
  176. +++ b/utils/csprng-generate.c
  177. @@ -832,7 +832,9 @@ int main(int argc, char **argv) {
  178. mode_of_operation.file_read_size = 16384;
  179. mode_of_operation.max_number_of_csprng_blocks = arguments.max_num_of_blocks;
  180. mode_of_operation.random_length_of_csprng_generated_bytes = arguments.randomize_num_of_blocks;
  181. +#if defined(ENABLE_HTTP_RNG)
  182. mode_of_operation.http_random_verbosity = arguments.verbose;
  183. +#endif
  184. fips_state = fips_approved_csprng_initialize(arguments.fips_test, 0, &mode_of_operation);
  185. @@ -942,9 +944,11 @@ int main(int argc, char **argv) {
  186. current_time = time(NULL);
  187. strftime(current_time_string, sizeof(current_time_string) , "%a %b %H:%M:%S %Y", localtime(&current_time));
  188. fprintf ( stderr, "\n========================= %s ==========================\n", current_time_string );
  189. +#if defined(ENABLE_HTTP_RNG)
  190. if ( arguments.entropy_source == HTTP_RNG || arguments.add_input_source == HTTP_RNG ) {
  191. http_random_status( fips_state->csprng_state->http, 1);
  192. }
  193. +#endif
  194. print_statistics(total_bytes_written, arguments.unlimited, remaining_bytes, arguments.size, stderr, &start_time);
  195. fprintf(stderr, "\n");
  196. if ( arguments.fips_test) fprintf ( stderr, "%s", dump_fips_statistics ( &fips_state->fips_ctx.fips_statistics ) );
  197. @@ -968,9 +972,11 @@ int main(int argc, char **argv) {
  198. current_time = time(NULL);
  199. strftime(current_time_string, sizeof(current_time_string) , "%a %b %H:%M:%S %Y", localtime(&current_time));
  200. fprintf ( stderr, "\n======FINAL REPORT======= %s ==========================\n", current_time_string );
  201. +#if defined(ENABLE_HTTP_RNG)
  202. if ( arguments.entropy_source == HTTP_RNG || arguments.add_input_source == HTTP_RNG ) {
  203. http_random_status( fips_state->csprng_state->http, 1);
  204. }
  205. +#endif
  206. print_statistics(total_bytes_written, arguments.unlimited, remaining_bytes, arguments.size, stderr, &start_time);
  207. fprintf(stderr, "\n");
  208. if ( arguments.fips_test) fprintf ( stderr, "%s", dump_fips_statistics ( &fips_state->fips_ctx.fips_statistics ) );
  209. --
  210. 1.7.2.3