Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
set hashlen in bytes for skeins.
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenthz committed Dec 7, 2012
1 parent f722dac commit e1159a6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Crypto/Hash/Skein256.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Crypto/Hash/Skein512.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cbits/skein256.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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++)
Expand Down
4 changes: 2 additions & 2 deletions cbits/skein512.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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++)
Expand Down
2 changes: 1 addition & 1 deletion cbits/skein512.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit e1159a6

Please sign in to comment.