Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 49449
Collapse All | Expand All

(-)crypto++-5.1/algebra.cpp (-1 / +1 lines)
Lines 54-60 Link Here
54
	Element g[3]={b, a};
54
	Element g[3]={b, a};
55
	unsigned int i0=0, i1=1, i2=2;
55
	unsigned int i0=0, i1=1, i2=2;
56
56
57
	while (!Equal(g[i1], Identity()))
57
	while (!Equal(g[i1], this->Identity()))
58
	{
58
	{
59
		g[i2] = Mod(g[i0], g[i1]);
59
		g[i2] = Mod(g[i0], g[i1]);
60
		unsigned int t = i0; i0 = i1; i1 = i2; i2 = t;
60
		unsigned int t = i0; i0 = i1; i1 = i2; i2 = t;
(-)crypto++-5.1/asn.h (-2 / +2 lines)
Lines 221-228 Link Here
221
	}
221
	}
222
	void DEREncode(BufferedTransformation &out)
222
	void DEREncode(BufferedTransformation &out)
223
	{
223
	{
224
		if (get() != NULL)
224
		if (this->get() != NULL)
225
			get()->DEREncode(out);
225
			this->get()->DEREncode(out);
226
	}
226
	}
227
};
227
};
228
228
(-)crypto++-5.1/blowfish.cpp (-1 / +1 lines)
Lines 30-36 Link Here
30
	for (i=0; i<ROUNDS; i+=2)
30
	for (i=0; i<ROUNDS; i+=2)
31
		crypt_block(pbox+i, pbox+i+2);
31
		crypt_block(pbox+i, pbox+i+2);
32
32
33
	crypt_block(pbox+ROUNDS, sbox);
33
	crypt_block((word32*)pbox+ROUNDS, sbox);
34
34
35
	for (i=0; i<4*256-2; i+=2)
35
	for (i=0; i<4*256-2; i+=2)
36
		crypt_block(sbox+i, sbox+i+2);
36
		crypt_block(sbox+i, sbox+i+2);
(-)crypto++-5.1/cbcmac.h (-1 / +1 lines)
Lines 37-43 Link Here
37
public:
37
public:
38
	CBC_MAC() {}
38
	CBC_MAC() {}
39
	CBC_MAC(const byte *key, unsigned int length=CBC_MAC_Base<T>::DEFAULT_KEYLENGTH)
39
	CBC_MAC(const byte *key, unsigned int length=CBC_MAC_Base<T>::DEFAULT_KEYLENGTH)
40
		{SetKey(key, length);}
40
		{this->SetKey(key, length);}
41
};
41
};
42
42
43
template <class T>
43
template <class T>
(-)crypto++-5.1/dh.h (-7 / +7 lines)
Lines 61-78 Link Here
61
61
62
		if (FIPS_140_2_ComplianceEnabled())
62
		if (FIPS_140_2_ComplianceEnabled())
63
		{
63
		{
64
			SecByteBlock privateKey2(PrivateKeyLength());
64
			SecByteBlock privateKey2(this->PrivateKeyLength());
65
			GeneratePrivateKey(rng, privateKey2);
65
			this->GeneratePrivateKey(rng, privateKey2);
66
66
67
			SecByteBlock publicKey2(PublicKeyLength());
67
			SecByteBlock publicKey2(this->PublicKeyLength());
68
			Base::GeneratePublicKey(rng, privateKey2, publicKey2);
68
			Base::GeneratePublicKey(rng, privateKey2, publicKey2);
69
69
70
			SecByteBlock agreedValue(AgreedValueLength()), agreedValue2(AgreedValueLength());
70
			SecByteBlock agreedValue(this->AgreedValueLength()), agreedValue2(this->AgreedValueLength());
71
			Agree(agreedValue, privateKey, publicKey2);
71
			this->Agree(agreedValue, privateKey, publicKey2);
72
			Agree(agreedValue2, privateKey2, publicKey);
72
			this->Agree(agreedValue2, privateKey2, publicKey);
73
73
74
			if (agreedValue != agreedValue2)
74
			if (agreedValue != agreedValue2)
75
				throw SelfTestFailure(AlgorithmName() + ": pairwise consistency test failed");
75
				throw SelfTestFailure(this->AlgorithmName() + ": pairwise consistency test failed");
76
		}
76
		}
77
	}
77
	}
78
78
(-)crypto++-5.1/dmac.h (-1 / +1 lines)
Lines 40-46 Link Here
40
public:
40
public:
41
	DMAC() {}
41
	DMAC() {}
42
	DMAC(const byte *key, unsigned int length=DMAC_Base<T>::DEFAULT_KEYLENGTH)
42
	DMAC(const byte *key, unsigned int length=DMAC_Base<T>::DEFAULT_KEYLENGTH)
43
		{SetKey(key, length);}
43
		{this->SetKey(key, length);}
44
};
44
};
45
45
46
template <class T>
46
template <class T>
(-)crypto++-5.1/dsa.cpp (-1 / +1 lines)
Lines 98-104 Link Here
98
		if (!useInputCounterValue || c == counter)
98
		if (!useInputCounterValue || c == counter)
99
		{
99
		{
100
			W[SHA::DIGESTSIZE - 1 - b/8] |= 0x80;
100
			W[SHA::DIGESTSIZE - 1 - b/8] |= 0x80;
101
			X.Decode(W + SHA::DIGESTSIZE - 1 - b/8, L/8);
101
			X.Decode((byte*)W + SHA::DIGESTSIZE - 1 - b/8, L/8);
102
			p = X-((X % (2*q))-1);
102
			p = X-((X % (2*q))-1);
103
103
104
			if (p.GetBit(L-1) && IsPrime(p))
104
			if (p.GetBit(L-1) && IsPrime(p))
(-)crypto++-5.1/eccrypto.cpp (-11 / +11 lines)
Lines 369-375 Link Here
369
	const EcRecommendedParameters<EllipticCurve> &param = *it;
369
	const EcRecommendedParameters<EllipticCurve> &param = *it;
370
	m_oid = oid;
370
	m_oid = oid;
371
	std::auto_ptr<EllipticCurve> ec(param.NewEC());
371
	std::auto_ptr<EllipticCurve> ec(param.NewEC());
372
	m_groupPrecomputation.SetCurve(*ec);
372
	this->m_groupPrecomputation.SetCurve(*ec);
373
373
374
	StringSource ssG(param.g, true, new HexDecoder);
374
	StringSource ssG(param.g, true, new HexDecoder);
375
	Element G;
375
	Element G;
Lines 390-396 Link Here
390
		if (m_oid.m_values.empty())
390
		if (m_oid.m_values.empty())
391
			return false;
391
			return false;
392
392
393
		ThrowIfTypeMismatch(name, typeid(OID), valueType);
393
		this->ThrowIfTypeMismatch(name, typeid(OID), valueType);
394
		*reinterpret_cast<OID *>(pValue) = m_oid;
394
		*reinterpret_cast<OID *>(pValue) = m_oid;
395
		return true;
395
		return true;
396
	}
396
	}
Lines 471-477 Link Here
471
		DERSequenceEncoder seq(bt);
471
		DERSequenceEncoder seq(bt);
472
		DEREncodeUnsigned<word32>(seq, 1);	// version
472
		DEREncodeUnsigned<word32>(seq, 1);	// version
473
		GetCurve().DEREncode(seq);
473
		GetCurve().DEREncode(seq);
474
		GetCurve().DEREncodePoint(seq, GetSubgroupGenerator(), m_compress);
474
		GetCurve().DEREncodePoint(seq, this->GetSubgroupGenerator(), m_compress);
475
		m_n.DEREncode(seq);
475
		m_n.DEREncode(seq);
476
		if (m_k.NotZero())
476
		if (m_k.NotZero())
477
			m_k.DEREncode(seq);
477
			m_k.DEREncode(seq);
Lines 525-536 Link Here
525
	if (level >= 1)
525
	if (level >= 1)
526
	{
526
	{
527
		if (gpc)
527
		if (gpc)
528
			pass = pass && gpc->Exponentiate(GetGroupPrecomputation(), Integer::One()) == g;
528
			pass = pass && gpc->Exponentiate(this->GetGroupPrecomputation(), Integer::One()) == g;
529
	}
529
	}
530
	if (level >= 2)
530
	if (level >= 2)
531
	{
531
	{
532
		const Integer &q = GetSubgroupOrder();
532
		const Integer &q = GetSubgroupOrder();
533
		pass = pass && IsIdentity(gpc ? gpc->Exponentiate(GetGroupPrecomputation(), q) : ExponentiateElement(g, q));
533
		pass = pass && IsIdentity(gpc ? gpc->Exponentiate(this->GetGroupPrecomputation(), q) : ExponentiateElement(g, q));
534
	}
534
	}
535
	return pass;
535
	return pass;
536
}
536
}
Lines 565-571 Link Here
565
void DL_PublicKey_EC<EC>::BERDecodeKey2(BufferedTransformation &bt, bool parametersPresent, unsigned int size)
565
void DL_PublicKey_EC<EC>::BERDecodeKey2(BufferedTransformation &bt, bool parametersPresent, unsigned int size)
566
{
566
{
567
	typename EC::Point P;
567
	typename EC::Point P;
568
	if (!GetGroupParameters().GetCurve().DecodePoint(P, bt, size))
568
	if (!this->GetGroupParameters().GetCurve().DecodePoint(P, bt, size))
569
		BERDecodeError();
569
		BERDecodeError();
570
	SetPublicElement(P);
570
	SetPublicElement(P);
571
}
571
}
Lines 573-579 Link Here
573
template <class EC>
573
template <class EC>
574
void DL_PublicKey_EC<EC>::DEREncodeKey(BufferedTransformation &bt) const
574
void DL_PublicKey_EC<EC>::DEREncodeKey(BufferedTransformation &bt) const
575
{
575
{
576
	GetGroupParameters().GetCurve().EncodePoint(bt, GetPublicElement(), GetGroupParameters().GetPointCompression());
576
	this->GetGroupParameters().GetCurve().EncodePoint(bt, this->GetPublicElement(), this->GetGroupParameters().GetPointCompression());
577
}
577
}
578
578
579
// ******************************************************************
579
// ******************************************************************
Lines 596-602 Link Here
596
		if (!seq.EndReached() && seq.PeekByte() == (CONTEXT_SPECIFIC | CONSTRUCTED | 0))
596
		if (!seq.EndReached() && seq.PeekByte() == (CONTEXT_SPECIFIC | CONSTRUCTED | 0))
597
		{
597
		{
598
			BERGeneralDecoder parameters(seq, CONTEXT_SPECIFIC | CONSTRUCTED | 0);
598
			BERGeneralDecoder parameters(seq, CONTEXT_SPECIFIC | CONSTRUCTED | 0);
599
			AccessGroupParameters().BERDecode(parameters);
599
			this->AccessGroupParameters().BERDecode(parameters);
600
			parameters.MessageEnd();
600
			parameters.MessageEnd();
601
		}
601
		}
602
		if (!seq.EndReached())
602
		if (!seq.EndReached())
Lines 608-619 Link Here
608
			BERDecodeBitString(publicKey, subjectPublicKey, unusedBits);
608
			BERDecodeBitString(publicKey, subjectPublicKey, unusedBits);
609
			publicKey.MessageEnd();
609
			publicKey.MessageEnd();
610
			Element Q;
610
			Element Q;
611
			if (!(unusedBits == 0 && GetGroupParameters().GetCurve().DecodePoint(Q, subjectPublicKey, subjectPublicKey.size())))
611
			if (!(unusedBits == 0 && this->GetGroupParameters().GetCurve().DecodePoint(Q, subjectPublicKey, subjectPublicKey.size())))
612
				BERDecodeError();
612
				BERDecodeError();
613
		}
613
		}
614
	seq.MessageEnd();
614
	seq.MessageEnd();
615
615
616
	SetPrivateExponent(x);
616
	this->SetPrivateExponent(x);
617
}
617
}
618
618
619
template <class EC>
619
template <class EC>
Lines 623-629 Link Here
623
		DEREncodeUnsigned<word32>(privateKey, 1);	// version
623
		DEREncodeUnsigned<word32>(privateKey, 1);	// version
624
		// SEC 1 ver 1.0 says privateKey (m_d) has the same length as order of the curve
624
		// SEC 1 ver 1.0 says privateKey (m_d) has the same length as order of the curve
625
		// this will be changed to order of base point in a future version
625
		// this will be changed to order of base point in a future version
626
		GetPrivateExponent().DEREncodeAsOctetString(privateKey, GetGroupParameters().GetSubgroupOrder().ByteCount());
626
		this->GetPrivateExponent().DEREncodeAsOctetString(privateKey, this->GetGroupParameters().GetSubgroupOrder().ByteCount());
627
	privateKey.MessageEnd();
627
	privateKey.MessageEnd();
628
}
628
}
629
629
(-)crypto++-5.1/eccrypto.h (-8 / +8 lines)
Lines 42-48 Link Here
42
42
43
	void Initialize(const EllipticCurve &ec, const Point &G, const Integer &n, const Integer &k = Integer::Zero())
43
	void Initialize(const EllipticCurve &ec, const Point &G, const Integer &n, const Integer &k = Integer::Zero())
44
	{
44
	{
45
		m_groupPrecomputation.SetCurve(ec);
45
		this->m_groupPrecomputation.SetCurve(ec);
46
		SetSubgroupGenerator(G);
46
		SetSubgroupGenerator(G);
47
		m_n = n;
47
		m_n = n;
48
		m_k = k;
48
		m_k = k;
Lines 59-66 Link Here
59
	void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg);
59
	void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg);
60
60
61
	// DL_GroupParameters
61
	// DL_GroupParameters
62
	const DL_FixedBasePrecomputation<Element> & GetBasePrecomputation() const {return m_gpc;}
62
	const DL_FixedBasePrecomputation<Element> & GetBasePrecomputation() const {return this->m_gpc;}
63
	DL_FixedBasePrecomputation<Element> & AccessBasePrecomputation() {return m_gpc;}
63
	DL_FixedBasePrecomputation<Element> & AccessBasePrecomputation() {return this->m_gpc;}
64
	const Integer & GetSubgroupOrder() const {return m_n;}
64
	const Integer & GetSubgroupOrder() const {return m_n;}
65
	Integer GetCofactor() const;
65
	Integer GetCofactor() const;
66
	bool ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const;
66
	bool ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const;
Lines 115-121 Link Here
115
	void SetEncodeAsOID(bool encodeAsOID) {m_encodeAsOID = encodeAsOID;}
115
	void SetEncodeAsOID(bool encodeAsOID) {m_encodeAsOID = encodeAsOID;}
116
	bool GetEncodeAsOID() const {return m_encodeAsOID;}
116
	bool GetEncodeAsOID() const {return m_encodeAsOID;}
117
117
118
	const EllipticCurve& GetCurve() const {return m_groupPrecomputation.GetCurve();}
118
	const EllipticCurve& GetCurve() const {return this->m_groupPrecomputation.GetCurve();}
119
119
120
#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
120
#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
121
	const Point& GetBasePoint() const {return GetSubgroupGenerator();}
121
	const Point& GetBasePoint() const {return GetSubgroupGenerator();}
Lines 141-149 Link Here
141
	typedef typename EC::Point Element;
141
	typedef typename EC::Point Element;
142
142
143
	void Initialize(const DL_GroupParameters_EC<EC> &params, const Element &Q)
143
	void Initialize(const DL_GroupParameters_EC<EC> &params, const Element &Q)
144
		{AccessGroupParameters() = params; SetPublicElement(Q);}
144
		{this->AccessGroupParameters() = params; SetPublicElement(Q);}
145
	void Initialize(const EC &ec, const Element &G, const Integer &n, const Element &Q)
145
	void Initialize(const EC &ec, const Element &G, const Integer &n, const Element &Q)
146
		{AccessGroupParameters().Initialize(ec, G, n); SetPublicElement(Q);}
146
		{this->AccessGroupParameters().Initialize(ec, G, n); SetPublicElement(Q);}
147
147
148
	// X509PublicKey
148
	// X509PublicKey
149
	void BERDecodeKey2(BufferedTransformation &bt, bool parametersPresent, unsigned int size);
149
	void BERDecodeKey2(BufferedTransformation &bt, bool parametersPresent, unsigned int size);
Lines 158-166 Link Here
158
	typedef typename EC::Point Element;
158
	typedef typename EC::Point Element;
159
159
160
	void Initialize(const DL_GroupParameters_EC<EC> &params, const Integer &x)
160
	void Initialize(const DL_GroupParameters_EC<EC> &params, const Integer &x)
161
		{AccessGroupParameters() = params; SetPrivateExponent(x);}
161
		{this->AccessGroupParameters() = params; this->SetPrivateExponent(x);}
162
	void Initialize(const EC &ec, const Element &G, const Integer &n, const Integer &x)
162
	void Initialize(const EC &ec, const Element &G, const Integer &n, const Integer &x)
163
		{AccessGroupParameters().Initialize(ec, G, n); SetPrivateExponent(x);}
163
		{this->AccessGroupParameters().Initialize(ec, G, n); this->SetPrivateExponent(x);}
164
	void Initialize(RandomNumberGenerator &rng, const DL_GroupParameters_EC<EC> &params)
164
	void Initialize(RandomNumberGenerator &rng, const DL_GroupParameters_EC<EC> &params)
165
		{GenerateRandom(rng, params);}
165
		{GenerateRandom(rng, params);}
166
	void Initialize(RandomNumberGenerator &rng, const EC &ec, const Element &G, const Integer &n)
166
	void Initialize(RandomNumberGenerator &rng, const EC &ec, const Element &G, const Integer &n)
(-)crypto++-5.1/elgamal.h (-2 / +2 lines)
Lines 79-87 Link Here
79
{
79
{
80
public:
80
public:
81
	unsigned int FixedMaxPlaintextLength() const {return MaxPlaintextLength(FixedCiphertextLength());}
81
	unsigned int FixedMaxPlaintextLength() const {return MaxPlaintextLength(FixedCiphertextLength());}
82
	unsigned int FixedCiphertextLength() const {return CiphertextLength(0);}
82
	unsigned int FixedCiphertextLength() const {return this->CiphertextLength(0);}
83
83
84
	const DL_GroupParameters_GFP & GetGroupParameters() const {return GetKey().GetGroupParameters();}
84
	const DL_GroupParameters_GFP & GetGroupParameters() const {return this->GetKey().GetGroupParameters();}
85
85
86
	DecodingResult FixedLengthDecrypt(RandomNumberGenerator &rng, const byte *cipherText, byte *plainText) const
86
	DecodingResult FixedLengthDecrypt(RandomNumberGenerator &rng, const byte *cipherText, byte *plainText) const
87
		{return Decrypt(rng, cipherText, FixedCiphertextLength(), plainText);}
87
		{return Decrypt(rng, cipherText, FixedCiphertextLength(), plainText);}
(-)crypto++-5.1/gfpcrypt.h (-36 / +36 lines)
Lines 93-111 Link Here
93
		{AssignFromHelper<DL_GroupParameters_IntegerBased>(this, source);}
93
		{AssignFromHelper<DL_GroupParameters_IntegerBased>(this, source);}
94
94
95
	// DL_GroupParameters
95
	// DL_GroupParameters
96
	const DL_FixedBasePrecomputation<Element> & GetBasePrecomputation() const {return m_gpc;}
96
	const DL_FixedBasePrecomputation<Element> & GetBasePrecomputation() const {return this->m_gpc;}
97
	DL_FixedBasePrecomputation<Element> & AccessBasePrecomputation() {return m_gpc;}
97
	DL_FixedBasePrecomputation<Element> & AccessBasePrecomputation() {return this->m_gpc;}
98
98
99
	// IntegerGroupParameters
99
	// IntegerGroupParameters
100
	const Integer & GetModulus() const {return m_groupPrecomputation.GetModulus();}
100
	const Integer & GetModulus() const {return this->m_groupPrecomputation.GetModulus();}
101
	const Integer & GetGenerator() const {return m_gpc.GetBase(GetGroupPrecomputation());}
101
	const Integer & GetGenerator() const {return this->m_gpc.GetBase(this->GetGroupPrecomputation());}
102
102
103
	void SetModulusAndSubgroupGenerator(const Integer &p, const Integer &g)		// these have to be set together
103
	void SetModulusAndSubgroupGenerator(const Integer &p, const Integer &g)		// these have to be set together
104
		{m_groupPrecomputation.SetModulus(p); m_gpc.SetBase(GetGroupPrecomputation(), g); ParametersChanged();}
104
		{this->m_groupPrecomputation.SetModulus(p); this->m_gpc.SetBase(this->GetGroupPrecomputation(), g); this->ParametersChanged();}
105
105
106
	// non-inherited
106
	// non-inherited
107
	bool operator==(const DL_GroupParameters_IntegerBasedImpl<GROUP_PRECOMP, BASE_PRECOMP> &rhs) const
107
	bool operator==(const DL_GroupParameters_IntegerBasedImpl<GROUP_PRECOMP, BASE_PRECOMP> &rhs) const
108
		{return GetModulus() == rhs.GetModulus() && GetGenerator() == rhs.GetGenerator() && GetSubgroupOrder() == rhs.GetSubgroupOrder();}
108
		{return GetModulus() == rhs.GetModulus() && GetGenerator() == rhs.GetGenerator() && this->GetSubgroupOrder() == rhs.GetSubgroupOrder();}
109
	bool operator!=(const DL_GroupParameters_IntegerBasedImpl<GROUP_PRECOMP, BASE_PRECOMP> &rhs) const
109
	bool operator!=(const DL_GroupParameters_IntegerBasedImpl<GROUP_PRECOMP, BASE_PRECOMP> &rhs) const
110
		{return !operator==(rhs);}
110
		{return !operator==(rhs);}
111
};
111
};
Lines 210-226 Link Here
210
{
210
{
211
public:
211
public:
212
	void Initialize(const DL_GroupParameters_IntegerBased &params, const Integer &y)
212
	void Initialize(const DL_GroupParameters_IntegerBased &params, const Integer &y)
213
		{AccessGroupParameters().Initialize(params); SetPublicElement(y);}
213
		{this->AccessGroupParameters().Initialize(params); this->SetPublicElement(y);}
214
	void Initialize(const Integer &p, const Integer &g, const Integer &y)
214
	void Initialize(const Integer &p, const Integer &g, const Integer &y)
215
		{AccessGroupParameters().Initialize(p, g); SetPublicElement(y);}
215
		{this->AccessGroupParameters().Initialize(p, g); this->SetPublicElement(y);}
216
	void Initialize(const Integer &p, const Integer &q, const Integer &g, const Integer &y)
216
	void Initialize(const Integer &p, const Integer &q, const Integer &g, const Integer &y)
217
		{AccessGroupParameters().Initialize(p, q, g); SetPublicElement(y);}
217
		{this->AccessGroupParameters().Initialize(p, q, g); this->SetPublicElement(y);}
218
218
219
	// X509PublicKey
219
	// X509PublicKey
220
	void BERDecodeKey(BufferedTransformation &bt)
220
	void BERDecodeKey(BufferedTransformation &bt)
221
		{SetPublicElement(Integer(bt));}
221
		{this->SetPublicElement(Integer(bt));}
222
	void DEREncodeKey(BufferedTransformation &bt) const
222
	void DEREncodeKey(BufferedTransformation &bt) const
223
		{GetPublicElement().DEREncode(bt);}
223
		{this->GetPublicElement().DEREncode(bt);}
224
};
224
};
225
225
226
//! .
226
//! .
Lines 229-245 Link Here
229
{
229
{
230
public:
230
public:
231
	void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits)
231
	void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits)
232
		{GenerateRandomWithKeySize(rng, modulusBits);}
232
		{this->GenerateRandomWithKeySize(rng, modulusBits);}
233
	void Initialize(RandomNumberGenerator &rng, const Integer &p, const Integer &g)
233
	void Initialize(RandomNumberGenerator &rng, const Integer &p, const Integer &g)
234
		{GenerateRandom(rng, MakeParameters("Modulus", p)("SubgroupGenerator", g));}
234
		{this->GenerateRandom(rng, MakeParameters("Modulus", p)("SubgroupGenerator", g));}
235
	void Initialize(RandomNumberGenerator &rng, const Integer &p, const Integer &q, const Integer &g)
235
	void Initialize(RandomNumberGenerator &rng, const Integer &p, const Integer &q, const Integer &g)
236
		{GenerateRandom(rng, MakeParameters("Modulus", p)("SubgroupOrder", q)("SubgroupGenerator", g));}
236
		{this->GenerateRandom(rng, MakeParameters("Modulus", p)("SubgroupOrder", q)("SubgroupGenerator", g));}
237
	void Initialize(const DL_GroupParameters_IntegerBased &params, const Integer &x)
237
	void Initialize(const DL_GroupParameters_IntegerBased &params, const Integer &x)
238
		{AccessGroupParameters().Initialize(params); SetPrivateExponent(x);}
238
		{this->AccessGroupParameters().Initialize(params); this->SetPrivateExponent(x);}
239
	void Initialize(const Integer &p, const Integer &g, const Integer &x)
239
	void Initialize(const Integer &p, const Integer &g, const Integer &x)
240
		{AccessGroupParameters().Initialize(p, g); SetPrivateExponent(x);}
240
		{this->AccessGroupParameters().Initialize(p, g); this->SetPrivateExponent(x);}
241
	void Initialize(const Integer &p, const Integer &q, const Integer &g, const Integer &x)
241
	void Initialize(const Integer &p, const Integer &q, const Integer &g, const Integer &x)
242
		{AccessGroupParameters().Initialize(p, q, g); SetPrivateExponent(x);}
242
		{this->AccessGroupParameters().Initialize(p, q, g); this->SetPrivateExponent(x);}
243
};
243
};
244
244
245
//! .
245
//! .
Lines 272-285 Link Here
272
272
273
			if (seq.EndReached())
273
			if (seq.EndReached())
274
			{
274
			{
275
				AccessGroupParameters().Initialize(v1, v1/2, v2);
275
				this->AccessGroupParameters().Initialize(v1, v1/2, v2);
276
				SetPublicElement(v3);
276
				this->SetPublicElement(v3);
277
			}
277
			}
278
			else
278
			else
279
			{
279
			{
280
				Integer v4(seq);
280
				Integer v4(seq);
281
				AccessGroupParameters().Initialize(v1, v2, v3);
281
				this->AccessGroupParameters().Initialize(v1, v2, v3);
282
				SetPublicElement(v4);
282
				this->SetPublicElement(v4);
283
			}
283
			}
284
284
285
		seq.MessageEnd();
285
		seq.MessageEnd();
Lines 288-298 Link Here
288
	void DEREncode(BufferedTransformation &bt) const
288
	void DEREncode(BufferedTransformation &bt) const
289
	{
289
	{
290
		DERSequenceEncoder seq(bt);
290
		DERSequenceEncoder seq(bt);
291
			GetGroupParameters().GetModulus().DEREncode(seq);
291
			this->GetGroupParameters().GetModulus().DEREncode(seq);
292
			if (GetGroupParameters().GetCofactor() != 2)
292
			if (this->GetGroupParameters().GetCofactor() != 2)
293
				GetGroupParameters().GetSubgroupOrder().DEREncode(seq);
293
				this->GetGroupParameters().GetSubgroupOrder().DEREncode(seq);
294
			GetGroupParameters().GetGenerator().DEREncode(seq);
294
			this->GetGroupParameters().GetGenerator().DEREncode(seq);
295
			GetPublicElement().DEREncode(seq);
295
			this->GetPublicElement().DEREncode(seq);
296
		seq.MessageEnd();
296
		seq.MessageEnd();
297
	}
297
	}
298
};
298
};
Lines 312-325 Link Here
312
312
313
			if (seq.EndReached())
313
			if (seq.EndReached())
314
			{
314
			{
315
				AccessGroupParameters().Initialize(v1, v1/2, v2);
315
				this->AccessGroupParameters().Initialize(v1, v1/2, v2);
316
				SetPrivateExponent(v4 % (v1/2));	// some old keys may have x >= q
316
				this->SetPrivateExponent(v4 % (v1/2));	// some old keys may have x >= q
317
			}
317
			}
318
			else
318
			else
319
			{
319
			{
320
				Integer v5(seq);
320
				Integer v5(seq);
321
				AccessGroupParameters().Initialize(v1, v2, v3);
321
				this->AccessGroupParameters().Initialize(v1, v2, v3);
322
				SetPrivateExponent(v5);
322
				this->SetPrivateExponent(v5);
323
			}
323
			}
324
324
325
		seq.MessageEnd();
325
		seq.MessageEnd();
Lines 328-339 Link Here
328
	void DEREncode(BufferedTransformation &bt) const
328
	void DEREncode(BufferedTransformation &bt) const
329
	{
329
	{
330
		DERSequenceEncoder seq(bt);
330
		DERSequenceEncoder seq(bt);
331
			GetGroupParameters().GetModulus().DEREncode(seq);
331
			this->GetGroupParameters().GetModulus().DEREncode(seq);
332
			if (GetGroupParameters().GetCofactor() != 2)
332
			if (this->GetGroupParameters().GetCofactor() != 2)
333
				GetGroupParameters().GetSubgroupOrder().DEREncode(seq);
333
				this->GetGroupParameters().GetSubgroupOrder().DEREncode(seq);
334
			GetGroupParameters().GetGenerator().DEREncode(seq);
334
			this->GetGroupParameters().GetGenerator().DEREncode(seq);
335
			GetGroupParameters().ExponentiateBase(GetPrivateExponent()).DEREncode(seq);
335
			this->GetGroupParameters().ExponentiateBase(this->GetPrivateExponent()).DEREncode(seq);
336
			GetPrivateExponent().DEREncode(seq);
336
			this->GetPrivateExponent().DEREncode(seq);
337
		seq.MessageEnd();
337
		seq.MessageEnd();
338
	}
338
	}
339
};
339
};
(-)crypto++-5.1/hmac.h (-1 / +1 lines)
Lines 44-50 Link Here
44
public:
44
public:
45
	HMAC() {}
45
	HMAC() {}
46
	HMAC(const byte *key, unsigned int length=HMAC_Base<T>::DEFAULT_KEYLENGTH)
46
	HMAC(const byte *key, unsigned int length=HMAC_Base<T>::DEFAULT_KEYLENGTH)
47
		{SetKey(key, length);}
47
		{this->SetKey(key, length);}
48
};
48
};
49
49
50
template <class T>
50
template <class T>
(-)crypto++-5.1/iterhash.h (-12 / +12 lines)
Lines 82-88 Link Here
82
{
82
{
83
protected:
83
protected:
84
	IteratedHashWithStaticTransform(unsigned int digestSize) : IteratedHash<T, B, S>(digestSize) {}
84
	IteratedHashWithStaticTransform(unsigned int digestSize) : IteratedHash<T, B, S>(digestSize) {}
85
	void vTransform(const T *data) {M::Transform(m_digest, data);}
85
	void vTransform(const T *data) {M::Transform(this->m_digest, data);}
86
	std::string AlgorithmName() const {return M::StaticAlgorithmName();}
86
	std::string AlgorithmName() const {return M::StaticAlgorithmName();}
87
};
87
};
88
88
Lines 90-108 Link Here
90
90
91
template <class T, class B, class BASE> void IteratedHashBase2<T, B, BASE>::TruncatedFinal(byte *hash, unsigned int size)
91
template <class T, class B, class BASE> void IteratedHashBase2<T, B, BASE>::TruncatedFinal(byte *hash, unsigned int size)
92
{
92
{
93
	ThrowIfInvalidTruncatedSize(size);
93
	this->ThrowIfInvalidTruncatedSize(size);
94
94
95
	PadLastBlock(BlockSize() - 2*sizeof(HashWordType));
95
	PadLastBlock(this->BlockSize() - 2*sizeof(HashWordType));
96
	CorrectEndianess(m_data, m_data, BlockSize() - 2*sizeof(HashWordType));
96
	CorrectEndianess(this->m_data, this->m_data, this->BlockSize() - 2*sizeof(HashWordType));
97
97
98
	m_data[m_data.size()-2] = B::ToEnum() ? GetBitCountHi() : GetBitCountLo();
98
	this->m_data[this->m_data.size()-2] = B::ToEnum() ? this->GetBitCountHi() : this->GetBitCountLo();
99
	m_data[m_data.size()-1] = B::ToEnum() ? GetBitCountLo() : GetBitCountHi();
99
	this->m_data[this->m_data.size()-1] = B::ToEnum() ? this->GetBitCountLo() : this->GetBitCountHi();
100
100
101
	vTransform(m_data);
101
	vTransform(this->m_data);
102
	CorrectEndianess(m_digest, m_digest, DigestSize());
102
	CorrectEndianess(this->m_digest, this->m_digest, this->DigestSize());
103
	memcpy(hash, m_digest, size);
103
	memcpy(hash, this->m_digest, size);
104
104
105
	Restart();		// reinit for next use
105
	this->Restart();		// reinit for next use
106
}
106
}
107
107
108
template <class T, class B, class BASE> void IteratedHashBase2<T, B, BASE>::HashBlock(const HashWordType *input)
108
template <class T, class B, class BASE> void IteratedHashBase2<T, B, BASE>::HashBlock(const HashWordType *input)
Lines 111-118 Link Here
111
		vTransform(input);
111
		vTransform(input);
112
	else
112
	else
113
	{
113
	{
114
		ByteReverse(m_data.begin(), input, BlockSize());
114
		ByteReverse(this->m_data.begin(), input, this->BlockSize());
115
		vTransform(m_data);
115
		vTransform(this->m_data);
116
	}
116
	}
117
}
117
}
118
118
(-)crypto++-5.1/lubyrack.h (-49 / +49 lines)
Lines 29-35 Link Here
29
		// VC60 workaround: have to define these functions within class definition
29
		// VC60 workaround: have to define these functions within class definition
30
		void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length)
30
		void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length)
31
		{
31
		{
32
			AssertValidKeyLength(length);
32
			this->AssertValidKeyLength(length);
33
33
34
			L = length/2;
34
			L = length/2;
35
			buffer.New(2*S);
35
			buffer.New(2*S);
Lines 50-90 Link Here
50
	{
50
	{
51
	public:
51
	public:
52
52
53
#define KL key
53
#define KL this->key
54
#define KR key+L
54
#define KR this->key+this->L
55
#define BL buffer
55
#define BL this->buffer
56
#define BR buffer+S
56
#define BR (byte*)this->buffer+this->S
57
#define IL inBlock
57
#define IL inBlock
58
#define IR inBlock+S
58
#define IR inBlock+this->S
59
#define OL outBlock
59
#define OL outBlock
60
#define OR outBlock+S
60
#define OR outBlock+this->S
61
61
62
		void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
62
		void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
63
		{
63
		{
64
			hm.Update(KL, L);
64
			this->hm.Update(KL, this->L);
65
			hm.Update(IL, S);
65
			this->hm.Update(IL, this->S);
66
			hm.Final(BR);
66
			this->hm.Final(BR);
67
			xorbuf(BR, IR, S);
67
			xorbuf(BR, IR, this->S);
68
68
69
			hm.Update(KR, L);
69
			this->hm.Update(KR, this->L);
70
			hm.Update(BR, S);
70
			this->hm.Update(BR, this->S);
71
			hm.Final(BL);
71
			this->hm.Final(BL);
72
			xorbuf(BL, IL, S);
72
			xorbuf(BL, IL, this->S);
73
73
74
			hm.Update(KL, L);
74
			this->hm.Update(KL, this->L);
75
			hm.Update(BL, S);
75
			this->hm.Update(BL, this->S);
76
			hm.Final(digest);
76
			this->hm.Final(this->digest);
77
			xorbuf(BR, digest, S);
77
			xorbuf(BR, this->digest, this->S);
78
78
79
			hm.Update(KR, L);
79
			this->hm.Update(KR, this->L);
80
			hm.Update(OR, S);
80
			this->hm.Update(OR, this->S);
81
			hm.Final(digest);
81
			this->hm.Final(this->digest);
82
			xorbuf(BL, digest, S);
82
			xorbuf(BL, this->digest, this->S);
83
83
84
			if (xorBlock)
84
			if (xorBlock)
85
				xorbuf(outBlock, xorBlock, buffer, 2*S);
85
				xorbuf(outBlock, xorBlock, this->buffer, 2*this->S);
86
			else
86
			else
87
				memcpy(outBlock, buffer, 2*S);
87
				memcpy(outBlock, this->buffer, 2*this->S);
88
		}
88
		}
89
	};
89
	};
90
90
Lines 93-122 Link Here
93
	public:
93
	public:
94
		void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
94
		void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
95
		{
95
		{
96
			hm.Update(KR, L);
96
			this->hm.Update(KR, this->L);
97
			hm.Update(IR, S);
97
			this->hm.Update(IR, this->S);
98
			hm.Final(BL);
98
			this->hm.Final(BL);
99
			xorbuf(BL, IL, S);
99
			xorbuf(BL, IL, this->S);
100
100
101
			hm.Update(KL, L);
101
			this->hm.Update(KL, this->L);
102
			hm.Update(BL, S);
102
			this->hm.Update(BL, this->S);
103
			hm.Final(BR);
103
			this->hm.Final(BR);
104
			xorbuf(BR, IR, S);
104
			xorbuf(BR, IR, this->S);
105
105
106
			hm.Update(KR, L);
106
			this->hm.Update(KR, this->L);
107
			hm.Update(BR, S);
107
			this->hm.Update(BR, this->S);
108
			hm.Final(digest);
108
			this->hm.Final(this->digest);
109
			xorbuf(BL, digest, S);
109
			xorbuf(BL, this->digest, this->S);
110
110
111
			hm.Update(KL, L);
111
			this->hm.Update(KL, this->L);
112
			hm.Update(OL, S);
112
			this->hm.Update(OL, this->S);
113
			hm.Final(digest);
113
			this->hm.Final(this->digest);
114
			xorbuf(BR, digest, S);
114
			xorbuf(BR, this->digest, this->S);
115
115
116
			if (xorBlock)
116
			if (xorBlock)
117
				xorbuf(outBlock, xorBlock, buffer, 2*S);
117
				xorbuf(outBlock, xorBlock, this->buffer, 2*this->S);
118
			else
118
			else
119
				memcpy(outBlock, buffer, 2*S);
119
				memcpy(outBlock, this->buffer, 2*this->S);
120
		}
120
		}
121
#undef KL
121
#undef KL
122
#undef KR
122
#undef KR
(-)crypto++-5.1/mdc.h (-7 / +7 lines)
Lines 30-51 Link Here
30
		void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length)
30
		void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length)
31
		{
31
		{
32
			assert(direction == ENCRYPTION);
32
			assert(direction == ENCRYPTION);
33
			AssertValidKeyLength(length);
33
			this->AssertValidKeyLength(length);
34
			memcpy(Key(), userKey, KEYLENGTH);
34
			memcpy(Key(), userKey, this->KEYLENGTH);
35
			T::CorrectEndianess(Key(), Key(), KEYLENGTH);
35
			T::CorrectEndianess(Key(), Key(), this->KEYLENGTH);
36
		}
36
		}
37
37
38
		void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
38
		void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
39
		{
39
		{
40
			T::CorrectEndianess(Buffer(), (HashWordType *)inBlock, BLOCKSIZE);
40
			T::CorrectEndianess(Buffer(), (HashWordType *)inBlock, this->BLOCKSIZE);
41
			T::Transform(Buffer(), Key());
41
			T::Transform(Buffer(), Key());
42
			if (xorBlock)
42
			if (xorBlock)
43
			{
43
			{
44
				T::CorrectEndianess(Buffer(), Buffer(), BLOCKSIZE);
44
				T::CorrectEndianess(Buffer(), Buffer(), this->BLOCKSIZE);
45
				xorbuf(outBlock, xorBlock, m_buffer, BLOCKSIZE);
45
				xorbuf(outBlock, xorBlock, m_buffer, this->BLOCKSIZE);
46
			}
46
			}
47
			else
47
			else
48
				T::CorrectEndianess((HashWordType *)outBlock, Buffer(), BLOCKSIZE);
48
				T::CorrectEndianess((HashWordType *)outBlock, Buffer(), this->BLOCKSIZE);
49
		}
49
		}
50
50
51
		bool IsPermutation() const {return false;}
51
		bool IsPermutation() const {return false;}
(-)crypto++-5.1/modes.h (-10 / +10 lines)
Lines 239-256 Link Here
239
public:
239
public:
240
	CipherModeFinalTemplate_CipherHolder()
240
	CipherModeFinalTemplate_CipherHolder()
241
	{
241
	{
242
		m_cipher = &m_object;
242
		this->m_cipher = &this->m_object;
243
		ResizeBuffers();
243
		this->ResizeBuffers();
244
	}
244
	}
245
	CipherModeFinalTemplate_CipherHolder(const byte *key, unsigned int length)
245
	CipherModeFinalTemplate_CipherHolder(const byte *key, unsigned int length)
246
	{
246
	{
247
		m_cipher = &m_object;
247
		this->m_cipher = &this->m_object;
248
		SetKey(key, length);
248
		this->SetKey(key, length);
249
	}
249
	}
250
	CipherModeFinalTemplate_CipherHolder(const byte *key, unsigned int length, const byte *iv, int feedbackSize = 0)
250
	CipherModeFinalTemplate_CipherHolder(const byte *key, unsigned int length, const byte *iv, int feedbackSize = 0)
251
	{
251
	{
252
		m_cipher = &m_object;
252
		this->m_cipher = &this->m_object;
253
		SetKey(key, length, MakeParameters("IV", iv)("FeedbackSize", feedbackSize));
253
		this->SetKey(key, length, MakeParameters("IV", iv)("FeedbackSize", feedbackSize));
254
	}
254
	}
255
};
255
};
256
256
Lines 261-270 Link Here
261
public:
261
public:
262
	CipherModeFinalTemplate_ExternalCipher(BlockCipher &cipher, const byte *iv = NULL, int feedbackSize = 0)
262
	CipherModeFinalTemplate_ExternalCipher(BlockCipher &cipher, const byte *iv = NULL, int feedbackSize = 0)
263
	{
263
	{
264
		m_cipher = &cipher;
264
		this->m_cipher = &cipher;
265
		ResizeBuffers();
265
		this->ResizeBuffers();
266
		SetFeedbackSize(feedbackSize);
266
		this->SetFeedbackSize(feedbackSize);
267
		SetIV(iv);
267
		this->SetIV(iv);
268
	}
268
	}
269
};
269
};
270
270
(-)crypto++-5.1/osrng.h (-1 / +2 lines)
Lines 7-12 Link Here
7
7
8
#include "randpool.h"
8
#include "randpool.h"
9
#include "rng.h"
9
#include "rng.h"
10
#include "fips140.h"
10
11
11
NAMESPACE_BEGIN(CryptoPP)
12
NAMESPACE_BEGIN(CryptoPP)
12
13
Lines 128-134 Link Here
128
	do
129
	do
129
	{
130
	{
130
		OS_GenerateRandomBlock(blocking, seed, seed.size());
131
		OS_GenerateRandomBlock(blocking, seed, seed.size());
131
		key = seed + BLOCK_CIPHER::BLOCKSIZE;
132
		key = (byte*)seed + BLOCK_CIPHER::BLOCKSIZE;
132
	}	// check that seed and key don't have same value
133
	}	// check that seed and key don't have same value
133
	while (memcmp(key, seed, STDMIN((unsigned int)BLOCK_CIPHER::BLOCKSIZE, (unsigned int)BLOCK_CIPHER::DEFAULT_KEYLENGTH)) == 0);
134
	while (memcmp(key, seed, STDMIN((unsigned int)BLOCK_CIPHER::BLOCKSIZE, (unsigned int)BLOCK_CIPHER::DEFAULT_KEYLENGTH)) == 0);
134
135
(-)crypto++-5.1/panama.cpp (-9 / +9 lines)
Lines 90-96 Link Here
90
template <class B>
90
template <class B>
91
unsigned int PanamaHash<B>::HashMultipleBlocks(const word32 *input, unsigned int length)
91
unsigned int PanamaHash<B>::HashMultipleBlocks(const word32 *input, unsigned int length)
92
{
92
{
93
	Iterate(length / BLOCKSIZE, input);
93
	this->Iterate(length / BLOCKSIZE, input);
94
	return length % BLOCKSIZE;
94
	return length % BLOCKSIZE;
95
}
95
}
96
96
Lines 103-112 Link Here
103
	
103
	
104
	vTransform(m_data);
104
	vTransform(m_data);
105
105
106
	Iterate(32);	// pull
106
	this->Iterate(32);	// pull
107
107
108
	ConditionalByteReverse(B::ToEnum(), m_state+9, m_state+9, DIGESTSIZE);
108
	ConditionalByteReverse(B::ToEnum(), this->m_state+9, this->m_state+9, DIGESTSIZE);
109
	memcpy(hash, m_state+9, size);
109
	memcpy(hash, this->m_state+9, size);
110
110
111
	Restart();		// reinit for next use
111
	Restart();		// reinit for next use
112
}
112
}
Lines 116-137 Link Here
116
{
116
{
117
	FixedSizeSecBlock<word32, 8> buf;
117
	FixedSizeSecBlock<word32, 8> buf;
118
118
119
	Reset();
119
	this->Reset();
120
	memcpy(buf, key, 32);
120
	memcpy(buf, key, 32);
121
	Iterate(1, buf);
121
	this->Iterate(1, buf);
122
	if (length == 64)
122
	if (length == 64)
123
		memcpy(buf, key+32, 32);
123
		memcpy(buf, key+32, 32);
124
	else
124
	else
125
		memset(buf, 0, 32);
125
		memset(buf, 0, 32);
126
	Iterate(1, buf);
126
	this->Iterate(1, buf);
127
127
128
	Iterate(32);
128
	this->Iterate(32);
129
}
129
}
130
130
131
template <class B>
131
template <class B>
132
void PanamaCipherPolicy<B>::OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, unsigned int iterationCount)
132
void PanamaCipherPolicy<B>::OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, unsigned int iterationCount)
133
{
133
{
134
	Iterate(iterationCount, NULL, (word32 *)output, (const word32 *)input);
134
	this->Iterate(iterationCount, NULL, (word32 *)output, (const word32 *)input);
135
}
135
}
136
136
137
template class Panama<BigEndian>;
137
template class Panama<BigEndian>;
(-)crypto++-5.1/panama.h (-2 / +2 lines)
Lines 36-42 Link Here
36
36
37
protected:
37
protected:
38
	void Init() {Panama<B>::Reset();}
38
	void Init() {Panama<B>::Reset();}
39
	void vTransform(const word32 *data) {Iterate(1, data);}	// push
39
	void vTransform(const word32 *data) {this->Iterate(1, data);}	// push
40
	unsigned int HashMultipleBlocks(const word32 *input, unsigned int length);
40
	unsigned int HashMultipleBlocks(const word32 *input, unsigned int length);
41
};
41
};
42
42
Lines 70-76 Link Here
70
public:
70
public:
71
 	PanamaMAC() {}
71
 	PanamaMAC() {}
72
	PanamaMAC(const byte *key, unsigned int length=PanamaMAC_Base<B>::DEFAULT_KEYLENGTH)
72
	PanamaMAC(const byte *key, unsigned int length=PanamaMAC_Base<B>::DEFAULT_KEYLENGTH)
73
		{SetKey(key, length);}
73
		{this->SetKey(key, length);}
74
};
74
};
75
75
76
//! .
76
//! .
(-)crypto++-5.1/polynomi.h (-17 / +17 lines)
Lines 316-361 Link Here
316
		{return a.Equals(b, m_ring);}
316
		{return a.Equals(b, m_ring);}
317
317
318
	const Element& Identity() const
318
	const Element& Identity() const
319
		{return result = m_ring.Identity();}
319
		{return this->result = m_ring.Identity();}
320
320
321
	const Element& Add(const Element &a, const Element &b) const
321
	const Element& Add(const Element &a, const Element &b) const
322
		{return result = a.Plus(b, m_ring);}
322
		{return this->result = a.Plus(b, m_ring);}
323
323
324
	Element& Accumulate(Element &a, const Element &b) const
324
	Element& Accumulate(Element &a, const Element &b) const
325
		{a.Accumulate(b, m_ring); return a;}
325
		{a.Accumulate(b, m_ring); return a;}
326
326
327
	const Element& Inverse(const Element &a) const
327
	const Element& Inverse(const Element &a) const
328
		{return result = a.Inverse(m_ring);}
328
		{return this->result = a.Inverse(m_ring);}
329
329
330
	const Element& Subtract(const Element &a, const Element &b) const
330
	const Element& Subtract(const Element &a, const Element &b) const
331
		{return result = a.Minus(b, m_ring);}
331
		{return this->result = a.Minus(b, m_ring);}
332
332
333
	Element& Reduce(Element &a, const Element &b) const
333
	Element& Reduce(Element &a, const Element &b) const
334
		{return a.Reduce(b, m_ring);}
334
		{return a.Reduce(b, m_ring);}
335
335
336
	const Element& Double(const Element &a) const
336
	const Element& Double(const Element &a) const
337
		{return result = a.Doubled(m_ring);}
337
		{return this->result = a.Doubled(m_ring);}
338
338
339
	const Element& MultiplicativeIdentity() const
339
	const Element& MultiplicativeIdentity() const
340
		{return result = m_ring.MultiplicativeIdentity();}
340
		{return this->result = m_ring.MultiplicativeIdentity();}
341
341
342
	const Element& Multiply(const Element &a, const Element &b) const
342
	const Element& Multiply(const Element &a, const Element &b) const
343
		{return result = a.Times(b, m_ring);}
343
		{return this->result = a.Times(b, m_ring);}
344
344
345
	const Element& Square(const Element &a) const
345
	const Element& Square(const Element &a) const
346
		{return result = a.Squared(m_ring);}
346
		{return this->result = a.Squared(m_ring);}
347
347
348
	bool IsUnit(const Element &a) const
348
	bool IsUnit(const Element &a) const
349
		{return a.IsUnit(m_ring);}
349
		{return a.IsUnit(m_ring);}
350
350
351
	const Element& MultiplicativeInverse(const Element &a) const
351
	const Element& MultiplicativeInverse(const Element &a) const
352
		{return result = a.MultiplicativeInverse(m_ring);}
352
		{return this->result = a.MultiplicativeInverse(m_ring);}
353
353
354
	const Element& Divide(const Element &a, const Element &b) const
354
	const Element& Divide(const Element &a, const Element &b) const
355
		{return result = a.DividedBy(b, m_ring);}
355
		{return this->result = a.DividedBy(b, m_ring);}
356
356
357
	const Element& Mod(const Element &a, const Element &b) const
357
	const Element& Mod(const Element &a, const Element &b) const
358
		{return result = a.Modulo(b, m_ring);}
358
		{return this->result = a.Modulo(b, m_ring);}
359
359
360
	void DivisionAlgorithm(Element &r, Element &q, const Element &a, const Element &d) const
360
	void DivisionAlgorithm(Element &r, Element &q, const Element &a, const Element &d) const
361
		{Element::Divide(r, q, a, d, m_ring);}
361
		{Element::Divide(r, q, a, d, m_ring);}
Lines 391-397 Link Here
391
//!
391
//!
392
template <class T, int instance>
392
template <class T, int instance>
393
inline bool operator==(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b)
393
inline bool operator==(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b)
394
	{return a.Equals(b, fixedRing);}
394
	{return a.Equals(b, T::fixedRing);}
395
//!
395
//!
396
template <class T, int instance>
396
template <class T, int instance>
397
inline bool operator!=(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b)
397
inline bool operator!=(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b)
Lines 417-439 Link Here
417
//!
417
//!
418
template <class T, int instance>
418
template <class T, int instance>
419
inline CryptoPP::PolynomialOverFixedRing<T, instance> operator+(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b)
419
inline CryptoPP::PolynomialOverFixedRing<T, instance> operator+(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b)
420
	{return CryptoPP::PolynomialOverFixedRing<T, instance>(a.Plus(b, fixedRing));}
420
	{return CryptoPP::PolynomialOverFixedRing<T, instance>(a.Plus(b, T::fixedRing));}
421
//!
421
//!
422
template <class T, int instance>
422
template <class T, int instance>
423
inline CryptoPP::PolynomialOverFixedRing<T, instance> operator-(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b)
423
inline CryptoPP::PolynomialOverFixedRing<T, instance> operator-(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b)
424
	{return CryptoPP::PolynomialOverFixedRing<T, instance>(a.Minus(b, fixedRing));}
424
	{return CryptoPP::PolynomialOverFixedRing<T, instance>(a.Minus(b, T::fixedRing));}
425
//!
425
//!
426
template <class T, int instance>
426
template <class T, int instance>
427
inline CryptoPP::PolynomialOverFixedRing<T, instance> operator*(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b)
427
inline CryptoPP::PolynomialOverFixedRing<T, instance> operator*(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b)
428
	{return CryptoPP::PolynomialOverFixedRing<T, instance>(a.Times(b, fixedRing));}
428
	{return CryptoPP::PolynomialOverFixedRing<T, instance>(a.Times(b, T::fixedRing));}
429
//!
429
//!
430
template <class T, int instance>
430
template <class T, int instance>
431
inline CryptoPP::PolynomialOverFixedRing<T, instance> operator/(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b)
431
inline CryptoPP::PolynomialOverFixedRing<T, instance> operator/(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b)
432
	{return CryptoPP::PolynomialOverFixedRing<T, instance>(a.DividedBy(b, fixedRing));}
432
	{return CryptoPP::PolynomialOverFixedRing<T, instance>(a.DividedBy(b, T::fixedRing));}
433
//!
433
//!
434
template <class T, int instance>
434
template <class T, int instance>
435
inline CryptoPP::PolynomialOverFixedRing<T, instance> operator%(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b)
435
inline CryptoPP::PolynomialOverFixedRing<T, instance> operator%(const CryptoPP::PolynomialOverFixedRing<T, instance> &a, const CryptoPP::PolynomialOverFixedRing<T, instance> &b)
436
	{return CryptoPP::PolynomialOverFixedRing<T, instance>(a.Modulo(b, fixedRing));}
436
	{return CryptoPP::PolynomialOverFixedRing<T, instance>(a.Modulo(b, T::fixedRing));}
437
437
438
NAMESPACE_END
438
NAMESPACE_END
439
439
(-)crypto++-5.1/pubkey.h (-109 / +110 lines)
Lines 36-41 Link Here
36
#include "filters.h"
36
#include "filters.h"
37
#include "eprecomp.h"
37
#include "eprecomp.h"
38
#include "fips140.h"
38
#include "fips140.h"
39
#include "modarith.h"
39
#include "argnames.h"
40
#include "argnames.h"
40
#include <memory>
41
#include <memory>
41
42
Lines 142-153 Link Here
142
class TF_CryptoSystemBase : public INTERFACE, protected BASE
143
class TF_CryptoSystemBase : public INTERFACE, protected BASE
143
{
144
{
144
public:
145
public:
145
	unsigned int FixedMaxPlaintextLength() const {return GetMessageEncodingInterface().MaxUnpaddedLength(PaddedBlockBitLength());}
146
	unsigned int FixedMaxPlaintextLength() const {return this->GetMessageEncodingInterface().MaxUnpaddedLength(PaddedBlockBitLength());}
146
	unsigned int FixedCiphertextLength() const {return GetTrapdoorFunctionBounds().MaxImage().ByteCount();}
147
	unsigned int FixedCiphertextLength() const {return this->GetTrapdoorFunctionBounds().MaxImage().ByteCount();}
147
148
148
protected:
149
protected:
149
	unsigned int PaddedBlockByteLength() const {return BitsToBytes(PaddedBlockBitLength());}
150
	unsigned int PaddedBlockByteLength() const {return BitsToBytes(PaddedBlockBitLength());}
150
	unsigned int PaddedBlockBitLength() const {return GetTrapdoorFunctionBounds().PreimageBound().BitCount()-1;}
151
	unsigned int PaddedBlockBitLength() const {return this->GetTrapdoorFunctionBounds().PreimageBound().BitCount()-1;}
151
};
152
};
152
153
153
//! .
154
//! .
Lines 288-294 Link Here
288
class PK_MessageAccumulatorImpl : public PK_MessageAccumulatorBase, protected ObjectHolder<HASH_ALGORITHM>
289
class PK_MessageAccumulatorImpl : public PK_MessageAccumulatorBase, protected ObjectHolder<HASH_ALGORITHM>
289
{
290
{
290
public:
291
public:
291
	HashTransformation & AccessHash() {return m_object;}
292
	HashTransformation & AccessHash() {return this->m_object;}
292
};
293
};
293
294
294
//! .
295
//! .
Lines 297-318 Link Here
297
{
298
{
298
public:
299
public:
299
	unsigned int SignatureLength() const 
300
	unsigned int SignatureLength() const 
300
		{return GetTrapdoorFunctionBounds().MaxPreimage().ByteCount();}
301
		{return this->GetTrapdoorFunctionBounds().MaxPreimage().ByteCount();}
301
	unsigned int MaxRecoverableLength() const 
302
	unsigned int MaxRecoverableLength() const 
302
		{return GetMessageEncodingInterface().MaxRecoverableLength(MessageRepresentativeBitLength(), GetHashIdentifier().second, GetDigestSize());}
303
		{return this->GetMessageEncodingInterface().MaxRecoverableLength(MessageRepresentativeBitLength(), GetHashIdentifier().second, GetDigestSize());}
303
	unsigned int MaxRecoverableLengthFromSignatureLength(unsigned int signatureLength) const
304
	unsigned int MaxRecoverableLengthFromSignatureLength(unsigned int signatureLength) const
304
		{return MaxRecoverableLength();}
305
		{return MaxRecoverableLength();}
305
306
306
	bool IsProbabilistic() const 
307
	bool IsProbabilistic() const 
307
		{return GetTrapdoorFunctionInterface().IsRandomized() || GetMessageEncodingInterface().IsProbabilistic();}
308
		{return this->GetTrapdoorFunctionInterface().IsRandomized() || this->GetMessageEncodingInterface().IsProbabilistic();}
308
	bool AllowNonrecoverablePart() const 
309
	bool AllowNonrecoverablePart() const 
309
		{return GetMessageEncodingInterface().AllowNonrecoverablePart();}
310
		{return this->GetMessageEncodingInterface().AllowNonrecoverablePart();}
310
	bool RecoverablePartFirst() const 
311
	bool RecoverablePartFirst() const 
311
		{return GetMessageEncodingInterface().RecoverablePartFirst();}
312
		{return this->GetMessageEncodingInterface().RecoverablePartFirst();}
312
313
313
protected:
314
protected:
314
	unsigned int MessageRepresentativeLength() const {return BitsToBytes(MessageRepresentativeBitLength());}
315
	unsigned int MessageRepresentativeLength() const {return BitsToBytes(MessageRepresentativeBitLength());}
315
	unsigned int MessageRepresentativeBitLength() const {return GetTrapdoorFunctionBounds().ImageBound().BitCount()-1;}
316
	unsigned int MessageRepresentativeBitLength() const {return this->GetTrapdoorFunctionBounds().ImageBound().BitCount()-1;}
316
	virtual HashIdentifier GetHashIdentifier() const =0;
317
	virtual HashIdentifier GetHashIdentifier() const =0;
317
	virtual unsigned int GetDigestSize() const =0;
318
	virtual unsigned int GetDigestSize() const =0;
318
};
319
};
Lines 401-407 Link Here
401
	// for signature scheme
402
	// for signature scheme
402
	HashIdentifier GetHashIdentifier() const
403
	HashIdentifier GetHashIdentifier() const
403
	{
404
	{
404
		typedef CPP_TYPENAME SchemeOptions::MessageEncodingMethod::HashIdentifierLookup::HashIdentifierLookup2<CPP_TYPENAME SchemeOptions::HashFunction> L;
405
		typedef CPP_TYPENAME SchemeOptions::MessageEncodingMethod::HashIdentifierLookup::template HashIdentifierLookup2<CPP_TYPENAME SchemeOptions::HashFunction> L;
405
		return L::Lookup();
406
		return L::Lookup();
406
	}
407
	}
407
	unsigned int GetDigestSize() const
408
	unsigned int GetDigestSize() const
Lines 446-452 Link Here
446
class TF_PublicObjectImpl : public TF_ObjectImpl<BASE, SCHEME_OPTIONS, typename SCHEME_OPTIONS::PublicKey>, public PublicKeyCopier<SCHEME_OPTIONS>
447
class TF_PublicObjectImpl : public TF_ObjectImpl<BASE, SCHEME_OPTIONS, typename SCHEME_OPTIONS::PublicKey>, public PublicKeyCopier<SCHEME_OPTIONS>
447
{
448
{
448
public:
449
public:
449
	void CopyKeyInto(typename SCHEME_OPTIONS::PublicKey &key) const {key = GetKey();}
450
	void CopyKeyInto(typename SCHEME_OPTIONS::PublicKey &key) const {key = this->GetKey();}
450
};
451
};
451
452
452
//! .
453
//! .
Lines 454-461 Link Here
454
class TF_PrivateObjectImpl : public TF_ObjectImpl<BASE, SCHEME_OPTIONS, typename SCHEME_OPTIONS::PrivateKey>, public PrivateKeyCopier<SCHEME_OPTIONS>
455
class TF_PrivateObjectImpl : public TF_ObjectImpl<BASE, SCHEME_OPTIONS, typename SCHEME_OPTIONS::PrivateKey>, public PrivateKeyCopier<SCHEME_OPTIONS>
455
{
456
{
456
public:
457
public:
457
	void CopyKeyInto(typename SCHEME_OPTIONS::PrivateKey &key) const {key = GetKey();}
458
	void CopyKeyInto(typename SCHEME_OPTIONS::PrivateKey &key) const {key = this->GetKey();}
458
	void CopyKeyInto(typename SCHEME_OPTIONS::PublicKey &key) const {key = GetKey();}
459
	void CopyKeyInto(typename SCHEME_OPTIONS::PublicKey &key) const {key = this->GetKey();}
459
};
460
};
460
461
461
//! .
462
//! .
Lines 674-696 Link Here
674
675
675
	bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
676
	bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
676
	{
677
	{
677
		return GetValueHelper(this, name, valueType, pValue, &GetAbstractGroupParameters())
678
		return GetValueHelper(this, name, valueType, pValue, &this->GetAbstractGroupParameters())
678
				CRYPTOPP_GET_FUNCTION_ENTRY(PublicElement);
679
				CRYPTOPP_GET_FUNCTION_ENTRY(PublicElement);
679
	}
680
	}
680
681
681
	void AssignFrom(const NameValuePairs &source);
682
	void AssignFrom(const NameValuePairs &source);
682
	
683
	
683
	// non-inherited
684
	// non-inherited
684
	virtual const Element & GetPublicElement() const {return GetPublicPrecomputation().GetBase(GetAbstractGroupParameters().GetGroupPrecomputation());}
685
	virtual const Element & GetPublicElement() const {return this->GetPublicPrecomputation().GetBase(this->GetAbstractGroupParameters().GetGroupPrecomputation());}
685
	virtual void SetPublicElement(const Element &y) {AccessPublicPrecomputation().SetBase(GetAbstractGroupParameters().GetGroupPrecomputation(), y);}
686
	virtual void SetPublicElement(const Element &y) {AccessPublicPrecomputation().SetBase(this->GetAbstractGroupParameters().GetGroupPrecomputation(), y);}
686
	virtual Element ExponentiatePublicElement(const Integer &exponent) const
687
	virtual Element ExponentiatePublicElement(const Integer &exponent) const
687
	{
688
	{
688
		const DL_GroupParameters<T> &params = GetAbstractGroupParameters();
689
		const DL_GroupParameters<T> &params = this->GetAbstractGroupParameters();
689
		return GetPublicPrecomputation().Exponentiate(params.GetGroupPrecomputation(), exponent);
690
		return GetPublicPrecomputation().Exponentiate(params.GetGroupPrecomputation(), exponent);
690
	}
691
	}
691
	virtual Element CascadeExponentiateBaseAndPublicElement(const Integer &baseExp, const Integer &publicExp) const
692
	virtual Element CascadeExponentiateBaseAndPublicElement(const Integer &baseExp, const Integer &publicExp) const
692
	{
693
	{
693
		const DL_GroupParameters<T> &params = GetAbstractGroupParameters();
694
		const DL_GroupParameters<T> &params = this->GetAbstractGroupParameters();
694
		return params.GetBasePrecomputation().CascadeExponentiate(params.GetGroupPrecomputation(), baseExp, GetPublicPrecomputation(), publicExp);
695
		return params.GetBasePrecomputation().CascadeExponentiate(params.GetGroupPrecomputation(), baseExp, GetPublicPrecomputation(), publicExp);
695
	}
696
	}
696
697
Lines 709-727 Link Here
709
710
710
	void MakePublicKey(DL_PublicKey<T> &pub) const
711
	void MakePublicKey(DL_PublicKey<T> &pub) const
711
	{
712
	{
712
		pub.AccessAbstractGroupParameters().AssignFrom(GetAbstractGroupParameters());
713
		pub.AccessAbstractGroupParameters().AssignFrom(this->GetAbstractGroupParameters());
713
		pub.SetPublicElement(GetAbstractGroupParameters().ExponentiateBase(GetPrivateExponent()));
714
		pub.SetPublicElement(this->GetAbstractGroupParameters().ExponentiateBase(GetPrivateExponent()));
714
	}
715
	}
715
716
716
	bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
717
	bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
717
	{
718
	{
718
		return GetValueHelper(this, name, valueType, pValue, &GetAbstractGroupParameters())
719
		return GetValueHelper(this, name, valueType, pValue, &this->GetAbstractGroupParameters())
719
				CRYPTOPP_GET_FUNCTION_ENTRY(PrivateExponent);
720
				CRYPTOPP_GET_FUNCTION_ENTRY(PrivateExponent);
720
	}
721
	}
721
722
722
	void AssignFrom(const NameValuePairs &source)
723
	void AssignFrom(const NameValuePairs &source)
723
	{
724
	{
724
		AccessAbstractGroupParameters().AssignFrom(source);
725
		this->AccessAbstractGroupParameters().AssignFrom(source);
725
		AssignFromHelper(this, source)
726
		AssignFromHelper(this, source)
726
			CRYPTOPP_SET_FUNCTION_ENTRY(PrivateExponent);
727
			CRYPTOPP_SET_FUNCTION_ENTRY(PrivateExponent);
727
	}
728
	}
Lines 738-744 Link Here
738
		pPrivateKey->MakePublicKey(*this);
739
		pPrivateKey->MakePublicKey(*this);
739
	else
740
	else
740
	{
741
	{
741
		AccessAbstractGroupParameters().AssignFrom(source);
742
		this->AccessAbstractGroupParameters().AssignFrom(source);
742
		AssignFromHelper(this, source)
743
		AssignFromHelper(this, source)
743
			CRYPTOPP_SET_FUNCTION_ENTRY(PublicElement);
744
			CRYPTOPP_SET_FUNCTION_ENTRY(PublicElement);
744
	}
745
	}
Lines 806-813 Link Here
806
807
807
	void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &params)
808
	void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &params)
808
	{
809
	{
809
		if (!params.GetThisObject(AccessGroupParameters()))
810
		if (!params.GetThisObject(this->AccessGroupParameters()))
810
			AccessGroupParameters().GenerateRandom(rng, params);
811
			this->AccessGroupParameters().GenerateRandom(rng, params);
811
//		std::pair<const byte *, int> seed;
812
//		std::pair<const byte *, int> seed;
812
		Integer x(rng, Integer::One(), GetAbstractGroupParameters().GetMaxExponent());
813
		Integer x(rng, Integer::One(), GetAbstractGroupParameters().GetMaxExponent());
813
//			Integer::ANY, Integer::Zero(), Integer::One(),
814
//			Integer::ANY, Integer::Zero(), Integer::One(),
Lines 827-834 Link Here
827
		{GetAbstractGroupParameters().SavePrecomputation(storedPrecomputation);}
828
		{GetAbstractGroupParameters().SavePrecomputation(storedPrecomputation);}
828
829
829
	// DL_Key
830
	// DL_Key
830
	const DL_GroupParameters<Element> & GetAbstractGroupParameters() const {return GetGroupParameters();}
831
	const DL_GroupParameters<Element> & GetAbstractGroupParameters() const {return this->GetGroupParameters();}
831
	DL_GroupParameters<Element> & AccessAbstractGroupParameters() {return AccessGroupParameters();}
832
	DL_GroupParameters<Element> & AccessAbstractGroupParameters() {return this->AccessGroupParameters();}
832
833
833
	// DL_PrivateKey
834
	// DL_PrivateKey
834
	const Integer & GetPrivateExponent() const {return m_x;}
835
	const Integer & GetPrivateExponent() const {return m_x;}
Lines 873-879 Link Here
873
	bool Validate(RandomNumberGenerator &rng, unsigned int level) const
874
	bool Validate(RandomNumberGenerator &rng, unsigned int level) const
874
	{
875
	{
875
		bool pass = GetAbstractGroupParameters().Validate(rng, level);
876
		bool pass = GetAbstractGroupParameters().Validate(rng, level);
876
		pass = pass && GetAbstractGroupParameters().ValidateElement(level, GetPublicElement(), &GetPublicPrecomputation());
877
		pass = pass && GetAbstractGroupParameters().ValidateElement(level, this->GetPublicElement(), &GetPublicPrecomputation());
877
		return pass;
878
		return pass;
878
	}
879
	}
879
880
Lines 908-915 Link Here
908
	}
909
	}
909
910
910
	// DL_Key
911
	// DL_Key
911
	const DL_GroupParameters<Element> & GetAbstractGroupParameters() const {return GetGroupParameters();}
912
	const DL_GroupParameters<Element> & GetAbstractGroupParameters() const {return this->GetGroupParameters();}
912
	DL_GroupParameters<Element> & AccessAbstractGroupParameters() {return AccessGroupParameters();}
913
	DL_GroupParameters<Element> & AccessAbstractGroupParameters() {return this->AccessGroupParameters();}
913
914
914
	// DL_PublicKey
915
	// DL_PublicKey
915
	const DL_FixedBasePrecomputation<Element> & GetPublicPrecomputation() const {return m_ypc;}
916
	const DL_FixedBasePrecomputation<Element> & GetPublicPrecomputation() const {return m_ypc;}
Lines 917-923 Link Here
917
918
918
	// non-inherited
919
	// non-inherited
919
	bool operator==(const DL_PublicKeyImpl<GP> &rhs) const
920
	bool operator==(const DL_PublicKeyImpl<GP> &rhs) const
920
		{return GetGroupParameters() == rhs.GetGroupParameters() && GetPublicElement() == rhs.GetPublicElement();}
921
		{return this->GetGroupParameters() == rhs.GetGroupParameters() && this->GetPublicElement() == rhs.GetPublicElement();}
921
922
922
private:
923
private:
923
	typename GP::BasePrecomputation m_ypc;
924
	typename GP::BasePrecomputation m_ypc;
Lines 991-998 Link Here
991
public:
992
public:
992
	unsigned int SignatureLength() const
993
	unsigned int SignatureLength() const
993
	{
994
	{
994
		return GetSignatureAlgorithm().RLen(GetAbstractGroupParameters())
995
		return GetSignatureAlgorithm().RLen(this->GetAbstractGroupParameters())
995
			+ GetSignatureAlgorithm().SLen(GetAbstractGroupParameters());
996
			+ GetSignatureAlgorithm().SLen(this->GetAbstractGroupParameters());
996
	}
997
	}
997
	unsigned int MaxRecoverableLength() const 
998
	unsigned int MaxRecoverableLength() const 
998
		{return GetMessageEncodingInterface().MaxRecoverableLength(0, GetHashIdentifier().second, GetDigestSize());}
999
		{return GetMessageEncodingInterface().MaxRecoverableLength(0, GetHashIdentifier().second, GetDigestSize());}
Lines 1008-1014 Link Here
1008
1009
1009
protected:
1010
protected:
1010
	unsigned int MessageRepresentativeLength() const {return BitsToBytes(MessageRepresentativeBitLength());}
1011
	unsigned int MessageRepresentativeLength() const {return BitsToBytes(MessageRepresentativeBitLength());}
1011
	unsigned int MessageRepresentativeBitLength() const {return GetAbstractGroupParameters().GetSubgroupOrder().BitCount();}
1012
	unsigned int MessageRepresentativeBitLength() const {return this->GetAbstractGroupParameters().GetSubgroupOrder().BitCount();}
1012
1013
1013
	virtual const DL_ElgamalLikeSignatureAlgorithm<CPP_TYPENAME KEY_INTERFACE::Element> & GetSignatureAlgorithm() const =0;
1014
	virtual const DL_ElgamalLikeSignatureAlgorithm<CPP_TYPENAME KEY_INTERFACE::Element> & GetSignatureAlgorithm() const =0;
1014
	virtual const PK_SignatureMessageEncodingMethod & GetMessageEncodingInterface() const =0;
1015
	virtual const PK_SignatureMessageEncodingMethod & GetMessageEncodingInterface() const =0;
Lines 1024-1032 Link Here
1024
	// for validation testing
1025
	// for validation testing
1025
	void RawSign(const Integer &k, const Integer &e, Integer &r, Integer &s) const
1026
	void RawSign(const Integer &k, const Integer &e, Integer &r, Integer &s) const
1026
	{
1027
	{
1027
		const DL_ElgamalLikeSignatureAlgorithm<T> &alg = GetSignatureAlgorithm();
1028
		const DL_ElgamalLikeSignatureAlgorithm<T> &alg = this->GetSignatureAlgorithm();
1028
		const DL_GroupParameters<T> &params = GetAbstractGroupParameters();
1029
		const DL_GroupParameters<T> &params = this->GetAbstractGroupParameters();
1029
		const DL_PrivateKey<T> &key = GetKeyInterface();
1030
		const DL_PrivateKey<T> &key = this->GetKeyInterface();
1030
1031
1031
		r = params.ConvertElementToInteger(params.ExponentiateBase(k));
1032
		r = params.ConvertElementToInteger(params.ExponentiateBase(k));
1032
		alg.Sign(params, key.GetPrivateExponent(), k, e, r, s);
1033
		alg.Sign(params, key.GetPrivateExponent(), k, e, r, s);
Lines 1036-1042 Link Here
1036
	{
1037
	{
1037
		PK_MessageAccumulatorBase &ma = static_cast<PK_MessageAccumulatorBase &>(messageAccumulator);
1038
		PK_MessageAccumulatorBase &ma = static_cast<PK_MessageAccumulatorBase &>(messageAccumulator);
1038
		ma.m_recoverableMessage.Assign(recoverableMessage, recoverableMessageLength);
1039
		ma.m_recoverableMessage.Assign(recoverableMessage, recoverableMessageLength);
1039
		GetMessageEncodingInterface().ProcessRecoverableMessage(ma.AccessHash(), 
1040
		this->GetMessageEncodingInterface().ProcessRecoverableMessage(ma.AccessHash(), 
1040
			recoverableMessage, recoverableMessageLength, 
1041
			recoverableMessage, recoverableMessageLength, 
1041
			ma.m_presignature, ma.m_presignature.size(),
1042
			ma.m_presignature, ma.m_presignature.size(),
1042
			ma.m_semisignature);
1043
			ma.m_semisignature);
Lines 1044-1067 Link Here
1044
1045
1045
	unsigned int SignAndRestart(RandomNumberGenerator &rng, PK_MessageAccumulator &messageAccumulator, byte *signature, bool restart) const
1046
	unsigned int SignAndRestart(RandomNumberGenerator &rng, PK_MessageAccumulator &messageAccumulator, byte *signature, bool restart) const
1046
	{
1047
	{
1047
		GetMaterial().DoQuickSanityCheck();
1048
		this->GetMaterial().DoQuickSanityCheck();
1048
1049
1049
		PK_MessageAccumulatorBase &ma = static_cast<PK_MessageAccumulatorBase &>(messageAccumulator);
1050
		PK_MessageAccumulatorBase &ma = static_cast<PK_MessageAccumulatorBase &>(messageAccumulator);
1050
		const DL_ElgamalLikeSignatureAlgorithm<T> &alg = GetSignatureAlgorithm();
1051
		const DL_ElgamalLikeSignatureAlgorithm<T> &alg = this->GetSignatureAlgorithm();
1051
		const DL_GroupParameters<T> &params = GetAbstractGroupParameters();
1052
		const DL_GroupParameters<T> &params = this->GetAbstractGroupParameters();
1052
		const DL_PrivateKey<T> &key = GetKeyInterface();
1053
		const DL_PrivateKey<T> &key = this->GetKeyInterface();
1053
1054
1054
		SecByteBlock representative(MessageRepresentativeLength());
1055
		SecByteBlock representative(this->MessageRepresentativeLength());
1055
		GetMessageEncodingInterface().ComputeMessageRepresentative(
1056
		this->GetMessageEncodingInterface().ComputeMessageRepresentative(
1056
			rng, 
1057
			rng, 
1057
			ma.m_recoverableMessage, ma.m_recoverableMessage.size(), 
1058
			ma.m_recoverableMessage, ma.m_recoverableMessage.size(), 
1058
			ma.AccessHash(), GetHashIdentifier(), ma.m_empty, 
1059
			ma.AccessHash(), this->GetHashIdentifier(), ma.m_empty, 
1059
			representative, MessageRepresentativeBitLength());
1060
			representative, this->MessageRepresentativeBitLength());
1060
		ma.m_empty = true;
1061
		ma.m_empty = true;
1061
		Integer e(representative, representative.size());
1062
		Integer e(representative, representative.size());
1062
1063
1063
		Integer r;
1064
		Integer r;
1064
		if (MaxRecoverableLength() > 0)
1065
		if (this->MaxRecoverableLength() > 0)
1065
			r.Decode(ma.m_semisignature, ma.m_semisignature.size());
1066
			r.Decode(ma.m_semisignature, ma.m_semisignature.size());
1066
		else
1067
		else
1067
			r.Decode(ma.m_presignature, ma.m_presignature.size());
1068
			r.Decode(ma.m_presignature, ma.m_presignature.size());
Lines 1075-1088 Link Here
1075
		if (restart)
1076
		if (restart)
1076
			RestartMessageAccumulator(rng, ma);
1077
			RestartMessageAccumulator(rng, ma);
1077
1078
1078
		return SignatureLength();
1079
		return this->SignatureLength();
1079
	}
1080
	}
1080
1081
1081
protected:
1082
protected:
1082
	void RestartMessageAccumulator(RandomNumberGenerator &rng, PK_MessageAccumulatorBase &ma) const
1083
	void RestartMessageAccumulator(RandomNumberGenerator &rng, PK_MessageAccumulatorBase &ma) const
1083
	{
1084
	{
1084
		const DL_ElgamalLikeSignatureAlgorithm<T> &alg = GetSignatureAlgorithm();
1085
		const DL_ElgamalLikeSignatureAlgorithm<T> &alg = this->GetSignatureAlgorithm();
1085
		const DL_GroupParameters<T> &params = GetAbstractGroupParameters();
1086
		const DL_GroupParameters<T> &params = this->GetAbstractGroupParameters();
1086
		ma.m_k.Randomize(rng, 1, params.GetSubgroupOrder()-1);
1087
		ma.m_k.Randomize(rng, 1, params.GetSubgroupOrder()-1);
1087
		ma.m_presignature.New(params.GetEncodedElementSize(false));
1088
		ma.m_presignature.New(params.GetEncodedElementSize(false));
1088
		params.ConvertElementToInteger(params.ExponentiateBase(ma.m_k)).Encode(ma.m_presignature, ma.m_presignature.size());
1089
		params.ConvertElementToInteger(params.ExponentiateBase(ma.m_k)).Encode(ma.m_presignature, ma.m_presignature.size());
Lines 1097-1125 Link Here
1097
	void InputSignature(PK_MessageAccumulator &messageAccumulator, const byte *signature, unsigned int signatureLength) const
1098
	void InputSignature(PK_MessageAccumulator &messageAccumulator, const byte *signature, unsigned int signatureLength) const
1098
	{
1099
	{
1099
		PK_MessageAccumulatorBase &ma = static_cast<PK_MessageAccumulatorBase &>(messageAccumulator);
1100
		PK_MessageAccumulatorBase &ma = static_cast<PK_MessageAccumulatorBase &>(messageAccumulator);
1100
		const DL_ElgamalLikeSignatureAlgorithm<T> &alg = GetSignatureAlgorithm();
1101
		const DL_ElgamalLikeSignatureAlgorithm<T> &alg = this->GetSignatureAlgorithm();
1101
		const DL_GroupParameters<T> &params = GetAbstractGroupParameters();
1102
		const DL_GroupParameters<T> &params = this->GetAbstractGroupParameters();
1102
1103
1103
		unsigned int rLen = alg.RLen(params);
1104
		unsigned int rLen = alg.RLen(params);
1104
		ma.m_semisignature.Assign(signature, rLen);
1105
		ma.m_semisignature.Assign(signature, rLen);
1105
		ma.m_s.Decode(signature+rLen, alg.SLen(params));
1106
		ma.m_s.Decode(signature+rLen, alg.SLen(params));
1106
1107
1107
		GetMessageEncodingInterface().ProcessSemisignature(ma.AccessHash(), ma.m_semisignature, ma.m_semisignature.size());
1108
		this->GetMessageEncodingInterface().ProcessSemisignature(ma.AccessHash(), ma.m_semisignature, ma.m_semisignature.size());
1108
	}
1109
	}
1109
	
1110
	
1110
	bool VerifyAndRestart(PK_MessageAccumulator &messageAccumulator) const
1111
	bool VerifyAndRestart(PK_MessageAccumulator &messageAccumulator) const
1111
	{
1112
	{
1112
		GetMaterial().DoQuickSanityCheck();
1113
		this->GetMaterial().DoQuickSanityCheck();
1113
1114
1114
		PK_MessageAccumulatorBase &ma = static_cast<PK_MessageAccumulatorBase &>(messageAccumulator);
1115
		PK_MessageAccumulatorBase &ma = static_cast<PK_MessageAccumulatorBase &>(messageAccumulator);
1115
		const DL_ElgamalLikeSignatureAlgorithm<T> &alg = GetSignatureAlgorithm();
1116
		const DL_ElgamalLikeSignatureAlgorithm<T> &alg = this->GetSignatureAlgorithm();
1116
		const DL_GroupParameters<T> &params = GetAbstractGroupParameters();
1117
		const DL_GroupParameters<T> &params = this->GetAbstractGroupParameters();
1117
		const DL_PublicKey<T> &key = GetKeyInterface();
1118
		const DL_PublicKey<T> &key = this->GetKeyInterface();
1118
1119
1119
		SecByteBlock representative(MessageRepresentativeLength());
1120
		SecByteBlock representative(this->MessageRepresentativeLength());
1120
		GetMessageEncodingInterface().ComputeMessageRepresentative(NullRNG(), ma.m_recoverableMessage, ma.m_recoverableMessage.size(), 
1121
		this->GetMessageEncodingInterface().ComputeMessageRepresentative(NullRNG(), ma.m_recoverableMessage, ma.m_recoverableMessage.size(), 
1121
			ma.AccessHash(), GetHashIdentifier(), ma.m_empty,
1122
			ma.AccessHash(), this->GetHashIdentifier(), ma.m_empty,
1122
			representative, MessageRepresentativeBitLength());
1123
			representative, this->MessageRepresentativeBitLength());
1123
		ma.m_empty = true;
1124
		ma.m_empty = true;
1124
		Integer e(representative, representative.size());
1125
		Integer e(representative, representative.size());
1125
1126
Lines 1129-1147 Link Here
1129
1130
1130
	DecodingResult RecoverAndRestart(byte *recoveredMessage, PK_MessageAccumulator &messageAccumulator) const
1131
	DecodingResult RecoverAndRestart(byte *recoveredMessage, PK_MessageAccumulator &messageAccumulator) const
1131
	{
1132
	{
1132
		GetMaterial().DoQuickSanityCheck();
1133
		this->GetMaterial().DoQuickSanityCheck();
1133
1134
1134
		PK_MessageAccumulatorBase &ma = static_cast<PK_MessageAccumulatorBase &>(messageAccumulator);
1135
		PK_MessageAccumulatorBase &ma = static_cast<PK_MessageAccumulatorBase &>(messageAccumulator);
1135
		const DL_ElgamalLikeSignatureAlgorithm<T> &alg = GetSignatureAlgorithm();
1136
		const DL_ElgamalLikeSignatureAlgorithm<T> &alg = this->GetSignatureAlgorithm();
1136
		const DL_GroupParameters<T> &params = GetAbstractGroupParameters();
1137
		const DL_GroupParameters<T> &params = this->GetAbstractGroupParameters();
1137
		const DL_PublicKey<T> &key = GetKeyInterface();
1138
		const DL_PublicKey<T> &key = this->GetKeyInterface();
1138
1139
1139
		SecByteBlock representative(MessageRepresentativeLength());
1140
		SecByteBlock representative(this->MessageRepresentativeLength());
1140
		GetMessageEncodingInterface().ComputeMessageRepresentative(
1141
		this->GetMessageEncodingInterface().ComputeMessageRepresentative(
1141
			NullRNG(), 
1142
			NullRNG(), 
1142
			ma.m_recoverableMessage, ma.m_recoverableMessage.size(), 
1143
			ma.m_recoverableMessage, ma.m_recoverableMessage.size(), 
1143
			ma.AccessHash(), GetHashIdentifier(), ma.m_empty,
1144
			ma.AccessHash(), this->GetHashIdentifier(), ma.m_empty,
1144
			representative, MessageRepresentativeBitLength());
1145
			representative, this->MessageRepresentativeBitLength());
1145
		ma.m_empty = true;
1146
		ma.m_empty = true;
1146
		Integer e(representative, representative.size());
1147
		Integer e(representative, representative.size());
1147
1148
Lines 1149-1156 Link Here
1149
		Integer r(ma.m_semisignature, ma.m_semisignature.size());
1150
		Integer r(ma.m_semisignature, ma.m_semisignature.size());
1150
		alg.RecoverPresignature(params, key, r, ma.m_s).Encode(ma.m_presignature, ma.m_presignature.size());
1151
		alg.RecoverPresignature(params, key, r, ma.m_s).Encode(ma.m_presignature, ma.m_presignature.size());
1151
1152
1152
		return GetMessageEncodingInterface().RecoverMessageFromSemisignature(
1153
		return this->GetMessageEncodingInterface().RecoverMessageFromSemisignature(
1153
			ma.AccessHash(), GetHashIdentifier(),
1154
			ma.AccessHash(), this->GetHashIdentifier(),
1154
			ma.m_presignature, ma.m_presignature.size(),
1155
			ma.m_presignature, ma.m_presignature.size(),
1155
			ma.m_semisignature, ma.m_semisignature.size(),
1156
			ma.m_semisignature, ma.m_semisignature.size(),
1156
			recoveredMessage);
1157
			recoveredMessage);
Lines 1166-1179 Link Here
1166
1167
1167
	unsigned int MaxPlaintextLength(unsigned int cipherTextLength) const
1168
	unsigned int MaxPlaintextLength(unsigned int cipherTextLength) const
1168
	{
1169
	{
1169
		unsigned int minLen = GetAbstractGroupParameters().GetEncodedElementSize(true);
1170
		unsigned int minLen = this->GetAbstractGroupParameters().GetEncodedElementSize(true);
1170
		return cipherTextLength < minLen ? 0 : GetSymmetricEncryptionAlgorithm().GetMaxSymmetricPlaintextLength(cipherTextLength - minLen);
1171
		return cipherTextLength < minLen ? 0 : GetSymmetricEncryptionAlgorithm().GetMaxSymmetricPlaintextLength(cipherTextLength - minLen);
1171
	}
1172
	}
1172
1173
1173
	unsigned int CiphertextLength(unsigned int plainTextLength) const
1174
	unsigned int CiphertextLength(unsigned int plainTextLength) const
1174
	{
1175
	{
1175
		unsigned int len = GetSymmetricEncryptionAlgorithm().GetSymmetricCiphertextLength(plainTextLength);
1176
		unsigned int len = GetSymmetricEncryptionAlgorithm().GetSymmetricCiphertextLength(plainTextLength);
1176
		return len == 0 ? 0 : GetAbstractGroupParameters().GetEncodedElementSize(true) + len;
1177
		return len == 0 ? 0 : this->GetAbstractGroupParameters().GetEncodedElementSize(true) + len;
1177
	}
1178
	}
1178
1179
1179
protected:
1180
protected:
Lines 1193-1203 Link Here
1193
	{
1194
	{
1194
		try
1195
		try
1195
		{
1196
		{
1196
			const DL_KeyAgreementAlgorithm<T> &agreeAlg = GetKeyAgreementAlgorithm();
1197
			const DL_KeyAgreementAlgorithm<T> &agreeAlg = this->GetKeyAgreementAlgorithm();
1197
			const DL_KeyDerivationAlgorithm<T> &derivAlg = GetKeyDerivationAlgorithm();
1198
			const DL_KeyDerivationAlgorithm<T> &derivAlg = this->GetKeyDerivationAlgorithm();
1198
			const DL_SymmetricEncryptionAlgorithm &encAlg = GetSymmetricEncryptionAlgorithm();
1199
			const DL_SymmetricEncryptionAlgorithm &encAlg = this->GetSymmetricEncryptionAlgorithm();
1199
			const DL_GroupParameters<T> &params = GetAbstractGroupParameters();
1200
			const DL_GroupParameters<T> &params = this->GetAbstractGroupParameters();
1200
			const DL_PrivateKey<T> &key = GetKeyInterface();
1201
			const DL_PrivateKey<T> &key = this->GetKeyInterface();
1201
1202
1202
			Element q = params.DecodeElement(cipherText, true);
1203
			Element q = params.DecodeElement(cipherText, true);
1203
			unsigned int elementSize = params.GetEncodedElementSize(true);
1204
			unsigned int elementSize = params.GetEncodedElementSize(true);
Lines 1227-1237 Link Here
1227
1228
1228
	void Encrypt(RandomNumberGenerator &rng, const byte *plainText, unsigned int plainTextLength, byte *cipherText) const
1229
	void Encrypt(RandomNumberGenerator &rng, const byte *plainText, unsigned int plainTextLength, byte *cipherText) const
1229
	{
1230
	{
1230
		const DL_KeyAgreementAlgorithm<T> &agreeAlg = GetKeyAgreementAlgorithm();
1231
		const DL_KeyAgreementAlgorithm<T> &agreeAlg = this->GetKeyAgreementAlgorithm();
1231
		const DL_KeyDerivationAlgorithm<T> &derivAlg = GetKeyDerivationAlgorithm();
1232
		const DL_KeyDerivationAlgorithm<T> &derivAlg = this->GetKeyDerivationAlgorithm();
1232
		const DL_SymmetricEncryptionAlgorithm &encAlg = GetSymmetricEncryptionAlgorithm();
1233
		const DL_SymmetricEncryptionAlgorithm &encAlg = this->GetSymmetricEncryptionAlgorithm();
1233
		const DL_GroupParameters<T> &params = GetAbstractGroupParameters();
1234
		const DL_GroupParameters<T> &params = this->GetAbstractGroupParameters();
1234
		const DL_PublicKey<T> &key = GetKeyInterface();
1235
		const DL_PublicKey<T> &key = this->GetKeyInterface();
1235
1236
1236
		Integer x(rng, Integer::One(), params.GetMaxExponent());
1237
		Integer x(rng, Integer::One(), params.GetMaxExponent());
1237
		Element q = params.ExponentiateBase(x);
1238
		Element q = params.ExponentiateBase(x);
Lines 1307-1313 Link Here
1307
	// for signature scheme
1308
	// for signature scheme
1308
	HashIdentifier GetHashIdentifier() const
1309
	HashIdentifier GetHashIdentifier() const
1309
	{
1310
	{
1310
		typedef CPP_TYPENAME SchemeOptions::MessageEncodingMethod::HashIdentifierLookup::HashIdentifierLookup2<CPP_TYPENAME SchemeOptions::HashFunction> L;
1311
		typedef CPP_TYPENAME SchemeOptions::MessageEncodingMethod::HashIdentifierLookup::template HashIdentifierLookup2<CPP_TYPENAME SchemeOptions::HashFunction> L;
1311
		return L::Lookup();
1312
		return L::Lookup();
1312
	}
1313
	}
1313
	unsigned int GetDigestSize() const
1314
	unsigned int GetDigestSize() const
Lines 1348-1354 Link Here
1348
{
1349
{
1349
public:
1350
public:
1350
	void CopyKeyInto(typename SCHEME_OPTIONS::PublicKey &key) const
1351
	void CopyKeyInto(typename SCHEME_OPTIONS::PublicKey &key) const
1351
		{key = GetKey();}
1352
		{key = this->GetKey();}
1352
};
1353
};
1353
1354
1354
//! .
1355
//! .
Lines 1357-1365 Link Here
1357
{
1358
{
1358
public:
1359
public:
1359
	void CopyKeyInto(typename SCHEME_OPTIONS::PublicKey &key) const
1360
	void CopyKeyInto(typename SCHEME_OPTIONS::PublicKey &key) const
1360
		{GetKey().MakePublicKey(key);}
1361
		{this->GetKey().MakePublicKey(key);}
1361
	void CopyKeyInto(typename SCHEME_OPTIONS::PrivateKey &key) const
1362
	void CopyKeyInto(typename SCHEME_OPTIONS::PrivateKey &key) const
1362
		{key = GetKey();}
1363
		{key = this->GetKey();}
1363
};
1364
};
1364
1365
1365
//! .
1366
//! .
Lines 1369-1375 Link Here
1369
	PK_MessageAccumulator * NewSignatureAccumulator(RandomNumberGenerator &rng = NullRNG()) const
1370
	PK_MessageAccumulator * NewSignatureAccumulator(RandomNumberGenerator &rng = NullRNG()) const
1370
	{
1371
	{
1371
		std::auto_ptr<PK_MessageAccumulatorBase> p(new PK_MessageAccumulatorImpl<CPP_TYPENAME SCHEME_OPTIONS::HashFunction>);
1372
		std::auto_ptr<PK_MessageAccumulatorBase> p(new PK_MessageAccumulatorImpl<CPP_TYPENAME SCHEME_OPTIONS::HashFunction>);
1372
		RestartMessageAccumulator(rng, *p);
1373
		this->RestartMessageAccumulator(rng, *p);
1373
		return p.release();
1374
		return p.release();
1374
	}
1375
	}
1375
};
1376
};
Lines 1518-1536 Link Here
1518
	PK_FinalTemplate() {}
1519
	PK_FinalTemplate() {}
1519
1520
1520
	PK_FinalTemplate(const Integer &v1)
1521
	PK_FinalTemplate(const Integer &v1)
1521
		{AccessKey().Initialize(v1);}
1522
		{this->AccessKey().Initialize(v1);}
1522
1523
1523
	PK_FinalTemplate(const typename BASE::KeyClass &key)  {AccessKey().operator=(key);}
1524
	PK_FinalTemplate(const typename BASE::KeyClass &key)  {this->AccessKey().operator=(key);}
1524
1525
1525
	template <class T>
1526
	template <class T>
1526
	PK_FinalTemplate(const PublicKeyCopier<T> &key)
1527
	PK_FinalTemplate(const PublicKeyCopier<T> &key)
1527
		{key.CopyKeyInto(AccessKey());}
1528
		{key.CopyKeyInto(this->AccessKey());}
1528
1529
1529
	template <class T>
1530
	template <class T>
1530
	PK_FinalTemplate(const PrivateKeyCopier<T> &key)
1531
	PK_FinalTemplate(const PrivateKeyCopier<T> &key)
1531
		{key.CopyKeyInto(AccessKey());}
1532
		{key.CopyKeyInto(this->AccessKey());}
1532
1533
1533
	PK_FinalTemplate(BufferedTransformation &bt) {AccessKey().BERDecode(bt);}
1534
	PK_FinalTemplate(BufferedTransformation &bt) {this->AccessKey().BERDecode(bt);}
1534
1535
1535
#if (defined(_MSC_VER) && _MSC_VER < 1300)
1536
#if (defined(_MSC_VER) && _MSC_VER < 1300)
1536
1537
Lines 1566-1624 Link Here
1566
1567
1567
	template <class T1, class T2>
1568
	template <class T1, class T2>
1568
	PK_FinalTemplate(const T1 &v1, const T2 &v2)
1569
	PK_FinalTemplate(const T1 &v1, const T2 &v2)
1569
		{AccessKey().Initialize(v1, v2);}
1570
		{this->AccessKey().Initialize(v1, v2);}
1570
1571
1571
	template <class T1, class T2, class T3>
1572
	template <class T1, class T2, class T3>
1572
	PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3)
1573
	PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3)
1573
		{AccessKey().Initialize(v1, v2, v3);}
1574
		{this->AccessKey().Initialize(v1, v2, v3);}
1574
	
1575
	
1575
	template <class T1, class T2, class T3, class T4>
1576
	template <class T1, class T2, class T3, class T4>
1576
	PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4)
1577
	PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4)
1577
		{AccessKey().Initialize(v1, v2, v3, v4);}
1578
		{this->AccessKey().Initialize(v1, v2, v3, v4);}
1578
1579
1579
	template <class T1, class T2, class T3, class T4, class T5>
1580
	template <class T1, class T2, class T3, class T4, class T5>
1580
	PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5)
1581
	PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5)
1581
		{AccessKey().Initialize(v1, v2, v3, v4, v5);}
1582
		{this->AccessKey().Initialize(v1, v2, v3, v4, v5);}
1582
1583
1583
	template <class T1, class T2, class T3, class T4, class T5, class T6>
1584
	template <class T1, class T2, class T3, class T4, class T5, class T6>
1584
	PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6)
1585
	PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6)
1585
		{AccessKey().Initialize(v1, v2, v3, v4, v5, v6);}
1586
		{this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6);}
1586
1587
1587
	template <class T1, class T2, class T3, class T4, class T5, class T6, class T7>
1588
	template <class T1, class T2, class T3, class T4, class T5, class T6, class T7>
1588
	PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6, const T7 &v7)
1589
	PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6, const T7 &v7)
1589
		{AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7);}
1590
		{this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7);}
1590
1591
1591
	template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
1592
	template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
1592
	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)
1593
	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)
1593
		{AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7, v8);}
1594
		{this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7, v8);}
1594
1595
1595
	template <class T1, class T2>
1596
	template <class T1, class T2>
1596
	PK_FinalTemplate(T1 &v1, const T2 &v2)
1597
	PK_FinalTemplate(T1 &v1, const T2 &v2)
1597
		{AccessKey().Initialize(v1, v2);}
1598
		{this->AccessKey().Initialize(v1, v2);}
1598
1599
1599
	template <class T1, class T2, class T3>
1600
	template <class T1, class T2, class T3>
1600
	PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3)
1601
	PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3)
1601
		{AccessKey().Initialize(v1, v2, v3);}
1602
		{this->AccessKey().Initialize(v1, v2, v3);}
1602
	
1603
	
1603
	template <class T1, class T2, class T3, class T4>
1604
	template <class T1, class T2, class T3, class T4>
1604
	PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4)
1605
	PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4)
1605
		{AccessKey().Initialize(v1, v2, v3, v4);}
1606
		{this->AccessKey().Initialize(v1, v2, v3, v4);}
1606
1607
1607
	template <class T1, class T2, class T3, class T4, class T5>
1608
	template <class T1, class T2, class T3, class T4, class T5>
1608
	PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5)
1609
	PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5)
1609
		{AccessKey().Initialize(v1, v2, v3, v4, v5);}
1610
		{this->AccessKey().Initialize(v1, v2, v3, v4, v5);}
1610
1611
1611
	template <class T1, class T2, class T3, class T4, class T5, class T6>
1612
	template <class T1, class T2, class T3, class T4, class T5, class T6>
1612
	PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6)
1613
	PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6)
1613
		{AccessKey().Initialize(v1, v2, v3, v4, v5, v6);}
1614
		{this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6);}
1614
1615
1615
	template <class T1, class T2, class T3, class T4, class T5, class T6, class T7>
1616
	template <class T1, class T2, class T3, class T4, class T5, class T6, class T7>
1616
	PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6, const T7 &v7)
1617
	PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6, const T7 &v7)
1617
		{AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7);}
1618
		{this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7);}
1618
1619
1619
	template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
1620
	template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
1620
	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)
1621
	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)
1621
		{AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7, v8);}
1622
		{this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7, v8);}
1622
1623
1623
#endif
1624
#endif
1624
};
1625
};
(-)crypto++-5.1/pwdbased.h (-1 / +1 lines)
Lines 51-57 Link Here
51
template <class T>
51
template <class T>
52
void PKCS5_PBKDF1<T>::DeriveKey(byte *derived, unsigned int derivedLen, const byte *password, unsigned int passwordLen, const byte *salt, unsigned int saltLen, unsigned int iterations) const
52
void PKCS5_PBKDF1<T>::DeriveKey(byte *derived, unsigned int derivedLen, const byte *password, unsigned int passwordLen, const byte *salt, unsigned int saltLen, unsigned int iterations) const
53
{
53
{
54
	assert(derivedLen <= MaxDerivedLength());
54
	assert(derivedLen <= this->MaxDerivedLength());
55
	assert(iterations > 0);
55
	assert(iterations > 0);
56
56
57
	T hash;
57
	T hash;
(-)crypto++-5.1/seckey.h (-5 / +5 lines)
Lines 156-162 Link Here
156
class BlockCipherBaseTemplate : public AlgorithmImpl<SimpleKeyingInterfaceImpl<TwoBases<INFO, INTERFACE> > >
156
class BlockCipherBaseTemplate : public AlgorithmImpl<SimpleKeyingInterfaceImpl<TwoBases<INFO, INTERFACE> > >
157
{
157
{
158
public:
158
public:
159
	unsigned int BlockSize() const {return BLOCKSIZE;}
159
	unsigned int BlockSize() const {return this->BLOCKSIZE;}
160
};
160
};
161
161
162
//! .
162
//! .
Lines 166-176 Link Here
166
public:
166
public:
167
 	BlockCipherTemplate() {}
167
 	BlockCipherTemplate() {}
168
	BlockCipherTemplate(const byte *key)
168
	BlockCipherTemplate(const byte *key)
169
		{SetKey(key, DEFAULT_KEYLENGTH);}
169
		{SetKey(key, this->DEFAULT_KEYLENGTH);}
170
	BlockCipherTemplate(const byte *key, unsigned int length)
170
	BlockCipherTemplate(const byte *key, unsigned int length)
171
		{SetKey(key, length);}
171
		{SetKey(key, length);}
172
	BlockCipherTemplate(const byte *key, unsigned int length, unsigned int rounds)
172
	BlockCipherTemplate(const byte *key, unsigned int length, unsigned int rounds)
173
		{SetKeyWithRounds(key, length, rounds);}
173
		{this->SetKeyWithRounds(key, length, rounds);}
174
174
175
	bool IsForwardTransformation() const {return DIR == ENCRYPTION;}
175
	bool IsForwardTransformation() const {return DIR == ENCRYPTION;}
176
176
Lines 194-204 Link Here
194
public:
194
public:
195
 	MessageAuthenticationCodeTemplate() {}
195
 	MessageAuthenticationCodeTemplate() {}
196
	MessageAuthenticationCodeTemplate(const byte *key)
196
	MessageAuthenticationCodeTemplate(const byte *key)
197
		{SetKey(key, DEFAULT_KEYLENGTH);}
197
		{SetKey(key, this->DEFAULT_KEYLENGTH);}
198
	MessageAuthenticationCodeTemplate(const byte *key, unsigned int length)
198
	MessageAuthenticationCodeTemplate(const byte *key, unsigned int length)
199
		{SetKey(key, length);}
199
		{SetKey(key, length);}
200
200
201
	std::string AlgorithmName() const {return StaticAlgorithmName();}
201
	std::string AlgorithmName() const {return this->StaticAlgorithmName();}
202
202
203
	void SetKey(const byte *key, unsigned int length, const NameValuePairs &param = g_nullNameValuePairs)
203
	void SetKey(const byte *key, unsigned int length, const NameValuePairs &param = g_nullNameValuePairs)
204
	{
204
	{
(-)crypto++-5.1/shark.cpp (-1 / +1 lines)
Lines 82-88 Link Here
82
	for (unsigned int i=0; i<DEFAULT_ROUNDS; i++)
82
	for (unsigned int i=0; i<DEFAULT_ROUNDS; i++)
83
		m_roundKeys[i] = cbox[0][i];
83
		m_roundKeys[i] = cbox[0][i];
84
84
85
	m_roundKeys[DEFAULT_ROUNDS] = SHARKTransform(cbox[0][DEFAULT_ROUNDS]);
85
	((word64*)m_roundKeys)[DEFAULT_ROUNDS] = SHARKTransform(cbox[0][DEFAULT_ROUNDS]);
86
86
87
#ifdef IS_LITTLE_ENDIAN
87
#ifdef IS_LITTLE_ENDIAN
88
	m_roundKeys[0] = ByteReverse(m_roundKeys[0]);
88
	m_roundKeys[0] = ByteReverse(m_roundKeys[0]);
(-)crypto++-5.1/simple.h (-9 / +9 lines)
Lines 68-74 Link Here
68
	Unflushable() {}
68
	Unflushable() {}
69
	Unflushable(BufferedTransformation *q) : T(q) {}
69
	Unflushable(BufferedTransformation *q) : T(q) {}
70
	bool Flush(bool completeFlush, int propagation=-1, bool blocking=true)
70
	bool Flush(bool completeFlush, int propagation=-1, bool blocking=true)
71
		{return ChannelFlush(NULL_CHANNEL, completeFlush, propagation);}
71
		{return ChannelFlush(this->NULL_CHANNEL, completeFlush, propagation);}
72
	bool IsolatedFlush(bool hardFlush, bool blocking)
72
	bool IsolatedFlush(bool hardFlush, bool blocking)
73
		{assert(false); return false;}
73
		{assert(false); return false;}
74
	bool ChannelFlush(const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true)
74
	bool ChannelFlush(const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true)
Lines 77-83 Link Here
77
			throw CannotFlush("Unflushable<T>: this object has buffered input that cannot be flushed");
77
			throw CannotFlush("Unflushable<T>: this object has buffered input that cannot be flushed");
78
		else 
78
		else 
79
		{
79
		{
80
			BufferedTransformation *attached = AttachedTransformation();
80
			BufferedTransformation *attached = this->AttachedTransformation();
81
			return attached && propagation ? attached->ChannelFlush(channel, hardFlush, propagation-1, blocking) : false;
81
			return attached && propagation ? attached->ChannelFlush(channel, hardFlush, propagation-1, blocking) : false;
82
		}
82
		}
83
	}
83
	}
Lines 131-154 Link Here
131
	Multichannel(BufferedTransformation *q) : CustomSignalPropagation<T>(q) {}
131
	Multichannel(BufferedTransformation *q) : CustomSignalPropagation<T>(q) {}
132
132
133
	void Initialize(const NameValuePairs &parameters, int propagation)
133
	void Initialize(const NameValuePairs &parameters, int propagation)
134
		{ChannelInitialize(NULL_CHANNEL, parameters, propagation);}
134
		{ChannelInitialize(this->NULL_CHANNEL, parameters, propagation);}
135
	bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)
135
	bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)
136
		{return ChannelFlush(NULL_CHANNEL, hardFlush, propagation, blocking);}
136
		{return ChannelFlush(this->NULL_CHANNEL, hardFlush, propagation, blocking);}
137
	bool MessageSeriesEnd(int propagation=-1, bool blocking=true)
137
	bool MessageSeriesEnd(int propagation=-1, bool blocking=true)
138
		{return ChannelMessageSeriesEnd(NULL_CHANNEL, propagation, blocking);}
138
		{return ChannelMessageSeriesEnd(this->NULL_CHANNEL, propagation, blocking);}
139
	byte * CreatePutSpace(unsigned int &size)
139
	byte * CreatePutSpace(unsigned int &size)
140
		{return ChannelCreatePutSpace(NULL_CHANNEL, size);}
140
		{return ChannelCreatePutSpace(this->NULL_CHANNEL, size);}
141
	unsigned int Put2(const byte *begin, unsigned int length, int messageEnd, bool blocking)
141
	unsigned int Put2(const byte *begin, unsigned int length, int messageEnd, bool blocking)
142
		{return ChannelPut2(NULL_CHANNEL, begin, length, messageEnd, blocking);}
142
		{return ChannelPut2(this->NULL_CHANNEL, begin, length, messageEnd, blocking);}
143
	unsigned int PutModifiable2(byte *inString, unsigned int length, int messageEnd, bool blocking)
143
	unsigned int PutModifiable2(byte *inString, unsigned int length, int messageEnd, bool blocking)
144
		{return ChannelPutModifiable2(NULL_CHANNEL, inString, length, messageEnd, blocking);}
144
		{return ChannelPutModifiable2(this->NULL_CHANNEL, inString, length, messageEnd, blocking);}
145
145
146
//	void ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1)
146
//	void ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1)
147
//		{PropagateMessageSeriesEnd(propagation, channel);}
147
//		{PropagateMessageSeriesEnd(propagation, channel);}
148
	byte * ChannelCreatePutSpace(const std::string &channel, unsigned int &size)
148
	byte * ChannelCreatePutSpace(const std::string &channel, unsigned int &size)
149
		{size = 0; return NULL;}
149
		{size = 0; return NULL;}
150
	bool ChannelPutModifiable(const std::string &channel, byte *inString, unsigned int length)
150
	bool ChannelPutModifiable(const std::string &channel, byte *inString, unsigned int length)
151
		{ChannelPut(channel, inString, length); return false;}
151
		{this->ChannelPut(channel, inString, length); return false;}
152
152
153
	virtual unsigned int ChannelPut2(const std::string &channel, const byte *begin, unsigned int length, int messageEnd, bool blocking) =0;
153
	virtual unsigned int ChannelPut2(const std::string &channel, const byte *begin, unsigned int length, int messageEnd, bool blocking) =0;
154
	unsigned int ChannelPutModifiable2(const std::string &channel, byte *begin, unsigned int length, int messageEnd, bool blocking)
154
	unsigned int ChannelPutModifiable2(const std::string &channel, byte *begin, unsigned int length, int messageEnd, bool blocking)
(-)crypto++-5.1/smartptr.h (-5 / +6 lines)
Lines 2-7 Link Here
2
#define CRYPTOPP_SMARTPTR_H
2
#define CRYPTOPP_SMARTPTR_H
3
3
4
#include "config.h"
4
#include "config.h"
5
#include "misc.h"
5
#include <algorithm>
6
#include <algorithm>
6
7
7
NAMESPACE_BEGIN(CryptoPP)
8
NAMESPACE_BEGIN(CryptoPP)
Lines 54-67 Link Here
54
	value_ptr<T>& operator=(const value_ptr<T>& rhs);
55
	value_ptr<T>& operator=(const value_ptr<T>& rhs);
55
	bool operator==(const value_ptr<T>& rhs)
56
	bool operator==(const value_ptr<T>& rhs)
56
	{
57
	{
57
		return (!m_p && !rhs.m_p) || (m_p && rhs.m_p && *m_p == *rhs.m_p);
58
		return (!this->m_p && !rhs.m_p) || (this->m_p && rhs.m_p && *this->m_p == *rhs.m_p);
58
	}
59
	}
59
};
60
};
60
61
61
template <class T> value_ptr<T>& value_ptr<T>::operator=(const value_ptr<T>& rhs)
62
template <class T> value_ptr<T>& value_ptr<T>::operator=(const value_ptr<T>& rhs)
62
{
63
{
63
	T *old_p = m_p;
64
	T *old_p = this->m_p;
64
	m_p = rhs.m_p ? new T(*rhs.m_p) : NULL;
65
	this->m_p = rhs.m_p ? new T(*rhs.m_p) : NULL;
65
	delete old_p;
66
	delete old_p;
66
	return *this;
67
	return *this;
67
}
68
}
Lines 81-88 Link Here
81
82
82
template <class T> clonable_ptr<T>& clonable_ptr<T>::operator=(const clonable_ptr<T>& rhs)
83
template <class T> clonable_ptr<T>& clonable_ptr<T>::operator=(const clonable_ptr<T>& rhs)
83
{
84
{
84
	T *old_p = m_p;
85
	T *old_p = this->m_p;
85
	m_p = rhs.m_p ? rhs.m_p->Clone() : NULL;
86
	this->m_p = rhs.m_p ? rhs.m_p->Clone() : NULL;
86
	delete old_p;
87
	delete old_p;
87
	return *this;
88
	return *this;
88
}
89
}
(-)crypto++-5.1/square.cpp (-1 / +1 lines)
Lines 62-68 Link Here
62
		for (int i = 0; i < ROUNDS/2; i++)
62
		for (int i = 0; i < ROUNDS/2; i++)
63
			for (int j = 0; j < 4; j++)
63
			for (int j = 0; j < 4; j++)
64
				std::swap(roundkeys[i][j], roundkeys[ROUNDS-i][j]);
64
				std::swap(roundkeys[i][j], roundkeys[ROUNDS-i][j]);
65
		SquareTransform (roundkeys[ROUNDS], roundkeys[ROUNDS]);
65
		SquareTransform (((word32(*)[4])roundkeys)[ROUNDS], ((word32(*)[4])roundkeys)[ROUNDS]);
66
	}
66
	}
67
}
67
}
68
68
(-)crypto++-5.1/strciphr.cpp (-6 / +6 lines)
Lines 8-14 Link Here
8
template <class S>
8
template <class S>
9
byte AdditiveCipherTemplate<S>::GenerateByte()
9
byte AdditiveCipherTemplate<S>::GenerateByte()
10
{
10
{
11
	PolicyInterface &policy = AccessPolicy();
11
	PolicyInterface &policy = this->AccessPolicy();
12
12
13
	if (m_leftOver == 0)
13
	if (m_leftOver == 0)
14
	{
14
	{
Lines 37-43 Link Here
37
37
38
	assert(m_leftOver == 0);
38
	assert(m_leftOver == 0);
39
39
40
	PolicyInterface &policy = AccessPolicy();
40
	PolicyInterface &policy = this->AccessPolicy();
41
	unsigned int bytesPerIteration = policy.GetBytesPerIteration();
41
	unsigned int bytesPerIteration = policy.GetBytesPerIteration();
42
	unsigned int alignment = policy.GetAlignment();
42
	unsigned int alignment = policy.GetAlignment();
43
43
Lines 81-87 Link Here
81
template <class S>
81
template <class S>
82
void AdditiveCipherTemplate<S>::Resynchronize(const byte *iv)
82
void AdditiveCipherTemplate<S>::Resynchronize(const byte *iv)
83
{
83
{
84
	PolicyInterface &policy = AccessPolicy();
84
	PolicyInterface &policy = this->AccessPolicy();
85
	m_leftOver = 0;
85
	m_leftOver = 0;
86
	m_buffer.New(GetBufferByteSize(policy));
86
	m_buffer.New(GetBufferByteSize(policy));
87
	policy.CipherResynchronize(m_buffer, iv);
87
	policy.CipherResynchronize(m_buffer, iv);
Lines 90-96 Link Here
90
template <class BASE>
90
template <class BASE>
91
void AdditiveCipherTemplate<BASE>::Seek(dword position)
91
void AdditiveCipherTemplate<BASE>::Seek(dword position)
92
{
92
{
93
	PolicyInterface &policy = AccessPolicy();
93
	PolicyInterface &policy = this->AccessPolicy();
94
	unsigned int bytesPerIteration = policy.GetBytesPerIteration();
94
	unsigned int bytesPerIteration = policy.GetBytesPerIteration();
95
95
96
	policy.SeekToIteration(position / bytesPerIteration);
96
	policy.SeekToIteration(position / bytesPerIteration);
Lines 108-114 Link Here
108
template <class BASE>
108
template <class BASE>
109
void CFB_CipherTemplate<BASE>::Resynchronize(const byte *iv)
109
void CFB_CipherTemplate<BASE>::Resynchronize(const byte *iv)
110
{
110
{
111
	PolicyInterface &policy = AccessPolicy();
111
	PolicyInterface &policy = this->AccessPolicy();
112
	policy.CipherResynchronize(iv);
112
	policy.CipherResynchronize(iv);
113
	m_leftOver = policy.GetBytesPerIteration();
113
	m_leftOver = policy.GetBytesPerIteration();
114
}
114
}
Lines 116-122 Link Here
116
template <class BASE>
116
template <class BASE>
117
void CFB_CipherTemplate<BASE>::ProcessData(byte *outString, const byte *inString, unsigned int length)
117
void CFB_CipherTemplate<BASE>::ProcessData(byte *outString, const byte *inString, unsigned int length)
118
{
118
{
119
	PolicyInterface &policy = AccessPolicy();
119
	PolicyInterface &policy = this->AccessPolicy();
120
	unsigned int bytesPerIteration = policy.GetBytesPerIteration();
120
	unsigned int bytesPerIteration = policy.GetBytesPerIteration();
121
	unsigned int alignment = policy.GetAlignment();
121
	unsigned int alignment = policy.GetAlignment();
122
	byte *reg = policy.GetRegisterBegin();
122
	byte *reg = policy.GetRegisterBegin();
(-)crypto++-5.1/strciphr.h (-12 / +12 lines)
Lines 123-134 Link Here
123
    byte GenerateByte();
123
    byte GenerateByte();
124
    void ProcessData(byte *outString, const byte *inString, unsigned int length);
124
    void ProcessData(byte *outString, const byte *inString, unsigned int length);
125
	void Resynchronize(const byte *iv);
125
	void Resynchronize(const byte *iv);
126
	unsigned int OptimalBlockSize() const {return GetPolicy().GetBytesPerIteration();}
126
	unsigned int OptimalBlockSize() const {return this->GetPolicy().GetBytesPerIteration();}
127
	unsigned int GetOptimalNextBlockSize() const {return m_leftOver;}
127
	unsigned int GetOptimalNextBlockSize() const {return m_leftOver;}
128
	unsigned int OptimalDataAlignment() const {return GetPolicy().GetAlignment();}
128
	unsigned int OptimalDataAlignment() const {return this->GetPolicy().GetAlignment();}
129
	bool IsSelfInverting() const {return true;}
129
	bool IsSelfInverting() const {return true;}
130
	bool IsForwardTransformation() const {return true;}
130
	bool IsForwardTransformation() const {return true;}
131
	bool IsRandomAccess() const {return GetPolicy().IsRandomAccess();}
131
	bool IsRandomAccess() const {return this->GetPolicy().IsRandomAccess();}
132
	void Seek(dword position);
132
	void Seek(dword position);
133
133
134
	typedef typename BASE::PolicyInterface PolicyInterface;
134
	typedef typename BASE::PolicyInterface PolicyInterface;
Lines 165-171 Link Here
165
	unsigned int GetAlignment() const {return sizeof(WordType);}
165
	unsigned int GetAlignment() const {return sizeof(WordType);}
166
	unsigned int GetBytesPerIteration() const {return sizeof(WordType) * W;}
166
	unsigned int GetBytesPerIteration() const {return sizeof(WordType) * W;}
167
	bool CanIterate() const {return true;}
167
	bool CanIterate() const {return true;}
168
	void TransformRegister() {Iterate(NULL, NULL, ENCRYPTION, 1);}
168
	void TransformRegister() {this->Iterate(NULL, NULL, ENCRYPTION, 1);}
169
169
170
	template <class B>
170
	template <class B>
171
	struct RegisterOutput
171
	struct RegisterOutput
Lines 215-223 Link Here
215
public:
215
public:
216
	void ProcessData(byte *outString, const byte *inString, unsigned int length);
216
	void ProcessData(byte *outString, const byte *inString, unsigned int length);
217
	void Resynchronize(const byte *iv);
217
	void Resynchronize(const byte *iv);
218
	unsigned int OptimalBlockSize() const {return GetPolicy().GetBytesPerIteration();}
218
	unsigned int OptimalBlockSize() const {return this->GetPolicy().GetBytesPerIteration();}
219
	unsigned int GetOptimalNextBlockSize() const {return m_leftOver;}
219
	unsigned int GetOptimalNextBlockSize() const {return m_leftOver;}
220
	unsigned int OptimalDataAlignment() const {return GetPolicy().GetAlignment();}
220
	unsigned int OptimalDataAlignment() const {return this->GetPolicy().GetAlignment();}
221
	bool IsRandomAccess() const {return false;}
221
	bool IsRandomAccess() const {return false;}
222
	bool IsSelfInverting() const {return false;}
222
	bool IsSelfInverting() const {return false;}
223
223
Lines 251-266 Link Here
251
public:
251
public:
252
 	SymmetricCipherFinalTemplate() {}
252
 	SymmetricCipherFinalTemplate() {}
253
	SymmetricCipherFinalTemplate(const byte *key)
253
	SymmetricCipherFinalTemplate(const byte *key)
254
		{SetKey(key, DEFAULT_KEYLENGTH);}
254
		{SetKey(key, this->DEFAULT_KEYLENGTH);}
255
	SymmetricCipherFinalTemplate(const byte *key, unsigned int length)
255
	SymmetricCipherFinalTemplate(const byte *key, unsigned int length)
256
		{SetKey(key, length);}
256
		{SetKey(key, length);}
257
	SymmetricCipherFinalTemplate(const byte *key, unsigned int length, const byte *iv)
257
	SymmetricCipherFinalTemplate(const byte *key, unsigned int length, const byte *iv)
258
		{SetKey(key, length); Resynchronize(iv);}
258
		{SetKey(key, length); this->Resynchronize(iv);}
259
259
260
	void SetKey(const byte *key, unsigned int length, const NameValuePairs &params = g_nullNameValuePairs)
260
	void SetKey(const byte *key, unsigned int length, const NameValuePairs &params = g_nullNameValuePairs)
261
	{
261
	{
262
		ThrowIfInvalidKeyLength(length);
262
		this->ThrowIfInvalidKeyLength(length);
263
		UncheckedSetKey(params, key, length);
263
		this->UncheckedSetKey(params, key, length);
264
	}
264
	}
265
265
266
	Clonable * Clone() const {return static_cast<SymmetricCipher *>(new SymmetricCipherFinalTemplate<BASE, INFO>(*this));}
266
	Clonable * Clone() const {return static_cast<SymmetricCipher *>(new SymmetricCipherFinalTemplate<BASE, INFO>(*this));}
Lines 269-275 Link Here
269
template <class S>
269
template <class S>
270
void AdditiveCipherTemplate<S>::UncheckedSetKey(const NameValuePairs &params, const byte *key, unsigned int length)
270
void AdditiveCipherTemplate<S>::UncheckedSetKey(const NameValuePairs &params, const byte *key, unsigned int length)
271
{
271
{
272
	PolicyInterface &policy = AccessPolicy();
272
	PolicyInterface &policy = this->AccessPolicy();
273
	policy.CipherSetKey(params, key, length);
273
	policy.CipherSetKey(params, key, length);
274
	m_buffer.New(GetBufferByteSize(policy));
274
	m_buffer.New(GetBufferByteSize(policy));
275
	m_leftOver = 0;
275
	m_leftOver = 0;
Lines 278-284 Link Here
278
template <class BASE>
278
template <class BASE>
279
void CFB_CipherTemplate<BASE>::UncheckedSetKey(const NameValuePairs &params, const byte *key, unsigned int length)
279
void CFB_CipherTemplate<BASE>::UncheckedSetKey(const NameValuePairs &params, const byte *key, unsigned int length)
280
{
280
{
281
	PolicyInterface &policy = AccessPolicy();
281
	PolicyInterface &policy = this->AccessPolicy();
282
	policy.CipherSetKey(params, key, length);
282
	policy.CipherSetKey(params, key, length);
283
	m_leftOver = policy.GetBytesPerIteration();
283
	m_leftOver = policy.GetBytesPerIteration();
284
}
284
}
(-)crypto++-5.1/xormac.h (-42 / +43 lines)
Lines 5-10 Link Here
5
5
6
#include "iterhash.h"
6
#include "iterhash.h"
7
#include "argnames.h"
7
#include "argnames.h"
8
#include "algparam.h"
8
9
9
NAMESPACE_BEGIN(CryptoPP)
10
NAMESPACE_BEGIN(CryptoPP)
10
11
Lines 25-31 Link Here
25
	void Resynchronize(const byte *IV)
26
	void Resynchronize(const byte *IV)
26
	{
27
	{
27
		GetWord(false, BIG_ENDIAN_ORDER, m_counter, IV);
28
		GetWord(false, BIG_ENDIAN_ORDER, m_counter, IV);
28
		Restart();
29
		this->Restart();
29
	}
30
	}
30
	unsigned int IVSize() const
31
	unsigned int IVSize() const
31
		{return 4;}
32
		{return 4;}
Lines 65-90 Link Here
65
public:
66
public:
66
	XMACC() {}
67
	XMACC() {}
67
	XMACC(const byte *key, word32 counter = 0xffffffff)
68
	XMACC(const byte *key, word32 counter = 0xffffffff)
68
		{SetKey(key, KEYLENGTH, MakeParameters(Name::XMACC_Counter(), counter));}
69
		{this->SetKey(key, this->KEYLENGTH, MakeParameters(Name::XMACC_Counter(), counter));}
69
};
70
};
70
71
71
template <class T> void XMACC_Base<T>::CheckedSetKey(void *, Empty empty, const byte *key, unsigned int length, const NameValuePairs &params)
72
template <class T> void XMACC_Base<T>::CheckedSetKey(void *, Empty empty, const byte *key, unsigned int length, const NameValuePairs &params)
72
{
73
{
73
	ThrowIfInvalidKeyLength(length);
74
	this->ThrowIfInvalidKeyLength(length);
74
	m_counter = 0xffffffff;
75
	m_counter = 0xffffffff;
75
	const byte *iv = NULL;
76
	const byte *iv = NULL;
76
	if (params.GetValue(Name::IV(), iv))
77
	if (params.GetValue(Name::IV(), iv))
77
		GetWord(false, BIG_ENDIAN_ORDER, m_counter, iv);
78
		GetWord(false, BIG_ENDIAN_ORDER, m_counter, iv);
78
	else
79
	else
79
		params.GetValue(Name::XMACC_Counter(), m_counter);
80
		params.GetValue(Name::XMACC_Counter(), m_counter);
80
	memcpy(m_key, key, KEYLENGTH);
81
	memcpy(m_key, key, this->KEYLENGTH);
81
	Init();
82
	Init();
82
}
83
}
83
84
84
template <class T> void XMACC_Base<T>::Init()
85
template <class T> void XMACC_Base<T>::Init()
85
{
86
{
86
	m_index = 0x80000000;
87
	m_index = 0x80000000;
87
	memset(m_digest, 0, T::DIGESTSIZE);
88
	memset(this->m_digest, 0, T::DIGESTSIZE);
88
}
89
}
89
90
90
template <class T> inline void XMACC_Base<T>::WriteWord32(byte *output, word32 value)
91
template <class T> inline void XMACC_Base<T>::WriteWord32(byte *output, word32 value)
Lines 103-167 Link Here
103
104
104
template <class T> void XMACC_Base<T>::vTransform(const HashWordType *input)
105
template <class T> void XMACC_Base<T>::vTransform(const HashWordType *input)
105
{
106
{
106
	memcpy(m_buffer, m_key, KEYLENGTH);
107
	memcpy(m_buffer, m_key, this->KEYLENGTH);
107
	WriteWord32((byte *)m_buffer.begin()+KEYLENGTH, ++m_index);
108
	WriteWord32((byte *)m_buffer.begin()+this->KEYLENGTH, ++m_index);
108
	T::CorrectEndianess(m_buffer, m_buffer, T::DIGESTSIZE);
109
	T::CorrectEndianess(m_buffer, m_buffer, T::DIGESTSIZE);
109
	T::Transform(m_buffer, input);
110
	T::Transform(m_buffer, input);
110
	XorDigest(m_digest, m_buffer);
111
	XorDigest(this->m_digest, m_buffer);
111
}
112
}
112
113
113
template <class T> void XMACC_Base<T>::TruncatedFinal(byte *mac, unsigned int size)
114
template <class T> void XMACC_Base<T>::TruncatedFinal(byte *mac, unsigned int size)
114
{
115
{
115
	ThrowIfInvalidTruncatedSize(size);
116
	this->ThrowIfInvalidTruncatedSize(size);
116
	if (size < 4)
117
	if (size < 4)
117
		throw InvalidArgument("XMACC: truncating the MAC to less than 4 bytes will cause it to be unverifiable");
118
		throw InvalidArgument("XMACC: truncating the MAC to less than 4 bytes will cause it to be unverifiable");
118
	if (m_counter == 0xffffffff)
119
	if (m_counter == 0xffffffff)
119
		throw InvalidArgument("XMACC: the counter must be initialized to a valid value for MAC generation");
120
		throw InvalidArgument("XMACC: the counter must be initialized to a valid value for MAC generation");
120
121
121
	PadLastBlock(BLOCKSIZE - 2*sizeof(HashWordType));
122
	PadLastBlock(this->BLOCKSIZE - 2*sizeof(HashWordType));
122
	CorrectEndianess(m_data, m_data, BLOCKSIZE - 2*sizeof(HashWordType));
123
	CorrectEndianess(this->m_data, this->m_data, this->BLOCKSIZE - 2*sizeof(HashWordType));
123
	m_data[m_data.size()-2] = ByteReverse(GetBitCountHi());	// byteReverse for backwards compatibility
124
	this->m_data[this->m_data.size()-2] = ByteReverse(this->GetBitCountHi());	// byteReverse for backwards compatibility
124
	m_data[m_data.size()-1] = ByteReverse(GetBitCountLo());
125
	this->m_data[this->m_data.size()-1] = ByteReverse(this->GetBitCountLo());
125
	vTransform(m_data);
126
	vTransform(this->m_data);
126
127
127
	memcpy(m_buffer, m_key, KEYLENGTH);
128
	memcpy(m_buffer, m_key, this->KEYLENGTH);
128
	WriteWord32((byte *)m_buffer.begin()+KEYLENGTH, 0);
129
	WriteWord32((byte *)m_buffer.begin()+this->KEYLENGTH, 0);
129
	memset(m_data, 0, BLOCKSIZE-4);
130
	memset(this->m_data, 0, this->BLOCKSIZE-4);
130
	WriteWord32((byte *)m_data.begin()+BLOCKSIZE-4, ++m_counter);
131
	WriteWord32((byte *)this->m_data.begin()+this->BLOCKSIZE-4, ++m_counter);
131
	T::CorrectEndianess(m_buffer, m_buffer, T::DIGESTSIZE);
132
	T::CorrectEndianess(m_buffer, m_buffer, T::DIGESTSIZE);
132
	T::CorrectEndianess(m_data, m_data, BLOCKSIZE);
133
	T::CorrectEndianess(this->m_data, this->m_data, this->BLOCKSIZE);
133
	T::Transform(m_buffer, m_data);
134
	T::Transform(m_buffer, this->m_data);
134
	XorDigest(m_digest, m_buffer);
135
	XorDigest(this->m_digest, m_buffer);
135
136
136
	WriteWord32(mac, m_counter);
137
	WriteWord32(mac, m_counter);
137
	T::CorrectEndianess(m_digest, m_digest, T::DIGESTSIZE);
138
	T::CorrectEndianess(this->m_digest, this->m_digest, T::DIGESTSIZE);
138
	memcpy(mac+4, m_digest, size-4);
139
	memcpy(mac+4, this->m_digest, size-4);
139
140
140
	Restart();		// reinit for next use
141
	this->Restart();		// reinit for next use
141
}
142
}
142
143
143
template <class T> bool XMACC_Base<T>::TruncatedVerify(const byte *mac, unsigned int size)
144
template <class T> bool XMACC_Base<T>::TruncatedVerify(const byte *mac, unsigned int size)
144
{
145
{
145
	assert(4 <= size && size <= DIGESTSIZE);
146
	assert(4 <= size && size <= DIGESTSIZE);
146
147
147
	PadLastBlock(BLOCKSIZE - 2*sizeof(HashWordType));
148
	this->PadLastBlock(this->BLOCKSIZE - 2*sizeof(HashWordType));
148
	CorrectEndianess(m_data, m_data, BLOCKSIZE - 2*sizeof(HashWordType));
149
	CorrectEndianess(this->m_data, this->m_data, this->BLOCKSIZE - 2*sizeof(HashWordType));
149
	m_data[m_data.size()-2] = ByteReverse(GetBitCountHi());	// byteReverse for backwards compatibility
150
	this->m_data[this->m_data.size()-2] = ByteReverse(this->GetBitCountHi());	// byteReverse for backwards compatibility
150
	m_data[m_data.size()-1] = ByteReverse(GetBitCountLo());
151
	this->m_data[this->m_data.size()-1] = ByteReverse(this->GetBitCountLo());
151
	vTransform(m_data);
152
	vTransform(this->m_data);
152
153
153
	memcpy(m_buffer, m_key, KEYLENGTH);
154
	memcpy(m_buffer, m_key, this->KEYLENGTH);
154
	WriteWord32((byte *)m_buffer.begin()+KEYLENGTH, 0);
155
	WriteWord32((byte *)m_buffer.begin()+this->KEYLENGTH, 0);
155
	memset(m_data, 0, BLOCKSIZE-4);
156
	memset(this->m_data, 0, this->BLOCKSIZE-4);
156
	memcpy((byte *)m_data.begin()+BLOCKSIZE-4, mac, 4);
157
	memcpy((byte *)this->m_data.begin()+this->BLOCKSIZE-4, mac, 4);
157
	T::CorrectEndianess(m_buffer, m_buffer, T::DIGESTSIZE);
158
	T::CorrectEndianess(m_buffer, m_buffer, T::DIGESTSIZE);
158
	T::CorrectEndianess(m_data, m_data, BLOCKSIZE);
159
	T::CorrectEndianess(this->m_data, this->m_data, this->BLOCKSIZE);
159
	T::Transform(m_buffer, m_data);
160
	T::Transform(m_buffer, this->m_data);
160
	XorDigest(m_digest, m_buffer);
161
	XorDigest(this->m_digest, m_buffer);
161
162
162
	T::CorrectEndianess(m_digest, m_digest, T::DIGESTSIZE);
163
	T::CorrectEndianess(this->m_digest, this->m_digest, T::DIGESTSIZE);
163
	bool macValid = (memcmp(mac+4, m_digest, size-4) == 0);
164
	bool macValid = (memcmp(mac+4, this->m_digest, size-4) == 0);
164
	Restart();		// reinit for next use
165
	this->Restart();		// reinit for next use
165
	return macValid;
166
	return macValid;
166
}
167
}
167
168

Return to bug 49449