1
0

Key.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #ifndef Key_H
  16. #define Key_H
  17. #include "benc/String.h"
  18. #include "crypto/random/Random.h"
  19. #include "memory/Allocator.h"
  20. #include "util/Linker.h"
  21. Linker_require("crypto/Key.c");
  22. #include <stdint.h>
  23. /**
  24. * Generates a new key such that its derived IP address is in fc00::/8.
  25. */
  26. int Key_gen(uint8_t addressOut[16],
  27. uint8_t publicKeyOut[32],
  28. uint8_t privateKeyOut[32],
  29. struct Random* rand);
  30. char* Key_parse_strerror(int error);
  31. #define Key_parse_TOO_SHORT -1
  32. #define Key_parse_MALFORMED -2
  33. #define Key_parse_DECODE_FAILED -3
  34. /** Invalid cjdns key (doesn't hash to an address beginning with FC) */
  35. #define Key_parse_INVALID -4
  36. /**
  37. * Parse a key.
  38. *
  39. * @param key a public key similar to h9xgk0418x538kg2h5yw4n32rkl4wk4wplkzsmltpg20q78bu7q0.k
  40. * @param keyBytesOut a 32 byte array which will be set to the key.
  41. * @param ip6Out a 16 byte array which will be set to the IPv6 address, if NULL it will be skipped
  42. * and the function will not check if the first byte is FC.
  43. * @return an error code or 0 if no error.
  44. */
  45. int Key_parse(String* key, uint8_t keyBytesOut[32], uint8_t ip6Out[16]);
  46. String* Key_stringify(uint8_t key[32], struct Allocator* alloc);
  47. #endif