Digest.swift 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // Hash.swift
  3. // CryptoSwift
  4. //
  5. // Created by Marcin Krzyzanowski on 07/08/14.
  6. // Copyright (c) 2014 Marcin Krzyzanowski. All rights reserved.
  7. //
  8. @available(*, deprecated:0.6.0, renamed: "Digest")
  9. public typealias Hash = Digest
  10. /// Hash functions to calculate Digest.
  11. public struct Digest {
  12. /// Calculate MD5 Digest
  13. /// - parameter bytes: input message
  14. /// - returns: Digest bytes
  15. public static func md5(_ bytes: Array<UInt8>) -> Array<UInt8> {
  16. return MD5().calculate(for: bytes)
  17. }
  18. /// Calculate SHA1 Digest
  19. /// - parameter bytes: input message
  20. /// - returns: Digest bytes
  21. public static func sha1(_ bytes: Array<UInt8>) -> Array<UInt8> {
  22. return SHA1().calculate(for: bytes)
  23. }
  24. /// Calculate SHA2-224 Digest
  25. /// - parameter bytes: input message
  26. /// - returns: Digest bytes
  27. public static func sha224(_ bytes: Array<UInt8>) -> Array<UInt8> {
  28. return SHA2(variant: .sha224).calculate(for: bytes)
  29. }
  30. /// Calculate SHA2-256 Digest
  31. /// - parameter bytes: input message
  32. /// - returns: Digest bytes
  33. public static func sha256(_ bytes: Array<UInt8>) -> Array<UInt8> {
  34. return SHA2(variant: .sha256).calculate(for: bytes)
  35. }
  36. /// Calculate SHA2-384 Digest
  37. /// - parameter bytes: input message
  38. /// - returns: Digest bytes
  39. public static func sha384(_ bytes: Array<UInt8>) -> Array<UInt8> {
  40. return SHA2(variant: .sha384).calculate(for: bytes)
  41. }
  42. /// Calculate SHA2-512 Digest
  43. /// - parameter bytes: input message
  44. /// - returns: Digest bytes
  45. public static func sha512(_ bytes: Array<UInt8>) -> Array<UInt8> {
  46. return SHA2(variant: .sha512).calculate(for: bytes)
  47. }
  48. /// Calculate SHA3 Digest
  49. /// - parameter bytes: input message
  50. /// - parameter variant: SHA-3 variant
  51. /// - returns: Digest bytes
  52. public static func sha3(_ bytes: Array<UInt8>, variant: SHA3.Variant) -> Array<UInt8> {
  53. return SHA3(variant: variant).calculate(for: bytes)
  54. }
  55. }