bip39.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * Copyright (c) 2013-2014 Tomas Dzetkulic
  3. * Copyright (c) 2013-2014 Pavol Rusnak
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included
  13. * in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  16. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
  19. * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #ifndef __BIP39_H__
  24. #define __BIP39_H__
  25. #include <stdbool.h>
  26. #include <stdint.h>
  27. #include "options.h"
  28. #define BIP39_WORD_COUNT 2048
  29. #define BIP39_PBKDF2_ROUNDS 2048
  30. #if USE_BIP39_CACHE
  31. void bip39_cache_clear(void);
  32. #endif
  33. extern const char *const BIP39_WORDLIST_ENGLISH[BIP39_WORD_COUNT];
  34. const char *mnemonic_generate(int strength); // strength in bits
  35. const char *mnemonic_from_data(const uint8_t *data, int len);
  36. void mnemonic_clear(void);
  37. int mnemonic_check(const char *mnemonic);
  38. int mnemonic_to_bits(const char *mnemonic, uint8_t *bits);
  39. // passphrase must be at most 256 characters otherwise it would be truncated
  40. void mnemonic_to_seed(const char *mnemonic, const char *passphrase,
  41. uint8_t seed[512 / 8],
  42. void (*progress_callback)(uint32_t current,
  43. uint32_t total));
  44. int mnemonic_find_word(const char *word);
  45. const char *mnemonic_complete_word(const char *prefix, int len);
  46. const char *mnemonic_get_word(int index);
  47. uint32_t mnemonic_word_completion_mask(const char *prefix, int len);
  48. #endif