Lines 114-122
Link Here
|
114 |
PublicKeyBaseTemplate(const F &f) : f(f) {} |
114 |
PublicKeyBaseTemplate(const F &f) : f(f) {} |
115 |
PublicKeyBaseTemplate(BufferedTransformation &bt) : f(bt) {} |
115 |
PublicKeyBaseTemplate(BufferedTransformation &bt) : f(bt) {} |
116 |
virtual ~PublicKeyBaseTemplate() {} |
116 |
virtual ~PublicKeyBaseTemplate() {} |
117 |
void DEREncode(BufferedTransformation &bt) const {f.DEREncode(bt);} |
117 |
void DEREncode(BufferedTransformation &bt) const {this->f.DEREncode(bt);} |
118 |
|
118 |
|
119 |
const F & GetTrapdoorFunction() const {return f;} |
119 |
const F & GetTrapdoorFunction() const {return this->f;} |
120 |
|
120 |
|
121 |
protected: |
121 |
protected: |
122 |
// a hack to avoid having to write constructors for non-concrete derived classes |
122 |
// a hack to avoid having to write constructors for non-concrete derived classes |
Lines 135-147
Link Here
|
135 |
{ |
135 |
{ |
136 |
public: |
136 |
public: |
137 |
unsigned int MaxPlainTextLength() const {return pad.MaxUnpaddedLength(PaddedBlockBitLength());} |
137 |
unsigned int MaxPlainTextLength() const {return pad.MaxUnpaddedLength(PaddedBlockBitLength());} |
138 |
unsigned int CipherTextLength() const {return f.MaxImage().ByteCount();} |
138 |
unsigned int CipherTextLength() const {return this->f.MaxImage().ByteCount();} |
139 |
|
139 |
|
140 |
P pad; |
140 |
P pad; |
141 |
|
141 |
|
142 |
protected: |
142 |
protected: |
143 |
CryptoSystemBaseTemplate() {} |
143 |
CryptoSystemBaseTemplate() {} |
144 |
unsigned int PaddedBlockBitLength() const {return f.PreimageBound().BitCount()-1;} |
144 |
unsigned int PaddedBlockBitLength() const {return this->f.PreimageBound().BitCount()-1;} |
145 |
}; |
145 |
}; |
146 |
|
146 |
|
147 |
//! . |
147 |
//! . |
Lines 199-211
Link Here
|
199 |
{ |
199 |
{ |
200 |
public: |
200 |
public: |
201 |
unsigned int MaxDigestLength() const {return pad.MaxUnpaddedLength(PaddedBlockBitLength());} |
201 |
unsigned int MaxDigestLength() const {return pad.MaxUnpaddedLength(PaddedBlockBitLength());} |
202 |
unsigned int DigestSignatureLength() const {return f.MaxPreimage().ByteCount();} |
202 |
unsigned int DigestSignatureLength() const {return this->f.MaxPreimage().ByteCount();} |
203 |
|
203 |
|
204 |
P pad; |
204 |
P pad; |
205 |
|
205 |
|
206 |
protected: |
206 |
protected: |
207 |
DigestSignatureSystemBaseTemplate() {} |
207 |
DigestSignatureSystemBaseTemplate() {} |
208 |
unsigned int PaddedBlockBitLength() const {return f.ImageBound().BitCount()-1;} |
208 |
unsigned int PaddedBlockBitLength() const {return this->f.ImageBound().BitCount()-1;} |
209 |
}; |
209 |
}; |
210 |
|
210 |
|
211 |
//! . |
211 |
//! . |
Lines 239-245
Link Here
|
239 |
class SignatureSystemBaseTemplate : virtual public PK_SignatureSystem, virtual public S |
239 |
class SignatureSystemBaseTemplate : virtual public PK_SignatureSystem, virtual public S |
240 |
{ |
240 |
{ |
241 |
public: |
241 |
public: |
242 |
unsigned int SignatureLength() const {return DigestSignatureLength();} |
242 |
unsigned int SignatureLength() const {return this->DigestSignatureLength();} |
243 |
HashModule * NewMessageAccumulator() const {return new H;} |
243 |
HashModule * NewMessageAccumulator() const {return new H;} |
244 |
|
244 |
|
245 |
protected: |
245 |
protected: |
Lines 274-284
Link Here
|
274 |
void SignerTemplate<S,H>::Sign(RandomNumberGenerator &rng, HashModule *messageAccumulator, byte *signature) const |
274 |
void SignerTemplate<S,H>::Sign(RandomNumberGenerator &rng, HashModule *messageAccumulator, byte *signature) const |
275 |
{ |
275 |
{ |
276 |
std::auto_ptr<HashModule> ma(messageAccumulator); |
276 |
std::auto_ptr<HashModule> ma(messageAccumulator); |
277 |
if (ma->DigestSize() > MaxDigestLength()) |
277 |
if (ma->DigestSize() > this->MaxDigestLength()) |
278 |
throw KeyTooShort(); |
278 |
throw KeyTooShort(); |
279 |
SecByteBlock digest(ma->DigestSize()); |
279 |
SecByteBlock digest(ma->DigestSize()); |
280 |
ma->Final(digest); |
280 |
ma->Final(digest); |
281 |
SignDigest(rng, digest, digest.size, signature); |
281 |
this->SignDigest(rng, digest, digest.size, signature); |
282 |
} |
282 |
} |
283 |
|
283 |
|
284 |
template <class S, class H> |
284 |
template <class S, class H> |
Lines 287-293
Link Here
|
287 |
std::auto_ptr<HashModule> ma(messageAccumulator); |
287 |
std::auto_ptr<HashModule> ma(messageAccumulator); |
288 |
SecByteBlock digest(ma->DigestSize()); |
288 |
SecByteBlock digest(ma->DigestSize()); |
289 |
ma->Final(digest); |
289 |
ma->Final(digest); |
290 |
return VerifyDigest(digest, digest.size, sig); |
290 |
return this->VerifyDigest(digest, digest.size, sig); |
291 |
} |
291 |
} |
292 |
|
292 |
|
293 |
// ******************************************************** |
293 |
// ******************************************************** |
Lines 308-320
Link Here
|
308 |
class SignatureSystemWithRecoveryBaseTemplate : virtual public PK_SignatureSystemWithRecovery, virtual public PublicKeyBaseTemplate<F> |
308 |
class SignatureSystemWithRecoveryBaseTemplate : virtual public PK_SignatureSystemWithRecovery, virtual public PublicKeyBaseTemplate<F> |
309 |
{ |
309 |
{ |
310 |
public: |
310 |
public: |
311 |
unsigned int SignatureLength() const {return f.MaxPreimage().ByteCount();} |
311 |
unsigned int SignatureLength() const {return this->f.MaxPreimage().ByteCount();} |
312 |
HashModule * NewMessageAccumulator() const {return new H(PaddedBlockBitLength());} |
312 |
HashModule * NewMessageAccumulator() const {return new H(PaddedBlockBitLength());} |
313 |
unsigned int MaximumRecoverableLength() const {return H::MaximumRecoverableLength(PaddedBlockBitLength());} |
313 |
unsigned int MaximumRecoverableLength() const {return H::MaximumRecoverableLength(PaddedBlockBitLength());} |
314 |
bool AllowLeftoverMessage() const {return H::AllowLeftoverMessage();} |
314 |
bool AllowLeftoverMessage() const {return H::AllowLeftoverMessage();} |
315 |
|
315 |
|
316 |
protected: |
316 |
protected: |
317 |
unsigned int PaddedBlockBitLength() const {return f.ImageBound().BitCount()-1;} |
317 |
unsigned int PaddedBlockBitLength() const {return this->f.ImageBound().BitCount()-1;} |
318 |
}; |
318 |
}; |
319 |
|
319 |
|
320 |
//! . |
320 |
//! . |
Lines 342-367
Link Here
|
342 |
std::auto_ptr<H> ma(static_cast<H*>(messageAccumulator)); |
342 |
std::auto_ptr<H> ma(static_cast<H*>(messageAccumulator)); |
343 |
if (ma->MaximumRecoverableLength() == 0) |
343 |
if (ma->MaximumRecoverableLength() == 0) |
344 |
throw KeyTooShort(); |
344 |
throw KeyTooShort(); |
345 |
SecByteBlock representative(PaddedBlockByteLength()); |
345 |
SecByteBlock representative(this->PaddedBlockByteLength()); |
346 |
ma->Encode(rng, representative); |
346 |
ma->Encode(rng, representative); |
347 |
f.CalculateInverse(Integer(representative, representative.size)).Encode(signature, SignatureLength()); |
347 |
this->f.CalculateInverse(Integer(representative, representative.size)).Encode(signature, this->SignatureLength()); |
348 |
} |
348 |
} |
349 |
|
349 |
|
350 |
template <class F, class H> |
350 |
template <class F, class H> |
351 |
bool VerifierWithRecoveryTemplate<F,H>::Verify(HashModule *messageAccumulator, const byte *signature) const |
351 |
bool VerifierWithRecoveryTemplate<F,H>::Verify(HashModule *messageAccumulator, const byte *signature) const |
352 |
{ |
352 |
{ |
353 |
std::auto_ptr<H> ma(static_cast<H*>(messageAccumulator)); |
353 |
std::auto_ptr<H> ma(static_cast<H*>(messageAccumulator)); |
354 |
SecByteBlock representative(PaddedBlockByteLength()); |
354 |
SecByteBlock representative(this->PaddedBlockByteLength()); |
355 |
f.ApplyFunction(Integer(signature, SignatureLength())).Encode(representative, representative.size); |
355 |
this->f.ApplyFunction(Integer(signature, SignatureLength())).Encode(representative, representative.size); |
356 |
return ma->Verify(representative); |
356 |
return ma->Verify(representative); |
357 |
} |
357 |
} |
358 |
|
358 |
|
359 |
template <class F, class H> |
359 |
template <class F, class H> |
360 |
HashModule * VerifierWithRecoveryTemplate<F,H>::NewLeftoverMessageAccumulator(const byte *signature) const |
360 |
HashModule * VerifierWithRecoveryTemplate<F,H>::NewLeftoverMessageAccumulator(const byte *signature) const |
361 |
{ |
361 |
{ |
362 |
SecByteBlock representative(PaddedBlockByteLength()); |
362 |
SecByteBlock representative(this->PaddedBlockByteLength()); |
363 |
f.ApplyFunction(Integer(signature, SignatureLength())).Encode(representative, representative.size); |
363 |
this->f.ApplyFunction(Integer(signature, this->SignatureLength())).Encode(representative, representative.size); |
364 |
return new H(representative, PaddedBlockBitLength()); |
364 |
return new H(representative, this->PaddedBlockBitLength()); |
365 |
} |
365 |
} |
366 |
|
366 |
|
367 |
template <class F, class H> |
367 |
template <class F, class H> |