RSA (cryptosystem)

https://en.wikipedia.org/wiki/RSA_(cryptosystem)

 

RSA is one of the first practical实用性的 public-key cryptosystems and is widely used for secure data transmission.

In such a cryptosystem密码系统, the encryption key is public and differs from the decryption key which is kept secret.  加密的key是公开的,解密的key是保密的

In RSA, this asymmetry不对称 is based on the practical difficulty of factoring因素 the product of two large prime numbers, the factoring problem.

RSA is made of the initial letters of the surnames of Ron RivestAdi Shamir, and Leonard Adleman, who first publicly described the algorithm in 1977. 

Clifford Cocks, an English mathematician数学家 working for the UK intelligence agency情报机构 GCHQ, had developed an equivalent system in 1973, but it was not declassified撤销文件的机密等级 until 1997.[1]

 

A user of RSA creates and then publishes a public key based on two large prime numbers, along with an auxiliary辅助的 value.

The prime numbers must be kept secret.

Anyone can use the public key to encrypt a message, but with currently published methods,

if the public key is large enough, only someone with knowledge of the prime numbers can feasibly切实 decode the message.[2] 

Breaking RSAencryption is known as the RSA problem; whether it is as hard as the factoring problem remains an open question.

RSA is a relatively slow algorithm, and because of this it is less commonly used to directly encrypt user data.

More often通常, RSA passes encrypted shared keys for symmetric对称的 key cryptography密码学;密码使用法 which in turn can perform bulk encryption-decryption operations at much higher speed.

 

Operation

The RSA algorithm involves four steps: key generation, key distribution, encryption and decryption.

RSA involves a public key and a private key. The public key can be known by everyone and is used for encrypting messages.

 

The intention is that messages encrypted with the public key can only be decrypted in a reasonable amount of time using the private key.

The basic principle behind RSA is the observation that it is practical to find three very large positive integers e,d and n such that with modular exponentiation  幂运算for all m:

(m^e)^d \mod{n} = m

and that even knowing e and n or even m it can be extremely difficult to find d.

Additionally, for some operations it is convenient that the order of the two exponentiations can be changed and that this relation also implies:

(m^d)^e \mod{n}= m

 

 

Key distribution

To enable Bob to send his encrypted messages, Alice transmits her public key (ne) to Bob via a reliable,可靠的 but not necessarily secret route路线, and keeps the private key d secret and this is never revealed透露 to anyone. Once distributed the keys can be reused over and over.    

公钥(m,e)    私钥d  

Bob用公钥将信息加密后,发送给Alice。  只有Alice自己知道私钥

 

Encryption

Bob then wishes to send message M to Alice.

He first turns M into an integer m, such that 0 ≤ m < n and gcd(mn) = 1 by using an agreed-upon reversible可逆的 protocol known as a padding scheme.

He then computes the ciphertext密文 c, using the public key e of Alice, corresponding to

 

c \equiv m^e \mod{n}

 

This can be done efficiently, even for 500-bit numbers, using modular exponentiation. Bob then transmits c to Alice.

 

 

Decryption

Alice can recover m from c by using her private key exponent d by computing

c^d \equiv (m^e)^d \equiv m \mod{n}

Given m, she can recover the original message M by reversing the padding scheme.

 

 

Key generation

The keys for the RSA algorithm are generated the following way:

  1. Choose two distinct prime numbers p and q.
    • For security purposes, the integers p and q should be chosen at random, and should be similar in magnitude量级 but 'differ in length by a few digits'[2] to make factoring harder. Prime integers can be efficiently found using aprimality test.
  2. Compute n = pq.
    • n is used as the modulus模数 for both the public and private keys. Its length, usually expressed in bits, is the key length.
  3. Compute φ(n) = φ(p)φ(q) = (p − 1)(q − 1) = n − (p + q − 1), where φ is Euler's totient function. This value is kept private.
  4. Choose an integer d such that 1 < d < φ(n) and gcd(d, φ(n)) = 1; i.e., d and φ(n) are coprime.
  5. Determine e as e ≡ d−1 (mod φ(n)); i.e., e is the modular multiplicative inverse of d (modulo φ(n))
  • This is more clearly stated as: solve for e given de ≡ 1 (mod φ(n))
  • e having a short bit-length and small Hamming weight results in more efficient encryption – most commonly 216 + 1 = 65,537. However, much smaller values of e (such as 3) have been shown to be less secure in some settings.[13]
  • e is released as the public key exponent.
  • d is kept as the private key exponent.

The public key consists of the modulus n and the public (or encryption) exponent e. The private key consists of the modulus n and the private (or decryption) exponent d, which must be kept secret. pq, and φ(n) must also be kept secret because they can be used to calculate d.

  • An alternative, used by PKCS#1, is to choose d matching de ≡ 1 (mod λ) with λ = lcm(p − 1, q − 1), where lcm is the least common multiple. Using λ instead of φ(n) allows more choices for d. λ can also be defined using theCarmichael function, λ(n).

Since any common factors of (p-1) and (q-1) are present in the factorisation of p*q-1,[14] it is recommended that (p-1) and (q-1) have only very small common factors, if any besides the necessary 2.[15][2][16]

 

 

 

Example

Here is an example of RSA encryption and decryption. The parameters used here are artificially small, but one can also use OpenSSL to generate and examine a real keypair.

  1. Choose two distinct prime numbers, such as
    p = 61 and  q = 53          //233*9001
  2. Compute n = pq giving
    n = 61\times 53 = 3233              //2097233
  3. Compute the totient欧拉函数 of the product as φ(n) = (p − 1)(q − 1) giving
    \varphi(3233) = (61 - 1)(53 - 1) = 3120          //2088000
  4. Choose any number 1 < d < 3120 that is coprime  互质 to 3120.

           Choosing a prime number for d leaves us only to check that d is not a divisor因子 of 3120.

Let  d = 2753       //d不能是3120的因子                                

      5.Compute e, the modular multiplicative inverse of d (mod φ(n)) yielding,       2753*e%3120=1;

e = 17
Worked example for the modular multiplicative inverse:     通过计算得到e
d \times e \; \operatorname{mod}\; \varphi(n) = 1
2753 \times 17  \; \operatorname{mod}\; 3120 = 1                                d*7%2088000=1;求出d=1193143

 

The public key is (n = 3233, e = 17). For a padded plaintext没有加密过的文件 message m, the encryption function is

 用公钥对m进行加密    c(m) = m^{17} \; \operatorname{mod}\; 3233

The private key is (d = 2753). For an encrypted ciphertext密文 c, the decryption function is

用私钥对c进行解密    m(c) = c^{2753} \; \operatorname{mod}\; 3233                   

 

For instance, in order to encrypt m = 65, we calculate

c = 65^{17} \; \operatorname{mod}\; 3233 = 2790     对65进行加密,65^17%3233=

To decrypt c = 2790, we calculate

m = 2790^{2753} \; \operatorname{mod}\; 3233 = 65      对2790进行解密,2790^2753%3233

 

Both of these calculations can be computed efficiently using the square-and-multiply algorithm for modular exponentiation.

In real-life situations the primes selected would be much larger;

in our example it would be trivial to factor n, 3233 (obtained from the freely available public key) back to the primes p and q.  

Given e, also from the public key, we could then compute d and so acquire the private key.

 

Practical implementations use the Chinese remainder theorem to speed up the calculation using modulus of factors (mod pq using mod p and mod q).

The values dpdq and qinv, which are part of the private key are computed as follows:

\begin{align}            d_p &= d\; \operatorname{mod}\; (p-1) = 2753 \; \operatorname{mod}\; (61-1) = 53 \\            d_q &= d\; \operatorname{mod}\;(q-1) = 2753 \; \operatorname{mod}\; (53-1) = 49 \\   q_\text{inv} &= q^{-1} \; \operatorname{mod}\; p = 53^{-1} \; \operatorname{mod}\; 61 = 38 \\                &\Rightarrow (q_\text{inv} \times q) \; \operatorname{mod}\; p = 38 \times 53 \; \operatorname{mod}\; 61= 1 \end{align}

Here is how dpdq and qinv are used for efficient decryption. (Encryption is efficient by choice of a suitable d and e pair)

\begin{align}   m_1 &= c^{d_p} \; \operatorname{mod}\; p = 2790^{53} \; \operatorname{mod}\; 61 = 4 \\   m_2 &= c^{d_q} \; \operatorname{mod}\; q = 2790^{49} \; \operatorname{mod}\; 53 = 12 \\     h &= (q_\text{inv} \times (m_1 - m_2)) \; \operatorname{mod}\; p = (38 \times -8) \; \operatorname{mod}\; 61 = 1 \\     m &= m_2 + h \times q = 12 + 1 \times 53 = 65 \end{align}

 

 

RSA Public Key: (N, 7)    公钥的两个参数应该是(m,e)   
N = 233 * M     //p=233   q=9001     232*9000=2088000

RSA的公钥  (2097233,7)      Modulus=2097233 Exponent=7

a密文是197372,对其解密    

b密文是333079,对其解密      

 

d*e%((233-1)(9001-1))

=d*7%2088000=1    

 for(int i = 1; i <= 2088000; i++)
                {
                    if(i*7%2088000 == 1)
                    {
                        Console.WriteLine(i);
                        break;
                    }
                }

打印结果:1193143,所以d=1193143

 

a密文是197372,对其解密      a=197372^1193143mod2097233

b密文是333079,对其解密      b=333079^1193143mod2097233

 

https://www.cs.drexel.edu/~jpopyack/IntroCS/HW/RSAWorksheet.html

https://www.cs.drexel.edu/~introcs/Fa11/notes/10.1_Cryptography/RSA_Express_EncryptDecrypt.html

http://extranet.cryptomathic.com/rsacalc/index

                BigInteger number = 197372;
                int exponent = 1193143;
                BigInteger modulus = 2097233;
                Console.WriteLine("({0}^{1}) Mod {2} = {3}",
                                  number, exponent, modulus,
                                  BigInteger.ModPow(number, exponent, modulus));

a=378

b=390696

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
autosar参考资料,Secure相关概念汇总 AES 加密算法,由NIST制定的标准,例如AES-128, AES-192 AsymmetricCryptography 使用两个不同值进行加密和解密的加密算法。非对称算法是基于很大数量的,并且很耗时。 Authenticity 确认数据(例如固件)的真实性 Car-to-X 车辆与其他组件(例如其他汽车,交通标志等)的通信方案 Cipher 实现加密算法的模块(硬件或软件) Chain-of-Trust 作为安全启动的增强变体,固件检查分为多个子块,以减少启动时间。 ECU 电子控制单元,一个由TIER1开发的组件 Elliptic Curve Algorithm 在80年代开发的非对称密码算法,使用短密钥(<512位) EVITA 欧盟资助的项目,旨在为不同用例指定安全模块 Glitch Attack 电压毛刺使设备处于未指定的状态和行为。 HASH 一种基于任意输入数据计算值的算法,该值可用于验证输入数据 HSM 硬件安全模块;集成了密码和内核的加密模块,有时用户可对其进行编程 Integrity 涉及维护数据的一致性,准确性和可信赖性 Key / Crypto Key 加密算法用作输入参数的值。 Key Management 在生产和现场设备中处理和分发密码密钥 NIST National Institute of Standards and Technology,即国家标准技术局 OTA Over-The-Air的缩写,即云端升级,通过无线连接进行固件更新 Physical Attack 一种攻击方法,使用了超出规格的设备(例如,电压过高/过低/温度或时钟,强光等)。 Replay Attacks 记录并重播加密消息或图像。在这种情况下,攻击者无需知道安全信息(例如密钥)。 RNG / TRNG / PRNG 随机数生成器–真正的随机数生成器根据随机物理效应生成数字; PRNG根据数学算法生成数字 RSA 70年代开发的非对称密码算法使用长密钥(> 1500位) Secure-Boot 一种在硬件模块启动时检查设备固件是否已修改的方法 Secure Memory 一种存储安全信息(例如,加密密钥)并具有严格访问限制的存储器。 SHA 由NIST指定的哈希算法系列,例如 SHA-1,SHA-2,SHA-2 SHE 安全标准;由HIS组中的德国汽车OEM指定。 Side-Channel Attacks 一种攻击方法,攻击者在其中测量加密模块/软件的各个方面。根据这些测量,攻击者可以推导/猜测安全信息,例如: key。 Signature 用于证明数字消息或文档真实性的值 Symmetric Cryptography 使用相同值进行加密和解密的加密算法
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值