crypto.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #include "../../types/plugin_state.h"
  3. typedef uint8_t CryptoSeedIVResult;
  4. enum CryptoSeedIVResults {
  5. /**
  6. * @brief IV seeding operation failed
  7. */
  8. CryptoSeedIVResultFailed = 0b00,
  9. /**
  10. * @brief IV seeding operation succeeded
  11. */
  12. CryptoSeedIVResultFlagSuccess = 0b01,
  13. /**
  14. * @brief As a part of IV seeding operation new crypto verify data has been generated
  15. */
  16. CryptoSeedIVResultFlagNewCryptoVerifyData = 0b10
  17. };
  18. /**
  19. * @brief Encrypts plain data using built-in certificate and given initialization vector (IV)
  20. * @param plain_data plain data to be encrypted
  21. * @param plain_data_length plain data length
  22. * @param iv initialization vector (IV) to be used to encrypt plain data
  23. * @param[out] encrypted_data_length encrypted data length
  24. * @return Encrypted data
  25. */
  26. uint8_t* totp_crypto_encrypt(
  27. const uint8_t* plain_data,
  28. const size_t plain_data_length,
  29. const uint8_t* iv,
  30. size_t* encrypted_data_length);
  31. /**
  32. * @brief Decrypts encrypted data using built-in certificate and given initialization vector (IV)
  33. * @param encrypted_data encrypted data to be decrypted
  34. * @param encrypted_data_length encrypted data length
  35. * @param iv initialization vector (IV) to be used to encrypt plain data
  36. * @param[out] decrypted_data_length decrypted data length
  37. * @return Decrypted data
  38. */
  39. uint8_t* totp_crypto_decrypt(
  40. const uint8_t* encrypted_data,
  41. const size_t encrypted_data_length,
  42. const uint8_t* iv,
  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 pin user's PIN
  48. * @param pin_length user's PIN length
  49. * @return Results of seeding IV
  50. */
  51. CryptoSeedIVResult
  52. totp_crypto_seed_iv(PluginState* plugin_state, const uint8_t* pin, uint8_t pin_length);
  53. /**
  54. * @brief Verifies whether cryptographic information (certificate + IV) is valid and can be used for encryption and decryption
  55. * @param plugin_state application state
  56. * @return \c true if cryptographic information is valid; \c false otherwise
  57. */
  58. bool totp_crypto_verify_key(const PluginState* plugin_state);