Try   HackMD

cryptography

目錄

  1. ECB
  2. CBC
  3. CFB
  4. OFB
  5. CTR
  6. RSA
  7. OAEP
  8. 參考資料以及繪圖軟體

ECB

說明 : 明文、密文為 1 對 1

加密(Encrypt) :

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

解密(Decrypt) :

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

  • block 是個別加密
  • 會被重送攻擊
  • block 可以被調位置
  • 安全等級低 : 因為密文同等同於明文也是相同訊息

補充 重送攻擊 :

中間人攻擊的低階版本
主要是在不同區塊產生分叉之後,因為分開之後 2 方都還擁有分開之前的資料 所以可以在 2 邊做一樣的交易,但因為分開之後各自經營的客戶與交易並不會相互交換訊息,所以可以在 B 處拿到東西並且用一樣的憑證在 C 處拿到東西

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

另一個簡單的舉例 : Alice 想向 Bob 證明自己的身分所以提供了密碼,但 Eve 竊聽了對話並保留了密碼,之後 Eve(冒充 Alice)連接到 Bob,Eve 可以傳送從 Bob 接受的最後一個對談中讀取的 Alice 的密碼讓 Eve 得到存取權限。

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

CBC

說明 : 在 ECB 加密的基礎上增加 XOR 運算

加密(Encrypt) :

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

解密(Decrypt) :

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

  • 一定要上一個 block 加密完成才能加密下一個 block
  • 當某一個 block 的 bit 出錯時,只會影響該 block 以及下一個 block
  • 如果 block 被丟失時,則會讓後續所有的 block 都被影響

補充 初始化向量 :

電腦隨機生成相同大小的密文區塊

CFB

說明 : 不同順序的 CBC 加密

加密(Encrypt) :

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

解密(Decrypt) :

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

補充 CFB 的缺陷

如果想要指定直接加密第 x 個明文,需要從頭開始加密

OFB

說明 : 彌補 CFB 加密的缺陷,只需要重複加密 (x - 1) 次初始化向量

加密(Encrypt) :

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

解密(Decrypt) :

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

CTR

說明 : 節省 OFB 加密的運算效率,讓加密過程不需重複 (x - 1) 次加密,改成使用 counter(計數器) 取代初始化向量

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

  • 可同步加密解密
  • 丟失任一 block 均不會影響其他 block

補充 CTR 小重點

不可忽略區塊加密

RSA

說明 : 目前常見的加密方法,運用質因數運算

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

解密流程

運用蒙哥馬利複除法
以下以

R=100 為例,
RN
互值
小註解 :
N<RT<N2<R2

  1. 收到
    c=16
    已知
    N=33,d=3
  2. N=N1modR=3
  3. Rc modN=1600mod33=16
  4. T1=(Rc modN)2=256
  5. x1=NT1 modR=(T1 modR)N modR=(56)×3 mod100=68
  6. Rc2 modN=R1T1 modN=T1+x1NR=256+68×33100=25
  7. T2=(Rc2 modN)(Rc modN)=25×16=400
  8. x2=NT2 modR=0
  9. Rc3 modN=R1T2 modN=T2+x2NR=4
  10. x=N(Rc3 modN) modR=12
  11. m=c3 modN=R1(Rc3 modN) modN=(Rc3 modN)+xNR=4
  • 各名詞解釋
    • c
      : 密文
    • N
      : RSA 公鑰中的模數
    • d
      : RSA 私鑰中的解密指數
    • R
      : 模數
      N
      的倍數,用於處理模運算
    • m
      : 明文

補充更詳盡的資料

https://hackmd.io/@Koios/RSA

OAEP

說明 : 一般來說會結合 RSA 加密

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

  • n
    是 RSA 加密中的位數
  • k0k1
    是協議中的固定整數
  • m
    nk0k1
    位長的明文訊息
  • GH
    為隨機預言(oracle)
  • 是 XOR

運作流程(加密)

  1. k1
    位長的
    0
    使消息填滿到
    nk0
    位的長度
  2. 隨機生成
    k0
    位長的
    r
  3. G
    k0
    位長的
    r
    擴展到
    nk0
    位長
  4. x=m000......0G(r)
  5. H
    nk0
    位長的
    x
    縮至
    k0
    位長
  6. y=rH(x)
  7. x,y

    之後可以運用 RSA 加密編碼的消息,利用 OAEP 避免 RSA 加密後的確定性

解密流程

  1. 恢復
    r
    yH(x)
  2. 恢復消息
    m000......0
    xG(r)

參考資料以及繪圖軟體