Professional Documents
Culture Documents
Chuong 3 Co Che Bao Mat
Chuong 3 Co Che Bao Mat
Chương 3:
CƠ CHẾ BẢO MẬT VÀ GIAO THỨC
XÁC THỰC AN TOÀN
77
101101111010101001000110000011000010001000010110111101010100001000
101101111010101001000110000011000010001000010110111101010100001000
78
Mã đối xứng
101101111010101001000110000011000010001000010110111101010100001000
§ Mật mã đối xứng sử dụng cùng một khóa cho việc mã hóa và giải
mã. Có thể nói mã đối xứng là mã một khoá hay mã khóa riêng hay
mã khoá thỏa thuận.
79
Mã đối xứng
101101111010101001000110000011000010001000010110111101010100001000
80
Mã đối xứng
101101111010101001000110000011000010001000010110111101010100001000
§ Mọi thuật toán mã cổ điển đều là mã khoá đối xứng, thông tin về
khóa được chia sẻ giữa người gửi và người nhận. Mã đối xứng là
kiểu mã khóa duy nhất trước khi phát minh ra khoá mã công khai
(còn được gọi là mã không đối xứng) vào những năm 1970.
81
Mã đối xứng - Ceasar
101101111010101001000110000011000010001000010110111101010100001000
§ Đây là mã thay thế được biết sớm nhất. Thế kỷ thứ 3 trước công
nguyên, nhà quân sự người La Mã Julius Ceasar đã nghĩ ra phương
pháp mã hóa một bản tin như sau: thay thế mỗi chữ trong bản tin
bằng chữ đứng sau nó k vị trí trong bảng chữ cái. Giả sử chọn k =
3, ta có bảng chuyển đổi như sau:
Chữ ban đầu: a b c d e f g h i j k l m n o p q r s t u v w x y z
Chữ thay thế: D E F G H I J K L M N O P Q R S T U V W X Y Z A B C
(sau Z sẽ vòng lại là A, do đó x à A, y à B và z à C)
82
Mã đối xứng - Ceasar
101101111010101001000110000011000010001000010110111101010100001000
Giả sử có bản tin gốc (bản rõ): meet me after the toga party
Như vậy bản tin mã hóa (bản mã): ………………………….....
83
Mã đối xứng - Ceasar
101101111010101001000110000011000010001000010110111101010100001000
84
Mã đối xứng – Mã thay thế đơn bảng
101101111010101001000110000011000010001000010110111101010100001000
Phương pháp đơn bảng tổng quát hóa phương pháp Ceasar bằng cách
dòng mã hóa không phải là một dịch chuyển k vị trí của các chữ cái
A, B, C, … nữa mà là một hoán vị của 26 chữ cái này. Lúc này mỗi
hoán vị được xem như là một khóa. Giả sử có hoán vị sau:
85
Mã đối xứng – Mã thay thế đơn bảng
101101111010101001000110000011000010001000010110111101010100001000
86
Mã thay thế đa ký tự - Playfair
101101111010101001000110000011000010001000010110111101010100001000
Mã hóa Playfair xem hai ký tự đứng sát nhau là một đơn vị mã hóa,
hai ký tự này được thay thế cùng lúc bằng hai ký tự khác. Playfair
dùng một ma trận 5x5 các ký tự như sau:
M O N A R
C H Y B D
E F G I/J K
L P Q S T
U V W X Z
87
Mã thay thế đa ký tự - Playfair
101101111010101001000110000011000010001000010110111101010100001000
Việc mã hóa từng cặp được thực hiện theo quy tắc:
• Nếu hai ký tự trong cặp thuộc cùng một hàng, thì được thay bằng
hai ký tự tiếp theo trong hàng. Nếu đến cuối hàng thì quay về đầu
hàng. Ví dụ cặp ar được mã hóa thành RM.
• Nếu hai ký tự trong cặp thuộc cùng một cột, thì được thay bằng hai
ký tự tiếp theo trong cột. Nếu đến cuối cột thì quay về đầu cột. Ví dụ
cặp ov được mã hóa thành HO.
88
Mã thay thế đa ký tự - Playfair
101101111010101001000110000011000010001000010110111101010100001000
Việc mã hóa từng cặp được thực hiện theo quy tắc:
• Trong các trường hợp còn lại, hai ký tự được mã hóa sẽ tạo thành
đường chéo của một hình chữ nhật và được thay bằng 2 ký tự trên
đường chéo kia. Ví dụ: hs trở thành BP (B cùng dòng với H và P
cùng dòng với S); ea trở thành IM (hoặc JM)
89
Mã thay thế đa ký tự - Playfair
101101111010101001000110000011000010001000010110111101010100001000
Nếu chỉ xét trên 26 chữ cái thì mã khóa Playfair có 26x26=676 cặp
chữ cái, do đó các cặp chữ cái này ít bị chênh lệch về tần suất hơn so
với sự chênh lệnh tần suất của từng chữ cái.
Ngoài ra số lượng các cặp chữ cái nhiều hơn cũng làm cho việc phá
mã tần suất khó khăn hơn.
90
Mã thay thế đa ký tự - Playfair
101101111010101001000110000011000010001000010110111101010100001000
91
Mã thay thế đa bảng - Vigenere
101101111010101001000110000011000010001000010110111101010100001000
Thế kỷ thứ 15, một nhà ngoại giao người Pháp tên là Vigenere đã tìm
ra phương án mã hóa thay thế đa bảng. Phương pháp Vigenere dựa
trên bảng phía dưới.
Dòng thứ k của bảng là một mã hóa Ceasar k-1 vị trí. Ví dụ, dòng
thứ 4, ứng với từ khóa D là mã hóa Ceasar 3 vị trí. (Trong trường
hợp tổng quát, mỗi dòng của bảng Vigenere không phải là một mã
hóa Ceasar nữa mà là một mã hóa đơn bảng, do đó có tên gọi là mã
hóa đa bảng).
92
Mã thay thế đa bảng - Vigenere
101101111010101001000110000011000010001000010110111101010100001000
93
Mã thay thế đa bảng - Vigenere
101101111010101001000110000011000010001000010110111101010100001000
Để mã hóa một bản tin thì cần có một khóa có chiều dài bằng chiều
dài bản tin. Thường thì khóa là một cụm từ nào đó và được viết lặp
lại cho đến khi có chiều dài bằng chiều dài bản tin. Ví dụ với bản tin
là “We are discovered, save yourself” và khóa là từ
DECEPTIVE, chúng ta mã hóa như sau:
plaintext: wearediscoveredsaveyourself
key: DECEPTIVEDECEPTIVEDECEPTIVE
ciphertext: ZICVTWQNGRZGVTWAVZHCQYGLMGJ
94
Mã thay thế đa bảng - Vigenere
101101111010101001000110000011000010001000010110111101010100001000
95
Mã Rail Fence
101101111010101001000110000011000010001000010110111101010100001000
• Đây là mã hoán vị đơn giản. Viết các chữ của bản rõ theo đường chéo trên một số
dòng. Sau đó đọc các chữ theo theo từng dòng sẽ nhận được bản mã. Số dòng
chính là khoá của mã. Vì khi biết số dòng ta sẽ tính được số chữ trên mỗi dòng và
lại viết bản mã theo các dòng sau đó lấy bản rõ bằng cách viết lại theo các cột.
• Ví dụ: Viết bản tin “meet me after the toga party” lần lượt trên hai dòng như
sau
mematrhtgpry
etefeteoaat
• Sau đó ghép các chữ ở dòng thứ nhất với các chữ ở dòng thứ hai cho bản
mã:
• MEMATRHTGPRYETEFETEOAAT
96
Mã Rail Fence
101101111010101001000110000011000010001000010110111101010100001000
97
Mã hoán vị - Permutation Cipher
101101111010101001000110000011000010001000010110111101010100001000
Cách thực hiện là xáo trộn thứ tự của các chữ cái trong bản rõ. Do
thứ tự của các chữ cái bị mất đi nên người đọc không thể hiểu được ý
nghĩa của bản tin dù các chữ đó không thay đổi.
98
Mã hoán vị - Permutation Cipher
101101111010101001000110000011000010001000010110111101010100001000
Một cách thực hiện đơn giản là ghi bản rõ theo từng hàng, sau đó kết
xuất bản mã dựa trên các cột. Ví dụ bản rõ
“attackpostponeduntilthisnoon” được viết lại thành bảng 4 x 7 như
sau:
99
Mã hoán vị - Permutation Cipher
101101111010101001000110000011000010001000010110111101010100001000
Một cơ chế phức tạp hơn là chúng ta có thể hoán vị các cột trước khi
kết xuất bản mã. Ví dụ chọn một khóa là MONARCH, ta có thể hoán
vị các cột:
100
Mã hoán vị - Permutation Cipher
101101111010101001000110000011000010001000010110111101010100001000
101
Mã hoán vị - Permutation Cipher
101101111010101001000110000011000010001000010110111101010100001000
Hoán vị 2 lần:
102
Mã hoán vị - Permutation Cipher
101101111010101001000110000011000010001000010110111101010100001000
Hoán vị 2 lần:
103
Chuẩn mã DES
101101111010101001000110000011000010001000010110111101010100001000
104
Chuẩn mã DES
101101111010101001000110000011000010001000010110111101010100001000
105
Chuẩn mã DES
101101111010101001000110000011000010001000010110111101010100001000
106
Double DES
101101111010101001000110000011000010001000010110111101010100001000
• Mã hóa:
[
C = DESK 2 DESK1 (M ) ]
• Giải mã:
[
M = DESK1 DESK 2 (C )
-1 -1
]
107
Double DES
101101111010101001000110000011000010001000010110111101010100001000
• Mã hóa:
{ [
C = DESK1 DESK 2 DESK1(M)
-1
]}
• Giải mã:
{
M = DESK1 DESK2 DESK1(C )
-1
[ -1
]}
108
101101111010101001000110000011000010001000010110111101010100001000
101101111010101001000110000011000010001000010110111101010100001000
109
Hệ mã khóa công khai
101101111010101001000110000011000010001000010110111101010100001000
110
Hệ mã khóa công khai
101101111010101001000110000011000010001000010110111101010100001000
111
Hệ mã khóa công khai
101101111010101001000110000011000010001000010110111101010100001000
• Ứng dụng:
• - Mã/giải mã – cung cấp bảo mật. Đây là ứng dụng bảo mật
truyền thống giống như ta vẫn thường dùng với khoá đối
xứng.
112
Hệ mã khóa công khai
101101111010101001000110000011000010001000010110111101010100001000
• Ứng dụng:
• - Chữ ký điện tử - cung cấp xác thực. Một trong các ứng dụng
mới của khoá công khai mà khoá đối xứng không thể thực
hiện được, đó là khoá công khai có đủ cơ sở để xác nhận
người gửi và có thể là một lựa chọn để tạo chữ ký điện tử của
người gửi.
113
Hệ mật mã RSA
101101111010101001000110000011000010001000010110111101010100001000
§ RSA là tên viết tắt của ba tác giả Rivest, Sharmir, Adleman
của trường MIT đã đề ra hệ mật mã công khai.
§ Hệ mật này được đề xuất năm 1977, dựa trên cơ sở tính các
luỹ thừa trong số học.
§ Độ an toàn của hệ mật dựa trên độ khó của việc phân tích
thành thừa số nguyên tố của các số nguyên lớn.
114
Hệ mật mã RSA
101101111010101001000110000011000010001000010110111101010100001000
Số nguyên tố
Ví dụ:
7 và 11 là 2 số nguyên tố
4 và 9 không phải là 2 số nguyên tố
Số nguyên tố cùng nhau:
2 số nguyên a và b là 2 số nguyên tố cùng nhau (ký hiệu ab), nếu
chúng có ước chung lớn nhất bằng 1 (gcd(a,b)=1 hay a b =1)
Ví dụ:
4 và 9 là 2 số nguyên tố cùng nhau vì: gcd(4, 9) = 1
15 và 25 không phải là 2 số nguyên tố cùng nhau
vì: gcd(25, 15) = 5
Hệ mật mã RSA
101101111010101001000110000011000010001000010110111101010100001000
(1) Mã hóa:
INPUT: Bản gốc m và Khóa công khai (n,e)
OUTPUT: Bản mã c = me mod n
101101111010101001000110000011000010001000010110111101010100001000
122
Identification & Authentication Protocols
101101111010101001000110000011000010001000010110111101010100001000
• The military has a need for many specialized security protocols. One such class of protocols is
used to identify friend or foe, or IFF. A simple example of an IFF protocol appears in Figure
9.1, used by the South African Air Force, or SAAF, fighting Cuban soldiers stationed in
Angola, who were flying Soviet MiG aircraft.
Simple Authentication Protocols
101101111010101001000110000011000010001000010110111101010100001000
• In this IFF protocol, when the SAAF radar detected an aircraft approaching, a random
number, or challenge, N was sent to the aircraft. All SAAF aircraft knew a key K that they
used to encrypt the challenge, E(N,K), which was then sent back to the radar station.
Simple Authentication Protocols
101101111010101001000110000011000010001000010110111101010100001000
• There is a clever attack on the IFF system in Figure 9.2. Anderson has dubbed
this attack the “MiG-in-the-middle”, which is a pun on man-in-the-middle.
Simple Authentication Protocols
101101111010101001000110000011000010001000010110111101010100001000
• Authentication Protocols:
• Simple Authentication
Simple Authentication Protocols
101101111010101001000110000011000010001000010110111101010100001000
• Authentication Protocols:
• If Trudy is able to passively observe the messages, she can later replay the messages to
convince Bob that she is Alice, as illustrated in Figure 9.4.
• Second issue is that Alice’s password is sent in the clear.
• The third issue is that Bob must know Alice’s password in order to authenticate her.
Simple Authentication Protocols
101101111010101001000110000011000010001000010110111101010100001000
• Authentication Protocols:
• Authentication Protocols:
“challenge-response” mechanism
• Authentication Protocols:
• One problem with the protocol in Figure 9.7 is that Bob must know Alice’s
password. Our next goal will be to obtain a similar result as in Figure 9.7
without requiring Bob to know Alice’s password.
Simple Authentication Protocols
101101111010101001000110000011000010001000010110111101010100001000
• Authentication Protocols:
vAuthentication Using Symmetric Keys:
Plain text: P
Key : K
to obtain cipher text C: C = E(P,K)
to recover the plaintext P: P = D(C,K)
• Suppose that Alice and Bob share symmetric key KAB and that this key is
known only to Alice and Bob.
• In the process of authenticating, the key KAB must not be revealed to Trudy.
Simple Authentication Protocols
101101111010101001000110000011000010001000010110111101010100001000
• Authentication Protocols:
vAuthentication Using Symmetric Keys:
• Authentication Protocols:
vAuthentication Using Symmetric Keys:
• Authentication Protocols:
vAuthentication Using Symmetric Keys:
• A more plausible approach to mutual authentication would be to use the secure
authentication protocol in Figure 9.8 and repeat the process twice, once for
Bob to authenticate Alice and once more for Alice to authenticate Bob.
Simple Authentication Protocols
101101111010101001000110000011000010001000010110111101010100001000
• Authentication Protocols:
vAuthentication Using Symmetric Keys:
• Authentication Protocols:
vAuthentication Using Symmetric Keys:
• In Figure 9.12, we’ve made a couple of minor changes, included the user’s identity with the
encryption of the nonce.
• The conclusion is that a one-way authentication protocol may not be secure for mutual
authentication. Yet another conclusion is that “obvious” changes to protocols can raise serious
security issues.
Simple Authentication Protocols
101101111010101001000110000011000010001000010110111101010100001000
• Authentication Protocols:
vAuthentication Using Public Keys:
to encrypt a message M with Alice’s public key: C ={M}Alice
to decrypt C with Alice’s private key: M = [C]Alice
• The serious problem: if Alice uses the same key pair to encrypt as she uses for
authentication….
Simple Authentication Protocols
101101111010101001000110000011000010001000010110111101010100001000
• Authentication Protocols:
vAuthentication Using Public Keys:
• The protocol in Figure 9.14 accomplishes authentication using digital signatures. It has the
same flaw: if Trudy can pose as Bob, she can get Alice to sign anything. The solution to this
problem is to always use different key pairs for signing and encryption.
Simple Authentication Protocols
101101111010101001000110000011000010001000010110111101010100001000
• Authentication Protocols:
vSession Keys:
• In addition to authentication, a session key is often required.
• Authentication Protocols:
vSession Keys:
• There is a fatal flaw in Figure 9.16. Since the key is signed, anybody can use
Bob’s (or Alice’s) public key and find the session key K. BUT it does provide
mutual authentication.
• Can we improve on these protocols to achieve both mutual authentication and
a secure session key?
Simple Authentication Protocols
101101111010101001000110000011000010001000010110111101010100001000
• Authentication Protocols:
vSession Keys:
• Authentication Protocols:
vSession Keys:
• Authentication Protocols:
vPerfect Forward Secrecy:
• Suppose that Alice encrypts a message with a shared symmetric
key KAB and sends the resulting ciphertext to Bob.
• If Trudy records the ciphertext and later attacks Alice’s computer
and finds the shared key KAB, then Trudy can decrypt the recorded
ciphertext.
• The purpose of PFS is to prevent this from happening.
Simple Authentication Protocols
101101111010101001000110000011000010001000010110111101010100001000
• Authentication Protocols:
vPerfect Forward Secrecy:
• This protocol fails to provide PFS, since Trudy could also record the first message E(KS,KAB)
along with the ciphertext encrypted with KS. Then if she later recovers KAB, she can recover
the session key KS and use it to decrypt the recorded ciphertext messages.
Simple Authentication Protocols
101101111010101001000110000011000010001000010110111101010100001000
• Authentication Protocols:
vPerfect Forward Secrecy:
• The protocol appears in Figure 9.20 is Diffie-Hellman key exchange protocol. In this protocol,
g and p are public, and Alice chooses a secret exponent a and Bob a secret exponent b. Then
Alice sends ga mod p to Bob and Bob sends gb mod p to Alice. Alice and Bob can then each
compute the shared secret gab mod p.
Simple Authentication Protocols
101101111010101001000110000011000010001000010110111101010100001000
• Authentication Protocols:
vPerfect Forward Secrecy:
• When Alice has computed the shared session key KS = gab mod p, she must
forget her secret exponent a and Bob must forget his secret exponent b.
• If Trudy records the conversation in Figure 9.21 and later is able to find KAB,
she will not be able to recover the session key KS unless she can break Diffie-
Hellman.
Simple Authentication Protocols
101101111010101001000110000011000010001000010110111101010100001000
• Authentication Protocols:
vMutual Authentication, Session Key, and PFS:
Simple Authentication Protocols
101101111010101001000110000011000010001000010110111101010100001000
• Authentication Protocols:
vTimestamps:
• A timestamp T can be used in place of a nonce, we don’t
need to waste any messages exchanging nonces.
• Timestamps are used in many real-world security
protocols, such as Kerberos—which we’ll discuss in the
next slides.
Simple Authentication Protocols
101101111010101001000110000011000010001000010110111101010100001000
• Authentication Protocols:
vTimestamps:
• The protocol in Figure 9.23 uses a timestamp with the sign and encrypt
authentication protocol, so obviously the timestamp version of encrypt and
sign must also be secure???
Simple Authentication Protocols
101101111010101001000110000011000010001000010110111101010100001000
• Authentication Protocols:
vTimestamps:
Simple Authentication Protocols
101101111010101001000110000011000010001000010110111101010100001000
• Authentication Protocols:
vTimestamps:
• The attack in Figure 9.25 shows that our encrypt and sign is not secure when we use a
timestamp. But our sign and encrypt protocol seems to be secure when a timestamp is used. In
addition, the non-timestamp versions of both sign and encrypt as well as encrypt and sign are
secure (see Figures 9.17 and 9.18). These examples clearly illustrate that, when it comes to
security protocols, we can never take anything for granted.
Bài tập
101101111010101001000110000011000010001000010110111101010100001000
IAUTMOCSNREBDLHVWYFPZJXKGQ
153
Bài tập
101101111010101001000110000011000010001000010110111101010100001000
154
Bài tập
101101111010101001000110000011000010001000010110111101010100001000
155
Thảo luận
101101111010101001000110000011000010001000010110111101010100001000
156
Câu hỏi ôn tập
101101111010101001000110000011000010001000010110111101010100001000
157
Hết chương 3
158