crypto_facade.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #pragma once
  2. #include "../../types/plugin_state.h"
  3. #include "common_types.h"
  4. /**
  5. * @brief Checks whether key slot can be used for encryption purposes
  6. * @param key_slot key slot index
  7. * @return \c true if key slot can be used for encryption; \c false otherwise
  8. */
  9. bool totp_crypto_check_key_slot(uint8_t key_slot);
  10. /**
  11. * @brief Encrypts plain data using built-in certificate and given initialization vector (IV)
  12. * @param plain_data plain data to be encrypted
  13. * @param plain_data_length plain data length
  14. * @param iv initialization vector (IV) to be used to encrypt plain data
  15. * @param crypto_version version of crypto algorithms to use
  16. * @param key_slot key slot to be used
  17. * @param[out] encrypted_data_length encrypted data length
  18. * @return Encrypted data
  19. */
  20. uint8_t* totp_crypto_encrypt(
  21. const uint8_t* plain_data,
  22. const size_t plain_data_length,
  23. const uint8_t* iv,
  24. uint8_t crypto_version,
  25. uint8_t key_slot,
  26. size_t* encrypted_data_length);
  27. /**
  28. * @brief Decrypts encrypted data using built-in certificate and given initialization vector (IV)
  29. * @param encrypted_data encrypted data to be decrypted
  30. * @param encrypted_data_length encrypted data length
  31. * @param iv initialization vector (IV) to be used to encrypt plain data
  32. * @param crypto_version version of crypto algorithms to use
  33. * @param key_slot key slot to be used
  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 uint8_t* iv,
  41. uint8_t crypto_version,
  42. uint8_t key_slot,
  43. size_t* decrypted_data_length);
  44. /**
  45. * @brief Seed initialization vector (IV) using user's PIN
  46. * @param plugin_state application state
  47. * @param key_slot key slot to be used
  48. * @param pin user's PIN
  49. * @param pin_length user's PIN length
  50. * @return Results of seeding IV
  51. */
  52. CryptoSeedIVResult
  53. totp_crypto_seed_iv(PluginState* plugin_state, const uint8_t* pin, uint8_t pin_length);
  54. /**
  55. * @brief Verifies whether cryptographic information (certificate + IV) is valid and can be used for encryption and decryption
  56. * @param plugin_state application state
  57. * @return \c true if cryptographic information is valid; \c false otherwise
  58. */
  59. bool totp_crypto_verify_key(const PluginState* plugin_state);