Does swift have default support for SHA3-256 hashing algorithm for all devices iOS 12 and above?
Support for SHA3 algorithm
[Wow, my response was completely wrong, confusing SHA-2 and SHA-3. See RandomBits’s answer below. Sorry about the mixup.]
Does swift have default support for SHA3-256 hashing algorithm for all devices iOS 12 and above?
Yes.
Just to be clear, SHA-3 is a family of algorithms based on the bit size (224, 256, 384, 512). Most folks leave out the 3, rendering SHA-3/256 as SHA-256.
With that in mind:
-
Apple CryptoKit supports the 256-, 384-, and 512-bit variants. This requires iOS 13. -
Common Crypto (<CommonCrypto/CommonDigest.h>
) supports all four variants all the way back to the dawn of iOS.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
According to the linked Apple CryptoKit documentation, only the SHA-2 algorithms are supported, e.g.:
An implementation of Secure Hashing Algorithm 2 (SHA-2) hashing with a 256-bit digest.
This is easily verified by comparing the result of using CryptoKit with any of the online digest tools. For example, the SHA-2/256 bit digest for the empty string is:
E3B0 C442 98FC 1C14 9AFB F4C8 996F B924 27AE 41E4 649B 934C A495 991B 7852 B855
The SHA-3 family of algorithms is supported by the CryptoSwift package available from GitHub. Note, this is not the Apple curated swift-crypto
package (which is excellent, but mostly mirrors CryptoKit).
My understanding is that the SHA-2 family of algorithms are often referred to as simply SHA while the SHA-3 family of algorithms are explicitly referred to as SHA-3 since they are more recent (released 2015).