首页 > 其他分享 >52 Things: Number 15: Key generation, encryption and decryption algorithms for RSA-OAEP and ECIES.

52 Things: Number 15: Key generation, encryption and decryption algorithms for RSA-OAEP and ECIES.

时间:2024-04-11 23:35:12浏览次数:14  
标签:decryption 15 0t generation encryption RSA OAEP 加密 scheme

52 Things: Number 15: Key generation, encryption and decryption algorithms for RSA-OAEP and ECIES.

52件事:第15件:RSA-OAEP和ECIES的密钥生成、加密和解密算法。

  This is the latest in a series of blog posts to address the list of  '52 Things Every PhD Student Should Know' to do Cryptography: a set of questions compiled to give PhD candidates a sense of what they should know by the end of their first year. We came back to "more crypto" staff by describing the key generation, encryption and decryption algorithms for RSA-OAEP and ECIES. 
这是一系列博客文章中的最新一篇,旨在解决“每个博士生都应该知道的52件事”做密码学:这是一组问题,旨在让博士生在第一年结束时了解他们应该知道什么。我们通过描述RSA-OAEP和ECIES的密钥生成、加密和解密算法,回到了“更多加密”的工作人员。



1. RSA-OAEP 1.RSA-OAEP
RSA-OAEP  stands for RSA encryption/decryption scheme and OAEP padding scheme respectively. They are often used conjointly in real world.
RSA-OAEP分别代表RSA加密/解密方案和OAEP填充方案。它们在现实世界中经常被联合使用。

1.1 RSA[1]
RSA is one of the earliest public key encryption scheme that has been deployed widely in real world. It is based on the assumption of the hardness of RSA problem which has been described in previous blog (here).
RSA是最早在现实世界中广泛部署的公钥加密方案之一。它是基于先前博客(此处)中描述的RSA问题的硬度的假设。

Key Generation: 密钥生成:
  1.  Generate two large primes p, q, and compute the modulo N=pq.
    生成两个大素数 p 、 q ,并计算模 N=pq 。
  2.  Selects a random number e∈ZN s.t. gcd(ϕ(N),e)=1 where gcd stands for Greatest Common Divisor
    选择一个随机数 e∈ZN s.t. gcd(ϕ(N),e)=1 ,其中#2代表最大公约数。
  3.  Since ϕ(N) and e are co-prime (gcd(ϕ(N),e)=1), we can use XGCD to find the multiplicative inverse d of e over modulo ϕ(N): d=e−1modϕ(N).
    由于 ϕ(N) 和 e 是同素( gcd(ϕ(N),e)=1 ),我们可以使用XGCD来找到#4在模 ϕ(N) 上的乘法逆 d : d=e−1modϕ(N) 。
  4. We distribute (N,e) as our public key and hold (p,q,d) as our secret key.
    我们将 (N,e) 作为公钥分发,并将 (p,q,d) 作为私钥。
Encryption: 加密:
  1. Parse the message to an integer m∈ZN.
    将消息解析为整数 m∈ZN 。
  2. Compute c=memodN. 计算 c=memodN 。
  3. Output c as our ciphertext.
    输出 c 作为我们的密文。
Decryption: 解密:
Before we receive the ciphertext, we precompute some values: dmodp−1, q−1modp, dmodq−1 and p−1modq.
在我们收到密文之前,我们预先计算一些值: dmodp−1 、 q−1modp 、 dmodq−1 和 p−1modq 。
Then upon receiving the ciphertext c, we
然后,在接收到密文 c 之后,我们
  1. Compute 计算 dmodp−1
  2. Output m as our plaintext.
    输出 m 作为我们的明文。
Notice that the computation of m is in fact m=cdmodN using CRT. The reason is that performing exponentiations over small modulo(p and q) are faster than doing it over large modulos(N). The decryption works by applying  Fermat's Little Theorem and we will have cd=med=m1modϕ(N)=m(modN) .
请注意, m 的计算实际上是使用CRT的 m=cdmodN 。原因是在小模(#2和#3)上执行幂运算比在大模(#4)上执行快。解密通过应用费马小定理来进行,我们将得到 cd=med=m1modϕ(N)=m(modN) 。

1.2 OAEP[2]
OAEP stands for Optimal Asymmetric Encryption Padding. It is a padding scheme used together with asymmetric encryption (usually RSA). It can bring some randomness to a deterministic encryption scheme. When used with RSA, the combined scheme is proven to be IND-CCA secure.
OAEP代表最优非对称加密填充。它是一种与非对称加密(通常为RSA)一起使用的填充方案。它可以给确定性加密方案带来一些随机性。当与RSA一起使用时,组合方案被证明是IND-CCA安全的。

Let
  • f be a k-bit trapdoor one-way permutation. f:{0,1}k→{0,1}k
    f 是 k 比特陷门单向排列#2.
  • m be the n-bit message
    m 是 n 位消息
  • G, H be two psudorandom functions: G:{0,1}s→{0,1}n+t and H:{0,1}n+t→{0,1}s, where k=n+t+s
    G 、 H 是两个伪随机函数: G:{0,1}s→{0,1}n+t 和 H:{0,1}n+t→{0,1}s ,其中 k=n+t+s
  • R be s-bit random number: R←{0,1}s
    R 为 s -位随机数: R←{0,1}s
Encryption: 加密:
We compute the k-bit ciphertext as follows:
我们计算 k 位密文如下:
Encrypt(m)=fpk({(m||0t)⊕G(R)}||{R⊕H((m||0t)⊕G(R))})

Decryption: 解密:
By using the trapdoor, we can recover the following value:
通过使用活板门,我们可以恢复以下值:
fsk(c)={(m||0t)⊕G(R)}||{R⊕H((m||0t)⊕G(R))}

Then 然后
  1.  Let the first n+t bits be T: T=(m||0t)⊕G(R), and the other s bits be S: S=R⊕H((m||0t)⊕G(R))
    设前 n+t 位为 T : T=(m||0t)⊕G(R) ,其他 s 位为#4: S=R⊕H((m||0t)⊕G(R))
  2.  Compute R as R=H(T)⊕S
    将 R 计算为 R=H(T)⊕S
  3.  Compute m||0t=T⊕G(R) 计算 m||0t=T⊕G(R)
  4. Verify if there is exactly t 0s following the n-bit message m. If validated, remove the t 0 bits and output m.
    验证 n 位消息 m 后面是否正好有 t 0s。如果已验证,则删除 t 0位并输出#4。
In practice, we replace fpk and fsk by RSA encryption and decryption function respectively.
在实践中,我们分别用RSA加解密函数代替 fpk 和 fsk 。

ECIES

Elliptic Curve Integrated Encryption Scheme is a variation of ElGamal public key encryption scheme based on Elliptic Curve Cryptography (click here to find more about elliptic curve).
椭圆曲线集成加密方案是基于椭圆曲线密码学的ElGamal公钥加密方案的变体(点击此处了解更多关于椭圆曲线的信息)。

For simplicity, we define an Elliptic Curve in the form:
为了简单起见,我们将椭圆曲线定义为:

E:y2=x3+ax+b

To further simplify our problem, we only discuss a curve E on a prime field Fq with a base point P having a prime order n. Then we can define a simplified domain parameter: D=(q,a,b,P,n) where:
为了进一步简化我们的问题,我们只讨论素数域 Fq 上的曲线 E ,其中基点 P 具有素数阶 n 。然后我们可以定义一个简化的域参数:#4,其中:
  • q is the prime field order. i.e. q is a prime and x,y,a,b are reduced to {0,1,2,...,q−1}
    q 是素数域顺序。即 q 是素数,#2被减少到 {0,1,2,...,q−1}
  • a,b are the coefficients of the curve.
    a,b 是曲线的系数。
  • P is a point on the curve.
    P 是曲线上的一个点。
  • n is the prime order of P. i.e. additions of P yields n points on the curve where n is a prime.
    n 是 P 的素数阶。即#2的相加在曲线上产生#3个点,其中#4是素数。
The domain parameter are made public.
域参数已公开。

ECIES are always associated with a symmetric encryption scheme and a MAC scheme. We denote them as {Enck(m)=c,Deck(c)=m} and {MACk(m)=t,Very(t,m)=T/F} respectively.
ECIES总是与对称加密方案和MAC方案相关联。我们将它们分别表示为 {Enck(m)=c,Deck(c)=m} 和 {MACk(m)=t,Very(t,m)=T/F} 。

We also denote KDF(s1,s2)=(kenc,kMAC) as the Key Derivation Function which takes two seeds s1,s2 and outputs a pair of symmetric encryption key and MAC key.
我们还将 KDF(s1,s2)=(kenc,kMAC) 表示为密钥推导函数,其取两个种子 s1,s2 并输出一对对称加密密钥和MAC密钥。

Then we describe the scheme as:
然后我们将该方案描述为:

Key Generation: 密钥生成:
  1. Pick a random integer d∈[1,n−1].
    选取一个随机整数 d∈[1,n−1] 。
  2. Compute a new point Q=dP.
    计算一个新点 Q=dP 。
  3.  Output Q as the public key and d as the secret key.
    输出 Q 作为公钥,输出 d 作为密钥。
Then the encryption of a message m is done as follows:
然后,消息 m 的加密如下进行:

Encryption:    加密:
  1.  Pick a random integer k∈[1,n−1].
    选取一个随机整数 k∈[1,n−1] 。
  2.  Compute R=kP,Z=kQ. If Z=∞ then we restart the process and pick a different k.
    计算 R=kP,Z=kQ 。如果是 Z=∞ ,那么我们重新启动流程并选择不同的 k 。
  3.  Generate (k1,k2)=KDF(xZ,R) where xZ is the x-coordinate of Z.
    生成 (k1,k2)=KDF(xZ,R) ,其中 xZ 是 Z 的 x 坐标。
  4. Compute c=Enck1(m) and t=MACk2(c).
    计算 c=Enck1(m) 和 t=MACk2(c) 。
  5. Output (R,c,t) as the ciphertext.
    输出 (R,c,t) 作为密文。
On receiving a ciphertext (R,c,t),
在接收到密文 (R,c,t) 时,

Decryption: 解密:
  1.  Verify if R is valid. This can be easily done by substituting R in to the curve.
    验证 R 是否有效。这可以很容易地通过将 R 代入曲线来实现。
  2. Compute Z′=dR. 计算 Z′=dR 。
  3. Generate (k′1,k′2)=KDF(xZ′,R), where xZ′ is the x-coordinate of Z′.
    生成 (k′1,k′2)=KDF(xZ′,R) ,其中 xZ′ 是 Z′ 的 x 坐标。
  4. Verify if MAC is correct by calling Very(t,c).
    通过调用 Very(t,c) 验证MAC是否正确。
  5. Decrypt m′=Deck′1. 解密 m′=Deck′1 。
  6. Output m′ as the plaintext.
    输出 m′ 作为明文。
Since Z′=dR=dkP=kQ=Z; therefore seeds fed to KDF() are in fact same. Hence receiver can generate keys as same as the sender's and decrypt the message.
自 Z′=dR=dkP=kQ=Z ;因此,喂给KDF()的种子实际上是相同的。因此,接收方可以生成和发送方相同的密钥,并对消息进行解密。

However, my knowledge to ECC is very limited. For those who are interested, you can find more in [4].
然而,我对ECC的了解非常有限。对于那些感兴趣的人,你可以在[4]中找到更多信息。  

标签:decryption,15,0t,generation,encryption,RSA,OAEP,加密,scheme
From: https://www.cnblogs.com/3cH0-Nu1L/p/18106076

相关文章

  • 52 Things: Number 16: Describe the key generation, signature and verification al
    52Things:Number16:Describethekeygeneration,signatureandverificationalgorithmsforDSA,SchnorrandRSA-FDH.52件事:第16件:描述DSA、Schnorr和RSA-FDH的密钥生成、签名和验证算法。 Thisisthelatestinaseriesofblogpoststoaddressthelistof'......
  • Educational Codeforces Round 154 (Rated for Div. 2)
    B和C写的太慢了。吃了不该吃的罚时,C还莫名其妙的T了一发,另一发也是不应该T的。B连想了两个假做法,然后甚至都实现了,然后过不了样例,再基于这两个才想到了真做法。当时的思路已经有些模糊了,但是确实是写的太慢了,而且\(O(n^2)\)的限制给的也很宽裕,但是我居然还傻乎乎的去先\(O(n^2)......
  • 2024-04-11 15:45
    今天终于是写上日记了,之前要么没时间要么就不想写,过完年后有一大片空白期,领导看我们很清闲,就给我们各自安排学习任务,我学习Flutter相关知识,但是学习了之后发现Flutter是个框架,里边的语言是dart语言,发现还的学习dart,还要整理学习文档,哦我的天之前的东西都没明白就又学习另外一种语......
  • 算法训练营Day08-LeetCode344. 反转字符串 && 541. 反转字符串 II && 151. 反转字符串
    344.反转字符串题目链接:LeetCode344.反转字符串编写一个函数,其作用是将输入的字符串反转过来。输入字符串以字符数组s的形式给出。不要给另外的数组分配额外的空间,你必须原地修改输入数组、使用O(1)的额外空间解决这一问题思路:字符串首尾字符交换即可完成反转。定......
  • (数据科学学习手札159)使用ruff对Python代码进行自动美化
    本文示例代码已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes1简介大家好我是费老师,在日常编写Python代码的过程中,由于个人经验及编程习惯上的差异,有些人写出的代码可读性很高,一眼看上去就非常整洁易懂,而有些人写出的代码则十分“潦草随意”,......
  • 力扣经典150题第十六题:接雨水
    目录力扣经典150题第十六题:接雨水1.题目描述2.问题分析3.解题思路4.代码实现5.时间复杂度分析6.应用和扩展7.总结8.参考资料力扣经典150题第十六题:接雨水1.题目描述给定n个非负整数表示每个宽度为1的柱子的高度图,计算按此排列的柱子,下雨之后能接多少......
  • 力扣经典150题第十五题:分发糖果
    目录力扣经典150题第十五题:分发糖果1.题目描述2.问题分析3.解题思路4.代码实现5.时间复杂度分析6.应用和扩展7.总结8.参考资料力扣经典150题第十五题:分发糖果1.题目描述n个孩子站成一排。给你一个整数数组ratings表示每个孩子的评分。你需要按照以下......
  • LeetCode 面试经典150题---005
    ####135.分发糖果n个孩子站成一排。给你一个整数数组ratings表示每个孩子的评分。你需要按照以下要求,给这些孩子分发糖果:每个孩子至少分配到1个糖果。相邻两个孩子评分更高的孩子会获得更多的糖果。请你给每个孩子分发糖果,计算并返回需要准备的最少糖果数目。n==rat......
  • day15 文件操作
    一.文件路径路径:绝对路劲和相对路径相对路径:相对简短的路径(大致的位置:比如住在杭州临平区)绝对路径:完整的路径(就是完整的地址,比如H:\软件存储12378911wy\向日葵远程控制\SunloginClient).....相对路径:./--代表当前文件夹../--代表返回到上一层文件夹二.字......
  • 模拟开关芯片 BL1551B中文资料 BL1551B引脚图及功能说明
     BL1551B是一款由贝岭(上海)微电子技术有限公司(ShanghaiBellingCo.,Ltd.)生产的模拟开关芯片。以下是关于BL1551B的功能和参数介绍:功能:BL1551B是一款高性能、低功耗的模拟开关芯片,适用于音频、视频和其他模拟信号的切换和控制。内置两个单刀双掷(SPDT)开关,可实现两路信......