5 #ifndef CRYPTOPP_IMPORTS
11 #include "algebra.cpp"
12 #include "eprecomp.cpp"
14 ANONYMOUS_NAMESPACE_BEGIN
18 #if defined(HAVE_GCC_INIT_PRIORITY)
19 const EC2N::Point g_identity __attribute__ ((init_priority (CRYPTOPP_INIT_PRIORITY + 50))) =
EC2N::Point();
20 #elif defined(HAVE_MSC_INIT_PRIORITY)
21 #pragma warning(disable: 4075)
22 #pragma init_seg(".CRT$XCU")
24 #pragma warning(default: 4075)
25 #elif defined(HAVE_XLC_INIT_PRIORITY)
30 ANONYMOUS_NAMESPACE_END
35 : m_field(BERDecodeGF2NP(bt))
38 m_field->BERDecodeElement(seq, m_a);
39 m_field->BERDecodeElement(seq, m_b);
41 if (!seq.EndReached())
52 m_field->DEREncode(bt);
54 m_field->DEREncodeElement(seq, m_a);
55 m_field->DEREncodeElement(seq, m_b);
68 if (encodedPointLen < 1 || !bt.
Get(type))
83 P.x.Decode(bt, m_field->MaxElementByteLength());
87 P.y = m_field->SquareRoot(m_b);
91 FieldElement z = m_field->Square(P.x);
93 P.y = m_field->Divide(m_field->Add(m_field->Multiply(z, m_field->Add(P.x, m_a)), m_b), z);
94 CRYPTOPP_ASSERT(P.x == m_field->Subtract(m_field->Divide(m_field->Subtract(m_field->Multiply(P.y, z), m_b), z), m_a));
95 z = m_field->SolveQuadraticEquation(P.y);
97 z.SetCoefficient(0, type & 1);
99 P.y = m_field->Multiply(z, P.x);
107 unsigned int len = m_field->MaxElementByteLength();
124 bt.
Put((
byte)(2U + (!P.x ? 0U : m_field->Divide(P.y, P.x).GetBit(0))));
125 P.x.Encode(bt, m_field->MaxElementByteLength());
129 unsigned int len = m_field->MaxElementByteLength();
162 CRYPTOPP_UNUSED(rng);
164 pass = pass && m_a.CoefficientCount() <= m_field->MaxElementBitLength();
165 pass = pass && m_b.CoefficientCount() <= m_field->MaxElementBitLength();
168 pass = pass && m_field->GetModulus().IsIrreducible();
175 const FieldElement &x = P.x, &y = P.y;
177 (x.CoefficientCount() <= m_field->MaxElementBitLength()
178 && y.CoefficientCount() <= m_field->MaxElementBitLength()
179 && !(((x+m_a)*x*x+m_b-(x+y)*y)%m_field->GetModulus()));
184 if (P.identity && Q.identity)
187 if (P.identity && !Q.identity)
190 if (!P.identity && Q.identity)
193 return (m_field->Equal(P.x,Q.x) && m_field->Equal(P.y,Q.y));
198 #if defined(HAVE_GCC_INIT_PRIORITY) || defined(HAVE_MSC_INIT_PRIORITY) || defined(HAVE_XLC_INIT_PRIORITY)
200 #elif defined(CRYPTOPP_CXX11_DYNAMIC_INIT)
214 m_R.identity =
false;
215 m_R.y = m_field->Add(P.x, P.y);
223 if (P.identity)
return Q;
224 if (Q.identity)
return P;
226 if (m_field->Equal(P.x, Q.x) && m_field->Equal(P.y, m_field->Add(Q.x, Q.y)))
return Identity();
228 FieldElement t = m_field->Add(P.y, Q.y);
229 t = m_field->Divide(t, m_field->Add(P.x, Q.x));
230 FieldElement x = m_field->Square(t);
231 m_field->Accumulate(x, t);
232 m_field->Accumulate(x, Q.x);
233 m_field->Accumulate(x, m_a);
234 m_R.y = m_field->Add(P.y, m_field->Multiply(t, x));
235 m_field->Accumulate(x, P.x);
236 m_field->Accumulate(m_R.y, x);
239 m_R.identity =
false;
245 if (P.identity)
return P;
246 if (!m_field->IsUnit(P.x))
return Identity();
248 FieldElement t = m_field->Divide(P.y, P.x);
249 m_field->Accumulate(t, P.x);
250 m_R.y = m_field->Square(P.x);
251 m_R.x = m_field->Square(t);
252 m_field->Accumulate(m_R.x, t);
253 m_field->Accumulate(m_R.x, m_a);
254 m_field->Accumulate(m_R.y, m_field->Multiply(t, m_R.x));
255 m_field->Accumulate(m_R.y, m_R.x);
257 m_R.identity =
false;