|
@@ -64,6 +64,11 @@ void Scalar::set_random()
|
|
set(temp);
|
|
set(temp);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+mpz_class Scalar::toInt() const
|
|
|
|
+{
|
|
|
|
+ return element;
|
|
|
|
+}
|
|
|
|
+
|
|
Scalar Scalar::operator+(const Scalar& b) const
|
|
Scalar Scalar::operator+(const Scalar& b) const
|
|
{
|
|
{
|
|
mpz_class temp = element + b.element;
|
|
mpz_class temp = element + b.element;
|
|
@@ -138,6 +143,33 @@ Scalar Scalar::operator--(int)
|
|
return retval;
|
|
return retval;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+Scalar Scalar::curveAdd(const Scalar& b) const
|
|
|
|
+{
|
|
|
|
+ mpz_class temp = element + b.element;
|
|
|
|
+
|
|
|
|
+ mpz_mod(temp.get_mpz_t(), temp.get_mpz_t(), mpz_bn_n.get_mpz_t());
|
|
|
|
+
|
|
|
|
+ return Scalar(temp);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+Scalar Scalar::curveSub(const Scalar& b) const
|
|
|
|
+{
|
|
|
|
+ mpz_class temp = element - b.element;
|
|
|
|
+
|
|
|
|
+ mpz_mod(temp.get_mpz_t(), temp.get_mpz_t(), mpz_bn_n.get_mpz_t());
|
|
|
|
+
|
|
|
|
+ return Scalar(temp);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+Scalar Scalar::curveMult(const Scalar& b) const
|
|
|
|
+{
|
|
|
|
+ mpz_class temp = element * b.element;
|
|
|
|
+
|
|
|
|
+ mpz_mod(temp.get_mpz_t(), temp.get_mpz_t(), mpz_bn_n.get_mpz_t());
|
|
|
|
+
|
|
|
|
+ return Scalar(temp);
|
|
|
|
+}
|
|
|
|
+
|
|
Scalar Scalar::curveInverse() const
|
|
Scalar Scalar::curveInverse() const
|
|
{
|
|
{
|
|
mpz_class temp;
|
|
mpz_class temp;
|
|
@@ -172,6 +204,26 @@ bool Scalar::operator==(const Scalar& b) const
|
|
return element == b.element;
|
|
return element == b.element;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+bool Scalar::operator<(const Scalar& b) const
|
|
|
|
+{
|
|
|
|
+ return element < b.element;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+bool Scalar::operator<=(const Scalar& b) const
|
|
|
|
+{
|
|
|
|
+ return element <= b.element;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+bool Scalar::operator>(const Scalar& b) const
|
|
|
|
+{
|
|
|
|
+ return element > b.element;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+bool Scalar::operator>=(const Scalar& b) const
|
|
|
|
+{
|
|
|
|
+ return element >= b.element;
|
|
|
|
+}
|
|
|
|
+
|
|
bool Scalar::operator!=(const Scalar& b) const
|
|
bool Scalar::operator!=(const Scalar& b) const
|
|
{
|
|
{
|
|
return element != b.element;
|
|
return element != b.element;
|