Crypto++ 8.9
Free C++ class library of cryptographic schemes
ecpoint.h
Go to the documentation of this file.
1// ecpoint.h - written and placed in the public domain by Jeffrey Walton
2// Data structures moved from ecp.h and ec2n.h. Added EncodedPoint interface
3
4/// \file ecpoint.h
5/// \brief Classes for Elliptic Curve points
6/// \since Crypto++ 6.0
7
8#ifndef CRYPTOPP_ECPOINT_H
9#define CRYPTOPP_ECPOINT_H
10
11#include "cryptlib.h"
12#include "integer.h"
13#include "algebra.h"
14#include "gf2n.h"
15
16NAMESPACE_BEGIN(CryptoPP)
17
18/// \brief Elliptical Curve Point over GF(p), where p is prime
19/// \since Crypto++ 2.0
20struct CRYPTOPP_DLL ECPPoint
21{
22 virtual ~ECPPoint() {}
23
24 /// \brief Construct an ECPPoint
25 /// \details identity is set to <tt>true</tt>
26 ECPPoint() : identity(true) {}
27
28 /// \brief Construct an ECPPoint from coordinates
29 /// \details identity is set to <tt>false</tt>
30 ECPPoint(const Integer &x, const Integer &y)
31 : x(x), y(y), identity(false) {}
32
33 /// \brief Tests points for equality
34 /// \param t the other point
35 /// \return true if the points are equal, false otherwise
36 bool operator==(const ECPPoint &t) const
37 {return (identity && t.identity) || (!identity && !t.identity && x==t.x && y==t.y);}
38
39 /// \brief Tests points for ordering
40 /// \param t the other point
41 /// \return true if this point is less than other, false otherwise
42 bool operator< (const ECPPoint &t) const
43 {return identity ? !t.identity : (!t.identity && (x<t.x || (x==t.x && y<t.y)));}
44
45 Integer x, y;
46 bool identity;
47};
48
50
51/// \brief Elliptical Curve Point over GF(2^n)
52/// \since Crypto++ 2.0
53struct CRYPTOPP_DLL EC2NPoint
54{
55 virtual ~EC2NPoint() {}
56
57 /// \brief Construct an EC2NPoint
58 /// \details identity is set to <tt>true</tt>
59 EC2NPoint() : identity(true) {}
60
61 /// \brief Construct an EC2NPoint from coordinates
62 /// \details identity is set to <tt>false</tt>
64 : x(x), y(y), identity(false) {}
65
66 /// \brief Tests points for equality
67 /// \param t the other point
68 /// \return true if the points are equal, false otherwise
69 bool operator==(const EC2NPoint &t) const
70 {return (identity && t.identity) || (!identity && !t.identity && x==t.x && y==t.y);}
71
72 /// \brief Tests points for ordering
73 /// \param t the other point
74 /// \return true if this point is less than other, false otherwise
75 bool operator< (const EC2NPoint &t) const
76 {return identity ? !t.identity : (!t.identity && (x<t.x || (x==t.x && y<t.y)));}
77
78 PolynomialMod2 x, y;
79 bool identity;
80};
81
83
84/// \brief Abstract class for encoding and decoding ellicptic curve points
85/// \tparam Point ellicptic curve point
86/// \details EncodedPoint is an interface for encoding and decoding elliptic curve points.
87/// The template parameter <tt>Point</tt> should be a class like ECP or EC2N.
88/// \since Crypto++ 6.0
89template <class Point>
91{
92public:
93 virtual ~EncodedPoint() {}
94
95 /// \brief Decodes an elliptic curve point
96 /// \param P point which is decoded
97 /// \param bt source BufferedTransformation
98 /// \param len number of bytes to read from the BufferedTransformation
99 /// \return true if a point was decoded, false otherwise
100 virtual bool DecodePoint(Point &P, BufferedTransformation &bt, size_t len) const =0;
101
102 /// \brief Decodes an elliptic curve point
103 /// \param P point which is decoded
104 /// \param encodedPoint byte array with the encoded point
105 /// \param len the size of the array
106 /// \return true if a point was decoded, false otherwise
107 virtual bool DecodePoint(Point &P, const byte *encodedPoint, size_t len) const =0;
108
109 /// \brief Verifies points on elliptic curve
110 /// \param P point to verify
111 /// \return true if the point is valid, false otherwise
112 virtual bool VerifyPoint(const Point &P) const =0;
113
114 /// \brief Determines encoded point size
115 /// \param compressed flag indicating if the point is compressed
116 /// \return the minimum number of bytes required to encode the point
117 virtual unsigned int EncodedPointSize(bool compressed = false) const =0;
118
119 /// \brief Encodes an elliptic curve point
120 /// \param P point which is decoded
121 /// \param encodedPoint byte array for the encoded point
122 /// \param compressed flag indicating if the point is compressed
123 /// \details <tt>encodedPoint</tt> must be at least EncodedPointSize() in length
124 virtual void EncodePoint(byte *encodedPoint, const Point &P, bool compressed) const =0;
125
126 /// \brief Encodes an elliptic curve point
127 /// \param bt target BufferedTransformation
128 /// \param P point which is encoded
129 /// \param compressed flag indicating if the point is compressed
130 virtual void EncodePoint(BufferedTransformation &bt, const Point &P, bool compressed) const =0;
131
132 /// \brief BER Decodes an elliptic curve point
133 /// \param bt source BufferedTransformation
134 /// \return the decoded elliptic curve point
135 virtual Point BERDecodePoint(BufferedTransformation &bt) const =0;
136
137 /// \brief DER Encodes an elliptic curve point
138 /// \param bt target BufferedTransformation
139 /// \param P point which is encoded
140 /// \param compressed flag indicating if the point is compressed
141 virtual void DEREncodePoint(BufferedTransformation &bt, const Point &P, bool compressed) const =0;
142};
143
144NAMESPACE_END
145
146#endif // CRYPTOPP_ECPOINT_H
Classes for performing mathematics over different fields.
bool operator<(const OID &lhs, const OID &rhs)
Compare two OIDs for ordering.
Abstract group.
Definition algebra.h:27
Interface for buffered transformations.
Definition cryptlib.h:1657
Abstract class for encoding and decoding ellicptic curve points.
Definition ecpoint.h:91
virtual bool DecodePoint(Point &P, const byte *encodedPoint, size_t len) const =0
Decodes an elliptic curve point.
virtual unsigned int EncodedPointSize(bool compressed=false) const =0
Determines encoded point size.
virtual bool VerifyPoint(const Point &P) const =0
Verifies points on elliptic curve.
virtual void EncodePoint(byte *encodedPoint, const Point &P, bool compressed) const =0
Encodes an elliptic curve point.
virtual void DEREncodePoint(BufferedTransformation &bt, const Point &P, bool compressed) const =0
DER Encodes an elliptic curve point.
virtual bool DecodePoint(Point &P, BufferedTransformation &bt, size_t len) const =0
Decodes an elliptic curve point.
virtual void EncodePoint(BufferedTransformation &bt, const Point &P, bool compressed) const =0
Encodes an elliptic curve point.
virtual Point BERDecodePoint(BufferedTransformation &bt) const =0
BER Decodes an elliptic curve point.
Multiple precision integer with arithmetic operations.
Definition integer.h:50
Polynomial with Coefficients in GF(2)
Definition gf2n.h:27
#define CRYPTOPP_DLL_TEMPLATE_CLASS
Instantiate templates in a dynamic library.
Definition config_dll.h:72
Abstract base classes that provide a uniform interface to this library.
Classes and functions for schemes over GF(2^n)
Multiple precision integer with arithmetic operations.
Crypto++ library namespace.
Elliptical Curve Point over GF(2^n)
Definition ecpoint.h:54
EC2NPoint()
Construct an EC2NPoint.
Definition ecpoint.h:59
bool operator==(const EC2NPoint &t) const
Tests points for equality.
Definition ecpoint.h:69
EC2NPoint(const PolynomialMod2 &x, const PolynomialMod2 &y)
Construct an EC2NPoint from coordinates.
Definition ecpoint.h:63
Elliptical Curve Point over GF(p), where p is prime.
Definition ecpoint.h:21
bool operator==(const ECPPoint &t) const
Tests points for equality.
Definition ecpoint.h:36
ECPPoint()
Construct an ECPPoint.
Definition ecpoint.h:26
ECPPoint(const Integer &x, const Integer &y)
Construct an ECPPoint from coordinates.
Definition ecpoint.h:30