《区块链技术与应用》: P2 密码学原理
P2 Cryptographic Principle
Hashing
Cryptographic Hash Functions
1. Collision Resistance (also known as Collision-Free):
- Given an input x , it is computationally infeasible(不可行的) to find another input y such that
This ensures that each message has a unique hash digest, making it practically impossible to alter the content without being detected.
给定一个 input x ,在计算上找不到另一个输入 y,使得H(x) = H(y) ,这样可以确保每条消息都有一个唯一的哈希摘要,从而几乎不可能在不被检测到的情况下更改内容。这个性质用于检测消息篡改
- While no hash function can mathematically guarantee collision resistance, some functions, such as MD5, were once thought to be resistant but were later found to be vulnerable to collision attacks.
虽然没有哈希函数可以在数学上保证抗碰撞性,理论上证明不出来这性质,靠实践经验来检验Collision Resistance,但一些函数(如 MD5)曾经被认为具有抗碰撞性,但后来发现容易受到碰撞攻击。
2. Hiding:
- A cryptographic hash function is a one-way function, meaning that it is irreversible. Given x , you can easily compute H(x) , but given H(x) , it's infeasible to find x .
加密哈希函数是单向函数,这意味着它是不可逆的。给定 x ,你可以轻松计算 H(x) ,但给定 H(x) ,找到 x 是不可行的。 note: 知道哈希没有办法反推输入,除非暴力遍历。
- This property enables digital commitment, similar to the digital equivalent of a sealed envelope. In practice, this is often combined with a random nonce, producing H(x || /text{nonce}) , ensuring that the original value remains hidden.
此属性支持 数字承诺,类似于密封信封的数字等效物 。在实践中,这通常与随机 nonce 结合使用,产生 。之所以这样干才能确保原始值保持隐藏,主要是考虑到:输入样本太小的话,暴力求解就太容易了,所以拼接Nonce增加难度(输入空间的长度、随机性、均匀性)。
数字承诺 的现实例子: 张三预测哪一个股票涨的最猛,直接公开预测的内容,很可能影响收盘结果。 所以预测结果不能提前公开。那么就,只公布一个数字承诺(哈希值),收盘之后再公开原值,因为有hiding性质,所以这个结果并不会泄露;因为有Collision Resistance性质,所以这个原消息值不能(在不被检测到的情况下)被篡改,即使是发布者张三也不能篡改,篡改会引起哈希值校验不一致。
实际操作要注意:Hiding的特性能起作用,要保证 输入空间要足够大,分布足够均匀
比如你承诺的消息值是 某一个股票编号,但是一共就几千支股票(输入空间小),很容易暴力遍历每一个原消息值计算哈希摘要,从而破解原消息值。样本空间长度够了,但是不均匀的话,也会有问题,比如高概率就只集中在某几个样本,暴力破解的成功率也就很大。
3. Puzzle-Friendliness:
性质:无法通过输出哈西值的一个范围限定,来准备输入。所以要想让哈希值落在某个特定的范围内,是没有好办法的,只有遍历去尝试。
- Bitcoin mining leverages this property by requiring the computation of a hash that begins with a certain number of leading zeros. This is typically achieved by finding a nonce such that:
- This mechanism ensures that solving the puzzle is computationally difficult but verifying the solution is straightforward.
比特币挖矿通过要求计算以一定数量的前导零开头的哈希值来利用这一特性。解决这个问题的方法: 不停尝试各个Nonce,使得。
这种机制确保解决难题在计算上很困难(只能遍历尝试,所以解决这个问题,可以作为工作量证明proof of work),但验证解决方案很简单,计算消息的哈希看是否有这么多前导0即可。
| whole output space |
+---------------------------------------------------+
|////////////| |
+---------------------------------------------------+
target space
Bitcoin utilizes the SHA-256 hash function, which satisfies all three of the properties mentioned above.
比特币使用 SHA-256 哈希函数,它满足上述所有三个属性。
Digital Signatures
-
Bitcoin Account Management
- Bitcoin, being decentralized, allows account creation independently. An account is essentially created by generating a cryptographic key pair (public and private keys).
比特币是去中心化的,允许独立创建账户(不需要任何人批准)。账户本质上就是生成一个密钥对(公钥和私钥)。
-
Asymmetric Encryption Algorithm:
- This form of encryption resolves the issue of key distribution in symmetric encryption by using a pair of keys: a public key for encryption and a private key for decryption.
- When broadcasting a transaction in Bitcoin, the sender signs it with their private key, and other nodes verify it using the sender's public key.
- 这种形式的加密通过使用一对密钥可以解决对称加密中的密钥分发不方便的问题:公钥用于加密,私钥用于解密。
- 在比特币中广播交易时,发送者使用他们的私钥进行签名,其他节点使用发送者的公钥进行验证。即,公钥用于验签,私钥用于签名
- 私钥相当于密码,需要保密,且可以证明所有权。公钥相当于银行账号,可以公开,可以标识账号。私钥签名 证明自己的所有权,公钥验签 检验对方的所有权。
-
Key Security:
- The probability of generating the same key pair as someone else is infinitesimally small.
生成与其他人相同的密钥对的概率非常小。(需要有好的随机源)
- Bitcoin requires a good source of randomness not only during key generation but also during every signing process to prevent potential private key leakage.
比特币不仅在密钥生成过程中,而且在每个签名过程中都需要良好的随机源,以防止潜在的私钥泄露。
共有 0 条评论