Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
Botan::PointGFp Class Reference

`#include <point_gfp.h>`

## Public Types
enum | Compression_Type { UNCOMPRESSED = 0, COMPRESSED = 1, HYBRID = 2 }

## Public Member Functions
BigInt | get_affine_x () const
BigInt | get_affine_y () const
const CurveGFp & | get_curve () const
bool | is_zero () const
PointGFp & | negate ()
bool | on_the_curve () const
PointGFp & | operator*= (const BigInt &scalar)
PointGFp & | operator+= (const PointGFp &rhs)
PointGFp & | operator-= (const PointGFp &rhs)
PointGFp & | operator= (const PointGFp &)=default
PointGFp & | operator= (PointGFp &&other)
bool | operator== (const PointGFp &other) const
| PointGFp ()=default
| PointGFp (const CurveGFp &curve)
| PointGFp (const PointGFp &)=default
| PointGFp (PointGFp &&other)
| PointGFp (const CurveGFp &curve, const BigInt &x, const BigInt &y)
void | randomize_repr (RandomNumberGenerator &rng)
void | swap (PointGFp &other)

## Static Public Member Functions
static PointGFp | zero_of (const CurveGFp &curve)

## Friends
class | Blinded_Point_Multiply
BOTAN_DLL PointGFp | multi_exponentiate (const PointGFp &p1, const BigInt &z1, const PointGFp &p2, const BigInt &z2)
BOTAN_DLL PointGFp | operator* (const BigInt &scalar, const PointGFp &point)

## Detailed Description

This class represents one point on a curve of GF(p)

Definition at line 41 of file point_gfp.h.

## Member Enumeration Documentation

enum Botan::PointGFp::Compression_Type

Enumerator
UNCOMPRESSED |
COMPRESSED |
HYBRID |

Definition at line 44 of file point_gfp.h.

44 {
45 UNCOMPRESSED = 0,
46 COMPRESSED = 1,
47 HYBRID = 2
48 };
Botan::PointGFp::COMPRESSED
Definition: point_gfp.h:46
Botan::PointGFp::UNCOMPRESSED
Definition: point_gfp.h:45
Botan::PointGFp::HYBRID
Definition: point_gfp.h:47

## Constructor & Destructor Documentation

Botan::PointGFp::PointGFp | ( |  | ) |
| default

Construct an uninitialized PointGFp

Referenced by operator-=().

Botan::PointGFp::PointGFp | ( | const CurveGFp & | curve | ) |
| explicit

Construct the zero point

Parameters

  curve | The base curve

Definition at line 18 of file point_gfp.cpp.

References Botan::CurveGFp::to_rep().

18 :
19 m_curve(curve),
20 m_coord_x(0),
21 m_coord_y(1),
22 m_coord_z(0)
23 {
24 m_curve.to_rep(m_coord_x, m_monty_ws);
25 m_curve.to_rep(m_coord_y, m_monty_ws);
26 m_curve.to_rep(m_coord_z, m_monty_ws);
27 }
Botan::CurveGFp::to_rep
void to_rep(BigInt &x, secure_vector< word > &ws) const
Definition: curve_gfp.h:97

Botan::PointGFp::PointGFp | ( | const PointGFp & |  | ) |
| default

Copy constructor

Botan::PointGFp::PointGFp | ( | PointGFp && | other | ) |
| inline

Move Constructor

Definition at line 74 of file point_gfp.h.

75 {
76 this->swap(other);
77 }
Botan::PointGFp::swap
void swap(PointGFp &other)
Definition: point_gfp.cpp:447

Botan::PointGFp::PointGFp | ( | const CurveGFp & | curve,
|  | const BigInt & | x,
|  | const BigInt & | y
| ) |  |

Construct a point from its affine coordinates

Parameters

  curve | the base curve
  x | affine x coordinate
  y | affine y coordinate

Definition at line 29 of file point_gfp.cpp.

References Botan::CurveGFp::get_p(), and Botan::CurveGFp::to_rep().

29 :
30 m_curve(curve),
31 m_coord_x(x),
32 m_coord_y(y),
33 m_coord_z(1)
34 {
35 if(x <= 0 || x >= curve.get_p())
36 throw Invalid_Argument("Invalid PointGFp affine x");
37 if(y <= 0 || y >= curve.get_p())
38 throw Invalid_Argument("Invalid PointGFp affine y");
39
40 m_curve.to_rep(m_coord_x, m_monty_ws);
41 m_curve.to_rep(m_coord_y, m_monty_ws);
42 m_curve.to_rep(m_coord_z, m_monty_ws);
43 }
Botan::CurveGFp::to_rep
void to_rep(BigInt &x, secure_vector< word > &ws) const
Definition: curve_gfp.h:97

## Member Function Documentation

BigInt Botan::PointGFp::get_affine_x | ( |  | ) | const

get affine x coordinate

Returns
  affine x coordinate

Definition at line 390 of file point_gfp.cpp.

References Botan::CurveGFp::from_rep(), Botan::CurveGFp::get_p(), Botan::inverse_mod(), and is_zero().

Referenced by Botan::EC2OSP(), operator==(), and Botan::GOST_3410_PublicKey::public_key_bits().

391 {
392 if(is_zero())
393 throw Illegal_Transformation("Cannot convert zero point to affine");
394
395 BigInt z2 = curve_sqr(m_coord_z);
396 m_curve.from_rep(z2, m_monty_ws);
397 z2 = inverse_mod(z2, m_curve.get_p());
398
399 return curve_mult(z2, m_coord_x);
400 }
Botan::CurveGFp::from_rep
void from_rep(BigInt &x, secure_vector< word > &ws) const
Definition: curve_gfp.h:102
Botan::inverse_mod
BigInt inverse_mod(const BigInt &n, const BigInt &mod)
Definition: numthry.cpp:276
Botan::CurveGFp::get_p
const BigInt & get_p() const
Definition: curve_gfp.h:91
Botan::PointGFp::is_zero
bool is_zero() const
Definition: point_gfp.h:177

BigInt Botan::PointGFp::get_affine_y | ( |  | ) | const

get affine y coordinate

Returns
  affine y coordinate

Definition at line 402 of file point_gfp.cpp.

References Botan::CurveGFp::get_p(), Botan::inverse_mod(), is_zero(), and Botan::CurveGFp::to_rep().

Referenced by Botan::EC2OSP(), operator==(), and Botan::GOST_3410_PublicKey::public_key_bits().

403 {
404 if(is_zero())
405 throw Illegal_Transformation("Cannot convert zero point to affine");
406
407 BigInt z3 = curve_mult(m_coord_z, curve_sqr(m_coord_z));
408 z3 = inverse_mod(z3, m_curve.get_p());
409 m_curve.to_rep(z3, m_monty_ws);
410
411 return curve_mult(z3, m_coord_y);
412 }
Botan::CurveGFp::to_rep
void to_rep(BigInt &x, secure_vector< word > &ws) const
Definition: curve_gfp.h:97
Botan::inverse_mod
BigInt inverse_mod(const BigInt &n, const BigInt &mod)
Definition: numthry.cpp:276
Botan::CurveGFp::get_p
const BigInt & get_p() const
Definition: curve_gfp.h:91
Botan::PointGFp::is_zero
bool is_zero() const
Definition: point_gfp.h:177

const CurveGFp& Botan::PointGFp::get_curve | ( |  | ) | const
| inline

Return base curve of this point

Returns
  the curve over GF(p) of this point

Definition at line 159 of file point_gfp.h.

References m_curve.

Referenced by Botan::Blinded_Point_Multiply::Blinded_Point_Multiply(), Botan::EC2OSP(), Botan::multi_exponentiate(), Botan::operator*(), and operator==().

159 { return m_curve; }

bool Botan::PointGFp::is_zero | ( |  | ) | const
| inline

Is this the point at infinity?

Returns
  true, if this point is at infinity, false otherwise.

Definition at line 177 of file point_gfp.h.

Referenced by Botan::EC_PublicKey::check_key(), Botan::ECIES_KA_Operation::derive_secret(), Botan::EC2OSP(), get_affine_x(), get_affine_y(), on_the_curve(), operator-=(), and operator==().

178 { return (m_coord_x.is_zero() && m_coord_z.is_zero()); }
Botan::BigInt::is_zero
bool is_zero() const
Definition: bigint.h:250

PointGFp& Botan::PointGFp::negate | ( |  | ) |
| inline

Negate this point

Returns
  *this

Definition at line 148 of file point_gfp.h.

References Botan::CT::is_zero(), and m_curve.

Referenced by Botan::operator-().

149 {
150 if(!is_zero())
151 m_coord_y = m_curve.get_p() - m_coord_y;
152 return *this;
153 }
Botan::CurveGFp::get_p
const BigInt & get_p() const
Definition: curve_gfp.h:91
Botan::PointGFp::is_zero
bool is_zero() const
Definition: point_gfp.h:177

bool Botan::PointGFp::on_the_curve | ( |  | ) | const

Checks whether the point is to be found on the underlying curve; used to prevent fault attacks.

Returns
  if the point is on the curve

Definition at line 414 of file point_gfp.cpp.

References Botan::CurveGFp::from_rep(), Botan::CurveGFp::get_a_rep(), Botan::CurveGFp::get_b_rep(), and is_zero().

Referenced by Botan::EC_PublicKey::check_key(), Botan::EC_PrivateKey::EC_PrivateKey(), Botan::GOST_3410_PublicKey::GOST_3410_PublicKey(), Botan::OS2ECP(), and Botan::EC_Group::verify_group().

415 {
416 /*
417 Is the point still on the curve?? (If everything is correct, the
418 point is always on its curve; then the function will return true.
419 If somehow the state is corrupted, which suggests a fault attack
420 (or internal computational error), then return false.
421 */
422 if(is_zero())
423 return true;
424
425 const BigInt y2 = m_curve.from_rep(curve_sqr(m_coord_y), m_monty_ws);
426 const BigInt x3 = curve_mult(m_coord_x, curve_sqr(m_coord_x));
427 const BigInt ax = curve_mult(m_coord_x, m_curve.get_a_rep());
428 const BigInt z2 = curve_sqr(m_coord_z);
429
430 if(m_coord_z == z2) // Is z equal to 1 (in Montgomery form)?
431 {
432 if(y2 != m_curve.from_rep(x3 + ax + m_curve.get_b_rep(), m_monty_ws))
433 return false;
434 }
435
436 const BigInt z3 = curve_mult(m_coord_z, z2);
437 const BigInt ax_z4 = curve_mult(ax, curve_sqr(z2));
438 const BigInt b_z6 = curve_mult(m_curve.get_b_rep(), curve_sqr(z3));
439
440 if(y2 != m_curve.from_rep(x3 + ax_z4 + b_z6, m_monty_ws))
441 return false;
442
443 return true;
444 }
Botan::CurveGFp::get_a_rep
const BigInt & get_a_rep() const
Definition: curve_gfp.h:93
Botan::CurveGFp::from_rep
void from_rep(BigInt &x, secure_vector< word > &ws) const
Definition: curve_gfp.h:102
Botan::CurveGFp::get_b_rep
const BigInt & get_b_rep() const
Definition: curve_gfp.h:95
Botan::PointGFp::is_zero
bool is_zero() const
Definition: point_gfp.h:177

PointGFp & Botan::PointGFp::operator*= | ( | const BigInt & | scalar | ) |

*= Operator

Parameters

  scalar | the PointGFp to multiply with *this

Returns
  resulting PointGFp

Definition at line 242 of file point_gfp.cpp.

243 {
244 *this = scalar * *this;
245 return *this;
246 }

PointGFp & Botan::PointGFp::operator+= | ( | const PointGFp & | rhs | ) |

+= Operator

Parameters

  rhs | the PointGFp to add to the local value

Returns
  resulting PointGFp

Definition at line 223 of file point_gfp.cpp.

224 {
225 std::vector<BigInt> ws(9);
226 add(rhs, ws);
227 return *this;
228 }

PointGFp & Botan::PointGFp::operator-= | ( | const PointGFp & | rhs | ) |

-= Operator

Parameters

  rhs | the PointGFp to subtract from the local value

Returns
  resulting PointGFp

Definition at line 230 of file point_gfp.cpp.

References is_zero(), and PointGFp().

231 {
232 PointGFp minus_rhs = PointGFp(rhs).negate();
233
234 if(is_zero())
235 *this = minus_rhs;
236 else
237 *this += minus_rhs;
238
239 return *this;
240 }
Botan::PointGFp::PointGFp
PointGFp()=default
Botan::PointGFp::is_zero
bool is_zero() const
Definition: point_gfp.h:177

PointGFp& Botan::PointGFp::operator= | ( | const PointGFp & |  | ) |
| default

Standard Assignment

PointGFp& Botan::PointGFp::operator= | ( | PointGFp && | other | ) |
| inline

Move Assignment

Definition at line 87 of file point_gfp.h.

88 {
89 if(this != &other)
90 this->swap(other);
91 return (*this);
92 }
Botan::PointGFp::swap
void swap(PointGFp &other)
Definition: point_gfp.cpp:447

bool Botan::PointGFp::operator== | ( | const PointGFp & | other | ) | const

Equality operator

Definition at line 456 of file point_gfp.cpp.

References get_affine_x(), get_affine_y(), get_curve(), and is_zero().

457 {
458 if(get_curve() != other.get_curve())
459 return false;
460
461 // If this is zero, only equal if other is also zero
462 if(is_zero())
463 return other.is_zero();
464
465 return (get_affine_x() == other.get_affine_x() &&
466 get_affine_y() == other.get_affine_y());
467 }
Botan::PointGFp::get_affine_y
BigInt get_affine_y() const
Definition: point_gfp.cpp:402
Botan::PointGFp::get_curve
const CurveGFp & get_curve() const
Definition: point_gfp.h:159
Botan::PointGFp::get_affine_x
BigInt get_affine_x() const
Definition: point_gfp.cpp:390
Botan::PointGFp::is_zero
bool is_zero() const
Definition: point_gfp.h:177

void Botan::PointGFp::randomize_repr | ( | RandomNumberGenerator & | rng | ) |

Randomize the point representation The actual value (get_affine_x, get_affine_y) does not change

Definition at line 45 of file point_gfp.cpp.

References Botan::BigInt::is_zero(), Botan::BigInt::randomize(), and Botan::CurveGFp::to_rep().

Referenced by Botan::Blinded_Point_Multiply::blinded_multiply().

46 {
47 if(BOTAN_POINTGFP_RANDOMIZE_BLINDING_BITS > 1)
48 {
49 BigInt mask;
50 while(mask.is_zero())
51 mask.randomize(rng, BOTAN_POINTGFP_RANDOMIZE_BLINDING_BITS, false);
52
53 m_curve.to_rep(mask, m_monty_ws);
54 const BigInt mask2 = curve_mult(mask, mask);
55 const BigInt mask3 = curve_mult(mask2, mask);
56
57 m_coord_x = curve_mult(m_coord_x, mask2);
58 m_coord_y = curve_mult(m_coord_y, mask3);
59 m_coord_z = curve_mult(m_coord_z, mask);
60 }
61 }
Botan::CurveGFp::to_rep
void to_rep(BigInt &x, secure_vector< word > &ws) const
Definition: curve_gfp.h:97

void Botan::PointGFp::swap | ( | PointGFp & | other | ) |

swaps the states of *this and other, does not throw!

Parameters

  other | the object to swap values with

Definition at line 447 of file point_gfp.cpp.

References Botan::BigInt::swap(), and Botan::CurveGFp::swap().

448 {
449 m_curve.swap(other.m_curve);
450 m_coord_x.swap(other.m_coord_x);
451 m_coord_y.swap(other.m_coord_y);
452 m_coord_z.swap(other.m_coord_z);
453 m_monty_ws.swap(other.m_monty_ws);
454 }
Botan::BigInt::swap
void swap(BigInt &other)
Definition: bigint.h:122
Botan::CurveGFp::swap
void swap(CurveGFp &other)
Definition: curve_gfp.h:140

static PointGFp Botan::PointGFp::zero_of | ( | const CurveGFp & | curve | ) |
| inline static

Definition at line 61 of file point_gfp.h.

Referenced by Botan::Blinded_Point_Multiply::Blinded_Point_Multiply().

62 {
63 return PointGFp(curve);
64 }
Botan::PointGFp::PointGFp
PointGFp()=default

## Friends And Related Function Documentation

friend class Blinded_Point_Multiply
| friend

Definition at line 204 of file point_gfp.h.

BOTAN_DLL PointGFp multi_exponentiate | ( | const PointGFp & | p1,
|  | const BigInt & | z1,
|  | const PointGFp & | p2,
|  | const BigInt & | z2
| ) |  |
| friend

Multiexponentiation

Parameters

  p1 | a point
  z1 | a scalar
  p2 | a point
  z2 | a scalar

Returns
  (p1 * z1 + p2 * z2)

Definition at line 248 of file point_gfp.cpp.

250 {
251 const PointGFp p3 = p1 + p2;
252
253 PointGFp H(p1.get_curve()); // create as zero
254 size_t bits_left = std::max(z1.bits(), z2.bits());
255
256 std::vector<BigInt> ws(9);
257
258 while(bits_left)
259 {
260 H.mult2(ws);
261
262 const bool z1_b = z1.get_bit(bits_left - 1);
263 const bool z2_b = z2.get_bit(bits_left - 1);
264
265 if(z1_b == true && z2_b == true)
266 H.add(p3, ws);
267 else if(z1_b)
268 H.add(p1, ws);
269 else if(z2_b)
270 H.add(p2, ws);
271
272 --bits_left;
273 }
274
275 if(z1.is_negative() != z2.is_negative())
276 H.negate();
277
278 return H;
279 }
Botan::PointGFp::PointGFp
PointGFp()=default
Botan::CT::max
T max(T a, T b)
Definition: ct_utils.h:173

BOTAN_DLL PointGFp operator* | ( | const BigInt & | scalar,
|  | const PointGFp & | point
| ) |  |
| friend

Multiplication Operator

Parameters

  scalar | the scalar value
  point | the point value

Returns
  scalar*point on the curve

Definition at line 281 of file point_gfp.cpp.

282 {
283 //BOTAN_ASSERT(point.on_the_curve(), "Input is on the curve");
284
285 const CurveGFp& curve = point.get_curve();
286
287 const size_t scalar_bits = scalar.bits();
288
289 std::vector<BigInt> ws(9);
290
291 PointGFp R[2] = { PointGFp(curve), point };
292
293 for(size_t i = scalar_bits; i > 0; i--)
294 {
295 const size_t b = scalar.get_bit(i - 1);
296 R[b ^ 1].add(R[b], ws);
297 R[b].mult2(ws);
298 }
299
300 if(scalar.is_negative())
301 R[0].negate();
302
303 //BOTAN_ASSERT(R[0].on_the_curve(), "Output is on the curve");
304
305 return R[0];
306 }
Botan::PointGFp::PointGFp
PointGFp()=default
Botan::PointGFp::negate
PointGFp & negate()
Definition: point_gfp.h:148

The documentation for this class was generated from the following files:

- src/lib/math/ec_gfp/point_gfp.h
- src/lib/math/ec_gfp/point_gfp.cpp