Namespace for libecc. More...
Classes | |
class | bitset_index |
A bitset index. More... | |
class | bitset_index_iterator |
A bitset index with increment/decrement methods. More... | |
class | bitset_iterator |
A non-mutable bitset-iterator. More... | |
class | bitset_base |
Base class of libecc::bitset. More... | |
class | bitset_invertible |
A bitset with a fixed number of bits, having possibly an infinite number of leading virtual 1's. More... | |
class | bitset |
A bitset with a fixed number of bits. More... | |
struct | assign |
Operation used with libecc::bitset::shift_op. More... | |
struct | exor |
Operation used with libecc::bitset::shift_op. More... | |
struct | left |
Shift direction used with libecc::bitset::shift_op. More... | |
struct | right |
Shift direction used with libecc::bitset::shift_op. More... | |
class | rng |
Pseudo Random Number Generator. More... | |
class | sha1 |
SHA-1. More... | |
class | polynomial |
Polynomial representation of the Galois field F2m. More... | |
class | point |
Point (x,y) on elliptic curve x3 + ax2 + b = y2 + xy. More... | |
Typedefs | |
typedef unsigned long | bitset_digit_t |
Internal data type, used to store the bits of class bitset. | |
Functions | |
bool | operator== (bitset_index const &i1, bitset_index const &i2) |
Equality operator. | |
bool | operator!= (bitset_index const &i1, bitset_index const &i2) |
Inequality operator. | |
template<int DIRECTION> | |
bool | operator< (bitset_index_iterator< DIRECTION > const &i1, bitset_index_iterator< DIRECTION > const &i2) |
Less. | |
template<int DIRECTION> | |
bool | operator> (bitset_index_iterator< DIRECTION > const &i1, bitset_index_iterator< DIRECTION > const &i2) |
Greater. | |
template<int DIRECTION> | |
bool | operator<= (bitset_index_iterator< DIRECTION > const &i1, bitset_index_iterator< DIRECTION > const &i2) |
Less or equal. | |
template<int DIRECTION> | |
bool | operator>= (bitset_index_iterator< DIRECTION > const &i1, bitset_index_iterator< DIRECTION > const &i2) |
Greater or equal. | |
template<unsigned int N, int DIRECTION> | |
bitset_iterator< N, DIRECTION > | operator+ (bitset_iterator< N, DIRECTION > const &i, int d) |
Iterator addition. | |
template<unsigned int N, int DIRECTION> | |
bitset_iterator< N, DIRECTION > | operator+ (int d, bitset_iterator< N, DIRECTION > const &i) |
Iterator addition. | |
template<unsigned int N, int DIRECTION> | |
bitset_iterator< N, DIRECTION > | operator- (bitset_iterator< N, DIRECTION > const &i, int d) |
Iterator subtraction. | |
template<unsigned int N, int DIRECTION> | |
bitset_iterator< N, DIRECTION > | operator- (int d, bitset_iterator< N, DIRECTION > const &i) |
Iterator subtraction. | |
template<unsigned int N, bool inverted> | |
bitset_invertible< N,!inverted > const & | operator~ (bitset_invertible< N, inverted > const &bits) |
Invert a bitset. | |
template<unsigned int n1, bool inverted1, unsigned int n2, bool inverted2> | |
bool | operator== (bitset_invertible< n1, inverted1 > const &bits1, bitset_invertible< n2, inverted2 > const &bits2) |
Equivalence operator. | |
template<unsigned int n1, bool inverted1, unsigned int n2, bool inverted2> | |
bool | operator!= (bitset_invertible< n1, inverted1 > const &bits1, bitset_invertible< n2, inverted2 > const &bits2) |
Unequivalence operator. | |
template<unsigned int m, bool inverted1, bool inverted2> | |
Operator::bitsetExpression< m, inverted1, inverted2, Operator::bitsetAND > | operator& (bitset_invertible< m, inverted1 > const &arg1, bitset_invertible< m, inverted2 > const &arg2) |
Assignment operator with bitwise AND for expressions. | |
template<unsigned int m, bool inverted1, bool inverted2> | |
Operator::bitsetExpression< m, inverted1, inverted2, Operator::bitsetOR > | operator| (bitset_invertible< m, inverted1 > const &arg1, bitset_invertible< m, inverted2 > const &arg2) |
Assignment operator with bitwise OR for expressions. | |
template<unsigned int m, bool inverted1, bool inverted2> | |
Operator::bitsetExpression< m, inverted1, inverted2, Operator::bitsetXOR > | operator^ (bitset_invertible< m, inverted1 > const &arg1, bitset_invertible< m, inverted2 > const &arg2) |
Assignment operator with bitwise XOR for expressions. | |
template<unsigned int N> | |
std::istream & | operator>> (std::istream &is, bitset< N > &bitsetx) |
Read bitset from istream. | |
template<unsigned int N> | |
std::ostream & | operator<< (std::ostream &os, bitset< N > const &bits) |
Write bitset to ostream. | |
template<unsigned int m, unsigned int k, unsigned int k1, unsigned int k2> | |
polynomial< m, k, k1, k2 > | operator* (polynomial< m, k, k1, k2 > const &, polynomial< m, k, k1, k2 > const &) |
template<unsigned int m, unsigned int k, unsigned int k1, unsigned int k2> | |
polynomial< m, k, k1, k2 > | operator/ (polynomial< m, k, k1, k2 > const &, polynomial< m, k, k1, k2 > const &) |
template<unsigned int m, unsigned int k, unsigned int k1, unsigned int k2> | |
bool | operator== (polynomial< m, k, k1, k2 > const &, polynomial< m, k, k1, k2 > const &) |
template<unsigned int m, unsigned int k, unsigned int k1, unsigned int k2> | |
bool | operator!= (polynomial< m, k, k1, k2 > const &, polynomial< m, k, k1, k2 > const &) |
template<unsigned int m, unsigned int k, unsigned int k1, unsigned int k2> | |
std::ostream & | operator<< (std::ostream &, polynomial< m, k, k1, k2 > const &) |
template<unsigned int m, unsigned int k, unsigned int k1, unsigned int k2> | |
polynomial< m, k, k1, k2 > ::xor_type | operator+ (polynomial< m, k, k1, k2 > const &, polynomial< m, k, k1, k2 > const &) |
template<unsigned int m, unsigned int k, unsigned int k1, unsigned int k2> | |
polynomial< m, k, k1, k2 > ::xor_type | operator- (polynomial< m, k, k1, k2 > const &, polynomial< m, k, k1, k2 > const &) |
template<class field_type , class square_functor > | |
field_type | exponentiation (field_type const &base, mpz_class const &exponent, square_functor const &do_square=multiplicative_square< field_type >()) |
template<unsigned int m> | |
bitset< m > & | gcd (bitset< m > &polynomial_coefficients0, bitset< m > &polynomial_coefficients1) |
Namespace for libecc.
unsigned long libecc::bitset_digit_t |
Internal data type, used to store the bits of class bitset.
The number of bits in the builtin-type long
turns out to be equal to the size of the databus between memory and cpu. The internal type used to store the bits of a bitset is therefore an unsigned long
resulting in the most efficient code for bit manipulation.
field_type libecc::exponentiation | ( | field_type const & | base, | |
mpz_class const & | exponent, | |||
square_functor const & | do_square = multiplicative_square<field_type>() | |||
) |
Calculates the exponentiation of an arbitrary field element. The field must have defined the methods unity()
and operator*=
.
field_type | The type of the field element. | |
square_functor | A functor to calculate the square of a field_type. | |
base | The field_type that will be exponentiated. | |
exponent | The exponent of the exponentiation. | |
do_square | The square_functor. |
square_functor must define a method void operator()(field_type& x)
setting x
to its square.
For example for a libecc::polynomial :
template<unsigned int m, unsigned int k> classpolynomial_square { libecc::bitset_digit_t buffer[libecc::polynomial<m, k>::square_digits]; public: void operator()(libecc::polynomial<m, k>& p) { p = p.square(buffer); } };
and then use
libecc::polynomial<m, k> power(exponentiation(base, exponent, polynomial_square<m, k>()));
The default functor multiplicative_square uses operator*=
.
bitset<m>& libecc::gcd | ( | bitset< m > & | polynomial_coefficients0, | |
bitset< m > & | polynomial_coefficients1 | |||
) |
Calculates the Greatest Common Denominator of two polynomials over with respectively coefficients polynomial_coefficients0 and polynomial_coefficients1.
References libecc::bitset_base< N >::rbegin().
bool libecc::operator!= | ( | bitset_index const & | i1, | |
bitset_index const & | i2 | |||
) | [inline] |
Inequality operator.
References libecc::bitset_index::M_index.
bool libecc::operator!= | ( | polynomial< m, k, k1, k2 > const & | p1, | |
polynomial< m, k, k1, k2 > const & | p2 | |||
) | [inline] |
Compare two polynomials. Returns true
when p1 != p2, false
otherwise.
bool libecc::operator!= | ( | bitset_invertible< n1, inverted1 > const & | bits1, | |
bitset_invertible< n2, inverted2 > const & | bits2 | |||
) | [inline] |
Unequivalence operator.
!(bits1 == bits2)
Operator::bitsetExpression<m, inverted1, inverted2, Operator::bitsetAND> libecc::operator& | ( | bitset_invertible< m, inverted1 > const & | arg1, | |
bitset_invertible< m, inverted2 > const & | arg2 | |||
) |
Assignment operator with bitwise AND for expressions.
polynomial< m, k, k1, k2 > libecc::operator* | ( | polynomial< m, k, k1, k2 > const & | p1, | |
polynomial< m, k, k1, k2 > const & | p2 | |||
) | [inline] |
Multiply polynomial p1 with polynomial p2.
bitset_iterator< N, DIRECTION > libecc::operator+ | ( | int | d, | |
bitset_iterator< N, DIRECTION > const & | i | |||
) | [inline] |
Iterator addition.
bitset_iterator< N, DIRECTION > libecc::operator+ | ( | bitset_iterator< N, DIRECTION > const & | i, | |
int | d | |||
) | [inline] |
Iterator addition.
polynomial< m, k, k1, k2 >::xor_type libecc::operator+ | ( | polynomial< m, k, k1, k2 > const & | p1, | |
polynomial< m, k, k1, k2 > const & | p2 | |||
) | [inline] |
Prepare the addition of two polynomials.
Returns a dummy object with two pointers to the polynomials to be added. The addition does not take place until the final destination polynomial is known as well.
Note that it is not possible to write:
p1 OP= p1 + p2 + p3;
There is a complicated reason for that. Instead, write
polynomial<m,k> tmp(p2 + p3); p1 OP= p1 + tmp;
For example, when adding a whole series of polynomials you'd do:
polynomial<m,k> result(p1 + p2); result += p3 + p4; result += p5 + p5; ...
Basically, it is not supported to add or substract a polynomial to or from a temporary that represents an addition or subtraction by itself.
bitset_iterator< N, DIRECTION > libecc::operator- | ( | bitset_iterator< N, DIRECTION > const & | i, | |
int | d | |||
) | [inline] |
Iterator subtraction.
bitset_iterator< N, DIRECTION > libecc::operator- | ( | int | d, | |
bitset_iterator< N, DIRECTION > const & | i | |||
) | [inline] |
Iterator subtraction.
polynomial< m, k, k1, k2 >::xor_type libecc::operator- | ( | polynomial< m, k, k1, k2 > const & | p1, | |
polynomial< m, k, k1, k2 > const & | p2 | |||
) | [inline] |
Prepare the subtraction of two polynomials.
Returns a dummy object with two pointers to the polynomials to be subtracted. The subtraction does not take place until the final destination polynomial is known as well.
polynomial< m, k, k1, k2 > libecc::operator/ | ( | polynomial< m, k, k1, k2 > const & | e1, | |
polynomial< m, k, k1, k2 > const & | e2 | |||
) | [inline] |
Devide polynomial p1 by polynomial p2.
bool libecc::operator< | ( | bitset_index_iterator< DIRECTION > const & | i1, | |
bitset_index_iterator< DIRECTION > const & | i2 | |||
) | [inline] |
Less.
std::ostream& libecc::operator<< | ( | std::ostream & | os, | |
bitset< N > const & | bits | |||
) |
Write bitset to ostream.
std::ostream & libecc::operator<< | ( | std::ostream & | os, | |
polynomial< m, k, k1, k2 > const & | p | |||
) |
Write the binary coefficients of the polynomial p to os.
For example, an output string 1001101
means t6 + t3 + t2 + 1.
bool libecc::operator<= | ( | bitset_index_iterator< DIRECTION > const & | i1, | |
bitset_index_iterator< DIRECTION > const & | i2 | |||
) | [inline] |
Less or equal.
bool libecc::operator== | ( | polynomial< m, k, k1, k2 > const & | p1, | |
polynomial< m, k, k1, k2 > const & | p2 | |||
) | [inline] |
Compare two polynomials. Returns true
when p1 == p2, false
otherwise.
bool libecc::operator== | ( | bitset_index const & | i1, | |
bitset_index const & | i2 | |||
) | [inline] |
Equality operator.
References libecc::bitset_index::M_index.
bool libecc::operator== | ( | bitset_invertible< n1, inverted1 > const & | bits1, | |
bitset_invertible< n2, inverted2 > const & | bits2 | |||
) |
Equivalence operator.
This operator can only compare bitsets and inverted bitsets with eachother.
For example:
if (x == ~y) ...
References libecc::bitset_base< N >::vector.
bool libecc::operator> | ( | bitset_index_iterator< DIRECTION > const & | i1, | |
bitset_index_iterator< DIRECTION > const & | i2 | |||
) | [inline] |
Greater.
References libecc::bitset_index::M_index.
bool libecc::operator>= | ( | bitset_index_iterator< DIRECTION > const & | i1, | |
bitset_index_iterator< DIRECTION > const & | i2 | |||
) | [inline] |
Greater or equal.
References libecc::bitset_index::M_index.
std::istream& libecc::operator>> | ( | std::istream & | is, | |
bitset< N > & | bitsetx | |||
) |
Read bitset from istream.
References libecc::bitset< N >::bitset().
Operator::bitsetExpression<m, inverted1, inverted2, Operator::bitsetXOR> libecc::operator^ | ( | bitset_invertible< m, inverted1 > const & | arg1, | |
bitset_invertible< m, inverted2 > const & | arg2 | |||
) |
Assignment operator with bitwise XOR for expressions.
Operator::bitsetExpression<m, inverted1, inverted2, Operator::bitsetOR> libecc::operator| | ( | bitset_invertible< m, inverted1 > const & | arg1, | |
bitset_invertible< m, inverted2 > const & | arg2 | |||
) |
Assignment operator with bitwise OR for expressions.
bitset_invertible<N, !inverted> const& libecc::operator~ | ( | bitset_invertible< N, inverted > const & | bits | ) | [inline] |
Invert a bitset.
This operator is just a cast and doesn't actually do anything until you assign the expression that it is part of to another bitset.
For example:
x = ~y; x ^= ~y & ~z;
Both cases will run over the digits of bitset x just once and apply the given formula (and any like it) directly on the digits of the bitsets involved.
Inversion can also be used together with the equivalence operators. For example:
if (x == ~y) ...
will only run once over the digits of both bitset and compare the digits once by one using x.digit(d) == ~y.digit(d)
.