You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

292 lines
8.5 KiB

6 years ago
8 years ago
8 years ago
6 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
7 years ago
7 years ago
6 years ago
8 years ago
8 years ago
7 years ago
8 years ago
  1. /**
  2. * @file cryptotech.h
  3. * @brief cryptotech function typedefs and structures for crypto drivers
  4. * to implement and interface with engine
  5. * @license GNU General Public License 3.0 - see LICENSE.txt
  6. * @todo Various signature mismatches between function pointers def'd here
  7. * and corresponding \@copydoc targets.
  8. */
  9. #ifndef CRYPTOTECH_H
  10. #define CRYPTOTECH_H
  11. #include "pEpEngine.h"
  12. #include "bloblist.h"
  13. /**
  14. * @enum PEP_cryptotech
  15. *
  16. * @brief TODO
  17. *
  18. */
  19. typedef enum _PEP_cryptotech {
  20. PEP_crypt_none = 0,
  21. PEP_crypt_OpenPGP,
  22. // PEP_ctypt_PEP,
  23. // PEP_crypt_SMIME,
  24. // PEP_crypt_CMS,
  25. PEP_crypt__count ///< Represents number of currently supported cryptotech drivers(?)
  26. } PEP_cryptotech;
  27. /**
  28. * @brief Signature for crypto drivers to implement for decrypt_and_verify()
  29. *
  30. * @copydoc decrypt_and_verify()
  31. *
  32. * @see decrypt_and_verify()
  33. */
  34. typedef PEP_STATUS (*decrypt_and_verify_t)(
  35. PEP_SESSION session, const char *ctext, size_t csize,
  36. const char *dsigtext, size_t dsigsize,
  37. char **ptext, size_t *psize, stringlist_t **keylist,
  38. char **filename_ptr
  39. );
  40. /**
  41. * @brief Signature for crypto drivers to implement for verify_text()
  42. * @copydoc verify_text()
  43. * @see verify_text()
  44. */
  45. typedef PEP_STATUS (*verify_text_t)(
  46. PEP_SESSION session, const char *text, size_t size,
  47. const char *signature, size_t sig_size, stringlist_t **keylist
  48. );
  49. /**
  50. * @brief Signature for crypto drivers to implement for encrypt_and_sign()
  51. * @copydoc encrypt_and_sign()
  52. * @see encrypt_and_sign()
  53. */
  54. typedef PEP_STATUS (*encrypt_and_sign_t)(
  55. PEP_SESSION session, const stringlist_t *keylist, const char *ptext,
  56. size_t psize, char **ctext, size_t *csize
  57. );
  58. /**
  59. * @brief Signature for crypto drivers to implement for encrypt_only()
  60. * @copydoc encrypt_only()
  61. * @see encrypt_only()
  62. */
  63. typedef PEP_STATUS (*encrypt_only_t)(
  64. PEP_SESSION session, const stringlist_t *keylist, const char *ptext,
  65. size_t psize, char **ctext, size_t *csize
  66. );
  67. /**
  68. * @brief Signature for crypto drivers to implement for sign_only()
  69. * @copydoc pgp_sign_only()
  70. * @see sign_only - This wrapper function has a mismatched signature
  71. * @see pgp_sign_only() - This is one function that might be pointed to via an pointer of type sign_only_t
  72. */
  73. typedef PEP_STATUS (*sign_only_t)(
  74. PEP_SESSION session, const char* fpr, const char *ptext,
  75. size_t psize, char **stext, size_t *ssize
  76. );
  77. /**
  78. * @brief Signature for crypto drivers to implement for delete_keypair()
  79. * @copydoc delete_keypair()
  80. * @see delete_keypair()
  81. */
  82. typedef PEP_STATUS (*delete_keypair_t)(PEP_SESSION session, const char *fpr);
  83. /**
  84. * @brief Signature for crypto drivers to implement for export_key()
  85. * @copydoc pgp_export_keydata()
  86. * @see export_key() - This wrapper function has a mismatched signature
  87. * @see pgp_export_keydata() - This is one function that might be pointed to via an pointer of type export_key_t
  88. */
  89. typedef PEP_STATUS (*export_key_t)(
  90. PEP_SESSION session, const char *fpr, char **key_data, size_t *size,
  91. bool secret
  92. );
  93. /**
  94. * @brief Signature for crypto drivers to implement for find_keys()
  95. * @copydoc find_keys()
  96. * @see find_keys()
  97. */
  98. typedef PEP_STATUS (*find_keys_t)(
  99. PEP_SESSION session, const char *pattern, stringlist_t **keylist
  100. );
  101. /**
  102. * @brief Signature for crypto drivers to implement for generate_keypair()
  103. * @copydoc generate_keypair()
  104. * @see generate_keypair()
  105. */
  106. typedef PEP_STATUS (*generate_keypair_t)(
  107. PEP_SESSION session, pEp_identity *identity
  108. );
  109. /**
  110. * @brief Signature for crypto drivers to implement for get_key_rating()
  111. * @copydoc get_key_rating()
  112. * @see get_key_rating()
  113. */
  114. typedef PEP_STATUS (*get_key_rating_t)(
  115. PEP_SESSION session,
  116. const char *fpr,
  117. PEP_comm_type *comm_type
  118. );
  119. /**
  120. * @brief Signature for crypto drivers to implement for import_key()
  121. * @copydoc pgp_import_keydata()
  122. * @see import_key() - This wrapper function has a mismatched signature
  123. * @see pgp_import_keydata() - This is one function that might be pointed to via an pointer of type import_key_t
  124. */
  125. typedef PEP_STATUS (*import_key_t)(PEP_SESSION session, const char *key_data,
  126. size_t size, identity_list **private_idents, stringlist_t** imported_keys,
  127. uint64_t* changed_key_index);
  128. /**
  129. * @brief Signature for crypto drivers to implement for recv_key()
  130. * @copydoc recv_key()
  131. * @see recv_key()
  132. */
  133. typedef PEP_STATUS (*recv_key_t)(PEP_SESSION session, const char *pattern);
  134. /**
  135. * @brief Signature for crypto drivers to implement for send_key()
  136. * @copydoc send_key()
  137. * @see send_key()
  138. */
  139. typedef PEP_STATUS (*send_key_t)(PEP_SESSION session, const char *pattern);
  140. /**
  141. * @brief Signature for crypto drivers to implement for renew_key()
  142. * @copydoc renew_key()
  143. * @see renew_key()
  144. */
  145. typedef PEP_STATUS (*renew_key_t)(PEP_SESSION session, const char *fpr,
  146. const timestamp *ts);
  147. /**
  148. * @brief Signature for crypto drivers to implement for revoke_key()
  149. * @copydoc revoke_key()
  150. * @see revoke_key()
  151. */
  152. typedef PEP_STATUS (*revoke_key_t)(PEP_SESSION session, const char *fpr,
  153. const char *reason);
  154. /**
  155. * @brief Signature for crypto drivers to implement for key_expired()
  156. * @copydoc key_expired()
  157. * @see key_expired()
  158. */
  159. typedef PEP_STATUS (*key_expired_t)(PEP_SESSION session, const char *fpr,
  160. const time_t when, bool *expired);
  161. /**
  162. * @brief Signature for crypto drivers to implement for key_revoked()
  163. * @copydoc key_revoked()
  164. * @see key_revoked()
  165. */
  166. typedef PEP_STATUS (*key_revoked_t)(PEP_SESSION session, const char *fpr,
  167. bool *revoked);
  168. /**
  169. * @brief Signature for crypto drivers to implement for key_created()
  170. * @copydoc key_created()
  171. * @see key_created()
  172. */
  173. typedef PEP_STATUS (*key_created_t)(PEP_SESSION session, const char *fpr,
  174. time_t *created);
  175. /**
  176. * @brief Signature for crypto drivers to implement for binary_path()
  177. * @todo where is binary_path() documented?
  178. * <!--@copydoc binary_path()-->
  179. * <!--@see binary_path()-->
  180. */
  181. typedef PEP_STATUS (*binary_path_t)(const char **path);
  182. /**
  183. * @brief Signature for crypto drivers to implement for contains_priv_key()
  184. * @copydoc contains_priv_key()
  185. * @see contains_priv_key()
  186. */
  187. typedef PEP_STATUS (*contains_priv_key_t)(PEP_SESSION session, const char *fpr,
  188. bool *has_private);
  189. /**
  190. * @brief Signature for crypto drivers to implement for find_private_keys()
  191. * @copydoc find_private_keys()
  192. * @see find_private_keys()
  193. */
  194. typedef PEP_STATUS (*find_private_keys_t)(
  195. PEP_SESSION session, const char *pattern, stringlist_t **keylist
  196. );
  197. /**
  198. * @brief Signature for crypto drivers to implement for config_cipher_suite()
  199. * @copydoc config_cipher_suite()
  200. * @see config_cipher_suite()
  201. */
  202. typedef PEP_STATUS (*config_cipher_suite_t)(PEP_SESSION session,
  203. PEP_CIPHER_SUITE suite);
  204. /**
  205. * @struct PEP_cryptotech_t
  206. *
  207. * @brief TODO
  208. *
  209. */
  210. typedef struct _PEP_cryptotech_t {
  211. uint8_t id;
  212. // the following are default values; comm_type may vary with key length or b0rken crypto
  213. uint8_t unconfirmed_comm_type;
  214. uint8_t confirmed_comm_type;
  215. decrypt_and_verify_t decrypt_and_verify;
  216. verify_text_t verify_text;
  217. encrypt_and_sign_t encrypt_and_sign;
  218. encrypt_only_t encrypt_only;
  219. sign_only_t sign_only;
  220. delete_keypair_t delete_keypair;
  221. export_key_t export_key;
  222. find_keys_t find_keys;
  223. generate_keypair_t generate_keypair;
  224. get_key_rating_t get_key_rating;
  225. import_key_t import_key;
  226. recv_key_t recv_key;
  227. send_key_t send_key;
  228. renew_key_t renew_key;
  229. revoke_key_t revoke_key;
  230. key_expired_t key_expired;
  231. key_revoked_t key_revoked;
  232. key_created_t key_created;
  233. binary_path_t binary_path;
  234. contains_priv_key_t contains_priv_key;
  235. find_private_keys_t find_private_keys;
  236. config_cipher_suite_t config_cipher_suite;
  237. } PEP_cryptotech_t;
  238. extern PEP_cryptotech_t cryptotech[PEP_crypt__count]; ///< array of all supported cryptotech drivers/interfaces (?)
  239. typedef uint64_t cryptotech_mask;
  240. /**
  241. * <!-- init_cryptotech() -->
  242. *
  243. * @brief TODO
  244. *
  245. * @param[in] session PEP_SESSION
  246. * @param[in] in_first bool
  247. *
  248. */
  249. PEP_STATUS init_cryptotech(PEP_SESSION session, bool in_first);
  250. /**
  251. * <!-- release_cryptotech() -->
  252. *
  253. * @brief TODO
  254. *
  255. * @param[in] session PEP_SESSION
  256. * @param[in] out_last bool
  257. *
  258. */
  259. void release_cryptotech(PEP_SESSION session, bool out_last);
  260. #endif