summaryrefslogtreecommitdiff
path: root/ecp.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2018-08-22 16:36:05 -0400
committerJeffrey Walton <noloader@gmail.com>2018-08-22 16:36:05 -0400
commit8c450a9f7a98800b6e08358454e9d35c0832a24f (patch)
treeff75c06fcf8f48ab9ea696779ff57bedae3af2e9 /ecp.cpp
parent0ba3687c3957ee33d040e3fa38ea84d6fd8b819e (diff)
downloadcryptopp-git-8c450a9f7a98800b6e08358454e9d35c0832a24f.tar.gz
Avoid Singleton when possible (GH #708)
Also clear several sign conversion warnings
Diffstat (limited to 'ecp.cpp')
-rw-r--r--ecp.cpp33
1 files changed, 27 insertions, 6 deletions
diff --git a/ecp.cpp b/ecp.cpp
index 73f66685..4805785a 100644
--- a/ecp.cpp
+++ b/ecp.cpp
@@ -12,20 +12,34 @@
#include "filters.h"
#include "algebra.cpp"
-NAMESPACE_BEGIN(CryptoPP)
-
ANONYMOUS_NAMESPACE_BEGIN
-static inline ECP::Point ToMontgomery(const ModularArithmetic &mr, const ECP::Point &P)
+
+using CryptoPP::ECP;
+using CryptoPP::ModularArithmetic;
+
+#if defined(HAVE_GCC_INIT_PRIORITY)
+ const ECP::Point g_identity __attribute__ ((init_priority (CRYPTOPP_INIT_PRIORITY + 51))) = ECP::Point();
+#elif defined(HAVE_MSC_INIT_PRIORITY)
+ #pragma warning(disable: 4075)
+ #pragma init_seg(".CRT$XCU")
+ const ECP::Point g_identity;
+ #pragma warning(default: 4075)
+#endif
+
+inline ECP::Point ToMontgomery(const ModularArithmetic &mr, const ECP::Point &P)
{
return P.identity ? P : ECP::Point(mr.ConvertIn(P.x), mr.ConvertIn(P.y));
}
-static inline ECP::Point FromMontgomery(const ModularArithmetic &mr, const ECP::Point &P)
+inline ECP::Point FromMontgomery(const ModularArithmetic &mr, const ECP::Point &P)
{
return P.identity ? P : ECP::Point(mr.ConvertOut(P.x), mr.ConvertOut(P.y));
}
+
NAMESPACE_END
+NAMESPACE_BEGIN(CryptoPP)
+
ECP::ECP(const ECP &ecp, bool convertToMontgomeryRepresentation)
{
if (convertToMontgomeryRepresentation && !ecp.GetField().IsMontgomeryRepresentation())
@@ -124,13 +138,13 @@ void ECP::EncodePoint(BufferedTransformation &bt, const Point &P, bool compresse
NullStore().TransferTo(bt, EncodedPointSize(compressed));
else if (compressed)
{
- bt.Put(2 + P.y.GetBit(0));
+ bt.Put((byte)(2U + P.y.GetBit(0)));
P.x.Encode(bt, GetField().MaxElementByteLength());
}
else
{
unsigned int len = GetField().MaxElementByteLength();
- bt.Put(4); // uncompressed
+ bt.Put(4U); // uncompressed
P.x.Encode(bt, len);
P.y.Encode(bt, len);
}
@@ -201,7 +215,14 @@ bool ECP::Equal(const Point &P, const Point &Q) const
const ECP::Point& ECP::Identity() const
{
+#if defined(HAVE_GCC_INIT_PRIORITY) || defined(HAVE_MSC_INIT_PRIORITY)
+ return g_identity;
+#elif defined(CRYPTOPP_CXX11_DYNAMIC_INIT)
+ static const ECP::Point g_identity;
+ return g_identity;
+#else
return Singleton<Point>().Ref();
+#endif
}
const ECP::Point& ECP::Inverse(const Point &P) const