xmr.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // Created by Dusan Klinec on 10/05/2018.
  3. //
  4. #if USE_MONERO
  5. #ifndef TREZOR_CRYPTO_XMR_H
  6. #define TREZOR_CRYPTO_XMR_H
  7. #include "../ed25519-donna/ed25519-donna.h"
  8. #include "../hasher.h"
  9. extern const ge25519 ALIGN(16) xmr_h;
  10. typedef unsigned char xmr_key_t[32];
  11. typedef struct xmr_ctkey {
  12. xmr_key_t dest;
  13. xmr_key_t mask;
  14. } xmr_ctkey_t;
  15. /* sets H point to r */
  16. void ge25519_set_xmr_h(ge25519 *r);
  17. /* random scalar value */
  18. void xmr_random_scalar(bignum256modm m);
  19. /* cn_fast_hash */
  20. void xmr_fast_hash(uint8_t *hash, const void *data, size_t length);
  21. /* incremental hashing wrappers */
  22. void xmr_hasher_init(Hasher *hasher);
  23. void xmr_hasher_update(Hasher *hasher, const void *data, size_t length);
  24. void xmr_hasher_final(Hasher *hasher, uint8_t *hash);
  25. void xmr_hasher_copy(Hasher *dst, const Hasher *src);
  26. /* H_s(buffer) */
  27. void xmr_hash_to_scalar(bignum256modm r, const void *data, size_t length);
  28. /* H_p(buffer) */
  29. void xmr_hash_to_ec(ge25519 *P, const void *data, size_t length);
  30. /* derivation to scalar value */
  31. void xmr_derivation_to_scalar(bignum256modm s, const ge25519 *p,
  32. uint32_t output_index);
  33. /* derivation */
  34. void xmr_generate_key_derivation(ge25519 *r, const ge25519 *A,
  35. const bignum256modm b);
  36. /* H_s(derivation || varint(output_index)) + base */
  37. void xmr_derive_private_key(bignum256modm s, const ge25519 *deriv, uint32_t idx,
  38. const bignum256modm base);
  39. /* H_s(derivation || varint(output_index))G + base */
  40. void xmr_derive_public_key(ge25519 *r, const ge25519 *deriv, uint32_t idx,
  41. const ge25519 *base);
  42. /* aG + bB, G is basepoint */
  43. void xmr_add_keys2(ge25519 *r, const bignum256modm a, const bignum256modm b,
  44. const ge25519 *B);
  45. void xmr_add_keys2_vartime(ge25519 *r, const bignum256modm a,
  46. const bignum256modm b, const ge25519 *B);
  47. /* aA + bB */
  48. void xmr_add_keys3(ge25519 *r, const bignum256modm a, const ge25519 *A,
  49. const bignum256modm b, const ge25519 *B);
  50. void xmr_add_keys3_vartime(ge25519 *r, const bignum256modm a, const ge25519 *A,
  51. const bignum256modm b, const ge25519 *B);
  52. /* subaddress secret */
  53. void xmr_get_subaddress_secret_key(bignum256modm r, uint32_t major,
  54. uint32_t minor, const bignum256modm m);
  55. /* Generates Pedersen commitment C = aG + bH */
  56. void xmr_gen_c(ge25519 *r, const bignum256modm a, uint64_t amount);
  57. #endif // TREZOR_CRYPTO_XMR_H
  58. #endif // USE_MONERO