xref: /OK3568_Linux_fs/kernel/Documentation/crypto/userspace-if.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593SmuzhiyunUser Space Interface
2*4882a593Smuzhiyun====================
3*4882a593Smuzhiyun
4*4882a593SmuzhiyunIntroduction
5*4882a593Smuzhiyun------------
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunThe concepts of the kernel crypto API visible to kernel space is fully
8*4882a593Smuzhiyunapplicable to the user space interface as well. Therefore, the kernel
9*4882a593Smuzhiyuncrypto API high level discussion for the in-kernel use cases applies
10*4882a593Smuzhiyunhere as well.
11*4882a593Smuzhiyun
12*4882a593SmuzhiyunThe major difference, however, is that user space can only act as a
13*4882a593Smuzhiyunconsumer and never as a provider of a transformation or cipher
14*4882a593Smuzhiyunalgorithm.
15*4882a593Smuzhiyun
16*4882a593SmuzhiyunThe following covers the user space interface exported by the kernel
17*4882a593Smuzhiyuncrypto API. A working example of this description is libkcapi that can
18*4882a593Smuzhiyunbe obtained from [1]. That library can be used by user space
19*4882a593Smuzhiyunapplications that require cryptographic services from the kernel.
20*4882a593Smuzhiyun
21*4882a593SmuzhiyunSome details of the in-kernel kernel crypto API aspects do not apply to
22*4882a593Smuzhiyunuser space, however. This includes the difference between synchronous
23*4882a593Smuzhiyunand asynchronous invocations. The user space API call is fully
24*4882a593Smuzhiyunsynchronous.
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun[1] https://www.chronox.de/libkcapi.html
27*4882a593Smuzhiyun
28*4882a593SmuzhiyunUser Space API General Remarks
29*4882a593Smuzhiyun------------------------------
30*4882a593Smuzhiyun
31*4882a593SmuzhiyunThe kernel crypto API is accessible from user space. Currently, the
32*4882a593Smuzhiyunfollowing ciphers are accessible:
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun-  Message digest including keyed message digest (HMAC, CMAC)
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun-  Symmetric ciphers
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun-  AEAD ciphers
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun-  Random Number Generators
41*4882a593Smuzhiyun
42*4882a593SmuzhiyunThe interface is provided via socket type using the type AF_ALG. In
43*4882a593Smuzhiyunaddition, the setsockopt option type is SOL_ALG. In case the user space
44*4882a593Smuzhiyunheader files do not export these flags yet, use the following macros:
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun::
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun    #ifndef AF_ALG
49*4882a593Smuzhiyun    #define AF_ALG 38
50*4882a593Smuzhiyun    #endif
51*4882a593Smuzhiyun    #ifndef SOL_ALG
52*4882a593Smuzhiyun    #define SOL_ALG 279
53*4882a593Smuzhiyun    #endif
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun
56*4882a593SmuzhiyunA cipher is accessed with the same name as done for the in-kernel API
57*4882a593Smuzhiyuncalls. This includes the generic vs. unique naming schema for ciphers as
58*4882a593Smuzhiyunwell as the enforcement of priorities for generic names.
59*4882a593Smuzhiyun
60*4882a593SmuzhiyunTo interact with the kernel crypto API, a socket must be created by the
61*4882a593Smuzhiyunuser space application. User space invokes the cipher operation with the
62*4882a593Smuzhiyunsend()/write() system call family. The result of the cipher operation is
63*4882a593Smuzhiyunobtained with the read()/recv() system call family.
64*4882a593Smuzhiyun
65*4882a593SmuzhiyunThe following API calls assume that the socket descriptor is already
66*4882a593Smuzhiyunopened by the user space application and discusses only the kernel
67*4882a593Smuzhiyuncrypto API specific invocations.
68*4882a593Smuzhiyun
69*4882a593SmuzhiyunTo initialize the socket interface, the following sequence has to be
70*4882a593Smuzhiyunperformed by the consumer:
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun1. Create a socket of type AF_ALG with the struct sockaddr_alg
73*4882a593Smuzhiyun   parameter specified below for the different cipher types.
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun2. Invoke bind with the socket descriptor
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun3. Invoke accept with the socket descriptor. The accept system call
78*4882a593Smuzhiyun   returns a new file descriptor that is to be used to interact with the
79*4882a593Smuzhiyun   particular cipher instance. When invoking send/write or recv/read
80*4882a593Smuzhiyun   system calls to send data to the kernel or obtain data from the
81*4882a593Smuzhiyun   kernel, the file descriptor returned by accept must be used.
82*4882a593Smuzhiyun
83*4882a593SmuzhiyunIn-place Cipher operation
84*4882a593Smuzhiyun-------------------------
85*4882a593Smuzhiyun
86*4882a593SmuzhiyunJust like the in-kernel operation of the kernel crypto API, the user
87*4882a593Smuzhiyunspace interface allows the cipher operation in-place. That means that
88*4882a593Smuzhiyunthe input buffer used for the send/write system call and the output
89*4882a593Smuzhiyunbuffer used by the read/recv system call may be one and the same. This
90*4882a593Smuzhiyunis of particular interest for symmetric cipher operations where a
91*4882a593Smuzhiyuncopying of the output data to its final destination can be avoided.
92*4882a593Smuzhiyun
93*4882a593SmuzhiyunIf a consumer on the other hand wants to maintain the plaintext and the
94*4882a593Smuzhiyunciphertext in different memory locations, all a consumer needs to do is
95*4882a593Smuzhiyunto provide different memory pointers for the encryption and decryption
96*4882a593Smuzhiyunoperation.
97*4882a593Smuzhiyun
98*4882a593SmuzhiyunMessage Digest API
99*4882a593Smuzhiyun------------------
100*4882a593Smuzhiyun
101*4882a593SmuzhiyunThe message digest type to be used for the cipher operation is selected
102*4882a593Smuzhiyunwhen invoking the bind syscall. bind requires the caller to provide a
103*4882a593Smuzhiyunfilled struct sockaddr data structure. This data structure must be
104*4882a593Smuzhiyunfilled as follows:
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun::
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun    struct sockaddr_alg sa = {
109*4882a593Smuzhiyun        .salg_family = AF_ALG,
110*4882a593Smuzhiyun        .salg_type = "hash", /* this selects the hash logic in the kernel */
111*4882a593Smuzhiyun        .salg_name = "sha1" /* this is the cipher name */
112*4882a593Smuzhiyun    };
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun
115*4882a593SmuzhiyunThe salg_type value "hash" applies to message digests and keyed message
116*4882a593Smuzhiyundigests. Though, a keyed message digest is referenced by the appropriate
117*4882a593Smuzhiyunsalg_name. Please see below for the setsockopt interface that explains
118*4882a593Smuzhiyunhow the key can be set for a keyed message digest.
119*4882a593Smuzhiyun
120*4882a593SmuzhiyunUsing the send() system call, the application provides the data that
121*4882a593Smuzhiyunshould be processed with the message digest. The send system call allows
122*4882a593Smuzhiyunthe following flags to be specified:
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun-  MSG_MORE: If this flag is set, the send system call acts like a
125*4882a593Smuzhiyun   message digest update function where the final hash is not yet
126*4882a593Smuzhiyun   calculated. If the flag is not set, the send system call calculates
127*4882a593Smuzhiyun   the final message digest immediately.
128*4882a593Smuzhiyun
129*4882a593SmuzhiyunWith the recv() system call, the application can read the message digest
130*4882a593Smuzhiyunfrom the kernel crypto API. If the buffer is too small for the message
131*4882a593Smuzhiyundigest, the flag MSG_TRUNC is set by the kernel.
132*4882a593Smuzhiyun
133*4882a593SmuzhiyunIn order to set a message digest key, the calling application must use
134*4882a593Smuzhiyunthe setsockopt() option of ALG_SET_KEY. If the key is not set the HMAC
135*4882a593Smuzhiyunoperation is performed without the initial HMAC state change caused by
136*4882a593Smuzhiyunthe key.
137*4882a593Smuzhiyun
138*4882a593SmuzhiyunSymmetric Cipher API
139*4882a593Smuzhiyun--------------------
140*4882a593Smuzhiyun
141*4882a593SmuzhiyunThe operation is very similar to the message digest discussion. During
142*4882a593Smuzhiyuninitialization, the struct sockaddr data structure must be filled as
143*4882a593Smuzhiyunfollows:
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun::
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun    struct sockaddr_alg sa = {
148*4882a593Smuzhiyun        .salg_family = AF_ALG,
149*4882a593Smuzhiyun        .salg_type = "skcipher", /* this selects the symmetric cipher */
150*4882a593Smuzhiyun        .salg_name = "cbc(aes)" /* this is the cipher name */
151*4882a593Smuzhiyun    };
152*4882a593Smuzhiyun
153*4882a593Smuzhiyun
154*4882a593SmuzhiyunBefore data can be sent to the kernel using the write/send system call
155*4882a593Smuzhiyunfamily, the consumer must set the key. The key setting is described with
156*4882a593Smuzhiyunthe setsockopt invocation below.
157*4882a593Smuzhiyun
158*4882a593SmuzhiyunUsing the sendmsg() system call, the application provides the data that
159*4882a593Smuzhiyunshould be processed for encryption or decryption. In addition, the IV is
160*4882a593Smuzhiyunspecified with the data structure provided by the sendmsg() system call.
161*4882a593Smuzhiyun
162*4882a593SmuzhiyunThe sendmsg system call parameter of struct msghdr is embedded into the
163*4882a593Smuzhiyunstruct cmsghdr data structure. See recv(2) and cmsg(3) for more
164*4882a593Smuzhiyuninformation on how the cmsghdr data structure is used together with the
165*4882a593Smuzhiyunsend/recv system call family. That cmsghdr data structure holds the
166*4882a593Smuzhiyunfollowing information specified with a separate header instances:
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun-  specification of the cipher operation type with one of these flags:
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun   -  ALG_OP_ENCRYPT - encryption of data
171*4882a593Smuzhiyun
172*4882a593Smuzhiyun   -  ALG_OP_DECRYPT - decryption of data
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun-  specification of the IV information marked with the flag ALG_SET_IV
175*4882a593Smuzhiyun
176*4882a593SmuzhiyunThe send system call family allows the following flag to be specified:
177*4882a593Smuzhiyun
178*4882a593Smuzhiyun-  MSG_MORE: If this flag is set, the send system call acts like a
179*4882a593Smuzhiyun   cipher update function where more input data is expected with a
180*4882a593Smuzhiyun   subsequent invocation of the send system call.
181*4882a593Smuzhiyun
182*4882a593SmuzhiyunNote: The kernel reports -EINVAL for any unexpected data. The caller
183*4882a593Smuzhiyunmust make sure that all data matches the constraints given in
184*4882a593Smuzhiyun/proc/crypto for the selected cipher.
185*4882a593Smuzhiyun
186*4882a593SmuzhiyunWith the recv() system call, the application can read the result of the
187*4882a593Smuzhiyuncipher operation from the kernel crypto API. The output buffer must be
188*4882a593Smuzhiyunat least as large as to hold all blocks of the encrypted or decrypted
189*4882a593Smuzhiyundata. If the output data size is smaller, only as many blocks are
190*4882a593Smuzhiyunreturned that fit into that output buffer size.
191*4882a593Smuzhiyun
192*4882a593SmuzhiyunAEAD Cipher API
193*4882a593Smuzhiyun---------------
194*4882a593Smuzhiyun
195*4882a593SmuzhiyunThe operation is very similar to the symmetric cipher discussion. During
196*4882a593Smuzhiyuninitialization, the struct sockaddr data structure must be filled as
197*4882a593Smuzhiyunfollows:
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun::
200*4882a593Smuzhiyun
201*4882a593Smuzhiyun    struct sockaddr_alg sa = {
202*4882a593Smuzhiyun        .salg_family = AF_ALG,
203*4882a593Smuzhiyun        .salg_type = "aead", /* this selects the symmetric cipher */
204*4882a593Smuzhiyun        .salg_name = "gcm(aes)" /* this is the cipher name */
205*4882a593Smuzhiyun    };
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun
208*4882a593SmuzhiyunBefore data can be sent to the kernel using the write/send system call
209*4882a593Smuzhiyunfamily, the consumer must set the key. The key setting is described with
210*4882a593Smuzhiyunthe setsockopt invocation below.
211*4882a593Smuzhiyun
212*4882a593SmuzhiyunIn addition, before data can be sent to the kernel using the write/send
213*4882a593Smuzhiyunsystem call family, the consumer must set the authentication tag size.
214*4882a593SmuzhiyunTo set the authentication tag size, the caller must use the setsockopt
215*4882a593Smuzhiyuninvocation described below.
216*4882a593Smuzhiyun
217*4882a593SmuzhiyunUsing the sendmsg() system call, the application provides the data that
218*4882a593Smuzhiyunshould be processed for encryption or decryption. In addition, the IV is
219*4882a593Smuzhiyunspecified with the data structure provided by the sendmsg() system call.
220*4882a593Smuzhiyun
221*4882a593SmuzhiyunThe sendmsg system call parameter of struct msghdr is embedded into the
222*4882a593Smuzhiyunstruct cmsghdr data structure. See recv(2) and cmsg(3) for more
223*4882a593Smuzhiyuninformation on how the cmsghdr data structure is used together with the
224*4882a593Smuzhiyunsend/recv system call family. That cmsghdr data structure holds the
225*4882a593Smuzhiyunfollowing information specified with a separate header instances:
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun-  specification of the cipher operation type with one of these flags:
228*4882a593Smuzhiyun
229*4882a593Smuzhiyun   -  ALG_OP_ENCRYPT - encryption of data
230*4882a593Smuzhiyun
231*4882a593Smuzhiyun   -  ALG_OP_DECRYPT - decryption of data
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun-  specification of the IV information marked with the flag ALG_SET_IV
234*4882a593Smuzhiyun
235*4882a593Smuzhiyun-  specification of the associated authentication data (AAD) with the
236*4882a593Smuzhiyun   flag ALG_SET_AEAD_ASSOCLEN. The AAD is sent to the kernel together
237*4882a593Smuzhiyun   with the plaintext / ciphertext. See below for the memory structure.
238*4882a593Smuzhiyun
239*4882a593SmuzhiyunThe send system call family allows the following flag to be specified:
240*4882a593Smuzhiyun
241*4882a593Smuzhiyun-  MSG_MORE: If this flag is set, the send system call acts like a
242*4882a593Smuzhiyun   cipher update function where more input data is expected with a
243*4882a593Smuzhiyun   subsequent invocation of the send system call.
244*4882a593Smuzhiyun
245*4882a593SmuzhiyunNote: The kernel reports -EINVAL for any unexpected data. The caller
246*4882a593Smuzhiyunmust make sure that all data matches the constraints given in
247*4882a593Smuzhiyun/proc/crypto for the selected cipher.
248*4882a593Smuzhiyun
249*4882a593SmuzhiyunWith the recv() system call, the application can read the result of the
250*4882a593Smuzhiyuncipher operation from the kernel crypto API. The output buffer must be
251*4882a593Smuzhiyunat least as large as defined with the memory structure below. If the
252*4882a593Smuzhiyunoutput data size is smaller, the cipher operation is not performed.
253*4882a593Smuzhiyun
254*4882a593SmuzhiyunThe authenticated decryption operation may indicate an integrity error.
255*4882a593SmuzhiyunSuch breach in integrity is marked with the -EBADMSG error code.
256*4882a593Smuzhiyun
257*4882a593SmuzhiyunAEAD Memory Structure
258*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~
259*4882a593Smuzhiyun
260*4882a593SmuzhiyunThe AEAD cipher operates with the following information that is
261*4882a593Smuzhiyuncommunicated between user and kernel space as one data stream:
262*4882a593Smuzhiyun
263*4882a593Smuzhiyun-  plaintext or ciphertext
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun-  associated authentication data (AAD)
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun-  authentication tag
268*4882a593Smuzhiyun
269*4882a593SmuzhiyunThe sizes of the AAD and the authentication tag are provided with the
270*4882a593Smuzhiyunsendmsg and setsockopt calls (see there). As the kernel knows the size
271*4882a593Smuzhiyunof the entire data stream, the kernel is now able to calculate the right
272*4882a593Smuzhiyunoffsets of the data components in the data stream.
273*4882a593Smuzhiyun
274*4882a593SmuzhiyunThe user space caller must arrange the aforementioned information in the
275*4882a593Smuzhiyunfollowing order:
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun-  AEAD encryption input: AAD \|\| plaintext
278*4882a593Smuzhiyun
279*4882a593Smuzhiyun-  AEAD decryption input: AAD \|\| ciphertext \|\| authentication tag
280*4882a593Smuzhiyun
281*4882a593SmuzhiyunThe output buffer the user space caller provides must be at least as
282*4882a593Smuzhiyunlarge to hold the following data:
283*4882a593Smuzhiyun
284*4882a593Smuzhiyun-  AEAD encryption output: ciphertext \|\| authentication tag
285*4882a593Smuzhiyun
286*4882a593Smuzhiyun-  AEAD decryption output: plaintext
287*4882a593Smuzhiyun
288*4882a593SmuzhiyunRandom Number Generator API
289*4882a593Smuzhiyun---------------------------
290*4882a593Smuzhiyun
291*4882a593SmuzhiyunAgain, the operation is very similar to the other APIs. During
292*4882a593Smuzhiyuninitialization, the struct sockaddr data structure must be filled as
293*4882a593Smuzhiyunfollows:
294*4882a593Smuzhiyun
295*4882a593Smuzhiyun::
296*4882a593Smuzhiyun
297*4882a593Smuzhiyun    struct sockaddr_alg sa = {
298*4882a593Smuzhiyun        .salg_family = AF_ALG,
299*4882a593Smuzhiyun        .salg_type = "rng", /* this selects the random number generator */
300*4882a593Smuzhiyun        .salg_name = "drbg_nopr_sha256" /* this is the RNG name */
301*4882a593Smuzhiyun    };
302*4882a593Smuzhiyun
303*4882a593Smuzhiyun
304*4882a593SmuzhiyunDepending on the RNG type, the RNG must be seeded. The seed is provided
305*4882a593Smuzhiyunusing the setsockopt interface to set the key. For example, the
306*4882a593Smuzhiyunansi_cprng requires a seed. The DRBGs do not require a seed, but may be
307*4882a593Smuzhiyunseeded. The seed is also known as a *Personalization String* in NIST SP 800-90A
308*4882a593Smuzhiyunstandard.
309*4882a593Smuzhiyun
310*4882a593SmuzhiyunUsing the read()/recvmsg() system calls, random numbers can be obtained.
311*4882a593SmuzhiyunThe kernel generates at most 128 bytes in one call. If user space
312*4882a593Smuzhiyunrequires more data, multiple calls to read()/recvmsg() must be made.
313*4882a593Smuzhiyun
314*4882a593SmuzhiyunWARNING: The user space caller may invoke the initially mentioned accept
315*4882a593Smuzhiyunsystem call multiple times. In this case, the returned file descriptors
316*4882a593Smuzhiyunhave the same state.
317*4882a593Smuzhiyun
318*4882a593SmuzhiyunFollowing CAVP testing interfaces are enabled when kernel is built with
319*4882a593SmuzhiyunCRYPTO_USER_API_RNG_CAVP option:
320*4882a593Smuzhiyun
321*4882a593Smuzhiyun-  the concatenation of *Entropy* and *Nonce* can be provided to the RNG via
322*4882a593Smuzhiyun   ALG_SET_DRBG_ENTROPY setsockopt interface. Setting the entropy requires
323*4882a593Smuzhiyun   CAP_SYS_ADMIN permission.
324*4882a593Smuzhiyun
325*4882a593Smuzhiyun-  *Additional Data* can be provided using the send()/sendmsg() system calls,
326*4882a593Smuzhiyun   but only after the entropy has been set.
327*4882a593Smuzhiyun
328*4882a593SmuzhiyunZero-Copy Interface
329*4882a593Smuzhiyun-------------------
330*4882a593Smuzhiyun
331*4882a593SmuzhiyunIn addition to the send/write/read/recv system call family, the AF_ALG
332*4882a593Smuzhiyuninterface can be accessed with the zero-copy interface of
333*4882a593Smuzhiyunsplice/vmsplice. As the name indicates, the kernel tries to avoid a copy
334*4882a593Smuzhiyunoperation into kernel space.
335*4882a593Smuzhiyun
336*4882a593SmuzhiyunThe zero-copy operation requires data to be aligned at the page
337*4882a593Smuzhiyunboundary. Non-aligned data can be used as well, but may require more
338*4882a593Smuzhiyunoperations of the kernel which would defeat the speed gains obtained
339*4882a593Smuzhiyunfrom the zero-copy interface.
340*4882a593Smuzhiyun
341*4882a593SmuzhiyunThe system-inherent limit for the size of one zero-copy operation is 16
342*4882a593Smuzhiyunpages. If more data is to be sent to AF_ALG, user space must slice the
343*4882a593Smuzhiyuninput into segments with a maximum size of 16 pages.
344*4882a593Smuzhiyun
345*4882a593SmuzhiyunZero-copy can be used with the following code example (a complete
346*4882a593Smuzhiyunworking example is provided with libkcapi):
347*4882a593Smuzhiyun
348*4882a593Smuzhiyun::
349*4882a593Smuzhiyun
350*4882a593Smuzhiyun    int pipes[2];
351*4882a593Smuzhiyun
352*4882a593Smuzhiyun    pipe(pipes);
353*4882a593Smuzhiyun    /* input data in iov */
354*4882a593Smuzhiyun    vmsplice(pipes[1], iov, iovlen, SPLICE_F_GIFT);
355*4882a593Smuzhiyun    /* opfd is the file descriptor returned from accept() system call */
356*4882a593Smuzhiyun    splice(pipes[0], NULL, opfd, NULL, ret, 0);
357*4882a593Smuzhiyun    read(opfd, out, outlen);
358*4882a593Smuzhiyun
359*4882a593Smuzhiyun
360*4882a593SmuzhiyunSetsockopt Interface
361*4882a593Smuzhiyun--------------------
362*4882a593Smuzhiyun
363*4882a593SmuzhiyunIn addition to the read/recv and send/write system call handling to send
364*4882a593Smuzhiyunand retrieve data subject to the cipher operation, a consumer also needs
365*4882a593Smuzhiyunto set the additional information for the cipher operation. This
366*4882a593Smuzhiyunadditional information is set using the setsockopt system call that must
367*4882a593Smuzhiyunbe invoked with the file descriptor of the open cipher (i.e. the file
368*4882a593Smuzhiyundescriptor returned by the accept system call).
369*4882a593Smuzhiyun
370*4882a593SmuzhiyunEach setsockopt invocation must use the level SOL_ALG.
371*4882a593Smuzhiyun
372*4882a593SmuzhiyunThe setsockopt interface allows setting the following data using the
373*4882a593Smuzhiyunmentioned optname:
374*4882a593Smuzhiyun
375*4882a593Smuzhiyun-  ALG_SET_KEY -- Setting the key. Key setting is applicable to:
376*4882a593Smuzhiyun
377*4882a593Smuzhiyun   -  the skcipher cipher type (symmetric ciphers)
378*4882a593Smuzhiyun
379*4882a593Smuzhiyun   -  the hash cipher type (keyed message digests)
380*4882a593Smuzhiyun
381*4882a593Smuzhiyun   -  the AEAD cipher type
382*4882a593Smuzhiyun
383*4882a593Smuzhiyun   -  the RNG cipher type to provide the seed
384*4882a593Smuzhiyun
385*4882a593Smuzhiyun-  ALG_SET_AEAD_AUTHSIZE -- Setting the authentication tag size for
386*4882a593Smuzhiyun   AEAD ciphers. For a encryption operation, the authentication tag of
387*4882a593Smuzhiyun   the given size will be generated. For a decryption operation, the
388*4882a593Smuzhiyun   provided ciphertext is assumed to contain an authentication tag of
389*4882a593Smuzhiyun   the given size (see section about AEAD memory layout below).
390*4882a593Smuzhiyun
391*4882a593Smuzhiyun-  ALG_SET_DRBG_ENTROPY -- Setting the entropy of the random number generator.
392*4882a593Smuzhiyun   This option is applicable to RNG cipher type only.
393*4882a593Smuzhiyun
394*4882a593SmuzhiyunUser space API example
395*4882a593Smuzhiyun----------------------
396*4882a593Smuzhiyun
397*4882a593SmuzhiyunPlease see [1] for libkcapi which provides an easy-to-use wrapper around
398*4882a593Smuzhiyunthe aforementioned Netlink kernel interface. [1] also contains a test
399*4882a593Smuzhiyunapplication that invokes all libkcapi API calls.
400*4882a593Smuzhiyun
401*4882a593Smuzhiyun[1] https://www.chronox.de/libkcapi.html
402