Commit 619d294e9d2d9bb64c4eac62fde57096d5a84ba4

Authored by Jay Berkenbilt
1 parent 1360b530

Remove QUtil::srandom

ChangeLog
1 2020-04-06 Jay Berkenbilt <ejb@ql.org> 1 2020-04-06 Jay Berkenbilt <ejb@ql.org>
2 2
  3 + * Source-level incompatibility: remove QUtil::srandom. There was
  4 + no reason to ever call this, and it didn't do anything unless
  5 + insecure random number generation was compiled in, which it is not
  6 + by default. If you were calling this, just remove the call because
  7 + it wasn't doing anything anyway.
  8 +
3 * Add openssl crypto provider, contributed by Dean Scarff. This 9 * Add openssl crypto provider, contributed by Dean Scarff. This
4 provider is implemented using OpenSSL and also works with 10 provider is implemented using OpenSSL and also works with
5 BoringSSL. 11 BoringSSL.
include/qpdf/QUtil.hh
@@ -271,13 +271,6 @@ namespace QUtil @@ -271,13 +271,6 @@ namespace QUtil
271 QPDF_DLL 271 QPDF_DLL
272 long random(); 272 long random();
273 273
274 - // Wrapper around srandom from stdlib. Seeds the standard library  
275 - // weak random number generator, which is not used if secure  
276 - // random number generation is being used. You never need to call  
277 - // this method as it is called automatically if needed.  
278 - QPDF_DLL  
279 - void srandom(unsigned int seed);  
280 -  
281 // Initialize a buffer with random bytes. By default, qpdf tries 274 // Initialize a buffer with random bytes. By default, qpdf tries
282 // to use a secure random number source. It can be configured at 275 // to use a secure random number source. It can be configured at
283 // compile time to use an insecure random number source (from 276 // compile time to use an insecure random number source (from
libqpdf/InsecureRandomDataProvider.cc
@@ -30,8 +30,13 @@ InsecureRandomDataProvider::random() @@ -30,8 +30,13 @@ InsecureRandomDataProvider::random()
30 // Seed the random number generator with something simple, but 30 // Seed the random number generator with something simple, but
31 // just to be interesting, don't use the unmodified current 31 // just to be interesting, don't use the unmodified current
32 // time. It would be better if this were a more secure seed. 32 // time. It would be better if this were a more secure seed.
33 - QUtil::srandom(static_cast<unsigned int>(  
34 - QUtil::get_current_time() ^ 0xcccc)); 33 + unsigned int seed = static_cast<unsigned int>(
  34 + QUtil::get_current_time() ^ 0xcccc);
  35 +#ifdef HAVE_RANDOM
  36 + ::srandom(seed);
  37 +#else
  38 + srand(seed);
  39 +#endif
35 this->seeded_random = true; 40 this->seeded_random = true;
36 } 41 }
37 42
libqpdf/QUtil.cc
@@ -878,16 +878,6 @@ QUtil::toUTF16(unsigned long uval) @@ -878,16 +878,6 @@ QUtil::toUTF16(unsigned long uval)
878 878
879 // Random data support 879 // Random data support
880 880
881 -long  
882 -QUtil::random()  
883 -{  
884 - long result = 0L;  
885 - initializeWithRandomBytes(  
886 - reinterpret_cast<unsigned char*>(&result),  
887 - sizeof(result));  
888 - return result;  
889 -}  
890 -  
891 static RandomDataProvider* random_data_provider = 0; 881 static RandomDataProvider* random_data_provider = 0;
892 882
893 #ifdef USE_INSECURE_RANDOM 883 #ifdef USE_INSECURE_RANDOM
@@ -941,14 +931,14 @@ QUtil::initializeWithRandomBytes(unsigned char* data, size_t len) @@ -941,14 +931,14 @@ QUtil::initializeWithRandomBytes(unsigned char* data, size_t len)
941 random_data_provider->provideRandomData(data, len); 931 random_data_provider->provideRandomData(data, len);
942 } 932 }
943 933
944 -void  
945 -QUtil::srandom(unsigned int seed) 934 +long
  935 +QUtil::random()
946 { 936 {
947 -#ifdef HAVE_RANDOM  
948 - ::srandom(seed);  
949 -#else  
950 - srand(seed);  
951 -#endif 937 + long result = 0L;
  938 + initializeWithRandomBytes(
  939 + reinterpret_cast<unsigned char*>(&result),
  940 + sizeof(result));
  941 + return result;
952 } 942 }
953 943
954 bool 944 bool
manual/qpdf-manual.xml
@@ -4800,6 +4800,22 @@ print &quot;\n&quot;; @@ -4800,6 +4800,22 @@ print &quot;\n&quot;;
4800 </listitem> 4800 </listitem>
4801 <listitem> 4801 <listitem>
4802 <para> 4802 <para>
  4803 + Incompatible API (source-level) Changes (minor)
  4804 + </para>
  4805 + <itemizedlist>
  4806 + <listitem>
  4807 + <para>
  4808 + The <function>QUtil::srandom</function> method was removed.
  4809 + It didn't do anything unless insecure random numbers were
  4810 + compiled in, and they have been off by default for a long
  4811 + time. If you were calling it, just remove the call since it
  4812 + wasn't doing anything anyway.
  4813 + </para>
  4814 + </listitem>
  4815 + </itemizedlist>
  4816 + </listitem>
  4817 + <listitem>
  4818 + <para>
4803 Build/Packaging Changes 4819 Build/Packaging Changes
4804 </para> 4820 </para>
4805 <itemizedlist> 4821 <itemizedlist>