This course will introduce you to the foundations of modern cryptography, with an eye toward practical applications.

Loading...

From the course by University of Maryland, College Park

Cryptography

417 ratings

This course will introduce you to the foundations of modern cryptography, with an eye toward practical applications.

From the lesson

Week 4

Message Authentication Codes

- Jonathan KatzProfessor, University of Maryland, and Director, Maryland Cybersecurity Center

Maryland Cybersecurity Center

Returning to the sending of message authentication codes.

Â Remember from a few lectures back that we showed how to

Â construct a secure message authentication code for short fixed length messages.

Â Based on any sort of random function, aka block cypher.

Â And what we wanted to do was to extend this to give us

Â secure message authentication code for arbitrary length messages.

Â We've already seen one such construction, cbc MAC.

Â Here we'll explore another construction based on hash-functions.

Â The intuition is actually rather simple.

Â Let's assume we have two parties who have between them

Â a secure channel that can handle short messages.

Â And I've depicted that here via a cylinder which is very narrow.

Â To indicate that the parties have between them a way to reliably send messages, but

Â that can only handle very short messages.

Â Let's assume the center now has a larger message that it

Â wants to communicate reliably to the other party.

Â How can they do this?

Â Well in fact, the idea is rather simple.

Â What the sender can do is to take its message M and

Â hash it down to a shorter fixed length digest here called h.

Â The sender can then transmit the short digest h

Â to the receiver using the secure channel between them.

Â And then, transmit the longer message M over an insecure channel.

Â At the other end, the receiver will simply check.

Â Whether the hash of the longer message end that it

Â received is equal to the digest h that it received over the secure channel.

Â And this will give reliable transmission of the longer message M,

Â bootstrapping from the security of the secure channel.

Â That allows the parties to communicate the shorter message h.

Â And the reason this is secure is very simple.

Â By assumption the, the channel for h is reliable, it's secure.

Â So the adversary can't tamper with that.

Â So that means that the receiver will indeed receive digest h

Â that the sender sends.

Â Well, the adversary can then try to tamper with the longer message, M.

Â But the attacker will not be able to convince the verifier,

Â the receiver to accept a different message, M prime.

Â Unless the attacker can find another message M prime that also hashes to

Â the same value h.

Â But if the hash function the parties are using is collision resistant,

Â then an attacker will not be able to do this.

Â We can use this idea to bootstrap a method authentication code for short messages.

Â Into a message authentication code for arbitrary length messages.

Â Well, what the parties will do is simply instantiate this secured channel for

Â short messages.

Â Using some message authentication code that can handle short messages.

Â So now we're in

Â a setting where the parties don't have any secure channel between them.

Â But instead they share some key k in advance.

Â And once again the sender has some longer message M

Â that it wants to transmit reliably to the receiver.

Â Well, what the sender can do here,

Â is again, hash the message to obtain a digest h.

Â And then compute a message authentication code on the digest h

Â using the shared key k.

Â And again this is going to be done using some message authentication code that can

Â handle short fixed-length messages.

Â Like the one we've shown already a couple of lectures back.

Â The sender can then transmit h along with its tag t.

Â And then in addition, send the message m itself.

Â And the point is again that we can view this transmission of h

Â along with it's tag, t.

Â As a way of sending h over what's effectively a reliable secure channel.

Â So, at the other end, just to go through the steps,

Â the receiver will compute h of M and recover the digest h.

Â And then verify whether the tag t on the receive message h

Â indeed verifies under this short, fixed length message authentication code.

Â And if so, the receiver will accept the longer message M

Â as being the intended message of the other party.

Â Now in fact, you can notice pretty quickly, that there's no need for

Â the sender to actually transmit h, itself.

Â And it's suffices for

Â the sender to simply transmit the longer message M along with the tag t.

Â Where, again, the tag t is being computed, still over the shorter digest h.

Â What we can prove about this construction is that if

Â the underlying message authentication code is secure for fixed-length messages.

Â I.e, messages whose length is equal to the output length of the hash function.

Â And if the hash function h is itself collision-resistant,

Â then the previous construction, the combination of the two.

Â Gives a secure method authentication code for arbitrary length messages.

Â The intuition is very similar to what we've already said.

Â However, I wanted to go through a very simple proof sketch just to

Â give a high level idea of how a formal proof would go.

Â So let's assume that the sender authenticates messages in one and two etc.

Â Where, as usual in the experiment defining security for

Â message authentication codes, the attacker is free to choose these messages.

Â And can even choose them adaptively, based on previous tags that it's received.

Â And let's define by way of notation h of i as the hash of the ith message.

Â Now at some point in time let's assume the attacker outputs a forgery M,t.

Â For this to be a forgery, of course,

Â it has to be the case that M is not equal to Mi for any value i.

Â That is, M cannot be equal to any previously authenticated method.

Â Well there are two cases.

Â The first case is when the hash of M, the hash of the message on which the attacker

Â outputs its for, forgery, is equal to the hash of Mi for some i.

Â That is, the hash of M is equal to the hash of some previously

Â authenticated message.

Â Well in that case, the attacker certainly can output a forgery by simply

Â replaying the tag ti that was computed on Mi.

Â But the point is that this would mean the attacker has found a collision in H.

Â And that's simply because we know that M is not equal to Mi.

Â So if H of M is equal to H of Mi that exactly give a collision.

Â And if H is collision resistant then this is something that the attacker should not

Â be able to do.

Â This is infeasible for any efficient attacker.

Â On the other hand,

Â the second case is where H of M is not equal to h i for all i.

Â That is, the hash of M is distinct from the hashes of

Â all previously authenticated messages.

Â Well in this case, that means that the,

Â that the attacker, if its forgery is valid.

Â Then the attacker must have been able to find a valid tag

Â t on a previously unauthenticated message h.

Â With respect to the underlying fixed length message authentication code.

Â So under the assumption that the underlying message authentication code

Â is secure for authenticating short messages.

Â This too is in-feasible, and so this rules out any sort of way that

Â the adversary might try for concocting a forgery.

Â If we look at the hash and mac scheme that we presented a few slides back,

Â how may we instantiate that in practice?

Â Well, we've already shown a simple construction of

Â a message authentication code for fixed length messages based on any block cipher.

Â And if you remember, in that construction.

Â The message length that we were able to handle was exactly equal to

Â the block length of the underlying block cipher being used.

Â Or I suppose, technically, we could handle messages of at most that length by

Â suitably padding the messages before applying the block cipher.

Â So we could then try to take that block cipher baked based MAC for

Â fixed length messages and couple that with some cryptographic hash function.

Â If you try to do that you'll notice that there's a block length mismatch.

Â So for example, if we try instantiating the block cipher based MAC using AES.

Â Then that means that we can authenticate messages whose length is,

Â at most, 128 bits.

Â Because 128 bits is the block length of AES.

Â However, cryptographic hash functions like SHA-1 have

Â output lengths of 160 bits or more.

Â So we have a mismatch between the two, and we can't directly couple them

Â together to give an instantiation of the hash and MAC instruction.

Â One could imagine designing hash functions and

Â blog ciphers that would pair well together.

Â But even if we did that.

Â There will still be a drawback of instantiating the hash and

Â MAC approach in that way.

Â And that would be that

Â we need to implement two different cryptographic primitives.

Â We would have to implement both a hash function as well as a block cipher.

Â In general, this is not really a significant problem but

Â in certain applications for example if you're implementing crypto on hardware.

Â You might prefer not to have to implement two different cryptographic primitives

Â just to obtain a message authentication code.

Â To address these issues researchers have designed what's called HMAC.

Â Which can be viewed as a particular instantiation of the hash and

Â MAC approach.

Â That can be constructed entirely from a certain type of hash function.

Â Importantly MD5, SHA-1, and SHA-2 are all different sorts of hash functions.

Â That satisfy the requirements of HMAC.

Â And so HMAC can be defined based on any of these hash functions.

Â We've already talked about how MD5 is no longer collision resistant and

Â should not be used.

Â nevertheless, as far as we know it remains secure when used to construct HMAC.

Â Still it's prudent to avoid using MD5 even in such a construction and

Â to migrate to HMAC SHA-1 or HMAC SHA-2 instead.

Â Unfortunately SHA-3 is not of the same type.

Â And cannot be directly plugged in to HMAC,

Â to give an instantiation of the hash-and-MAC approach.

Â And, for that reason different mechanisms for

Â achieving message authentication based on SHA-3 are currently being worked out.

Â The HMAC approach can be viewed,

Â as I said, as following the hash-and-MAC paradigm.

Â By using a part of the hash function, a certain component of the hash function.

Â We haven't had a reason to introduce up til now.

Â Being used essentially as a block cipher.

Â I didn't want to present any of the details because it presents a bit of

Â digression to show how exactly that's the case.

Â But at an intuitive level that's exactly what's going on.

Â In the next lecture, we'll talk about combining both secrecy and

Â integrity to the get the best of both.

Â And to get what we call authenticated encryption.

Â That is, an encryption scheme that achieves the joint goals of

Â secrecy and integrity

Â Coursera provides universal access to the worldâ€™s best education,
partnering with top universities and organizations to offer courses online.