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