field_10x26.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**********************************************************************
  2. * Copyright (c) 2013, 2014 Pieter Wuille *
  3. * Distributed under the MIT software license, see the accompanying *
  4. * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
  5. **********************************************************************/
  6. #ifndef _SECP256K1_FIELD_REPR_
  7. #define _SECP256K1_FIELD_REPR_
  8. #include <stdint.h>
  9. typedef struct {
  10. /* X = sum(i=0..9, elem[i]*2^26) mod n */
  11. uint32_t n[10];
  12. #ifdef VERIFY
  13. int magnitude;
  14. int normalized;
  15. #endif
  16. } secp256k1_fe_t;
  17. /* Unpacks a constant into a overlapping multi-limbed FE element. */
  18. #define SECP256K1_FE_CONST_INNER(d7, d6, d5, d4, d3, d2, d1, d0) { \
  19. (d0) & 0x3FFFFFFUL, \
  20. ((d0) >> 26) | ((d1) & 0xFFFFFUL) << 6, \
  21. ((d1) >> 20) | ((d2) & 0x3FFFUL) << 12, \
  22. ((d2) >> 14) | ((d3) & 0xFFUL) << 18, \
  23. ((d3) >> 8) | ((d4) & 0x3) << 24, \
  24. ((d4) >> 2) & 0x3FFFFFFUL, \
  25. ((d4) >> 28) | ((d5) & 0x3FFFFFUL) << 4, \
  26. ((d5) >> 22) | ((d6) & 0xFFFF) << 10, \
  27. ((d6) >> 16) | ((d7) & 0x3FF) << 16, \
  28. ((d7) >> 10) \
  29. }
  30. #ifdef VERIFY
  31. #define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0)), 1, 1}
  32. #else
  33. #define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0))}
  34. #endif
  35. typedef struct {
  36. uint32_t n[8];
  37. } secp256k1_fe_storage_t;
  38. #define SECP256K1_FE_STORAGE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{ (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }}
  39. #endif