crypto_facade.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <stddef.h>
  5. #include "../../types/crypto_settings.h"
  6. #include "common_types.h"
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. /**
  11. * @brief Checks whether key slot can be used for encryption purposes
  12. * @param key_slot key slot index
  13. * @return \c true if key slot can be used for encryption; \c false otherwise
  14. */
  15. bool totp_crypto_check_key_slot(uint8_t key_slot);
  16. /**
  17. * @brief Encrypts plain data using built-in certificate and given initialization vector (IV)
  18. * @param plain_data plain data to be encrypted
  19. * @param plain_data_length plain data length
  20. * @param crypto_settings crypto settings
  21. * @param[out] encrypted_data_length encrypted data length
  22. * @return Encrypted data
  23. */
  24. uint8_t* totp_crypto_encrypt(
  25. const uint8_t* plain_data,
  26. const size_t plain_data_length,
  27. const CryptoSettings* crypto_settings,
  28. size_t* encrypted_data_length);
  29. /**
  30. * @brief Decrypts encrypted data using built-in certificate and given initialization vector (IV)
  31. * @param encrypted_data encrypted data to be decrypted
  32. * @param encrypted_data_length encrypted data length
  33. * @param crypto_settings crypto settings
  34. * @param[out] decrypted_data_length decrypted data length
  35. * @return Decrypted data
  36. */
  37. uint8_t* totp_crypto_decrypt(
  38. const uint8_t* encrypted_data,
  39. const size_t encrypted_data_length,
  40. const CryptoSettings* crypto_settings,
  41. size_t* decrypted_data_length);
  42. /**
  43. * @brief Seed initialization vector (IV) using user's PIN
  44. * @param crypto_settings crypto settings
  45. * @param pin user's PIN
  46. * @param pin_length user's PIN length
  47. * @return Results of seeding IV
  48. */
  49. CryptoSeedIVResult
  50. totp_crypto_seed_iv(CryptoSettings* crypto_settings, const uint8_t* pin, uint8_t pin_length);
  51. /**
  52. * @brief Verifies whether cryptographic information (certificate + IV) is valid and can be used for encryption and decryption
  53. * @param crypto_settings crypto settings
  54. * @return \c true if cryptographic information is valid; \c false otherwise
  55. */
  56. bool totp_crypto_verify_key(const CryptoSettings* crypto_settings);
  57. #ifdef __cplusplus
  58. }
  59. #endif