Botan 3.11.0
Crypto and TLS for C&
ec_group.h
Go to the documentation of this file.
1/*
2* ECC Domain Parameters
3*
4* (C) 2007 Falko Strenzke, FlexSecure GmbH
5* 2008-2010,2024 Jack Lloyd
6*
7* Botan is released under the Simplified BSD License (see license.txt)
8*/
9
10#ifndef BOTAN_ECC_DOMAIN_PARAMETERS_H_
11#define BOTAN_ECC_DOMAIN_PARAMETERS_H_
12
13#include <botan/asn1_obj.h>
14#include <botan/bigint.h>
15#include <botan/ec_apoint.h>
16#include <botan/ec_point_format.h>
17#include <botan/ec_scalar.h>
18#include <memory>
19#include <set>
20#include <span>
21
22#if defined(BOTAN_HAS_LEGACY_EC_POINT)
23 #include <botan/ec_point.h>
24#endif
25
26namespace Botan {
27
28/**
29* This enum indicates the source of the elliptic curve parameters
30* in use.
31*
32* Builtin means the curve is a known standard one which was compiled
33* in the library.
34*
35* ExternalSource means the curve parameters came from either an explicit
36* curve encoding or an application defined curve.
37*/
38enum class EC_Group_Source : uint8_t {
41};
42
43/**
44* Enum indicating the way the group in question is implemented
45*
46* This is returned by EC_Group::engine
47*/
48enum class EC_Group_Engine : uint8_t {
49 /// Using per curve implementation; fastest available
51 /// A generic implementation that handles many curves in one implementation
53 /// The old implementation, used as a fallback if none of the other
54 /// implementations can be used
55 /// TODO(Botan4) remove this
57};
58
59class EC_Mul2Table_Data;
60class EC_Group_Data;
61class EC_Group_Data_Map;
62
63/**
64* Class representing an elliptic curve
65*
66* The internal representation is stored in a shared_ptr, so copying an
67* EC_Group is inexpensive.
68*/
69class BOTAN_PUBLIC_API(2, 0) EC_Group final {
70 public:
71 /**
72 * Construct elliptic curve from the specified parameters
73 *
74 * This is used for example to create custom (application-specific) curves.
75 *
76 * Some build configurations do not support application specific curves, in
77 * which case this constructor will throw an exception. You can check for
78 * this situation beforehand using the function
79 * EC_Group::supports_application_specific_group()
80 *
81 * @param p the elliptic curve p
82 * @param a the elliptic curve a param
83 * @param b the elliptic curve b param
84 * @param base_x the x coordinate of the base point
85 * @param base_y the y coordinate of the base point
86 * @param order the order of the base point
87 * @param cofactor the cofactor
88 * @param oid an optional OID used to identify this curve
89 *
90 * @warning This constructor is deprecated and will be removed in Botan 4
91 *
92 * @warning support for cofactors > 1 is deprecated and will be removed
93 *
94 * @warning support for prime fields > 521 bits is deprecated and
95 * will be removed.
96 *
97 * @warning Support for explicitly encoded curve parameters is deprecated.
98 * An OID must be assigned.
99 */
100 BOTAN_DEPRECATED("Use alternate constructor")
101 EC_Group(const BigInt& p,
102 const BigInt& a,
103 const BigInt& b,
104 const BigInt& base_x,
105 const BigInt& base_y,
106 const BigInt& order,
107 const BigInt& cofactor,
108 const OID& oid = OID());
109
110 /**
111 * Construct elliptic curve from the specified parameters
112 *
113 * This is used for example to create custom (application-specific) curves.
114 *
115 * Some build configurations do not support application specific curves, in
116 * which case this constructor will throw an exception. You can check for
117 * this situation beforehand using the function
118 * EC_Group::supports_application_specific_group()
119 *
120 * Unlike the deprecated constructor, this constructor imposes additional
121 * restrictions on the parameters, namely:
122 *
123 * - An object identifier must be provided
124 *
125 * - The prime must be at least 192 bits and at most 512 bits, and a multiple
126 * of 32 bits. Currently, as long as BOTAN_DISABLE_DEPRECATED_FEATURES is not
127 * set, this constructor accepts primes as small as 128 bits - this lower
128 * bound will be removed in the next major release.
129 *
130 * - As an extension of the above restriction, the prime can also be exactly
131 * the 521-bit Mersenne prime (2**521-1) or exactly the 239-bit prime used in
132 * X9.62 239 bit groups (2**239 - 2**143 - 2**95 + 2**47 - 1)
133 *
134 * - The prime must be congruent to 3 modulo 4
135 *
136 * - The group order must have the same bit length as the prime. It is allowed
137 * for the order to be larger than p, but they must have the same bit length.
138 *
139 * - Only prime order curves (with cofactor == 1) are allowed
140 *
141 * @warning use only elliptic curve parameters that you trust
142 *
143 * @param oid an object identifier used to identify this curve
144 * @param p the elliptic curve prime (at most 521 bits)
145 * @param a the elliptic curve a param
146 * @param b the elliptic curve b param
147 * @param base_x the x coordinate of the group generator
148 * @param base_y the y coordinate of the group generator
149 * @param order the order of the group
150 */
151 EC_Group(const OID& oid,
152 const BigInt& p,
153 const BigInt& a,
154 const BigInt& b,
155 const BigInt& base_x,
156 const BigInt& base_y,
157 const BigInt& order);
158
159 /**
160 * Decode a BER encoded ECC domain parameter set
161 * @param ber the bytes of the BER encoding
162 */
163 explicit EC_Group(std::span<const uint8_t> ber);
164
165 BOTAN_DEPRECATED("Use EC_Group(std::span)")
166 EC_Group(const uint8_t ber[], size_t ber_len) : EC_Group(std::span{ber, ber_len}) {}
167
168 /**
169 * Create an EC domain by OID (or throw if unknown)
170 * @param oid the OID of the EC domain to create
171 */
172 BOTAN_DEPRECATED("Use EC_Group::from_OID") explicit EC_Group(const OID& oid) { *this = EC_Group::from_OID(oid); }
173
174 /**
175 * Create an EC domain from PEM encoding (as from PEM_encode()), or
176 * from an OID name (eg "secp256r1", or "1.2.840.10045.3.1.7")
177 * @param pem_or_oid PEM-encoded data, or an OID
178 *
179 * @warning Support for PEM in this function is deprecated. Use
180 * EC_Group::from_PEM or EC_Group::from_OID or EC_Group::from_name
181 */
182 BOTAN_DEPRECATED("Use EC_Group::from_{name,OID,PEM}") explicit EC_Group(std::string_view pem_or_oid);
183
184 /**
185 * Initialize an EC group from the PEM/ASN.1 encoding
186 */
187 static EC_Group from_PEM(std::string_view pem);
188
189 /**
190 * Initialize an EC group from a group named by an object identifier
191 */
192 static EC_Group from_OID(const OID& oid);
193
194 /**
195 * Initialize an EC group from a group common name (eg "secp256r1")
196 */
197 static EC_Group from_name(std::string_view name);
198
199 BOTAN_DEPRECATED("Use EC_Group::from_PEM") static EC_Group EC_Group_from_PEM(std::string_view pem) {
200 return EC_Group::from_PEM(pem);
201 }
202
203 /**
204 * Create an uninitialized EC_Group
205 */
206 BOTAN_DEPRECATED("Deprecated no replacement") EC_Group();
207
208 /**
209 * Unregister a previously registered group.
210 *
211 * Using this is discouraged for normal use. This is only useful or necessary if
212 * you are registering a very large number of distinct groups, and need to worry about memory constraints.
213 *
214 * Returns true if the group was found and unregistered.
215 */
216 static bool unregister(const OID& oid);
217
219
221 EC_Group(EC_Group&&) = default;
222
223 EC_Group& operator=(const EC_Group&);
224 EC_Group& operator=(EC_Group&&) = default;
225
226 bool initialized() const { return (m_data != nullptr); }
227
228 /**
229 * Verify EC_Group domain
230 * @returns true if group is valid. false otherwise
231 */
232 bool verify_group(RandomNumberGenerator& rng, bool strong = false) const;
233
234 bool operator==(const EC_Group& other) const;
235
236 EC_Group_Source source() const;
237
238 /**
239 * Return true if in this build configuration it is possible to
240 * register an application specific elliptic curve.
241 */
242 static bool supports_application_specific_group();
243
244 /**
245 * Return true if in this build configuration it is possible to
246 * register an application specific elliptic curve with a cofactor
247 * larger than 1.
248 */
249 static bool supports_application_specific_group_with_cofactor();
250
251 /**
252 * Return true if in this build configuration EC_Group::from_name(name) will succeed
253 */
254 static bool supports_named_group(std::string_view name);
255
256 /**
257 * Return true if this EC_Group was derived from an explicit encoding
258 *
259 * Explicit encoding of groups is deprecated; when support for explicit curves
260 * is removed in a future major release, this function will also be removed.
261 */
262 bool used_explicit_encoding() const { return m_explicit_encoding; }
263
264 /**
265 * Return how this EC_Group is implemented under the hood
266 *
267 * This is mostly useful for diagnostic or debugging purposes
268 */
269 EC_Group_Engine engine() const;
270
271 /**
272 * Return a set of known named EC groups
273 *
274 * This returns the set of groups for which from_name should succeed
275 * Note that the set of included groups can vary based on the
276 * build configuration.
277 */
278 static const std::set<std::string>& known_named_groups();
279
280 /**
281 * Create the DER encoding of this domain
282 * @param form of encoding to use
283 * @returns the group information encoded as DER
284 */
285 BOTAN_DEPRECATED("Use the variant that does not take EC_Group_Encoding")
286 std::vector<uint8_t> DER_encode(EC_Group_Encoding form) const;
287
288 /**
289 * Create the DER encoding of this domain, using namedCurve format
290 * @returns the group information encoded as DER
291 */
292 std::vector<uint8_t> DER_encode() const;
293
294 /**
295 * Return the PEM encoding
296 * @return string containing PEM data
297 *
298 * @warning In Botan4 the form parameter will be removed and only
299 * namedCurve will be supported
300 *
301 * TODO(Botan4) remove the argument
302 */
303 std::string PEM_encode(EC_Group_Encoding form = EC_Group_Encoding::Explicit) const;
304
305 /**
306 * Return the size of p in bits (same as get_p().bits())
307 */
308 size_t get_p_bits() const;
309
310 /**
311 * Return the size of p in bytes (same as get_p().bytes())
312 */
313 size_t get_p_bytes() const;
314
315 /**
316 * Return the size of group order in bits (same as get_order().bits())
317 */
318 size_t get_order_bits() const;
319
320 /**
321 * Return the size of the group order in bytes (same as get_order().bytes())
322 */
323 size_t get_order_bytes() const;
324
325 /// Table for computing g*x + h*y
326 class BOTAN_PUBLIC_API(3, 6) Mul2Table final {
327 public:
328 /**
329 * Create a table for computing g*x + h*y
330 */
332
333 /**
334 * Return the elliptic curve point g*x + h*y
335 *
336 * Where g is the group generator and h is the value passed to the constructor
337 *
338 * Returns nullopt if g*x + h*y was the point at infinity
339 *
340 * @warning this function is variable time with respect to x and y
341 */
342 std::optional<EC_AffinePoint> mul2_vartime(const EC_Scalar& x, const EC_Scalar& y) const;
343
344 /**
345 * Check if v equals the x coordinate of g*x + h*y reduced modulo the order
346 *
347 * Where g is the group generator and h is the value passed to the constructor
348 *
349 * Returns false if unequal, including if g*x + h*y was the point at infinity
350 *
351 * @warning this function is variable time with respect to x and y
352 */
353 bool mul2_vartime_x_mod_order_eq(const EC_Scalar& v, const EC_Scalar& x, const EC_Scalar& y) const;
354
355 /**
356 * Check if v equals the x coordinate of g*x*c + h*y*c reduced modulo the order
357 *
358 * Where g is the group generator and h is the value passed to the constructor
359 *
360 * Returns false if unequal, including if g*x*c + h*y*c was the point at infinity
361 *
362 * @warning this function is variable time with respect to x and y
363 */
365 const EC_Scalar& c,
366 const EC_Scalar& x,
367 const EC_Scalar& y) const;
368
370 Mul2Table(const Mul2Table& other) = delete;
371 Mul2Table(Mul2Table&& other) noexcept;
372 Mul2Table& operator=(const Mul2Table& other) = delete;
373 Mul2Table& operator=(Mul2Table&& other) noexcept;
374
375 private:
376 std::unique_ptr<EC_Mul2Table_Data> m_tbl;
377 };
378
379 /**
380 * Return the OID of these domain parameters
381 * @result the OID
382 */
383 const OID& get_curve_oid() const;
384
385 /**
386 * Return the prime modulus of the field
387 */
388 const BigInt& get_p() const;
389
390 /**
391 * Return the a parameter of the elliptic curve equation
392 */
393 const BigInt& get_a() const;
394
395 /**
396 * Return the b parameter of the elliptic curve equation
397 */
398 const BigInt& get_b() const;
399
400 /**
401 * Return the x coordinate of the base point
402 */
403 const BigInt& get_g_x() const;
404
405 /**
406 * Return the y coordinate of the base point
407 */
408 const BigInt& get_g_y() const;
409
410 /**
411 * Return the order of the base point
412 * @result order of the base point
413 */
414 const BigInt& get_order() const;
415
416 /**
417 * Return the cofactor
418 * @result the cofactor
419 * TODO(Botan4): Remove this
420 */
421 const BigInt& get_cofactor() const;
422
423 /**
424 * Return true if the cofactor is > 1
425 * TODO(Botan4): Remove this
426 */
427 bool has_cofactor() const;
428
429 /*
430 * For internal use only
431 * TODO(Botan4): Move this to an internal header
432 */
433 static std::shared_ptr<EC_Group_Data> EC_group_info(const OID& oid);
434
435 /*
436 * For internal use only
437 *
438 * @warning this invalidates pointers and can cause memory corruption.
439 * This function exists only to be called in tests.
440 *
441 * TODO(Botan4): Move this to an internal header
442 */
443 static size_t clear_registered_curve_data();
444
445 /*
446 * For internal use only
447 * TODO(Botan4): Move this to an internal header
448 */
449 static OID EC_group_identity_from_order(const BigInt& order);
450
451 /*
452 * For internal use only
453 */
454 const std::shared_ptr<EC_Group_Data>& _data() const { return m_data; }
455
456#if defined(BOTAN_HAS_LEGACY_EC_POINT)
457 /**
458 * Check if y is a plausible point on the curve
459 *
460 * In particular, checks that it is a point on the curve, not infinity,
461 * and that it has order matching the group.
462 */
463 bool verify_public_element(const EC_Point& y) const;
464
465 /**
466 * OS2ECP (Octet String To Elliptic Curve Point)
467 *
468 * Deserialize an encoded point. Verifies that the point is on the curve.
469 */
470 BOTAN_DEPRECATED("Use EC_AffinePoint::deserialize") EC_Point OS2ECP(const uint8_t bits[], size_t len) const {
471 return EC_AffinePoint(*this, std::span{bits, len}).to_legacy_point();
472 }
473
474 BOTAN_DEPRECATED("Use EC_AffinePoint::deserialize")
475 EC_Point OS2ECP(std::span<const uint8_t> encoded_point) const {
476 return EC_AffinePoint(*this, encoded_point).to_legacy_point();
477 }
478
479 /**
480 * Return group base point
481 * @result base point
482 */
483 BOTAN_DEPRECATED("Use EC_AffinePoint::generator") const EC_Point& get_base_point() const;
484
485 // Everything below here will be removed in a future release:
486
487 /**
488 * Return the canonical group generator
489 * @result standard generator of the curve
490 */
491 BOTAN_DEPRECATED("Use EC_AffinePoint::generator") const EC_Point& generator() const;
492
493 /**
494 * Multi exponentiate. Not constant time.
495 * @return base_point*x + h*y
496 */
497 BOTAN_DEPRECATED("Use EC_Group::Mul2Table")
498 EC_Point point_multiply(const BigInt& x_bn, const EC_Point& h_pt, const BigInt& y_bn) const {
499 auto x = EC_Scalar::from_bigint(*this, x_bn);
500 auto y = EC_Scalar::from_bigint(*this, y_bn);
501 auto h = EC_AffinePoint(*this, h_pt);
502
503 const Mul2Table gh_mul(h);
504
505 if(auto r = gh_mul.mul2_vartime(x, y)) {
506 return r->to_legacy_point();
507 } else {
508 return EC_AffinePoint::identity(*this).to_legacy_point();
509 }
510 }
511
512 /**
513 * Blinded point multiplication, attempts resistance to side channels
514 * @param k_bn the scalar
515 * @param rng a random number generator
516 * @return base_point*k
517 */
518 BOTAN_DEPRECATED("Use EC_AffinePoint and EC_Scalar")
519 EC_Point blinded_base_point_multiply(const BigInt& k_bn,
520 RandomNumberGenerator& rng,
521 std::vector<BigInt>& /*ws*/) const {
522 auto k = EC_Scalar::from_bigint(*this, k_bn);
523 auto pt = EC_AffinePoint::g_mul(k, rng);
524 return pt.to_legacy_point();
525 }
526
527 /**
528 * Blinded point multiplication, attempts resistance to side channels
529 * Returns just the x coordinate of the point
530 *
531 * @param k_bn the scalar
532 * @param rng a random number generator
533 * @return x coordinate of base_point*k
534 */
535 BOTAN_DEPRECATED("Use EC_AffinePoint and EC_Scalar")
536 BigInt blinded_base_point_multiply_x(const BigInt& k_bn,
537 RandomNumberGenerator& rng,
538 std::vector<BigInt>& /*ws*/) const {
539 auto k = EC_Scalar::from_bigint(*this, k_bn);
540 return BigInt(EC_AffinePoint::g_mul(k, rng).x_bytes());
541 }
542
543 /**
544 * Blinded point multiplication, attempts resistance to side channels
545 * @param point input point
546 * @param k_bn the scalar
547 * @param rng a random number generator
548 * @return point*k
549 */
550 BOTAN_DEPRECATED("Use EC_AffinePoint and EC_Scalar")
551 EC_Point blinded_var_point_multiply(const EC_Point& point,
552 const BigInt& k_bn,
553 RandomNumberGenerator& rng,
554 std::vector<BigInt>& /*ws*/) const {
555 auto k = EC_Scalar::from_bigint(*this, k_bn);
556 auto pt = EC_AffinePoint(*this, point);
557 return pt.mul(k, rng).to_legacy_point();
558 }
559
560 /**
561 * Return a random scalar ie an integer in [1,order)
562 */
563 BOTAN_DEPRECATED("Use EC_Scalar::random") BigInt random_scalar(RandomNumberGenerator& rng) const {
564 return EC_Scalar::random(*this, rng).to_bigint();
565 }
566
567 /**
568 * Hash onto the curve.
569 * For some curve types no mapping is currently available, in this
570 * case this function will throw an exception.
571 *
572 * @param hash_fn the hash function to use (typically "SHA-256" or "SHA-512")
573 * @param input the input to hash
574 * @param input_len length of input in bytes
575 * @param domain_sep a domain separator
576 * @param domain_sep_len length of domain_sep in bytes
577 * @param random_oracle if the mapped point must be uniform (use
578 "true" here unless you know what you are doing)
579 */
580 BOTAN_DEPRECATED("Use EC_AffinePoint")
581 EC_Point hash_to_curve(std::string_view hash_fn,
582 const uint8_t input[],
583 size_t input_len,
584 const uint8_t domain_sep[],
585 size_t domain_sep_len,
586 bool random_oracle = true) const {
587 auto inp = std::span{input, input_len};
588 auto dst = std::span{domain_sep, domain_sep_len};
589
590 if(random_oracle) {
591 return EC_AffinePoint::hash_to_curve_ro(*this, hash_fn, inp, dst).to_legacy_point();
592 } else {
593 return EC_AffinePoint::hash_to_curve_nu(*this, hash_fn, inp, dst).to_legacy_point();
594 }
595 }
596
597 /**
598 * Hash onto the curve.
599 * For some curve types no mapping is currently available, in this
600 * case this function will throw an exception.
601 *
602 * @param hash_fn the hash function to use (typically "SHA-256" or "SHA-512")
603 * @param input the input to hash
604 * @param input_len length of input in bytes
605 * @param domain_sep a domain separator
606 * @param random_oracle if the mapped point must be uniform (use
607 "true" here unless you know what you are doing)
608 */
609 BOTAN_DEPRECATED("Use EC_AffinePoint")
610 EC_Point hash_to_curve(std::string_view hash_fn,
611 const uint8_t input[],
612 size_t input_len,
613 std::string_view domain_sep,
614 bool random_oracle = true) const {
615 auto inp = std::span{input, input_len};
616
617 if(random_oracle) {
618 return EC_AffinePoint::hash_to_curve_ro(*this, hash_fn, inp, domain_sep).to_legacy_point();
619 } else {
620 return EC_AffinePoint::hash_to_curve_nu(*this, hash_fn, inp, domain_sep).to_legacy_point();
621 }
622 }
623
624 /**
625 * Return a point on this curve with the affine values x, y
626 */
627 BOTAN_DEPRECATED("Deprecated - use EC_AffinePoint") EC_Point point(const BigInt& x, const BigInt& y) const {
628 if(auto pt = EC_AffinePoint::from_bigint_xy(*this, x, y)) {
629 return pt->to_legacy_point();
630 } else {
631 throw Decoding_Error("Invalid x/y coordinates for elliptic curve point");
632 }
633 }
634
635 /**
636 * Return the zero (or infinite) point on this curve
637 */
638 BOTAN_DEPRECATED("Deprecated no replacement") EC_Point zero_point() const {
639 return EC_AffinePoint::identity(*this).to_legacy_point();
640 }
641#endif
642
643 /**
644 * Return if a == -3 mod p
645 */
646 BOTAN_DEPRECATED("Deprecated no replacement") bool a_is_minus_3() const { return get_a() + 3 == get_p(); }
647
648 /**
649 * Return if a == 0 mod p
650 */
651 BOTAN_DEPRECATED("Deprecated no replacement") bool a_is_zero() const { return get_a().is_zero(); }
652
653 /*
654 * Reduce x modulo the order
655 */
656 BOTAN_DEPRECATED("Use EC_Scalar") BigInt mod_order(const BigInt& x) const {
657 return EC_Scalar::from_bytes_mod_order(*this, x.serialize()).to_bigint();
658 }
659
660 /*
661 * Return inverse of x modulo the order
662 */
663 BOTAN_DEPRECATED("Use EC_Scalar") BigInt inverse_mod_order(const BigInt& x) const {
664 return EC_Scalar::from_bigint(*this, x).invert().to_bigint();
665 }
666
667 /*
668 * Reduce (x*x) modulo the order
669 */
670 BOTAN_DEPRECATED("Use EC_Scalar") BigInt square_mod_order(const BigInt& x) const {
671 auto xs = EC_Scalar::from_bigint(*this, x);
672 xs.square_self();
673 return xs.to_bigint();
674 }
675
676 /*
677 * Reduce (x*y) modulo the order
678 */
679 BOTAN_DEPRECATED("Use EC_Scalar") BigInt multiply_mod_order(const BigInt& x, const BigInt& y) const {
680 auto xs = EC_Scalar::from_bigint(*this, x);
681 auto ys = EC_Scalar::from_bigint(*this, y);
682 return (xs * ys).to_bigint();
683 }
684
685 /*
686 * Reduce (x*y*z) modulo the order
687 */
688 BOTAN_DEPRECATED("Use EC_Scalar")
689 BigInt multiply_mod_order(const BigInt& x, const BigInt& y, const BigInt& z) const {
690 auto xs = EC_Scalar::from_bigint(*this, x);
691 auto ys = EC_Scalar::from_bigint(*this, y);
692 auto zs = EC_Scalar::from_bigint(*this, z);
693 return (xs * ys * zs).to_bigint();
694 }
695
696 /*
697 * Return x^3 modulo the order
698 */
699 BOTAN_DEPRECATED("Deprecated no replacement") BigInt cube_mod_order(const BigInt& x) const {
700 auto xs = EC_Scalar::from_bigint(*this, x);
701 return (xs * xs * xs).to_bigint();
702 }
703
704 BOTAN_DEPRECATED("Just serialize the point and check") size_t point_size(EC_Point_Format format) const {
705 // Hybrid and standard format are (x,y), compressed is y, +1 format byte
706 if(format == EC_Point_Format::Compressed) {
707 return (1 + get_p_bytes());
708 } else {
709 return (1 + 2 * get_p_bytes());
710 }
711 }
712
713 private:
714 static EC_Group_Data_Map& ec_group_data();
715
716 explicit EC_Group(std::shared_ptr<EC_Group_Data>&& data);
717
718 static std::pair<std::shared_ptr<EC_Group_Data>, bool> BER_decode_EC_group(std::span<const uint8_t> ber,
719 EC_Group_Source source);
720
721 static std::shared_ptr<EC_Group_Data> load_EC_group_info(const char* p,
722 const char* a,
723 const char* b,
724 const char* g_x,
725 const char* g_y,
726 const char* order,
727 const OID& oid);
728
729 const EC_Group_Data& data() const;
730
731 // Member data
732 std::shared_ptr<EC_Group_Data> m_data;
733 bool m_explicit_encoding = false;
734};
735
736inline bool operator!=(const EC_Group& lhs, const EC_Group& rhs) {
737 return !(lhs == rhs);
738}
739
740} // namespace Botan
741
742#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_DEPRECATED(msg)
Definition api.h:73
#define BOTAN_FUTURE_EXPLICIT
Definition api.h:52
Mul2Table & operator=(const Mul2Table &other)=delete
Mul2Table(const Mul2Table &other)=delete
Mul2Table(Mul2Table &&other) noexcept
std::optional< EC_AffinePoint > mul2_vartime(const EC_Scalar &x, const EC_Scalar &y) const
Definition ec_group.cpp:834
BOTAN_FUTURE_EXPLICIT Mul2Table(const EC_AffinePoint &h)
Definition ec_group.cpp:830
Mul2Table & operator=(Mul2Table &&other) noexcept
bool mul2_vartime_x_mod_order_eq(const EC_Scalar &v, const EC_Scalar &x, const EC_Scalar &y) const
Definition ec_group.cpp:843
bool a_is_minus_3() const
Definition ec_group.h:646
static EC_Group EC_Group_from_PEM(std::string_view pem)
Definition ec_group.h:199
static EC_Group from_PEM(std::string_view pem)
Definition ec_group.cpp:481
const BigInt & get_b() const
Definition ec_group.cpp:617
const BigInt & get_a() const
Definition ec_group.cpp:613
bool initialized() const
Definition ec_group.h:226
const BigInt & get_g_y() const
Definition ec_group.cpp:665
const BigInt & get_cofactor() const
Definition ec_group.cpp:669
BigInt mod_order(const BigInt &x) const
Definition ec_group.h:656
BigInt cube_mod_order(const BigInt &x) const
Definition ec_group.h:699
BigInt multiply_mod_order(const BigInt &x, const BigInt &y) const
Definition ec_group.h:679
bool a_is_zero() const
Definition ec_group.h:651
const BigInt & get_p() const
Definition ec_group.cpp:609
const BigInt & get_order() const
Definition ec_group.cpp:657
static EC_Group from_OID(const OID &oid)
Definition ec_group.cpp:427
static std::shared_ptr< EC_Group_Data > EC_group_info(const OID &oid)
Definition ec_named.cpp:15
const BigInt & get_g_x() const
Definition ec_group.cpp:661
bool used_explicit_encoding() const
Definition ec_group.h:262
const std::shared_ptr< EC_Group_Data > & _data() const
Definition ec_group.h:454
EC_Group(const BigInt &p, const BigInt &a, const BigInt &b, const BigInt &base_x, const BigInt &base_y, const BigInt &order, const BigInt &cofactor, const OID &oid=OID())
Definition ec_group.cpp:486
const OID & get_curve_oid() const
Definition ec_group.cpp:677
BigInt square_mod_order(const BigInt &x) const
Definition ec_group.h:670
bool has_cofactor() const
Definition ec_group.cpp:673
static size_t clear_registered_curve_data()
Definition ec_group.cpp:233
BigInt inverse_mod_order(const BigInt &x) const
Definition ec_group.h:663
static bool unregister(const OID &oid)
Definition ec_group.cpp:582
size_t point_size(EC_Point_Format format) const
Definition ec_group.h:704
size_t get_p_bytes() const
Definition ec_group.cpp:597
static OID EC_group_identity_from_order(const BigInt &order)
Definition ec_named.cpp:356
static EC_Scalar from_bigint(const EC_Group &group, const BigInt &bn)
Definition ec_scalar.cpp:69
static EC_Scalar from_bytes_mod_order(const EC_Group &group, std::span< const uint8_t > bytes)
Definition ec_scalar.cpp:53
bool operator!=(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition alg_id.cpp:68
bool operator==(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition alg_id.cpp:53
EC_Group_Engine
Definition ec_group.h:48
@ Optimized
Using per curve implementation; fastest available.
Definition ec_group.h:50
@ Generic
A generic implementation that handles many curves in one implementation.
Definition ec_group.h:52
EC_Group_Source
Definition ec_group.h:38
EC_Point OS2ECP(std::span< const uint8_t > data, const CurveGFp &curve)
Definition ec_point.cpp:866