cryptodev_if.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #-
  2. # Copyright (c) 2006, Sam Leffler
  3. # All rights reserved.
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions
  7. # are met:
  8. # 1. Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. # 2. Redistributions in binary form must reproduce the above copyright
  11. # notice, this list of conditions and the following disclaimer in the
  12. # documentation and/or other materials provided with the distribution.
  13. #
  14. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  15. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  18. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  20. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  21. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  22. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  23. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  24. # SUCH DAMAGE.
  25. #
  26. # $FreeBSD$
  27. #
  28. #include <sys/malloc.h>
  29. #include <opencrypto/cryptodev.h>
  30. INTERFACE cryptodev;
  31. CODE {
  32. static int null_freesession(device_t dev,
  33. crypto_session_t crypto_session)
  34. {
  35. return 0;
  36. }
  37. };
  38. /**
  39. * @brief Probe to see if a crypto driver supports a session.
  40. *
  41. * The crypto framework invokes this method on each crypto driver when
  42. * creating a session for symmetric crypto operations to determine if
  43. * the driver supports the algorithms and mode requested by the
  44. * session.
  45. *
  46. * If the driver does not support a session with the requested
  47. * parameters, this function should fail with an error.
  48. *
  49. * If the driver does support a session with the requested parameters,
  50. * this function should return a negative value indicating the
  51. * priority of this driver. These negative values should be derived
  52. * from one of the CRYPTODEV_PROBE_* constants in
  53. * <opencrypto/cryptodev.h>.
  54. *
  55. * This function's return value is similar to that used by
  56. * DEVICE_PROBE(9). However, a return value of zero is not supported
  57. * and should not be used.
  58. *
  59. * @param dev the crypto driver device
  60. * @param csp crypto session parameters
  61. *
  62. * @retval negative if the driver supports this session - the
  63. * least negative value is used to select the
  64. * driver for the session
  65. * @retval EINVAL if the driver does not support the session
  66. * @retval positive if some other error occurs
  67. */
  68. METHOD int probesession {
  69. device_t dev;
  70. const struct crypto_session_params *csp;
  71. };
  72. /**
  73. * @brief Initialize a new crypto session object
  74. *
  75. * Invoked by the crypto framework to initialize driver-specific data
  76. * for a crypto session. The framework allocates and zeroes the
  77. * driver's per-session memory object prior to invoking this method.
  78. * The driver is able to access it's per-session memory object via
  79. * crypto_get_driver_session().
  80. *
  81. * @param dev the crypto driver device
  82. * @param crypto_session session being initialized
  83. * @param csp crypto session parameters
  84. *
  85. * @retval 0 success
  86. * @retval non-zero if some kind of error occurred
  87. */
  88. METHOD int newsession {
  89. device_t dev;
  90. crypto_session_t crypto_session;
  91. const struct crypto_session_params *csp;
  92. };
  93. /**
  94. * @brief Destroy a crypto session object
  95. *
  96. * The crypto framework invokes this method when tearing down a crypto
  97. * session. After this callback returns, the frame will explicitly
  98. * zero and free the drvier's per-session memory object. If the
  99. * driver requires additional actions to destroy a session, it should
  100. * perform those in this method. If the driver does not require
  101. * additional actions it does not need to provide an implementation of
  102. * this method.
  103. *
  104. * @param dev the crypto driver device
  105. * @param crypto_session session being destroyed
  106. */
  107. METHOD void freesession {
  108. device_t dev;
  109. crypto_session_t crypto_session;
  110. } DEFAULT null_freesession;
  111. /**
  112. * @brief Perform a symmetric crypto operation
  113. *
  114. * The crypto framework invokes this method for each symmetric crypto
  115. * operation performed on a session. A reference to the containing
  116. * session is stored as a member of 'struct cryptop'. This routine
  117. * should not block, but queue the operation if necessary.
  118. *
  119. * This method may return ERESTART to indicate that any internal
  120. * queues are full so the operation should be queued in the crypto
  121. * framework and retried in the future.
  122. *
  123. * To report errors with a crypto operation, 'crp_etype' should be set
  124. * and the operation completed by calling 'crypto_done'. This method
  125. * should then return zero.
  126. *
  127. * @param dev the crypto driver device
  128. * @param op crypto operation to perform
  129. * @param flags set to CRYPTO_HINT_MORE if additional symmetric
  130. * crypto operations are queued for this driver;
  131. * otherwise set to zero.
  132. *
  133. * @retval 0 success
  134. * @retval ERESTART internal queue is full
  135. */
  136. METHOD int process {
  137. device_t dev;
  138. struct cryptop *op;
  139. int flags;
  140. };
  141. /**
  142. * @brief Perform an asymmetric crypto operation
  143. *
  144. * The crypto framework invokes this method for each asymmetric crypto
  145. * operation. Each asymmetric crypto operation should be
  146. * self-contained and is not assicated with any persistent session.
  147. * This routine should not block, but queue the operation if
  148. * necessary.
  149. *
  150. * This method may return ERESTART to indicate that any internal
  151. * queues are full so the operation should be queued in the crypto
  152. * framework and retried in the future.
  153. *
  154. * To report errors with a crypto operation, 'krp_status' should be set
  155. * and the operation completed by calling 'crypto_kdone'. This method
  156. * should then return zero.
  157. *
  158. * @param dev the crypto driver device
  159. * @param op crypto operation to perform
  160. * @param flags set to CRYPTO_HINT_MORE if additional asymmetric
  161. * crypto operations are queued for this driver;
  162. * otherwise set to zero.
  163. *
  164. * @retval 0 success
  165. * @retval ERESTART internal queue is full
  166. */
  167. METHOD int kprocess {
  168. device_t dev;
  169. struct cryptkop *op;
  170. int flags;
  171. };