2

I'm familiar with CryptoKit and the SHA512 implementation, which is super easy to use.

let digest = SHA512.hash(data: Data("".utf8))

However, I can't seem to find how to compute SHA512/256 (the truncated version of SHA512) anywhere in the Apple CryptoKit documentation. Do I somehow have to combine SHA512 with SHA256Digest?

vicegax
  • 4,709
  • 28
  • 37
Morgan Wilde
  • 16,795
  • 10
  • 53
  • 99
  • "I can't seem to find how to compute SHA512/256 anywhere" What do you mean? Isn't that exactly what your snippet is demonstrating? – Alexander Aug 21 '22 at 18:58
  • This is computing a digest using the `SHA512` algo, but I'm looking for the `SHA512/256` algo, it's distinct from `SHA512`. – Morgan Wilde Aug 21 '22 at 19:06
  • 1
    Oh interesting. I'd suggest clarifying those details into the question, for others not-in-the-know – Alexander Aug 21 '22 at 19:48
  • 4
    CryptoKit is pretty limited in what it offers. I don't know anything common that offers SHA512/256; I would probably look at adapting CryptoSwift. https://cryptoswift.io – Rob Napier Aug 22 '22 at 00:36
  • 2
    Apple's `CryptoKit` does not implement such algorithm. This'll leave you with the provided libraries (answer and comment) or NaCL maybe, or you can write your own implementation – Bram Aug 31 '22 at 14:55

1 Answers1

1

I think this pod will do the trick.

This has the implementation for SHA512/SHA256. (Check readme's HASH section: SHA-2)

Link: SHA512/SHA256 Lead

user3840170
  • 26,597
  • 4
  • 30
  • 62
  • I did check out this library and found it to be outdated in terms of the Swift code it's using. I was looking for a CryptoKit solution, if one exists. – Morgan Wilde Aug 26 '22 at 11:44
  • @MorganWilde For all you know the answer is ‘it doesn’t’ (though sure, it would be nice to write so explicitly), so why not accept an alternative package? – user3840170 Aug 26 '22 at 19:59