rdb.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * replay-database.h
  3. *
  4. * interface for a replay database for packet security
  5. *
  6. * David A. McGrew
  7. * Cisco Systems, Inc.
  8. */
  9. #ifndef REPLAY_DB_H
  10. #define REPLAY_DB_H
  11. #include "integers.h" /* for uint32_t */
  12. #include "datatypes.h" /* for v128_t */
  13. #include "err.h" /* for err_status_t */
  14. /*
  15. * if the ith least significant bit is one, then the packet index
  16. * window_end-i is in the database
  17. */
  18. typedef struct {
  19. uint32_t window_start; /* packet index of the first bit in bitmask */
  20. v128_t bitmask;
  21. } rdb_t;
  22. #define rdb_bits_in_bitmask (8*sizeof(v128_t))
  23. /*
  24. * rdb init
  25. *
  26. * initalizes rdb
  27. *
  28. * returns err_status_ok on success, err_status_t_fail otherwise
  29. */
  30. err_status_t
  31. rdb_init(rdb_t *rdb);
  32. /*
  33. * rdb_check
  34. *
  35. * checks to see if index appears in rdb
  36. *
  37. * returns err_status_fail if the index already appears in rdb,
  38. * returns err_status_ok otherwise
  39. */
  40. err_status_t
  41. rdb_check(const rdb_t *rdb, uint32_t rdb_index);
  42. /*
  43. * rdb_add_index
  44. *
  45. * adds index to rdb_t (and does *not* check if index appears in db)
  46. *
  47. * returns err_status_ok on success, err_status_fail otherwise
  48. *
  49. */
  50. err_status_t
  51. rdb_add_index(rdb_t *rdb, uint32_t rdb_index);
  52. /*
  53. * the functions rdb_increment() and rdb_get_value() are for use by
  54. * senders, not receivers - DO NOT use these functions on the same
  55. * rdb_t upon which rdb_add_index is used!
  56. */
  57. /*
  58. * rdb_increment(db) increments the sequence number in db, if it is
  59. * not too high
  60. *
  61. * return values:
  62. *
  63. * err_status_ok no problem
  64. * err_status_key_expired sequence number too high
  65. *
  66. */
  67. err_status_t
  68. rdb_increment(rdb_t *rdb);
  69. /*
  70. * rdb_get_value(db) returns the current sequence number of db
  71. */
  72. uint32_t
  73. rdb_get_value(const rdb_t *rdb);
  74. #endif /* REPLAY_DB_H */