2022-10-17 18:22:34 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../../types/plugin_state.h"
|
|
|
|
|
2023-04-26 20:50:37 +00:00
|
|
|
typedef uint8_t CryptoSeedIVResult;
|
|
|
|
|
|
|
|
enum CryptoSeedIVResults {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief IV seeding operation failed
|
|
|
|
*/
|
|
|
|
CryptoSeedIVResultFailed = 0b00,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief IV seeding operation succeeded
|
|
|
|
*/
|
|
|
|
CryptoSeedIVResultFlagSuccess = 0b01,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief As a part of IV seeding operation new crypto verify data has been generated
|
|
|
|
*/
|
|
|
|
CryptoSeedIVResultFlagNewCryptoVerifyData = 0b10
|
|
|
|
};
|
|
|
|
|
2022-11-17 19:33:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Encrypts plain data using built-in certificate and given initialization vector (IV)
|
|
|
|
* @param plain_data plain data to be encrypted
|
|
|
|
* @param plain_data_length plain data length
|
|
|
|
* @param iv initialization vector (IV) to be used to encrypt plain data
|
|
|
|
* @param[out] encrypted_data_length encrypted data length
|
|
|
|
* @return Encrypted data
|
|
|
|
*/
|
2022-10-17 18:22:34 +00:00
|
|
|
uint8_t* totp_crypto_encrypt(
|
|
|
|
const uint8_t* plain_data,
|
2022-11-10 05:32:21 +00:00
|
|
|
const size_t plain_data_length,
|
2022-10-17 18:22:34 +00:00
|
|
|
const uint8_t* iv,
|
2022-11-10 05:32:21 +00:00
|
|
|
size_t* encrypted_data_length);
|
2022-11-17 19:33:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Decrypts encrypted data using built-in certificate and given initialization vector (IV)
|
|
|
|
* @param encrypted_data encrypted data to be decrypted
|
|
|
|
* @param encrypted_data_length encrypted data length
|
|
|
|
* @param iv initialization vector (IV) to be used to encrypt plain data
|
|
|
|
* @param[out] decrypted_data_length decrypted data length
|
|
|
|
* @return Decrypted data
|
|
|
|
*/
|
2022-10-17 18:22:34 +00:00
|
|
|
uint8_t* totp_crypto_decrypt(
|
|
|
|
const uint8_t* encrypted_data,
|
2022-11-10 05:32:21 +00:00
|
|
|
const size_t encrypted_data_length,
|
2022-10-17 18:22:34 +00:00
|
|
|
const uint8_t* iv,
|
2022-11-10 05:32:21 +00:00
|
|
|
size_t* decrypted_data_length);
|
2022-11-17 19:33:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Seed initialization vector (IV) using user's PIN
|
|
|
|
* @param plugin_state application state
|
|
|
|
* @param pin user's PIN
|
|
|
|
* @param pin_length user's PIN length
|
2023-04-26 20:50:37 +00:00
|
|
|
* @return Results of seeding IV
|
2022-11-17 19:33:31 +00:00
|
|
|
*/
|
2023-04-26 20:50:37 +00:00
|
|
|
CryptoSeedIVResult
|
|
|
|
totp_crypto_seed_iv(PluginState* plugin_state, const uint8_t* pin, uint8_t pin_length);
|
2022-11-17 19:33:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Verifies whether cryptographic information (certificate + IV) is valid and can be used for encryption and decryption
|
|
|
|
* @param plugin_state application state
|
|
|
|
* @return \c true if cryptographic information is valid; \c false otherwise
|
|
|
|
*/
|
2022-10-17 18:22:34 +00:00
|
|
|
bool totp_crypto_verify_key(const PluginState* plugin_state);
|