sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget'/translations/zh_CN/crypto/userspace-ifmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget'/translations/zh_TW/crypto/userspace-ifmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget'/translations/it_IT/crypto/userspace-ifmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget'/translations/ja_JP/crypto/userspace-ifmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget'/translations/ko_KR/crypto/userspace-ifmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget'/translations/sp_SP/crypto/userspace-ifmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhsection)}(hhh](htitle)}(hUser Space Interfaceh]hUser Space Interface}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhA/var/lib/git/docbuild/linux/Documentation/crypto/userspace-if.rsthKubh)}(hhh](h)}(h Introductionh]h Introduction}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh paragraph)}(hThe concepts of the kernel crypto API visible to kernel space is fully applicable to the user space interface as well. Therefore, the kernel crypto API high level discussion for the in-kernel use cases applies here as well.h]hThe concepts of the kernel crypto API visible to kernel space is fully applicable to the user space interface as well. Therefore, the kernel crypto API high level discussion for the in-kernel use cases applies here as well.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hThe major difference, however, is that user space can only act as a consumer and never as a provider of a transformation or cipher algorithm.h]hThe major difference, however, is that user space can only act as a consumer and never as a provider of a transformation or cipher algorithm.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hhhhubh)}(hX The following covers the user space interface exported by the kernel crypto API. A working example of this description is libkcapi that can be obtained from [1]. That library can be used by user space applications that require cryptographic services from the kernel.h]hX The following covers the user space interface exported by the kernel crypto API. A working example of this description is libkcapi that can be obtained from [1]. That library can be used by user space applications that require cryptographic services from the kernel.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hSome details of the in-kernel kernel crypto API aspects do not apply to user space, however. This includes the difference between synchronous and asynchronous invocations. The user space API call is fully synchronous.h]hSome details of the in-kernel kernel crypto API aspects do not apply to user space, however. This includes the difference between synchronous and asynchronous invocations. The user space API call is fully synchronous.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(h([1] https://www.chronox.de/libkcapi.htmlh](h[1] }(hjhhhNhNubh reference)}(h$https://www.chronox.de/libkcapi.htmlh]h$https://www.chronox.de/libkcapi.html}(hj hhhNhNubah}(h]h ]h"]h$]h&]refurijuh1j hjubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubeh}(h] introductionah ]h"] introductionah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hUser Space API General Remarksh]hUser Space API General Remarks}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj)hhhhhKubh)}(heThe kernel crypto API is accessible from user space. Currently, the following ciphers are accessible:h]heThe kernel crypto API is accessible from user space. Currently, the following ciphers are accessible:}(hj:hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj)hhubh bullet_list)}(hhh](h list_item)}(h;Message digest including keyed message digest (HMAC, CMAC) h]h)}(h:Message digest including keyed message digest (HMAC, CMAC)h]h:Message digest including keyed message digest (HMAC, CMAC)}(hjShhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK"hjOubah}(h]h ]h"]h$]h&]uh1jMhjJhhhhhNubjN)}(hSymmetric ciphers h]h)}(hSymmetric ciphersh]hSymmetric ciphers}(hjkhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK$hjgubah}(h]h ]h"]h$]h&]uh1jMhjJhhhhhNubjN)}(h AEAD ciphers h]h)}(h AEAD ciphersh]h AEAD ciphers}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK&hjubah}(h]h ]h"]h$]h&]uh1jMhjJhhhhhNubjN)}(hRandom Number Generators h]h)}(hRandom Number Generatorsh]hRandom Number Generators}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK(hjubah}(h]h ]h"]h$]h&]uh1jMhjJhhhhhNubeh}(h]h ]h"]h$]h&]bullet-uh1jHhhhK"hj)hhubh)}(hThe interface is provided via socket type using the type AF_ALG. In addition, the setsockopt option type is SOL_ALG. In case the user space header files do not export these flags yet, use the following macros:h]hThe interface is provided via socket type using the type AF_ALG. In addition, the setsockopt option type is SOL_ALG. In case the user space header files do not export these flags yet, use the following macros:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK*hj)hhubh literal_block)}(hR#ifndef AF_ALG #define AF_ALG 38 #endif #ifndef SOL_ALG #define SOL_ALG 279 #endifh]hR#ifndef AF_ALG #define AF_ALG 38 #endif #ifndef SOL_ALG #define SOL_ALG 279 #endif}hjsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1jhhhK0hj)hhubh)}(hA cipher is accessed with the same name as done for the in-kernel API calls. This includes the generic vs. unique naming schema for ciphers as well as the enforcement of priorities for generic names.h]hA cipher is accessed with the same name as done for the in-kernel API calls. This includes the generic vs. unique naming schema for ciphers as well as the enforcement of priorities for generic names.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK8hj)hhubh)}(hX To interact with the kernel crypto API, a socket must be created by the user space application. User space invokes the cipher operation with the send()/write() system call family. The result of the cipher operation is obtained with the read()/recv() system call family.h]hX To interact with the kernel crypto API, a socket must be created by the user space application. User space invokes the cipher operation with the send()/write() system call family. The result of the cipher operation is obtained with the read()/recv() system call family.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubjI)}(hhh](jN)}(hthe concatenation of *Entropy* and *Nonce* can be provided to the RNG via ALG_SET_DRBG_ENTROPY setsockopt interface. Setting the entropy requires CAP_SYS_ADMIN permission. h]h)}(hthe concatenation of *Entropy* and *Nonce* can be provided to the RNG via ALG_SET_DRBG_ENTROPY setsockopt interface. Setting the entropy requires CAP_SYS_ADMIN permission.h](hthe concatenation of }(hj2hhhNhNubj)}(h *Entropy*h]hEntropy}(hj:hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj2ubh and }(hj2hhhNhNubj)}(h*Nonce*h]hNonce}(hjLhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj2ubh can be provided to the RNG via ALG_SET_DRBG_ENTROPY setsockopt interface. Setting the entropy requires CAP_SYS_ADMIN permission.}(hj2hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMAhj.ubah}(h]h ]h"]h$]h&]uh1jMhj+hhhhhNubjN)}(ht*Additional Data* can be provided using the send()/sendmsg() system calls, but only after the entropy has been set. h]h)}(hs*Additional Data* can be provided using the send()/sendmsg() system calls, but only after the entropy has been set.h](j)}(h*Additional Data*h]hAdditional Data}(hjrhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjnubhb can be provided using the send()/sendmsg() system calls, but only after the entropy has been set.}(hjnhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMEhjjubah}(h]h ]h"]h$]h&]uh1jMhj+hhhhhNubeh}(h]h ]h"]h$]h&]jjuh1jHhhhMAhjhhubeh}(h]random-number-generator-apiah ]h"]random number generator apiah$]h&]uh1hhhhhhhhM!ubh)}(hhh](h)}(hZero-Copy Interfaceh]hZero-Copy Interface}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMIubh)}(hIn addition to the send/write/read/recv system call family, the AF_ALG interface can be accessed with the zero-copy interface of splice/vmsplice. As the name indicates, the kernel tries to avoid a copy operation into kernel space.h]hIn addition to the send/write/read/recv system call family, the AF_ALG interface can be accessed with the zero-copy interface of splice/vmsplice. As the name indicates, the kernel tries to avoid a copy operation into kernel space.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMKhjhhubh)}(hThe zero-copy operation requires data to be aligned at the page boundary. Non-aligned data can be used as well, but may require more operations of the kernel which would defeat the speed gains obtained from the zero-copy interface.h]hThe zero-copy operation requires data to be aligned at the page boundary. Non-aligned data can be used as well, but may require more operations of the kernel which would defeat the speed gains obtained from the zero-copy interface.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMPhjhhubh)}(hThe system-inherent limit for the size of one zero-copy operation is 16 pages. If more data is to be sent to AF_ALG, user space must slice the input into segments with a maximum size of 16 pages.h]hThe system-inherent limit for the size of one zero-copy operation is 16 pages. If more data is to be sent to AF_ALG, user space must slice the input into segments with a maximum size of 16 pages.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMUhjhhubh)}(hmZero-copy can be used with the following code example (a complete working example is provided with libkcapi):h]hmZero-copy can be used with the following code example (a complete working example is provided with libkcapi):}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMYhjhhubj)}(hint pipes[2]; pipe(pipes); /* input data in iov */ vmsplice(pipes[1], iov, iovlen, SPLICE_F_GIFT); /* opfd is the file descriptor returned from accept() system call */ splice(pipes[0], NULL, opfd, NULL, ret, 0); read(opfd, out, outlen);h]hint pipes[2]; pipe(pipes); /* input data in iov */ vmsplice(pipes[1], iov, iovlen, SPLICE_F_GIFT); /* opfd is the file descriptor returned from accept() system call */ splice(pipes[0], NULL, opfd, NULL, ret, 0); read(opfd, out, outlen);}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhM^hjhhubeh}(h]zero-copy-interfaceah ]h"]zero-copy interfaceah$]h&]uh1hhhhhhhhMIubh)}(hhh](h)}(hSetsockopt Interfaceh]hSetsockopt Interface}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMiubh)}(hXIn addition to the read/recv and send/write system call handling to send and retrieve data subject to the cipher operation, a consumer also needs to set the additional information for the cipher operation. This additional information is set using the setsockopt system call that must be invoked with the file descriptor of the open cipher (i.e. the file descriptor returned by the accept system call).h]hXIn addition to the read/recv and send/write system call handling to send and retrieve data subject to the cipher operation, a consumer also needs to set the additional information for the cipher operation. This additional information is set using the setsockopt system call that must be invoked with the file descriptor of the open cipher (i.e. the file descriptor returned by the accept system call).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMkhjhhubh)}(h6Each setsockopt invocation must use the level SOL_ALG.h]h6Each setsockopt invocation must use the level SOL_ALG.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMrhjhhubh)}(hWThe setsockopt interface allows setting the following data using the mentioned optname:h]hWThe setsockopt interface allows setting the following data using the mentioned optname:}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMthjhhubjI)}(hhh](jN)}(hALG_SET_KEY -- Setting the key. Key setting is applicable to: - the skcipher cipher type (symmetric ciphers) - the hash cipher type (keyed message digests) - the AEAD cipher type - the RNG cipher type to provide the seed h](h)}(h=ALG_SET_KEY -- Setting the key. Key setting is applicable to:h]h=ALG_SET_KEY -- Setting the key. Key setting is applicable to:}(hj?hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMwhj;ubjI)}(hhh](jN)}(h-the skcipher cipher type (symmetric ciphers) h]h)}(h,the skcipher cipher type (symmetric ciphers)h]h,the skcipher cipher type (symmetric ciphers)}(hjThhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMyhjPubah}(h]h ]h"]h$]h&]uh1jMhjMubjN)}(h-the hash cipher type (keyed message digests) h]h)}(h,the hash cipher type (keyed message digests)h]h,the hash cipher type (keyed message digests)}(hjlhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM{hjhubah}(h]h ]h"]h$]h&]uh1jMhjMubjN)}(hthe AEAD cipher type h]h)}(hthe AEAD cipher typeh]hthe AEAD cipher type}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM}hjubah}(h]h ]h"]h$]h&]uh1jMhjMubjN)}(h(the RNG cipher type to provide the seed h]h)}(h'the RNG cipher type to provide the seedh]h'the RNG cipher type to provide the seed}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jMhjMubeh}(h]h ]h"]h$]h&]jjuh1jHhhhMyhj;ubeh}(h]h ]h"]h$]h&]uh1jMhj8hhhNhNubjN)}(hXALG_SET_KEY_BY_KEY_SERIAL -- Setting the key via keyring key_serial_t. This operation behaves the same as ALG_SET_KEY. The decrypted data is copied from a keyring key, and uses that data as the key for symmetric encryption. The passed in key_serial_t must have the KEY_(POS|USR|GRP|OTH)_SEARCH permission set, otherwise -EPERM is returned. Supports key types: user, logon, encrypted, and trusted. h]hdefinition_list)}(hhh]hdefinition_list_item)}(hXALG_SET_KEY_BY_KEY_SERIAL -- Setting the key via keyring key_serial_t. This operation behaves the same as ALG_SET_KEY. The decrypted data is copied from a keyring key, and uses that data as the key for symmetric encryption. The passed in key_serial_t must have the KEY_(POS|USR|GRP|OTH)_SEARCH permission set, otherwise -EPERM is returned. Supports key types: user, logon, encrypted, and trusted. h](hterm)}(hFALG_SET_KEY_BY_KEY_SERIAL -- Setting the key via keyring key_serial_t.h]hFALG_SET_KEY_BY_KEY_SERIAL -- Setting the key via keyring key_serial_t.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhhhMhjubh definition)}(hhh](h)}(hThis operation behaves the same as ALG_SET_KEY. The decrypted data is copied from a keyring key, and uses that data as the key for symmetric encryption.h]hThis operation behaves the same as ALG_SET_KEY. The decrypted data is copied from a keyring key, and uses that data as the key for symmetric encryption.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubh)}(hThe passed in key_serial_t must have the KEY_(POS|USR|GRP|OTH)_SEARCH permission set, otherwise -EPERM is returned. Supports key types: user, logon, encrypted, and trusted.h]hThe passed in key_serial_t must have the KEY_(POS|USR|GRP|OTH)_SEARCH permission set, otherwise -EPERM is returned. Supports key types: user, logon, encrypted, and trusted.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubeh}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jMhj8hhhNhNubjN)}(hXGALG_SET_AEAD_AUTHSIZE -- Setting the authentication tag size for AEAD ciphers. For a encryption operation, the authentication tag of the given size will be generated. For a decryption operation, the provided ciphertext is assumed to contain an authentication tag of the given size (see section about AEAD memory layout below). h]h)}(hXFALG_SET_AEAD_AUTHSIZE -- Setting the authentication tag size for AEAD ciphers. For a encryption operation, the authentication tag of the given size will be generated. For a decryption operation, the provided ciphertext is assumed to contain an authentication tag of the given size (see section about AEAD memory layout below).h]hXFALG_SET_AEAD_AUTHSIZE -- Setting the authentication tag size for AEAD ciphers. For a encryption operation, the authentication tag of the given size will be generated. For a decryption operation, the provided ciphertext is assumed to contain an authentication tag of the given size (see section about AEAD memory layout below).}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubah}(h]h ]h"]h$]h&]uh1jMhj8hhhhhNubjN)}(hALG_SET_DRBG_ENTROPY -- Setting the entropy of the random number generator. This option is applicable to RNG cipher type only. h]h)}(h~ALG_SET_DRBG_ENTROPY -- Setting the entropy of the random number generator. This option is applicable to RNG cipher type only.h]h~ALG_SET_DRBG_ENTROPY -- Setting the entropy of the random number generator. This option is applicable to RNG cipher type only.}(hj0 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj, ubah}(h]h ]h"]h$]h&]uh1jMhj8hhhhhNubeh}(h]h ]h"]h$]h&]jjuh1jHhhhMwhjhhubeh}(h]setsockopt-interfaceah ]h"]setsockopt interfaceah$]h&]uh1hhhhhhhhMiubh)}(hhh](h)}(hUser space API exampleh]hUser space API example}(hjU hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjR hhhhhMubh)}(hPlease see [1] for libkcapi which provides an easy-to-use wrapper around the aforementioned Netlink kernel interface. [1] also contains a test application that invokes all libkcapi API calls.h]hPlease see [1] for libkcapi which provides an easy-to-use wrapper around the aforementioned Netlink kernel interface. [1] also contains a test application that invokes all libkcapi API calls.}(hjc hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjR hhubh)}(h([1] https://www.chronox.de/libkcapi.htmlh](h[1] }(hjq hhhNhNubj )}(h$https://www.chronox.de/libkcapi.htmlh]h$https://www.chronox.de/libkcapi.html}(hjy hhhNhNubah}(h]h ]h"]h$]h&]refurij{ uh1j hjq ubeh}(h]h ]h"]h$]h&]uh1hhhhMhjR hhubeh}(h]user-space-api-exampleah ]h"]user space api exampleah$]h&]uh1hhhhhhhhMubeh}(h]user-space-interfaceah ]h"]user space interfaceah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerj error_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}nameids}(j j j&j#jljijjj/j,jKjHjjjjjjjjjO jL j j u nametypes}(j j&jljj/jKjjjjjO j uh}(j hj#hjij)jjoj,jjHj2jjNjjjjjjjL jj jR u footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}Rparse_messages]transform_messages] transformerN include_log] decorationNhhub.