23#include <wwlib/wwfile.h>
28#define AUTHFILE_ID_STRING "SSH PRIVATE KEY FILE FORMAT 1.1\n"
62template <
int PRECISION>
87 void Decryption_Setup();
108template <
int PRECISION>
118template <
int PRECISION>
135template <
int PRECISION>
145template <
int PRECISION>
156template <
int PRECISION>
167template <
int PRECISION>
175 unsigned char buffer[1024];
186 unsigned char cypher_type;
187 file->
Read(&cypher_type, 1);
188 if (cypher_type != 0)
191 file->
Read(buffer, 4);
193 file->
Read(buffer, 4);
195 retval=retval && Load_Bignum(file, PublicN);
196 retval=retval && Load_Bignum(file, PublicE);
202 file->
Read(&comment_length, 4);
203 comment_length=ntohl(comment_length);
205 file->
Read(buffer, comment_length);
208 file->
Read(buffer, 4);
209 if ((buffer[0] != buffer[2]) || (buffer[1] != buffer[3]))
214 retval=retval && Load_Bignum(file, PrivateD);
215 retval=retval && Load_Bignum(file, q_inv_mod_p);
216 retval=retval && Load_Bignum(file, KeygenP);
217 retval=retval && Load_Bignum(file, KeygenQ);
231template <
int PRECISION>
232void RSACrypt<PRECISION>::Decryption_Setup(
void)
237 if (KeygenP < KeygenQ)
244 assert(KeygenP > KeygenQ);
247 Integer pm1(KeygenP);
251 Integer qm1(KeygenQ);
255 Integer::Unsigned_Divide(DmodPm1, temp, PrivateD, pm1);
256 assert(DmodPm1 < pm1);
259 Integer::Unsigned_Divide(DmodQm1, temp, PrivateD, qm1);
260 assert(DmodQm1 < qm1);
262 RP = KeygenQ.exp_b_mod_c(pm1, PublicN);
263 RQ = KeygenP.exp_b_mod_c(qm1, PublicN);
270template <
int PRECISION>
281template <
int PRECISION>
284#ifdef SIMPLE_AND_SLOW_RSA
314 if (plaintext >= PublicN)
326template <
int PRECISION>
327bool RSACrypt<PRECISION>::Load_Bignum(
FileClass *file, Integer &num)
330 unsigned char buffer[1024];
331 unsigned short int n_bits, n_bytes;
333 readlen=file->
Read(&n_bits, 2);
336 n_bits=ntohs(n_bits);
337 n_bytes=(n_bits+7)/8;
339 readlen=file->
Read(buffer, n_bytes);
340 if (readlen != n_bytes)
343 num.Unsigned_Decode(buffer, n_bytes);
virtual int Read(void *buffer, int size)=0
virtual int Open(char const *filename, int rights=READ)=0
void Get_Public_Keys(Integer &pub_n, Integer &pub_e) const
void Set_Public_Keys(const Integer &pub_n, const Integer &pub_e)
void Decrypt(const Integer &cyphertext, Integer &plaintext) const
void Get_Keygen_Keys(Integer &keygen_p, Integer &keygen_q) const
void Set_Keys(const Integer &pub_n, const Integer &pub_e, const Integer &priv_d, const Integer &keygen_p, const Integer &keygen_q)
bool Load_SSH_Keyset(FileClass *file)
void Encrypt(const Integer &plaintext, Integer &cyphertext) const
void Get_Private_Key(Integer &priv_d) const
int MPEXPORT XMP_Mod_Mult(digit *prod, const digit *multiplicand, const digit *multiplier, int precision)
int XMP_Prepare_Modulus(const digit *n_modulus, int precision)
void MPEXPORT XMP_Mod_Mult_Clear(int precision)
#define AUTHFILE_ID_STRING
Int exp_b_mod_c(const Int &e, const Int &m) const
static void Unsigned_Divide(Int &remainder, Int "ient, const Int ÷nd, const Int &divisor)