crypto.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #pragma once
  2. #include "../../types/plugin_state.h"
  3. /**
  4. * @brief Encrypts plain data using built-in certificate and given initialization vector (IV)
  5. * @param plain_data plain data to be encrypted
  6. * @param plain_data_length plain data length
  7. * @param iv initialization vector (IV) to be used to encrypt plain data
  8. * @param[out] encrypted_data_length encrypted data length
  9. * @return Encrypted data
  10. */
  11. uint8_t* totp_crypto_encrypt(
  12. const uint8_t* plain_data,
  13. const size_t plain_data_length,
  14. const uint8_t* iv,
  15. size_t* encrypted_data_length);
  16. /**
  17. * @brief Decrypts encrypted data using built-in certificate and given initialization vector (IV)
  18. * @param encrypted_data encrypted data to be decrypted
  19. * @param encrypted_data_length encrypted data length
  20. * @param iv initialization vector (IV) to be used to encrypt plain data
  21. * @param[out] decrypted_data_length decrypted data length
  22. * @return Decrypted data
  23. */
  24. uint8_t* totp_crypto_decrypt(
  25. const uint8_t* encrypted_data,
  26. const size_t encrypted_data_length,
  27. const uint8_t* iv,
  28. size_t* decrypted_data_length);
  29. /**
  30. * @brief Seed initialization vector (IV) using user's PIN
  31. * @param plugin_state application state
  32. * @param pin user's PIN
  33. * @param pin_length user's PIN length
  34. * @return \c true on success; \c false otherwise
  35. */
  36. bool totp_crypto_seed_iv(PluginState* plugin_state, const uint8_t* pin, uint8_t pin_length);
  37. /**
  38. * @brief Verifies whether cryptographic information (certificate + IV) is valid and can be used for encryption and decryption
  39. * @param plugin_state application state
  40. * @return \c true if cryptographic information is valid; \c false otherwise
  41. */
  42. bool totp_crypto_verify_key(const PluginState* plugin_state);