X-Git-Url: http://git.euphorik.ch/?p=crypto_lab3.git;a=blobdiff_plain;f=src%2FRsaCrtShamirsTrick.h;fp=src%2FRsaCrtShamirsTrick.h;h=07299e8a82cf490e1a82849a9252438581043b0a;hp=0000000000000000000000000000000000000000;hb=22aac262156e81085b22bdfcd0cc38950768be9b;hpb=2745bc6570ac32789650336b8c84a52d1883c62a diff --git a/src/RsaCrtShamirsTrick.h b/src/RsaCrtShamirsTrick.h new file mode 100644 index 0000000..07299e8 --- /dev/null +++ b/src/RsaCrtShamirsTrick.h @@ -0,0 +1,43 @@ +#ifndef RSACRT_SHAMIRS_TRICK_H +#define RSACRT_SHAMIRS_TRICK_H + +#include +#include + +#include + +#include "Rsa.h" + +class RsaCrtShamirsTrick +{ +public: + class UnableToSignWithShamirsTrick : public std::exception {}; + + struct KeyPriv { + mpz_class p; + mpz_class q; + mpz_class d; + mpz_class qInv; + }; + + /** + * Generate a pair of keys (public, private). + */ + static std::pair generateRSAKeys(uint exponent, uint keySizeBits); + + /** + * m must not be greater or equal than kPriv.n. + * Use the Shamir's trick to test if a fault has been created during the computation of Sp and Sq. + * If so it throws 'UnableToSignWithShamirsTrick'. + * @param m the message to sign. No padding is used. + */ + static mpz_class sign(const mpz_class& m, const KeyPriv& kPriv); + + /** + * Sp is altered by flipping its 42nd bit. + * @param m the message to sign. No padding is used. + */ + static mpz_class signWithFaultySp(const mpz_class& m, const KeyPriv& kPriv); +}; + +#endif