Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

set hashlen in bytes for skeins.

  • Loading branch information...
commit e1159a6dcfe8ad8202438069f45ba4ccde3fccae 1 parent f722dac
@vincenthz authored
View
8 Crypto/Hash/Skein256.hs
@@ -65,11 +65,11 @@ data Skein256 = Digest !ByteString
sizeCtx :: Int
sizeCtx = 88
+{- return the number of bytes of output for the digest -}
peekHashlen :: Ptr Ctx -> IO Int
-peekHashlen ptr = do
- let iptr = castPtr ptr :: Ptr CUInt
- a <- peek iptr
- return ((fromIntegral a + 7) `shiftR` 3)
+peekHashlen ptr = peek iptr >>= \v -> return $! fromIntegral v
+ where iptr :: Ptr Word32
+ iptr = castPtr ptr
{-# INLINE withByteStringPtr #-}
withByteStringPtr :: ByteString -> (Ptr Word8 -> IO a) -> IO a
View
8 Crypto/Hash/Skein512.hs
@@ -65,11 +65,11 @@ data Skein512 = Digest !ByteString
sizeCtx :: Int
sizeCtx = 152
+{- return the number of bytes of output for the digest -}
peekHashlen :: Ptr Ctx -> IO Int
-peekHashlen ptr = do
- let iptr = castPtr ptr :: Ptr CUInt
- a <- peek iptr
- return ((fromIntegral a + 7) `shiftR` 3)
+peekHashlen ptr = peek iptr >>= \v -> return $! fromIntegral v
+ where iptr :: Ptr Word32
+ iptr = castPtr ptr
{-# INLINE withByteStringPtr #-}
withByteStringPtr :: ByteString -> (Ptr Word8 -> IO a) -> IO a
View
4 cbits/skein256.c
@@ -108,7 +108,7 @@ void skein256_init(struct skein256_ctx *ctx, uint32_t hashlen)
uint64_t buf[4];
memset(ctx, 0, sizeof(*ctx));
- ctx->hashlen = hashlen;
+ ctx->hashlen = (hashlen + 7) >> 3;
SET_TYPE(ctx, FLAG_FIRST | FLAG_FINAL | FLAG_TYPE(TYPE_CFG));
memset(buf, '\0', sizeof(buf));
@@ -167,7 +167,7 @@ void skein256_finalize(struct skein256_ctx *ctx, uint8_t *out)
memset(ctx->buf, '\0', 32);
/* make sure we have a 8 bit rounded value */
- outsize = (ctx->hashlen + 7) >> 3;
+ outsize = ctx->hashlen;
/* backup h[0--4] */
for (j = 0; j < 4; j++)
View
4 cbits/skein512.c
@@ -126,7 +126,7 @@ void skein512_init(struct skein512_ctx *ctx, uint32_t hashlen)
uint64_t buf[8];
memset(ctx, 0, sizeof(*ctx));
- ctx->hashlen = hashlen;
+ ctx->hashlen = (hashlen + 7) >> 3;
SET_TYPE(ctx, FLAG_FIRST | FLAG_FINAL | FLAG_TYPE(TYPE_CFG));
memset(buf, '\0', sizeof(buf));
@@ -185,7 +185,7 @@ void skein512_finalize(struct skein512_ctx *ctx, uint8_t *out)
memset(ctx->buf, '\0', 64);
/* make sure we have a 8 bit rounded value */
- outsize = (ctx->hashlen + 7) >> 3;
+ outsize = ctx->hashlen;
/* backup h[0--7] */
for (j = 0; j < 8; j++)
View
2  cbits/skein512.h
@@ -28,7 +28,7 @@
struct skein512_ctx
{
- uint32_t hashlen; /* in bits, typically 384, 512 */
+ uint32_t hashlen; /* in bytes, typically 384/8, 512/8 */
uint32_t bufindex;
uint8_t buf[64];
uint64_t h[8];
Please sign in to comment.
Something went wrong with that request. Please try again.