|
ADS
Algorithms and Data Structures
|
The public key cryptosystem RSA of the reality check of section 17.3, on integers of 64 bits, a toy that shows the method and is not secure: the keys need some thousand bits. More...
#include "ADS/Contract.h"#include "ADS/numeric/NumberTheory.h"#include <cstdint>#include <random>#include <utility>#include "ADS/numeric/impl/RSA.tpp"Go to the source code of this file.
Classes | |
| struct | ADS::RsaKey |
| a key \( ( N , e ) \) More... | |
Namespaces | |
| namespace | ADS |
Functions | |
| template<class R> | |
| U64 | ADS::randomPrime (int bits, R &rng) |
| a random odd prime of exactly \( \mathit{bits} \) bits, by the test of Miller and Rabin on 40 bases | |
| template<class R> | |
| std::pair< RsaKey, RsaKey > | ADS::rsaKeys (R &rng) |
| a pair (public, private) of keys, with \( N \) of about 62 bits | |
| U64 | ADS::rsa (U64 M, const RsaKey &k) |
| the message \( M < N \) under the key, \( M^e \bmod N \): encrypting with a public key, or decrypting and signing with a private one | |
The public key cryptosystem RSA of the reality check of section 17.3, on integers of 64 bits, a toy that shows the method and is not secure: the keys need some thousand bits.
Three random primes \( s \), \( x \) and \( y \), found by the test of Miller and Rabin, give \( N = x y \) and the public exponent \( p \) with \( p s \bmod ( x - 1 ) ( y - 1 ) = 1 \); the public key is \( ( N , p ) \), the private one \( ( N , s ) \), \( C = M^p \bmod N \) encrypts and \( M = C^s \bmod N \) decrypts, since \( M^{p s} \bmod N = M \). Signing is decrypting with the private key, checking is encrypting with the public one.
The contracts [see Contract.h]: randomPrime() needs \( 2 \le \mathit{bits} \le 63 \) and gives an odd number of exactly that many bits; the keys of rsaKeys() undo each other, checked on the message 2; rsa() needs a message \( M < N \). The functions are defined in RSA.tpp.