crypto_facade.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. /**
  8. * @brief Checks whether key slot can be used for encryption purposes
  9. * @param key_slot key slot index
  10. * @return \c true if key slot can be used for encryption; \c false otherwise
  11. */
  12. bool totp_crypto_check_key_slot(uint8_t key_slot);
  13. /**
  14. * @brief Encrypts plain data using built-in certificate and given initialization vector (IV)
  15. * @param plain_data plain data to be encrypted
  16. * @param plain_data_length plain data length
  17. * @param crypto_settings crypto settings
  18. * @param[out] encrypted_data_length encrypted data length
  19. * @return Encrypted data
  20. */
  21. uint8_t* totp_crypto_encrypt(
  22. const uint8_t* plain_data,
  23. const size_t plain_data_length,
  24. const CryptoSettings* crypto_settings,
  25. size_t* encrypted_data_length);
  26. /**
  27. * @brief Decrypts encrypted data using built-in certificate and given initialization vector (IV)
  28. * @param encrypted_data encrypted data to be decrypted
  29. * @param encrypted_data_length encrypted data length
  30. * @param crypto_settings crypto settings
  31. * @param[out] decrypted_data_length decrypted data length
  32. * @return Decrypted data
  33. */
  34. uint8_t* totp_crypto_decrypt(
  35. const uint8_t* encrypted_data,
  36. const size_t encrypted_data_length,
  37. const CryptoSettings* crypto_settings,
  38. size_t* decrypted_data_length);
  39. /**
  40. * @brief Seed initialization vector (IV) using user's PIN
  41. * @param crypto_settings crypto settings
  42. * @param pin user's PIN
  43. * @param pin_length user's PIN length
  44. * @return Results of seeding IV
  45. */
  46. CryptoSeedIVResult
  47. totp_crypto_seed_iv(CryptoSettings* crypto_settings, const uint8_t* pin, uint8_t pin_length);
  48. /**
  49. * @brief Verifies whether cryptographic information (certificate + IV) is valid and can be used for encryption and decryption
  50. * @param crypto_settings crypto settings
  51. * @return \c true if cryptographic information is valid; \c false otherwise
  52. */
  53. bool totp_crypto_verify_key(const CryptoSettings* crypto_settings);