taler-xotp_fw

xOTP generator firmware
Log | Files | Refs | Submodules | README

cryptoInterface.h (3835B)


      1 /**
      2  * @file cryptoInterface.h
      3  * @author Adrian STEINER (steia19@bfh.ch)
      4  * @brief Crypto interface to calculate the hash codes with the desired hash
      5  * methods
      6  * @version 0.1
      7  * @date 17-02-2025
      8  *
      9  * @copyright (C) 2025 Adrian STEINER
     10  * This program is free software: you can redistribute it and/or modify
     11  * it under the terms of the GNU General Public License as published by
     12  * the Free Software Foundation, either version 3 of the License, or
     13  * (at your option) any later version.
     14  *
     15  * This program is distributed in the hope that it will be useful,
     16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     18  * GNU General Public License for more details.
     19  *
     20  * You should have received a copy of the GNU General Public License
     21  * along with this program.  If not, see <https: //www.gnu.org/licenses/>.
     22  *
     23  */
     24 #ifndef CRYPTO_INTERFACE_H
     25 #define CRYPTO_INTERFACE_H
     26 
     27 #ifdef __cplusplus
     28 extern "C" {
     29 #endif
     30 
     31 #include <stdint.h>
     32 
     33 #include "talerAmount.h"
     34 #include "xtotpConfig.h"
     35 #include "xtotpCryptoHandler.h"
     36 
     37 /**
     38  * @brief Callback type for computing a TOTP value.
     39  *
     40  * This function computes a Time-based One-Time Password (TOTP) based on the
     41  * given time and algorithm settings.
     42  *
     43  * @param time The current time in seconds since the Unix epoch.
     44  * @param algoSettings Pointer to the algorithm settings used for TOTP
     45  * computation.
     46  * @return uint32_t The computed TOTP value.
     47  */
     48 typedef uint32_t (*cryptoCalcTotpCB)(const uint64_t time,
     49                                      const xtotpAlgoSettingsType *algoSettings);
     50 
     51 /**
     52  * @brief Callback type for computing an extended TOTP (X-TOTP) value.
     53  *
     54  * This function computes an X-TOTP value, which includes additional input such
     55  * as a monetary amount.
     56  *
     57  * @param time The current time in seconds since the Unix epoch.
     58  * @param algoSettings Pointer to the algorithm settings used for X-TOTP
     59  * computation.
     60  * @param amount Pointer to the amount structure used in the computation.
     61  * @return uint32_t The computed X-TOTP value.
     62  */
     63 typedef uint32_t (*cryptoCalcXTotpCB)(const uint64_t time,
     64                                       const xtotpAlgoSettingsType *algoSettings,
     65                                       const TALER_AmountNBO *amount);
     66 
     67 /**
     68  * @brief Structure representing the cryptographic interface for TOTP and X-TOTP
     69  * computation.
     70  */
     71 typedef struct {
     72   cryptoCalcTotpCB computeTotp; ///< Callback for computing a TOTP value. */
     73   cryptoCalcXTotpCB
     74       computeXTotp; ///< Callback for computing an X-TOTP value. */
     75 } cryptoInterface;
     76 
     77 /**
     78  * @brief Initializes the crypto interface with the provided callback functions.
     79  *
     80  * @param interfaceHandler Pointer to the cryptoInterface structure to
     81  * initialize.
     82  * @param computeTotpCB Callback function for TOTP computation.
     83  * @param computeXTotpCB Callback function for X-TOTP computation.
     84  * @return uint8_t Status code (e.g., 0 for success, non-zero for error).
     85  */
     86 uint8_t crypto_initInterface(cryptoInterface *interfaceHandler,
     87                              cryptoCalcTotpCB computeTotpCB,
     88                              cryptoCalcXTotpCB computeXTotpCB);
     89 
     90 /**
     91  * @brief Calculate with the algorithm the passkey with the given time
     92  *
     93  * @param cryptoHandler The crypto handler where the needed information are
     94  * stored
     95  * @param cryptoInterface THe crpyto interface for hardware independent code
     96  * @param currentTime The current time
     97  * @param amount Add amount if needed for xTOTP, use 0 in case of base TOTP
     98  * @return uint32_t the generated OTP passkey
     99  */
    100 uint32_t crypto_calc_OTP(xtotpCryptoHandler *cryptoHandler,
    101                          cryptoInterface *iCrypto,
    102                          uint64_t currentTime,
    103                          uint64_t amount);
    104 
    105 #ifdef __cplusplus
    106 }
    107 #endif
    108 
    109 #endif /* CRYPTO_INTERFACE_H*/