decrypt.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. babeld-lor
  3. Copyright (C) 2017 Rodrigo Garcia
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  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. #define LORAUTH_TOKENS_DIR "tokens"
  16. #define LORAUTH_TOKENS_FILE "ciphered-tokens.ctxt"
  17. #if !defined(MBEDTLS_CONFIG_FILE)
  18. #include "mbedtls/config.h"
  19. #else
  20. #include MBEDTLS_CONFIG_FILE
  21. #endif
  22. #if defined(MBEDTLS_PLATFORM_C)
  23. #include "mbedtls/platform.h"
  24. #else
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #define mbedtls_printf printf
  28. #define mbedtls_exit exit
  29. #define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
  30. #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
  31. #endif
  32. #if defined(MBEDTLS_BIGNUM_C) && defined(MBEDTLS_RSA_C) && \
  33. defined(MBEDTLS_FS_IO) && defined(MBEDTLS_ENTROPY_C) && \
  34. defined(MBEDTLS_CTR_DRBG_C)
  35. #include "mbedtls/rsa.h"
  36. #include "mbedtls/entropy.h"
  37. #include "mbedtls/ctr_drbg.h"
  38. #include <string.h>
  39. #endif
  40. #if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_RSA_C) || \
  41. !defined(MBEDTLS_FS_IO) || !defined(MBEDTLS_ENTROPY_C) || \
  42. !defined(MBEDTLS_CTR_DRBG_C)
  43. #error "MBEDTLS_BIGNUM_C and/or MBEDTLS_RSA_C and/or MBEDTLS_FS_IO and/or MBEDTLS_ENTROPY_C and/or MBEDTLS_CTR_DRBG_C not defined."
  44. #else
  45. extern mbedtls_rsa_context rsa_context;
  46. extern mbedtls_entropy_context rsa_entropy;
  47. extern mbedtls_ctr_drbg_context rsa_ctr_drbg;
  48. unsigned char rsa_result[1024];
  49. unsigned char rsa_buff[513];
  50. int rsa_module_init(char public_key_file[],
  51. mbedtls_rsa_context *rsa_context,
  52. mbedtls_entropy_context *rsa_entropy,
  53. mbedtls_ctr_drbg_context *rsa_ctr_drbg);
  54. int rsa_decrypt(mbedtls_rsa_context *rsa_context,
  55. mbedtls_entropy_context *rsa_entropy,
  56. mbedtls_ctr_drbg_context *rsa_ctr_drbg,
  57. char *encrypted_message,
  58. unsigned char *rsa_result);
  59. #endif