8
Cryptography and Cryptography and Network Security Network Security Chapter 12 Chapter 12 Fifth Edition Fifth Edition by William Stallings by William Stallings Lecture slides by Lecture slides by Lawrie Lawrie Brown Brown (with edits by RHB) (with edits by RHB) Chapter 12 Chapter 12 Message Message Authentication Codes Authentication Codes At cats' green on the Sunday he took the message from At cats' green on the Sunday he took the message from the inside of the pillar and added Peter Moran's name to the inside of the pillar and added Peter Moran's name to the two names already printed there in the "Brontosaur" the two names already printed there in the "Brontosaur" code. The message now read: code. The message now read: Leviathan to Dragon: Leviathan to Dragon: Martin Hillman, Trevor Allan, Peter Moran: observe and Martin Hillman, Trevor Allan, Peter Moran: observe and tail. tail. What was the good of it John hardly knew. He felt What was the good of it John hardly knew. He felt better, he felt that at last he had made an attack on Peter better, he felt that at last he had made an attack on Peter Moran instead of waiting passively and effecting no Moran instead of waiting passively and effecting no retaliation. Besides, what was the use of being in retaliation. Besides, what was the use of being in possession of the key to the codes if he never took possession of the key to the codes if he never took advantage of it? advantage of it? Talking to Strange Men, Talking to Strange Men, Ruth Rendell Ruth Rendell Outline Outline will consider: will consider: message authentication requirements message authentication requirements message authentication using encryption message authentication using encryption MACs MACs HMAC authentication using a hash function HMAC authentication using a hash function CMAC authentication using a block cipher CMAC authentication using a block cipher GCM authentication using a block cipher GCM authentication using a block cipher PRNG using Hash Functions and PRNG using Hash Functions and MACs MACs Message Authentication Message Authentication message authentication is concerned with: message authentication is concerned with: protecting the integrity of a message protecting the integrity of a message validating identity of originator validating identity of originator non non - - repudiation of origin (dispute resolution) repudiation of origin (dispute resolution) three alternative approaches used: three alternative approaches used: hash functions (see Ch 11) hash functions (see Ch 11) message encryption message encryption message authentication codes ( message authentication codes ( MACs MACs ) )

Chapter 12 – Message Cryptography and Authentication …banach/COMP61411.Info/Course...Using Symmetric Ciphers for MACs • can use any block cipher chaining mode and use final block

  • Upload
    others

  • View
    12

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Chapter 12 – Message Cryptography and Authentication …banach/COMP61411.Info/Course...Using Symmetric Ciphers for MACs • can use any block cipher chaining mode and use final block

Cryptography and Cryptography and

Network SecurityNetwork Security

Chapter 12Chapter 12

Fifth EditionFifth Edition

by William Stallingsby William Stallings

Lecture slides by Lecture slides by LawrieLawrie BrownBrown

(with edits by RHB)(with edits by RHB)

Chapter 12 Chapter 12 –– Message Message

Authentication CodesAuthentication Codes

•• At cats' green on the Sunday he took the message from At cats' green on the Sunday he took the message from the inside of the pillar and added Peter Moran's name to the inside of the pillar and added Peter Moran's name to the two names already printed there in the "Brontosaur" the two names already printed there in the "Brontosaur" code. The message now read: code. The message now read: ““Leviathan to Dragon: Leviathan to Dragon: Martin Hillman, Trevor Allan, Peter Moran: observe and Martin Hillman, Trevor Allan, Peter Moran: observe and tail.tail.”” What was the good of it John hardly knew. He felt What was the good of it John hardly knew. He felt better, he felt that at last he had made an attack on Peter better, he felt that at last he had made an attack on Peter Moran instead of waiting passively and effecting no Moran instead of waiting passively and effecting no retaliation. Besides, what was the use of being in retaliation. Besides, what was the use of being in possession of the key to the codes if he never took possession of the key to the codes if he never took advantage of it?advantage of it?

•• ——Talking to Strange Men, Talking to Strange Men, Ruth RendellRuth Rendell

OutlineOutline

•• will consider:will consider:

–– message authentication requirementsmessage authentication requirements

–– message authentication using encryptionmessage authentication using encryption

–– MACsMACs

–– HMAC authentication using a hash functionHMAC authentication using a hash function

–– CMAC authentication using a block cipherCMAC authentication using a block cipher

–– GCM authentication using a block cipherGCM authentication using a block cipher

–– PRNG using Hash Functions and PRNG using Hash Functions and MACsMACs

Message AuthenticationMessage Authentication

•• message authentication is concerned with: message authentication is concerned with: –– protecting the integrity of a message protecting the integrity of a message

–– validating identity of originator validating identity of originator

–– nonnon--repudiation of origin (dispute resolution)repudiation of origin (dispute resolution)

•• three alternative approaches used:three alternative approaches used:–– hash functions (see Ch 11)hash functions (see Ch 11)

–– message encryptionmessage encryption

–– message authentication codes (message authentication codes (MACsMACs))

王博文�
消息验证码�
王博文�
•消息身份验证涉及: - 保护信息的完整性 - 验证发端人的身份 - 不可否认原产地(争议解决)•使用了三种替代方法: - 哈希函数(见第11章) - 邮件加密 - 消息验证码(MAC)�
Page 2: Chapter 12 – Message Cryptography and Authentication …banach/COMP61411.Info/Course...Using Symmetric Ciphers for MACs • can use any block cipher chaining mode and use final block

Symmetric Message EncryptionSymmetric Message Encryption

•• encryption can also provides authenticationencryption can also provides authentication

•• if symmetric encryption is used then:if symmetric encryption is used then:

–– receiver knows sender must have created itreceiver knows sender must have created it

–– since only sender and receiver know key usedsince only sender and receiver know key used

–– know content cannot have been altered know content cannot have been altered ……

–– if message has if message has suitable structuresuitable structure, redundancy , redundancy

or a checksum to detect any changes or a checksum to detect any changes ……

Message Authentication Code Message Authentication Code

(MAC)(MAC)

•• generated by an algorithm that creates a small generated by an algorithm that creates a small

fixedfixed--sized blocksized block

–– depending on both message and some depending on both message and some keykey

–– like encryption, but like encryption, but need not be reversibleneed not be reversible

•• appended to message as a appended to message as a digest / tagdigest / tag

•• receiver performs same computation on receiver performs same computation on

message and checks it matches the MACmessage and checks it matches the MAC

•• provides assurance that message is unaltered provides assurance that message is unaltered

and comes from senderand comes from sender

•• esp. useful if message can be esp. useful if message can be any any bitpatternbitpattern

Message Authentication CodesMessage Authentication Codes

•• a MAC is a cryptographic checksuma MAC is a cryptographic checksum

MACMAC == CCKK(M)(M)

–– condenses a variablecondenses a variable--length message length message MM

–– using a secret key using a secret key KK

–– to a fixedto a fixed--sized authenticatorsized authenticator

•• is a manyis a many--toto--one functionone function

–– potentially many messages have same MACpotentially many messages have same MAC

–– but finding these needs to be very difficultbut finding these needs to be very difficult

Message Authentication CodesMessage Authentication Codes

•• as shown the MAC provides authenticationas shown the MAC provides authentication

•• can also use encryption for secrecycan also use encryption for secrecy

–– generally use separate keys for eachgenerally use separate keys for each

–– can compute MAC either before or after encryptioncan compute MAC either before or after encryption

–– is generally regarded as better done beforeis generally regarded as better done before

•• why use a MAC?why use a MAC?

–– sometimes only authentication is neededsometimes only authentication is needed

–– sometimes need authentication to persist longer than sometimes need authentication to persist longer than

the encryption (the encryption (egeg. archival use). archival use)

–– protection for arbitrary protection for arbitrary bitpatternbitpattern plaintextsplaintexts

•• a MAC is not a digital signature (repudiation)a MAC is not a digital signature (repudiation)

王博文�
对称消息加密•加密还可以提供身份验证•如果使用对称加密,则: - 接收者知道发件人必须创建它 - 因为只有发送者和接收者知道使用的密钥 - 知道内容不能改变...... - 如果消息具有合适的结构,冗余或校验和以检测任何更改......�
王博文�
消息验证码(MAC)•由创建小型固定大小块的算法生成 - 取决于消息和一些密钥 - 像加密一样,但不必是可逆的•作为摘要/标记附加到消息•接收器对消息执行相同的计算并检查它是否与MAC匹配•确保消息不会发生变化并来自发件人•尤其是 如果消息可以是任何位模式,则非常有用�
王博文�
•MAC是加密校验和 - 压缩可变长度消息M. - 使用密钥K. - 固定大小的验证器•是一对多的功能 - 可能有很多消息具有相同的MAC - 但发现这些需求非常困难�
王博文�
•如图所示,MAC提供身份验证•也可以使用加密来保密 - 通常为每个使用单独的密钥 - 可以在加密之前或之后计算MAC - 通常认为以前做得更好•为什么要使用MAC? - 有时只需要身份验证 - 有时需要身份验证才能比加密持续更长时间(例如,存档使用) - 保护任意位模式明文•MAC不是数字签名(拒绝)�
Page 3: Chapter 12 – Message Cryptography and Authentication …banach/COMP61411.Info/Course...Using Symmetric Ciphers for MACs • can use any block cipher chaining mode and use final block

Uses of MAC Authenticated EncryptionAuthenticated Encryption

•• simultaneously protect confidentiality and simultaneously protect confidentiality and

authenticity of communicationsauthenticity of communications

–– often required but usually separateoften required but usually separate

•• approachesapproaches

–– HashHash--thenthen--encrypt: E(K, (M || H(M))encrypt: E(K, (M || H(M))

–– MACMAC--thenthen--encrypt: E(K2, (M || MAC(K1, M)) encrypt: E(K2, (M || MAC(K1, M))

–– EncryptEncrypt--thenthen--MAC: (C=E(K2, M), T=MAC(K1, C) MAC: (C=E(K2, M), T=MAC(K1, C)

–– EncryptEncrypt--andand--MAC: (C=E(K2, M), T=MAC(K1, M)MAC: (C=E(K2, M), T=MAC(K1, M)

•• decryption / verification straightforwarddecryption / verification straightforward

•• vulnerabilities with all, without good designvulnerabilities with all, without good design

Requirements for Requirements for MACsMACs

•• taking into account the types of attackstaking into account the types of attacks

•• need the MAC to satisfy the following:need the MAC to satisfy the following:

1.1. knowing a message and MAC, is infeasible to find knowing a message and MAC, is infeasible to find

another message with same MACanother message with same MAC

2.2. MACsMACs should be uniformly distributedshould be uniformly distributed

3.3. MAC should depend equally on all bits of the MAC should depend equally on all bits of the

messagemessage

•• similar to hash function properties (similar to hash function properties (preimagepreimage

resistance, second resistance, second preimagepreimage resistance, resistance,

collision resistance)collision resistance)

Security of Security of MACsMACs

•• like block ciphers have:like block ciphers have:

•• brutebrute--forceforce attacks exploitingattacks exploiting

–– strong collision resistance hash have cost 2strong collision resistance hash have cost 2mm//22

•• 128128--bit hash looks vulnerable, 160bit hash looks vulnerable, 160--bits betterbits better

–– MACsMACs with known messagewith known message--MAC pairsMAC pairs

•• can either attack can either attack keyspacekeyspace ((cfcf key search) or MACkey search) or MAC

•• at least 128at least 128--bit MAC is needed for securitybit MAC is needed for security

王博文�
•同时保护通信的机密性和真实性 - 经常需要但通常是分开的•方法•解密/验证简单明了•所有人的漏洞,没有良好的设计�
王博文�
•考虑到攻击的类型•需要MAC满足以下条件:1.知道消息和MAC,找不到具有相同MAC的另一条消息是不可行的2. MAC应该是均匀分布的3. MAC应该同等地依赖于消息的所有位•类似于散列函数属性(前像像阻力,第二前像素抗性,抗冲击性)�
王博文�
像分组密码有:•暴力攻击利用 - 强大的碰撞阻力哈希值为2m / 2•128位散列看起来很脆弱,160位更好 - 具有已知消息-MAC对的MAC•可以攻击密钥空间(cf key search)或MAC•安全性至少需要128位MAC�
Page 4: Chapter 12 – Message Cryptography and Authentication …banach/COMP61411.Info/Course...Using Symmetric Ciphers for MACs • can use any block cipher chaining mode and use final block

Security of Security of MACsMACs

•• cryptanalytic attackscryptanalytic attacks exploit structureexploit structure

–– like block ciphers want brutelike block ciphers want brute--force attacks to force attacks to be the best alternativebe the best alternative

•• more variety of more variety of MACsMACs so harder to so harder to generalize about cryptanalysis generalize about cryptanalysis

Keyed Hash Functions as Keyed Hash Functions as MACsMACs

•• want a MAC based on a hash function want a MAC based on a hash function

–– because hash functions are generally fasterbecause hash functions are generally faster

–– crypto hash function code is widely availablecrypto hash function code is widely available

•• hash includes a key along with messagehash includes a key along with message

•• original proposal:original proposal:

KeyedHashKeyedHash == Hash(Key|MessageHash(Key|Message) )

–– some weaknesses were found with this some weaknesses were found with this

•• eventually led to development of HMAC eventually led to development of HMAC

HMAC Design ObjectivesHMAC Design Objectives

•• use, without modifications, hash functionsuse, without modifications, hash functions

•• allow for easy allow for easy replaceabilityreplaceability of embedded of embedded

hash functionhash function

•• preserve original performance of hash preserve original performance of hash

function without significant degradationfunction without significant degradation

•• use and handle keys in a simple way.use and handle keys in a simple way.

•• have well understood cryptographic analysis have well understood cryptographic analysis

of authentication mechanism strengthof authentication mechanism strength

HMACHMAC

•• specified as Internet standard RFC2104 specified as Internet standard RFC2104

•• uses hash function on the message:uses hash function on the message:HMACHMAC

KK(M)(M) == Hash[(KHash[(K++ XORXOR opadopad)) || ||

Hash[(KHash[(K++ XORXOR ipadipad)) |||| M)]M)] ]]

–– where where KK++ is the key, zerois the key, zero--padded out to size padded out to size

–– opadopad, , ipadipad are specified padding constants (50% are specified padding constants (50% bits in common), repeated to pad out to sizebits in common), repeated to pad out to size

•• overhead is just 3 more hash calculations than overhead is just 3 more hash calculations than the message needs alonethe message needs alone

•• any hash function can be usedany hash function can be used–– eg. MD5, SHAeg. MD5, SHA--1, RIPEMD1, RIPEMD--160, Whirlpool160, Whirlpool

王博文�
密码分析攻击利用结构 - 像分组密码一样,蛮力攻击是最好的选择•更多种类的MAC更难以概括为密码分析�
王博文�
键控哈希函数作为MAC•想要基于散列函数的MAC - 因为哈希函数通常更快 - 加密哈希函数代码广泛可用hash包括一个键和消息•原始提案:KeyedHash = Hash(Key | Message) - 发现了一些弱点•最终促成了HMAC的发展�
王博文�
HMAC设计目标•无需修改即可使用散列函数•允许嵌入式散列函数的轻松替换•保留散列函数的原始性能而不会显着降低•以简单的方式使用和处理密钥。•充分了解身份验证机制强度的加密分析�
王博文�
•指定为Internet标准RFC2104•对消息使用哈希函数: - 其中K +是关键,零填充到大小 - opad,ipad是指定的填充常量(共同的50%位),重复填充到大小•开销只比消息需要多3个哈希计算•可以使用任何哈希函数 - 例如 MD5,SHA-1,RIPEMD-160,惠而浦�
Page 5: Chapter 12 – Message Cryptography and Authentication …banach/COMP61411.Info/Course...Using Symmetric Ciphers for MACs • can use any block cipher chaining mode and use final block

HMAC HMAC

OverviewOverview

ipad = (00110110)*

opad = (01011100)*

HMAC HMAC

PrecomPrecom--

putationputation

HMAC SecurityHMAC Security

•• proved proved security of HMAC relates to that of security of HMAC relates to that of the underlying hash algorithmthe underlying hash algorithm

•• attacking HMAC requires either:attacking HMAC requires either:

–– brute force attack on key usedbrute force attack on key used

–– birthday attack (but since keyed, would need birthday attack (but since keyed, would need to observe a very large number of messages)to observe a very large number of messages)

•• choose hash function used based on choose hash function used based on speed versus security constraintsspeed versus security constraints

Using Symmetric Ciphers for Using Symmetric Ciphers for MACsMACs

•• can use any block cipher chaining mode can use any block cipher chaining mode

and use final block as a MACand use final block as a MAC

•• Data Authentication Algorithm (DAA)Data Authentication Algorithm (DAA) is is

a widely used MAC based on DESa widely used MAC based on DES--CBCCBC

–– using IV=0 and zerousing IV=0 and zero--pad of final blockpad of final block

–– encrypt message using DES in CBC modeencrypt message using DES in CBC mode

–– and send just the final block as the MACand send just the final block as the MAC

•• or the leftmost M bits (16or the leftmost M bits (16≤≤MM≤≤64) of final block64) of final block

•• but final MAC is now too small for securitybut final MAC is now too small for security

王博文�
预计算�
王博文�
•证明HMAC的安全性与底层哈希算法的安全性有关•攻击HMAC需要: - 对使用的密钥进行暴力攻击 - 生日攻击(但自键入后,需要观察大量的消息)•根据速度与安全约束选择使用的哈希函数�
王博文�
使用对称密码进行MAC•可以使用任何分组密码链模式并使用最终块作为MAC•数据认证算法(DAA)是一种广泛使用的基于DES-CBC的MAC - 使用IV = 0和最终块的零填充 - 在CBC模式下使用DES加密消息 - 并将最后一个块作为MAC发送•或最后一个块的最左边M位(16≤M≤64)•但最终的MAC现在太小而不安全�
Page 6: Chapter 12 – Message Cryptography and Authentication …banach/COMP61411.Info/Course...Using Symmetric Ciphers for MACs • can use any block cipher chaining mode and use final block

Data Authentication AlgorithmData Authentication Algorithm

N.B. DAAN.B. DAAKK(X) = DAA(X) = DAAKK(X || (X XOR DAA(X || (X XOR DAAKK(X)))(X)))

CMACCMAC

•• previously saw the DAA (CBCpreviously saw the DAA (CBC--MAC)MAC)

•• widely used in government and industrywidely used in government and industry

•• but has message size limitationbut has message size limitation

•• can overcome using 2 keys and paddingcan overcome using 2 keys and padding

•• thus forming the Cipherthus forming the Cipher--based Message based Message

Authentication Code (CMAC)Authentication Code (CMAC)

•• adopted by NIST SP800adopted by NIST SP800--38B38B

CMAC OverviewCMAC Overview

K1 = L•x

K2 = L•x2

L = E (K,0n)

GF(2blocksize)

use

Counter with Cipher Block Counter with Cipher Block

ChainingChaining--Message Message

Authentication Code (CCM) Authentication Code (CCM)

•• NIST standard SP 800NIST standard SP 800--38C for 38C for WiFiWiFi

•• variation of encryptvariation of encrypt--andand--MAC approachMAC approach

•• algorithmic ingredients algorithmic ingredients

–– AES encryption algorithmAES encryption algorithm

–– CTR mode of operationCTR mode of operation

–– CMAC authentication algorithmCMAC authentication algorithm

•• single key used for both encryption & MAC single key used for both encryption & MAC

王博文�
•之前看过DAA(CBC-MAC)•广泛用于政府和工业•但邮件大小有限制•可以克服使用2键和填充•从而形成基于密码的消息认证码(CMAC)•由NIST SP800-38B采用�
王博文�
具有密码块链接的计数器 - 消息认证码(CCM)•适用于WiFi的NIST标准SP 800-38C•加密和MAC方法的变化•算法成分 - AES加密算法 - CTR操作模式 - CMAC认证算法•用于加密和MAC的单一密钥�
Page 7: Chapter 12 – Message Cryptography and Authentication …banach/COMP61411.Info/Course...Using Symmetric Ciphers for MACs • can use any block cipher chaining mode and use final block

CCM CCM

OperationOperation

Galois/Counter Mode (GCM)Galois/Counter Mode (GCM)

•• NIST standard SP 800NIST standard SP 800--38D, parallelizable38D, parallelizable

•• message is encrypted in variant of CTRmessage is encrypted in variant of CTR

•• ciphertextciphertext multiplied with key multiplied with key HH and length and length

over GF(2over GF(2128128) to generate authenticator) to generate authenticator

•• have GMAC MAChave GMAC MAC--only mode alsoonly mode also

•• uses two functions:uses two functions:

–– GHASH GHASH -- a keyed hash functiona keyed hash function

–– GCTR GCTR -- CTR mode with incremented counterCTR mode with incremented counter

GCM GCM

Mode Mode

OverviewOverview

GCM FunctionsGCM Functions

王博文�
伽罗瓦/计数器模式(GCM)•NIST标准SP 800-38D,可并行化•邮件以CTR的变体加密•密文乘以密钥H和长度128通过GF(2)生成验证器•还具有GMAC MAC-only模式•使用两个功能: - GHASH - 一个键控哈希函数 - GCTR - CTR模式,增加计数器�
Page 8: Chapter 12 – Message Cryptography and Authentication …banach/COMP61411.Info/Course...Using Symmetric Ciphers for MACs • can use any block cipher chaining mode and use final block

GCM FunctionsGCM Functions Pseudorandom Number Pseudorandom Number

Generation (PRNG) Using Hash Generation (PRNG) Using Hash

Functions and Functions and MACsMACs

•• essential elements of PRNG are essential elements of PRNG are

–– seed valueseed value

–– deterministic algorithm deterministic algorithm

•• seed must be known only as neededseed must be known only as needed

•• can base PRNG oncan base PRNG on

–– encryption algorithm (encryption algorithm (ChsChs 7 & 10)7 & 10)

–– hash function (ISO18031 & NIST SP 800hash function (ISO18031 & NIST SP 800--90)90)

–– MAC (NIST SP 800MAC (NIST SP 800--90)90)

PRNG using a Hash FunctionPRNG using a Hash Function

•• hash PRNG from hash PRNG from

SP800SP800--90 and 90 and

ISO18031ISO18031

–– take seed Vtake seed V

–– repeatedly add 1repeatedly add 1

–– hash Vhash V

–– use nuse n--bits of hash bits of hash

as random valueas random value

•• secure if good secure if good

hash usedhash used

PRNG using a MACPRNG using a MAC

•• MAC MAC PRNGsPRNGs in in

SP800SP800--90, 90,

IEEE 802.11i, IEEE 802.11i,

TLSTLS

–– use keyuse key

–– input based on input based on

last hash in last hash in

various waysvarious ways

王博文�
•PRNG的基本要素是 - 种子价值 - 确定性算法•种子必须只在需要时才知道•可以基于PRNG - 加密算法(第7章和第10章) - 哈希函数(ISO18031和NIST SP 800-90) - MAC(NIST SP 800-90)씉
王博文�
使用散列函数和MAC的伪随机数生成(PRNG�
王博文�
- 取种子V. - 反复添加1 - 哈希五 - 使用n位散列作为随机值如果使用了好的哈希则安全�
王博文�
- 使用密钥 - 以各种方式基于最后一个哈希输入�