port to GCC 3.4

pull/2/head
weidai 2004-06-19 08:28:09 +00:00
parent 40a5b80a45
commit f78fccb3cc
30 changed files with 418 additions and 423 deletions

View File

@ -321,8 +321,12 @@ synchronization when multiple threads access a common Crypto++ object.
- added ThreadUserTimer for timing thread CPU usage - added ThreadUserTimer for timing thread CPU usage
- added option for password-based key derivation functions - added option for password-based key derivation functions
to iterate until a mimimum elapsed thread CPU time is reached to iterate until a mimimum elapsed thread CPU time is reached
- added option for DEFLATE compression to detect uncompressible
files and process them more quickly
- improved compatibility and performance on 64-bit platforms, - improved compatibility and performance on 64-bit platforms,
including Alpha, IA-64, x86-64, PPC64, Sparc64, and MIPS64 including Alpha, IA-64, x86-64, PPC64, Sparc64, and MIPS64
- fixed ONE_AND_ZEROS_PADDING to use 0x80 instead 0x01 as padding. - fixed ONE_AND_ZEROS_PADDING to use 0x80 instead 0x01 as padding.
- fixed encoding/decoding of PKCS #8 privateKeyInfo to properly
handle optional attributes
Written by Wei Dai Written by Wei Dai

View File

@ -54,7 +54,7 @@ template <class T> const T& AbstractEuclideanDomain<T>::Gcd(const Element &a, co
Element g[3]={b, a}; Element g[3]={b, a};
unsigned int i0=0, i1=1, i2=2; unsigned int i0=0, i1=1, i2=2;
while (!Equal(g[i1], Identity())) while (!Equal(g[i1], this->Identity()))
{ {
g[i2] = Mod(g[i0], g[i1]); g[i2] = Mod(g[i0], g[i1]);
unsigned int t = i0; i0 = i1; i1 = i2; i2 = t; unsigned int t = i0; i0 = i1; i1 = i2; i2 = t;

View File

@ -23,7 +23,7 @@ public:
} }
template <class T> ConstByteArrayParameter(const T &string, bool deepCopy = false) template <class T> ConstByteArrayParameter(const T &string, bool deepCopy = false)
{ {
CRYPTOPP_COMPILE_ASSERT(sizeof(string[0])==1); CRYPTOPP_COMPILE_ASSERT(sizeof(CPP_TYPENAME T::value_type) == 1);
Assign((const byte *)string.data(), string.size(), deepCopy); Assign((const byte *)string.data(), string.size(), deepCopy);
} }
@ -320,7 +320,7 @@ public:
template <class R> template <class R>
AlgorithmParameters<AlgorithmParameters<PARENT,T>, R> operator()(const char *name, const R &value) const AlgorithmParameters<AlgorithmParameters<PARENT,T>, R> operator()(const char *name, const R &value) const
{ {
return AlgorithmParameters<AlgorithmParameters<PARENT,T>, R>(*this, name, value, m_throwIfNotUsed); return AlgorithmParameters<AlgorithmParameters<PARENT,T>, R>(*this, name, value, this->m_throwIfNotUsed);
} }
template <class R> template <class R>

View File

@ -35,8 +35,8 @@ class CBC_MAC : public MessageAuthenticationCodeImpl<CBC_MAC_Base, CBC_MAC<T> >,
{ {
public: public:
CBC_MAC() {} CBC_MAC() {}
CBC_MAC(const byte *key, unsigned int length=DEFAULT_KEYLENGTH) CBC_MAC(const byte *key, unsigned int length=SameKeyLengthAs<T>::DEFAULT_KEYLENGTH)
{SetKey(key, length);} {this->SetKey(key, length);}
static std::string StaticAlgorithmName() {return std::string("CBC-MAC(") + T::StaticAlgorithmName() + ")";} static std::string StaticAlgorithmName() {return std::string("CBC-MAC(") + T::StaticAlgorithmName() + ")";}

14
dh.h
View File

@ -61,18 +61,18 @@ public:
if (FIPS_140_2_ComplianceEnabled()) if (FIPS_140_2_ComplianceEnabled())
{ {
SecByteBlock privateKey2(PrivateKeyLength()); SecByteBlock privateKey2(this->PrivateKeyLength());
GeneratePrivateKey(rng, privateKey2); this->GeneratePrivateKey(rng, privateKey2);
SecByteBlock publicKey2(PublicKeyLength()); SecByteBlock publicKey2(this->PublicKeyLength());
Base::GeneratePublicKey(rng, privateKey2, publicKey2); Base::GeneratePublicKey(rng, privateKey2, publicKey2);
SecByteBlock agreedValue(AgreedValueLength()), agreedValue2(AgreedValueLength()); SecByteBlock agreedValue(this->AgreedValueLength()), agreedValue2(this->AgreedValueLength());
Agree(agreedValue, privateKey, publicKey2); this->Agree(agreedValue, privateKey, publicKey2);
Agree(agreedValue2, privateKey2, publicKey); this->Agree(agreedValue2, privateKey2, publicKey);
if (agreedValue != agreedValue2) if (agreedValue != agreedValue2)
throw SelfTestFailure(AlgorithmName() + ": pairwise consistency test failed"); throw SelfTestFailure(this->AlgorithmName() + ": pairwise consistency test failed");
} }
} }

2
dmac.h
View File

@ -40,7 +40,7 @@ class DMAC : public MessageAuthenticationCodeFinal<DMAC_Base<T> >
public: public:
DMAC() {} DMAC() {}
DMAC(const byte *key, unsigned int length=DMAC_Base<T>::DEFAULT_KEYLENGTH) DMAC(const byte *key, unsigned int length=DMAC_Base<T>::DEFAULT_KEYLENGTH)
{SetKey(key, length);} {this->SetKey(key, length);}
}; };
template <class T> template <class T>

View File

@ -375,7 +375,7 @@ template <class EC> void DL_GroupParameters_EC<EC>::Initialize(const OID &oid)
const EcRecommendedParameters<EllipticCurve> &param = *it; const EcRecommendedParameters<EllipticCurve> &param = *it;
m_oid = oid; m_oid = oid;
std::auto_ptr<EllipticCurve> ec(param.NewEC()); std::auto_ptr<EllipticCurve> ec(param.NewEC());
m_groupPrecomputation.SetCurve(*ec); this->m_groupPrecomputation.SetCurve(*ec);
StringSource ssG(param.g, true, new HexDecoder); StringSource ssG(param.g, true, new HexDecoder);
Element G; Element G;
@ -396,7 +396,7 @@ bool DL_GroupParameters_EC<EC>::GetVoidValue(const char *name, const std::type_i
if (m_oid.m_values.empty()) if (m_oid.m_values.empty())
return false; return false;
ThrowIfTypeMismatch(name, typeid(OID), valueType); this->ThrowIfTypeMismatch(name, typeid(OID), valueType);
*reinterpret_cast<OID *>(pValue) = m_oid; *reinterpret_cast<OID *>(pValue) = m_oid;
return true; return true;
} }
@ -477,7 +477,7 @@ void DL_GroupParameters_EC<EC>::DEREncode(BufferedTransformation &bt) const
DERSequenceEncoder seq(bt); DERSequenceEncoder seq(bt);
DEREncodeUnsigned<word32>(seq, 1); // version DEREncodeUnsigned<word32>(seq, 1); // version
GetCurve().DEREncode(seq); GetCurve().DEREncode(seq);
GetCurve().DEREncodePoint(seq, GetSubgroupGenerator(), m_compress); GetCurve().DEREncodePoint(seq, this->GetSubgroupGenerator(), m_compress);
m_n.DEREncode(seq); m_n.DEREncode(seq);
if (m_k.NotZero()) if (m_k.NotZero())
m_k.DEREncode(seq); m_k.DEREncode(seq);
@ -531,12 +531,12 @@ bool DL_GroupParameters_EC<EC>::ValidateElement(unsigned int level, const Elemen
if (level >= 1) if (level >= 1)
{ {
if (gpc) if (gpc)
pass = pass && gpc->Exponentiate(GetGroupPrecomputation(), Integer::One()) == g; pass = pass && gpc->Exponentiate(this->GetGroupPrecomputation(), Integer::One()) == g;
} }
if (level >= 2) if (level >= 2)
{ {
const Integer &q = GetSubgroupOrder(); const Integer &q = GetSubgroupOrder();
pass = pass && IsIdentity(gpc ? gpc->Exponentiate(GetGroupPrecomputation(), q) : ExponentiateElement(g, q)); pass = pass && IsIdentity(gpc ? gpc->Exponentiate(this->GetGroupPrecomputation(), q) : ExponentiateElement(g, q));
} }
return pass; return pass;
} }
@ -571,7 +571,7 @@ template <class EC>
void DL_PublicKey_EC<EC>::BERDecodeKey2(BufferedTransformation &bt, bool parametersPresent, unsigned int size) void DL_PublicKey_EC<EC>::BERDecodeKey2(BufferedTransformation &bt, bool parametersPresent, unsigned int size)
{ {
typename EC::Point P; typename EC::Point P;
if (!GetGroupParameters().GetCurve().DecodePoint(P, bt, size)) if (!this->GetGroupParameters().GetCurve().DecodePoint(P, bt, size))
BERDecodeError(); BERDecodeError();
SetPublicElement(P); SetPublicElement(P);
} }
@ -579,7 +579,7 @@ void DL_PublicKey_EC<EC>::BERDecodeKey2(BufferedTransformation &bt, bool paramet
template <class EC> template <class EC>
void DL_PublicKey_EC<EC>::DEREncodeKey(BufferedTransformation &bt) const void DL_PublicKey_EC<EC>::DEREncodeKey(BufferedTransformation &bt) const
{ {
GetGroupParameters().GetCurve().EncodePoint(bt, GetPublicElement(), GetGroupParameters().GetPointCompression()); this->GetGroupParameters().GetCurve().EncodePoint(bt, this->GetPublicElement(), this->GetGroupParameters().GetPointCompression());
} }
// ****************************************************************** // ******************************************************************
@ -602,7 +602,7 @@ void DL_PrivateKey_EC<EC>::BERDecodeKey2(BufferedTransformation &bt, bool parame
if (!seq.EndReached() && seq.PeekByte() == (CONTEXT_SPECIFIC | CONSTRUCTED | 0)) if (!seq.EndReached() && seq.PeekByte() == (CONTEXT_SPECIFIC | CONSTRUCTED | 0))
{ {
BERGeneralDecoder parameters(seq, CONTEXT_SPECIFIC | CONSTRUCTED | 0); BERGeneralDecoder parameters(seq, CONTEXT_SPECIFIC | CONSTRUCTED | 0);
AccessGroupParameters().BERDecode(parameters); this->AccessGroupParameters().BERDecode(parameters);
parameters.MessageEnd(); parameters.MessageEnd();
} }
if (!seq.EndReached()) if (!seq.EndReached())
@ -614,12 +614,12 @@ void DL_PrivateKey_EC<EC>::BERDecodeKey2(BufferedTransformation &bt, bool parame
BERDecodeBitString(publicKey, subjectPublicKey, unusedBits); BERDecodeBitString(publicKey, subjectPublicKey, unusedBits);
publicKey.MessageEnd(); publicKey.MessageEnd();
Element Q; Element Q;
if (!(unusedBits == 0 && GetGroupParameters().GetCurve().DecodePoint(Q, subjectPublicKey, subjectPublicKey.size()))) if (!(unusedBits == 0 && this->GetGroupParameters().GetCurve().DecodePoint(Q, subjectPublicKey, subjectPublicKey.size())))
BERDecodeError(); BERDecodeError();
} }
seq.MessageEnd(); seq.MessageEnd();
SetPrivateExponent(x); this->SetPrivateExponent(x);
} }
template <class EC> template <class EC>
@ -629,7 +629,7 @@ void DL_PrivateKey_EC<EC>::DEREncodeKey(BufferedTransformation &bt) const
DEREncodeUnsigned<word32>(privateKey, 1); // version DEREncodeUnsigned<word32>(privateKey, 1); // version
// SEC 1 ver 1.0 says privateKey (m_d) has the same length as order of the curve // SEC 1 ver 1.0 says privateKey (m_d) has the same length as order of the curve
// this will be changed to order of base point in a future version // this will be changed to order of base point in a future version
GetPrivateExponent().DEREncodeAsOctetString(privateKey, GetGroupParameters().GetSubgroupOrder().ByteCount()); this->GetPrivateExponent().DEREncodeAsOctetString(privateKey, this->GetGroupParameters().GetSubgroupOrder().ByteCount());
privateKey.MessageEnd(); privateKey.MessageEnd();
} }

View File

@ -42,7 +42,7 @@ public:
void Initialize(const EllipticCurve &ec, const Point &G, const Integer &n, const Integer &k = Integer::Zero()) void Initialize(const EllipticCurve &ec, const Point &G, const Integer &n, const Integer &k = Integer::Zero())
{ {
m_groupPrecomputation.SetCurve(ec); this->m_groupPrecomputation.SetCurve(ec);
SetSubgroupGenerator(G); SetSubgroupGenerator(G);
m_n = n; m_n = n;
m_k = k; m_k = k;
@ -59,8 +59,8 @@ public:
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg); void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg);
// DL_GroupParameters // DL_GroupParameters
const DL_FixedBasePrecomputation<Element> & GetBasePrecomputation() const {return m_gpc;} const DL_FixedBasePrecomputation<Element> & GetBasePrecomputation() const {return this->m_gpc;}
DL_FixedBasePrecomputation<Element> & AccessBasePrecomputation() {return m_gpc;} DL_FixedBasePrecomputation<Element> & AccessBasePrecomputation() {return this->m_gpc;}
const Integer & GetSubgroupOrder() const {return m_n;} const Integer & GetSubgroupOrder() const {return m_n;}
Integer GetCofactor() const; Integer GetCofactor() const;
bool ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const; bool ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const;
@ -115,10 +115,10 @@ public:
void SetEncodeAsOID(bool encodeAsOID) {m_encodeAsOID = encodeAsOID;} void SetEncodeAsOID(bool encodeAsOID) {m_encodeAsOID = encodeAsOID;}
bool GetEncodeAsOID() const {return m_encodeAsOID;} bool GetEncodeAsOID() const {return m_encodeAsOID;}
const EllipticCurve& GetCurve() const {return m_groupPrecomputation.GetCurve();} const EllipticCurve& GetCurve() const {return this->m_groupPrecomputation.GetCurve();}
bool operator==(const ThisClass &rhs) const bool operator==(const ThisClass &rhs) const
{return m_groupPrecomputation.GetCurve() == rhs.m_groupPrecomputation.GetCurve() && m_gpc.GetBase(m_groupPrecomputation) == rhs.m_gpc.GetBase(rhs.m_groupPrecomputation);} {return this->m_groupPrecomputation.GetCurve() == rhs.m_groupPrecomputation.GetCurve() && this->m_gpc.GetBase(this->m_groupPrecomputation) == rhs.m_gpc.GetBase(rhs.m_groupPrecomputation);}
#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
const Point& GetBasePoint() const {return GetSubgroupGenerator();} const Point& GetBasePoint() const {return GetSubgroupGenerator();}
@ -149,9 +149,9 @@ public:
typedef typename EC::Point Element; typedef typename EC::Point Element;
void Initialize(const DL_GroupParameters_EC<EC> &params, const Element &Q) void Initialize(const DL_GroupParameters_EC<EC> &params, const Element &Q)
{AccessGroupParameters() = params; SetPublicElement(Q);} {this->AccessGroupParameters() = params; SetPublicElement(Q);}
void Initialize(const EC &ec, const Element &G, const Integer &n, const Element &Q) void Initialize(const EC &ec, const Element &G, const Integer &n, const Element &Q)
{AccessGroupParameters().Initialize(ec, G, n); SetPublicElement(Q);} {this->AccessGroupParameters().Initialize(ec, G, n); SetPublicElement(Q);}
// X509PublicKey // X509PublicKey
void BERDecodeKey2(BufferedTransformation &bt, bool parametersPresent, unsigned int size); void BERDecodeKey2(BufferedTransformation &bt, bool parametersPresent, unsigned int size);
@ -171,9 +171,9 @@ public:
typedef typename EC::Point Element; typedef typename EC::Point Element;
void Initialize(const DL_GroupParameters_EC<EC> &params, const Integer &x) void Initialize(const DL_GroupParameters_EC<EC> &params, const Integer &x)
{AccessGroupParameters() = params; SetPrivateExponent(x);} {this->AccessGroupParameters() = params; this->SetPrivateExponent(x);}
void Initialize(const EC &ec, const Element &G, const Integer &n, const Integer &x) void Initialize(const EC &ec, const Element &G, const Integer &n, const Integer &x)
{AccessGroupParameters().Initialize(ec, G, n); SetPrivateExponent(x);} {this->AccessGroupParameters().Initialize(ec, G, n); this->SetPrivateExponent(x);}
void Initialize(RandomNumberGenerator &rng, const DL_GroupParameters_EC<EC> &params) void Initialize(RandomNumberGenerator &rng, const DL_GroupParameters_EC<EC> &params)
{GenerateRandom(rng, params);} {GenerateRandom(rng, params);}
void Initialize(RandomNumberGenerator &rng, const EC &ec, const Element &G, const Integer &n) void Initialize(RandomNumberGenerator &rng, const EC &ec, const Element &G, const Integer &n)

View File

@ -79,9 +79,9 @@ class CRYPTOPP_NO_VTABLE ElGamalObjectImpl : public DL_ObjectImplBase<BASE, SCHE
{ {
public: public:
unsigned int FixedMaxPlaintextLength() const {return MaxPlaintextLength(FixedCiphertextLength());} unsigned int FixedMaxPlaintextLength() const {return MaxPlaintextLength(FixedCiphertextLength());}
unsigned int FixedCiphertextLength() const {return CiphertextLength(0);} unsigned int FixedCiphertextLength() const {return this->CiphertextLength(0);}
const DL_GroupParameters_GFP & GetGroupParameters() const {return GetKey().GetGroupParameters();} const DL_GroupParameters_GFP & GetGroupParameters() const {return this->GetKey().GetGroupParameters();}
DecodingResult FixedLengthDecrypt(RandomNumberGenerator &rng, const byte *cipherText, byte *plainText) const DecodingResult FixedLengthDecrypt(RandomNumberGenerator &rng, const byte *cipherText, byte *plainText) const
{return Decrypt(rng, cipherText, FixedCiphertextLength(), plainText);} {return Decrypt(rng, cipherText, FixedCiphertextLength(), plainText);}

View File

@ -95,19 +95,19 @@ public:
{AssignFromHelper<DL_GroupParameters_IntegerBased>(this, source);} {AssignFromHelper<DL_GroupParameters_IntegerBased>(this, source);}
// DL_GroupParameters // DL_GroupParameters
const DL_FixedBasePrecomputation<Element> & GetBasePrecomputation() const {return m_gpc;} const DL_FixedBasePrecomputation<Element> & GetBasePrecomputation() const {return this->m_gpc;}
DL_FixedBasePrecomputation<Element> & AccessBasePrecomputation() {return m_gpc;} DL_FixedBasePrecomputation<Element> & AccessBasePrecomputation() {return this->m_gpc;}
// IntegerGroupParameters // IntegerGroupParameters
const Integer & GetModulus() const {return m_groupPrecomputation.GetModulus();} const Integer & GetModulus() const {return this->m_groupPrecomputation.GetModulus();}
const Integer & GetGenerator() const {return m_gpc.GetBase(GetGroupPrecomputation());} const Integer & GetGenerator() const {return this->m_gpc.GetBase(this->GetGroupPrecomputation());}
void SetModulusAndSubgroupGenerator(const Integer &p, const Integer &g) // these have to be set together void SetModulusAndSubgroupGenerator(const Integer &p, const Integer &g) // these have to be set together
{m_groupPrecomputation.SetModulus(p); m_gpc.SetBase(GetGroupPrecomputation(), g); ParametersChanged();} {this->m_groupPrecomputation.SetModulus(p); this->m_gpc.SetBase(this->GetGroupPrecomputation(), g); this->ParametersChanged();}
// non-inherited // non-inherited
bool operator==(const DL_GroupParameters_IntegerBasedImpl<GROUP_PRECOMP, BASE_PRECOMP> &rhs) const bool operator==(const DL_GroupParameters_IntegerBasedImpl<GROUP_PRECOMP, BASE_PRECOMP> &rhs) const
{return GetModulus() == rhs.GetModulus() && GetGenerator() == rhs.GetGenerator() && GetSubgroupOrder() == rhs.GetSubgroupOrder();} {return GetModulus() == rhs.GetModulus() && GetGenerator() == rhs.GetGenerator() && this->GetSubgroupOrder() == rhs.GetSubgroupOrder();}
bool operator!=(const DL_GroupParameters_IntegerBasedImpl<GROUP_PRECOMP, BASE_PRECOMP> &rhs) const bool operator!=(const DL_GroupParameters_IntegerBasedImpl<GROUP_PRECOMP, BASE_PRECOMP> &rhs) const
{return !operator==(rhs);} {return !operator==(rhs);}
}; };
@ -211,17 +211,17 @@ class DL_PublicKey_GFP : public DL_PublicKeyImpl<GP>
{ {
public: public:
void Initialize(const DL_GroupParameters_IntegerBased &params, const Integer &y) void Initialize(const DL_GroupParameters_IntegerBased &params, const Integer &y)
{AccessGroupParameters().Initialize(params); SetPublicElement(y);} {this->AccessGroupParameters().Initialize(params); this->SetPublicElement(y);}
void Initialize(const Integer &p, const Integer &g, const Integer &y) void Initialize(const Integer &p, const Integer &g, const Integer &y)
{AccessGroupParameters().Initialize(p, g); SetPublicElement(y);} {this->AccessGroupParameters().Initialize(p, g); this->SetPublicElement(y);}
void Initialize(const Integer &p, const Integer &q, const Integer &g, const Integer &y) void Initialize(const Integer &p, const Integer &q, const Integer &g, const Integer &y)
{AccessGroupParameters().Initialize(p, q, g); SetPublicElement(y);} {this->AccessGroupParameters().Initialize(p, q, g); this->SetPublicElement(y);}
// X509PublicKey // X509PublicKey
void BERDecodeKey(BufferedTransformation &bt) void BERDecodeKey(BufferedTransformation &bt)
{SetPublicElement(Integer(bt));} {this->SetPublicElement(Integer(bt));}
void DEREncodeKey(BufferedTransformation &bt) const void DEREncodeKey(BufferedTransformation &bt) const
{GetPublicElement().DEREncode(bt);} {this->GetPublicElement().DEREncode(bt);}
}; };
//! . //! .
@ -230,17 +230,17 @@ class DL_PrivateKey_GFP : public DL_PrivateKeyImpl<GP>
{ {
public: public:
void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits) void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits)
{GenerateRandomWithKeySize(rng, modulusBits);} {this->GenerateRandomWithKeySize(rng, modulusBits);}
void Initialize(RandomNumberGenerator &rng, const Integer &p, const Integer &g) void Initialize(RandomNumberGenerator &rng, const Integer &p, const Integer &g)
{GenerateRandom(rng, MakeParameters("Modulus", p)("SubgroupGenerator", g));} {this->GenerateRandom(rng, MakeParameters("Modulus", p)("SubgroupGenerator", g));}
void Initialize(RandomNumberGenerator &rng, const Integer &p, const Integer &q, const Integer &g) void Initialize(RandomNumberGenerator &rng, const Integer &p, const Integer &q, const Integer &g)
{GenerateRandom(rng, MakeParameters("Modulus", p)("SubgroupOrder", q)("SubgroupGenerator", g));} {this->GenerateRandom(rng, MakeParameters("Modulus", p)("SubgroupOrder", q)("SubgroupGenerator", g));}
void Initialize(const DL_GroupParameters_IntegerBased &params, const Integer &x) void Initialize(const DL_GroupParameters_IntegerBased &params, const Integer &x)
{AccessGroupParameters().Initialize(params); SetPrivateExponent(x);} {this->AccessGroupParameters().Initialize(params); this->SetPrivateExponent(x);}
void Initialize(const Integer &p, const Integer &g, const Integer &x) void Initialize(const Integer &p, const Integer &g, const Integer &x)
{AccessGroupParameters().Initialize(p, g); SetPrivateExponent(x);} {this->AccessGroupParameters().Initialize(p, g); this->SetPrivateExponent(x);}
void Initialize(const Integer &p, const Integer &q, const Integer &g, const Integer &x) void Initialize(const Integer &p, const Integer &q, const Integer &g, const Integer &x)
{AccessGroupParameters().Initialize(p, q, g); SetPrivateExponent(x);} {this->AccessGroupParameters().Initialize(p, q, g); this->SetPrivateExponent(x);}
}; };
//! . //! .
@ -273,14 +273,14 @@ public:
if (seq.EndReached()) if (seq.EndReached())
{ {
AccessGroupParameters().Initialize(v1, v1/2, v2); this->AccessGroupParameters().Initialize(v1, v1/2, v2);
SetPublicElement(v3); this->SetPublicElement(v3);
} }
else else
{ {
Integer v4(seq); Integer v4(seq);
AccessGroupParameters().Initialize(v1, v2, v3); this->AccessGroupParameters().Initialize(v1, v2, v3);
SetPublicElement(v4); this->SetPublicElement(v4);
} }
seq.MessageEnd(); seq.MessageEnd();
@ -289,11 +289,11 @@ public:
void DEREncode(BufferedTransformation &bt) const void DEREncode(BufferedTransformation &bt) const
{ {
DERSequenceEncoder seq(bt); DERSequenceEncoder seq(bt);
GetGroupParameters().GetModulus().DEREncode(seq); this->GetGroupParameters().GetModulus().DEREncode(seq);
if (GetGroupParameters().GetCofactor() != 2) if (this->GetGroupParameters().GetCofactor() != 2)
GetGroupParameters().GetSubgroupOrder().DEREncode(seq); this->GetGroupParameters().GetSubgroupOrder().DEREncode(seq);
GetGroupParameters().GetGenerator().DEREncode(seq); this->GetGroupParameters().GetGenerator().DEREncode(seq);
GetPublicElement().DEREncode(seq); this->GetPublicElement().DEREncode(seq);
seq.MessageEnd(); seq.MessageEnd();
} }
}; };
@ -313,14 +313,14 @@ public:
if (seq.EndReached()) if (seq.EndReached())
{ {
AccessGroupParameters().Initialize(v1, v1/2, v2); this->AccessGroupParameters().Initialize(v1, v1/2, v2);
SetPrivateExponent(v4 % (v1/2)); // some old keys may have x >= q this->SetPrivateExponent(v4 % (v1/2)); // some old keys may have x >= q
} }
else else
{ {
Integer v5(seq); Integer v5(seq);
AccessGroupParameters().Initialize(v1, v2, v3); this->AccessGroupParameters().Initialize(v1, v2, v3);
SetPrivateExponent(v5); this->SetPrivateExponent(v5);
} }
seq.MessageEnd(); seq.MessageEnd();
@ -329,12 +329,12 @@ public:
void DEREncode(BufferedTransformation &bt) const void DEREncode(BufferedTransformation &bt) const
{ {
DERSequenceEncoder seq(bt); DERSequenceEncoder seq(bt);
GetGroupParameters().GetModulus().DEREncode(seq); this->GetGroupParameters().GetModulus().DEREncode(seq);
if (GetGroupParameters().GetCofactor() != 2) if (this->GetGroupParameters().GetCofactor() != 2)
GetGroupParameters().GetSubgroupOrder().DEREncode(seq); this->GetGroupParameters().GetSubgroupOrder().DEREncode(seq);
GetGroupParameters().GetGenerator().DEREncode(seq); this->GetGroupParameters().GetGenerator().DEREncode(seq);
GetGroupParameters().ExponentiateBase(GetPrivateExponent()).DEREncode(seq); this->GetGroupParameters().ExponentiateBase(this->GetPrivateExponent()).DEREncode(seq);
GetPrivateExponent().DEREncode(seq); this->GetPrivateExponent().DEREncode(seq);
seq.MessageEnd(); seq.MessageEnd();
} }
}; };

2
hmac.h
View File

@ -44,7 +44,7 @@ public:
HMAC() {} HMAC() {}
HMAC(const byte *key, unsigned int length=HMAC_Base::DEFAULT_KEYLENGTH) HMAC(const byte *key, unsigned int length=HMAC_Base::DEFAULT_KEYLENGTH)
{SetKey(key, length);} {this->SetKey(key, length);}
static std::string StaticAlgorithmName() {return std::string("HMAC(") + T::StaticAlgorithmName() + ")";} static std::string StaticAlgorithmName() {return std::string("HMAC(") + T::StaticAlgorithmName() + ")";}
std::string AlgorithmName() const {return std::string("HMAC(") + m_hash.AlgorithmName() + ")";} std::string AlgorithmName() const {return std::string("HMAC(") + m_hash.AlgorithmName() + ")";}

View File

@ -1560,10 +1560,12 @@ typedef Portable LowLevel;
#ifdef SSE2_INTRINSICS_AVAILABLE #ifdef SSE2_INTRINSICS_AVAILABLE
#ifdef __GNUC__ #ifdef __GNUC__
#define __fastcall #define CRYPTOPP_FASTCALL
#else
#define CRYPTOPP_FASTCALL __fastcall
#endif #endif
static void __fastcall P4_Mul(__m128i *C, const __m128i *A, const __m128i *B) static void CRYPTOPP_FASTCALL P4_Mul(__m128i *C, const __m128i *A, const __m128i *B)
{ {
__m128i a3210 = _mm_load_si128(A); __m128i a3210 = _mm_load_si128(A);
__m128i b3210 = _mm_load_si128(B); __m128i b3210 = _mm_load_si128(B);

View File

@ -77,7 +77,7 @@ public:
CRYPTOPP_COMPILE_ASSERT((BLOCKSIZE & (BLOCKSIZE - 1)) == 0); // blockSize is a power of 2 CRYPTOPP_COMPILE_ASSERT((BLOCKSIZE & (BLOCKSIZE - 1)) == 0); // blockSize is a power of 2
protected: protected:
IteratedHash() {SetBlockSize(T_BlockSize);} IteratedHash() {this->SetBlockSize(T_BlockSize);}
}; };
template <class T_HashWordType, class T_Endianness, unsigned int T_BlockSize, unsigned int T_StateSize, class T_Transform, unsigned int T_DigestSize = T_StateSize> template <class T_HashWordType, class T_Endianness, unsigned int T_BlockSize, unsigned int T_StateSize, class T_Transform, unsigned int T_DigestSize = T_StateSize>
@ -91,30 +91,30 @@ public:
protected: protected:
IteratedHashWithStaticTransform() IteratedHashWithStaticTransform()
{ {
SetStateSize(T_StateSize); this->SetStateSize(T_StateSize);
Init(); Init();
} }
void HashEndianCorrectedBlock(const T_HashWordType *data) {T_Transform::Transform(m_digest, data);} void HashEndianCorrectedBlock(const T_HashWordType *data) {T_Transform::Transform(this->m_digest, data);}
void Init() {T_Transform::InitState(m_digest);} void Init() {T_Transform::InitState(this->m_digest);}
}; };
// ************************************************************* // *************************************************************
template <class T, class B, class BASE> void IteratedHashBase2<T, B, BASE>::TruncatedFinal(byte *digest, unsigned int size) template <class T, class B, class BASE> void IteratedHashBase2<T, B, BASE>::TruncatedFinal(byte *digest, unsigned int size)
{ {
ThrowIfInvalidTruncatedSize(size); this->ThrowIfInvalidTruncatedSize(size);
PadLastBlock(BlockSize() - 2*sizeof(HashWordType)); PadLastBlock(this->BlockSize() - 2*sizeof(HashWordType));
CorrectEndianess(m_data, m_data, BlockSize() - 2*sizeof(HashWordType)); CorrectEndianess(this->m_data, this->m_data, this->BlockSize() - 2*sizeof(HashWordType));
m_data[m_data.size()-2] = B::ToEnum() ? GetBitCountHi() : GetBitCountLo(); this->m_data[this->m_data.size()-2] = B::ToEnum() ? this->GetBitCountHi() : this->GetBitCountLo();
m_data[m_data.size()-1] = B::ToEnum() ? GetBitCountLo() : GetBitCountHi(); this->m_data[this->m_data.size()-1] = B::ToEnum() ? this->GetBitCountLo() : this->GetBitCountHi();
HashEndianCorrectedBlock(m_data); HashEndianCorrectedBlock(this->m_data);
CorrectEndianess(m_digest, m_digest, DigestSize()); CorrectEndianess(this->m_digest, this->m_digest, this->DigestSize());
memcpy(digest, m_digest, size); memcpy(digest, this->m_digest, size);
Restart(); // reinit for next use this->Restart(); // reinit for next use
} }
template <class T, class B, class BASE> void IteratedHashBase2<T, B, BASE>::HashBlock(const HashWordType *input) template <class T, class B, class BASE> void IteratedHashBase2<T, B, BASE>::HashBlock(const HashWordType *input)
@ -123,8 +123,8 @@ template <class T, class B, class BASE> void IteratedHashBase2<T, B, BASE>::Hash
HashEndianCorrectedBlock(input); HashEndianCorrectedBlock(input);
else else
{ {
ByteReverse(m_data.begin(), input, BlockSize()); ByteReverse(this->m_data.begin(), input, this->BlockSize());
HashEndianCorrectedBlock(m_data); HashEndianCorrectedBlock(this->m_data);
} }
} }

View File

@ -29,7 +29,7 @@ class LR : public LR_Info<T>, public BlockCipherDocumentation
// VC60 workaround: have to define these functions within class definition // VC60 workaround: have to define these functions within class definition
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length) void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length)
{ {
AssertValidKeyLength(length); this->AssertValidKeyLength(length);
L = length/2; L = length/2;
buffer.New(2*S); buffer.New(2*S);
@ -50,41 +50,41 @@ class LR : public LR_Info<T>, public BlockCipherDocumentation
{ {
public: public:
#define KL key #define KL this->key
#define KR key+L #define KR this->key+this->L
#define BL buffer #define BL this->buffer
#define BR buffer+S #define BR this->buffer+this->S
#define IL inBlock #define IL inBlock
#define IR inBlock+S #define IR inBlock+this->S
#define OL outBlock #define OL outBlock
#define OR outBlock+S #define OR outBlock+this->S
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
{ {
hm.Update(KL, L); this->hm.Update(KL, this->L);
hm.Update(IL, S); this->hm.Update(IL, this->S);
hm.Final(BR); this->hm.Final(BR);
xorbuf(BR, IR, S); xorbuf(BR, IR, this->S);
hm.Update(KR, L); this->hm.Update(KR, this->L);
hm.Update(BR, S); this->hm.Update(BR, this->S);
hm.Final(BL); this->hm.Final(BL);
xorbuf(BL, IL, S); xorbuf(BL, IL, this->S);
hm.Update(KL, L); this->hm.Update(KL, this->L);
hm.Update(BL, S); this->hm.Update(BL, this->S);
hm.Final(digest); this->hm.Final(this->digest);
xorbuf(BR, digest, S); xorbuf(BR, this->digest, this->S);
hm.Update(KR, L); this->hm.Update(KR, this->L);
hm.Update(OR, S); this->hm.Update(OR, this->S);
hm.Final(digest); this->hm.Final(this->digest);
xorbuf(BL, digest, S); xorbuf(BL, this->digest, this->S);
if (xorBlock) if (xorBlock)
xorbuf(outBlock, xorBlock, buffer, 2*S); xorbuf(outBlock, xorBlock, this->buffer, 2*this->S);
else else
memcpy(outBlock, buffer, 2*S); memcpy(outBlock, this->buffer, 2*this->S);
} }
}; };
@ -93,30 +93,30 @@ class LR : public LR_Info<T>, public BlockCipherDocumentation
public: public:
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
{ {
hm.Update(KR, L); this->hm.Update(KR, this->L);
hm.Update(IR, S); this->hm.Update(IR, this->S);
hm.Final(BL); this->hm.Final(BL);
xorbuf(BL, IL, S); xorbuf(BL, IL, this->S);
hm.Update(KL, L); this->hm.Update(KL, this->L);
hm.Update(BL, S); this->hm.Update(BL, this->S);
hm.Final(BR); this->hm.Final(BR);
xorbuf(BR, IR, S); xorbuf(BR, IR, this->S);
hm.Update(KR, L); this->hm.Update(KR, this->L);
hm.Update(BR, S); this->hm.Update(BR, this->S);
hm.Final(digest); this->hm.Final(this->digest);
xorbuf(BL, digest, S); xorbuf(BL, this->digest, this->S);
hm.Update(KL, L); this->hm.Update(KL, this->L);
hm.Update(OL, S); this->hm.Update(OL, this->S);
hm.Final(digest); this->hm.Final(this->digest);
xorbuf(BR, digest, S); xorbuf(BR, this->digest, this->S);
if (xorBlock) if (xorBlock)
xorbuf(outBlock, xorBlock, buffer, 2*S); xorbuf(outBlock, xorBlock, this->buffer, 2*this->S);
else else
memcpy(outBlock, buffer, 2*S); memcpy(outBlock, this->buffer, 2*this->S);
} }
#undef KL #undef KL
#undef KR #undef KR

14
mdc.h
View File

@ -30,22 +30,22 @@ class MDC : public MDC_Info<T>
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length) void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length)
{ {
assert(direction == ENCRYPTION); assert(direction == ENCRYPTION);
AssertValidKeyLength(length); this->AssertValidKeyLength(length);
memcpy(Key(), userKey, KEYLENGTH); memcpy(Key(), userKey, this->KEYLENGTH);
T::CorrectEndianess(Key(), Key(), KEYLENGTH); T::CorrectEndianess(Key(), Key(), this->KEYLENGTH);
} }
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
{ {
T::CorrectEndianess(Buffer(), (HashWordType *)inBlock, BLOCKSIZE); T::CorrectEndianess(Buffer(), (HashWordType *)inBlock, this->BLOCKSIZE);
T::Transform(Buffer(), Key()); T::Transform(Buffer(), Key());
if (xorBlock) if (xorBlock)
{ {
T::CorrectEndianess(Buffer(), Buffer(), BLOCKSIZE); T::CorrectEndianess(Buffer(), Buffer(), this->BLOCKSIZE);
xorbuf(outBlock, xorBlock, m_buffer, BLOCKSIZE); xorbuf(outBlock, xorBlock, m_buffer, this->BLOCKSIZE);
} }
else else
T::CorrectEndianess((HashWordType *)outBlock, Buffer(), BLOCKSIZE); T::CorrectEndianess((HashWordType *)outBlock, Buffer(), this->BLOCKSIZE);
} }
bool IsPermutation() const {return false;} bool IsPermutation() const {return false;}

8
misc.h
View File

@ -114,14 +114,14 @@ retry:
// ************** misc functions *************** // ************** misc functions ***************
// can't use std::min or std::max in MSVC60 or Cygwin 1.1.0 // can't use std::min or std::max in MSVC60 or Cygwin 1.1.0
template <class _Tp> inline const _Tp& STDMIN(const _Tp& __a, const _Tp& __b) template <class T> inline const T& STDMIN(const T& a, const T& b)
{ {
return __b < __a ? __b : __a; return b < a ? b : a;
} }
template <class _Tp> inline const _Tp& STDMAX(const _Tp& __a, const _Tp& __b) template <class T> inline const T& STDMAX(const T& a, const T& b)
{ {
return __a < __b ? __b : __a; return a < b ? b : a;
} }
#define RETURN_IF_NONZERO(x) unsigned int returnedValue = x; if (returnedValue) return returnedValue #define RETURN_IF_NONZERO(x) unsigned int returnedValue = x; if (returnedValue) return returnedValue

34
modes.h
View File

@ -255,23 +255,23 @@ class CipherModeFinalTemplate_CipherHolder : public ObjectHolder<CIPHER>, public
public: public:
CipherModeFinalTemplate_CipherHolder() CipherModeFinalTemplate_CipherHolder()
{ {
m_cipher = &m_object; this->m_cipher = &this->m_object;
ResizeBuffers(); this->ResizeBuffers();
} }
CipherModeFinalTemplate_CipherHolder(const byte *key, unsigned int length) CipherModeFinalTemplate_CipherHolder(const byte *key, unsigned int length)
{ {
m_cipher = &m_object; this->m_cipher = &this->m_object;
SetKey(key, length); this->SetKey(key, length);
} }
CipherModeFinalTemplate_CipherHolder(const byte *key, unsigned int length, const byte *iv) CipherModeFinalTemplate_CipherHolder(const byte *key, unsigned int length, const byte *iv)
{ {
m_cipher = &m_object; this->m_cipher = &this->m_object;
SetKey(key, length, MakeParameters(Name::IV(), iv)); this->SetKey(key, length, MakeParameters(Name::IV(), iv));
} }
CipherModeFinalTemplate_CipherHolder(const byte *key, unsigned int length, const byte *iv, int feedbackSize) CipherModeFinalTemplate_CipherHolder(const byte *key, unsigned int length, const byte *iv, int feedbackSize)
{ {
m_cipher = &m_object; this->m_cipher = &this->m_object;
SetKey(key, length, MakeParameters(Name::IV(), iv)(Name::FeedbackSize(), feedbackSize)); this->SetKey(key, length, MakeParameters(Name::IV(), iv)(Name::FeedbackSize(), feedbackSize));
} }
}; };
@ -293,20 +293,20 @@ public:
template <class BASE> template <class BASE>
void CipherModeFinalTemplate_ExternalCipher<BASE>::SetCipher(BlockCipher &cipher) void CipherModeFinalTemplate_ExternalCipher<BASE>::SetCipher(BlockCipher &cipher)
{ {
ThrowIfResynchronizable(); this->ThrowIfResynchronizable();
m_cipher = &cipher; this->m_cipher = &cipher;
ResizeBuffers(); this->ResizeBuffers();
} }
template <class BASE> template <class BASE>
void CipherModeFinalTemplate_ExternalCipher<BASE>::SetCipherWithIV(BlockCipher &cipher, const byte *iv, int feedbackSize) void CipherModeFinalTemplate_ExternalCipher<BASE>::SetCipherWithIV(BlockCipher &cipher, const byte *iv, int feedbackSize)
{ {
ThrowIfInvalidIV(iv); this->ThrowIfInvalidIV(iv);
m_cipher = &cipher; this->m_cipher = &cipher;
ResizeBuffers(); this->ResizeBuffers();
SetFeedbackSize(feedbackSize); this->SetFeedbackSize(feedbackSize);
if (IsResynchronizable()) if (this->IsResynchronizable())
Resynchronize(iv); this->Resynchronize(iv);
} }
CRYPTOPP_DLL_TEMPLATE_CLASS CFB_CipherTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> >; CRYPTOPP_DLL_TEMPLATE_CLASS CFB_CipherTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> >;

View File

@ -53,7 +53,7 @@ void Panama<B>::Iterate(unsigned int count, const word32 *p, word32 *z, const wo
word32 *const b16 = b[(bstart+16) % STAGES]; word32 *const b16 = b[(bstart+16) % STAGES];
word32 *const b4 = b[(bstart+4) % STAGES]; word32 *const b4 = b[(bstart+4) % STAGES];
bstart = (bstart + STAGES - 1) % STAGES; bstart = (bstart + STAGES - 1) % STAGES;
word32 *const b0 = b[bstart]; word32 *const b0 = b[bstart];
word32 *const b25 = b[(bstart+25) % STAGES]; word32 *const b25 = b[(bstart+25) % STAGES];
@ -90,25 +90,25 @@ void Panama<B>::Iterate(unsigned int count, const word32 *p, word32 *z, const wo
template <class B> template <class B>
unsigned int PanamaHash<B>::HashMultipleBlocks(const word32 *input, unsigned int length) unsigned int PanamaHash<B>::HashMultipleBlocks(const word32 *input, unsigned int length)
{ {
Iterate(length / BLOCKSIZE, input); this->Iterate(length / this->BLOCKSIZE, input);
return length % BLOCKSIZE; return length % this->BLOCKSIZE;
} }
template <class B> template <class B>
void PanamaHash<B>::TruncatedFinal(byte *hash, unsigned int size) void PanamaHash<B>::TruncatedFinal(byte *hash, unsigned int size)
{ {
ThrowIfInvalidTruncatedSize(size); this->ThrowIfInvalidTruncatedSize(size);
PadLastBlock(BLOCKSIZE, 0x01); PadLastBlock(this->BLOCKSIZE, 0x01);
HashEndianCorrectedBlock(m_data); HashEndianCorrectedBlock(this->m_data);
Iterate(32); // pull this->Iterate(32); // pull
ConditionalByteReverse(B::ToEnum(), m_state+9, m_state+9, DIGESTSIZE); ConditionalByteReverse(B::ToEnum(), this->m_state+9, this->m_state+9, DIGESTSIZE);
memcpy(hash, m_state+9, size); memcpy(hash, this->m_state+9, size);
Restart(); // reinit for next use this->Restart(); // reinit for next use
} }
template <class B> template <class B>
@ -116,22 +116,22 @@ void PanamaCipherPolicy<B>::CipherSetKey(const NameValuePairs &params, const byt
{ {
FixedSizeSecBlock<word32, 8> buf; FixedSizeSecBlock<word32, 8> buf;
Reset(); this->Reset();
memcpy(buf, key, 32); memcpy(buf, key, 32);
Iterate(1, buf); this->Iterate(1, buf);
if (length == 64) if (length == 64)
memcpy(buf, key+32, 32); memcpy(buf, key+32, 32);
else else
memset(buf, 0, 32); memset(buf, 0, 32);
Iterate(1, buf); this->Iterate(1, buf);
Iterate(32); this->Iterate(32);
} }
template <class B> template <class B>
void PanamaCipherPolicy<B>::OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, unsigned int iterationCount) void PanamaCipherPolicy<B>::OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, unsigned int iterationCount)
{ {
Iterate(iterationCount, NULL, (word32 *)output, (const word32 *)input); this->Iterate(iterationCount, NULL, (word32 *)output, (const word32 *)input);
} }
template class Panama<BigEndian>; template class Panama<BigEndian>;

View File

@ -37,7 +37,7 @@ public:
protected: protected:
void Init() {Panama<B>::Reset();} void Init() {Panama<B>::Reset();}
void HashEndianCorrectedBlock(const word32 *data) {Iterate(1, data);} // push void HashEndianCorrectedBlock(const word32 *data) {this->Iterate(1, data);} // push
unsigned int HashMultipleBlocks(const word32 *input, unsigned int length); unsigned int HashMultipleBlocks(const word32 *input, unsigned int length);
}; };
@ -52,7 +52,7 @@ public:
Restart(); Restart();
} }
static const char * StaticAlgorithmName() {return B::ToEnum() == BIG_ENDIAN ? "Panama-BE" : "Panama-LE";} static const char * StaticAlgorithmName() {return B::ToEnum() == BIG_ENDIAN_ORDER ? "Panama-BE" : "Panama-LE";}
protected: protected:
void Init() void Init()
@ -71,7 +71,7 @@ class PanamaMAC : public MessageAuthenticationCodeImpl<PanamaMAC_Base<B> >
public: public:
PanamaMAC() {} PanamaMAC() {}
PanamaMAC(const byte *key, unsigned int length=PanamaMAC_Base<B>::DEFAULT_KEYLENGTH) PanamaMAC(const byte *key, unsigned int length=PanamaMAC_Base<B>::DEFAULT_KEYLENGTH)
{SetKey(key, length);} {this->SetKey(key, length);}
}; };
//! . //! .

View File

@ -324,46 +324,46 @@ public:
{return a.Equals(b, m_ring);} {return a.Equals(b, m_ring);}
const Element& Identity() const const Element& Identity() const
{return result = m_ring.Identity();} {return this->result = m_ring.Identity();}
const Element& Add(const Element &a, const Element &b) const const Element& Add(const Element &a, const Element &b) const
{return result = a.Plus(b, m_ring);} {return this->result = a.Plus(b, m_ring);}
Element& Accumulate(Element &a, const Element &b) const Element& Accumulate(Element &a, const Element &b) const
{a.Accumulate(b, m_ring); return a;} {a.Accumulate(b, m_ring); return a;}
const Element& Inverse(const Element &a) const const Element& Inverse(const Element &a) const
{return result = a.Inverse(m_ring);} {return this->result = a.Inverse(m_ring);}
const Element& Subtract(const Element &a, const Element &b) const const Element& Subtract(const Element &a, const Element &b) const
{return result = a.Minus(b, m_ring);} {return this->result = a.Minus(b, m_ring);}
Element& Reduce(Element &a, const Element &b) const Element& Reduce(Element &a, const Element &b) const
{return a.Reduce(b, m_ring);} {return a.Reduce(b, m_ring);}
const Element& Double(const Element &a) const const Element& Double(const Element &a) const
{return result = a.Doubled(m_ring);} {return this->result = a.Doubled(m_ring);}
const Element& MultiplicativeIdentity() const const Element& MultiplicativeIdentity() const
{return result = m_ring.MultiplicativeIdentity();} {return this->result = m_ring.MultiplicativeIdentity();}
const Element& Multiply(const Element &a, const Element &b) const const Element& Multiply(const Element &a, const Element &b) const
{return result = a.Times(b, m_ring);} {return this->result = a.Times(b, m_ring);}
const Element& Square(const Element &a) const const Element& Square(const Element &a) const
{return result = a.Squared(m_ring);} {return this->result = a.Squared(m_ring);}
bool IsUnit(const Element &a) const bool IsUnit(const Element &a) const
{return a.IsUnit(m_ring);} {return a.IsUnit(m_ring);}
const Element& MultiplicativeInverse(const Element &a) const const Element& MultiplicativeInverse(const Element &a) const
{return result = a.MultiplicativeInverse(m_ring);} {return this->result = a.MultiplicativeInverse(m_ring);}
const Element& Divide(const Element &a, const Element &b) const const Element& Divide(const Element &a, const Element &b) const
{return result = a.DividedBy(b, m_ring);} {return this->result = a.DividedBy(b, m_ring);}
const Element& Mod(const Element &a, const Element &b) const const Element& Mod(const Element &a, const Element &b) const
{return result = a.Modulo(b, m_ring);} {return this->result = a.Modulo(b, m_ring);}
void DivisionAlgorithm(Element &r, Element &q, const Element &a, const Element &d) const void DivisionAlgorithm(Element &r, Element &q, const Element &a, const Element &d) const
{Element::Divide(r, q, a, d, m_ring);} {Element::Divide(r, q, a, d, m_ring);}
@ -399,7 +399,7 @@ Element BulkPolynomialInterpolateAt(const Ring &ring, const Element y[], const E
//! //!
template <class T, int instance> template <class T, int instance>
inline bool operator==(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b) inline bool operator==(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b)
{return a.Equals(b, ms_fixedRing);} {return a.Equals(b, a.ms_fixedRing);}
//! //!
template <class T, int instance> template <class T, int instance>
inline bool operator!=(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b) inline bool operator!=(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b)
@ -425,23 +425,23 @@ inline bool operator<=(const CryptoPP::PolynomialOverFixedRing<T, instance> &a,
//! //!
template <class T, int instance> template <class T, int instance>
inline CryptoPP::PolynomialOverFixedRing<T, instance> operator+(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b) inline CryptoPP::PolynomialOverFixedRing<T, instance> operator+(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b)
{return CryptoPP::PolynomialOverFixedRing<T, instance>(a.Plus(b, ms_fixedRing));} {return CryptoPP::PolynomialOverFixedRing<T, instance>(a.Plus(b, a.ms_fixedRing));}
//! //!
template <class T, int instance> template <class T, int instance>
inline CryptoPP::PolynomialOverFixedRing<T, instance> operator-(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b) inline CryptoPP::PolynomialOverFixedRing<T, instance> operator-(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b)
{return CryptoPP::PolynomialOverFixedRing<T, instance>(a.Minus(b, ms_fixedRing));} {return CryptoPP::PolynomialOverFixedRing<T, instance>(a.Minus(b, a.ms_fixedRing));}
//! //!
template <class T, int instance> template <class T, int instance>
inline CryptoPP::PolynomialOverFixedRing<T, instance> operator*(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b) inline CryptoPP::PolynomialOverFixedRing<T, instance> operator*(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b)
{return CryptoPP::PolynomialOverFixedRing<T, instance>(a.Times(b, ms_fixedRing));} {return CryptoPP::PolynomialOverFixedRing<T, instance>(a.Times(b, a.ms_fixedRing));}
//! //!
template <class T, int instance> template <class T, int instance>
inline CryptoPP::PolynomialOverFixedRing<T, instance> operator/(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b) inline CryptoPP::PolynomialOverFixedRing<T, instance> operator/(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b)
{return CryptoPP::PolynomialOverFixedRing<T, instance>(a.DividedBy(b, ms_fixedRing));} {return CryptoPP::PolynomialOverFixedRing<T, instance>(a.DividedBy(b, a.ms_fixedRing));}
//! //!
template <class T, int instance> template <class T, int instance>
inline CryptoPP::PolynomialOverFixedRing<T, instance> operator%(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b) inline CryptoPP::PolynomialOverFixedRing<T, instance> operator%(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b)
{return CryptoPP::PolynomialOverFixedRing<T, instance>(a.Modulo(b, ms_fixedRing));} {return CryptoPP::PolynomialOverFixedRing<T, instance>(a.Modulo(b, a.ms_fixedRing));}
NAMESPACE_END NAMESPACE_END

234
pubkey.h
View File

@ -32,7 +32,7 @@
The "DL_" prefix means an implementation using group operations (in groups where discrete log is hard). The "DL_" prefix means an implementation using group operations (in groups where discrete log is hard).
*/ */
#include "integer.h" #include "modarith.h"
#include "filters.h" #include "filters.h"
#include "eprecomp.h" #include "eprecomp.h"
#include "fips140.h" #include "fips140.h"
@ -152,13 +152,13 @@ template <class INTERFACE, class BASE>
class CRYPTOPP_NO_VTABLE TF_CryptoSystemBase : public PK_FixedLengthCryptoSystemImpl<INTERFACE>, protected BASE class CRYPTOPP_NO_VTABLE TF_CryptoSystemBase : public PK_FixedLengthCryptoSystemImpl<INTERFACE>, protected BASE
{ {
public: public:
bool ParameterSupported(const char *name) const {return GetMessageEncodingInterface().ParameterSupported(name);} bool ParameterSupported(const char *name) const {return this->GetMessageEncodingInterface().ParameterSupported(name);}
unsigned int FixedMaxPlaintextLength() const {return GetMessageEncodingInterface().MaxUnpaddedLength(PaddedBlockBitLength());} unsigned int FixedMaxPlaintextLength() const {return this->GetMessageEncodingInterface().MaxUnpaddedLength(PaddedBlockBitLength());}
unsigned int FixedCiphertextLength() const {return GetTrapdoorFunctionBounds().MaxImage().ByteCount();} unsigned int FixedCiphertextLength() const {return this->GetTrapdoorFunctionBounds().MaxImage().ByteCount();}
protected: protected:
unsigned int PaddedBlockByteLength() const {return BitsToBytes(PaddedBlockBitLength());} unsigned int PaddedBlockByteLength() const {return BitsToBytes(PaddedBlockBitLength());}
unsigned int PaddedBlockBitLength() const {return GetTrapdoorFunctionBounds().PreimageBound().BitCount()-1;} unsigned int PaddedBlockBitLength() const {return this->GetTrapdoorFunctionBounds().PreimageBound().BitCount()-1;}
}; };
//! . //! .
@ -299,7 +299,7 @@ template <class HASH_ALGORITHM>
class PK_MessageAccumulatorImpl : public PK_MessageAccumulatorBase, protected ObjectHolder<HASH_ALGORITHM> class PK_MessageAccumulatorImpl : public PK_MessageAccumulatorBase, protected ObjectHolder<HASH_ALGORITHM>
{ {
public: public:
HashTransformation & AccessHash() {return m_object;} HashTransformation & AccessHash() {return this->m_object;}
}; };
//! . //! .
@ -308,22 +308,22 @@ class CRYPTOPP_NO_VTABLE TF_SignatureSchemeBase : public INTERFACE, protected BA
{ {
public: public:
unsigned int SignatureLength() const unsigned int SignatureLength() const
{return GetTrapdoorFunctionBounds().MaxPreimage().ByteCount();} {return this->GetTrapdoorFunctionBounds().MaxPreimage().ByteCount();}
unsigned int MaxRecoverableLength() const unsigned int MaxRecoverableLength() const
{return GetMessageEncodingInterface().MaxRecoverableLength(MessageRepresentativeBitLength(), GetHashIdentifier().second, GetDigestSize());} {return this->GetMessageEncodingInterface().MaxRecoverableLength(MessageRepresentativeBitLength(), GetHashIdentifier().second, GetDigestSize());}
unsigned int MaxRecoverableLengthFromSignatureLength(unsigned int signatureLength) const unsigned int MaxRecoverableLengthFromSignatureLength(unsigned int signatureLength) const
{return MaxRecoverableLength();} {return this->MaxRecoverableLength();}
bool IsProbabilistic() const bool IsProbabilistic() const
{return GetTrapdoorFunctionInterface().IsRandomized() || GetMessageEncodingInterface().IsProbabilistic();} {return this->GetTrapdoorFunctionInterface().IsRandomized() || this->GetMessageEncodingInterface().IsProbabilistic();}
bool AllowNonrecoverablePart() const bool AllowNonrecoverablePart() const
{return GetMessageEncodingInterface().AllowNonrecoverablePart();} {return this->GetMessageEncodingInterface().AllowNonrecoverablePart();}
bool RecoverablePartFirst() const bool RecoverablePartFirst() const
{return GetMessageEncodingInterface().RecoverablePartFirst();} {return this->GetMessageEncodingInterface().RecoverablePartFirst();}
protected: protected:
unsigned int MessageRepresentativeLength() const {return BitsToBytes(MessageRepresentativeBitLength());} unsigned int MessageRepresentativeLength() const {return BitsToBytes(MessageRepresentativeBitLength());}
unsigned int MessageRepresentativeBitLength() const {return GetTrapdoorFunctionBounds().ImageBound().BitCount()-1;} unsigned int MessageRepresentativeBitLength() const {return this->GetTrapdoorFunctionBounds().ImageBound().BitCount()-1;}
virtual HashIdentifier GetHashIdentifier() const =0; virtual HashIdentifier GetHashIdentifier() const =0;
virtual unsigned int GetDigestSize() const =0; virtual unsigned int GetDigestSize() const =0;
}; };
@ -423,8 +423,8 @@ protected:
// for signature scheme // for signature scheme
HashIdentifier GetHashIdentifier() const HashIdentifier GetHashIdentifier() const
{ {
typedef CPP_TYPENAME SchemeOptions::MessageEncodingMethod::HashIdentifierLookup::HashIdentifierLookup2<CPP_TYPENAME SchemeOptions::HashFunction> L; typedef CPP_TYPENAME SchemeOptions::MessageEncodingMethod::HashIdentifierLookup::template HashIdentifierLookup2<CPP_TYPENAME SchemeOptions::HashFunction> L;
return L::Lookup(); return L::Lookup();
} }
unsigned int GetDigestSize() const unsigned int GetDigestSize() const
{ {
@ -664,23 +664,23 @@ public:
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
{ {
return GetValueHelper(this, name, valueType, pValue, &GetAbstractGroupParameters()) return GetValueHelper(this, name, valueType, pValue, &this->GetAbstractGroupParameters())
CRYPTOPP_GET_FUNCTION_ENTRY(PublicElement); CRYPTOPP_GET_FUNCTION_ENTRY(PublicElement);
} }
void AssignFrom(const NameValuePairs &source); void AssignFrom(const NameValuePairs &source);
// non-inherited // non-inherited
virtual const Element & GetPublicElement() const {return GetPublicPrecomputation().GetBase(GetAbstractGroupParameters().GetGroupPrecomputation());} virtual const Element & GetPublicElement() const {return GetPublicPrecomputation().GetBase(this->GetAbstractGroupParameters().GetGroupPrecomputation());}
virtual void SetPublicElement(const Element &y) {AccessPublicPrecomputation().SetBase(GetAbstractGroupParameters().GetGroupPrecomputation(), y);} virtual void SetPublicElement(const Element &y) {AccessPublicPrecomputation().SetBase(this->GetAbstractGroupParameters().GetGroupPrecomputation(), y);}
virtual Element ExponentiatePublicElement(const Integer &exponent) const virtual Element ExponentiatePublicElement(const Integer &exponent) const
{ {
const DL_GroupParameters<T> &params = GetAbstractGroupParameters(); const DL_GroupParameters<T> &params = this->GetAbstractGroupParameters();
return GetPublicPrecomputation().Exponentiate(params.GetGroupPrecomputation(), exponent); return GetPublicPrecomputation().Exponentiate(params.GetGroupPrecomputation(), exponent);
} }
virtual Element CascadeExponentiateBaseAndPublicElement(const Integer &baseExp, const Integer &publicExp) const virtual Element CascadeExponentiateBaseAndPublicElement(const Integer &baseExp, const Integer &publicExp) const
{ {
const DL_GroupParameters<T> &params = GetAbstractGroupParameters(); const DL_GroupParameters<T> &params = this->GetAbstractGroupParameters();
return params.GetBasePrecomputation().CascadeExponentiate(params.GetGroupPrecomputation(), baseExp, GetPublicPrecomputation(), publicExp); return params.GetBasePrecomputation().CascadeExponentiate(params.GetGroupPrecomputation(), baseExp, GetPublicPrecomputation(), publicExp);
} }
@ -699,19 +699,19 @@ public:
void MakePublicKey(DL_PublicKey<T> &pub) const void MakePublicKey(DL_PublicKey<T> &pub) const
{ {
pub.AccessAbstractGroupParameters().AssignFrom(GetAbstractGroupParameters()); pub.AccessAbstractGroupParameters().AssignFrom(this->GetAbstractGroupParameters());
pub.SetPublicElement(GetAbstractGroupParameters().ExponentiateBase(GetPrivateExponent())); pub.SetPublicElement(this->GetAbstractGroupParameters().ExponentiateBase(GetPrivateExponent()));
} }
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
{ {
return GetValueHelper(this, name, valueType, pValue, &GetAbstractGroupParameters()) return GetValueHelper(this, name, valueType, pValue, &this->GetAbstractGroupParameters())
CRYPTOPP_GET_FUNCTION_ENTRY(PrivateExponent); CRYPTOPP_GET_FUNCTION_ENTRY(PrivateExponent);
} }
void AssignFrom(const NameValuePairs &source) void AssignFrom(const NameValuePairs &source)
{ {
AccessAbstractGroupParameters().AssignFrom(source); this->AccessAbstractGroupParameters().AssignFrom(source);
AssignFromHelper(this, source) AssignFromHelper(this, source)
CRYPTOPP_SET_FUNCTION_ENTRY(PrivateExponent); CRYPTOPP_SET_FUNCTION_ENTRY(PrivateExponent);
} }
@ -728,7 +728,7 @@ void DL_PublicKey<T>::AssignFrom(const NameValuePairs &source)
pPrivateKey->MakePublicKey(*this); pPrivateKey->MakePublicKey(*this);
else else
{ {
AccessAbstractGroupParameters().AssignFrom(source); this->AccessAbstractGroupParameters().AssignFrom(source);
AssignFromHelper(this, source) AssignFromHelper(this, source)
CRYPTOPP_SET_FUNCTION_ENTRY(PublicElement); CRYPTOPP_SET_FUNCTION_ENTRY(PublicElement);
} }
@ -796,8 +796,8 @@ public:
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &params) void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &params)
{ {
if (!params.GetThisObject(AccessGroupParameters())) if (!params.GetThisObject(this->AccessGroupParameters()))
AccessGroupParameters().GenerateRandom(rng, params); this->AccessGroupParameters().GenerateRandom(rng, params);
// std::pair<const byte *, int> seed; // std::pair<const byte *, int> seed;
Integer x(rng, Integer::One(), GetAbstractGroupParameters().GetMaxExponent()); Integer x(rng, Integer::One(), GetAbstractGroupParameters().GetMaxExponent());
// Integer::ANY, Integer::Zero(), Integer::One(), // Integer::ANY, Integer::Zero(), Integer::One(),
@ -817,8 +817,8 @@ public:
{GetAbstractGroupParameters().SavePrecomputation(storedPrecomputation);} {GetAbstractGroupParameters().SavePrecomputation(storedPrecomputation);}
// DL_Key // DL_Key
const DL_GroupParameters<Element> & GetAbstractGroupParameters() const {return GetGroupParameters();} const DL_GroupParameters<Element> & GetAbstractGroupParameters() const {return this->GetGroupParameters();}
DL_GroupParameters<Element> & AccessAbstractGroupParameters() {return AccessGroupParameters();} DL_GroupParameters<Element> & AccessAbstractGroupParameters() {return this->AccessGroupParameters();}
// DL_PrivateKey // DL_PrivateKey
const Integer & GetPrivateExponent() const {return m_x;} const Integer & GetPrivateExponent() const {return m_x;}
@ -863,7 +863,7 @@ public:
bool Validate(RandomNumberGenerator &rng, unsigned int level) const bool Validate(RandomNumberGenerator &rng, unsigned int level) const
{ {
bool pass = GetAbstractGroupParameters().Validate(rng, level); bool pass = GetAbstractGroupParameters().Validate(rng, level);
pass = pass && GetAbstractGroupParameters().ValidateElement(level, GetPublicElement(), &GetPublicPrecomputation()); pass = pass && GetAbstractGroupParameters().ValidateElement(level, this->GetPublicElement(), &GetPublicPrecomputation());
return pass; return pass;
} }
@ -898,8 +898,8 @@ public:
} }
// DL_Key // DL_Key
const DL_GroupParameters<Element> & GetAbstractGroupParameters() const {return GetGroupParameters();} const DL_GroupParameters<Element> & GetAbstractGroupParameters() const {return this->GetGroupParameters();}
DL_GroupParameters<Element> & AccessAbstractGroupParameters() {return AccessGroupParameters();} DL_GroupParameters<Element> & AccessAbstractGroupParameters() {return this->AccessGroupParameters();}
// DL_PublicKey // DL_PublicKey
const DL_FixedBasePrecomputation<Element> & GetPublicPrecomputation() const {return m_ypc;} const DL_FixedBasePrecomputation<Element> & GetPublicPrecomputation() const {return m_ypc;}
@ -907,7 +907,7 @@ public:
// non-inherited // non-inherited
bool operator==(const DL_PublicKeyImpl<GP> &rhs) const bool operator==(const DL_PublicKeyImpl<GP> &rhs) const
{return GetGroupParameters() == rhs.GetGroupParameters() && GetPublicElement() == rhs.GetPublicElement();} {return this->GetGroupParameters() == rhs.GetGroupParameters() && this->GetPublicElement() == rhs.GetPublicElement();}
private: private:
typename GP::BasePrecomputation m_ypc; typename GP::BasePrecomputation m_ypc;
@ -982,8 +982,8 @@ class CRYPTOPP_NO_VTABLE DL_SignatureSchemeBase : public INTERFACE, public DL_Ba
public: public:
unsigned int SignatureLength() const unsigned int SignatureLength() const
{ {
return GetSignatureAlgorithm().RLen(GetAbstractGroupParameters()) return GetSignatureAlgorithm().RLen(this->GetAbstractGroupParameters())
+ GetSignatureAlgorithm().SLen(GetAbstractGroupParameters()); + GetSignatureAlgorithm().SLen(this->GetAbstractGroupParameters());
} }
unsigned int MaxRecoverableLength() const unsigned int MaxRecoverableLength() const
{return GetMessageEncodingInterface().MaxRecoverableLength(0, GetHashIdentifier().second, GetDigestSize());} {return GetMessageEncodingInterface().MaxRecoverableLength(0, GetHashIdentifier().second, GetDigestSize());}
@ -999,7 +999,7 @@ public:
protected: protected:
unsigned int MessageRepresentativeLength() const {return BitsToBytes(MessageRepresentativeBitLength());} unsigned int MessageRepresentativeLength() const {return BitsToBytes(MessageRepresentativeBitLength());}
unsigned int MessageRepresentativeBitLength() const {return GetAbstractGroupParameters().GetSubgroupOrder().BitCount();} unsigned int MessageRepresentativeBitLength() const {return this->GetAbstractGroupParameters().GetSubgroupOrder().BitCount();}
virtual const DL_ElgamalLikeSignatureAlgorithm<CPP_TYPENAME KEY_INTERFACE::Element> & GetSignatureAlgorithm() const =0; virtual const DL_ElgamalLikeSignatureAlgorithm<CPP_TYPENAME KEY_INTERFACE::Element> & GetSignatureAlgorithm() const =0;
virtual const PK_SignatureMessageEncodingMethod & GetMessageEncodingInterface() const =0; virtual const PK_SignatureMessageEncodingMethod & GetMessageEncodingInterface() const =0;
@ -1015,9 +1015,9 @@ public:
// for validation testing // for validation testing
void RawSign(const Integer &k, const Integer &e, Integer &r, Integer &s) const void RawSign(const Integer &k, const Integer &e, Integer &r, Integer &s) const
{ {
const DL_ElgamalLikeSignatureAlgorithm<T> &alg = GetSignatureAlgorithm(); const DL_ElgamalLikeSignatureAlgorithm<T> &alg = this->GetSignatureAlgorithm();
const DL_GroupParameters<T> &params = GetAbstractGroupParameters(); const DL_GroupParameters<T> &params = this->GetAbstractGroupParameters();
const DL_PrivateKey<T> &key = GetKeyInterface(); const DL_PrivateKey<T> &key = this->GetKeyInterface();
r = params.ConvertElementToInteger(params.ExponentiateBase(k)); r = params.ConvertElementToInteger(params.ExponentiateBase(k));
alg.Sign(params, key.GetPrivateExponent(), k, e, r, s); alg.Sign(params, key.GetPrivateExponent(), k, e, r, s);
@ -1027,7 +1027,7 @@ public:
{ {
PK_MessageAccumulatorBase &ma = static_cast<PK_MessageAccumulatorBase &>(messageAccumulator); PK_MessageAccumulatorBase &ma = static_cast<PK_MessageAccumulatorBase &>(messageAccumulator);
ma.m_recoverableMessage.Assign(recoverableMessage, recoverableMessageLength); ma.m_recoverableMessage.Assign(recoverableMessage, recoverableMessageLength);
GetMessageEncodingInterface().ProcessRecoverableMessage(ma.AccessHash(), this->GetMessageEncodingInterface().ProcessRecoverableMessage(ma.AccessHash(),
recoverableMessage, recoverableMessageLength, recoverableMessage, recoverableMessageLength,
ma.m_presignature, ma.m_presignature.size(), ma.m_presignature, ma.m_presignature.size(),
ma.m_semisignature); ma.m_semisignature);
@ -1035,24 +1035,24 @@ public:
unsigned int SignAndRestart(RandomNumberGenerator &rng, PK_MessageAccumulator &messageAccumulator, byte *signature, bool restart) const unsigned int SignAndRestart(RandomNumberGenerator &rng, PK_MessageAccumulator &messageAccumulator, byte *signature, bool restart) const
{ {
GetMaterial().DoQuickSanityCheck(); this->GetMaterial().DoQuickSanityCheck();
PK_MessageAccumulatorBase &ma = static_cast<PK_MessageAccumulatorBase &>(messageAccumulator); PK_MessageAccumulatorBase &ma = static_cast<PK_MessageAccumulatorBase &>(messageAccumulator);
const DL_ElgamalLikeSignatureAlgorithm<T> &alg = GetSignatureAlgorithm(); const DL_ElgamalLikeSignatureAlgorithm<T> &alg = this->GetSignatureAlgorithm();
const DL_GroupParameters<T> &params = GetAbstractGroupParameters(); const DL_GroupParameters<T> &params = this->GetAbstractGroupParameters();
const DL_PrivateKey<T> &key = GetKeyInterface(); const DL_PrivateKey<T> &key = this->GetKeyInterface();
SecByteBlock representative(MessageRepresentativeLength()); SecByteBlock representative(this->MessageRepresentativeLength());
GetMessageEncodingInterface().ComputeMessageRepresentative( this->GetMessageEncodingInterface().ComputeMessageRepresentative(
rng, rng,
ma.m_recoverableMessage, ma.m_recoverableMessage.size(), ma.m_recoverableMessage, ma.m_recoverableMessage.size(),
ma.AccessHash(), GetHashIdentifier(), ma.m_empty, ma.AccessHash(), this->GetHashIdentifier(), ma.m_empty,
representative, MessageRepresentativeBitLength()); representative, this->MessageRepresentativeBitLength());
ma.m_empty = true; ma.m_empty = true;
Integer e(representative, representative.size()); Integer e(representative, representative.size());
Integer r; Integer r;
if (MaxRecoverableLength() > 0) if (this->MaxRecoverableLength() > 0)
r.Decode(ma.m_semisignature, ma.m_semisignature.size()); r.Decode(ma.m_semisignature, ma.m_semisignature.size());
else else
r.Decode(ma.m_presignature, ma.m_presignature.size()); r.Decode(ma.m_presignature, ma.m_presignature.size());
@ -1066,14 +1066,14 @@ public:
if (restart) if (restart)
RestartMessageAccumulator(rng, ma); RestartMessageAccumulator(rng, ma);
return SignatureLength(); return this->SignatureLength();
} }
protected: protected:
void RestartMessageAccumulator(RandomNumberGenerator &rng, PK_MessageAccumulatorBase &ma) const void RestartMessageAccumulator(RandomNumberGenerator &rng, PK_MessageAccumulatorBase &ma) const
{ {
const DL_ElgamalLikeSignatureAlgorithm<T> &alg = GetSignatureAlgorithm(); const DL_ElgamalLikeSignatureAlgorithm<T> &alg = this->GetSignatureAlgorithm();
const DL_GroupParameters<T> &params = GetAbstractGroupParameters(); const DL_GroupParameters<T> &params = this->GetAbstractGroupParameters();
ma.m_k.Randomize(rng, 1, params.GetSubgroupOrder()-1); ma.m_k.Randomize(rng, 1, params.GetSubgroupOrder()-1);
ma.m_presignature.New(params.GetEncodedElementSize(false)); ma.m_presignature.New(params.GetEncodedElementSize(false));
params.ConvertElementToInteger(params.ExponentiateBase(ma.m_k)).Encode(ma.m_presignature, ma.m_presignature.size()); params.ConvertElementToInteger(params.ExponentiateBase(ma.m_k)).Encode(ma.m_presignature, ma.m_presignature.size());
@ -1088,29 +1088,29 @@ public:
void InputSignature(PK_MessageAccumulator &messageAccumulator, const byte *signature, unsigned int signatureLength) const void InputSignature(PK_MessageAccumulator &messageAccumulator, const byte *signature, unsigned int signatureLength) const
{ {
PK_MessageAccumulatorBase &ma = static_cast<PK_MessageAccumulatorBase &>(messageAccumulator); PK_MessageAccumulatorBase &ma = static_cast<PK_MessageAccumulatorBase &>(messageAccumulator);
const DL_ElgamalLikeSignatureAlgorithm<T> &alg = GetSignatureAlgorithm(); const DL_ElgamalLikeSignatureAlgorithm<T> &alg = this->GetSignatureAlgorithm();
const DL_GroupParameters<T> &params = GetAbstractGroupParameters(); const DL_GroupParameters<T> &params = this->GetAbstractGroupParameters();
unsigned int rLen = alg.RLen(params); unsigned int rLen = alg.RLen(params);
ma.m_semisignature.Assign(signature, rLen); ma.m_semisignature.Assign(signature, rLen);
ma.m_s.Decode(signature+rLen, alg.SLen(params)); ma.m_s.Decode(signature+rLen, alg.SLen(params));
GetMessageEncodingInterface().ProcessSemisignature(ma.AccessHash(), ma.m_semisignature, ma.m_semisignature.size()); this->GetMessageEncodingInterface().ProcessSemisignature(ma.AccessHash(), ma.m_semisignature, ma.m_semisignature.size());
} }
bool VerifyAndRestart(PK_MessageAccumulator &messageAccumulator) const bool VerifyAndRestart(PK_MessageAccumulator &messageAccumulator) const
{ {
GetMaterial().DoQuickSanityCheck(); this->GetMaterial().DoQuickSanityCheck();
PK_MessageAccumulatorBase &ma = static_cast<PK_MessageAccumulatorBase &>(messageAccumulator); PK_MessageAccumulatorBase &ma = static_cast<PK_MessageAccumulatorBase &>(messageAccumulator);
const DL_ElgamalLikeSignatureAlgorithm<T> &alg = GetSignatureAlgorithm(); const DL_ElgamalLikeSignatureAlgorithm<T> &alg = this->GetSignatureAlgorithm();
const DL_GroupParameters<T> &params = GetAbstractGroupParameters(); const DL_GroupParameters<T> &params = this->GetAbstractGroupParameters();
const DL_PublicKey<T> &key = GetKeyInterface(); const DL_PublicKey<T> &key = this->GetKeyInterface();
SecByteBlock representative(MessageRepresentativeLength()); SecByteBlock representative(this->MessageRepresentativeLength());
GetMessageEncodingInterface().ComputeMessageRepresentative(NullRNG(), ma.m_recoverableMessage, ma.m_recoverableMessage.size(), this->GetMessageEncodingInterface().ComputeMessageRepresentative(NullRNG(), ma.m_recoverableMessage, ma.m_recoverableMessage.size(),
ma.AccessHash(), GetHashIdentifier(), ma.m_empty, ma.AccessHash(), this->GetHashIdentifier(), ma.m_empty,
representative, MessageRepresentativeBitLength()); representative, this->MessageRepresentativeBitLength());
ma.m_empty = true; ma.m_empty = true;
Integer e(representative, representative.size()); Integer e(representative, representative.size());
@ -1120,19 +1120,19 @@ public:
DecodingResult RecoverAndRestart(byte *recoveredMessage, PK_MessageAccumulator &messageAccumulator) const DecodingResult RecoverAndRestart(byte *recoveredMessage, PK_MessageAccumulator &messageAccumulator) const
{ {
GetMaterial().DoQuickSanityCheck(); this->GetMaterial().DoQuickSanityCheck();
PK_MessageAccumulatorBase &ma = static_cast<PK_MessageAccumulatorBase &>(messageAccumulator); PK_MessageAccumulatorBase &ma = static_cast<PK_MessageAccumulatorBase &>(messageAccumulator);
const DL_ElgamalLikeSignatureAlgorithm<T> &alg = GetSignatureAlgorithm(); const DL_ElgamalLikeSignatureAlgorithm<T> &alg = this->GetSignatureAlgorithm();
const DL_GroupParameters<T> &params = GetAbstractGroupParameters(); const DL_GroupParameters<T> &params = this->GetAbstractGroupParameters();
const DL_PublicKey<T> &key = GetKeyInterface(); const DL_PublicKey<T> &key = this->GetKeyInterface();
SecByteBlock representative(MessageRepresentativeLength()); SecByteBlock representative(this->MessageRepresentativeLength());
GetMessageEncodingInterface().ComputeMessageRepresentative( this->GetMessageEncodingInterface().ComputeMessageRepresentative(
NullRNG(), NullRNG(),
ma.m_recoverableMessage, ma.m_recoverableMessage.size(), ma.m_recoverableMessage, ma.m_recoverableMessage.size(),
ma.AccessHash(), GetHashIdentifier(), ma.m_empty, ma.AccessHash(), this->GetHashIdentifier(), ma.m_empty,
representative, MessageRepresentativeBitLength()); representative, this->MessageRepresentativeBitLength());
ma.m_empty = true; ma.m_empty = true;
Integer e(representative, representative.size()); Integer e(representative, representative.size());
@ -1140,8 +1140,8 @@ public:
Integer r(ma.m_semisignature, ma.m_semisignature.size()); Integer r(ma.m_semisignature, ma.m_semisignature.size());
alg.RecoverPresignature(params, key, r, ma.m_s).Encode(ma.m_presignature, ma.m_presignature.size()); alg.RecoverPresignature(params, key, r, ma.m_s).Encode(ma.m_presignature, ma.m_presignature.size());
return GetMessageEncodingInterface().RecoverMessageFromSemisignature( return this->GetMessageEncodingInterface().RecoverMessageFromSemisignature(
ma.AccessHash(), GetHashIdentifier(), ma.AccessHash(), this->GetHashIdentifier(),
ma.m_presignature, ma.m_presignature.size(), ma.m_presignature, ma.m_presignature.size(),
ma.m_semisignature, ma.m_semisignature.size(), ma.m_semisignature, ma.m_semisignature.size(),
recoveredMessage); recoveredMessage);
@ -1157,14 +1157,14 @@ public:
unsigned int MaxPlaintextLength(unsigned int ciphertextLength) const unsigned int MaxPlaintextLength(unsigned int ciphertextLength) const
{ {
unsigned int minLen = GetAbstractGroupParameters().GetEncodedElementSize(true); unsigned int minLen = this->GetAbstractGroupParameters().GetEncodedElementSize(true);
return ciphertextLength < minLen ? 0 : GetSymmetricEncryptionAlgorithm().GetMaxSymmetricPlaintextLength(ciphertextLength - minLen); return ciphertextLength < minLen ? 0 : GetSymmetricEncryptionAlgorithm().GetMaxSymmetricPlaintextLength(ciphertextLength - minLen);
} }
unsigned int CiphertextLength(unsigned int plaintextLength) const unsigned int CiphertextLength(unsigned int plaintextLength) const
{ {
unsigned int len = GetSymmetricEncryptionAlgorithm().GetSymmetricCiphertextLength(plaintextLength); unsigned int len = GetSymmetricEncryptionAlgorithm().GetSymmetricCiphertextLength(plaintextLength);
return len == 0 ? 0 : GetAbstractGroupParameters().GetEncodedElementSize(true) + len; return len == 0 ? 0 : this->GetAbstractGroupParameters().GetEncodedElementSize(true) + len;
} }
bool ParameterSupported(const char *name) const bool ParameterSupported(const char *name) const
@ -1187,11 +1187,11 @@ public:
{ {
try try
{ {
const DL_KeyAgreementAlgorithm<T> &agreeAlg = GetKeyAgreementAlgorithm(); const DL_KeyAgreementAlgorithm<T> &agreeAlg = this->GetKeyAgreementAlgorithm();
const DL_KeyDerivationAlgorithm<T> &derivAlg = GetKeyDerivationAlgorithm(); const DL_KeyDerivationAlgorithm<T> &derivAlg = this->GetKeyDerivationAlgorithm();
const DL_SymmetricEncryptionAlgorithm &encAlg = GetSymmetricEncryptionAlgorithm(); const DL_SymmetricEncryptionAlgorithm &encAlg = this->GetSymmetricEncryptionAlgorithm();
const DL_GroupParameters<T> &params = GetAbstractGroupParameters(); const DL_GroupParameters<T> &params = this->GetAbstractGroupParameters();
const DL_PrivateKey<T> &key = GetKeyInterface(); const DL_PrivateKey<T> &key = this->GetKeyInterface();
Element q = params.DecodeElement(ciphertext, true); Element q = params.DecodeElement(ciphertext, true);
unsigned int elementSize = params.GetEncodedElementSize(true); unsigned int elementSize = params.GetEncodedElementSize(true);
@ -1221,11 +1221,11 @@ public:
void Encrypt(RandomNumberGenerator &rng, const byte *plaintext, unsigned int plaintextLength, byte *ciphertext, const NameValuePairs &parameters = g_nullNameValuePairs) const void Encrypt(RandomNumberGenerator &rng, const byte *plaintext, unsigned int plaintextLength, byte *ciphertext, const NameValuePairs &parameters = g_nullNameValuePairs) const
{ {
const DL_KeyAgreementAlgorithm<T> &agreeAlg = GetKeyAgreementAlgorithm(); const DL_KeyAgreementAlgorithm<T> &agreeAlg = this->GetKeyAgreementAlgorithm();
const DL_KeyDerivationAlgorithm<T> &derivAlg = GetKeyDerivationAlgorithm(); const DL_KeyDerivationAlgorithm<T> &derivAlg = this->GetKeyDerivationAlgorithm();
const DL_SymmetricEncryptionAlgorithm &encAlg = GetSymmetricEncryptionAlgorithm(); const DL_SymmetricEncryptionAlgorithm &encAlg = this->GetSymmetricEncryptionAlgorithm();
const DL_GroupParameters<T> &params = GetAbstractGroupParameters(); const DL_GroupParameters<T> &params = this->GetAbstractGroupParameters();
const DL_PublicKey<T> &key = GetKeyInterface(); const DL_PublicKey<T> &key = this->GetKeyInterface();
Integer x(rng, Integer::One(), params.GetMaxExponent()); Integer x(rng, Integer::One(), params.GetMaxExponent());
Element q = params.ExponentiateBase(x); Element q = params.ExponentiateBase(x);
@ -1300,8 +1300,8 @@ protected:
// for signature scheme // for signature scheme
HashIdentifier GetHashIdentifier() const HashIdentifier GetHashIdentifier() const
{ {
typedef CPP_TYPENAME SchemeOptions::MessageEncodingMethod::HashIdentifierLookup::HashIdentifierLookup2<CPP_TYPENAME SchemeOptions::HashFunction> L; typedef typename SchemeOptions::MessageEncodingMethod::HashIdentifierLookup HashLookup;
return L::Lookup(); return HashLookup::template HashIdentifierLookup2<CPP_TYPENAME SchemeOptions::HashFunction>::Lookup();
} }
unsigned int GetDigestSize() const unsigned int GetDigestSize() const
{ {
@ -1341,7 +1341,7 @@ class CRYPTOPP_NO_VTABLE DL_PublicObjectImpl : public DL_ObjectImpl<BASE, SCHEME
{ {
public: public:
void CopyKeyInto(typename SCHEME_OPTIONS::PublicKey &key) const void CopyKeyInto(typename SCHEME_OPTIONS::PublicKey &key) const
{key = GetKey();} {key = this->GetKey();}
}; };
//! . //! .
@ -1350,9 +1350,9 @@ class CRYPTOPP_NO_VTABLE DL_PrivateObjectImpl : public DL_ObjectImpl<BASE, SCHEM
{ {
public: public:
void CopyKeyInto(typename SCHEME_OPTIONS::PublicKey &key) const void CopyKeyInto(typename SCHEME_OPTIONS::PublicKey &key) const
{GetKey().MakePublicKey(key);} {this->GetKey().MakePublicKey(key);}
void CopyKeyInto(typename SCHEME_OPTIONS::PrivateKey &key) const void CopyKeyInto(typename SCHEME_OPTIONS::PrivateKey &key) const
{key = GetKey();} {key = this->GetKey();}
}; };
//! . //! .
@ -1363,7 +1363,7 @@ public:
PK_MessageAccumulator * NewSignatureAccumulator(RandomNumberGenerator &rng) const PK_MessageAccumulator * NewSignatureAccumulator(RandomNumberGenerator &rng) const
{ {
std::auto_ptr<PK_MessageAccumulatorBase> p(new PK_MessageAccumulatorImpl<CPP_TYPENAME SCHEME_OPTIONS::HashFunction>); std::auto_ptr<PK_MessageAccumulatorBase> p(new PK_MessageAccumulatorImpl<CPP_TYPENAME SCHEME_OPTIONS::HashFunction>);
RestartMessageAccumulator(rng, *p); this->RestartMessageAccumulator(rng, *p);
return p.release(); return p.release();
} }
}; };
@ -1513,107 +1513,107 @@ public:
PK_FinalTemplate() {} PK_FinalTemplate() {}
PK_FinalTemplate(const Integer &v1) PK_FinalTemplate(const Integer &v1)
{AccessKey().Initialize(v1);} {this->AccessKey().Initialize(v1);}
PK_FinalTemplate(const typename BASE::KeyClass &key) {AccessKey().operator=(key);} PK_FinalTemplate(const typename BASE::KeyClass &key) {this->AccessKey().operator=(key);}
template <class T> template <class T>
PK_FinalTemplate(const PublicKeyCopier<T> &key) PK_FinalTemplate(const PublicKeyCopier<T> &key)
{key.CopyKeyInto(AccessKey());} {key.CopyKeyInto(this->AccessKey());}
template <class T> template <class T>
PK_FinalTemplate(const PrivateKeyCopier<T> &key) PK_FinalTemplate(const PrivateKeyCopier<T> &key)
{key.CopyKeyInto(AccessKey());} {key.CopyKeyInto(this->AccessKey());}
PK_FinalTemplate(BufferedTransformation &bt) {AccessKey().BERDecode(bt);} PK_FinalTemplate(BufferedTransformation &bt) {this->AccessKey().BERDecode(bt);}
#if (defined(_MSC_VER) && _MSC_VER < 1300) #if (defined(_MSC_VER) && _MSC_VER < 1300)
template <class T1, class T2> template <class T1, class T2>
PK_FinalTemplate(T1 &v1, T2 &v2) PK_FinalTemplate(T1 &v1, T2 &v2)
{AccessKey().Initialize(v1, v2);} {this->AccessKey().Initialize(v1, v2);}
template <class T1, class T2, class T3> template <class T1, class T2, class T3>
PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3) PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3)
{AccessKey().Initialize(v1, v2, v3);} {this->AccessKey().Initialize(v1, v2, v3);}
template <class T1, class T2, class T3, class T4> template <class T1, class T2, class T3, class T4>
PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3, T4 &v4) PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3, T4 &v4)
{AccessKey().Initialize(v1, v2, v3, v4);} {this->AccessKey().Initialize(v1, v2, v3, v4);}
template <class T1, class T2, class T3, class T4, class T5> template <class T1, class T2, class T3, class T4, class T5>
PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3, T4 &v4, T5 &v5) PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3, T4 &v4, T5 &v5)
{AccessKey().Initialize(v1, v2, v3, v4, v5);} {this->AccessKey().Initialize(v1, v2, v3, v4, v5);}
template <class T1, class T2, class T3, class T4, class T5, class T6> template <class T1, class T2, class T3, class T4, class T5, class T6>
PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3, T4 &v4, T5 &v5, T6 &v6) PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3, T4 &v4, T5 &v5, T6 &v6)
{AccessKey().Initialize(v1, v2, v3, v4, v5, v6);} {this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6);}
template <class T1, class T2, class T3, class T4, class T5, class T6, class T7> template <class T1, class T2, class T3, class T4, class T5, class T6, class T7>
PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3, T4 &v4, T5 &v5, T6 &v6, T7 &v7) PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3, T4 &v4, T5 &v5, T6 &v6, T7 &v7)
{AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7);} {this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7);}
template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8> template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3, T4 &v4, T5 &v5, T6 &v6, T7 &v7, T8 &v8) PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3, T4 &v4, T5 &v5, T6 &v6, T7 &v7, T8 &v8)
{AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7, v8);} {this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7, v8);}
#else #else
template <class T1, class T2> template <class T1, class T2>
PK_FinalTemplate(const T1 &v1, const T2 &v2) PK_FinalTemplate(const T1 &v1, const T2 &v2)
{AccessKey().Initialize(v1, v2);} {this->AccessKey().Initialize(v1, v2);}
template <class T1, class T2, class T3> template <class T1, class T2, class T3>
PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3) PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3)
{AccessKey().Initialize(v1, v2, v3);} {this->AccessKey().Initialize(v1, v2, v3);}
template <class T1, class T2, class T3, class T4> template <class T1, class T2, class T3, class T4>
PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4) PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4)
{AccessKey().Initialize(v1, v2, v3, v4);} {this->AccessKey().Initialize(v1, v2, v3, v4);}
template <class T1, class T2, class T3, class T4, class T5> template <class T1, class T2, class T3, class T4, class T5>
PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5) PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5)
{AccessKey().Initialize(v1, v2, v3, v4, v5);} {this->AccessKey().Initialize(v1, v2, v3, v4, v5);}
template <class T1, class T2, class T3, class T4, class T5, class T6> template <class T1, class T2, class T3, class T4, class T5, class T6>
PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6) PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6)
{AccessKey().Initialize(v1, v2, v3, v4, v5, v6);} {this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6);}
template <class T1, class T2, class T3, class T4, class T5, class T6, class T7> template <class T1, class T2, class T3, class T4, class T5, class T6, class T7>
PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6, const T7 &v7) PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6, const T7 &v7)
{AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7);} {this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7);}
template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8> template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6, const T7 &v7, const T8 &v8) PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6, const T7 &v7, const T8 &v8)
{AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7, v8);} {this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7, v8);}
template <class T1, class T2> template <class T1, class T2>
PK_FinalTemplate(T1 &v1, const T2 &v2) PK_FinalTemplate(T1 &v1, const T2 &v2)
{AccessKey().Initialize(v1, v2);} {this->AccessKey().Initialize(v1, v2);}
template <class T1, class T2, class T3> template <class T1, class T2, class T3>
PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3) PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3)
{AccessKey().Initialize(v1, v2, v3);} {this->AccessKey().Initialize(v1, v2, v3);}
template <class T1, class T2, class T3, class T4> template <class T1, class T2, class T3, class T4>
PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4) PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4)
{AccessKey().Initialize(v1, v2, v3, v4);} {this->AccessKey().Initialize(v1, v2, v3, v4);}
template <class T1, class T2, class T3, class T4, class T5> template <class T1, class T2, class T3, class T4, class T5>
PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5) PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5)
{AccessKey().Initialize(v1, v2, v3, v4, v5);} {this->AccessKey().Initialize(v1, v2, v3, v4, v5);}
template <class T1, class T2, class T3, class T4, class T5, class T6> template <class T1, class T2, class T3, class T4, class T5, class T6>
PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6) PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6)
{AccessKey().Initialize(v1, v2, v3, v4, v5, v6);} {this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6);}
template <class T1, class T2, class T3, class T4, class T5, class T6, class T7> template <class T1, class T2, class T3, class T4, class T5, class T6, class T7>
PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6, const T7 &v7) PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6, const T7 &v7)
{AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7);} {this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7);}
template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8> template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6, const T7 &v7, const T8 &v8) PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6, const T7 &v7, const T8 &v8)
{AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7, v8);} {this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7, v8);}
#endif #endif
}; };

3
rsa.h
View File

@ -94,9 +94,6 @@ public:
void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u) {m_u = u;} void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u) {m_u = u;}
protected: protected:
virtual void DEREncodeOptionalAttributes(BufferedTransformation &bt) const {}
virtual void BERDecodeOptionalAttributes(BufferedTransformation &bt) {}
Integer m_d, m_p, m_q, m_dp, m_dq, m_u; Integer m_d, m_p, m_q, m_dp, m_dq, m_u;
}; };

View File

@ -197,7 +197,7 @@ template <class T, class A = AllocatorWithCleanup<T> >
class SecBlock class SecBlock
{ {
public: public:
explicit SecBlock(unsigned int size=0) explicit SecBlock(unsigned int size=0)
: m_size(size) {m_ptr = m_alloc.allocate(size, NULL);} : m_size(size) {m_ptr = m_alloc.allocate(size, NULL);}
SecBlock(const SecBlock<T, A> &t) SecBlock(const SecBlock<T, A> &t)
: m_size(t.m_size) {m_ptr = m_alloc.allocate(m_size, NULL); memcpy(m_ptr, t.m_ptr, m_size*sizeof(T));} : m_size(t.m_size) {m_ptr = m_alloc.allocate(m_size, NULL); memcpy(m_ptr, t.m_ptr, m_size*sizeof(T));}
@ -214,25 +214,15 @@ public:
~SecBlock() ~SecBlock()
{m_alloc.deallocate(m_ptr, m_size);} {m_alloc.deallocate(m_ptr, m_size);}
#if defined(__GNUC__) || defined(__BCPLUSPLUS__)
operator const void *() const operator const void *() const
{return m_ptr;} {return m_ptr;}
operator void *() operator void *()
{return m_ptr;} {return m_ptr;}
#endif
#if defined(__GNUC__) // reduce warnings
operator const void *()
{return m_ptr;}
#endif
operator const T *() const operator const T *() const
{return m_ptr;} {return m_ptr;}
operator T *() operator T *()
{return m_ptr;} {return m_ptr;}
#if defined(__GNUC__) // reduce warnings
operator const T *()
{return m_ptr;}
#endif
template <typename I> template <typename I>
T *operator +(I offset) T *operator +(I offset)
@ -250,6 +240,7 @@ public:
const T& operator[](I index) const const T& operator[](I index) const
{assert(index >= 0 && (unsigned int)index < m_size); return m_ptr[index];} {assert(index >= 0 && (unsigned int)index < m_size); return m_ptr[index];}
typedef typename A::value_type value_type;
typedef typename A::pointer iterator; typedef typename A::pointer iterator;
typedef typename A::const_pointer const_iterator; typedef typename A::const_pointer const_iterator;
typedef typename A::size_type size_type; typedef typename A::size_type size_type;

View File

@ -156,7 +156,7 @@ template <class INFO, class BASE = BlockCipher>
class CRYPTOPP_NO_VTABLE BlockCipherImpl : public AlgorithmImpl<SimpleKeyingInterfaceImpl<BASE, INFO>, INFO>, public INFO class CRYPTOPP_NO_VTABLE BlockCipherImpl : public AlgorithmImpl<SimpleKeyingInterfaceImpl<BASE, INFO>, INFO>, public INFO
{ {
public: public:
unsigned int BlockSize() const {return BLOCKSIZE;} unsigned int BlockSize() const {return this->BLOCKSIZE;}
}; };
//! . //! .
@ -166,11 +166,11 @@ class BlockCipherFinal : public ClonableImpl<BlockCipherFinal<DIR, BASE>, BASE>
public: public:
BlockCipherFinal() {} BlockCipherFinal() {}
BlockCipherFinal(const byte *key) BlockCipherFinal(const byte *key)
{SetKey(key, DEFAULT_KEYLENGTH);} {SetKey(key, this->DEFAULT_KEYLENGTH);}
BlockCipherFinal(const byte *key, unsigned int length) BlockCipherFinal(const byte *key, unsigned int length)
{SetKey(key, length);} {SetKey(key, length);}
BlockCipherFinal(const byte *key, unsigned int length, unsigned int rounds) BlockCipherFinal(const byte *key, unsigned int length, unsigned int rounds)
{SetKeyWithRounds(key, length, rounds);} {this->SetKeyWithRounds(key, length, rounds);}
bool IsForwardTransformation() const {return DIR == ENCRYPTION;} bool IsForwardTransformation() const {return DIR == ENCRYPTION;}
@ -203,9 +203,9 @@ class MessageAuthenticationCodeFinal : public ClonableImpl<MessageAuthentication
public: public:
MessageAuthenticationCodeFinal() {} MessageAuthenticationCodeFinal() {}
MessageAuthenticationCodeFinal(const byte *key) MessageAuthenticationCodeFinal(const byte *key)
{SetKey(key, DEFAULT_KEYLENGTH);} {SetKey(key, this->DEFAULT_KEYLENGTH);}
MessageAuthenticationCodeFinal(const byte *key, unsigned int length) MessageAuthenticationCodeFinal(const byte *key, unsigned int length)
{SetKey(key, length);} {this->SetKey(key, length);}
}; };
// ************** documentation *************** // ************** documentation ***************

View File

@ -64,7 +64,7 @@ class CRYPTOPP_NO_VTABLE Unflushable : public T
{ {
public: public:
bool Flush(bool completeFlush, int propagation=-1, bool blocking=true) bool Flush(bool completeFlush, int propagation=-1, bool blocking=true)
{return ChannelFlush(NULL_CHANNEL, completeFlush, propagation, blocking);} {return ChannelFlush(this->NULL_CHANNEL, completeFlush, propagation, blocking);}
bool IsolatedFlush(bool hardFlush, bool blocking) bool IsolatedFlush(bool hardFlush, bool blocking)
{assert(false); return false;} {assert(false); return false;}
bool ChannelFlush(const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true) bool ChannelFlush(const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true)
@ -73,7 +73,7 @@ public:
throw CannotFlush("Unflushable<T>: this object has buffered input that cannot be flushed"); throw CannotFlush("Unflushable<T>: this object has buffered input that cannot be flushed");
else else
{ {
BufferedTransformation *attached = AttachedTransformation(); BufferedTransformation *attached = this->AttachedTransformation();
return attached && propagation ? attached->ChannelFlush(channel, hardFlush, propagation-1, blocking) : false; return attached && propagation ? attached->ChannelFlush(channel, hardFlush, propagation-1, blocking) : false;
} }
} }
@ -125,22 +125,22 @@ class CRYPTOPP_NO_VTABLE Multichannel : public CustomFlushPropagation<T>
{ {
public: public:
bool Flush(bool hardFlush, int propagation=-1, bool blocking=true) bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)
{return ChannelFlush(NULL_CHANNEL, hardFlush, propagation, blocking);} {return ChannelFlush(this->NULL_CHANNEL, hardFlush, propagation, blocking);}
bool MessageSeriesEnd(int propagation=-1, bool blocking=true) bool MessageSeriesEnd(int propagation=-1, bool blocking=true)
{return ChannelMessageSeriesEnd(NULL_CHANNEL, propagation, blocking);} {return ChannelMessageSeriesEnd(this->NULL_CHANNEL, propagation, blocking);}
byte * CreatePutSpace(unsigned int &size) byte * CreatePutSpace(unsigned int &size)
{return ChannelCreatePutSpace(NULL_CHANNEL, size);} {return ChannelCreatePutSpace(this->NULL_CHANNEL, size);}
unsigned int Put2(const byte *begin, unsigned int length, int messageEnd, bool blocking) unsigned int Put2(const byte *begin, unsigned int length, int messageEnd, bool blocking)
{return ChannelPut2(NULL_CHANNEL, begin, length, messageEnd, blocking);} {return ChannelPut2(this->NULL_CHANNEL, begin, length, messageEnd, blocking);}
unsigned int PutModifiable2(byte *inString, unsigned int length, int messageEnd, bool blocking) unsigned int PutModifiable2(byte *inString, unsigned int length, int messageEnd, bool blocking)
{return ChannelPutModifiable2(NULL_CHANNEL, inString, length, messageEnd, blocking);} {return ChannelPutModifiable2(this->NULL_CHANNEL, inString, length, messageEnd, blocking);}
// void ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1) // void ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1)
// {PropagateMessageSeriesEnd(propagation, channel);} // {PropagateMessageSeriesEnd(propagation, channel);}
byte * ChannelCreatePutSpace(const std::string &channel, unsigned int &size) byte * ChannelCreatePutSpace(const std::string &channel, unsigned int &size)
{size = 0; return NULL;} {size = 0; return NULL;}
bool ChannelPutModifiable(const std::string &channel, byte *inString, unsigned int length) bool ChannelPutModifiable(const std::string &channel, byte *inString, unsigned int length)
{ChannelPut(channel, inString, length); return false;} {this->ChannelPut(channel, inString, length); return false;}
virtual unsigned int ChannelPut2(const std::string &channel, const byte *begin, unsigned int length, int messageEnd, bool blocking) =0; virtual unsigned int ChannelPut2(const std::string &channel, const byte *begin, unsigned int length, int messageEnd, bool blocking) =0;
unsigned int ChannelPutModifiable2(const std::string &channel, byte *begin, unsigned int length, int messageEnd, bool blocking) unsigned int ChannelPutModifiable2(const std::string &channel, byte *begin, unsigned int length, int messageEnd, bool blocking)

View File

@ -6,7 +6,7 @@
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)
template<class T> class simple_ptr template <class T> class simple_ptr
{ {
public: public:
simple_ptr() : m_p(NULL) {} simple_ptr() : m_p(NULL) {}
@ -14,7 +14,7 @@ public:
T *m_p; T *m_p;
}; };
template<class T> class member_ptr template <class T> class member_ptr
{ {
public: public:
explicit member_ptr(T *p = NULL) : m_p(p) {} explicit member_ptr(T *p = NULL) : m_p(p) {}
@ -62,14 +62,14 @@ public:
value_ptr<T>& operator=(const value_ptr<T>& rhs); value_ptr<T>& operator=(const value_ptr<T>& rhs);
bool operator==(const value_ptr<T>& rhs) bool operator==(const value_ptr<T>& rhs)
{ {
return (!m_p && !rhs.m_p) || (m_p && rhs.m_p && *m_p == *rhs.m_p); return (!this->m_p && !rhs.m_p) || (this->m_p && rhs.m_p && *this->m_p == *rhs.m_p);
} }
}; };
template <class T> value_ptr<T>& value_ptr<T>::operator=(const value_ptr<T>& rhs) template <class T> value_ptr<T>& value_ptr<T>::operator=(const value_ptr<T>& rhs)
{ {
T *old_p = m_p; T *old_p = this->m_p;
m_p = rhs.m_p ? new T(*rhs.m_p) : NULL; this->m_p = rhs.m_p ? new T(*rhs.m_p) : NULL;
delete old_p; delete old_p;
return *this; return *this;
} }
@ -89,8 +89,8 @@ public:
template <class T> clonable_ptr<T>& clonable_ptr<T>::operator=(const clonable_ptr<T>& rhs) template <class T> clonable_ptr<T>& clonable_ptr<T>::operator=(const clonable_ptr<T>& rhs)
{ {
T *old_p = m_p; T *old_p = this->m_p;
m_p = rhs.m_p ? rhs.m_p->Clone() : NULL; this->m_p = rhs.m_p ? rhs.m_p->Clone() : NULL;
delete old_p; delete old_p;
return *this; return *this;
} }
@ -190,32 +190,32 @@ template <class T> class vector_member_ptrs
{ {
public: public:
vector_member_ptrs(unsigned int size=0) vector_member_ptrs(unsigned int size=0)
: _size(size) {ptr = new member_ptr<T>[_size];} : m_size(size), m_ptr(new member_ptr<T>[size]) {}
~vector_member_ptrs() ~vector_member_ptrs()
{delete [] ptr;} {delete [] this->m_ptr;}
member_ptr<T>& operator[](unsigned int index) member_ptr<T>& operator[](unsigned int index)
{assert(index<_size); return ptr[index];} {assert(index<this->m_size); return this->m_ptr[index];}
const member_ptr<T>& operator[](unsigned int index) const const member_ptr<T>& operator[](unsigned int index) const
{assert(index<_size); return ptr[index];} {assert(index<this->m_size); return this->m_ptr[index];}
unsigned int size() const {return _size;} unsigned int size() const {return this->m_size;}
void resize(unsigned int newSize) void resize(unsigned int newSize)
{ {
member_ptr<T> *newPtr = new member_ptr<T>[newSize]; member_ptr<T> *newPtr = new member_ptr<T>[newSize];
for (unsigned int i=0; i<STDMIN(_size, newSize); i++) for (unsigned int i=0; i<this->m_size && i<newSize; i++)
newPtr[i].reset(ptr[i].release()); newPtr[i].reset(this->m_ptr[i].release());
delete [] ptr; delete [] this->m_ptr;
_size = newSize; this->m_size = newSize;
ptr = newPtr; this->m_ptr = newPtr;
} }
private: private:
vector_member_ptrs(const vector_member_ptrs<T> &c); // copy not allowed vector_member_ptrs(const vector_member_ptrs<T> &c); // copy not allowed
void operator=(const vector_member_ptrs<T> &x); // assignment not allowed void operator=(const vector_member_ptrs<T> &x); // assignment not allowed
unsigned int _size; unsigned int m_size;
member_ptr<T> *ptr; member_ptr<T> *m_ptr;
}; };
NAMESPACE_END NAMESPACE_END

View File

@ -11,7 +11,7 @@ NAMESPACE_BEGIN(CryptoPP)
template <class S> template <class S>
byte AdditiveCipherTemplate<S>::GenerateByte() byte AdditiveCipherTemplate<S>::GenerateByte()
{ {
PolicyInterface &policy = AccessPolicy(); PolicyInterface &policy = this->AccessPolicy();
if (m_leftOver == 0) if (m_leftOver == 0)
{ {
@ -40,7 +40,7 @@ inline void AdditiveCipherTemplate<S>::ProcessData(byte *outString, const byte *
assert(m_leftOver == 0); assert(m_leftOver == 0);
PolicyInterface &policy = AccessPolicy(); PolicyInterface &policy = this->AccessPolicy();
unsigned int bytesPerIteration = policy.GetBytesPerIteration(); unsigned int bytesPerIteration = policy.GetBytesPerIteration();
unsigned int alignment = policy.GetAlignment(); unsigned int alignment = policy.GetAlignment();
@ -84,7 +84,7 @@ inline void AdditiveCipherTemplate<S>::ProcessData(byte *outString, const byte *
template <class S> template <class S>
void AdditiveCipherTemplate<S>::Resynchronize(const byte *iv) void AdditiveCipherTemplate<S>::Resynchronize(const byte *iv)
{ {
PolicyInterface &policy = AccessPolicy(); PolicyInterface &policy = this->AccessPolicy();
m_leftOver = 0; m_leftOver = 0;
m_buffer.New(GetBufferByteSize(policy)); m_buffer.New(GetBufferByteSize(policy));
policy.CipherResynchronize(m_buffer, iv); policy.CipherResynchronize(m_buffer, iv);
@ -93,7 +93,7 @@ void AdditiveCipherTemplate<S>::Resynchronize(const byte *iv)
template <class BASE> template <class BASE>
void AdditiveCipherTemplate<BASE>::Seek(lword position) void AdditiveCipherTemplate<BASE>::Seek(lword position)
{ {
PolicyInterface &policy = AccessPolicy(); PolicyInterface &policy = this->AccessPolicy();
unsigned int bytesPerIteration = policy.GetBytesPerIteration(); unsigned int bytesPerIteration = policy.GetBytesPerIteration();
policy.SeekToIteration(position / bytesPerIteration); policy.SeekToIteration(position / bytesPerIteration);
@ -111,7 +111,7 @@ void AdditiveCipherTemplate<BASE>::Seek(lword position)
template <class BASE> template <class BASE>
void CFB_CipherTemplate<BASE>::Resynchronize(const byte *iv) void CFB_CipherTemplate<BASE>::Resynchronize(const byte *iv)
{ {
PolicyInterface &policy = AccessPolicy(); PolicyInterface &policy = this->AccessPolicy();
policy.CipherResynchronize(iv); policy.CipherResynchronize(iv);
m_leftOver = policy.GetBytesPerIteration(); m_leftOver = policy.GetBytesPerIteration();
} }
@ -119,9 +119,9 @@ void CFB_CipherTemplate<BASE>::Resynchronize(const byte *iv)
template <class BASE> template <class BASE>
void CFB_CipherTemplate<BASE>::ProcessData(byte *outString, const byte *inString, unsigned int length) void CFB_CipherTemplate<BASE>::ProcessData(byte *outString, const byte *inString, unsigned int length)
{ {
assert(length % MandatoryBlockSize() == 0); assert(length % this->MandatoryBlockSize() == 0);
PolicyInterface &policy = AccessPolicy(); PolicyInterface &policy = this->AccessPolicy();
unsigned int bytesPerIteration = policy.GetBytesPerIteration(); unsigned int bytesPerIteration = policy.GetBytesPerIteration();
unsigned int alignment = policy.GetAlignment(); unsigned int alignment = policy.GetAlignment();
byte *reg = policy.GetRegisterBegin(); byte *reg = policy.GetRegisterBegin();

View File

@ -124,12 +124,12 @@ public:
byte GenerateByte(); byte GenerateByte();
void ProcessData(byte *outString, const byte *inString, unsigned int length); void ProcessData(byte *outString, const byte *inString, unsigned int length);
void Resynchronize(const byte *iv); void Resynchronize(const byte *iv);
unsigned int OptimalBlockSize() const {return GetPolicy().GetBytesPerIteration();} unsigned int OptimalBlockSize() const {return this->GetPolicy().GetBytesPerIteration();}
unsigned int GetOptimalNextBlockSize() const {return m_leftOver;} unsigned int GetOptimalNextBlockSize() const {return this->m_leftOver;}
unsigned int OptimalDataAlignment() const {return GetPolicy().GetAlignment();} unsigned int OptimalDataAlignment() const {return this->GetPolicy().GetAlignment();}
bool IsSelfInverting() const {return true;} bool IsSelfInverting() const {return true;}
bool IsForwardTransformation() const {return true;} bool IsForwardTransformation() const {return true;}
bool IsRandomAccess() const {return GetPolicy().IsRandomAccess();} bool IsRandomAccess() const {return this->GetPolicy().IsRandomAccess();}
void Seek(lword position); void Seek(lword position);
typedef typename BASE::PolicyInterface PolicyInterface; typedef typename BASE::PolicyInterface PolicyInterface;
@ -139,8 +139,8 @@ protected:
unsigned int GetBufferByteSize(const PolicyInterface &policy) const {return policy.GetBytesPerIteration() * policy.GetIterationsToBuffer();} unsigned int GetBufferByteSize(const PolicyInterface &policy) const {return policy.GetBytesPerIteration() * policy.GetIterationsToBuffer();}
inline byte * KeystreamBufferBegin() {return m_buffer.data();} inline byte * KeystreamBufferBegin() {return this->m_buffer.data();}
inline byte * KeystreamBufferEnd() {return (m_buffer.data() + m_buffer.size());} inline byte * KeystreamBufferEnd() {return (this->m_buffer.data() + this->m_buffer.size());}
SecByteBlock m_buffer; SecByteBlock m_buffer;
unsigned int m_leftOver; unsigned int m_leftOver;
@ -171,7 +171,7 @@ struct CRYPTOPP_NO_VTABLE CFB_CipherConcretePolicy : public BASE
unsigned int GetAlignment() const {return sizeof(WordType);} unsigned int GetAlignment() const {return sizeof(WordType);}
unsigned int GetBytesPerIteration() const {return sizeof(WordType) * W;} unsigned int GetBytesPerIteration() const {return sizeof(WordType) * W;}
bool CanIterate() const {return true;} bool CanIterate() const {return true;}
void TransformRegister() {Iterate(NULL, NULL, ENCRYPTION, 1);} void TransformRegister() {this->Iterate(NULL, NULL, ENCRYPTION, 1);}
template <class B> template <class B>
struct RegisterOutput struct RegisterOutput
@ -221,9 +221,9 @@ class CRYPTOPP_NO_VTABLE CFB_CipherTemplate : public BASE
public: public:
void ProcessData(byte *outString, const byte *inString, unsigned int length); void ProcessData(byte *outString, const byte *inString, unsigned int length);
void Resynchronize(const byte *iv); void Resynchronize(const byte *iv);
unsigned int OptimalBlockSize() const {return GetPolicy().GetBytesPerIteration();} unsigned int OptimalBlockSize() const {return this->GetPolicy().GetBytesPerIteration();}
unsigned int GetOptimalNextBlockSize() const {return m_leftOver;} unsigned int GetOptimalNextBlockSize() const {return m_leftOver;}
unsigned int OptimalDataAlignment() const {return GetPolicy().GetAlignment();} unsigned int OptimalDataAlignment() const {return this->GetPolicy().GetAlignment();}
bool IsRandomAccess() const {return false;} bool IsRandomAccess() const {return false;}
bool IsSelfInverting() const {return false;} bool IsSelfInverting() const {return false;}
@ -255,7 +255,7 @@ template <class BASE>
class CFB_RequireFullDataBlocks : public BASE class CFB_RequireFullDataBlocks : public BASE
{ {
public: public:
unsigned int MandatoryBlockSize() const {return OptimalBlockSize();} unsigned int MandatoryBlockSize() const {return this->OptimalBlockSize();}
}; };
/* /*
@ -271,16 +271,16 @@ class SymmetricCipherFinal : public AlgorithmImpl<SimpleKeyingInterfaceImpl<BASE
public: public:
SymmetricCipherFinal() {} SymmetricCipherFinal() {}
SymmetricCipherFinal(const byte *key) SymmetricCipherFinal(const byte *key)
{SetKey(key, DEFAULT_KEYLENGTH);} {SetKey(key, this->DEFAULT_KEYLENGTH);}
SymmetricCipherFinal(const byte *key, unsigned int length) SymmetricCipherFinal(const byte *key, unsigned int length)
{SetKey(key, length);} {SetKey(key, length);}
SymmetricCipherFinal(const byte *key, unsigned int length, const byte *iv) SymmetricCipherFinal(const byte *key, unsigned int length, const byte *iv)
{SetKeyWithIV(key, length, iv);} {this->SetKeyWithIV(key, length, iv);}
void SetKey(const byte *key, unsigned int length, const NameValuePairs &params = g_nullNameValuePairs) void SetKey(const byte *key, unsigned int length, const NameValuePairs &params = g_nullNameValuePairs)
{ {
ThrowIfInvalidKeyLength(length); this->ThrowIfInvalidKeyLength(length);
UncheckedSetKey(params, key, length, GetIVAndThrowIfInvalid(params)); this->UncheckedSetKey(params, key, length, this->GetIVAndThrowIfInvalid(params));
} }
Clonable * Clone() const {return static_cast<SymmetricCipher *>(new SymmetricCipherFinal<BASE, INFO>(*this));} Clonable * Clone() const {return static_cast<SymmetricCipher *>(new SymmetricCipherFinal<BASE, INFO>(*this));}
@ -289,22 +289,22 @@ public:
template <class S> template <class S>
void AdditiveCipherTemplate<S>::UncheckedSetKey(const NameValuePairs &params, const byte *key, unsigned int length, const byte *iv) void AdditiveCipherTemplate<S>::UncheckedSetKey(const NameValuePairs &params, const byte *key, unsigned int length, const byte *iv)
{ {
PolicyInterface &policy = AccessPolicy(); PolicyInterface &policy = this->AccessPolicy();
policy.CipherSetKey(params, key, length); policy.CipherSetKey(params, key, length);
m_leftOver = 0; m_leftOver = 0;
m_buffer.New(GetBufferByteSize(policy)); m_buffer.New(GetBufferByteSize(policy));
if (IsResynchronizable()) if (this->IsResynchronizable())
policy.CipherResynchronize(m_buffer, iv); policy.CipherResynchronize(m_buffer, iv);
} }
template <class BASE> template <class BASE>
void CFB_CipherTemplate<BASE>::UncheckedSetKey(const NameValuePairs &params, const byte *key, unsigned int length, const byte *iv) void CFB_CipherTemplate<BASE>::UncheckedSetKey(const NameValuePairs &params, const byte *key, unsigned int length, const byte *iv)
{ {
PolicyInterface &policy = AccessPolicy(); PolicyInterface &policy = this->AccessPolicy();
policy.CipherSetKey(params, key, length); policy.CipherSetKey(params, key, length);
if (IsResynchronizable()) if (this->IsResynchronizable())
policy.CipherResynchronize(iv); policy.CipherResynchronize(iv);
m_leftOver = policy.GetBytesPerIteration(); m_leftOver = policy.GetBytesPerIteration();

2
tea.h
View File

@ -99,7 +99,7 @@ class BTEA : public BTEA_Info, public BlockCipherDocumentation
{ {
obj->ThrowIfInvalidKeyLength(length); obj->ThrowIfInvalidKeyLength(length);
obj->m_blockSize = param.GetIntValueWithDefault("BlockSize", 60*4); obj->m_blockSize = param.GetIntValueWithDefault("BlockSize", 60*4);
GetUserKey(BIG_ENDIAN_ORDER, obj->m_k.begin(), 4, userKey, KEYLENGTH); GetUserKey(BIG_ENDIAN_ORDER, obj->m_k.begin(), 4, key, KEYLENGTH);
} }
unsigned int BlockSize() const {return m_blockSize;} unsigned int BlockSize() const {return m_blockSize;}

View File

@ -6,6 +6,7 @@
#include "seckey.h" #include "seckey.h"
#include "iterhash.h" #include "iterhash.h"
#include "argnames.h" #include "argnames.h"
#include "algparam.h"
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)
@ -26,7 +27,7 @@ public:
void Resynchronize(const byte *IV) void Resynchronize(const byte *IV)
{ {
GetWord(false, BIG_ENDIAN_ORDER, m_counter, IV); GetWord(false, BIG_ENDIAN_ORDER, m_counter, IV);
Restart(); this->Restart();
} }
unsigned int IVSize() const unsigned int IVSize() const
{return 4;} {return 4;}
@ -66,26 +67,26 @@ class XMACC : public ClonableImpl<XMACC<T>, MessageAuthenticationCodeImpl<XMACC_
public: public:
XMACC() {} XMACC() {}
XMACC(const byte *key, word32 counter = 0xffffffff) XMACC(const byte *key, word32 counter = 0xffffffff)
{SetKey(key, KEYLENGTH, MakeParameters(Name::XMACC_Counter(), counter));} {this->SetKey(key, this->KEYLENGTH, MakeParameters(Name::XMACC_Counter(), counter));}
}; };
template <class T> void XMACC_Base<T>::CheckedSetKey(void *, Empty empty, const byte *key, unsigned int length, const NameValuePairs &params) template <class T> void XMACC_Base<T>::CheckedSetKey(void *, Empty empty, const byte *key, unsigned int length, const NameValuePairs &params)
{ {
ThrowIfInvalidKeyLength(length); this->ThrowIfInvalidKeyLength(length);
m_counter = 0xffffffff; m_counter = 0xffffffff;
const byte *iv = NULL; const byte *iv = NULL;
if (params.GetValue(Name::IV(), iv)) if (params.GetValue(Name::IV(), iv))
GetWord(false, BIG_ENDIAN_ORDER, m_counter, iv); GetWord(false, BIG_ENDIAN_ORDER, m_counter, iv);
else else
params.GetValue(Name::XMACC_Counter(), m_counter); params.GetValue(Name::XMACC_Counter(), m_counter);
memcpy(m_key, key, KEYLENGTH); memcpy(m_key, key, this->KEYLENGTH);
Init(); Init();
} }
template <class T> void XMACC_Base<T>::Init() template <class T> void XMACC_Base<T>::Init()
{ {
m_index = 0x80000000; m_index = 0x80000000;
memset(m_digest, 0, T::DIGESTSIZE); memset(this->m_digest, 0, T::DIGESTSIZE);
} }
template <class T> inline void XMACC_Base<T>::WriteWord32(byte *output, word32 value) template <class T> inline void XMACC_Base<T>::WriteWord32(byte *output, word32 value)
@ -104,65 +105,65 @@ template <class T> inline void XMACC_Base<T>::XorDigest(HashWordType *digest, co
template <class T> void XMACC_Base<T>::HashEndianCorrectedBlock(const HashWordType *input) template <class T> void XMACC_Base<T>::HashEndianCorrectedBlock(const HashWordType *input)
{ {
memcpy(m_buffer, m_key, KEYLENGTH); memcpy(m_buffer, m_key, this->KEYLENGTH);
WriteWord32((byte *)m_buffer.begin()+KEYLENGTH, ++m_index); WriteWord32((byte *)m_buffer.begin()+this->KEYLENGTH, ++m_index);
T::CorrectEndianess(m_buffer, m_buffer, T::DIGESTSIZE); T::CorrectEndianess(m_buffer, m_buffer, T::DIGESTSIZE);
T::Transform(m_buffer, input); T::Transform(m_buffer, input);
XorDigest(m_digest, m_buffer); XorDigest(this->m_digest, m_buffer);
} }
template <class T> void XMACC_Base<T>::TruncatedFinal(byte *mac, unsigned int size) template <class T> void XMACC_Base<T>::TruncatedFinal(byte *mac, unsigned int size)
{ {
ThrowIfInvalidTruncatedSize(size); this->ThrowIfInvalidTruncatedSize(size);
if (size < 4) if (size < 4)
throw InvalidArgument("XMACC: truncating the MAC to less than 4 bytes will cause it to be unverifiable"); throw InvalidArgument("XMACC: truncating the MAC to less than 4 bytes will cause it to be unverifiable");
if (m_counter == 0xffffffff) if (m_counter == 0xffffffff)
throw InvalidArgument("XMACC: the counter must be initialized to a valid value for MAC generation"); throw InvalidArgument("XMACC: the counter must be initialized to a valid value for MAC generation");
PadLastBlock(BLOCKSIZE - 2*sizeof(HashWordType)); PadLastBlock(this->BLOCKSIZE - 2*sizeof(HashWordType));
CorrectEndianess(m_data, m_data, BLOCKSIZE - 2*sizeof(HashWordType)); CorrectEndianess(this->m_data, this->m_data, this->BLOCKSIZE - 2*sizeof(HashWordType));
m_data[m_data.size()-2] = ByteReverse(GetBitCountHi()); // byteReverse for backwards compatibility this->m_data[this->m_data.size()-2] = ByteReverse(this->GetBitCountHi()); // ByteReverse for backwards compatibility
m_data[m_data.size()-1] = ByteReverse(GetBitCountLo()); this->m_data[this->m_data.size()-1] = ByteReverse(this->GetBitCountLo());
HashEndianCorrectedBlock(m_data); HashEndianCorrectedBlock(this->m_data);
memcpy(m_buffer, m_key, KEYLENGTH); memcpy(m_buffer, m_key, this->KEYLENGTH);
WriteWord32((byte *)m_buffer.begin()+KEYLENGTH, 0); WriteWord32((byte *)m_buffer.begin()+this->KEYLENGTH, 0);
memset(m_data, 0, BLOCKSIZE-4); memset(this->m_data, 0, this->BLOCKSIZE-4);
WriteWord32((byte *)m_data.begin()+BLOCKSIZE-4, ++m_counter); WriteWord32((byte *)this->m_data.begin()+this->BLOCKSIZE-4, ++m_counter);
T::CorrectEndianess(m_buffer, m_buffer, T::DIGESTSIZE); T::CorrectEndianess(m_buffer, m_buffer, T::DIGESTSIZE);
T::CorrectEndianess(m_data, m_data, BLOCKSIZE); T::CorrectEndianess(this->m_data, this->m_data, this->BLOCKSIZE);
T::Transform(m_buffer, m_data); T::Transform(m_buffer, this->m_data);
XorDigest(m_digest, m_buffer); XorDigest(this->m_digest, m_buffer);
WriteWord32(mac, m_counter); WriteWord32(mac, m_counter);
T::CorrectEndianess(m_digest, m_digest, T::DIGESTSIZE); T::CorrectEndianess(this->m_digest, this->m_digest, T::DIGESTSIZE);
memcpy(mac+4, m_digest, size-4); memcpy(mac+4, this->m_digest, size-4);
Restart(); // reinit for next use this->Restart(); // reinit for next use
} }
template <class T> bool XMACC_Base<T>::TruncatedVerify(const byte *mac, unsigned int size) template <class T> bool XMACC_Base<T>::TruncatedVerify(const byte *mac, unsigned int size)
{ {
assert(4 <= size && size <= DIGESTSIZE); assert(4 <= size && size <= DIGESTSIZE);
PadLastBlock(BLOCKSIZE - 2*sizeof(HashWordType)); PadLastBlock(this->BLOCKSIZE - 2*sizeof(HashWordType));
CorrectEndianess(m_data, m_data, BLOCKSIZE - 2*sizeof(HashWordType)); CorrectEndianess(this->m_data, this->m_data, this->BLOCKSIZE - 2*sizeof(HashWordType));
m_data[m_data.size()-2] = ByteReverse(GetBitCountHi()); // byteReverse for backwards compatibility this->m_data[this->m_data.size()-2] = ByteReverse(this->GetBitCountHi()); // ByteReverse for backwards compatibility
m_data[m_data.size()-1] = ByteReverse(GetBitCountLo()); this->m_data[this->m_data.size()-1] = ByteReverse(this->GetBitCountLo());
HashEndianCorrectedBlock(m_data); HashEndianCorrectedBlock(this->m_data);
memcpy(m_buffer, m_key, KEYLENGTH); memcpy(m_buffer, m_key, this->KEYLENGTH);
WriteWord32((byte *)m_buffer.begin()+KEYLENGTH, 0); WriteWord32((byte *)m_buffer.begin()+this->KEYLENGTH, 0);
memset(m_data, 0, BLOCKSIZE-4); memset(this->m_data, 0, this->BLOCKSIZE-4);
memcpy((byte *)m_data.begin()+BLOCKSIZE-4, mac, 4); memcpy((byte *)this->m_data.begin()+this->BLOCKSIZE-4, mac, 4);
T::CorrectEndianess(m_buffer, m_buffer, T::DIGESTSIZE); T::CorrectEndianess(m_buffer, m_buffer, T::DIGESTSIZE);
T::CorrectEndianess(m_data, m_data, BLOCKSIZE); T::CorrectEndianess(this->m_data, this->m_data, this->BLOCKSIZE);
T::Transform(m_buffer, m_data); T::Transform(m_buffer, this->m_data);
XorDigest(m_digest, m_buffer); XorDigest(this->m_digest, m_buffer);
T::CorrectEndianess(m_digest, m_digest, T::DIGESTSIZE); T::CorrectEndianess(this->m_digest, this->m_digest, T::DIGESTSIZE);
bool macValid = (memcmp(mac+4, m_digest, size-4) == 0); bool macValid = (memcmp(mac+4, this->m_digest, size-4) == 0);
Restart(); // reinit for next use this->Restart(); // reinit for next use
return macValid; return macValid;
} }