~zooko/cryptopp/trunk

« back to all changes in this revision

Viewing changes to rsa.cpp

  • Committer: weidai
  • Date: 2007-05-04 15:04:58 UTC
  • Revision ID: svn-v4:57ff6487-cd31-0410-9ec3-f628ee90f5f0:trunk/c5:328
reduce risk of random number reuse after VM rollback

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
        return ASN1::rsaEncryption();
46
46
}
47
47
 
48
 
void RSAFunction::BERDecodeKey(BufferedTransformation &bt)
 
48
void RSAFunction::BERDecodePublicKey(BufferedTransformation &bt, bool, size_t)
49
49
{
50
50
        BERSequenceDecoder seq(bt);
51
51
                m_n.BERDecode(seq);
53
53
        seq.MessageEnd();
54
54
}
55
55
 
56
 
void RSAFunction::DEREncodeKey(BufferedTransformation &bt) const
 
56
void RSAFunction::DEREncodePublicKey(BufferedTransformation &bt) const
57
57
{
58
58
        DERSequenceEncoder seq(bt);
59
59
                m_n.DEREncode(seq);
189
189
        }
190
190
}
191
191
 
192
 
void InvertibleRSAFunction::BERDecodeKey(BufferedTransformation &bt)
 
192
void InvertibleRSAFunction::BERDecodePrivateKey(BufferedTransformation &bt, bool, size_t)
193
193
{
194
194
        BERSequenceDecoder privateKey(bt);
195
195
                word32 version;
205
205
        privateKey.MessageEnd();
206
206
}
207
207
 
208
 
void InvertibleRSAFunction::DEREncodeKey(BufferedTransformation &bt) const
 
208
void InvertibleRSAFunction::DEREncodePrivateKey(BufferedTransformation &bt) const
209
209
{
210
210
        DERSequenceEncoder privateKey(bt);
211
211
                DEREncodeUnsigned<word32>(privateKey, 0);       // version
225
225
        DoQuickSanityCheck();
226
226
        ModularArithmetic modn(m_n);
227
227
        Integer r, rInv;
228
 
        do {    // do this loop for people using small numbers for testing
 
228
        do {    // do this in a loop for people using small numbers for testing
229
229
                r.Randomize(rng, Integer::One(), m_n - Integer::One());
230
230
                rInv = modn.MultiplicativeInverse(r);
231
231
        } while (rInv.IsZero());