Authenticator.swift 911 B

123456789101112131415161718192021222324252627282930313233343536
  1. //
  2. // MAC.swift
  3. // CryptoSwift
  4. //
  5. // Created by Marcin Krzyzanowski on 03/09/14.
  6. // Copyright (c) 2014 Marcin Krzyzanowski. All rights reserved.
  7. //
  8. import Foundation
  9. /**
  10. * Message Authentication
  11. */
  12. public enum Authenticator {
  13. /**
  14. Poly1305
  15. :param: key 256-bit key
  16. */
  17. case Poly1305(key: [UInt8])
  18. case HMAC(key: [UInt8], variant:CryptoSwift.HMAC.Variant)
  19. /**
  20. Generates an authenticator for message using a one-time key and returns the 16-byte result
  21. :returns: 16-byte message authentication code
  22. */
  23. public func authenticate(message: [UInt8]) -> [UInt8]? {
  24. switch (self) {
  25. case .Poly1305(let key):
  26. return CryptoSwift.Poly1305.authenticate(key: key, message: message)
  27. case .HMAC(let key, let variant):
  28. return CryptoSwift.HMAC.authenticate(key: key, message: message, variant: variant)
  29. }
  30. }
  31. }