You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

566 lines
22 KiB

  1. /**
  2. * @file decaf.hxx
  3. * @author Mike Hamburg
  4. *
  5. * @copyright
  6. * Copyright (c) 2015 Cryptography Research, Inc. \n
  7. * Released under the MIT License. See LICENSE.txt for license information.
  8. *
  9. * @brief A group of prime order p, C++ wrapper.
  10. *
  11. * The Decaf library implements cryptographic operations on a an elliptic curve
  12. * group of prime order p. It accomplishes this by using a twisted Edwards
  13. * curve (isogenous to Ed448-Goldilocks) and wiping out the cofactor.
  14. *
  15. * The formulas are all complete and have no special cases, except that
  16. * decaf_448_decode can fail because not every sequence of bytes is a valid group
  17. * element.
  18. *
  19. * The formulas contain no data-dependent branches, timing or memory accesses,
  20. * except for decaf_448_base_double_scalarmul_non_secret.
  21. */
  22. #ifndef __DECAF_448_HXX__
  23. #define __DECAF_448_HXX__ 1
  24. /** This code uses posix_memalign. */
  25. #define _XOPEN_SOURCE 600
  26. #include <stdlib.h>
  27. #include <string.h> /* for memcpy */
  28. #include "decaf.h"
  29. #include <string>
  30. #include <sys/types.h>
  31. #include <limits.h>
  32. /* TODO: This is incomplete */
  33. /* TODO: attribute nonnull */
  34. /** @cond internal */
  35. #if __cplusplus >= 201103L
  36. #define NOEXCEPT noexcept
  37. #define EXPLICIT_CON explicit
  38. #define GET_DATA(str) ((const unsigned char *)&(str)[0])
  39. #else
  40. #define NOEXCEPT throw()
  41. #define EXPLICIT_CON
  42. #define GET_DATA(str) ((const unsigned char *)((str).data()))
  43. #endif
  44. /** @endcond */
  45. namespace decaf {
  46. /**
  47. * Securely erase contents of memory.
  48. */
  49. void really_bzero(void *data, size_t size);
  50. /**
  51. * @brief Group with prime order.
  52. * @todo Move declarations of functions up here?
  53. */
  54. template<unsigned int bits = 448> struct decaf;
  55. /** @brief Passed to constructors to avoid (conservative) initialization */
  56. static const class NOINIT { public: NOINIT(){} } NI;
  57. /**
  58. * @brief Ed448-Goldilocks/Decaf instantiation of group.
  59. */
  60. template<> struct decaf<448> {
  61. /** @brief An exception for when crypto (ie point decode) has failed. */
  62. class CryptoException : public std::exception {
  63. public:
  64. /** @return "CryptoException" */
  65. virtual const char * what() const NOEXCEPT { return "CryptoException"; }
  66. };
  67. /** @cond internal */
  68. class Point;
  69. class Precomputed;
  70. /** @endcond */
  71. /**
  72. * @brief A scalar modulo the curve order.
  73. * Supports the usual arithmetic operations, all in constant time.
  74. */
  75. class Scalar {
  76. public:
  77. /** @brief access to the underlying scalar object */
  78. decaf_448_scalar_t s;
  79. /** @brief Don't initialize. */
  80. inline Scalar(const NOINIT &) {}
  81. /** @brief Set to an unsigned word */
  82. inline Scalar(const decaf_word_t w) NOEXCEPT { *this = w; }
  83. /** @brief Set to a signed word */
  84. inline Scalar(const int w) NOEXCEPT { *this = w; }
  85. /** @brief Construct from decaf_scalar_t object. */
  86. inline Scalar(const decaf_448_scalar_t &t = decaf_448_scalar_zero) NOEXCEPT { decaf_448_scalar_copy(s,t); }
  87. /** @brief Copy constructor. */
  88. inline Scalar(const Scalar &x) NOEXCEPT { decaf_448_scalar_copy(s,x.s); }
  89. /** @brief Construct from arbitrary-length little-endian byte sequence. */
  90. inline explicit Scalar(const std::string &str) NOEXCEPT { *this = str; }
  91. /** @brief Construct from arbitrary-length little-endian byte sequence. */
  92. inline Scalar(const unsigned char *buffer, size_t n) NOEXCEPT { decaf_448_scalar_decode_long(s,buffer,n); }
  93. /** @brief Construct from arbitrary-length little-endian byte sequence. */
  94. inline Scalar(const char *buffer, size_t n) NOEXCEPT { decaf_448_scalar_decode_long(s,(const unsigned char *)buffer,n); }
  95. /** @brief Construct from arbitrary-length little-endian byte sequence. */
  96. inline Scalar(const void *buffer, size_t n) NOEXCEPT { decaf_448_scalar_decode_long(s,(const unsigned char *)buffer,n); }
  97. /** @brief Assignment. */
  98. inline Scalar& operator=(const Scalar &x) NOEXCEPT { decaf_448_scalar_copy(s,x.s); return *this; }
  99. /** @brief Assign from unsigned word. */
  100. inline Scalar& operator=(decaf_word_t w) NOEXCEPT { decaf_448_scalar_set(s,w); return *this; }
  101. /** @brief Assign from signed int. */
  102. inline Scalar& operator=(int w) {
  103. Scalar t(-(decaf_word_t)INT_MIN);
  104. decaf_448_scalar_set(s,(decaf_word_t)w - (decaf_word_t)INT_MIN);
  105. *this -= t;
  106. return *this;
  107. }
  108. /** Destructor securely erases the scalar. */
  109. inline ~Scalar() NOEXCEPT { decaf_448_scalar_destroy(s); }
  110. /** @brief Assign from arbitrary-length little-endian byte sequence in C++ string. */
  111. inline Scalar &operator=(const std::string &str) NOEXCEPT {
  112. decaf_448_scalar_decode_long(s,GET_DATA(str),str.length()); return *this;
  113. }
  114. /**
  115. * @brief Decode from correct-length little-endian byte sequence.
  116. * @return DECAF_FAILURE if the scalar is greater than or equal to the group order q.
  117. */
  118. static inline decaf_bool_t __attribute__((warn_unused_result)) decode (
  119. Scalar &sc, const unsigned char buffer[DECAF_448_SCALAR_BYTES]
  120. ) NOEXCEPT {
  121. return decaf_448_scalar_decode(sc.s,buffer);
  122. }
  123. /** @brief Decode from correct-length little-endian byte sequence in C++ string. */
  124. static inline decaf_bool_t __attribute__((warn_unused_result)) decode (
  125. Scalar &sc, const std::string buffer
  126. ) NOEXCEPT {
  127. if (buffer.size() != DECAF_448_SCALAR_BYTES) return DECAF_FAILURE;
  128. return decaf_448_scalar_decode(sc.s,GET_DATA(buffer));
  129. }
  130. /** @brief Encode to fixed-length string */
  131. inline EXPLICIT_CON operator std::string() const NOEXCEPT {
  132. unsigned char buffer[DECAF_448_SCALAR_BYTES];
  133. decaf_448_scalar_encode(buffer, s);
  134. return std::string((char*)buffer,sizeof(buffer));
  135. }
  136. /** @brief Encode to fixed-length buffer */
  137. inline void encode(unsigned char buffer[DECAF_448_SCALAR_BYTES]) const NOEXCEPT{
  138. decaf_448_scalar_encode(buffer, s);
  139. }
  140. /** Add. */
  141. inline Scalar operator+ (const Scalar &q) const NOEXCEPT { Scalar r(NI); decaf_448_scalar_add(r.s,s,q.s); return r; }
  142. /** Add to this. */
  143. inline Scalar &operator+=(const Scalar &q) NOEXCEPT { decaf_448_scalar_add(s,s,q.s); return *this; }
  144. /** Subtract. */
  145. inline Scalar operator- (const Scalar &q) const NOEXCEPT { Scalar r(NI); decaf_448_scalar_sub(r.s,s,q.s); return r; }
  146. /** Subtract from this. */
  147. inline Scalar &operator-=(const Scalar &q) NOEXCEPT { decaf_448_scalar_sub(s,s,q.s); return *this; }
  148. /** Multiply */
  149. inline Scalar operator* (const Scalar &q) const NOEXCEPT { Scalar r(NI); decaf_448_scalar_mul(r.s,s,q.s); return r; }
  150. /** Multiply into this. */
  151. inline Scalar &operator*=(const Scalar &q) NOEXCEPT { decaf_448_scalar_mul(s,s,q.s); return *this; }
  152. /** Negate */
  153. inline Scalar operator- () const NOEXCEPT { Scalar r(NI); decaf_448_scalar_sub(r.s,decaf_448_scalar_zero,s); return r; }
  154. /** @brief Invert with Fermat's Little Theorem (slow!). If *this == 0, return 0. */
  155. inline Scalar inverse() const NOEXCEPT { Scalar r; decaf_448_scalar_invert(r.s,s); return r; }
  156. /** @brief Divide by inverting q. If q == 0, return 0. */
  157. inline Scalar operator/ (const Scalar &q) const NOEXCEPT { Scalar r(NI); decaf_448_scalar_mul(r.s,s,q.inverse().s); return r; }
  158. /** @brief Divide by inverting q. If q == 0, return 0. */
  159. inline Scalar &operator/=(const Scalar &q) NOEXCEPT { decaf_448_scalar_mul(s,s,q.inverse().s); return *this; }
  160. /** @brief Compare in constant time */
  161. inline bool operator!=(const Scalar &q) const NOEXCEPT { return ! decaf_448_scalar_eq(s,q.s); }
  162. /** @brief Compare in constant time */
  163. inline bool operator==(const Scalar &q) const NOEXCEPT { return !!decaf_448_scalar_eq(s,q.s); }
  164. /** @brief Scalarmul with scalar on left. */
  165. inline Point operator* (const Point &q) const NOEXCEPT { return q * (*this); }
  166. /** @brief Scalarmul-precomputed with scalar on left. */
  167. inline Point operator* (const Precomputed &q) const NOEXCEPT { return q * (*this); }
  168. /** @brief Direct scalar multiplication.
  169. * @todo Fix up bools.
  170. */
  171. inline decaf_bool_t direct_scalarmul(
  172. unsigned char out[DECAF_448_SER_BYTES],
  173. const unsigned char in[DECAF_448_SER_BYTES],
  174. decaf_bool_t allow_identity=DECAF_FALSE,
  175. decaf_bool_t short_circuit=DECAF_TRUE
  176. ) const NOEXCEPT {
  177. return decaf_448_direct_scalarmul(out, in, s, allow_identity, short_circuit);
  178. }
  179. /** @brief Direct scalar multiplication.
  180. * @todo Fix up bools.
  181. */
  182. inline std::string direct_scalarmul(
  183. const std::string in,
  184. decaf_bool_t allow_identity=DECAF_FALSE,
  185. decaf_bool_t short_circuit=DECAF_TRUE
  186. ) const NOEXCEPT {
  187. unsigned char out[DECAF_448_SER_BYTES];
  188. if (decaf_448_direct_scalarmul(out, GET_DATA(in), s, allow_identity, short_circuit)) {
  189. return std::string((char *)out,sizeof(out));
  190. } else {
  191. return "";
  192. }
  193. }
  194. };
  195. /**
  196. * @brief Element of prime-order group.
  197. */
  198. class Point {
  199. public:
  200. /** The c-level object. */
  201. decaf_448_point_t p;
  202. /** @brief Don't initialize. */
  203. inline Point(const NOINIT &) {}
  204. /** @brief Constructor sets to identity by default. */
  205. inline Point(const decaf_448_point_t &q = decaf_448_point_identity) { decaf_448_point_copy(p,q); }
  206. /** @brief Copy constructor. */
  207. inline Point(const Point &q) { decaf_448_point_copy(p,q.p); }
  208. /** @brief Assignment. */
  209. inline Point& operator=(const Point &q) { decaf_448_point_copy(p,q.p); return *this; }
  210. /** @brief Destructor securely erases the point. */
  211. inline ~Point() { decaf_448_point_destroy(p); }
  212. /**
  213. * @brief Initialize from C++ fixed-length byte string.
  214. * The all-zero string maps to the identity.
  215. *
  216. * @throw CryptoException the string was the wrong length, or wasn't the encoding of a point,
  217. * or was the identity and allow_identity was DECAF_FALSE.
  218. */
  219. inline explicit Point(const std::string &s, decaf_bool_t allow_identity=DECAF_TRUE) throw(CryptoException) {
  220. if (!decode(*this,s,allow_identity)) throw CryptoException();
  221. }
  222. /**
  223. * @brief Initialize from C fixed-length byte string.
  224. * The all-zero string maps to the identity.
  225. *
  226. * @throw CryptoException the string was the wrong length, or wasn't the encoding of a point,
  227. * or was the identity and allow_identity was DECAF_FALSE.
  228. */
  229. inline explicit Point(const unsigned char buffer[DECAF_448_SER_BYTES], decaf_bool_t allow_identity=DECAF_TRUE)
  230. throw(CryptoException) { if (!decode(*this,buffer,allow_identity)) throw CryptoException(); }
  231. /**
  232. * @brief Initialize from C fixed-length byte string.
  233. * The all-zero string maps to the identity.
  234. *
  235. * @retval DECAF_SUCCESS the string was successfully decoded.
  236. * @return DECAF_FAILURE the string wasn't the encoding of a point, or was the identity
  237. * and allow_identity was DECAF_FALSE. Contents of the buffer are undefined.
  238. */
  239. static inline decaf_bool_t __attribute__((warn_unused_result)) decode (
  240. Point &p, const unsigned char buffer[DECAF_448_SER_BYTES], decaf_bool_t allow_identity=DECAF_TRUE
  241. ) NOEXCEPT {
  242. return decaf_448_point_decode(p.p,buffer,allow_identity);
  243. }
  244. /**
  245. * @brief Initialize from C++ fixed-length byte string.
  246. * The all-zero string maps to the identity.
  247. *
  248. * @retval DECAF_SUCCESS the string was successfully decoded.
  249. * @return DECAF_FAILURE the string was the wrong length, or wasn't the encoding of a point,
  250. * or was the identity and allow_identity was DECAF_FALSE. Contents of the buffer are undefined.
  251. */
  252. static inline decaf_bool_t __attribute__((warn_unused_result)) decode (
  253. Point &p, const std::string &buffer, decaf_bool_t allow_identity=DECAF_TRUE
  254. ) NOEXCEPT {
  255. if (buffer.size() != DECAF_448_SER_BYTES) return DECAF_FAILURE;
  256. return decaf_448_point_decode(p.p,GET_DATA(buffer),allow_identity);
  257. }
  258. /**
  259. * @brief Map to the curve from a C buffer.
  260. * The all-zero buffer maps to the identity, as does the buffer {1,0...}
  261. */
  262. static inline Point from_hash_nonuniform ( const unsigned char buffer[DECAF_448_SER_BYTES] ) NOEXCEPT {
  263. Point p(NI); decaf_448_point_from_hash_nonuniform(p.p,buffer); return p;
  264. }
  265. /**
  266. * @brief Map to the curve from a C++ string buffer.
  267. * The empty or all-zero string maps to the identity, as does the string "\x01".
  268. * If the buffer is shorter than (TODO) DECAF_448_SER_BYTES, it will be zero-padded on the right.
  269. */
  270. static inline Point from_hash_nonuniform ( const std::string &s ) NOEXCEPT {
  271. std::string t = s;
  272. if (t.size() < DECAF_448_SER_BYTES) t.insert(t.size(),DECAF_448_SER_BYTES-t.size(),0);
  273. Point p(NI); decaf_448_point_from_hash_nonuniform(p.p,GET_DATA(t)); return p;
  274. }
  275. /**
  276. * @brief Map uniformly to the curve from a C buffer.
  277. * The all-zero buffer maps to the identity, as does the buffer {1,0...}.
  278. */
  279. static inline Point from_hash ( const unsigned char buffer[2*DECAF_448_SER_BYTES] ) NOEXCEPT {
  280. Point p(NI); decaf_448_point_from_hash_uniform(p.p,buffer); return p;
  281. }
  282. /**
  283. * @brief Map uniformly to the curve from a C++ buffer.
  284. * The empty or all-zero string maps to the identity, as does the string "\x01".
  285. * If the buffer is shorter than (TODO) 2*DECAF_448_SER_BYTES, well, it won't be as uniform,
  286. * but the buffer will be zero-padded on the right.
  287. */
  288. static inline Point from_hash ( const std::string &s ) NOEXCEPT {
  289. std::string t = s;
  290. if (t.size() <= DECAF_448_SER_BYTES) return from_hash_nonuniform(s);
  291. if (t.size() < 2*DECAF_448_SER_BYTES) t.insert(t.size(),2*DECAF_448_SER_BYTES-t.size(),0);
  292. Point p(NI); decaf_448_point_from_hash_uniform(p.p,GET_DATA(t)); return p;
  293. }
  294. /**
  295. * @brief Encode to string. The identity encodes to the all-zero string.
  296. */
  297. inline EXPLICIT_CON operator std::string() const NOEXCEPT {
  298. unsigned char buffer[DECAF_448_SER_BYTES];
  299. decaf_448_point_encode(buffer, p);
  300. return std::string((char*)buffer,sizeof(buffer));
  301. }
  302. /**
  303. * @brief Encode to a C buffer. The identity encodes to all zeros.
  304. */
  305. inline void encode(unsigned char buffer[DECAF_448_SER_BYTES]) const NOEXCEPT{
  306. decaf_448_point_encode(buffer, p);
  307. }
  308. /** @brief Point add. */
  309. inline Point operator+ (const Point &q) const NOEXCEPT { Point r(NI); decaf_448_point_add(r.p,p,q.p); return r; }
  310. /** @brief Point add. */
  311. inline Point &operator+=(const Point &q) NOEXCEPT { decaf_448_point_add(p,p,q.p); return *this; }
  312. /** @brief Point subtract. */
  313. inline Point operator- (const Point &q) const NOEXCEPT { Point r(NI); decaf_448_point_sub(r.p,p,q.p); return r; }
  314. /** @brief Point subtract. */
  315. inline Point &operator-=(const Point &q) NOEXCEPT { decaf_448_point_sub(p,p,q.p); return *this; }
  316. /** @brief Point negate. */
  317. inline Point operator- () const NOEXCEPT { Point r(NI); decaf_448_point_negate(r.p,p); return r; }
  318. /** @brief Double the point out of place. */
  319. inline Point times_two () const NOEXCEPT { Point r(NI); decaf_448_point_double(r.p,p); return r; }
  320. /** @brief Double the point in place. */
  321. inline Point &double_in_place() NOEXCEPT { decaf_448_point_double(p,p); return *this; }
  322. /** @brief Constant-time compare. */
  323. inline bool operator!=(const Point &q) const NOEXCEPT { return ! decaf_448_point_eq(p,q.p); }
  324. /** @brief Constant-time compare. */
  325. inline bool operator==(const Point &q) const NOEXCEPT { return !!decaf_448_point_eq(p,q.p); }
  326. /** @brief Scalar multiply. */
  327. inline Point operator* (const Scalar &s) const NOEXCEPT { Point r(NI); decaf_448_point_scalarmul(r.p,p,s.s); return r; }
  328. /** @brief Scalar multiply in place. */
  329. inline Point &operator*=(const Scalar &s) NOEXCEPT { decaf_448_point_scalarmul(p,p,s.s); return *this; }
  330. /** @brief Multiply by s.inverse(). If s=0, maps to the identity. */
  331. inline Point operator/ (const Scalar &s) const NOEXCEPT { return (*this) * s.inverse(); }
  332. /** @brief Multiply by s.inverse(). If s=0, maps to the identity. */
  333. inline Point &operator/=(const Scalar &s) NOEXCEPT { return (*this) *= s.inverse(); }
  334. /** @brief Double-scalar multiply, equivalent to q*qs + r*rs but faster. */
  335. static inline Point double_scalarmul (
  336. const Point &q, const Scalar &qs, const Point &r, const Scalar &rs
  337. ) NOEXCEPT {
  338. Point p(NI); decaf_448_point_double_scalarmul(p.p,q.p,qs.s,r.p,rs.s); return p;
  339. }
  340. /**
  341. * @brief Double-scalar multiply, equivalent to q*qs + r*rs but faster.
  342. * For those who like their scalars before the point.
  343. */
  344. static inline Point double_scalarmul (
  345. const Scalar &qs, const Point &q, const Scalar &rs, const Point &r
  346. ) NOEXCEPT {
  347. Point p(NI); decaf_448_point_double_scalarmul(p.p,q.p,qs.s,r.p,rs.s); return p;
  348. }
  349. /**
  350. * @brief Double-scalar multiply: this point by the first scalar and base by the second scalar.
  351. * @warning This function takes variable time, and may leak the scalars (or points, but currently
  352. * it doesn't).
  353. */
  354. inline Point non_secret_combo_with_base(const Scalar &s, const Scalar &s_base) {
  355. Point r(NI); decaf_448_base_double_scalarmul_non_secret(r.p,s_base.s,p,s.s); return r;
  356. }
  357. /** @brief Return the base point */
  358. static inline const Point base() NOEXCEPT { return Point(decaf_448_point_base); }
  359. /** @brief Return the identity point */
  360. static inline const Point identity() NOEXCEPT { return Point(decaf_448_point_identity); }
  361. };
  362. /**
  363. * @brief Precomputed table of points.
  364. * Minor difficulties arise here because the decaf API doesn't expose, as a constant, how big such an object is.
  365. * Therefore we have to call malloc() or friends, but that's probably for the best, because you don't want to
  366. * stack-allocate a 15kiB object anyway.
  367. */
  368. class Precomputed {
  369. private:
  370. /** @cond internal */
  371. union {
  372. decaf_448_precomputed_s *mine;
  373. const decaf_448_precomputed_s *yours;
  374. } ours;
  375. bool isMine;
  376. inline void clear() NOEXCEPT {
  377. if (isMine) {
  378. decaf_448_precomputed_destroy(ours.mine);
  379. free(ours.mine);
  380. ours.yours = decaf_448_precomputed_base;
  381. isMine = false;
  382. }
  383. }
  384. inline void alloc() throw(std::bad_alloc) {
  385. if (isMine) return;
  386. int ret = posix_memalign((void**)&ours.mine, alignof_decaf_448_precomputed_s,sizeof_decaf_448_precomputed_s);
  387. if (ret || !ours.mine) {
  388. isMine = false;
  389. throw std::bad_alloc();
  390. }
  391. isMine = true;
  392. }
  393. inline const decaf_448_precomputed_s *get() const NOEXCEPT { return isMine ? ours.mine : ours.yours; }
  394. /** @endcond */
  395. public:
  396. /** Destructor securely erases the memory. */
  397. inline ~Precomputed() NOEXCEPT { clear(); }
  398. /**
  399. * @brief Initialize from underlying type, declared as a reference to prevent
  400. * it from being called with 0, thereby breaking override.
  401. *
  402. * The underlying object must remain valid throughout the lifetime of this one.
  403. *
  404. * By default, initializes to the table for the base point.
  405. *
  406. * @warning The empty initializer makes this equal to base, unlike the empty
  407. * initializer for points which makes this equal to the identity.
  408. */
  409. inline Precomputed(
  410. const decaf_448_precomputed_s &yours = *decaf_448_precomputed_base
  411. ) NOEXCEPT {
  412. ours.yours = &yours;
  413. isMine = false;
  414. }
  415. /**
  416. * @brief Assign. This may require an allocation and memcpy.
  417. */
  418. inline Precomputed &operator=(const Precomputed &it) throw(std::bad_alloc) {
  419. if (this == &it) return *this;
  420. if (it.isMine) {
  421. alloc();
  422. memcpy(ours.mine,it.ours.mine,sizeof_decaf_448_precomputed_s);
  423. } else {
  424. clear();
  425. ours.yours = it.ours.yours;
  426. }
  427. isMine = it.isMine;
  428. return *this;
  429. }
  430. /**
  431. * @brief Initilaize from point. Must allocate memory, and may throw.
  432. */
  433. inline Precomputed &operator=(const Point &it) throw(std::bad_alloc) {
  434. alloc();
  435. decaf_448_precompute(ours.mine,it.p);
  436. return *this;
  437. }
  438. /**
  439. * @brief Copy constructor.
  440. */
  441. inline Precomputed(const Precomputed &it) throw(std::bad_alloc) : isMine(false) { *this = it; }
  442. /**
  443. * @brief Constructor which initializes from point.
  444. */
  445. inline explicit Precomputed(const Point &it) throw(std::bad_alloc) : isMine(false) { *this = it; }
  446. #if __cplusplus >= 201103L
  447. inline Precomputed &operator=(Precomputed &&it) NOEXCEPT {
  448. if (this == &it) return *this;
  449. clear();
  450. ours = it.ours;
  451. isMine = it.isMine;
  452. it.isMine = false;
  453. it.ours.yours = decaf_448_precomputed_base;
  454. return *this;
  455. }
  456. inline Precomputed(Precomputed &&it) NOEXCEPT : isMine(false) { *this = it; }
  457. #endif
  458. /** @brief Fixed base scalarmul. */
  459. inline Point operator* (const Scalar &s) const NOEXCEPT { Point r; decaf_448_precomputed_scalarmul(r.p,get(),s.s); return r; }
  460. /** @brief Multiply by s.inverse(). If s=0, maps to the identity. */
  461. inline Point operator/ (const Scalar &s) const NOEXCEPT { return (*this) * s.inverse(); }
  462. /** @brief Return the table for the base point. */
  463. static inline const Precomputed base() NOEXCEPT { return Precomputed(*decaf_448_precomputed_base); }
  464. };
  465. }; /* struct decaf<448> */
  466. #undef NOEXCEPT
  467. #undef EXPLICIT_CON
  468. #undef GET_DATA
  469. } /* namespace decaf */
  470. #endif /* __DECAF_448_HXX__ */