Botan 3.12.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 DER encoded ECC domain parameter set
161 * @param der the bytes of the DER encoding
162 */
163 explicit EC_Group(std::span<const uint8_t> der);
164
165 BOTAN_DEPRECATED("Use EC_Group(std::span)")
166 EC_Group(const uint8_t der[], size_t der_len) : EC_Group(std::span{der, der_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 EC_Group::from_name(name) should succeed for this name
253 * either because it is a group compiled into the library or it is a group
254 * which has already been registered by the application at runtime.
255 */
256 static bool supports_named_group(std::string_view name);
257
258 /**
259 * Return true if this EC_Group was derived from an explicit encoding
260 *
261 * Explicit encoding of groups is deprecated; when support for explicit curves
262 * is removed in a future major release, this function will also be removed.
263 */
264 bool used_explicit_encoding() const { return m_explicit_encoding; }
265
266 /**
267 * Return how this EC_Group is implemented under the hood
268 *
269 * This is mostly useful for diagnostic or debugging purposes
270 */
271 EC_Group_Engine engine() const;
272
273 /**
274 * Return a set of known named EC groups
275 *
276 * This returns a set of groups for which from_name should succeed.
277 *
278 * Note that the set of included groups can vary based on the build
279 * configuration, and that this list does not include any groups registered
280 * by the application at runtime.
281 */
282 static const std::set<std::string>& known_named_groups();
283
284 /**
285 * Create the DER encoding of this domain
286 * @param form of encoding to use
287 * @returns the group information encoded as DER
288 */
289 BOTAN_DEPRECATED("Use the variant that does not take EC_Group_Encoding")
290 std::vector<uint8_t> DER_encode(EC_Group_Encoding form) const;
291
292 /**
293 * Create the DER encoding of this domain, using namedCurve format
294 * @returns the group information encoded as DER
295 */
296 std::vector<uint8_t> DER_encode() const;
297
298 /**
299 * Return the PEM encoding
300 * @return string containing PEM data
301 *
302 * @warning In Botan4 the form parameter will be removed and only
303 * namedCurve will be supported
304 *
305 * TODO(Botan4) remove the argument
306 */
307 std::string PEM_encode(EC_Group_Encoding form = EC_Group_Encoding::Explicit) const;
308
309 /**
310 * Return the size of p in bits (same as get_p().bits())
311 */
312 size_t get_p_bits() const;
313
314 /**
315 * Return the size of p in bytes (same as get_p().bytes())
316 */
317 size_t get_p_bytes() const;
318
319 /**
320 * Return the size of group order in bits (same as get_order().bits())
321 */
322 size_t get_order_bits() const;
323
324 /**
325 * Return the size of the group order in bytes (same as get_order().bytes())
326 */
327 size_t get_order_bytes() const;
328
329 /// Table for computing g*x + h*y
330 class BOTAN_PUBLIC_API(3, 6) Mul2Table final {
331 public:
332 /**
333 * Create a table for computing g*x + h*y
334 */
336
337 /**
338 * Return the elliptic curve point g*x + h*y
339 *
340 * Where g is the group generator and h is the value passed to the constructor
341 *
342 * Returns nullopt if g*x + h*y was the point at infinity
343 *
344 * @warning this function is variable time with respect to x and y
345 */
346 std::optional<EC_AffinePoint> mul2_vartime(const EC_Scalar& x, const EC_Scalar& y) const;
347
348 /**
349 * Check if v equals the x coordinate of g*x + h*y reduced modulo the order
350 *
351 * Where g is the group generator and h is the value passed to the constructor
352 *
353 * Returns false if unequal, including if g*x + h*y was the point at infinity
354 *
355 * @warning this function is variable time with respect to x and y
356 */
357 bool mul2_vartime_x_mod_order_eq(const EC_Scalar& v, const EC_Scalar& x, const EC_Scalar& y) const;
358
359 /**
360 * Check if v equals the x coordinate of g*x*c + h*y*c reduced modulo the order
361 *
362 * Where g is the group generator and h is the value passed to the constructor
363 *
364 * Returns false if unequal, including if g*x*c + h*y*c was the point at infinity
365 *
366 * @warning this function is variable time with respect to x and y
367 */
369 const EC_Scalar& c,
370 const EC_Scalar& x,
371 const EC_Scalar& y) const;
372
374 Mul2Table(const Mul2Table& other) = delete;
375 Mul2Table(Mul2Table&& other) noexcept;
376 Mul2Table& operator=(const Mul2Table& other) = delete;
377 Mul2Table& operator=(Mul2Table&& other) noexcept;
378
379 private:
380 std::unique_ptr<EC_Mul2Table_Data> m_tbl;
381 };
382
383 /**
384 * Return the OID of these domain parameters
385 * @result the OID
386 */
387 const OID& get_curve_oid() const;
388
389 /**
390 * Return the prime modulus of the field
391 */
392 const BigInt& get_p() const;
393
394 /**
395 * Return the a parameter of the elliptic curve equation
396 */
397 const BigInt& get_a() const;
398
399 /**
400 * Return the b parameter of the elliptic curve equation
401 */
402 const BigInt& get_b() const;
403
404 /**
405 * Return the x coordinate of the base point
406 */
407 const BigInt& get_g_x() const;
408
409 /**
410 * Return the y coordinate of the base point
411 */
412 const BigInt& get_g_y() const;
413
414 /**
415 * Return the order of the base point
416 * @result order of the base point
417 */
418 const BigInt& get_order() const;
419
420 /**
421 * Return the cofactor
422 * @result the cofactor
423 * TODO(Botan4): Remove this
424 */
425 const BigInt& get_cofactor() const;
426
427 /**
428 * Return true if the cofactor is > 1
429 * TODO(Botan4): Remove this
430 */
431 bool has_cofactor() const;
432
433 /*
434 * For internal use only
435 * TODO(Botan4): Move this to an internal header
436 */
437 static std::shared_ptr<EC_Group_Data> EC_group_info(const OID& oid);
438
439 /*
440 * For internal use only
441 *
442 * @warning this invalidates pointers and can cause memory corruption.
443 * This function exists only to be called in tests.
444 *
445 * TODO(Botan4): Move this to an internal header
446 */
447 static size_t clear_registered_curve_data();
448
449 /*
450 * For internal use only
451 * TODO(Botan4): Move this to an internal header
452 */
453 static OID EC_group_identity_from_order(const BigInt& order);
454
455 /*
456 * For internal use only
457 */
458 const std::shared_ptr<EC_Group_Data>& _data() const { return m_data; }
459
460#if defined(BOTAN_HAS_LEGACY_EC_POINT)
461 /**
462 * Check if y is a plausible point on the curve
463 *
464 * In particular, checks that it is a point on the curve, not infinity,
465 * and that it has order matching the group.
466 */
467 bool verify_public_element(const EC_Point& y) const;
468
469 /**
470 * OS2ECP (Octet String To Elliptic Curve Point)
471 *
472 * Deserialize an encoded point. Verifies that the point is on the curve.
473 */
474 BOTAN_DEPRECATED("Use EC_AffinePoint::deserialize") EC_Point OS2ECP(const uint8_t bits[], size_t len) const {
475 return EC_AffinePoint(*this, std::span{bits, len}).to_legacy_point();
476 }
477
478 BOTAN_DEPRECATED("Use EC_AffinePoint::deserialize")
479 EC_Point OS2ECP(std::span<const uint8_t> encoded_point) const {
480 return EC_AffinePoint(*this, encoded_point).to_legacy_point();
481 }
482
483 /**
484 * Return group base point
485 * @result base point
486 */
487 BOTAN_DEPRECATED("Use EC_AffinePoint::generator") const EC_Point& get_base_point() const;
488
489 // Everything below here will be removed in a future release:
490
491 /**
492 * Return the canonical group generator
493 * @result standard generator of the curve
494 */
495 BOTAN_DEPRECATED("Use EC_AffinePoint::generator") const EC_Point& generator() const;
496
497 /**
498 * Multi exponentiate. Not constant time.
499 * @return base_point*x + h*y
500 */
501 BOTAN_DEPRECATED("Use EC_Group::Mul2Table")
502 EC_Point point_multiply(const BigInt& x_bn, const EC_Point& h_pt, const BigInt& y_bn) const {
503 auto x = EC_Scalar::from_bigint(*this, x_bn);
504 auto y = EC_Scalar::from_bigint(*this, y_bn);
505 auto h = EC_AffinePoint(*this, h_pt);
506
507 const Mul2Table gh_mul(h);
508
509 if(auto r = gh_mul.mul2_vartime(x, y)) {
510 return r->to_legacy_point();
511 } else {
512 return EC_AffinePoint::identity(*this).to_legacy_point();
513 }
514 }
515
516 /**
517 * Blinded point multiplication, attempts resistance to side channels
518 * @param k_bn the scalar
519 * @param rng a random number generator
520 * @return base_point*k
521 */
522 BOTAN_DEPRECATED("Use EC_AffinePoint and EC_Scalar")
523 EC_Point blinded_base_point_multiply(const BigInt& k_bn,
524 RandomNumberGenerator& rng,
525 std::vector<BigInt>& /*ws*/) const {
526 auto k = EC_Scalar::from_bigint(*this, k_bn);
527 auto pt = EC_AffinePoint::g_mul(k, rng);
528 return pt.to_legacy_point();
529 }
530
531 /**
532 * Blinded point multiplication, attempts resistance to side channels
533 * Returns just the x coordinate of the point
534 *
535 * @param k_bn the scalar
536 * @param rng a random number generator
537 * @return x coordinate of base_point*k
538 */
539 BOTAN_DEPRECATED("Use EC_AffinePoint and EC_Scalar")
540 BigInt blinded_base_point_multiply_x(const BigInt& k_bn,
541 RandomNumberGenerator& rng,
542 std::vector<BigInt>& /*ws*/) const {
543 auto k = EC_Scalar::from_bigint(*this, k_bn);
544 return BigInt(EC_AffinePoint::g_mul(k, rng).x_bytes());
545 }
546
547 /**
548 * Blinded point multiplication, attempts resistance to side channels
549 * @param point input point
550 * @param k_bn the scalar
551 * @param rng a random number generator
552 * @return point*k
553 */
554 BOTAN_DEPRECATED("Use EC_AffinePoint and EC_Scalar")
555 EC_Point blinded_var_point_multiply(const EC_Point& point,
556 const BigInt& k_bn,
557 RandomNumberGenerator& rng,
558 std::vector<BigInt>& /*ws*/) const {
559 auto k = EC_Scalar::from_bigint(*this, k_bn);
560 auto pt = EC_AffinePoint(*this, point);
561 return pt.mul(k, rng).to_legacy_point();
562 }
563
564 /**
565 * Return a random scalar ie an integer in [1,order)
566 */
567 BOTAN_DEPRECATED("Use EC_Scalar::random") BigInt random_scalar(RandomNumberGenerator& rng) const {
568 return EC_Scalar::random(*this, rng).to_bigint();
569 }
570
571 /**
572 * Hash onto the curve.
573 * For some curve types no mapping is currently available, in this
574 * case this function will throw an exception.
575 *
576 * @param hash_fn the hash function to use (typically "SHA-256" or "SHA-512")
577 * @param input the input to hash
578 * @param input_len length of input in bytes
579 * @param domain_sep a domain separator
580 * @param domain_sep_len length of domain_sep in bytes
581 * @param random_oracle if the mapped point must be uniform (use
582 "true" here unless you know what you are doing)
583 */
584 BOTAN_DEPRECATED("Use EC_AffinePoint")
585 EC_Point hash_to_curve(std::string_view hash_fn,
586 const uint8_t input[],
587 size_t input_len,
588 const uint8_t domain_sep[],
589 size_t domain_sep_len,
590 bool random_oracle = true) const {
591 auto inp = std::span{input, input_len};
592 auto dst = std::span{domain_sep, domain_sep_len};
593
594 if(random_oracle) {
595 return EC_AffinePoint::hash_to_curve_ro(*this, hash_fn, inp, dst).to_legacy_point();
596 } else {
597 return EC_AffinePoint::hash_to_curve_nu(*this, hash_fn, inp, dst).to_legacy_point();
598 }
599 }
600
601 /**
602 * Hash onto the curve.
603 * For some curve types no mapping is currently available, in this
604 * case this function will throw an exception.
605 *
606 * @param hash_fn the hash function to use (typically "SHA-256" or "SHA-512")
607 * @param input the input to hash
608 * @param input_len length of input in bytes
609 * @param domain_sep a domain separator
610 * @param random_oracle if the mapped point must be uniform (use
611 "true" here unless you know what you are doing)
612 */
613 BOTAN_DEPRECATED("Use EC_AffinePoint")
614 EC_Point hash_to_curve(std::string_view hash_fn,
615 const uint8_t input[],
616 size_t input_len,
617 std::string_view domain_sep,
618 bool random_oracle = true) const {
619 auto inp = std::span{input, input_len};
620
621 if(random_oracle) {
622 return EC_AffinePoint::hash_to_curve_ro(*this, hash_fn, inp, domain_sep).to_legacy_point();
623 } else {
624 return EC_AffinePoint::hash_to_curve_nu(*this, hash_fn, inp, domain_sep).to_legacy_point();
625 }
626 }
627
628 /**
629 * Return a point on this curve with the affine values x, y
630 */
631 BOTAN_DEPRECATED("Deprecated - use EC_AffinePoint") EC_Point point(const BigInt& x, const BigInt& y) const {
632 if(auto pt = EC_AffinePoint::from_bigint_xy(*this, x, y)) {
633 return pt->to_legacy_point();
634 } else {
635 throw Decoding_Error("Invalid x/y coordinates for elliptic curve point");
636 }
637 }
638
639 /**
640 * Return the zero (or infinite) point on this curve
641 */
642 BOTAN_DEPRECATED("Deprecated no replacement") EC_Point zero_point() const {
643 return EC_AffinePoint::identity(*this).to_legacy_point();
644 }
645#endif
646
647 /**
648 * Return if a == -3 mod p
649 */
650 BOTAN_DEPRECATED("Deprecated no replacement") bool a_is_minus_3() const { return get_a() + 3 == get_p(); }
651
652 /**
653 * Return if a == 0 mod p
654 */
655 BOTAN_DEPRECATED("Deprecated no replacement") bool a_is_zero() const { return get_a().is_zero(); }
656
657 /*
658 * Reduce x modulo the order
659 */
660 BOTAN_DEPRECATED("Use EC_Scalar") BigInt mod_order(const BigInt& x) const {
661 return EC_Scalar::from_bytes_mod_order(*this, x.serialize()).to_bigint();
662 }
663
664 /*
665 * Return inverse of x modulo the order
666 */
667 BOTAN_DEPRECATED("Use EC_Scalar") BigInt inverse_mod_order(const BigInt& x) const {
668 return EC_Scalar::from_bigint(*this, x).invert().to_bigint();
669 }
670
671 /*
672 * Reduce (x*x) modulo the order
673 */
674 BOTAN_DEPRECATED("Use EC_Scalar") BigInt square_mod_order(const BigInt& x) const {
675 auto xs = EC_Scalar::from_bigint(*this, x);
676 xs.square_self();
677 return xs.to_bigint();
678 }
679
680 /*
681 * Reduce (x*y) modulo the order
682 */
683 BOTAN_DEPRECATED("Use EC_Scalar") BigInt multiply_mod_order(const BigInt& x, const BigInt& y) const {
684 auto xs = EC_Scalar::from_bigint(*this, x);
685 auto ys = EC_Scalar::from_bigint(*this, y);
686 return (xs * ys).to_bigint();
687 }
688
689 /*
690 * Reduce (x*y*z) modulo the order
691 */
692 BOTAN_DEPRECATED("Use EC_Scalar")
693 BigInt multiply_mod_order(const BigInt& x, const BigInt& y, const BigInt& z) const {
694 auto xs = EC_Scalar::from_bigint(*this, x);
695 auto ys = EC_Scalar::from_bigint(*this, y);
696 auto zs = EC_Scalar::from_bigint(*this, z);
697 return (xs * ys * zs).to_bigint();
698 }
699
700 /*
701 * Return x^3 modulo the order
702 */
703 BOTAN_DEPRECATED("Deprecated no replacement") BigInt cube_mod_order(const BigInt& x) const {
704 auto xs = EC_Scalar::from_bigint(*this, x);
705 return (xs * xs * xs).to_bigint();
706 }
707
708 BOTAN_DEPRECATED("Just serialize the point and check") size_t point_size(EC_Point_Format format) const {
709 // Hybrid and standard format are (x,y), compressed is y, +1 format byte
710 if(format == EC_Point_Format::Compressed) {
711 return (1 + get_p_bytes());
712 } else {
713 return (1 + 2 * get_p_bytes());
714 }
715 }
716
717 private:
718 static EC_Group_Data_Map& ec_group_data();
719
720 explicit EC_Group(std::shared_ptr<EC_Group_Data>&& data);
721
722 static std::pair<std::shared_ptr<EC_Group_Data>, bool> DER_decode_EC_group(std::span<const uint8_t> der,
723 EC_Group_Source source);
724
725 static std::shared_ptr<EC_Group_Data> load_EC_group_info(const char* p,
726 const char* a,
727 const char* b,
728 const char* g_x,
729 const char* g_y,
730 const char* order,
731 const OID& oid);
732
733 const EC_Group_Data& data() const;
734
735 // Member data
736 std::shared_ptr<EC_Group_Data> m_data;
737 bool m_explicit_encoding = false;
738};
739
740inline bool operator!=(const EC_Group& lhs, const EC_Group& rhs) {
741 return !(lhs == rhs);
742}
743
744} // namespace Botan
745
746#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:864
BOTAN_FUTURE_EXPLICIT Mul2Table(const EC_AffinePoint &h)
Definition ec_group.cpp:860
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:873
bool a_is_minus_3() const
Definition ec_group.h:650
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:511
const BigInt & get_b() const
Definition ec_group.cpp:647
const BigInt & get_a() const
Definition ec_group.cpp:643
bool initialized() const
Definition ec_group.h:226
const BigInt & get_g_y() const
Definition ec_group.cpp:695
const BigInt & get_cofactor() const
Definition ec_group.cpp:699
BigInt mod_order(const BigInt &x) const
Definition ec_group.h:660
BigInt cube_mod_order(const BigInt &x) const
Definition ec_group.h:703
BigInt multiply_mod_order(const BigInt &x, const BigInt &y) const
Definition ec_group.h:683
bool a_is_zero() const
Definition ec_group.h:655
const BigInt & get_p() const
Definition ec_group.cpp:639
const BigInt & get_order() const
Definition ec_group.cpp:687
static EC_Group from_OID(const OID &oid)
Definition ec_group.cpp:457
static std::shared_ptr< EC_Group_Data > EC_group_info(const OID &oid)
Definition ec_named.cpp:16
const BigInt & get_g_x() const
Definition ec_group.cpp:691
bool used_explicit_encoding() const
Definition ec_group.h:264
const std::shared_ptr< EC_Group_Data > & _data() const
Definition ec_group.h:458
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:516
const OID & get_curve_oid() const
Definition ec_group.cpp:707
BigInt square_mod_order(const BigInt &x) const
Definition ec_group.h:674
bool has_cofactor() const
Definition ec_group.cpp:703
static size_t clear_registered_curve_data()
Definition ec_group.cpp:233
BigInt inverse_mod_order(const BigInt &x) const
Definition ec_group.h:667
static bool unregister(const OID &oid)
Definition ec_group.cpp:612
size_t point_size(EC_Point_Format format) const
Definition ec_group.h:708
size_t get_p_bytes() const
Definition ec_group.cpp:627
static OID EC_group_identity_from_order(const BigInt &order)
Definition ec_named.cpp:357
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