2 # Copyright (c) 2006, Sam Leffler
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
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.
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
29 #include <sys/malloc.h>
30 #include <opencrypto/cryptodev.h>
35 static int null_freesession(device_t dev,
36 crypto_session_t crypto_session)
43 * @brief Probe to see if a crypto driver supports a session.
45 * The crypto framework invokes this method on each crypto driver when
46 * creating a session for symmetric crypto operations to determine if
47 * the driver supports the algorithms and mode requested by the
50 * If the driver does not support a session with the requested
51 * parameters, this function should fail with an error.
53 * If the driver does support a session with the requested parameters,
54 * this function should return a negative value indicating the
55 * priority of this driver. These negative values should be derived
56 * from one of the CRYPTODEV_PROBE_* constants in
57 * <opencrypto/cryptodev.h>.
59 * This function's return value is similar to that used by
60 * DEVICE_PROBE(9). However, a return value of zero is not supported
61 * and should not be used.
63 * @param dev the crypto driver device
64 * @param csp crypto session parameters
66 * @retval negative if the driver supports this session - the
67 * least negative value is used to select the
68 * driver for the session
69 * @retval EINVAL if the driver does not support the session
70 * @retval positive if some other error occurs
72 METHOD int probesession {
74 const struct crypto_session_params *csp;
78 * @brief Initialize a new crypto session object
80 * Invoked by the crypto framework to initialize driver-specific data
81 * for a crypto session. The framework allocates and zeroes the
82 * driver's per-session memory object prior to invoking this method.
83 * The driver is able to access it's per-session memory object via
84 * crypto_get_driver_session().
86 * @param dev the crypto driver device
87 * @param crypto_session session being initialized
88 * @param csp crypto session parameters
91 * @retval non-zero if some kind of error occurred
93 METHOD int newsession {
95 crypto_session_t crypto_session;
96 const struct crypto_session_params *csp;
100 * @brief Destroy a crypto session object
102 * The crypto framework invokes this method when tearing down a crypto
103 * session. After this callback returns, the frame will explicitly
104 * zero and free the drvier's per-session memory object. If the
105 * driver requires additional actions to destroy a session, it should
106 * perform those in this method. If the driver does not require
107 * additional actions it does not need to provide an implementation of
110 * @param dev the crypto driver device
111 * @param crypto_session session being destroyed
113 METHOD void freesession {
115 crypto_session_t crypto_session;
116 } DEFAULT null_freesession;
119 * @brief Perform a symmetric crypto operation
121 * The crypto framework invokes this method for each symmetric crypto
122 * operation performed on a session. A reference to the containing
123 * session is stored as a member of 'struct cryptop'. This routine
124 * should not block, but queue the operation if necessary.
126 * This method may return ERESTART to indicate that any internal
127 * queues are full so the operation should be queued in the crypto
128 * framework and retried in the future.
130 * To report errors with a crypto operation, 'crp_etype' should be set
131 * and the operation completed by calling 'crypto_done'. This method
132 * should then return zero.
134 * @param dev the crypto driver device
135 * @param op crypto operation to perform
136 * @param flags set to CRYPTO_HINT_MORE if additional symmetric
137 * crypto operations are queued for this driver;
138 * otherwise set to zero.
141 * @retval ERESTART internal queue is full
150 * @brief Perform an asymmetric crypto operation
152 * The crypto framework invokes this method for each asymmetric crypto
153 * operation. Each asymmetric crypto operation should be
154 * self-contained and is not assicated with any persistent session.
155 * This routine should not block, but queue the operation if
158 * This method may return ERESTART to indicate that any internal
159 * queues are full so the operation should be queued in the crypto
160 * framework and retried in the future.
162 * To report errors with a crypto operation, 'krp_status' should be set
163 * and the operation completed by calling 'crypto_kdone'. This method
164 * should then return zero.
166 * @param dev the crypto driver device
167 * @param op crypto operation to perform
168 * @param flags set to CRYPTO_HINT_MORE if additional asymmetric
169 * crypto operations are queued for this driver;
170 * otherwise set to zero.
173 * @retval ERESTART internal queue is full
175 METHOD int kprocess {