Skip to content

Commit 78f3a26

Browse files
committed
Core: Internal: Hash: truncateDigest(->InNixWay)
Please, see the notes in the code.
1 parent 581ebcb commit 78f3a26

File tree

1 file changed

+5
-3
lines changed
  • hnix-store-core/src/System/Nix/Internal

1 file changed

+5
-3
lines changed

hnix-store-core/src/System/Nix/Internal/Hash.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ instance (ValidAlgo a, Kind.KnownNat n) => ValidAlgo ('Truncated n a) where
190190
type AlgoCtx ('Truncated n a) = AlgoCtx a
191191
initialize = initialize @a
192192
update = update @a
193-
finalize = truncateDigest @n . finalize @a
193+
finalize = truncateDigestInNixWay @n . finalize @a
194194

195195
-- | Bytewise truncation of a 'Digest'.
196196
--
@@ -199,9 +199,11 @@ instance (ValidAlgo a, Kind.KnownNat n) => ValidAlgo ('Truncated n a) where
199199
-- bytestring into a head part (truncation length) and tail part
200200
-- (leftover part), right-pads the leftovers with 0 to the truncation
201201
-- length, and combines the two strings bytewise with 'xor'.
202-
truncateDigest
202+
truncateDigestInNixWay
203203
:: forall n a .(Kind.KnownNat n) => Digest a -> Digest ('Truncated n a)
204-
truncateDigest (Digest c) =
204+
-- 2021-06-07: NOTE: ^ This is why all the cookery with DataKinds, trunkation length (if allowed arbitrary) needs to be represented in type.
205+
-- 2021-06-07: NOTE: Renamed function, since truncation can be done in a lot of ways, there is no practice of truncting hashes this way, moreover: <https://crypto.stackexchange.com/questions/56337/strength-of-hash-obtained-by-xor-of-parts-of-sha3>
206+
truncateDigestInNixWay (Digest c) =
205207
Digest $ BS.pack $ fmap truncOutputByte [0.. n-1]
206208
where
207209
n = fromIntegral $ Kind.natVal $ Proxy @n

0 commit comments

Comments
 (0)