
dons:
-- Fast md5 using OpenSSL and non-copying bytestrings md5sum :: B.ByteString -> String md5sum p = unsafePerformIO $ B.unsafeUseAsCStringLen p $ \(ptr,n) -> do digest <- c_md5 ptr (fromIntegral n) nullPtr liftM concat $ forM [0..15] $ \n -> do w <- peekElemOff digest n return $ case showHex w [] of [x] -> ['0', x]; x -> x
-- unsigned char *MD5(const unsigned char *d, unsigned long n, unsigned char *md); foreign import ccall "openssl/md5.h MD5" c_md5 :: Ptr CChar -> CULong -> Ptr CChar -> IO (Ptr Word8)
ByteStrings were designed for this zero-copy passing of big data to C, by the way, so its a perfect fit.
by the way, I note we do have a binding to OpenSSL, of sorts: http://cryp.to/hopenssl/ But it needs updating to use ByteStrings. Would make a good project for someone into crypto. -- Don