~zooko/cryptopp/trunk

« back to all changes in this revision

Viewing changes to oaep.cpp

  • Committer: weidai
  • Date: 2003-07-29 01:18:33 UTC
  • Revision ID: svn-v4:57ff6487-cd31-0410-9ec3-f628ee90f5f0:trunk/c5:118
fix potential threading problem with initialization of static objects

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
// ********************************************************
13
13
 
14
 
size_t OAEP_Base::MaxUnpaddedLength(size_t paddedLength) const
 
14
unsigned int OAEP_Base::MaxUnpaddedLength(unsigned int paddedLength) const
15
15
{
16
16
        return SaturatingSubtract(paddedLength/8, 1+2*DigestSize());
17
17
}
18
18
 
19
 
void OAEP_Base::Pad(RandomNumberGenerator &rng, const byte *input, size_t inputLength, byte *oaepBlock, size_t oaepBlockLen, const NameValuePairs &parameters) const
 
19
void OAEP_Base::Pad(RandomNumberGenerator &rng, const byte *input, unsigned int inputLength, byte *oaepBlock, unsigned int oaepBlockLen, const NameValuePairs &parameters) const
20
20
{
21
21
        assert (inputLength <= MaxUnpaddedLength(oaepBlockLen));
22
22
 
29
29
        oaepBlockLen /= 8;
30
30
 
31
31
        std::auto_ptr<HashTransformation> pHash(NewHash());
32
 
        const size_t hLen = pHash->DigestSize();
33
 
        const size_t seedLen = hLen, dbLen = oaepBlockLen-seedLen;
 
32
        const unsigned int hLen = pHash->DigestSize();
 
33
        const unsigned int seedLen = hLen, dbLen = oaepBlockLen-seedLen;
34
34
        byte *const maskedSeed = oaepBlock;
35
35
        byte *const maskedDB = oaepBlock+seedLen;
36
36
 
49
49
        pMGF->GenerateAndMask(*pHash, maskedSeed, seedLen, maskedDB, dbLen);
50
50
}
51
51
 
52
 
DecodingResult OAEP_Base::Unpad(const byte *oaepBlock, size_t oaepBlockLen, byte *output, const NameValuePairs &parameters) const
 
52
DecodingResult OAEP_Base::Unpad(const byte *oaepBlock, unsigned int oaepBlockLen, byte *output, const NameValuePairs &parameters) const
53
53
{
54
54
        bool invalid = false;
55
55
 
62
62
        oaepBlockLen /= 8;
63
63
 
64
64
        std::auto_ptr<HashTransformation> pHash(NewHash());
65
 
        const size_t hLen = pHash->DigestSize();
66
 
        const size_t seedLen = hLen, dbLen = oaepBlockLen-seedLen;
 
65
        const unsigned int hLen = pHash->DigestSize();
 
66
        const unsigned int seedLen = hLen, dbLen = oaepBlockLen-seedLen;
67
67
 
68
68
        invalid = (oaepBlockLen < 2*hLen+1) || invalid;
69
69