密码学入门与 Key signing party

陈天宇

May 2021

...... HITLUG 密码学入门与 Key signing party May 2021 1 / 49 Table of Contents

1 What is ? What cryptography is and what cryptography is not? 2 Cryptography Conventional Modern Cryptography Symmetric-key cryptography Public-key cryptography 国密算法 Hash Functions 3 PKI 4 Applications SSH TLS PGP BlockChain

5 Key signing Party ...... HITLUG 密码学入门与 Key signing party May 2021 2 / 49 Table of Contents

1 What is cryptography? What cryptography is and what cryptography is not? 2 Cryptography Conventional Encryption Modern Cryptography Symmetric-key cryptography Public-key cryptography Hybrid cryptosystem 国密算法 Hash Functions 3 PKI 4 Applications SSH TLS PGP BlockChain

5 Key signing Party ...... HITLUG 密码学入门与 Key signing party May 2021 3 / 49 What is Encryption & Decryption

...... HITLUG 密码学入门与 Key signing party May 2021 4 / 49 What is cryptography?

The science of using mathematics to encrypt and decrypt data Cryptography enables you to store sensitive information or transmit it across insecure networks (like the ) so that it cannot be read by anyone except the intended recipient.

...... HITLUG 密码学入门与 Key signing party May 2021 5 / 49 Table of Contents

1 What is cryptography? What cryptography is and what cryptography is not? 2 Cryptography Conventional Encryption Modern Cryptography Symmetric-key cryptography Public-key cryptography Hybrid cryptosystem 国密算法 Hash Functions 3 PKI 4 Applications SSH TLS PGP BlockChain

5 Key signing Party ...... HITLUG 密码学入门与 Key signing party May 2021 6 / 49 What cryptography is and what cryptography is not?

Encode / Decode Encrypt / Decrypt

...... HITLUG 密码学入门与 Key signing party May 2021 7 / 49 Encode / Decode

ASCII Morse code Base16 / Base32 / Base58 / Base64 GB2312 / Big-5 / UTF-8

...... HITLUG 密码学入门与 Key signing party May 2021 8 / 49 Encrypt / Decrypt

Conventional Encryption Symmetric-key cryptography Public-key cryptography Hybrid cryptosystem

...... HITLUG 密码学入门与 Key signing party May 2021 9 / 49 Table of Contents

1 What is cryptography? What cryptography is and what cryptography is not? 2 Cryptography Conventional Encryption Modern Cryptography Symmetric-key cryptography Public-key cryptography Hybrid cryptosystem 国密算法 Hash Functions 3 PKI 4 Applications SSH TLS PGP BlockChain

5 Key signing Party ...... HITLUG 密码学入门与 Key signing party May 2021 10 / 49 Table of Contents

1 What is cryptography? What cryptography is and what cryptography is not? 2 Cryptography Conventional Encryption Modern Cryptography Symmetric-key cryptography Public-key cryptography Hybrid cryptosystem 国密算法 Hash Functions 3 PKI 4 Applications SSH TLS PGP BlockChain

5 Key signing Party ...... HITLUG 密码学入门与 Key signing party May 2021 11 / 49 Conventional Encryption

图: 凯撒密码 (Caesar’s Cipher)

...... HITLUG 密码学入门与 Key signing party May 2021 12 / 49 Conventional Encryption

图: ROT13

...... HITLUG 密码学入门与 Key signing party May 2021 13 / 49 维吉尼亚密码 (Vigenère cipher)

图: 维吉尼亚密码 (Vigenère cipher)

...... HITLUG 密码学入门与 Key signing party May 2021 14 / 49 维吉尼亚密码 (Vigenère cipher)

CipherText ≡ PlainText + Key(mod26)

图: Vigenère cipher

...... HITLUG 密码学入门与 Key signing party May 2021 15 / 49 恩尼格玛密码机 (Enigma)

://zh.wikipedia.org/wiki/￿￿￿￿￿￿￿ https://youtu.be/V4V2bpZlqx8

...... HITLUG 密码学入门与 Key signing party May 2021 16 / 49 Table of Contents

1 What is cryptography? What cryptography is and what cryptography is not? 2 Cryptography Conventional Encryption Modern Cryptography Symmetric-key cryptography Public-key cryptography Hybrid cryptosystem 国密算法 Hash Functions 3 PKI 4 Applications SSH TLS PGP BlockChain

5 Key signing Party ...... HITLUG 密码学入门与 Key signing party May 2021 17 / 49 Symmetric-key cryptography

DES 3DES AES RC2 RC4

...... HITLUG 密码学入门与 Key signing party May 2021 18 / 49 1998 年 7 月,EFF 的 DES 破解机(Deep Crack)在 56 小时内破解 了 DES 密钥 1999 年 1 月,Deep Crack 和 distributed.net 合作在 22 小时 15 分 钟内破解了一个 DES 密钥 1999 年 10 月,DES 作为 FIPS46-3 第四次延长标准期限,其中规 定优先使用 3DES,而普通 DES 只允许在遗留的系统中应用 2000 年 10 月,在历时接近 5 年的征集和选拔之后,NIST 选择了高级 加密标准(AES)替代 DES 和 3DES。2001 年 2 月 28 日,联邦公报发 表了 AES 标准,以此开始了其标准化进程,并于 2001 年 11 月 26 日成 为 FIPS PUB 197 标准。

DES

DES 1976 年被美国联邦政府的国家标准局确定为联邦资料处理标准 (FIPS),随后在国际上广泛流传开来。 它基于使用 56 位密钥的对称算法。

...... HITLUG 密码学入门与 Key signing party May 2021 19 / 49 2000 年 10 月,在历时接近 5 年的征集和选拔之后,NIST 选择了高级 加密标准(AES)替代 DES 和 3DES。2001 年 2 月 28 日,联邦公报发 表了 AES 标准,以此开始了其标准化进程,并于 2001 年 11 月 26 日成 为 FIPS PUB 197 标准。

DES

DES 1976 年被美国联邦政府的国家标准局确定为联邦资料处理标准 (FIPS),随后在国际上广泛流传开来。 它基于使用 56 位密钥的对称算法。 1998 年 7 月,EFF 的 DES 破解机(Deep Crack)在 56 小时内破解 了 DES 密钥 1999 年 1 月,Deep Crack 和 distributed.net 合作在 22 小时 15 分 钟内破解了一个 DES 密钥 1999 年 10 月,DES 作为 FIPS46-3 第四次延长标准期限,其中规 定优先使用 3DES,而普通 DES 只允许在遗留的系统中应用

...... HITLUG 密码学入门与 Key signing party May 2021 19 / 49 DES

DES 1976 年被美国联邦政府的国家标准局确定为联邦资料处理标准 (FIPS),随后在国际上广泛流传开来。 它基于使用 56 位密钥的对称算法。 1998 年 7 月,EFF 的 DES 破解机(Deep Crack)在 56 小时内破解 了 DES 密钥 1999 年 1 月,Deep Crack 和 distributed.net 合作在 22 小时 15 分 钟内破解了一个 DES 密钥 1999 年 10 月,DES 作为 FIPS46-3 第四次延长标准期限,其中规 定优先使用 3DES,而普通 DES 只允许在遗留的系统中应用 2000 年 10 月,在历时接近 5 年的征集和选拔之后,NIST 选择了高级 加密标准(AES)替代 DES 和 3DES。2001 年 2 月 28 日,联邦公报发 表了 AES 标准,以此开始了其标准化进程,并于 2001 年 11 月 26 日成 为 FIPS PUB 197 标准。

...... HITLUG 密码学入门与 Key signing party May 2021 19 / 49 3DES

对每个数据块应用三次资料加密标准(DES)算法 由于 DES 密钥长度过低,容易被暴力破解;3DES 便被设计用来提供一 种相对简单的方法,通过增加 DES 的密钥长度来避免被暴力破解,而 不是设计一种全新的块密码算法。

...... HITLUG 密码学入门与 Key signing party May 2021 20 / 49 AES

AddRoundKey SubBytes ShiftRows MixColumns

...... HITLUG 密码学入门与 Key signing party May 2021 21 / 49 Public-key cryptography

DSA RSA ElGamal ECDSA

...... HITLUG 密码学入门与 Key signing party May 2021 22 / 49 DSA

基于模算数和离散对数的复杂度 NIST 于 1991 年提出将 DSA 用于其数字签名标准,并于 1994 年将其 作为 FIPS 186 采用。

...... HITLUG 密码学入门与 Key signing party May 2021 23 / 49 RSA

p, q, N, r, e, d

图: RSA Calculator

...... HITLUG 密码学入门与 Key signing party May 2021 24 / 49 Hybrid cryptosystem & Session key

A hybrid cipher uses both a symmetric cipher and a public-key cipher. It works by using a public-key cipher to share a key for the symmetric cipher. The actual message being sent is then encrypted using the key and sent to the recipient. Since symmetric key sharing is secure, the symmetric key used is different for each message sent. Hence it is sometimes calleda session key. Explanation in The GNU Privacy Handbook

...... HITLUG 密码学入门与 Key signing party May 2021 25 / 49 Table of Contents

1 What is cryptography? What cryptography is and what cryptography is not? 2 Cryptography Conventional Encryption Modern Cryptography Symmetric-key cryptography Public-key cryptography Hybrid cryptosystem 国密算法 Hash Functions 3 PKI 4 Applications SSH TLS PGP BlockChain

5 Key signing Party ...... HITLUG 密码学入门与 Key signing party May 2021 26 / 49 国密算法

SM1:为对称加密。其加密强度与 AES 相当。该算法不公开,调用 该算法时,需要通过加密芯片的接口进行调用。 SM2:非对称加密,基于 ECC(椭圆加密算法)。该算法已公开。由 于该算法基于 ECC,故其签名速度与秘钥生成速度都快于 RSA。 ECC256 位(SM2 采用的就是 ECC256 位的一种)安全强度比 RSA 2048 位高,但运算速度快于 RSA。即 SM2>RSA2048,安全度高且 运算速度块。 SM3:消息摘要,可以用 MD5 作为对比理解。该算法已公开。校 验结果为 256 位。 SM4:对称加密,密钥长度和分组长度均为 128 位。无线局域网标 准的分组数据算法。

...... HITLUG 密码学入门与 Key signing party May 2021 27 / 49 GmSSL

GmSSL 是一个开源的密码工具箱,支持 SM2/SM3/SM4/SM9/ZUC 等 国密 (国家商用密码) 算法、SM2 国密数字证书及基于 SM2 证书的 SSL/TLS 安全通信协议,支持国密硬件密码设备,提供符合国密规范的 编程接口与命令行工具,可以用于构建 PKI/CA、安全通信、数据加密 等符合国密标准的安全应用。GmSSL 项目是 OpenSSL 项目的分支,并 与 OpenSSL 保持接口兼容。因此 GmSSL 可以替代应用中的 OpenSSL 组件,并使应用自动具备基于国密的安全能力。GmSSL 项目采用对商业 应用友好的类 BSD 开源许可证,开源且可以用于闭源的商业应用。 http://gmssl.org/

...... HITLUG 密码学入门与 Key signing party May 2021 28 / 49 Table of Contents

1 What is cryptography? What cryptography is and what cryptography is not? 2 Cryptography Conventional Encryption Modern Cryptography Symmetric-key cryptography Public-key cryptography Hybrid cryptosystem 国密算法 Hash Functions 3 PKI 4 Applications SSH TLS PGP BlockChain

5 Key signing Party ...... HITLUG 密码学入门与 Key signing party May 2021 29 / 49 Hash Functions

MD5 SHA-1 SHA-2(SHA-224, SHA-256, SHA-384, etc.)

In late 2018 the project picked SHA-256 as its successor hash. ()

...... HITLUG 密码学入门与 Key signing party May 2021 30 / 49 Table of Contents

1 What is cryptography? What cryptography is and what cryptography is not? 2 Cryptography Conventional Encryption Modern Cryptography Symmetric-key cryptography Public-key cryptography Hybrid cryptosystem 国密算法 Hash Functions 3 PKI 4 Applications SSH TLS PGP BlockChain

5 Key signing Party ...... HITLUG 密码学入门与 Key signing party May 2021 31 / 49 Public Key Infrastructure

...... HITLUG 密码学入门与 Key signing party May 2021 32 / 49 PKI in SSL/TLS

Domain Validation Organization Validation Extended Validation

...... HITLUG 密码学入门与 Key signing party May 2021 33 / 49 PKI in SSL/TLS

...... HITLUG 密码学入门与 Key signing party May 2021 34 / 49 PKI in SSL/TLS

Automated Certificate Management Environment(rfc8555) ca-certificates Certificate revocation list (CRL) Online Certificate Status Protocol (OCSP)

https://crt.sh/

...... HITLUG 密码学入门与 Key signing party May 2021 35 / 49 Table of Contents

1 What is cryptography? What cryptography is and what cryptography is not? 2 Cryptography Conventional Encryption Modern Cryptography Symmetric-key cryptography Public-key cryptography Hybrid cryptosystem 国密算法 Hash Functions 3 PKI 4 Applications SSH TLS PGP BlockChain

5 Key signing Party ...... HITLUG 密码学入门与 Key signing party May 2021 36 / 49 Applications

SSH TLS PGP Blockchain

...... HITLUG 密码学入门与 Key signing party May 2021 37 / 49 Table of Contents

1 What is cryptography? What cryptography is and what cryptography is not? 2 Cryptography Conventional Encryption Modern Cryptography Symmetric-key cryptography Public-key cryptography Hybrid cryptosystem 国密算法 Hash Functions 3 PKI 4 Applications SSH TLS PGP BlockChain

5 Key signing Party ...... HITLUG 密码学入门与 Key signing party May 2021 38 / 49 SSH

Secure SHell (protocol)

Alternative to , OpenSSH, PuTTY Connect to remote X11 Forwarding SFTP / SCP Push Git commit to GitHub, GitLab

...... HITLUG 密码学入门与 Key signing party May 2021 39 / 49 Table of Contents

1 What is cryptography? What cryptography is and what cryptography is not? 2 Cryptography Conventional Encryption Modern Cryptography Symmetric-key cryptography Public-key cryptography Hybrid cryptosystem 国密算法 Hash Functions 3 PKI 4 Applications SSH TLS PGP BlockChain

5 Key signing Party ...... HITLUG 密码学入门与 Key signing party May 2021 40 / 49 TLS

BoringSSL, GnuTLS, LibreSSL, OpenSSL, wolfSSL

HTTPS Email FTPS DNS mmTLS

...... HITLUG 密码学入门与 Key signing party May 2021 41 / 49 Table of Contents

1 What is cryptography? What cryptography is and what cryptography is not? 2 Cryptography Conventional Encryption Modern Cryptography Symmetric-key cryptography Public-key cryptography Hybrid cryptosystem 国密算法 Hash Functions 3 PKI 4 Applications SSH TLS PGP BlockChain

5 Key signing Party ...... HITLUG 密码学入门与 Key signing party May 2021 42 / 49 PGP

Pretty Good Privacy GnuPG, GnuPG2 apt, rpm, pacman email Git Commit, Git Tag XMPP mnter key-cert

...... HITLUG 密码学入门与 Key signing party May 2021 43 / 49 PGP

Key server

keys.openpgp.org pgp.mit.edu keyring.debian.org keyserver.ubuntu.com attester.flowcrypt.com zimmermann.mayfirst.org

...... HITLUG 密码学入门与 Key signing party May 2021 44 / 49 Table of Contents

1 What is cryptography? What cryptography is and what cryptography is not? 2 Cryptography Conventional Encryption Modern Cryptography Symmetric-key cryptography Public-key cryptography Hybrid cryptosystem 国密算法 Hash Functions 3 PKI 4 Applications SSH TLS PGP BlockChain

5 Key signing Party ...... HITLUG 密码学入门与 Key signing party May 2021 45 / 49 BlockChain

BTC: Bitcoin uses the Elliptic Curve Digital Signature Algorithm (ECDSA). Your private key is used to create the signature and your public key is used to verify the signature.

ETH: Ethereum uses ECDSA (Elliptic Curve Digital Signature Algorithm) for it’s public-key cryptography.

...... HITLUG 密码学入门与 Key signing party May 2021 46 / 49 Table of Contents

1 What is cryptography? What cryptography is and what cryptography is not? 2 Cryptography Conventional Encryption Modern Cryptography Symmetric-key cryptography Public-key cryptography Hybrid cryptosystem 国密算法 Hash Functions 3 PKI 4 Applications SSH TLS PGP BlockChain

5 Key signing Party ...... HITLUG 密码学入门与 Key signing party May 2021 47 / 49 Key signing Party

...... HITLUG 密码学入门与 Key signing party May 2021 48 / 49 Key signing Party

Create a keypair Generate a revocation certificate Make your public key public Get your key digitally signed Send your signed key to the server

https://wiki.debian.org/Keysigning https://wiki.ubuntu.com/KeySigningParty The Keysigning Party HOWTO

...... HITLUG 密码学入门与 Key signing party May 2021 49 / 49