packages feed

SecureHash-SHA3 0.1.0.2 → 0.1.1.0

raw patch · 5 files changed

+60/−66 lines, 5 filesdep ~basedep ~bytestringPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: base, bytestring

API changes (from Hackage documentation)

+ Crypto.SecureHash.SHA3: sha3_228 :: ByteString -> ByteString
+ Crypto.SecureHash.SHA3: sha3_256 :: ByteString -> ByteString
+ Crypto.SecureHash.SHA3: sha3_384 :: ByteString -> ByteString
- Crypto.SecureHash.SHA3.FFI: c_safe_FIPS202_SHA3_224 :: Ptr Word8 -> CUInt -> Ptr Word8 -> IO ()
+ Crypto.SecureHash.SHA3.FFI: c_safe_FIPS202_SHA3_224 :: Ptr Word8 -> Word64 -> Ptr Word8 -> IO ()
- Crypto.SecureHash.SHA3.FFI: c_safe_FIPS202_SHA3_256 :: Ptr Word8 -> CUInt -> Ptr Word8 -> IO ()
+ Crypto.SecureHash.SHA3.FFI: c_safe_FIPS202_SHA3_256 :: Ptr Word8 -> Word64 -> Ptr Word8 -> IO ()
- Crypto.SecureHash.SHA3.FFI: c_safe_FIPS202_SHA3_384 :: Ptr Word8 -> CUInt -> Ptr Word8 -> IO ()
+ Crypto.SecureHash.SHA3.FFI: c_safe_FIPS202_SHA3_384 :: Ptr Word8 -> Word64 -> Ptr Word8 -> IO ()
- Crypto.SecureHash.SHA3.FFI: c_safe_FIPS202_SHA3_512 :: Ptr Word8 -> Word32 -> Ptr Word8 -> IO ()
+ Crypto.SecureHash.SHA3.FFI: c_safe_FIPS202_SHA3_512 :: Ptr Word8 -> Word64 -> Ptr Word8 -> IO ()
- Crypto.SecureHash.SHA3.FFI: c_safe_FIPS202_SHAKE128 :: Ptr Word8 -> CUInt -> Ptr Word8 -> CUInt -> IO ()
+ Crypto.SecureHash.SHA3.FFI: c_safe_FIPS202_SHAKE128 :: Ptr Word8 -> Word64 -> Ptr Word8 -> Word64 -> IO ()
- Crypto.SecureHash.SHA3.FFI: c_safe_FIPS202_SHAKE256 :: Ptr Word8 -> CUInt -> Ptr Word8 -> CUInt -> IO ()
+ Crypto.SecureHash.SHA3.FFI: c_safe_FIPS202_SHAKE256 :: Ptr Word8 -> Word64 -> Ptr Word8 -> Word64 -> IO ()
- Crypto.SecureHash.SHA3.FFI: c_unsafe_FIPS202_SHA3_224 :: Ptr Word8 -> CUInt -> Ptr Word8 -> IO ()
+ Crypto.SecureHash.SHA3.FFI: c_unsafe_FIPS202_SHA3_224 :: Ptr Word8 -> Word64 -> Ptr Word8 -> IO ()
- Crypto.SecureHash.SHA3.FFI: c_unsafe_FIPS202_SHA3_256 :: Ptr Word8 -> CUInt -> Ptr Word8 -> IO ()
+ Crypto.SecureHash.SHA3.FFI: c_unsafe_FIPS202_SHA3_256 :: Ptr Word8 -> Word64 -> Ptr Word8 -> IO ()
- Crypto.SecureHash.SHA3.FFI: c_unsafe_FIPS202_SHA3_384 :: Ptr Word8 -> CUInt -> Ptr Word8 -> IO ()
+ Crypto.SecureHash.SHA3.FFI: c_unsafe_FIPS202_SHA3_384 :: Ptr Word8 -> Word64 -> Ptr Word8 -> IO ()
- Crypto.SecureHash.SHA3.FFI: c_unsafe_FIPS202_SHA3_512 :: Ptr Word8 -> Word32 -> Ptr Word8 -> IO ()
+ Crypto.SecureHash.SHA3.FFI: c_unsafe_FIPS202_SHA3_512 :: Ptr Word8 -> Word64 -> Ptr Word8 -> IO ()
- Crypto.SecureHash.SHA3.FFI: c_unsafe_FIPS202_SHAKE128 :: Ptr Word8 -> CUInt -> Ptr Word8 -> CUInt -> IO ()
+ Crypto.SecureHash.SHA3.FFI: c_unsafe_FIPS202_SHAKE128 :: Ptr Word8 -> Word64 -> Ptr Word8 -> Word64 -> IO ()
- Crypto.SecureHash.SHA3.FFI: c_unsafe_FIPS202_SHAKE256 :: Ptr Word8 -> CUInt -> Ptr Word8 -> CUInt -> IO ()
+ Crypto.SecureHash.SHA3.FFI: c_unsafe_FIPS202_SHAKE256 :: Ptr Word8 -> Word64 -> Ptr Word8 -> Word64 -> IO ()

Files

CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for SecureHash-SHA3 +## 0.1.1.0 -- 2019-01-25+* added 256, 228, 384 size hash output variants of sha3, to round out the+  initial 512 bit one!+ ## 0.1.0.2 -- 2018-12-01  * First version that builds with both GCC and CLANG
SecureHash-SHA3.cabal view
@@ -11,7 +11,7 @@ -- PVP summary:      +-+------- breaking API changes --                   | | +----- non-breaking API additions --                   | | | +--- code changes with no API change-version:             0.1.0.2+version:             0.1.1.0  -- A short (one-line) description of the package. synopsis:            simple static linked SHA3 using private symbols and the ref impl
cbits/CTS_SHA3.h view
@@ -1,6 +1,6 @@ #ifndef HS_SECUREHASH_SHA3_H #define HS_SECUREHASH_SHA3_H-+#include<stdint.h> /* Implementation by the Keccak Team, namely, Guido Bertoni, Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer,@@ -72,12 +72,12 @@   * @param  outputByteLen   The number of output bytes desired.   * @pre    One must have r+c=1600 and the rate a multiple of 8 bits in this implementation.   */-static void CTS_Keccak(unsigned int rate, unsigned int capacity, const unsigned char *input, unsigned long long int inputByteLen, unsigned char delimitedSuffix, unsigned char *output, unsigned long long int outputByteLen);+static void CTS_Keccak(unsigned int rate, unsigned int capacity, const unsigned char *input, uint64_t inputByteLen, unsigned char delimitedSuffix, unsigned char *output, uint64_t outputByteLen);  /**   *  Function to compute SHAKE128 on the input message with any output length.   */-static void CTS_FIPS202_SHAKE128(const unsigned char *input, unsigned int inputByteLen, unsigned char *output, int outputByteLen)+static void CTS_FIPS202_SHAKE128(const unsigned char *input, uint64_t inputByteLen, unsigned char *output, uint64_t outputByteLen) {     CTS_Keccak(1344, 256, input, inputByteLen, 0x1F, output, outputByteLen); }@@ -85,7 +85,7 @@ /**   *  Function to compute SHAKE256 on the input message with any output length.   */-static void CTS_FIPS202_SHAKE256(const unsigned char *input, unsigned int inputByteLen, unsigned char *output, int outputByteLen)+static void CTS_FIPS202_SHAKE256(const unsigned char *input, uint64_t inputByteLen, unsigned char *output, uint64_t outputByteLen) {     CTS_Keccak(1088, 512, input, inputByteLen, 0x1F, output, outputByteLen); }@@ -93,7 +93,7 @@ /**   *  Function to compute SHA3-224 on the input message. The output length is fixed to 28 bytes.   */-static void CTS_FIPS202_SHA3_224(const unsigned char *input, unsigned int inputByteLen, unsigned char *output)+static void CTS_FIPS202_SHA3_224(const unsigned char *input, uint64_t inputByteLen, unsigned char *output) {     CTS_Keccak(1152, 448, input, inputByteLen, 0x06, output, 28); }@@ -101,7 +101,7 @@ /**   *  Function to compute SHA3-256 on the input message. The output length is fixed to 32 bytes.   */-static void CTS_FIPS202_SHA3_256(const unsigned char *input, unsigned int inputByteLen, unsigned char *output)+static void CTS_FIPS202_SHA3_256(const unsigned char *input, uint64_t inputByteLen, unsigned char *output) {     CTS_Keccak(1088, 512, input, inputByteLen, 0x06, output, 32); }@@ -109,7 +109,7 @@ /**   *  Function to compute SHA3-384 on the input message. The output length is fixed to 48 bytes.   */-static void CTS_FIPS202_SHA3_384(const unsigned char *input, unsigned int inputByteLen, unsigned char *output)+static void CTS_FIPS202_SHA3_384(const unsigned char *input, uint64_t inputByteLen, unsigned char *output) {     CTS_Keccak(832, 768, input, inputByteLen, 0x06, output, 48); }@@ -133,7 +133,7 @@ */  typedef unsigned char UINT8;-typedef unsigned long long int UINT64;+typedef uint64_t UINT64; typedef UINT64 tKeccakLane;  #ifndef LITTLE_ENDIAN@@ -300,7 +300,7 @@ #include <string.h> #define MIN(a, b) ((a) < (b) ? (a) : (b)) -static void CTS_Keccak(unsigned int rate, unsigned int capacity, const unsigned char *input, unsigned long long int inputByteLen, unsigned char delimitedSuffix, unsigned char *output, unsigned long long int outputByteLen)+static void CTS_Keccak(unsigned int rate, unsigned int capacity, const unsigned char *input, uint64_t inputByteLen, unsigned char delimitedSuffix, unsigned char *output, uint64_t outputByteLen) {     UINT8 state[200];     unsigned int rateInBytes = rate/8;
src/Crypto/SecureHash/SHA3.hs view
@@ -1,7 +1,12 @@ {-# LANGUAGE BangPatterns #-} {-# LANGUAGE Trustworthy  #-}-module Crypto.SecureHash.SHA3(sha3_512) where+{- | This module exposes the reference sha3 functions with digest sizes ++-}++module Crypto.SecureHash.SHA3(sha3_512,sha3_256,sha3_228, sha3_384) where+ import Crypto.SecureHash.SHA3.FFI import qualified Data.ByteString as BS import Data.ByteString (ByteString)@@ -12,12 +17,12 @@ import System.IO.Unsafe (unsafeDupablePerformIO)  import Foreign.Ptr-import Data.Word (Word8,Word32)+import Data.Word (Word8,Word64)    {-# INLINE withByteStringPtr #-}-withByteStringPtr :: ByteString -> Word32 -> (Ptr Word8  -> Word32 ->  Ptr Word8-> IO ()) -> IO ByteString+withByteStringPtr :: ByteString -> Word64 -> (Ptr Word8  -> Word64 ->  Ptr Word8-> IO ()) -> IO ByteString withByteStringPtr b resSize f =     withForeignPtr fptr $ \ptr ->           create (fromIntegral resSize) $ \resPtr -> f (ptr `plusPtr` off) (fromIntegral $ BS.length b) resPtr@@ -26,16 +31,30 @@ unsafeDoIO :: IO a -> a unsafeDoIO = unsafeDupablePerformIO -sha3_512_IO :: BS.ByteString -> IO ByteString-sha3_512_IO bsIn = withByteStringPtr bsIn  64 c_FIPS202_SHA3_512 +{-# INLINE hoistedSha3App #-}+hoistedSha3App :: Word64 -> (Ptr Word8 -> Word64 -> Ptr Word8 -> IO ()) -> (ByteString ->  ByteString)+hoistedSha3App = \size f -> (\bsIn ->  unsafeDoIO $  withByteStringPtr bsIn  size f) -sha3_512 :: BS.ByteString ->  ByteString-sha3_512 = (\x -> unsafeDoIO (sha3_512_IO x))+sha3_512 :: ByteString ->  ByteString+sha3_512 =  wrappedSha3 64  c_safe_FIPS202_SHA3_512 c_unsafe_FIPS202_SHA3_512 -c_FIPS202_SHA3_512 :: Ptr Word8 -> Word32 -> Ptr Word8 -> IO ()-c_FIPS202_SHA3_512 ptrIn size ptrOut =-    if size >= 1024-      then c_safe_FIPS202_SHA3_512 ptrIn size ptrOut-      else c_unsafe_FIPS202_SHA3_512 ptrIn size ptrOut+sha3_228 :: ByteString -> ByteString+sha3_228 = wrappedSha3 28 c_safe_FIPS202_SHA3_224 c_unsafe_FIPS202_SHA3_224++sha3_256 :: ByteString -> ByteString+sha3_256 = wrappedSha3 32 c_safe_FIPS202_SHA3_256 c_unsafe_FIPS202_SHA3_256++sha3_384 :: ByteString -> ByteString+sha3_384 = wrappedSha3 48 c_safe_FIPS202_SHA3_384 c_unsafe_FIPS202_SHA3_384++wrappedSha3 :: Word64 -> (Ptr Word8 -> Word64 -> Ptr Word8 -> IO ())+      -> (Ptr Word8 -> Word64 -> Ptr Word8 -> IO ())+      -> (ByteString -> ByteString)+wrappedSha3 = \resSize safeF unsafeF ->+  hoistedSha3App resSize $ \ ptrIn size ptrOut ->+  if size >= 1024+      then safeF ptrIn size ptrOut+      else unsafeF ptrIn size ptrOut+ 
src/Crypto/SecureHash/SHA3/FFI.hs view
@@ -15,12 +15,14 @@  module Crypto.SecureHash.SHA3.FFI where -import Foreign.C.Types+-- import Foreign.C.Types import Foreign.Ptr import Data.Word + {- + /* *   *  Function to compute SHA3-512 on the input message. The output length is fixed to 64 bytes.   */@@ -37,66 +39,35 @@  -} foreign import capi unsafe "CTS_SHA3.h CTS_FIPS202_SHA3_512"-  c_unsafe_FIPS202_SHA3_512 :: Ptr Word8 -> Word32 -> Ptr Word8 -> IO ()+  c_unsafe_FIPS202_SHA3_512 :: Ptr Word8 -> Word64 -> Ptr Word8 -> IO () foreign import capi safe "CTS_SHA3.h CTS_FIPS202_SHA3_512"-  c_safe_FIPS202_SHA3_512 :: Ptr Word8 -> Word32 -> Ptr Word8 -> IO ()+  c_safe_FIPS202_SHA3_512 :: Ptr Word8 -> Word64 -> Ptr Word8 -> IO ()  foreign import capi unsafe "CTS_SHA3.h CTS_FIPS202_SHA3_256"-  c_unsafe_FIPS202_SHA3_256 :: Ptr Word8 -> CUInt -> Ptr Word8 -> IO ()+  c_unsafe_FIPS202_SHA3_256 :: Ptr Word8 -> Word64 -> Ptr Word8 -> IO () foreign import capi safe "CTS_SHA3.h CTS_FIPS202_SHA3_256"-  c_safe_FIPS202_SHA3_256 :: Ptr Word8 -> CUInt -> Ptr Word8 -> IO ()+  c_safe_FIPS202_SHA3_256 :: Ptr Word8 -> Word64 -> Ptr Word8 -> IO ()  foreign import capi unsafe "CTS_SHA3.h CTS_FIPS202_SHA3_224"-  c_unsafe_FIPS202_SHA3_224 :: Ptr Word8 -> CUInt -> Ptr Word8 -> IO ()+  c_unsafe_FIPS202_SHA3_224 :: Ptr Word8 -> Word64 -> Ptr Word8 -> IO () foreign import capi safe "CTS_SHA3.h CTS_FIPS202_SHA3_224"-  c_safe_FIPS202_SHA3_224 :: Ptr Word8 -> CUInt -> Ptr Word8 -> IO ()+  c_safe_FIPS202_SHA3_224 :: Ptr Word8 -> Word64 -> Ptr Word8 -> IO ()   foreign import capi unsafe "CTS_SHA3.h CTS_FIPS202_SHA3_384"-  c_unsafe_FIPS202_SHA3_384 :: Ptr Word8 -> CUInt -> Ptr Word8 -> IO ()+  c_unsafe_FIPS202_SHA3_384 :: Ptr Word8 -> Word64 -> Ptr Word8 -> IO () foreign import capi safe "CTS_SHA3.h CTS_FIPS202_SHA3_384"-  c_safe_FIPS202_SHA3_384 :: Ptr Word8 -> CUInt -> Ptr Word8 -> IO ()+  c_safe_FIPS202_SHA3_384 :: Ptr Word8 -> Word64 -> Ptr Word8 -> IO ()   foreign import capi unsafe "CTS_SHA3.h CTS_FIPS202_SHAKE128"-  c_unsafe_FIPS202_SHAKE128 :: Ptr Word8 -> CUInt -> Ptr Word8 -> CUInt -> IO ()+  c_unsafe_FIPS202_SHAKE128 :: Ptr Word8 -> Word64 -> Ptr Word8 -> Word64 -> IO () foreign import capi safe "CTS_SHA3.h CTS_FIPS202_SHAKE128"-  c_safe_FIPS202_SHAKE128 :: Ptr Word8 -> CUInt -> Ptr Word8 -> CUInt -> IO ()+  c_safe_FIPS202_SHAKE128 :: Ptr Word8 -> Word64 -> Ptr Word8 -> Word64-> IO ()   foreign import capi unsafe "CTS_SHA3.h CTS_FIPS202_SHAKE256"-  c_unsafe_FIPS202_SHAKE256 :: Ptr Word8 -> CUInt -> Ptr Word8 -> CUInt -> IO ()+  c_unsafe_FIPS202_SHAKE256 :: Ptr Word8 -> Word64 -> Ptr Word8 -> Word64 -> IO () foreign import capi safe "CTS_SHA3.h CTS_FIPS202_SHAKE256"-  c_safe_FIPS202_SHAKE256 :: Ptr Word8 -> CUInt -> Ptr Word8 -> CUInt -> IO ()---{-- /Users/carter/WorkSpace/active/SecureHash-SHA3/cbits/CTS_SHA3.h: line 80, column 1:-    error:-     warning: unused function 'CTS_FIPS202_SHAKE128' [-Wunused-function]-   |-80 | static void CTS_FIPS202_SHAKE128(const unsigned char *input, unsigned int inputByteLen, unsigned char *output, int outputByteLen)-   |             ^--  /Users/carter/WorkSpace/active/SecureHash-SHA3/cbits/CTS_SHA3.h: line 88, column 1:-    error:-     warning: unused function 'CTS_FIPS202_SHAKE256' [-Wunused-function]-   |-88 | static void CTS_FIPS202_SHAKE256(const unsigned char *input, unsigned int inputByteLen, unsigned char *output, int outputByteLen)-   |             ^--  /Users/carter/WorkSpace/active/SecureHash-SHA3/cbits/CTS_SHA3.h: line 96, column 1:-    error:-     warning: unused function 'CTS_FIPS202_SHA3_224' [-Wunused-function]-   |-96 | static void CTS_FIPS202_SHA3_224(const unsigned char *input, unsigned int inputByteLen, unsigned char *output)-   |             ^--  /Users/carter/WorkSpace/active/SecureHash-SHA3/cbits/CTS_SHA3.h: line 112, column 1:-    error:-     warning: unused function 'CTS_FIPS202_SHA3_384' [-Wunused-function]-    |-112 | static void CTS_FIPS202_SHA3_384(const unsigned char *input, unsigned int inputByteLen, unsigned char *output)-    |             ^+  c_safe_FIPS202_SHAKE256 :: Ptr Word8 -> Word64 -> Ptr Word8 -> Word64 -> IO () --}