packages feed

entropy 0.3 → 0.3.1

raw patch · 4 files changed

+61/−7 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

System/EntropyNix.hs view
@@ -24,7 +24,15 @@ import Foreign.C.Types import Data.ByteString.Internal as B +#ifdef arch_i386+-- See .cabal wrt GCC 4.8.2 asm compilation bug+#undef HAVE_RDRAND+#endif+ #ifdef XEN+#ifndef HAVE_RDRAND+#error "The entropy package requires RDRAND support when using the halvm/Xen"+#endif data CryptHandle = UseRdRand -- or die trying #else @@ -108,4 +116,3 @@ cpuHasRdRand :: IO Bool cpuHasRdRand = (/= 0) `fmap` c_cpu_has_rdrand #endif-
cbits/rdrand.c view
@@ -20,6 +20,7 @@      return (int) err; } +#ifdef arch_x86_64 // Returns 0 on success, non-zero on failure. int get_rand_bytes(uint8_t *therand, size_t len) {@@ -51,5 +52,48 @@     }     return fail; }+#endif /* x86-64 */++#ifdef arch_i386+// Returns 1 on success+inline int _rdrand32_step(uint32_t *therand)+{+     unsigned char err;+     asm volatile("rdrand %0 ; setc %1"+                 : "=r" (*therand), "=qm" (err));+     return (int) err;+}++int get_rand_bytes(uint8_t *therand, size_t len)+{+    int cnt;+    int fail=0;+    uint8_t *p = therand;+    uint8_t *end = therand + len;+    if((uint32_t)p % sizeof(uint32_t) != 0) {+        uint32_t tmp;+        fail |= !_rdrand32_step(&tmp);+        while((uint32_t)p % sizeof(uint32_t) != 0 && p != end) {+            *p = (uint8_t)(tmp & 0xFF);+            tmp = tmp >> 8;+            p++;+        }+    }+    for(; p <= end - sizeof(uint32_t); p+=sizeof(uint32_t)) {+        fail |= !_rdrand32_step((uint32_t *)p);+    }+    if(p != end) {+        uint32_t tmp;+        int cnt;+        fail |= !_rdrand32_step(&tmp);+        while(p != end) {+            *p = (uint8_t)(tmp & 0xFF);+            tmp = tmp >> 8;+            p++;+        }+    }+    return fail;+}+#endif /* i386 */  #endif // RDRAND
cbits/rdrand.h view
@@ -2,11 +2,9 @@ #ifdef HAVE_RDRAND #include <stdint.h> -#ifdef arch_x86_64 int cpu_has_rdrand()  // Returns 0 on success, non-zero on failure. int get_rand_bytes(uint8_t *therand, size_t len)-#endif /* arch_x86_64 */ #endif // HAVE_RDRAND #endif // rdrand_h
entropy.cabal view
@@ -1,9 +1,9 @@ name:           entropy-version:        0.3+version:        0.3.1 description:    A platform independent method to obtain cryptographically strong entropy -                (urandom on Linux, CryptAPI on Windows, patches welcome). +                (RDRAND when available anywhere, urandom on nix, CryptAPI on Windows, patches welcome).                 Users looking for cryptographically strong (number-theoretically-                sound) PRNGs should see the 'DRBG' package too!+                sound) PRNGs should see the 'DRBG' package too. synopsis:       A platform independent entropy source license:        BSD3 license-file:   LICENSE@@ -19,7 +19,7 @@ build-type:        Custom -- ^^ Test for RDRAND support using 'ghc' cabal-version:  >=1.10-tested-with:    GHC == 7.6.3+tested-with:    GHC == 7.8.2 -- data-files: extra-source-files:   ./cbits/rdrand.c, ./cbits/rdrand.h, README.md @@ -29,6 +29,7 @@ flag halvm     description:        Build for the HaLVM     default:            False+ library   ghc-options:  -O2   exposed-modules: System.Entropy@@ -41,10 +42,14 @@   default-language:    Haskell2010   if(flag(halvm))     cpp-options: -DXEN -DHAVE_RDRAND+    cc-options:  -DXEN -DHAVE_RDRAND   if arch(x86_64)     cpp-options: -Darch_x86_64+    -- gcc 4.8.2 on i386 fails to compile rdrand.c when using -fPIC!     c-sources:    cbits/rdrand.c     include-dirs: cbits+  if arch(i386)+    cpp-options: -Darch_i386   if os(windows)     cpp-options: -DisWindows     extra-libraries: advapi32