KCAPI-ENC(1)
π NAME π
kcapi-enc β Kernel Crypto API Symmetric Cipher Crypto Helper
π¦ SYNOPSIS π¦
kcapi-enc [OPTION]
πΈ DESCRIPTION πΈ
okay so bestie, kcapi-enc is the little command-line bestie that lets you use the symmetric ciphers of the Linux kernel crypto API straight from your terminal. no kernel module drama, no writing C, just vibes. β¨
Your input data can come in either way: through STDIN, or from a file that you point at with a command line option. Same energy on the way out β the output either goes into a file you named with a command line option, or it goes to STDOUT. π
Now, the tea: most symmetric ciphers are block ciphers, and block ciphers are picky β they need the input data to be multiples of the block size. So kcapi-enc automatically adds padding when you're using a block cipher and your input data's size isn't a multiple of the cipher's block size, but only during encryption. The automated unpadding during decryption? That only happens when both the input and output data are provided as files. If either your input comes in via STDIN or your output goes out via STDOUT, the unpadding is not applied. no cap. π«Ά
The padding schema used is consistent with OpenSSL's enc application. So data encrypted with OpenSSL's enc tool can be decrypted with kcapi-enc and vice versa. it's giving interoperability, we love to see it. ππ
The symmetric key used for the cryptographic operation can be provided either via a file descriptor or via a password. When you use a file descriptor, the data you provide is taken directly as the symmetric key. Here's the thing though β the Linux kernel crypto API does not allow specifying the used key size with the cipher algorithm name (so like, AES-128 or AES-256 cannot be specified, only AES), which means the size of the provided key defines which cipher operation is used. When you provide a password, kcapi-enc derives a 256 bit key from that password using PBKDF2. PBKDF2 with HMAC-SHA256 as default transforms the password into a key.
The PBKDF2 operation needs two extra input values: a salt and an iteration count. Both can be provided via the command line. If the iteration count is not specified, kcapi-enc determines the iteration count internally by counting how many iterations are necessary to surpass 100ms operation time. That determined number is provided via STDERR and must be re-used when decrypting the data. If the salt is not provided via command line, kcapi-enc generates a 256 bit salt and sends its hexadecimal representation to STDERR. This salt must be used during decryption to ensure the PBKDF2 operation generates the correct symmetric key. write it down bestie, fr fr. π
The following options are supported when invoking kcapi-enc:
β¨ OPTIONS β¨
-c,--cipher NAMEβ theNAMEargument specifies the symmetric cipher to be used. The allowed ciphers are defined by the Linux kernel. Currently registered ciphers can be reviewed at/proc/crypto. The content of this file, however, can change when new ciphers are registered. TheNAMEargument is given directly to the Linux kernel crypto API. The chosen cipher must be either of typeskcipheror of typeaeadas marked in/proc/crypto. π-e,--encryptβ perform an encryption operation on the input data. This is the default behavior, which implies that this option can be skipped. The input data is automatically padded if the the data size is not a multiple of the block size of the chosen cipher. β¨-d,--decryptβ perform a decryption operation on the input data. Automated unpadding is performed only when the input and output data is provided via files referenced with the command line options. π-i,--infile FILEβ use the file referenced withFILEas the input data. If this option is not provided,kcapi-encexpects the input data via STDIN.-o,--outfile FILEβ use the file referenced withFILEas the destination for the output of the cryptographic operation. If this option is not provided,kcapi-encwill provide the output via STDOUT.--iv IVβ use theIVdata as initialization vector for the cryptographic operation. ThatIVvalue is expected to be a hexadecimal notation and must match the block size of the chosen cipher. When the CTR block chaining mode is used, theIVvalue is the start value of the counter. When using the CCM cipher, theIVmust specify the initialization vector. If the CCM nonce should be specified instead, the option--ccm-noncemust be used instead. π«--aad AADβ for AEAD ciphers likeCCM,GCMor theauthencciphers of the Linux kernel crypto API, the additional authentication data can be provided with theAADparameter. The data is expected in hexadecimal format.--tag TAGβ the AEAD tag value required for the decryption operation is provided with theTAGparameter. This parameter is expected in hexadecimal format. π·οΈ--taglen LENGTHβ during encryption operation of AEAD ciphers, the tag is generated. It is permissible to generate differently sized tags where the parameterLENGTHspecifies the size of the tag value to be generated in bytes.--ccm-nonce NONCEβ use theNONCEdata as CCM nonce as defined inSP800-38C Appendix A.2. ThatNONCEvalue is expected to be a hexadecimal notation and must match the constraints ofSP800-38C Appendix A.2.--salt SALTβ when performing the PBKDF2 operation to obtain the symmetric key from the password, theSALTvalue is used as one input parameter. To ensure the same symmetric key is generated from a given password, the same salt value must be used. This implies that during decryption, the same salt used during the encryption operation must be referenced.kcapi-encis unable to determine whether the symmetric key derived from the password is the correct one to decrypt the data, because any symmetric key will always successfully decrypt data. Yet, the resulting data may be different from what is expected. π-p,--passwd PASSWORDβ thePASSWORDparameter provides the password from which the symmetric key is derived used to encrypt or decrypt the data.
WARNING the password provided with the command line can be seen from other applications or users when inspecting the/procfile system! Thus, a password SHOULD NOT be used via the command line and thepasswdfdoption should be used instead. π¨
--passwdfd FDβ instead of providing the password via command line, it can be injected intokcapi-encusing a file descriptor. The file descriptor number the password will be send through can be provided with theFDoption.--pbkdfiter NUMβ performNUMiterations of the PBKDF2 operation to derive the symmetric key. If this option is not supplied,kcapi-encdetermines a number of iterations that is large enough to surpass 100ms operational time for the PBKDF2 function. The determined iteration number is logged and must be reused if the same symmetric key is to be generated from the same password.--pbkdfmac MACβ use the keyed message digest referenced withMACfor the PBKDF2 operation. If this option is not supplied, the default ofhmac(sha256)is used.--key-len LENGTHβLENGTHspecifies length of the key passed to the cipher algorithm.kcapi-encuses 32-byte key by default.--keyfd FDβ to provide a symmetric key that is directly used for the cryptographic operation, the file descriptor referenced withFDmust be used. Using a file descriptor is intentionally the only way to provide a symmetric key tokcapi-enc. π--nounpadβ during decryption and when the input data is provided via a file as well as the output is written to a file,kcapi-encautomatically tries to detect a padding and removes the padding data. If this automated unpadding is not desired, thenounpadoption will prevent the unpadding. π-v,--verboseβ enable a verbose operation ofkcapi-enc. Using this option multiple times increases the verbosity. π£οΈ-q,--quietβ prevent the generation of any log output. Note, some log output would be needed for proper operation like the display of the number of PBKDF2 iterations or the internally generated PBKDF2 salt. During quiet operation, none of this information is displayed. Note, both information can also be supplied via the command line so thatkcapi-encdoes not need to generate this information. π€«-h,--helpβ display the help text.--versionβ display the version number of thekcapi-encapplication.
π SEE ALSO π
kcapi-dgst(1) kcapi-hasher(1) kcapi-rng(1)
and that's the whole page bestie, you ate that π β¨ this one's dated 2017-08-14 and it lives in the KCAPI-ENC(1) corner of the General Commands Manual β go forth and encrypt responsibly, mwah ππ¦π
π¦ where this page comes from
- fedora 43: libkcapi-tools 1.5.0-6.fc43 Β· BSD-3-Clause OR GPL-2.0-only
- fedora 44: libkcapi-tools 1.5.0-7.fc44 Β· BSD-3-Clause OR GPL-2.0-only
- nixos 26.05: libkcapi 1.5.0
- Copyright (c) 2017 - 2024 by Stephan Mueller (smueller@chronox.de)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms