Shamir's trick implementation.
[crypto_lab3.git] / src / RsaCrt.h
1 #ifndef RSACRT_H
2 #define RSACRT_H
3
4 #include <utility>
5 #include <exception>
6
7 #include <gmpxx.h>
8
9 #include "Rsa.h"
10
11 class RsaCrt
12 {
13 public:
14 struct KeyPriv {
15 mpz_class p;
16 mpz_class q;
17 mpz_class dp;
18 mpz_class dq;
19 mpz_class qInv;
20 };
21
22 /**
23 * Generate a pair of keys (public, private).
24 */
25 static std::pair<Rsa::KeyPub, KeyPriv> generateRSAKeys(uint exponent, uint keySizeBits);
26
27 /**
28 * m must not be greater or equal than kPriv.n.
29 * @param m the message to sign. No padding is used.
30 */
31 static mpz_class sign(const mpz_class& m, const KeyPriv& kPriv);
32
33 /**
34 * Sp is altered by flipping its 42nd bit.
35 * @param m the message to sign. No padding is used.
36 */
37 static mpz_class signWithFaultySp(const mpz_class& m, const KeyPriv& kPriv);
38
39 private:
40 static mpz_class sign(const mpz_class& m, const KeyPriv& kPriv, bool withError);
41 };
42
43 #endif