crypto_v1.h 1.9 KB

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