77 Commits

Author SHA1 Message Date
Ingo Franzki
296eb39c60 Changes to support PHMAC with integritysetup and cryptsetup
Make the PHMAC integrity algorithm know to libcryptsetup.

The size of a key for PHMAC is not known, because PHMAC gets an opaque
blob as key, who's physical size has nothing to do with the cryptographic
size. Thus, let INTEGRITY_key_size() and crypt_parse_integrity_mode()
return the required_key_size as key size for PHMAC, or -EINVAL if
required_key_size is zero, to indicate that the size is unknown.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2025-11-13 09:21:40 +01:00
Milan Broz
8364178b38 Update copyright year. 2025-01-15 23:09:36 +01:00
Milan Broz
491f31c4d4 Add --integrity-key-size option to cryptsetup.
This patch adds support for --integrity-key-size option that can be used
to setup non-standard HMAC integrity key size.
2024-12-03 20:25:54 +01:00
Milan Broz
3a7794795f Always set cipher_mode even in crypt_parse_name_and_mode.
Othewrwise some tools like valgrind can see unitialized string.
2024-07-29 16:00:01 +02:00
Milan Broz
8f4a149ed3 Fix bad parsing of capi:xts(aes)-plain
Corrent logic confuses it with aes-plain (capi:xts(aes)-plain
does not work in luksFormat).
For CAPI format we need to skip this test.
2024-06-03 16:40:01 +00:00
Milan Broz
661f57def4 Use SPDX license identifiers.
This patch switches code to SPDX one-line license identifiers according to
https://spdx.dev/learn/handling-license-info/
and replacing long license text headers.

I used C++ format on the first line in style
// SPDX-License-Identifier: <id>
except exported libcryptsetup.h, when only C comments are used.

The only additional changes are:
- switch backend utf8.c from LGPL2+ to LGPL2.1+ (as in systemd)
- add some additional formatting lines.
2024-06-03 16:38:15 +00:00
Milan Broz
bd0ef58b3a Update copyright notice to include 2024 year. 2024-01-23 16:10:44 +01:00
Milan Broz
dff9ee8c8c Also disallow active devices with internal kernel names.
The same problem fixed in commit 438cf1d1b3
is present in libdevmapper wrapper when parsing active device table.

The whole point of conversion was that non-authenticated modes
can be always represented in the old cipher-mode-iv format.
As the internal names contains dash, these are unsupported.

That said, the libdevmapper backend now correctly returns
full cipher specification including capi prefix for this case.

Init_by_name call now fails with incomplatible cipher definition error.
2023-05-02 15:42:21 +02:00
Milan Broz
438cf1d1b3 Disallow use of internal kenrel crypto driver names in "capi" specification.
The common way to specify cipher mode in cryptsetup
is to use cipher-mode-iv notation (like aes-xts-plain64).
With introduction of authenticated ciphers we also allow "capi:<spec>"
notation that is directly used by dm-crypt (e.g. capi:xts(aes)-plain64).

CAPI specification was never intended to be used with internal
kernel crypto api names (with dash in algorithm name), actually the
whole parsing routine wrongly parses mode here now.

The code not checks if parsing wrongly separated the full cipher
string and effectively allowing only proper cipher names
(example of no longer supported string is capi:xts(ecb(aes-generic))-plain64).

Thanks to Jan Wichelmann, Luca Wilke and Thomas Eisenbarth from
University of Lübeck for noticing the problems with this code.

Fixes: #809
2023-04-25 18:56:31 +02:00
Milan Broz
72f799b393 Update Copyright year. 2023-02-09 17:11:18 +01:00
Ondrej Kozina
19c15a652f Copy also integrity string in legacy mode.
So that it handles integrity string same as it does
with cipher string.
2022-10-20 14:24:11 +02:00
Ondrej Kozina
9a9ddc7d22 Move cipher_dm2c to crypto utilities.
(Gets renamed to crypt_capi_to_cipher)
2022-10-20 14:24:02 +02:00
Milan Broz
ceed3c0c3b Introduce crypt_log_hex helper and use it for log_std output. 2022-04-28 08:11:58 +00:00
Milan Broz
e161cd1859 Add constant time crypt_bytes_to_hex helper and use it in libdevmapper.
Fixes: #736
2022-04-28 08:11:58 +00:00
Milan Broz
ff14c17de7 Use constant time conversion for crypt_hex_to_bytes.
We use hexa conversions for keys, avoid possible
leaks with cover channels by making these functions
constant time.
2022-04-28 08:11:58 +00:00
Milan Broz
ab975bc1c4 Update copyright year.
And unify format in several places.
2022-01-29 10:43:02 +01:00
Milan Broz
4cdd826282 Check exit value for snprintf where it makes sense. 2021-05-18 22:07:47 +02:00
Milan Broz
ca2e1fc956 Fix some includes. 2021-02-27 21:14:38 +01:00
Ondrej Kozina
a4d7c46d80 Move cipher_null check in internal function crypt_is_cipher_null.
Also removes tools helper so that we keep check in one place.
2021-02-16 18:08:34 +01:00
Milan Broz
4471452105 Remove some stale FIXME markings. 2021-02-11 11:12:11 +00:00
Milan Broz
d1d9dd8e20 Update Copyright year. 2021-01-25 22:00:25 +01:00
Milan Broz
f2ab443cca Fix a problem in integritysetup if a hash algorithm has dash in the name.
If users want to use blake2b/blake2s, the kernel algorithm name
includes dash - like "blake2s-256".

Because we use dash as a separator, this patch adds an exception
for this case.

Fixes: #581.
2020-07-27 12:50:46 +02:00
Milan Broz
080566a1fd Update copyright year. 2020-01-03 13:04:55 +01:00
Milan Broz
b03cb3f3d8 Export memory safe functions.
Make crypt_safe_alloc/realloc/free and memzero part of API.
2019-11-16 21:28:54 +01:00
Milan Broz
a6f5ce8c7b Update copyright year.
And unify name copyright format.
2019-01-25 09:45:57 +01:00
Milan Broz
9df042c0b8 Use explicit_bzero if available. 2018-10-04 15:21:01 +02:00
Milan Broz
e654fabe04 Add some new AEAD modes and allow SHA1 for integrity check.
NOTE: all this code will be switched to generic checks, this list
is just a temporary hack.
2018-05-21 15:29:49 +02:00
Milan Broz
1fe014dbae Update copyright year. 2018-01-20 17:55:21 +01:00
Milan Broz
f6e613a76f Revert cipher requirement in parse cipher.
There is several specification that violate this (chacha20 etc).
Just use the old way...
2018-01-18 22:42:34 +01:00
Milan Broz
c6a8b6471a Allow ECB in cipher spec (fixes previous patch). 2018-01-18 21:55:52 +01:00
Milan Broz
aeea93fa95 Properly fail in luksFormat if cipher format is missing required IV.
For now, crypto API quietly used cipher witout IV if a cipher
algorithm wihtou IV specificaton was used (e.g. aes-xts).

This caused fail later during activation.

This patch allows only two specific backed use without specified IV
(ECB mode and NULL cipher).

Also check cipher string early during parsing of CLI options.
2018-01-18 21:20:25 +01:00
Milan Broz
c56bdee177 Add backend support for new device-mapper kernel options.
This patch adds support for using keyring for volume key
and support for new integrity fields for dm-crypt.

Also helpers for searching disk by id.

To be used later.
2017-09-24 19:49:35 +02:00
Milan Broz
503956707c Move crypt_keyfile_read() to libcryptsetup internal file.
The utils_crypt.c file is directly linked to userpsace tools,
we should use library call and not local implementation.
2017-08-15 08:35:10 +02:00
Milan Broz
0abf57be5d Change PBKDF interface API.
Prepare API for PBKDF that can set three costs
  - time (similar to iterations in PBKDF2)
  - memory (required memory for memory-hard function)
  - threads (required number of threads/CPUs).

This patch also removes wrongly designed API call
crypt_benchmark_kdf and replaces it with the new call
crypt_benchmark_pbkdf.

Two functions for PBKDF per context setting
are introduced: crypt_set_pbkdf_type and crypt_get_pbkdf_type.

The patch should be backward compatible when using
crypt_set_iteration_time function (works only for PBKDF2).

Signed-off-by: Milan Broz <gmazyland@gmail.com>
2017-08-06 21:24:05 +02:00
Milan Broz
c80dbb2210 Fxi luksKill slot to work in batch mode in non-tty environment.
If there is no TTY on stdin (like nohup or service) then
batch mode should not fail to kill slot.

For more info see Issue#329.
2017-06-21 13:31:08 +02:00
Milan Broz
0bb7098fd8 Add integritysetup command line tool for the dm-integrity standalone setting.
The dm-integrity target is intended to be used for authenticated
encryption through LUKS and dm-crypt.

It can be used in standalone as well; for this use case there
is a simple configuration utility called integritysetup
(similar to veritysetup to dm-verity).
2017-05-28 09:22:17 +02:00
Milan Broz
5fdfc0b54a Fix AF prototypes and move then to af.h. 2017-04-14 13:25:21 +02:00
Milan Broz
98368c4770 Update copyright years. 2017-03-12 13:17:15 +01:00
Tobias Stoeckmann
a0587d4307 Avoid integer overflows during memory allocation.
It is possible to overflow integers during memory allocation with
insanely large "key bytes" specified in a LUKS header.

Although it could be argued to properly validate LUKS headers while
parsing them, it's still a good idea to fix any form of possible
overflow attacks against cryptsetup in these allocation functions.
2016-07-02 20:57:10 +02:00
VittGam
e7e5354332 Fix off-by-one error in maximum keyfile size.
Allow keyfiles up to DEFAULT_KEYFILE_SIZE_MAXKB * 1024 bytes in size, and not that value minus one.

Signed-off-by: Vittorio Gambaletta <git-cryptsetup@vittgam.net>
2016-04-19 03:58:10 +00:00
Milan Broz
d293de579a Fix various backward incompatibilities in password processing. 2015-11-20 09:18:31 +01:00
Milan Broz
5293f5aae1 Move terminal handling to tools wrapper. 2015-11-20 09:18:31 +01:00
Milan Broz
252cdef110 Extract keyfile read from get_key wrapper. 2015-11-20 09:18:31 +01:00
Milan Broz
7843415243 Move string_to_size to userspace tools. 2015-08-26 12:42:25 +02:00
Milan Broz
0dc245401f Allow to enter empty password through stdin pipe.
Also always use empty passsword when using null cipher in tests.
2015-07-02 08:18:12 +02:00
Milan Broz
f7b61b2617 Prevent compiler to optiize-out memset for on-stack variables.
Also see
https://cryptocoding.net/index.php/Coding_rules#Prevent_compiler_interference_with_security-critical_operations

The used code is inspired by the code in Blake2 implementation.
2015-01-11 20:26:45 +01:00
Ondrej Kozina
3cffadb508 fix possible close of unrelated fd on error path
- infd var is uninitialised on error path in case where
  maxlen is less than 1
2014-10-01 20:10:23 +02:00
Milan Broz
7b42254975 Workaround for scan-build false positive.
Also tidy code to be more readable.
2014-08-10 16:07:47 +02:00
Milan Broz
29f21208a0 Change License from GPLv2 only to GPLv2+ ("or any later").
Agreed by all copyright authors.
2012-12-29 11:33:54 +01:00
Milan Broz
83f02e6682 Add copyright line for files I have written or modified. 2012-12-21 16:40:33 +01:00