diff --git a/Crypto/Hash/Keccak.hs b/Crypto/Hash/Keccak.hs index 296947c..bd51abd 100644 --- a/Crypto/Hash/Keccak.hs +++ b/Crypto/Hash/Keccak.hs @@ -28,7 +28,7 @@ instance HashAlgorithm Keccak_224 where hashInternalContextSize _ = 360 hashInternalInit p = c_keccak_init p 224 hashInternalUpdate = c_keccak_update - hashInternalFinalize = c_keccak_finalize + hashInternalFinalize p = c_keccak_finalize p 224 -- | Keccak (256 bits) cryptographic hash algorithm data Keccak_256 = Keccak_256 @@ -40,7 +40,7 @@ instance HashAlgorithm Keccak_256 where hashInternalContextSize _ = 360 hashInternalInit p = c_keccak_init p 256 hashInternalUpdate = c_keccak_update - hashInternalFinalize = c_keccak_finalize + hashInternalFinalize p = c_keccak_finalize p 256 -- | Keccak (384 bits) cryptographic hash algorithm data Keccak_384 = Keccak_384 @@ -52,7 +52,7 @@ instance HashAlgorithm Keccak_384 where hashInternalContextSize _ = 360 hashInternalInit p = c_keccak_init p 384 hashInternalUpdate = c_keccak_update - hashInternalFinalize = c_keccak_finalize + hashInternalFinalize p = c_keccak_finalize p 384 -- | Keccak (512 bits) cryptographic hash algorithm data Keccak_512 = Keccak_512 @@ -64,7 +64,7 @@ instance HashAlgorithm Keccak_512 where hashInternalContextSize _ = 360 hashInternalInit p = c_keccak_init p 512 hashInternalUpdate = c_keccak_update - hashInternalFinalize = c_keccak_finalize + hashInternalFinalize p = c_keccak_finalize p 512 foreign import ccall unsafe "cryptonite_keccak_init" @@ -74,4 +74,4 @@ foreign import ccall "cryptonite_keccak_update" c_keccak_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO () foreign import ccall unsafe "cryptonite_keccak_finalize" - c_keccak_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO () + c_keccak_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO () diff --git a/Crypto/Hash/SHA3.hs b/Crypto/Hash/SHA3.hs index 7ecdfa8..ded49ee 100644 --- a/Crypto/Hash/SHA3.hs +++ b/Crypto/Hash/SHA3.hs @@ -28,7 +28,7 @@ instance HashAlgorithm SHA3_224 where hashInternalContextSize _ = 360 hashInternalInit p = c_sha3_init p 224 hashInternalUpdate = c_sha3_update - hashInternalFinalize = c_sha3_finalize + hashInternalFinalize p = c_sha3_finalize p 224 -- | SHA3 (256 bits) cryptographic hash algorithm data SHA3_256 = SHA3_256 @@ -40,7 +40,7 @@ instance HashAlgorithm SHA3_256 where hashInternalContextSize _ = 360 hashInternalInit p = c_sha3_init p 256 hashInternalUpdate = c_sha3_update - hashInternalFinalize = c_sha3_finalize + hashInternalFinalize p = c_sha3_finalize p 256 -- | SHA3 (384 bits) cryptographic hash algorithm data SHA3_384 = SHA3_384 @@ -52,7 +52,7 @@ instance HashAlgorithm SHA3_384 where hashInternalContextSize _ = 360 hashInternalInit p = c_sha3_init p 384 hashInternalUpdate = c_sha3_update - hashInternalFinalize = c_sha3_finalize + hashInternalFinalize p = c_sha3_finalize p 384 -- | SHA3 (512 bits) cryptographic hash algorithm data SHA3_512 = SHA3_512 @@ -64,7 +64,7 @@ instance HashAlgorithm SHA3_512 where hashInternalContextSize _ = 360 hashInternalInit p = c_sha3_init p 512 hashInternalUpdate = c_sha3_update - hashInternalFinalize = c_sha3_finalize + hashInternalFinalize p = c_sha3_finalize p 512 foreign import ccall unsafe "cryptonite_sha3_init" @@ -74,4 +74,4 @@ foreign import ccall "cryptonite_sha3_update" c_sha3_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO () foreign import ccall unsafe "cryptonite_sha3_finalize" - c_sha3_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO () + c_sha3_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO () diff --git a/Crypto/Hash/SHA512t.hs b/Crypto/Hash/SHA512t.hs index 5e0f7fc..e9e6ac7 100644 --- a/Crypto/Hash/SHA512t.hs +++ b/Crypto/Hash/SHA512t.hs @@ -28,7 +28,7 @@ instance HashAlgorithm SHA512t_224 where hashInternalContextSize _ = 264 hashInternalInit p = c_sha512t_init p 224 hashInternalUpdate = c_sha512t_update - hashInternalFinalize = c_sha512t_finalize + hashInternalFinalize p = c_sha512t_finalize p 224 -- | SHA512t (256 bits) cryptographic hash algorithm data SHA512t_256 = SHA512t_256 @@ -40,7 +40,7 @@ instance HashAlgorithm SHA512t_256 where hashInternalContextSize _ = 264 hashInternalInit p = c_sha512t_init p 256 hashInternalUpdate = c_sha512t_update - hashInternalFinalize = c_sha512t_finalize + hashInternalFinalize p = c_sha512t_finalize p 256 foreign import ccall unsafe "cryptonite_sha512t_init" @@ -50,4 +50,4 @@ foreign import ccall "cryptonite_sha512t_update" c_sha512t_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO () foreign import ccall unsafe "cryptonite_sha512t_finalize" - c_sha512t_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO () + c_sha512t_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO () diff --git a/Crypto/Hash/Skein256.hs b/Crypto/Hash/Skein256.hs index b5a97fb..883b0f7 100644 --- a/Crypto/Hash/Skein256.hs +++ b/Crypto/Hash/Skein256.hs @@ -28,7 +28,7 @@ instance HashAlgorithm Skein256_224 where hashInternalContextSize _ = 96 hashInternalInit p = c_skein256_init p 224 hashInternalUpdate = c_skein256_update - hashInternalFinalize = c_skein256_finalize + hashInternalFinalize p = c_skein256_finalize p 224 -- | Skein256 (256 bits) cryptographic hash algorithm data Skein256_256 = Skein256_256 @@ -40,7 +40,7 @@ instance HashAlgorithm Skein256_256 where hashInternalContextSize _ = 96 hashInternalInit p = c_skein256_init p 256 hashInternalUpdate = c_skein256_update - hashInternalFinalize = c_skein256_finalize + hashInternalFinalize p = c_skein256_finalize p 256 foreign import ccall unsafe "cryptonite_skein256_init" @@ -50,4 +50,4 @@ foreign import ccall "cryptonite_skein256_update" c_skein256_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO () foreign import ccall unsafe "cryptonite_skein256_finalize" - c_skein256_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO () + c_skein256_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO () diff --git a/Crypto/Hash/Skein512.hs b/Crypto/Hash/Skein512.hs index bd2de5d..de2367d 100644 --- a/Crypto/Hash/Skein512.hs +++ b/Crypto/Hash/Skein512.hs @@ -28,7 +28,7 @@ instance HashAlgorithm Skein512_224 where hashInternalContextSize _ = 160 hashInternalInit p = c_skein512_init p 224 hashInternalUpdate = c_skein512_update - hashInternalFinalize = c_skein512_finalize + hashInternalFinalize p = c_skein512_finalize p 224 -- | Skein512 (256 bits) cryptographic hash algorithm data Skein512_256 = Skein512_256 @@ -40,7 +40,7 @@ instance HashAlgorithm Skein512_256 where hashInternalContextSize _ = 160 hashInternalInit p = c_skein512_init p 256 hashInternalUpdate = c_skein512_update - hashInternalFinalize = c_skein512_finalize + hashInternalFinalize p = c_skein512_finalize p 256 -- | Skein512 (384 bits) cryptographic hash algorithm data Skein512_384 = Skein512_384 @@ -52,7 +52,7 @@ instance HashAlgorithm Skein512_384 where hashInternalContextSize _ = 160 hashInternalInit p = c_skein512_init p 384 hashInternalUpdate = c_skein512_update - hashInternalFinalize = c_skein512_finalize + hashInternalFinalize p = c_skein512_finalize p 384 -- | Skein512 (512 bits) cryptographic hash algorithm data Skein512_512 = Skein512_512 @@ -64,7 +64,7 @@ instance HashAlgorithm Skein512_512 where hashInternalContextSize _ = 160 hashInternalInit p = c_skein512_init p 512 hashInternalUpdate = c_skein512_update - hashInternalFinalize = c_skein512_finalize + hashInternalFinalize p = c_skein512_finalize p 512 foreign import ccall unsafe "cryptonite_skein512_init" @@ -74,4 +74,4 @@ foreign import ccall "cryptonite_skein512_update" c_skein512_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO () foreign import ccall unsafe "cryptonite_skein512_finalize" - c_skein512_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO () + c_skein512_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO () diff --git a/cbits/cryptonite_keccak.c b/cbits/cryptonite_keccak.c index 801be92..5e13551 100644 --- a/cbits/cryptonite_keccak.c +++ b/cbits/cryptonite_keccak.c @@ -135,7 +135,7 @@ void cryptonite_keccak_update(struct keccak_ctx *ctx, uint8_t *data, uint32_t le } } -void cryptonite_keccak_finalize(struct keccak_ctx *ctx, uint8_t *out) +void cryptonite_keccak_finalize(struct keccak_ctx *ctx, uint32_t hashlen, uint8_t *out) { uint64_t w[25]; diff --git a/cbits/cryptonite_keccak.h b/cbits/cryptonite_keccak.h index 9f77bb4..c83f4b6 100644 --- a/cbits/cryptonite_keccak.h +++ b/cbits/cryptonite_keccak.h @@ -40,6 +40,6 @@ struct keccak_ctx void cryptonite_keccak_init(struct keccak_ctx *ctx, uint32_t hashlen); void cryptonite_keccak_update(struct keccak_ctx *ctx, uint8_t *data, uint32_t len); -void cryptonite_keccak_finalize(struct keccak_ctx *ctx, uint8_t *out); +void cryptonite_keccak_finalize(struct keccak_ctx *ctx, uint32_t hashlen, uint8_t *out); #endif diff --git a/cbits/cryptonite_sha3.c b/cbits/cryptonite_sha3.c index 13bfea9..923150a 100644 --- a/cbits/cryptonite_sha3.c +++ b/cbits/cryptonite_sha3.c @@ -135,7 +135,7 @@ void cryptonite_sha3_update(struct sha3_ctx *ctx, const uint8_t *data, uint32_t } } -void cryptonite_sha3_finalize(struct sha3_ctx *ctx, uint8_t *out) +void cryptonite_sha3_finalize(struct sha3_ctx *ctx, uint32_t hashlen, uint8_t *out) { uint64_t w[25]; @@ -155,5 +155,5 @@ void cryptonite_sha3_finalize(struct sha3_ctx *ctx, uint8_t *out) /* output */ cpu_to_le64_array(w, ctx->state, 25); - memcpy(out, w, ctx->hashlen); + memcpy(out, w, hashlen / 8); } diff --git a/cbits/cryptonite_sha3.h b/cbits/cryptonite_sha3.h index 3b46441..1f78674 100644 --- a/cbits/cryptonite_sha3.h +++ b/cbits/cryptonite_sha3.h @@ -40,6 +40,6 @@ struct sha3_ctx void cryptonite_sha3_init(struct sha3_ctx *ctx, uint32_t hashlen); void cryptonite_sha3_update(struct sha3_ctx *ctx, const uint8_t *data, uint32_t len); -void cryptonite_sha3_finalize(struct sha3_ctx *ctx, uint8_t *out); +void cryptonite_sha3_finalize(struct sha3_ctx *ctx, uint32_t hashlen, uint8_t *out); #endif diff --git a/cbits/cryptonite_sha512.c b/cbits/cryptonite_sha512.c index f86042a..6adf028 100644 --- a/cbits/cryptonite_sha512.c +++ b/cbits/cryptonite_sha512.c @@ -196,15 +196,15 @@ void cryptonite_sha512_finalize(struct sha512_ctx *ctx, uint8_t *out) #include -void cryptonite_sha512t_init(struct sha512t_ctx *tctx, int t) +void cryptonite_sha512t_init(struct sha512t_ctx *tctx, uint32_t hashlen) { struct sha512_ctx *ctx = &tctx->ctx; memset(ctx, 0, sizeof(*ctx)); - if (t >= 512) + if (hashlen >= 512) return; - tctx->t = t; + tctx->t = hashlen; - switch (t) { + switch (hashlen) { case 224: ctx->h[0] = 0x8c3d37c819544da2ULL; ctx->h[1] = 0x73e1996689dcd4d6ULL; @@ -234,7 +234,7 @@ void cryptonite_sha512t_init(struct sha512t_ctx *tctx, int t) for (i = 0; i < 8; i++) ctx->h[i] ^= 0xa5a5a5a5a5a5a5a5ULL; - i = sprintf(buf, "SHA-512/%d", t); + i = sprintf(buf, "SHA-512/%d", hashlen); cryptonite_sha512_update(ctx, (uint8_t *) buf, i); cryptonite_sha512_finalize(ctx, out); @@ -251,7 +251,7 @@ void cryptonite_sha512t_update(struct sha512t_ctx *ctx, const uint8_t *data, uin return cryptonite_sha512_update(&ctx->ctx, data, len); } -void cryptonite_sha512t_finalize(struct sha512t_ctx *ctx, uint8_t *out) +void cryptonite_sha512t_finalize(struct sha512t_ctx *ctx, uint32_t hashlen, uint8_t *out) { uint8_t intermediate[SHA512_DIGEST_SIZE]; diff --git a/cbits/cryptonite_sha512.h b/cbits/cryptonite_sha512.h index 4b547ea..a762584 100644 --- a/cbits/cryptonite_sha512.h +++ b/cbits/cryptonite_sha512.h @@ -58,8 +58,8 @@ void cryptonite_sha512_update(struct sha512_ctx *ctx, const uint8_t *data, uint3 void cryptonite_sha512_finalize(struct sha512_ctx *ctx, uint8_t *out); /* only multiples of 8 are supported as valid t values */ -void cryptonite_sha512t_init(struct sha512t_ctx *ctx, int t); +void cryptonite_sha512t_init(struct sha512t_ctx *ctx, uint32_t hashlen); void cryptonite_sha512t_update(struct sha512t_ctx *ctx, const uint8_t *data, uint32_t len); -void cryptonite_sha512t_finalize(struct sha512t_ctx *ctx, uint8_t *out); +void cryptonite_sha512t_finalize(struct sha512t_ctx *ctx, uint32_t hashlen, uint8_t *out); #endif diff --git a/cbits/cryptonite_skein256.c b/cbits/cryptonite_skein256.c index a2f6e07..d851898 100644 --- a/cbits/cryptonite_skein256.c +++ b/cbits/cryptonite_skein256.c @@ -155,7 +155,7 @@ void cryptonite_skein256_update(struct skein256_ctx *ctx, const uint8_t *data, u } } -void cryptonite_skein256_finalize(struct skein256_ctx *ctx, uint8_t *out) +void cryptonite_skein256_finalize(struct skein256_ctx *ctx, uint32_t hashlen, uint8_t *out) { uint32_t outsize; uint64_t *p = (uint64_t *) out; diff --git a/cbits/cryptonite_skein256.h b/cbits/cryptonite_skein256.h index eaaa037..f23b43c 100644 --- a/cbits/cryptonite_skein256.h +++ b/cbits/cryptonite_skein256.h @@ -40,6 +40,6 @@ struct skein256_ctx void cryponite_skein256_init(struct skein256_ctx *ctx, uint32_t hashlen); void cryponite_skein256_update(struct skein256_ctx *ctx, const uint8_t *data, uint32_t len); -void cryponite_skein256_finalize(struct skein256_ctx *ctx, uint8_t *out); +void cryponite_skein256_finalize(struct skein256_ctx *ctx, uint32_t hashlen, uint8_t *out); #endif diff --git a/cbits/cryptonite_skein512.c b/cbits/cryptonite_skein512.c index 5e38e51..8f411ff 100644 --- a/cbits/cryptonite_skein512.c +++ b/cbits/cryptonite_skein512.c @@ -173,7 +173,7 @@ void cryptonite_skein512_update(struct skein512_ctx *ctx, const uint8_t *data, u } } -void cryptonite_skein512_finalize(struct skein512_ctx *ctx, uint8_t *out) +void cryptonite_skein512_finalize(struct skein512_ctx *ctx, uint32_t hashlen, uint8_t *out) { uint32_t outsize; uint64_t *p = (uint64_t *) out; diff --git a/cbits/cryptonite_skein512.h b/cbits/cryptonite_skein512.h index 069500c..e3f4ab6 100644 --- a/cbits/cryptonite_skein512.h +++ b/cbits/cryptonite_skein512.h @@ -40,6 +40,6 @@ struct skein512_ctx void cryponite_skein512_init(struct skein512_ctx *ctx, uint32_t hashlen); void cryponite_skein512_update(struct skein512_ctx *ctx, const uint8_t *data, uint32_t len); -void cryponite_skein512_finalize(struct skein512_ctx *ctx, uint8_t *out); +void cryponite_skein512_finalize(struct skein512_ctx *ctx, uint32_t hashlen, uint8_t *out); #endif diff --git a/gen/template/hash-len.hs b/gen/template/hash-len.hs index df2a7f9..9f7381d 100644 --- a/gen/template/hash-len.hs +++ b/gen/template/hash-len.hs @@ -28,7 +28,7 @@ instance HashAlgorithm %%MODULENAME%%_%%CUSTOM_BITSIZE%% where hashInternalContextSize _ = %%CTX_SIZE_BYTES%% hashInternalInit p = c_%%HASHNAME%%_init p %%CUSTOM_BITSIZE%% hashInternalUpdate = c_%%HASHNAME%%_update - hashInternalFinalize = c_%%HASHNAME%%_finalize + hashInternalFinalize p = c_%%HASHNAME%%_finalize p %%CUSTOM_BITSIZE%% %{CUSTOMIZABLE%} foreign import ccall unsafe "cryptonite_%%HASHNAME%%_init" @@ -38,4 +38,4 @@ foreign import ccall "cryptonite_%%HASHNAME%%_update" c_%%HASHNAME%%_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO () foreign import ccall unsafe "cryptonite_%%HASHNAME%%_finalize" - c_%%HASHNAME%%_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO () + c_%%HASHNAME%%_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO ()