Browse files

set hashlen in bytes for skeins.

  • Loading branch information...
1 parent f722dac commit e1159a6dcfe8ad8202438069f45ba4ccde3fccae @vincenthz committed Dec 7, 2012
Showing with 13 additions and 13 deletions.
  1. +4 −4 Crypto/Hash/Skein256.hs
  2. +4 −4 Crypto/Hash/Skein512.hs
  3. +2 −2 cbits/skein256.c
  4. +2 −2 cbits/skein512.c
  5. +1 −1 cbits/skein512.h
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];

0 comments on commit e1159a6

Please sign in to comment.