Try to fix incorrect non-Latin handling on Win32 filenames.
[libdcp.git] / asdcplib / src / KM_prng.cpp
index 5212595f8b4669725b1f1ddcfe361e618138220b..463ae15752cf30d05987570737e33e6540a0d19f 100755 (executable)
@@ -1,3 +1,5 @@
+/* -*- c-basic-offset: 2; -*- */
+
 /*
 Copyright (c) 2006-2009, John Hurst
 All rights reserved.
@@ -48,7 +50,6 @@ using namespace Kumu;
 const char* DEV_URANDOM = "/dev/urandom";
 #endif // KM_WIN32
 
-
 const ui32_t RNG_KEY_SIZE = 512UL;
 const ui32_t RNG_KEY_SIZE_BITS = 256UL;
 const ui32_t RNG_BLOCK_SIZE = 16UL;
@@ -64,6 +65,7 @@ public:
   AES_KEY   m_Context;
   byte_t    m_ctr_buf[RNG_BLOCK_SIZE];
   Mutex     m_Lock;
+  unsigned int m_libdcp_test_rng_state;
 
   h__RNG()
   {
@@ -97,6 +99,10 @@ public:
     } // end AutoMutex context
 
     set_key(rng_key);
+
+#ifdef LIBDCP_POSIX    
+    reset();
+#endif    
   }
        
   //
@@ -138,7 +144,26 @@ public:
        AES_encrypt(m_ctr_buf, tmp, &m_Context);
        memcpy(buf + gen_count, tmp, len - gen_count);
       }
+
+#ifdef LIBDCP_POSIX
+    if (libdcp_test)
+      {    
+        for (unsigned int i = 0; i < len; ++i)
+         buf[i] = rand_r(&m_libdcp_test_rng_state);
+      }
+#endif
+
+#ifdef LIBDCP_WINDOWS
+    /* XXX */
+#endif
   }
+
+#ifdef LIBDCP_POSIX  
+  void reset ()
+  {
+    m_libdcp_test_rng_state = 1;
+  }
+#endif  
 };
 
 
@@ -192,6 +217,14 @@ Kumu::FortunaRNG::FillRandom(Kumu::ByteString& Buffer)
   return Buffer.Data();
 }
 
+#ifdef LIBDCP_POSIX
+void
+Kumu::FortunaRNG::Reset()
+{
+  s_RNG->reset();
+}
+#endif
+
 //------------------------------------------------------------------------------------------
 
 //