Specifies the length of the key in bits, for variable-size key algorithms.
Specifies the number of rounds to be used with the algorithm, for variable-round algorithms.
Contains the key to be used with the algorithm.
Contains an explicit initialization vector (IV), if it does not prefix the data. This field is ignored during initialization. If no IV is explicitly passed (see below on details), a random IV is used by the device driver processing the request.
Contains a pointer to another .Vt cryptoini structure. Multiple such structures may be linked to establish multi-algorithm sessions ( ipsec 4 is an example consumer of such a feature).
The .Vt cryptoini structure and its contents will not be modified by the framework (or the drivers used). Subsequent requests for processing that use the SID returned will avoid the cost of re-initializing the hardware (in essence, SID acts as an index in the session cache of the driver).
crypto_freesession is called with the SID returned by crypto_newsession to disestablish the session.
crypto_dispatch is called to process a request. The various fields in the .Vt cryptop structure are:
Contains the SID.
Indicates the total length in bytes of the buffer to be processed.
On return, contains the total length of the result. For symmetric crypto operations, this will be the same as the input length. This will be used if the framework needs to allocate a new buffer for the result (or for re-formatting the input).
This routine is invoked upon completion of the request, whether successful or not. It is invoked through the crypto_done routine. If the request was not successful, an error code is set in the crp_etype field. It is the responsibility of the callback routine to set the appropriate spl(9) level.
Contains the error type, if any errors were encountered, or zero if the request was successfully processed. If the EAGAIN error code is returned, the SID has changed (and has been recorded in the crp_sid field). The consumer should record the new SID and use it in all subsequent requests. In this case, the request may be re-submitted immediately. This mechanism is used by the framework to perform session migration (move a session from one driver to another, because of availability, performance, or other considerations).
Note that this field only makes sense when examined by the callback routine specified in crp_callback. Errors are returned to the invoker of crypto_process only when enough information is not present to call the callback routine (i.e., if the pointer passed is NULL or if no callback routine was specified).
Is a bitmask of flags associated with this request. Currently defined flags are:
The buffer pointed to by crp_buf is an mbuf chain.
Points to the input buffer. On return (when the callback is invoked), it contains the result of the request. The input buffer may be an mbuf chain or a contiguous buffer, depending on crp_flags.
This is passed through the crypto framework untouched and is intended for the invoking applications use.
This is a linked list of descriptors. Each descriptor provides information about what type of cryptographic operation should be done on the input buffer. The various fields are:
The offset in the input buffer where processing should start.
How many bytes, after crd_skip, should be processed.
Offset from the beginning of the buffer to insert any results. For encryption algorithms, this is where the initialization vector (IV) will be inserted when encrypting or where it can be found when decrypting (subject to crd_flags). For MAC algorithms, this is where the result of the keyed hash will be inserted.
The following flags are defined:
For encryption algorithms, this bit is set when encryption is required (when not set, decryption is performed).
For encryption algorithms, this bit is set when the IV already precedes the data, so the crd_inject value will be ignored and no IV will be written in the buffer. Otherwise, the IV used to encrypt the packet will be written at the location pointed to by crd_inject. The IV length is assumed to be equal to the blocksize of the encryption algorithm. Some applications that do special ""IV cooking"", such as the half-IV mode in ipsec(4), can use this flag to indicate that the IV should not be written on the packet. This flag is typically used in conjunction with the CRD_F_IV_EXPLICIT flag.
For encryption algorithms, this bit is set when the IV is explicitly provided by the consumer in the cri_iv fields. Otherwise, for encryption operations the IV is provided for by the driver used to perform the operation, whereas for decryption operations it is pointed to by the crd_inject field. This flag is typically used when the IV is calculated ""on the fly"" by the consumer, and does not precede the data (some ipsec(4) configurations, and the encrypted swap are two such examples).
For compression algorithms, this bit is set when compression is required (when not set, decompression is performed).
This .Vt cryptoini structure will not be modified by the framework or the device drivers. Since this information accompanies every cryptographic operation request, drivers may re-initialize state on-demand (typically an expensive operation). Furthermore, the cryptographic framework may re-route requests as a result of full queues or hardware failure, as described above.
Point to the next descriptor. Linked operations are useful in protocols such as ipsec(4), where multiple cryptographic transforms may be applied on the same block of data.
crypto_getreq allocates a .Vt cryptop structure with a linked list of as many .Vt cryptodesc structures as were specified in the argument passed to it.
crypto_freereq deallocates a structure .Vt cryptop and any .Vt cryptodesc structures linked to it. Note that it is the responsibility of the callback routine to do the necessary cleanups associated with the opaque field in the .Vt cryptop structure.
crypto_kdispatch is called to perform a keying operation. The various fields in the .Vt cryptkop structure are:
Operation code, such as CRK_MOD_EXP.
Return code. This errno -style variable indicates whether lower level reasons for operation failure.
Number if input parameters to the specified operation. Note that each operation has a (typically hardwired) number of such parameters.
Number if output parameters from the specified operation. Note that each operation has a (typically hardwired) number of such parameters.
An array of kernel memory blocks containing the parameters.
Identifier specifying which low-level driver is being used.
Callback called on completion of a keying operation.
int lp]*newsessionrp] "void *" "u_int32_t *" "struct cryptoini *";
int lp]*freesessionrp] "void *" "u_int64_t";
int lp]*processrp] "void *" "struct cryptop *";
int lp]*kprocessrp] "void *" "struct cryptkop *";
On invocation, the first argument to all routines is an opaque data value supplied when the algorithm is registered with crypto_register. The second argument to newsession contains the driver identifier obtained via crypto_get_driverid. On successful return, it should contain a driver-specific session identifier. The third argument is identical to that of crypto_newsession.
The freesession routine takes as arguments the opaque data value and the SID (which is the concatenation of the driver identifier and the driver-specific session identifier). It should clear any context associated with the session (clear hardware registers, memory, etc.).
The process routine is invoked with a request to perform crypto processing. This routine must not block, but should queue the request and return immediately. Upon processing the request, the callback routine should be invoked. In case of an unrecoverable error, the error indication must be placed in the crp_etype field of the .Vt cryptop structure. When the request is completed, or an error is detected, the process routine should invoke crypto_done. Session migration may be performed, as mentioned previously.
In case of a temporary resource exhaustion, the process routine may return ERESTART in which case the crypto services will requeue the request, mark the driver as "blocked", and stop submitting requests for processing. The driver is then responsible for notifying the crypto services when it is again able to process requests through the crypto_unblock routine. This simple flow control mechanism should only be used for short-lived resource exhaustion as it causes operations to be queued in the crypto layer. Doing so is preferable to returning an error in such cases as it can cause network protocols to degrade performance by treating the failure much like a lost packet.
The kprocess routine is invoked with a request to perform crypto key processing. This routine must not block, but should queue the request and return immediately. Upon processing the request, the callback routine should be invoked. In case of an unrecoverable error, the error indication must be placed in the krp_status field of the .Vt cryptkop structure. When the request is completed, or an error is detected, the kprocess routine should invoked crypto_kdone.