Introduction to Modern Cryptography Reading Notes
6 Hash Functions and Applications
哈希函数的定义
A hash function (with output length
) is a pair of probabilistic polynomial-time algorithms satisfying the following:
is a probabilistic algorithm that takes as input a security parameter and outputs a key . We assume that is implicit in . is a deterministic algorithm that takes as input a key and a string and outputs a string (where is the value of the security parameter implicit in ). If
is defined only for inputs of length , then we say that is a fixed-length hash function for inputs of length . In this case, we also call a compression function.
在这里,攻击者往往会知道
The collision-finding experiment
:
- A key
is generated by running . - The adversary
is given , and outputs . (If is a fixed-length hash function for inputs of length , then we require .) - The output of the experiment is defined to be
if and only if and . In such a case we say that has found a collision.
如果
下面给出两个其他关于哈希安全的概念。
- Second-preimage resistance 给出
和一个均匀分布的 ,一个PPT的 几乎无法找到 使得 - Preimage resistance 给出
和 对于一个均匀分布的 ,一个PPT的 几乎无法找到 使得 ( 可以等于 )
Merkle–Damgård 变换
Merkle–Damgård 变换可以将一个固定长度的哈希函数,用于任意长度的输入。
Let
be a compression function for inputs of length with output length . Fix and . Construct hash function as follows:
: remains unchanged.
: on input a key and a string of length , do:
- Append a
to , followed by enough zeros so that the length of the resulting string is less than a multiple of . Then append , encoded as an -bit string. Parse the resulting string as the sequence of -bit blocks . - Set
. - For
, compute . - Output
.
可以证明,如果
使用哈希函数的消息认证
对哈希函数的一般攻击
The Random-Oracle Model
random-oracle model 将哈希函数视为一个随机函数,假设存在一个随机函数
注意,random-oracle model 不是伪随机函数,因为伪随机函数只有在 key 保密时是伪随机的,但是所有群体都能计算 random-oracle model,不可能有一个保密的 key。
If
has not been queried to , then the value of is uniform.
If
queries to , the reduction can see this query and learn .
The reduction can set the value of
(i.e., the response to query ) to a value of its choice, as long as this value is correctly distributed, i.e., uniform.