OTPChecker.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**
  2. * @file OTPChecker.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * @section DESCRIPTION
  23. *
  24. * Object that checks OTPs agains known seeds.
  25. */
  26. #ifndef BADVPN_SECURITY_OTPCHECKER_H
  27. #define BADVPN_SECURITY_OTPCHECKER_H
  28. #include <stdint.h>
  29. #include <misc/balign.h>
  30. #include <misc/debug.h>
  31. #include <misc/modadd.h>
  32. #include <security/OTPCalculator.h>
  33. #include <system/DebugObject.h>
  34. struct OTPChecker_entry {
  35. otp_t otp;
  36. int avail;
  37. };
  38. #include <generated/bstruct_OTPChecker.h>
  39. /**
  40. * Object that checks OTPs agains known seeds.
  41. */
  42. typedef struct {
  43. DebugObject d_obj;
  44. int num_otps;
  45. int num_entries;
  46. int num_tables;
  47. int tables_used;
  48. int next_table;
  49. OTPCalculator calc;
  50. oc_tablesParams tables_params;
  51. oc_tables *tables;
  52. } OTPChecker;
  53. /**
  54. * Initializes the checker.
  55. *
  56. * @param mc the object
  57. * @param num_otps number of OTPs to generate from a seed. Must be >0.
  58. * @param cipher encryption cipher for calculating the OTPs. Must be valid
  59. * according to {@link BEncryption_cipher_valid}.
  60. * @param num_tables number of tables to keep, each for one seed. Must be >0.
  61. * @return 1 on success, 0 on failure
  62. */
  63. int OTPChecker_Init (OTPChecker *mc, int num_otps, int cipher, int num_tables) WARN_UNUSED;
  64. /**
  65. * Frees the checker.
  66. *
  67. * @param mc the object
  68. */
  69. void OTPChecker_Free (OTPChecker *mc);
  70. /**
  71. * Adds a seed whose OTPs should be recognized.
  72. *
  73. * @param mc the object
  74. * @param seed_id seed identifier
  75. * @param key encryption key
  76. * @param iv initialization vector
  77. */
  78. void OTPChecker_AddSeed (OTPChecker *mc, uint16_t seed_id, uint8_t *key, uint8_t *iv);
  79. /**
  80. * Removes all active seeds.
  81. *
  82. * @param mc the object
  83. */
  84. void OTPChecker_RemoveSeeds (OTPChecker *mc);
  85. /**
  86. * Checks an OTP.
  87. *
  88. * @param mc the object
  89. * @param seed_id identifer of seed whom the OTP is claimed to belong to
  90. * @param otp OTP to check
  91. * @return 1 if the OTP is valid, 0 if not
  92. */
  93. int OTPChecker_CheckOTP (OTPChecker *mc, uint16_t seed_id, otp_t otp);
  94. #endif