< Return to Video

MACs Based On PRFs (10 min)

  • 0:00 - 0:04
    Now that we know what MACs are, let's go
    ahead and build our first secure MACs.
  • 0:04 - 0:08
    First I want to remind you that a MAC is a
    pair of algorithms. The first is a signing
  • 0:08 - 0:13
    algorithm that's given a message and a key
    will generate a corresponding tag And the
  • 0:13 - 0:17
    second is verification algorithms are
    given a key message and a tag while
  • 0:17 - 0:22
    outputs zero or one depending on whether
    the tag is valid or not. And we said that
  • 0:22 - 0:26
    a MAC is secure if it is existentially
    unforgeable under a chosen message attack.
  • 0:26 - 0:31
    In other words, the attackers allow to
    mount a chosen message attack where he can
  • 0:31 - 0:35
    submit arbitrary messages of his choice
    and obtain the corresponding tags for
  • 0:35 - 0:40
    those messages, and then despite the
    ability to generate arbitrary tags The
  • 0:40 - 0:44
    attacker cannot create a new message-tag pair that was not given to him
  • 0:44 - 0:48
    during the chosen message attack. Okay so
    we've already seen this definition in the
  • 0:48 - 0:52
    last segment and now the question is how
    do we build secure MACs? So the first
  • 0:52 - 0:57
    example I want to give you is basically
    showing that any secure PRF directly gives
  • 0:57 - 1:02
    us a secure MAC as well. So let's see how
    we do it. So suppose we have a pseudo
  • 1:02 - 1:07
    random function so the pseudo random
    function takes and inputs X and outputs in
  • 1:07 - 1:12
    Y. And let's define the following MAC. So
    the way we sign a message 'M' is basically
  • 1:12 - 1:17
    by simply evaluating the function at the
    point 'M' So the tag for the message M is
  • 1:17 - 1:21
    simply the value of the function at the
    point M and then the way we verify a
  • 1:21 - 1:26
    message to that pair is by recomputing the
    value of the function at the message M and
  • 1:26 - 1:30
    checking whether that is equal to the tag
    given to us. We say yes if so and we
  • 1:30 - 1:35
    reject otherwise. So here you have in
    pictures basically that when Alice wants
  • 1:35 - 1:39
    to send a message to Bob she computes a
    tag by the value of PRF and then she
  • 1:39 - 1:43
    appends this tag to the message, Bob
    receives the corresponding tab pair, he
  • 1:43 - 1:48
    recomputes the value of the function and
    tests whether the given tag is actually
  • 1:48 - 1:53
    equal to the value of the function at the
    point M. So let's look at a bad example of
  • 1:53 - 1:58
    this instruction. And so suppose that we
    have a pseudo-random function that happens
  • 1:58 - 2:03
    to output only ten bits. Okay, so this is
    a fine pseudo-random function and it just
  • 2:03 - 2:08
    so happens that for any message 'M' it
    only outputs ten bits value. My question
  • 2:08 - 2:12
    to you is if we use this function 'F' to
    construct a MAC, is that going to be a
  • 2:12 - 2:17
    secure MAC? So the answer is no, this MAC
    is insecure. In particular because the
  • 2:17 - 2:21
    tags are too short. So consider the
    following simple adversary. What the
  • 2:21 - 2:26
    adversary will do is simply choose an
    arbitrary message M and just guess the
  • 2:26 - 2:31
    value of the MAC for that particular
    message. Now, because the tag is only ten
  • 2:31 - 2:35
    bits long, the adversary has a chance of
    one in two to the ten in guessing the MAC
  • 2:35 - 2:40
    correctly. In other words, the advantage
    of the guessing adversary, one distinctly
  • 2:40 - 2:44
    guesses a random tag for a given message.
    That adversary is going to have an
  • 2:44 - 2:49
    advantage against the mac that's basically
    one over two to the ten which is one over
  • 2:49 - 2:53
    a thousand twenty four and that's
    definitely non negligible. So the adversary
  • 2:53 - 2:57
    basically will successfully forge the mac
    on a given message with probability one
  • 2:57 - 3:02
    on a thousand which is insecure. However
    it turns out this is the only example that
  • 3:02 - 3:06
    where things can go wrong, only when the
    output of the function is small can things
  • 3:06 - 3:11
    go wrong. If the output of the PRF is
    large Then we get a secure MAC out of this
  • 3:11 - 3:14
    function. And let's state the security
    theorem here. So suppose we have a
  • 3:14 - 3:18
    function 'F' that takes messages in 'X'
    and outputs tags in 'Y', then the MAC
  • 3:18 - 3:23
    that's derived from this PRF in fact is a
    secure MAC. In particular, if you look at
  • 3:23 - 3:27
    the security theorem here, you'll see very
    clearly the era bounds, in other words
  • 3:27 - 3:31
    since the PRF is secure we know that this
    quantity here is negligible. And so if we
  • 3:31 - 3:35
    want this quantity to be negligible, this
    is what we want, we want to say that no
  • 3:35 - 3:40
    adversary can defeat the MAC 'I sub F',
    that implies that we want this quantity to
  • 3:40 - 3:44
    be negligible, in other words we want the
    output space to be large. And so for
  • 3:44 - 3:48
    example, taking a PRF that outputs eighty
    bits is perfectly fine. That will generate
  • 3:48 - 3:52
    an eighty bit MAC and therefore the
    advantage of any adversary will be at most
  • 3:52 - 3:57
    one over two to the eighty. So now the proof
    of this theorem is really simple, so lets
  • 3:57 - 4:01
    just go ahead and do it. So in fact lets
    start by saying that suppose instead of a
  • 4:01 - 4:05
    PRF we have a truly random function from
    the message space to the tag space so this
  • 4:05 - 4:10
    is just a random function from X to Y
    that's chosen at random from the set of
  • 4:10 - 4:15
    all such functions. Now lets see if that
    function can give us a secure mac. So what
  • 4:15 - 4:20
    the adversary says is, 'I want a tag on
    the message M1'. What he gets back is the
  • 4:20 - 4:24
    tag which just happens to be the function
    evaluated at the point M1. Notice there is
  • 4:24 - 4:28
    no key here because F is just a truly
    random function from X to Y. And then the
  • 4:28 - 4:33
    adversary gets to choose a message from M2
    and he obtains the tag from M2, he choose
  • 4:33 - 4:37
    M3, M4 up to MQ and he obtains all the
    corresponding tags. Now his goal is to
  • 4:37 - 4:41
    produce a message tag pair and we say that
    he wins, remember that this is an
  • 4:41 - 4:46
    existential forgery, in other words first
    of all T has to be equal to F of M This
  • 4:46 - 4:50
    means that 'T' is a valid tag for the
    message 'M'. And second of all, the
  • 4:50 - 4:55
    message 'M' has to be new. So the message
    'M' had better not be one of M-one to M-Q.
  • 4:55 - 4:59
    But let's just think about this for a
    minute, what does this mean? So the
  • 4:59 - 5:04
    adversary got to see the value of a truly
    random function at the points M-one to M-Q
  • 5:04 - 5:09
    and now he?s suppose to predict the value
    of this function as some new point, M
  • 5:09 - 5:13
    However, for a truly random function, the
    value of the function at the point M is
  • 5:13 - 5:18
    independent of its value at the points M-1
    to M-Q. So the best the adversary can do
  • 5:18 - 5:23
    at predicting the value of the function at
    the point M is just guess the value,
  • 5:23 - 5:27
    because he has no information about F of
    M. And as a result his advantage if he
  • 5:27 - 5:32
    guesses the value of the function at the
    point M he'll guess it right with
  • 5:32 - 5:36
    probability exactly one over Y. And then
    the tag that he produced will be correct
  • 5:36 - 5:41
    with probability exactly one over Y. Okay,
    again he had no information about the
  • 5:41 - 5:45
    value of the function of M and so the best
    he could do is guess. And if he guesses,
  • 5:45 - 5:49
    he'll get it right with probability one
    over Y. And now of course, because the
  • 5:49 - 5:54
    function capital F is a pseudo random
    function The adversary is gonna behave the
  • 5:54 - 5:59
    same whether we give him the truly random
    function or the pseudo random function.
  • 5:59 - 6:03
    The adversary can't tell the difference
    and as a result even if we use a pseudo
  • 6:03 - 6:07
    random function, the adversary is gonna
    have advantages at most one over Y in
  • 6:07 - 6:11
    winning the game. Okay, so you can see
    exactly the security theorem, let's go
  • 6:11 - 6:16
    back there for just a second. Essentially
    this is basically why we got an error term
  • 6:16 - 6:20
    of one over Y because of the guessing
    attack and that's the only way that the
  • 6:20 - 6:25
    attacker can win the game. So now that we
    know that any secure PRF is also a secure
  • 6:25 - 6:29
    MAC, we already know that we have our
    first example MAC. In particular, we know
  • 6:29 - 6:34
    that AES, or at least we believe that AES
    is a secure PRF, therefore, AES since it
  • 6:34 - 6:38
    takes sixteen byte inputs, right the
    message space for AES is 128 bits, which
  • 6:38 - 6:43
    is sixteen bytes. Therefore the AES cipher
    essentially gives us a MAC that can match
  • 6:43 - 6:48
    messages that are exactly sixteen bytes.
    Okay, so that's our first example of a
  • 6:48 - 6:53
    MAC. But now the question is if we have a
    PRF for small inputs like AES that only
  • 6:53 - 6:59
    acts on sixteen bytes, can we build a MAC
    for big messages that can act on gigabytes
  • 6:59 - 7:02
    of data? Sometimes I call this the
    McDonald's problem. Basically given a
  • 7:02 - 7:06
    small MAC and we build a big MAC out of
    it. In other words, given a MAC for small
  • 7:06 - 7:10
    messages and we build a MAC for large
    messages. So we're gonna look at two
  • 7:10 - 7:15
    constructions for doing so. The first
    example is called a CBC MAC that again
  • 7:15 - 7:19
    takes PRF for small messages as input
    and produces a PRF for very large
  • 7:19 - 7:24
    messages. As outputs. The second one we'll
    see is HMAC which does the same thing
  • 7:24 - 7:28
    again takes a PRF for small inputs and
    generates a PRF for very large inputs. Now
  • 7:28 - 7:32
    the two are used in very different
    contexts. Cbc-mac is actually very
  • 7:32 - 7:36
    commonly used in the banking industry. For
    example, there's a system called the
  • 7:36 - 7:41
    Automatic Clearing House, ACH, which banks
    use to clear checks with one another and
  • 7:41 - 7:45
    that system, CBC-MAC, is used to ensure
    integrity of the checks as they're
  • 7:45 - 7:49
    transferred from bank to bank. On the
    Internet, protocols like SSL and IPsec and
  • 7:49 - 7:53
    SSH, those all use HMAC for integrity. Two
    different MACs and were gonna discuss them
  • 7:53 - 7:57
    in the next couple of segments. And as I
    said were also gonna start from a PRF for
  • 7:57 - 8:01
    small messages and produce PRF for
    messages that are gigabytes long and in
  • 8:01 - 8:06
    particular they can both be substantiated
    with AES as the underlying cipher. So the
  • 8:06 - 8:11
    last comment I want to make about these
    PRF based MACs is that in fact their
  • 8:11 - 8:15
    output can be truncated. So suppose we
    have a PRF that outputs N bit outputs. So
  • 8:15 - 8:20
    again for AES this would be a PRF that
    outputs 128 bits as outputs. Its an easy
  • 8:20 - 8:25
    lemma to show that in fact if you have an
    N bit PRF if you truncated, in other words
  • 8:25 - 8:31
    if you only output first key bits The
    result is also a secure PRF and the
  • 8:31 - 8:37
    intuition here is if the big PRF outputs N
    bits of randomness for any inputs that you
  • 8:37 - 8:42
    give to the PRF then certainly chopping it
    off and truncating it to T bits is still
  • 8:42 - 8:47
    gonna look random. The attacker now gets
    less information so his job of
  • 8:47 - 8:52
    distinguishing the outputs from random
    just became harder. In other words, if the
  • 8:52 - 8:57
    N bit PRF is secure, then the T less than
    N bit PRF, the truncated PRF, would also
  • 8:57 - 9:01
    be secure. So this is an easy lemma and
    since any secure PRF also gives us a
  • 9:01 - 9:06
    secure MAC, what this means is if you give
    me a MAC that's based on a PRF and what I
  • 9:06 - 9:11
    can do is I can truncate it to W bits,
    however, because of the error term in the
  • 9:11 - 9:15
    MAC based PRF theorem we know that
    truncating to W bits will only be secure
  • 9:15 - 9:20
    as long as one over two to the W is
    negligible. So if you truncate the PRF to
  • 9:20 - 9:24
    only three bits, the resulting MAC is not
    going to be secure. However, if you
  • 9:24 - 9:29
    truncate it to say 80 bits or maybe even
    64 bits, then the resulting MAC is still
  • 9:29 - 9:34
    gonna be a secure MAC. Okay, so the thing
    to remember here is that even though we
  • 9:34 - 9:39
    use AES to construct larger PRFs and the
    output of these PRFs is gonna be 128 bits,
  • 9:39 - 9:44
    it doesn't mean that the MAC itself has to
    produce 128 bit tags We can always
  • 9:44 - 9:49
    truncate the outputs to 90 bits or 80
    bits, and as a result, we would get still
  • 9:49 - 9:53
    secure MACs but now the output tag is
    gonna be more reasonable size and doesn't
  • 9:53 - 9:58
    have to be the full 128 bits. Okay, so in
    the next segment we're gonna look at how
  • 9:58 - 9:59
    the CBC-MAC works.
Title:
MACs Based On PRFs (10 min)
Video Language:
English
rodolfojcj edited English subtitles for MACs Based On PRFs (10 min)
rodolfojcj edited English subtitles for MACs Based On PRFs (10 min)
rodolfojcj edited English subtitles for MACs Based On PRFs (10 min)
stanford-bot edited English subtitles for MACs Based On PRFs (10 min)
stanford-bot edited English subtitles for MACs Based On PRFs (10 min)
stanford-bot added a translation

English subtitles

Revisions