1f4bf4335SSam Leffler.\" $OpenBSD: crypto.9,v 1.19 2002/07/16 06:31:57 angelos Exp $ 2f4bf4335SSam Leffler.\" 3571dba6eSHiten Pandya.\" The author of this manual page is Angelos D. Keromytis (angelos@cis.upenn.edu) 4f4bf4335SSam Leffler.\" 5f4bf4335SSam Leffler.\" Copyright (c) 2000, 2001 Angelos D. Keromytis 6f4bf4335SSam Leffler.\" 7f4bf4335SSam Leffler.\" Permission to use, copy, and modify this software with or without fee 8f4bf4335SSam Leffler.\" is hereby granted, provided that this entire notice is included in 9f4bf4335SSam Leffler.\" all source code copies of any software which is or includes a copy or 10f4bf4335SSam Leffler.\" modification of this software. 11f4bf4335SSam Leffler.\" 12f4bf4335SSam Leffler.\" THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR 13f4bf4335SSam Leffler.\" IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY 14f4bf4335SSam Leffler.\" REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE 15f4bf4335SSam Leffler.\" MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR 16f4bf4335SSam Leffler.\" PURPOSE. 17f4bf4335SSam Leffler.\" 187621fdabSRuslan Ermilov.\" $FreeBSD$ 197621fdabSRuslan Ermilov.\" 20*c0341432SJohn Baldwin.Dd March 27, 2020 21f4bf4335SSam Leffler.Dt CRYPTO 9 22f4bf4335SSam Leffler.Os 23f4bf4335SSam Leffler.Sh NAME 24f4bf4335SSam Leffler.Nm crypto 25f4bf4335SSam Leffler.Nd API for cryptographic services in the kernel 26f4bf4335SSam Leffler.Sh SYNOPSIS 277621fdabSRuslan Ermilov.In opencrypto/cryptodev.h 28f4bf4335SSam Leffler.Sh DESCRIPTION 29f4bf4335SSam Leffler.Nm 30*c0341432SJohn Baldwinis a framework for in-kernel cryptography. 31*c0341432SJohn BaldwinIt permits in-kernel consumers to encrypt and decrypt data 32*c0341432SJohn Baldwinand also enables userland applications to use cryptographic hardware 33*c0341432SJohn Baldwinthrough the 341403a8c7SSam Leffler.Pa /dev/crypto 35*c0341432SJohn Baldwindevice. 36f4bf4335SSam Leffler.Pp 37*c0341432SJohn Baldwin.Nm 38*c0341432SJohn Baldwinsupports two modes of operation: 39*c0341432SJohn Baldwinone mode for symmetric-keyed cryptographic requests and digest, 40*c0341432SJohn Baldwinand a second mode for asymmetric-key requests and modular arithmetic. 41*c0341432SJohn Baldwin.Ss Symmetric-Key Mode 42*c0341432SJohn BaldwinSymmetric-key operations include encryption and decryption operations 43*c0341432SJohn Baldwinusing block and stream ciphers as well as computation and verification 44*c0341432SJohn Baldwinof message authentication codes (MACs). 45*c0341432SJohn BaldwinIn this mode, 46*c0341432SJohn Baldwinconsumers allocate sessions to describe a transform as discussed in 47*c0341432SJohn Baldwin.Xr crypto_session 9 . 48*c0341432SJohn BaldwinConsumers then allocate request objects to describe each transformation 49*c0341432SJohn Baldwinsuch as encrypting a network packet or decrypting a disk sector. 50*c0341432SJohn BaldwinRequests are described in 51*c0341432SJohn Baldwin.Xr crypto_request 9 . 52f4bf4335SSam Leffler.Pp 53*c0341432SJohn BaldwinDevice drivers are responsible for processing requests submitted by 54*c0341432SJohn Baldwinconsumers. 55*c0341432SJohn Baldwin.Xr crypto_driver 9 56*c0341432SJohn Baldwindescribes the interfaces drivers use to register with the framework, 57*c0341432SJohn Baldwinhelper routines the framework provides to faciliate request processing, 58*c0341432SJohn Baldwinand the interfaces drivers are required to provide. 59*c0341432SJohn Baldwin.Ss Asymmetric-Key Mode 60*c0341432SJohn BaldwinAssymteric-key operations do not use sessions. 61*c0341432SJohn BaldwinInstead, 62*c0341432SJohn Baldwinthese operations perform individual mathematical operations using a set 63*c0341432SJohn Baldwinof input and output parameters. 64*c0341432SJohn BaldwinThese operations are described in 65*c0341432SJohn Baldwin.Xr crypto_asym 9 . 66*c0341432SJohn BaldwinDrivers that support asymmetric operations use additional interfaces 67*c0341432SJohn Baldwindescribed in 68*c0341432SJohn Baldwin.Xr crypto_asym 9 69*c0341432SJohn Baldwinin addition to the base interfaces described in 70*c0341432SJohn Baldwin.Xr crypto_driver 9 . 71*c0341432SJohn Baldwin.Ss Callbacks 72f4bf4335SSam LefflerSince the consumers may not be associated with a process, drivers may 731403a8c7SSam Lefflernot 741403a8c7SSam Leffler.Xr sleep 9 . 75f4bf4335SSam LefflerThe same holds for the framework. 76f4bf4335SSam LefflerThus, a callback mechanism is used 77f4bf4335SSam Lefflerto notify a consumer that a request has been completed (the 780f7e2491SChristian Brueffercallback is specified by the consumer on a per-request basis). 79f4bf4335SSam LefflerThe callback is invoked by the framework whether the request was 80f4bf4335SSam Lefflersuccessfully completed or not. 81*c0341432SJohn BaldwinErrors are reported to the callback function. 82*c0341432SJohn Baldwin.Pp 83*c0341432SJohn BaldwinSession initialization does not use callbacks and returns errors 84*c0341432SJohn Baldwinsynchronously. 85*c0341432SJohn Baldwin.Ss Session Migration 86*c0341432SJohn BaldwinFor symmetric-key operations, 87*c0341432SJohn Baldwina specific error code, 88f4bf4335SSam Leffler.Er EAGAIN , 891b0909d5SConrad Meyeris used to indicate that a session handle has changed and that the 901b0909d5SConrad Meyerrequest may be re-submitted immediately with the new session. 91*c0341432SJohn BaldwinThe consumer should update its saved copy of the session handle 92*c0341432SJohn Baldwinto the value of 93*c0341432SJohn Baldwin.Fa crp_session 94*c0341432SJohn Baldwinso that future requests use the new session. 95*c0341432SJohn Baldwin.Ss Supported Algorithms 96*c0341432SJohn BaldwinMore details on some algorithms may be found in 97*c0341432SJohn Baldwin.Xr crypto 7 . 98*c0341432SJohn BaldwinThese algorithms are used for symmetric-mode operations. 99*c0341432SJohn BaldwinAsymmetric-mode operations support operations described in 100*c0341432SJohn Baldwin.Xr crypto_asym 9 . 101f4bf4335SSam Leffler.Pp 102*c0341432SJohn BaldwinThe following authentication algorithms are supported: 103f405d8ebSJohn-Mark Gurney.Pp 104*c0341432SJohn Baldwin.Bl -tag -offset indent -width CRYPTO_AES_CCM_CBC_MAC -compact 105284789e8SJohn Baldwin.It Dv CRYPTO_AES_CCM_CBC_MAC 10608fca7a5SJohn-Mark Gurney.It Dv CRYPTO_AES_NIST_GMAC 107284789e8SJohn Baldwin.It Dv CRYPTO_BLAKE2B 108284789e8SJohn Baldwin.It Dv CRYPTO_BLAKE2S 1097621fdabSRuslan Ermilov.It Dv CRYPTO_MD5 110b61e8b3eSChristian Brueffer.It Dv CRYPTO_MD5_HMAC 111b61e8b3eSChristian Brueffer.It Dv CRYPTO_MD5_KPDK 11208fca7a5SJohn-Mark Gurney.It Dv CRYPTO_NULL_HMAC 113284789e8SJohn Baldwin.It Dv CRYPTO_POLY1305 114284789e8SJohn Baldwin.It Dv CRYPTO_RIPEMD160 115b61e8b3eSChristian Brueffer.It Dv CRYPTO_RIPEMD160_HMAC 1167621fdabSRuslan Ermilov.It Dv CRYPTO_SHA1 117b61e8b3eSChristian Brueffer.It Dv CRYPTO_SHA1_HMAC 118b61e8b3eSChristian Brueffer.It Dv CRYPTO_SHA1_KPDK 119284789e8SJohn Baldwin.It Dv CRYPTO_SHA2_224 120284789e8SJohn Baldwin.It Dv CRYPTO_SHA2_224_HMAC 121284789e8SJohn Baldwin.It Dv CRYPTO_SHA2_256 12271ee05c8SPawel Jakub Dawidek.It Dv CRYPTO_SHA2_256_HMAC 123284789e8SJohn Baldwin.It Dv CRYPTO_SHA2_384 12471ee05c8SPawel Jakub Dawidek.It Dv CRYPTO_SHA2_384_HMAC 125284789e8SJohn Baldwin.It Dv CRYPTO_SHA2_512 12671ee05c8SPawel Jakub Dawidek.It Dv CRYPTO_SHA2_512_HMAC 127*c0341432SJohn Baldwin.El 128*c0341432SJohn Baldwin.Pp 129*c0341432SJohn BaldwinThe following encryption algorithms are supported: 130*c0341432SJohn Baldwin.Pp 131*c0341432SJohn Baldwin.Bl -tag -offset indent -width CRYPTO_CAMELLIA_CBC -compact 132*c0341432SJohn Baldwin.It Dv CRYPTO_AES_CBC 133*c0341432SJohn Baldwin.It Dv CRYPTO_AES_ICM 134*c0341432SJohn Baldwin.It Dv CRYPTO_AES_XTS 135*c0341432SJohn Baldwin.It Dv CRYPTO_ARC4 136*c0341432SJohn Baldwin.It Dv CRYPTO_BLF_CBC 137*c0341432SJohn Baldwin.It Dv CRYPTO_CAMELLIA_CBC 138*c0341432SJohn Baldwin.It Dv CRYPTO_CAST_CBC 139*c0341432SJohn Baldwin.It Dv CRYPTO_CHACHA20 140*c0341432SJohn Baldwin.It Dv CRYPTO_DES_CBC 141*c0341432SJohn Baldwin.It Dv CRYPTO_3DES_CBC 142*c0341432SJohn Baldwin.It Dv CRYPTO_NULL_CBC 14308fca7a5SJohn-Mark Gurney.It Dv CRYPTO_SKIPJACK_CBC 1447621fdabSRuslan Ermilov.El 145*c0341432SJohn Baldwin.Pp 146*c0341432SJohn BaldwinThe following authenticated encryption with additional data (AEAD) 147*c0341432SJohn Baldwinalgorithms are supported: 148*c0341432SJohn Baldwin.Pp 149*c0341432SJohn Baldwin.Bl -tag -offset indent -width CRYPTO_AES_NIST_GCM_16 -compact 150*c0341432SJohn Baldwin.It Dv CRYPTO_AES_CCM_16 151*c0341432SJohn Baldwin.It Dv CRYPTO_AES_NIST_GCM_16 152f4bf4335SSam Leffler.El 153f4bf4335SSam Leffler.Pp 154*c0341432SJohn BaldwinThe following compression algorithms are supported: 155f4bf4335SSam Leffler.Pp 156*c0341432SJohn Baldwin.Bl -tag -offset indent -width CRYPTO_DEFLATE_COMP -compact 157*c0341432SJohn Baldwin.It Dv CRYPTO_DEFLATE_COMP 158f4bf4335SSam Leffler.El 159f4bf4335SSam Leffler.Sh FILES 160627e7962SSam Leffler.Bl -tag -width ".Pa sys/opencrypto/crypto.c" 161627e7962SSam Leffler.It Pa sys/opencrypto/crypto.c 162f4bf4335SSam Lefflermost of the framework code 163f4bf4335SSam Leffler.El 164f4bf4335SSam Leffler.Sh SEE ALSO 165c7c8edc3SJohn-Mark Gurney.Xr crypto 4 , 166f4bf4335SSam Leffler.Xr ipsec 4 , 16708fca7a5SJohn-Mark Gurney.Xr crypto 7 , 168*c0341432SJohn Baldwin.Xr crypto_asym 9 , 169*c0341432SJohn Baldwin.Xr crypto_driver 9 , 170*c0341432SJohn Baldwin.Xr crypto_request 9 , 171*c0341432SJohn Baldwin.Xr crypto_session 9 , 1721403a8c7SSam Leffler.Xr sleep 9 173f4bf4335SSam Leffler.Sh HISTORY 174f4bf4335SSam LefflerThe cryptographic framework first appeared in 1757621fdabSRuslan Ermilov.Ox 2.7 1767621fdabSRuslan Ermilovand was written by 1778a7314fcSBaptiste Daroussin.An Angelos D. Keromytis Aq Mt angelos@openbsd.org . 178f4bf4335SSam Leffler.Sh BUGS 179*c0341432SJohn BaldwinThe framework needs a mechanism for determining which driver is 180f4bf4335SSam Lefflerbest for a specific set of algorithms associated with a session. 181f4bf4335SSam LefflerSome type of benchmarking is in order here. 182