From 36fa3fc2b13356f20ed58c37cdeb68c830c59829 Mon Sep 17 00:00:00 2001 From: weidai Date: Fri, 16 May 2003 00:02:31 +0000 Subject: misc optimizations git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@68 57ff6487-cd31-0410-9ec3-f628ee90f5f0 --- pubkey.h | 151 ++++++++++++++++++++++++++++----------------------------------- 1 file changed, 68 insertions(+), 83 deletions(-) (limited to 'pubkey.h') diff --git a/pubkey.h b/pubkey.h index ee600f4..41d9c7e 100644 --- a/pubkey.h +++ b/pubkey.h @@ -50,7 +50,7 @@ Integer DSA_EncodeDigest(unsigned int modulusBits, const byte *digest, unsigned // ******************************************************** //! . -class TrapdoorFunctionBounds +class CRYPTOPP_NO_VTABLE TrapdoorFunctionBounds { public: virtual ~TrapdoorFunctionBounds() {} @@ -62,7 +62,7 @@ public: }; //! . -class RandomizedTrapdoorFunction : public TrapdoorFunctionBounds +class CRYPTOPP_NO_VTABLE RandomizedTrapdoorFunction : public TrapdoorFunctionBounds { public: virtual Integer ApplyRandomizedFunction(RandomNumberGenerator &rng, const Integer &x) const =0; @@ -70,7 +70,7 @@ public: }; //! . -class TrapdoorFunction : public RandomizedTrapdoorFunction +class CRYPTOPP_NO_VTABLE TrapdoorFunction : public RandomizedTrapdoorFunction { public: Integer ApplyRandomizedFunction(RandomNumberGenerator &rng, const Integer &x) const @@ -81,7 +81,7 @@ public: }; //! . -class RandomizedTrapdoorFunctionInverse +class CRYPTOPP_NO_VTABLE RandomizedTrapdoorFunctionInverse { public: virtual ~RandomizedTrapdoorFunctionInverse() {} @@ -91,7 +91,7 @@ public: }; //! . -class TrapdoorFunctionInverse : public RandomizedTrapdoorFunctionInverse +class CRYPTOPP_NO_VTABLE TrapdoorFunctionInverse : public RandomizedTrapdoorFunctionInverse { public: virtual ~TrapdoorFunctionInverse() {} @@ -106,7 +106,7 @@ public: // ******************************************************** //! . -class PK_EncryptionMessageEncodingMethod +class CRYPTOPP_NO_VTABLE PK_EncryptionMessageEncodingMethod { public: virtual ~PK_EncryptionMessageEncodingMethod() {} @@ -123,7 +123,7 @@ public: //! . template -class TF_Base +class CRYPTOPP_NO_VTABLE TF_Base { protected: virtual const TrapdoorFunctionBounds & GetTrapdoorFunctionBounds() const =0; @@ -139,7 +139,7 @@ protected: //! . template -class TF_CryptoSystemBase : public INTERFACE, protected BASE +class CRYPTOPP_NO_VTABLE TF_CryptoSystemBase : public INTERFACE, protected BASE { public: unsigned int FixedMaxPlaintextLength() const {return GetMessageEncodingInterface().MaxUnpaddedLength(PaddedBlockBitLength());} @@ -151,14 +151,14 @@ protected: }; //! . -class TF_DecryptorBase : public TF_CryptoSystemBase > +class CRYPTOPP_NO_VTABLE TF_DecryptorBase : public TF_CryptoSystemBase > { public: DecodingResult FixedLengthDecrypt(RandomNumberGenerator &rng, const byte *cipherText, byte *plainText) const; }; //! . -class TF_EncryptorBase : public TF_CryptoSystemBase > +class CRYPTOPP_NO_VTABLE TF_EncryptorBase : public TF_CryptoSystemBase > { public: void Encrypt(RandomNumberGenerator &rng, const byte *plainText, unsigned int plainTextLength, byte *cipherText) const; @@ -169,7 +169,7 @@ public: typedef std::pair HashIdentifier; //! . -class PK_SignatureMessageEncodingMethod +class CRYPTOPP_NO_VTABLE PK_SignatureMessageEncodingMethod { public: virtual ~PK_SignatureMessageEncodingMethod() {} @@ -232,7 +232,7 @@ public: }; }; -class PK_DeterministicSignatureMessageEncodingMethod : public PK_SignatureMessageEncodingMethod +class CRYPTOPP_NO_VTABLE PK_DeterministicSignatureMessageEncodingMethod : public PK_SignatureMessageEncodingMethod { public: bool VerifyMessageRepresentative( @@ -240,7 +240,7 @@ public: byte *representative, unsigned int representativeBitLength) const; }; -class PK_RecoverableSignatureMessageEncodingMethod : public PK_SignatureMessageEncodingMethod +class CRYPTOPP_NO_VTABLE PK_RecoverableSignatureMessageEncodingMethod : public PK_SignatureMessageEncodingMethod { public: bool VerifyMessageRepresentative( @@ -266,7 +266,7 @@ public: byte *representative, unsigned int representativeBitLength) const; }; -class PK_MessageAccumulatorBase : public PK_MessageAccumulator +class CRYPTOPP_NO_VTABLE PK_MessageAccumulatorBase : public PK_MessageAccumulator { public: PK_MessageAccumulatorBase() : m_empty(true) {} @@ -293,7 +293,7 @@ public: //! . template -class TF_SignatureSchemeBase : public INTERFACE, protected BASE +class CRYPTOPP_NO_VTABLE TF_SignatureSchemeBase : public INTERFACE, protected BASE { public: unsigned int SignatureLength() const @@ -318,7 +318,7 @@ protected: }; //! . -class TF_SignerBase : public TF_SignatureSchemeBase > +class CRYPTOPP_NO_VTABLE TF_SignerBase : public TF_SignatureSchemeBase > { public: void InputRecoverableMessage(PK_MessageAccumulator &messageAccumulator, const byte *recoverableMessage, unsigned int recoverableMessageLength) const; @@ -326,7 +326,7 @@ public: }; //! . -class TF_VerifierBase : public TF_SignatureSchemeBase > +class CRYPTOPP_NO_VTABLE TF_VerifierBase : public TF_SignatureSchemeBase > { public: void InputSignature(PK_MessageAccumulator &messageAccumulator, const byte *signature, unsigned int signatureLength) const; @@ -356,24 +356,26 @@ struct TF_SignatureSchemeOptions : public TF_CryptoSchemeOptions //! . template -class PublicKeyCopier +class CRYPTOPP_NO_VTABLE PublicKeyCopier { public: + typedef KEYS::PublicKey KeyClass; virtual void CopyKeyInto(typename KEYS::PublicKey &key) const =0; }; //! . template -class PrivateKeyCopier +class CRYPTOPP_NO_VTABLE PrivateKeyCopier { public: + typedef KEYS::PrivateKey KeyClass; virtual void CopyKeyInto(typename KEYS::PublicKey &key) const =0; virtual void CopyKeyInto(typename KEYS::PrivateKey &key) const =0; }; //! . template -class TF_ObjectImplBase : public AlgorithmImpl +class CRYPTOPP_NO_VTABLE TF_ObjectImplBase : public AlgorithmImpl { public: typedef SCHEME_OPTIONS SchemeOptions; @@ -390,6 +392,15 @@ public: const KeyClass & GetTrapdoorFunction() const {return GetKey();} + PK_MessageAccumulator * NewSignatureAccumulator(RandomNumberGenerator &rng) const + { + return new PK_MessageAccumulatorImpl; + } + PK_MessageAccumulator * NewVerificationAccumulator() const + { + return new PK_MessageAccumulatorImpl; + } + protected: const typename BASE::MessageEncodingInterface & GetMessageEncodingInterface() const {static typename SCHEME_OPTIONS::MessageEncodingMethod messageEncodingMethod; return messageEncodingMethod;} @@ -422,79 +433,54 @@ public: const KEY & GetKey() const {return *m_pKey;} KEY & AccessKey() {throw NotImplemented("TF_ObjectImplExtRef: cannot modify refererenced key");} - void CopyKeyInto(typename SCHEME_OPTIONS::PrivateKey &key) const {assert(false);} - void CopyKeyInto(typename SCHEME_OPTIONS::PublicKey &key) const {assert(false);} - private: const KEY * m_pKey; }; //! . -template -class TF_ObjectImpl : public TF_ObjectImplBase +template +class CRYPTOPP_NO_VTABLE TF_ObjectImpl : public TF_ObjectImplBase, SCHEME_OPTIONS, typename KEY_COPIER::KeyClass> { public: - const KEY & GetKey() const {return m_trapdoorFunction;} - KEY & AccessKey() {return m_trapdoorFunction;} + typedef typename KEY_COPIER::KeyClass KeyClass; -private: - KEY m_trapdoorFunction; -}; - -//! . -template -class TF_PublicObjectImpl : public TF_ObjectImpl, public PublicKeyCopier -{ -public: - void CopyKeyInto(typename SCHEME_OPTIONS::PublicKey &key) const {key = GetKey();} -}; + const KeyClass & GetKey() const {return m_trapdoorFunction;} + KeyClass & AccessKey() {return m_trapdoorFunction;} -//! . -template -class TF_PrivateObjectImpl : public TF_ObjectImpl, public PrivateKeyCopier -{ -public: void CopyKeyInto(typename SCHEME_OPTIONS::PrivateKey &key) const {key = GetKey();} void CopyKeyInto(typename SCHEME_OPTIONS::PublicKey &key) const {key = GetKey();} + +private: + KeyClass m_trapdoorFunction; }; //! . template -class TF_DecryptorImpl : public TF_PrivateObjectImpl +class TF_DecryptorImpl : public TF_ObjectImpl > { }; //! . template -class TF_EncryptorImpl : public TF_PublicObjectImpl +class TF_EncryptorImpl : public TF_ObjectImpl > { }; //! . template -class TF_SignerImpl : public TF_PrivateObjectImpl +class TF_SignerImpl : public TF_ObjectImpl > { -public: - PK_MessageAccumulator * NewSignatureAccumulator(RandomNumberGenerator &rng) const - { - return new PK_MessageAccumulatorImpl; - } }; //! . template -class TF_VerifierImpl : public TF_PublicObjectImpl +class TF_VerifierImpl : public TF_ObjectImpl > { -public: - PK_MessageAccumulator * NewVerificationAccumulator() const - { - return new PK_MessageAccumulatorImpl; - } }; // ******************************************************** -class MaskGeneratingFunction +class CRYPTOPP_NO_VTABLE MaskGeneratingFunction { public: virtual ~MaskGeneratingFunction() {} @@ -548,7 +534,7 @@ public: //! . template -class DL_GroupParameters : public CryptoParameters +class CRYPTOPP_NO_VTABLE DL_GroupParameters : public CryptoParameters { typedef DL_GroupParameters ThisClass; @@ -658,7 +644,7 @@ protected: //! . template -class DL_Key +class CRYPTOPP_NO_VTABLE DL_Key { public: virtual const DL_GroupParameters & GetAbstractGroupParameters() const =0; @@ -667,7 +653,7 @@ public: //! . template -class DL_PublicKey : public DL_Key +class CRYPTOPP_NO_VTABLE DL_PublicKey : public DL_Key { typedef DL_PublicKey ThisClass; @@ -702,7 +688,7 @@ public: //! . template -class DL_PrivateKey : public DL_Key +class CRYPTOPP_NO_VTABLE DL_PrivateKey : public DL_Key { typedef DL_PrivateKey ThisClass; @@ -927,7 +913,7 @@ private: //! . template -class DL_ElgamalLikeSignatureAlgorithm +class CRYPTOPP_NO_VTABLE DL_ElgamalLikeSignatureAlgorithm { public: // virtual Integer EncodeDigest(unsigned int modulusBits, const byte *digest, unsigned int digestLength) const =0; @@ -943,7 +929,7 @@ public: //! . template -class DL_KeyAgreementAlgorithm +class CRYPTOPP_NO_VTABLE DL_KeyAgreementAlgorithm { public: typedef T Element; @@ -954,14 +940,14 @@ public: //! . template -class DL_KeyDerivationAlgorithm +class CRYPTOPP_NO_VTABLE DL_KeyDerivationAlgorithm { public: virtual void Derive(const DL_GroupParameters ¶ms, byte *derivedKey, unsigned int derivedLength, const T &agreedElement, const T &ephemeralPublicKey) const =0; }; //! . -class DL_SymmetricEncryptionAlgorithm +class CRYPTOPP_NO_VTABLE DL_SymmetricEncryptionAlgorithm { public: virtual unsigned int GetSymmetricKeyLength(unsigned int plainTextLength) const =0; @@ -973,7 +959,7 @@ public: //! . template -class DL_Base +class CRYPTOPP_NO_VTABLE DL_Base { protected: typedef KI KeyInterface; @@ -988,7 +974,7 @@ protected: //! . template -class DL_SignatureSchemeBase : public INTERFACE, public DL_Base +class CRYPTOPP_NO_VTABLE DL_SignatureSchemeBase : public INTERFACE, public DL_Base { public: unsigned int SignatureLength() const @@ -1020,7 +1006,7 @@ protected: //! . template -class DL_SignerBase : public DL_SignatureSchemeBase > +class CRYPTOPP_NO_VTABLE DL_SignerBase : public DL_SignatureSchemeBase > { public: // for validation testing @@ -1093,7 +1079,7 @@ protected: //! . template -class DL_VerifierBase : public DL_SignatureSchemeBase > +class CRYPTOPP_NO_VTABLE DL_VerifierBase : public DL_SignatureSchemeBase > { public: void InputSignature(PK_MessageAccumulator &messageAccumulator, const byte *signature, unsigned int signatureLength) const @@ -1161,7 +1147,7 @@ public: //! . template -class DL_CryptoSystemBase : public PK, public DL_Base +class CRYPTOPP_NO_VTABLE DL_CryptoSystemBase : public PK, public DL_Base { public: typedef typename DL_Base::Element Element; @@ -1186,7 +1172,7 @@ protected: //! . template -class DL_DecryptorBase : public DL_CryptoSystemBase > +class CRYPTOPP_NO_VTABLE DL_DecryptorBase : public DL_CryptoSystemBase > { public: typedef T Element; @@ -1222,7 +1208,7 @@ public: //! . template -class DL_EncryptorBase : public DL_CryptoSystemBase > +class CRYPTOPP_NO_VTABLE DL_EncryptorBase : public DL_CryptoSystemBase > { public: typedef T Element; @@ -1288,19 +1274,18 @@ struct DL_CryptoSchemeOptions : public DL_KeyedSchemeOptions //! . template -class DL_ObjectImplBase : public AlgorithmImpl +class CRYPTOPP_NO_VTABLE DL_ObjectImplBase : public AlgorithmImpl { public: typedef SCHEME_OPTIONS SchemeOptions; - typedef KEY KeyClass; - typedef typename KeyClass::Element Element; + typedef typename KEY::Element Element; PrivateKey & AccessPrivateKey() {return m_key;} PublicKey & AccessPublicKey() {return m_key;} // KeyAccessor - const KeyClass & GetKey() const {return m_key;} - KeyClass & AccessKey() {return m_key;} + const KEY & GetKey() const {return m_key;} + KEY & AccessKey() {return m_key;} protected: typename BASE::KeyInterface & AccessKeyInterface() {return m_key;} @@ -1319,12 +1304,12 @@ protected: } private: - KeyClass m_key; + KEY m_key; }; //! . template -class DL_ObjectImpl : public DL_ObjectImplBase +class CRYPTOPP_NO_VTABLE DL_ObjectImpl : public DL_ObjectImplBase { public: typedef typename KEY::Element Element; @@ -1346,7 +1331,7 @@ protected: //! . template -class DL_PublicObjectImpl : public DL_ObjectImpl, public PublicKeyCopier +class CRYPTOPP_NO_VTABLE DL_PublicObjectImpl : public DL_ObjectImpl, public PublicKeyCopier { public: void CopyKeyInto(typename SCHEME_OPTIONS::PublicKey &key) const @@ -1355,7 +1340,7 @@ public: //! . template -class DL_PrivateObjectImpl : public DL_ObjectImpl, public PrivateKeyCopier +class CRYPTOPP_NO_VTABLE DL_PrivateObjectImpl : public DL_ObjectImpl, public PrivateKeyCopier { public: void CopyKeyInto(typename SCHEME_OPTIONS::PublicKey &key) const @@ -1404,7 +1389,7 @@ class DL_DecryptorImpl : public DL_PrivateObjectImpl -class DL_SimpleKeyAgreementDomainBase : public SimpleKeyAgreementDomain +class CRYPTOPP_NO_VTABLE DL_SimpleKeyAgreementDomainBase : public SimpleKeyAgreementDomain { public: typedef T Element; -- cgit v1.2.1