Integrity
MAC - Message Authentication Code
Encryption in general does not solve the problem of message integrity.
The aim of message authentication code is to prevent any adversary from modifying the message sent by one party to another, or from injecting a new message, without the receiver detecting that the message did not originate from the intended party.
Formally, A message authentication code or consists of three probabilistic polynomial time algorithms such that:
- the key generation algorithm takes as input the security parameter and outputs a key with
- the tag generation algorithm takes as input a key and a message and outputs a tag i.e.
- the deterministic verification algorithm takes as input , a message and a tag . It outputs a bit with as valid and as invalid tag i.e.
Security of MACs:
Formally, The message authentication experiment :
- a key is generated by running
- the adversary is given input and oracle access to . the adversary eventually outputs . Let be the set of queries that asked its oracle.
- succeeds iff
The intuitive idea behind the definition is that no efficient adversary should be able to generate a valid tag on any new message that was not previously sent by one of the communicating parties.
A message authentication code is secure if for all PPT adversaries ,
Fixed Length Mac:
Pseudorandom functions are a natural tool for constructing secure message authentication codes. If the tag is obtained by applying it on , then forging a tag requires the adversary to correctly guess the value of the pseudorandom function at a new input .
Construction:
Let be a pseudorandom function.
- : on input a key and a message , output the tag
- : on input a key , a message and a tag , output iff .
Discussion:
- If is pseudorandom function, then the above construction is a secure fixed length MAC for messages of length .
CBC-MAC:
Basic Construction:
Insecure Construction Ahead
This basic scheme is not secure in the general case when messages of different lengths may be authenticated Please refer here to understand why this scheme is not secure.
Let be a pseudorandom function and a fix length function
- : on input a key and a message of length
- Parse as where
- Set . Then
- Output as the tag.
- : on input a key , a message and tag
- if is not of length output
- output
CBC-MAC vs CBC encryption
- CBC mode encryption uses random and this is crucial for security. CBC-MAC’s is and this is also crucial for security. random is not secure for CBC-MAC
Secure CBC-MAC for arbitrary length messages:
There are two ways the above construction can be modified. Here we will discuss only one.
- Prepend the message with its length and then compute basic CBC-MAC on the result
Hash Functions
- Hash functions are simply functions that take inputs of some length and compress then into short fixed-length outputs
- A good hash function is the one that yields few collisions, where a collision is a pair of distinct items and such that
- Collision-resistant hash functions are similar in spirit. The goal is to avoid collisions. However there are fundamental differences. For one, the desire to minimise collisions in the setting of data structures becomes a requirement in the setting of cryptography.
Collisions resistance
A function is collision resistant if it is infeasible for any probabilistic polynomial time algorithm to find a collision in .
Formally, we consider keyed hash functions. That is is a two-input function that takes as input a key and a string , and outputs a string.
The requirement is that it must be hard to find a collision in for a randomly generated key .
There are at least one differences between the keys in this context and what we have seen till now. The key is generally not kept secret and collision resistance is required even when the adversary is given the key .
Unkeyed Hash Functions
Cryptographic hash functions used in practice generally have a fixed output length and are usually unkeyed meaning that the hash function is just a fixed function
This is problematic from a theoretic standpoint since for any such function there is always a constant time algorithm that outputs a collision in
However, the unkeyed cryptographic hash functions used in real world are collisions resistant for all practical purposes since colliding pairs are unknown and computationally difficult to find.
Domain Extension: Merkle Damgard Transform
Hash functions are often constructed by first designing a collision resistant compression function handling fixed length inputs and then using domain extension to handle arbitrary length inputs.
Merkle Damgard transform is a common approach for extending a compression functions to a full fledged hash function while maintaining the collision resistant property.
The existence of this transform means that when designing collision resistant hash functions we can restrict our attention to the fixed length case.
Message Authentication using Hash functions
Hash and MAC
The idea behind hash and MAC approach is simple
- an arbitrarily long message is hashed down to a fixed length string using a collision resistant hash function
- A fixed length is applied to the result
The above construction is secure for arbitrarily long messages if the is a secure MAC function and the hash function is a collision resistant hash function.
HMAC:
good reference: https://crypto.stackexchange.com/questions/1070/why-is-hk-mathbin-vert-x-not-a-secure-mac-construction
Construction:
Let be a hash function constructed using Merkle Damgard transform to a compression function taking inputs of length .
Let , be a fixed constants of length
define MAC as follows:
: on input , run to obtain key . Also choose uniform . Output key
: on input key and message , output
: on input key and message and a tag , output iff
Roles of and
The reason is that this allows security of HMAC to be based on the potentially weaker assumption that is weakly collision resistant.
This is a defensive strategy that paid off when it was discovered that the hash function is not collision resistant.
The collision finding attacks on did not violate weak collision resistance and was not broken even though was.
This gave developers time to replace in implementations without immediate fear of attack.
The above discussion suggests that independent keys should be used in the outer and inner computations. for reasons of efficiency, a single key is used but the key is used in combination with ad to derive two other keys.
