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 29#include <sys/malloc.h> 30#include <opencrypto/cryptodev.h> 31 32INTERFACE cryptodev; 33 34CODE { 35 static int null_freesession(device_t dev, 36 crypto_session_t crypto_session) 37 { 38 return 0; 39 } 40}; 41 42/** 43 * @brief Probe to see if a crypto driver supports a session. 44 * 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 48 * session. 49 * 50 * If the driver does not support a session with the requested 51 * parameters, this function should fail with an error. 52 * 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>. 58 * 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. 62 * 63 * @param dev the crypto driver device 64 * @param csp crypto session parameters 65 * 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 71 */ 72METHOD int probesession { 73 device_t dev; 74 const struct crypto_session_params *csp; 75}; 76 77/** 78 * @brief Initialize a new crypto session object 79 * 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(). 85 * 86 * @param dev the crypto driver device 87 * @param crypto_session session being initialized 88 * @param csp crypto session parameters 89 * 90 * @retval 0 success 91 * @retval non-zero if some kind of error occurred 92 */ 93METHOD int newsession { 94 device_t dev; 95 crypto_session_t crypto_session; 96 const struct crypto_session_params *csp; 97}; 98 99/** 100 * @brief Destroy a crypto session object 101 * 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 108 * this method. 109 * 110 * @param dev the crypto driver device 111 * @param crypto_session session being destroyed 112 */ 113METHOD void freesession { 114 device_t dev; 115 crypto_session_t crypto_session; 116} DEFAULT null_freesession; 117 118/** 119 * @brief Perform a symmetric crypto operation 120 * 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. 125 * 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. 129 * 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. 133 * 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. 139 * 140 * @retval 0 success 141 * @retval ERESTART internal queue is full 142 */ 143METHOD int process { 144 device_t dev; 145 struct cryptop *op; 146 int flags; 147}; 148 149/** 150 * @brief Perform an asymmetric crypto operation 151 * 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 156 * necessary. 157 * 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. 161 * 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. 165 * 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. 171 * 172 * @retval 0 success 173 * @retval ERESTART internal queue is full 174 */ 175METHOD int kprocess { 176 device_t dev; 177 struct cryptkop *op; 178 int flags; 179}; 180