| 1 |
.\" Copyright (c) 2017 - 2022 by Stephan Mueller ([email protected]) |
| 2 |
.\" |
| 3 |
.\" Permission is granted to make and distribute verbatim copies of this |
| 4 |
.\" manual provided the copyright notice and this permission notice are |
| 5 |
.\" preserved on all copies. |
| 6 |
.\" |
| 7 |
.\" Permission is granted to copy and distribute modified versions of this |
| 8 |
.\" manual under the conditions for verbatim copying, provided that the |
| 9 |
.\" entire resulting derived work is distributed under the terms of a |
| 10 |
.\" permission notice identical to this one. |
| 11 |
.\" |
| 12 |
.\" Formatted or processed versions of this manual, if unaccompanied by |
| 13 |
.\" the source, must acknowledge the copyright and authors of this work. |
| 14 |
.\" License. |
| 15 |
.TH KCAPI-ENC 1 2017-08-14 |
| 16 |
.SH NAME |
| 17 |
kcapi-enc \- Kernel Crypto API Symmetric Cipher Crypto Helper |
| 18 |
.SH SYNOPSIS |
| 19 |
.B kcapi-enc |
| 20 |
[\fI\,OPTION\/\fR] |
| 21 |
.SH DESCRIPTION |
| 22 |
The |
| 23 |
.I kcapi-enc |
| 24 |
application provides tool to use the symmetric ciphers of the Linux |
| 25 |
kernel crypto API from the command line. |
| 26 |
.PP |
| 27 |
The input data can be provided either via STDIN or via a file |
| 28 |
that is referenced with a command line option. Similarly, the output |
| 29 |
data can either be sent to a file referenced with a command line option |
| 30 |
or to STDOUT. |
| 31 |
.PP |
| 32 |
The majority of symmetric ciphers are block ciphers requiring the |
| 33 |
input data to be multiples of the block size. |
| 34 |
.IR kcapi-enc |
| 35 |
automatically adds padding when using block ciphers and input data |
| 36 |
whose size is not a multiple of the cipher's block size during |
| 37 |
encryption. An automated unpadding during decryption is only applied |
| 38 |
when the input and output data is provided as files. If either |
| 39 |
the input data is provided via STDIN or the output data is obtained |
| 40 |
via STDOUT, the unpadding is not applied. |
| 41 |
.PP |
| 42 |
The used padding schema is consistent with OpenSSL's |
| 43 |
.IR enc |
| 44 |
application. Data encrypted with OpenSSL's |
| 45 |
.IR enc |
| 46 |
tool can be decrypted with |
| 47 |
.IR kcapi-enc |
| 48 |
and vice versa. |
| 49 |
.PP |
| 50 |
The symmetric key used for the cryptographic operation can either be |
| 51 |
provided via a file descriptor or via a password. When using a file |
| 52 |
descriptor, the provided data is taken directly as the symmetric key. |
| 53 |
As the Linux kernel crypto API does not allow specifying the used |
| 54 |
key size with the cipher algorithm name (e.g. AES-128 or AES-256 |
| 55 |
cannot be specified, but only AES), the size of the provided key |
| 56 |
defines which cipher operation is used. When providing a password, |
| 57 |
the |
| 58 |
.IR kcapi-enc |
| 59 |
application derives a 256 bit key from the password using PBKDF2. |
| 60 |
PBKDF2 with HMAC-SHA256 as default transforms the password into a key. |
| 61 |
The PBKDF2 operation requires two additional input values: a salt and |
| 62 |
an iteration count. Both can be provided via the command line. If |
| 63 |
the iteration count is not specified, |
| 64 |
.IR kcapi-enc |
| 65 |
determines the iteration count internally by counting how many |
| 66 |
iterations are necessary to surpass 100ms operation time. The determined |
| 67 |
number is provided via STDERR and must be re-used when decrypting |
| 68 |
the data. If the salt is not provided via command line, |
| 69 |
.IR kcapi-enc |
| 70 |
generates a 256 bit salt and sends its hexadecimal |
| 71 |
representation to STDERR. This salt must be used during decryption |
| 72 |
to ensure the PBKDF2 operation generates the correct symmetric key. |
| 73 |
.LP |
| 74 |
The following options are supported when invoking |
| 75 |
.IR kcapi-enc : |
| 76 |
.TP |
| 77 |
\fB-c\fR, \fB\-\-cipher \fI\,NAME\/\fR |
| 78 |
The |
| 79 |
.IR NAME |
| 80 |
argument specifies the symmetric cipher to be used. The allowed |
| 81 |
ciphers are defined by the Linux kernel. Currently registered |
| 82 |
ciphers can be reviewed at |
| 83 |
.IR /proc/crypto . |
| 84 |
The content of this file, however, can change when new ciphers |
| 85 |
are registered. The |
| 86 |
.IR NAME |
| 87 |
argument is given directly to the Linux kernel crypto API. The |
| 88 |
chosen cipher must be either of type |
| 89 |
.IR skcipher |
| 90 |
or of type |
| 91 |
.IR aead |
| 92 |
as marked in |
| 93 |
.IR /proc/crypto . |
| 94 |
.TP |
| 95 |
\fB\-e\fR, \fB\-\-encrypt\fR |
| 96 |
Perform an encryption operation on the input data. This is the |
| 97 |
default behavior which implies that this option can be skipped. |
| 98 |
The input data is automatically padded if the the data size is |
| 99 |
not a multiple of the block size of the chosen cipher. |
| 100 |
.TP |
| 101 |
\fB\-d\fR, \fB\-\-decrypt\fR |
| 102 |
Perform a decryption operation on the input data. Automated |
| 103 |
unpadding is performed only when the input and output data |
| 104 |
is provided via files referenced with the command line options. |
| 105 |
.TP |
| 106 |
\fB\-i\fR, \fB\-\-infile \fI\,FILE\/\fR |
| 107 |
Use the file referenced with |
| 108 |
.IR FILE |
| 109 |
as the input data. If this option is not provided, |
| 110 |
.IR kcapi-enc |
| 111 |
expects the input data via STDIN. |
| 112 |
.TP |
| 113 |
\fB\-o\fR, \fB\-\-outfile \fI\,FILE\/\fR |
| 114 |
Use the file referenced with |
| 115 |
.IR FILE |
| 116 |
as the destination for the output of the cryptographic |
| 117 |
operation. If this option is not provided, |
| 118 |
.IR kcapi-enc |
| 119 |
will provide the output via STDOUT. |
| 120 |
.TP |
| 121 |
\fB\-\-iv \fI\,IV\/\fR |
| 122 |
Use the |
| 123 |
.IR IV |
| 124 |
data as initialization vector for the cryptographic operation. |
| 125 |
That |
| 126 |
.IR IV |
| 127 |
value is expected to be a hexadecimal notation and must match |
| 128 |
the block size of the chosen cipher. When the CTR block chaining |
| 129 |
mode is used, the |
| 130 |
.IR IV |
| 131 |
value is the start value of the counter. When using the CCM |
| 132 |
cipher, the |
| 133 |
.IR IV |
| 134 |
must specify the initialization vector. If the CCM nonce should be |
| 135 |
specified instead, the option |
| 136 |
.IR --ccm-nonce |
| 137 |
must be used instead. |
| 138 |
.TP |
| 139 |
\fB\-\-aad \fI\,AAD\/\fR |
| 140 |
For AEAD ciphers like CCM, GCM or the authenc ciphers of the Linux |
| 141 |
kernel crypto API, the additional authentication data can be provided |
| 142 |
with the |
| 143 |
.IR AAD |
| 144 |
parameter. The data is expected in hexadecimal format. |
| 145 |
.TP |
| 146 |
\fB\-\-tag \fI\,TAG\/\fR |
| 147 |
The AEAD tag value required for the decryption operation is |
| 148 |
provided with the |
| 149 |
.IR TAG |
| 150 |
parameter. This parameter is expected in hexadecimal format. |
| 151 |
.TP |
| 152 |
\fB\-\-taglen \fI\,LENGTH\/\fR |
| 153 |
During encryption operation of AEAD ciphers, the tag is generated. It |
| 154 |
is permissible to generate differently sized tags where the parameter |
| 155 |
.IR LENGTH |
| 156 |
specifies the size of the tag value to be generated in bytes. |
| 157 |
.TP |
| 158 |
\fB\-\-ccm-nonce \fI\,NONCE\/\fR |
| 159 |
Use the |
| 160 |
.IR NONCE |
| 161 |
data as CCM nonce as defined in SP800-38C Appendix A.2. That |
| 162 |
.IR NONCE |
| 163 |
value is expected to be a hexadecimal notation and must match |
| 164 |
the constraints of SP800-38C Appendix A.2. |
| 165 |
.TP |
| 166 |
\fB\-\-salt \fI\,SALT\/\fR |
| 167 |
When performing the PBKDF2 operation to obtain the symmetric key |
| 168 |
from the password, the |
| 169 |
.IR SALT |
| 170 |
value is used as one input parameter. To ensure the same symmetric |
| 171 |
key is generated from a given password, the same salt value must |
| 172 |
be used. This implies that during decryption, the same salt |
| 173 |
used during the encryption operation must be referenced. |
| 174 |
.IR kcapi-enc |
| 175 |
is unable to determine whether the symmetric key derived from the password is |
| 176 |
the correct one to decrypt the data, because any symmetric key |
| 177 |
will always successfully decrypt data. Yet, the resulting data |
| 178 |
may be different from what is expected. |
| 179 |
.TP |
| 180 |
\fB\-p\fR, \fB\-\-passwd \fI\,PASSWORD\/\fR |
| 181 |
The |
| 182 |
.IR PASSWORD |
| 183 |
parameter provides the password from which the symmetric key |
| 184 |
is derived used to encrypt or decrypt the data. |
| 185 |
.BI WARNING |
| 186 |
The password provided with the command line can be seen from |
| 187 |
other applications or users when inspecting the |
| 188 |
.IR /proc |
| 189 |
file system! Thus, a password SHOULD NOT be used via the |
| 190 |
command line and the |
| 191 |
.IR passwdfd |
| 192 |
option should be used instead. |
| 193 |
.TP |
| 194 |
\fB\-\-passwdfd \fI\,FD\/\fR |
| 195 |
Instead of providing the password via command line, it can be |
| 196 |
injected into |
| 197 |
.IR kcapi-enc |
| 198 |
using a file descriptor. The file descriptor number the |
| 199 |
password will be send through can be provided with the |
| 200 |
.IR FD |
| 201 |
option. |
| 202 |
.TP |
| 203 |
\fB\-\-pbkdfiter \fI\,NUM\/\fR |
| 204 |
Perform |
| 205 |
.IR NUM |
| 206 |
iterations of the PBKDF2 operation to derive the symmetric key. |
| 207 |
If this option is not supplied, |
| 208 |
.IR kcapi-enc |
| 209 |
determines a number of iterations that is large enough to surpass |
| 210 |
100ms operational time for the PBKDF2 function. The determined |
| 211 |
iteration number is logged and must be reused if the same |
| 212 |
symmetric key is to be generated from the same password. |
| 213 |
.TP |
| 214 |
\fB\-\-pbkdfmac \fI\,MAC\/\fR |
| 215 |
Use the keyed message digest referenced with |
| 216 |
.IR MAC |
| 217 |
for the PBKDF2 operation. If this option is not supplied, the default |
| 218 |
of |
| 219 |
.IR hmac(sha256) |
| 220 |
is used. |
| 221 |
.TP |
| 222 |
\fB\-\-keyfd \fI\,FD\/\fR |
| 223 |
To provide a symmetric key that is directly used for the |
| 224 |
cryptographic operation, the file descriptor referenced with |
| 225 |
.IR FD |
| 226 |
must be used. Using a file descriptor is intentionally the only |
| 227 |
way to provide a symmetric key to |
| 228 |
.IR kcapi-enc . |
| 229 |
.TP |
| 230 |
\fB\-\-nounpad\fR |
| 231 |
During decryption and when the input data is provided via a file |
| 232 |
as well as the output is written to a file, |
| 233 |
.IR kcapi-enc |
| 234 |
automatically tries to detect a padding and removes the padding |
| 235 |
data. If this automated unpadding is not desired, the |
| 236 |
.IR nounpad |
| 237 |
option will prevent the unpadding. |
| 238 |
.TP |
| 239 |
\fB\-v\fR, \fB\-\-verbose\fR |
| 240 |
Enable a verbose operation of |
| 241 |
.IR kcapi-enc . |
| 242 |
Using this option multiple times increases the verbosity. |
| 243 |
.TP |
| 244 |
\fB\-q\fR, \fB\-\-quiet\fR |
| 245 |
Prevent the generation of any log output. Note, some log output |
| 246 |
would be needed for proper operation like the display of the |
| 247 |
number of PBKDF2 iterations or the internally generated PBKDF2 salt. |
| 248 |
During quiet operation, none of this information is displayed. |
| 249 |
Note, both information can also be supplied via the command line |
| 250 |
so that |
| 251 |
.IR kcapi-enc |
| 252 |
does not need to generate this information. |
| 253 |
.TP |
| 254 |
\fB\-h\fR, \fB\-\-help\fR |
| 255 |
Display the help text. |
| 256 |
.TP |
| 257 |
\fB\-\-version\fR |
| 258 |
Display the version number of the |
| 259 |
.IR kcapi-enc |
| 260 |
application. |
| 261 |
.PP |
| 262 |
.SH SEE ALSO |
| 263 |
\fBkcapi-dgst\fR(1) \fBkcapi-rng\fR(1) |