HMAC

public struct HMAC<H> : MACAlgorithm where H : HashFunction

Performs HMAC - Keyed-Hashing for Message Authentication Reference: https://tools.ietf.org/html/rfc2104

  • Key

    Undocumented

    Declaration

    Swift

    public typealias Key = SymmetricKey
  • MAC

    Undocumented

    Declaration

    Swift

    public typealias MAC = HashedAuthenticationCode<H>
  • Verifies a tag of a Message Authentication Code. The comparison is done in constant-time.

    Declaration

    Swift

    public static func isValidAuthenticationCode(_ mac: MAC, authenticating bufferPointer: UnsafeRawBufferPointer, using key: SymmetricKey) -> Bool

    Parameters

    key

    The key used to authenticate the data

    data

    The data to authenticate

    mac

    The MAC to verify

    Return Value

    Returns true if the MAC is valid. False otherwise.

  • Initializes an incremental HMAC

    Declaration

    Swift

    public init(key: SymmetricKey)

    Parameters

    key

    The key to use for HMAC.

  • Computes a Message Authentication Code.

    Declaration

    Swift

    public static func authenticationCode<D>(for data: D, using key: SymmetricKey) -> MAC where D : DataProtocol

    Parameters

    key

    The key used to authenticate the data

    data

    The data to authenticate

    Return Value

    A Message Authentication Code

  • Verifies a Message Authentication Code. The comparison is done in constant-time.

    Declaration

    Swift

    public static func isValidAuthenticationCode<D>(_ authenticationCode: MAC, authenticating authenticatedData: D, using key: SymmetricKey) -> Bool where D : DataProtocol

    Parameters

    authenticationCode

    The authentication code

    authenticatedData

    Authenticated Data

    key

    The key to authenticate the data with

    Return Value

    Returns true if the MAC is valid. False otherwise.

  • Verifies a Message Authentication Code. The comparison is done in constant-time.

    Declaration

    Swift

    public static func isValidAuthenticationCode<C: ContiguousBytes, D: DataProtocol>(_ authenticationCode: C,
                                                                                      authenticating authenticatedData: D,
                                                                                      using key: SymmetricKey) -> Bool

    Parameters

    authenticationCode

    The authentication code

    authenticatedData

    Authenticated Data

    key

    The key to authenticate the data with

    Return Value

    Returns true if the MAC is valid. False otherwise.

  • Updates the MAC with data.

    Declaration

    Swift

    public mutating func update<D>(data: D) where D : DataProtocol

    Parameters

    data

    The data to update the MAC

  • Returns the Message Authentication Code (MAC) from the data inputted into the MAC.

    Throws

    Throws if the MAC has already been finalized

    Declaration

    Swift

    public func finalize() -> MAC

    Return Value

    The Message Authentication Code