mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-06 16:30:04 +01:00
Compare commits
365 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ba577666c | ||
|
|
4e198501d7 | ||
|
|
0f03d04599 | ||
|
|
8af93e19a2 | ||
|
|
ffa035f45e | ||
|
|
3da51bba75 | ||
|
|
83c42227da | ||
|
|
a495563a35 | ||
|
|
c02c1494f7 | ||
|
|
e91b90b8c9 | ||
|
|
7c25327396 | ||
|
|
4dd568fbfc | ||
|
|
d3316ec930 | ||
|
|
b489b0aa64 | ||
|
|
2d298071e4 | ||
|
|
327ebccdb1 | ||
|
|
a6c8f974fe | ||
|
|
bcb5d150b0 | ||
|
|
640eba3569 | ||
|
|
f8db1ce650 | ||
|
|
3406a6f447 | ||
|
|
672db2c6b4 | ||
|
|
b35b98bcd9 | ||
|
|
afb7a5ce4b | ||
|
|
f3947c0109 | ||
|
|
9067054f59 | ||
|
|
3b02c1e690 | ||
|
|
945249fd02 | ||
|
|
68a140d0c5 | ||
|
|
4f223476f8 | ||
|
|
2d93638302 | ||
|
|
25129a99eb | ||
|
|
9dbce46c0f | ||
|
|
0185defb7f | ||
|
|
50412375da | ||
|
|
057c88eca9 | ||
|
|
a552ea9ac8 | ||
|
|
25e185f6f5 | ||
|
|
db09bc58fc | ||
|
|
0061ce298a | ||
|
|
c8da0a76aa | ||
|
|
7dbb47f76a | ||
|
|
d68d981f36 | ||
|
|
f65dbd5a07 | ||
|
|
2c7c527990 | ||
|
|
3cf86ec1be | ||
|
|
274c417e56 | ||
|
|
337b20a4ed | ||
|
|
35ab06c61c | ||
|
|
3e5e9eb620 | ||
|
|
e856bc37bb | ||
|
|
f594435298 | ||
|
|
a1fb77b8b3 | ||
|
|
8e3d5bbd70 | ||
|
|
443a8b806f | ||
|
|
2fc8b6a306 | ||
|
|
94f4f6b1b6 | ||
|
|
af1ce99a6f | ||
|
|
602d7f0bb0 | ||
|
|
53c4fbac2d | ||
|
|
acc846ceba | ||
|
|
89bce3d21b | ||
|
|
1de98c12a6 | ||
|
|
4d62ef49de | ||
|
|
de14f78e25 | ||
|
|
a2d33996f4 | ||
|
|
d59d935308 | ||
|
|
7c62c82c8f | ||
|
|
664f48e29d | ||
|
|
96896efed4 | ||
|
|
bdf16abc53 | ||
|
|
8030bd0593 | ||
|
|
a89e6e6e89 | ||
|
|
a5ed08f2d4 | ||
|
|
f92786a044 | ||
|
|
b282cb2366 | ||
|
|
883bde3f1b | ||
|
|
e969eba2bb | ||
|
|
3c3756fbd7 | ||
|
|
b8359b3652 | ||
|
|
75eaac3fef | ||
|
|
d70e2ba18d | ||
|
|
3a27ce636a | ||
|
|
0a951da27f | ||
|
|
be6ab40fb9 | ||
|
|
29ecd515ac | ||
|
|
0c7ce6215b | ||
|
|
ddd587d78d | ||
|
|
e6ef5bb698 | ||
|
|
b4cf5e2dab | ||
|
|
a1683189da | ||
|
|
a0fc06280e | ||
|
|
830edb22cf | ||
|
|
26bf547bbc | ||
|
|
cec31efee2 | ||
|
|
4ad075e928 | ||
|
|
10a6318b1f | ||
|
|
18528edc31 | ||
|
|
2b91d7c385 | ||
|
|
8d7235b9a9 | ||
|
|
02295bed47 | ||
|
|
0657956351 | ||
|
|
9f50fd2980 | ||
|
|
e32376acf1 | ||
|
|
8ab9c9dc68 | ||
|
|
a5363f184c | ||
|
|
e2637c5d49 | ||
|
|
4a72695241 | ||
|
|
af31af5e3d | ||
|
|
2aa0bb7eac | ||
|
|
8ae62715a8 | ||
|
|
506ba27358 | ||
|
|
4384e50578 | ||
|
|
1623ee71ab | ||
|
|
f425d07ec7 | ||
|
|
d260be02d4 | ||
|
|
4609fd87d7 | ||
|
|
9e90d91446 | ||
|
|
7bbf0796b5 | ||
|
|
fe3148f074 | ||
|
|
5e9c27118e | ||
|
|
c362ba9293 | ||
|
|
e97048dd32 | ||
|
|
5ea0ba61be | ||
|
|
7ae863e380 | ||
|
|
f238e8c075 | ||
|
|
7d9a14fd24 | ||
|
|
2f964d95d8 | ||
|
|
00f419e5ea | ||
|
|
cc698dcde3 | ||
|
|
edced6cfed | ||
|
|
4fb11976d2 | ||
|
|
68ba5b2b36 | ||
|
|
65fa22ff23 | ||
|
|
c25d81d2a1 | ||
|
|
57d16a7a55 | ||
|
|
def397d0c8 | ||
|
|
7843415243 | ||
|
|
5a8b045bdd | ||
|
|
ab62f45d57 | ||
|
|
e521edd6ca | ||
|
|
3a0293a299 | ||
|
|
8a4db1ad7b | ||
|
|
1aba9ab444 | ||
|
|
dfa2755aba | ||
|
|
6e82bdd9a5 | ||
|
|
0dc245401f | ||
|
|
a57f1b1b64 | ||
|
|
1a50fee1d0 | ||
|
|
046e0e5280 | ||
|
|
656b55cd4b | ||
|
|
8d7af433d8 | ||
|
|
dc3de39eb7 | ||
|
|
3d403a7bd0 | ||
|
|
91f6296699 | ||
|
|
bd94eb36b3 | ||
|
|
1a19329b18 | ||
|
|
78a43c053a | ||
|
|
d7d76e72f7 | ||
|
|
dd0dcc05df | ||
|
|
3be8731fef | ||
|
|
86d0ff1a2b | ||
|
|
3adfe80601 | ||
|
|
0bc437d92c | ||
|
|
6b10f30eb9 | ||
|
|
fedd5bc969 | ||
|
|
8aee4f95fb | ||
|
|
1f2d8de95f | ||
|
|
dced269426 | ||
|
|
b834a59eaf | ||
|
|
4f7b413638 | ||
|
|
e4355c2973 | ||
|
|
31a4d552a2 | ||
|
|
6d51e8ab69 | ||
|
|
8157e47ad4 | ||
|
|
62b0138dad | ||
|
|
c13a8003fa | ||
|
|
979aec773e | ||
|
|
b789b011a2 | ||
|
|
ea8864badf | ||
|
|
49335b600f | ||
|
|
7245af59d3 | ||
|
|
f7b61b2617 | ||
|
|
dc40b91cdf | ||
|
|
eccf347568 | ||
|
|
e24a72f84c | ||
|
|
2c70c057d6 | ||
|
|
f16f37233f | ||
|
|
3cffadb508 | ||
|
|
ce30d5f1fd | ||
|
|
6e0f0408a0 | ||
|
|
3d6bcae84c | ||
|
|
b8beedb621 | ||
|
|
fd5c2a5000 | ||
|
|
69bc154fca | ||
|
|
387041ccf2 | ||
|
|
64d6b339a0 | ||
|
|
4f5f1b78c4 | ||
|
|
3e886ecf57 | ||
|
|
210ea612b3 | ||
|
|
3350ff017f | ||
|
|
7b42254975 | ||
|
|
e84b1ed7c0 | ||
|
|
f3f1bfd73a | ||
|
|
89f795d7b4 | ||
|
|
c36a7968f4 | ||
|
|
3762c8b76e | ||
|
|
872becdbbd | ||
|
|
c9694437d2 | ||
|
|
64ad90f73c | ||
|
|
166d23a813 | ||
|
|
59fdf2a6bb | ||
|
|
3640eaa726 | ||
|
|
2250d5f71f | ||
|
|
d9678325a2 | ||
|
|
dc8c47d936 | ||
|
|
5b7100ff87 | ||
|
|
4afa592160 | ||
|
|
54c7a2b0aa | ||
|
|
9cabc9bf05 | ||
|
|
dfd46df8a5 | ||
|
|
25cd4f3a1d | ||
|
|
d5b594dd12 | ||
|
|
803686ea4b | ||
|
|
3add769b51 | ||
|
|
d5a72cd65a | ||
|
|
d63163e46c | ||
|
|
62d690492c | ||
|
|
54d81a6258 | ||
|
|
56679a6e4a | ||
|
|
e0788d9d61 | ||
|
|
833e066853 | ||
|
|
02f860140d | ||
|
|
027cebade3 | ||
|
|
bb8dbfdf5b | ||
|
|
8e380183f8 | ||
|
|
4f89028c67 | ||
|
|
6b4c33d3a5 | ||
|
|
7a2e6990ca | ||
|
|
98ba2f2333 | ||
|
|
4e4d933d7b | ||
|
|
91c739958c | ||
|
|
1a6e1ae918 | ||
|
|
aedf39a9ca | ||
|
|
a274cd3a74 | ||
|
|
6be21469fb | ||
|
|
e0d3ff8aeb | ||
|
|
0614ab6b07 | ||
|
|
49e55c0f42 | ||
|
|
be4edbb460 | ||
|
|
4d30237f7a | ||
|
|
a3c0f6784b | ||
|
|
6d4c2db3b1 | ||
|
|
1436f2a0a0 | ||
|
|
e6a46bf827 | ||
|
|
9563aa33c8 | ||
|
|
6225c901fe | ||
|
|
cad0cbf0c8 | ||
|
|
1fc441f091 | ||
|
|
22849ccd11 | ||
|
|
a809224ec7 | ||
|
|
ae23ecb9b2 | ||
|
|
0db77f3ace | ||
|
|
779c80c581 | ||
|
|
00ced59c1a | ||
|
|
20595f4b14 | ||
|
|
2e97d8f8e8 | ||
|
|
7effba0f71 | ||
|
|
2ad69eba90 | ||
|
|
4d218e4cbd | ||
|
|
a0346a09ce | ||
|
|
f6e85be3ed | ||
|
|
04e921846f | ||
|
|
e37f3728d7 | ||
|
|
2062ece2ab | ||
|
|
a5fa6f1015 | ||
|
|
9bdd5bf4fe | ||
|
|
110ce5607e | ||
|
|
78f938b0e9 | ||
|
|
ad2f50316f | ||
|
|
cf534f3759 | ||
|
|
75c105f853 | ||
|
|
680eb76e45 | ||
|
|
e364041b40 | ||
|
|
de37457a75 | ||
|
|
057db3b3b3 | ||
|
|
461011ad2a | ||
|
|
aa7346bb36 | ||
|
|
5206543902 | ||
|
|
7f93a49cc3 | ||
|
|
bec86e3d5a | ||
|
|
3ba95a822f | ||
|
|
486ec44c3e | ||
|
|
8dc4877697 | ||
|
|
7415c5858d | ||
|
|
8e5411f468 | ||
|
|
3bf40bb8dd | ||
|
|
79956a4d47 | ||
|
|
2d755335de | ||
|
|
d7762c09dd | ||
|
|
957201e758 | ||
|
|
004dc271a4 | ||
|
|
a9b24ccc82 | ||
|
|
c57071a43a | ||
|
|
df27f04f61 | ||
|
|
f3e398afc5 | ||
|
|
65877efe8b | ||
|
|
96acd87f0b | ||
|
|
fcb35d4e73 | ||
|
|
0d47e5eb76 | ||
|
|
f30bbbffe7 | ||
|
|
6b88461553 | ||
|
|
700b558fb6 | ||
|
|
58b5be440f | ||
|
|
626801f7df | ||
|
|
77a345d4cb | ||
|
|
18901fd501 | ||
|
|
5b86cb5cc2 | ||
|
|
ce23225e46 | ||
|
|
09c229fe6c | ||
|
|
db56125708 | ||
|
|
5736b0a114 | ||
|
|
a21c0503f8 | ||
|
|
e52d5f3d98 | ||
|
|
0e96b9d010 | ||
|
|
dcba8c28f2 | ||
|
|
da93a3320b | ||
|
|
53607a0274 | ||
|
|
67d19f3570 | ||
|
|
54c1f71bd3 | ||
|
|
a7e2809466 | ||
|
|
3f66e9fe4b | ||
|
|
f547d0fac3 | ||
|
|
cdf272315e | ||
|
|
31303718da | ||
|
|
4192bdd731 | ||
|
|
c18aa03552 | ||
|
|
b2283f045a | ||
|
|
8e3863aa20 | ||
|
|
79899badd0 | ||
|
|
691b7a63f2 | ||
|
|
154731306b | ||
|
|
d67548adfe | ||
|
|
cfeaaa02fc | ||
|
|
c5270f85d3 | ||
|
|
45931a890d | ||
|
|
1a5c169c06 | ||
|
|
d8fbf43022 | ||
|
|
3be96efe0b | ||
|
|
99a2486b09 | ||
|
|
c3c65ee864 | ||
|
|
db0f5f8d22 | ||
|
|
8b162ca258 | ||
|
|
4f990d5a74 | ||
|
|
1349efa34d | ||
|
|
cf99ecb5a9 | ||
|
|
0d818d0a92 | ||
|
|
42b0ab437a | ||
|
|
a36de633d5 | ||
|
|
8a43d49b89 | ||
|
|
ae9c9cf369 | ||
|
|
db44c27674 | ||
|
|
efa2c7b08b | ||
|
|
a9441043bc | ||
|
|
aaf0cfa3c1 |
2
AUTHORS
2
AUTHORS
@@ -1,3 +1,3 @@
|
||||
Christophe Saout <christophe@saout.de>
|
||||
Jana Saout <jana@saout.de>
|
||||
Clemens Fruhwirth <clemens@endorphin.org>
|
||||
Milan Broz <gmazyland@gmail.com>
|
||||
|
||||
@@ -3,4 +3,4 @@ Since version 1.6 this file is no longer maintained.
|
||||
See docs/*ReleaseNotes for release changes documentation.
|
||||
|
||||
See version control history for full commit messages.
|
||||
http://code.google.com/p/cryptsetup/source/list
|
||||
https://gitlab.com/cryptsetup/cryptsetup/commits/master
|
||||
|
||||
10
README
10
README
@@ -5,11 +5,11 @@ setup cryptographic volumes for dm-crypt (including LUKS extension)
|
||||
|
||||
WEB PAGE:
|
||||
|
||||
http://code.google.com/p/cryptsetup/
|
||||
https://gitlab.com/cryptsetup/cryptsetup/
|
||||
|
||||
FAQ:
|
||||
|
||||
http://code.google.com/p/cryptsetup/wiki/FrequentlyAskedQuestions
|
||||
https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions
|
||||
|
||||
MAILING LIST:
|
||||
|
||||
@@ -18,12 +18,12 @@ MAILING LIST:
|
||||
|
||||
DOWNLOAD:
|
||||
|
||||
http://code.google.com/p/cryptsetup/downloads/
|
||||
https://www.kernel.org/pub/linux/utils/cryptsetup/
|
||||
|
||||
SOURCE CODE:
|
||||
|
||||
URL: http://code.google.com/p/cryptsetup/source/browse/
|
||||
Checkout: git clone https://code.google.com/p/cryptsetup/
|
||||
URL: https://gitlab.com/cryptsetup/cryptsetup/tree/master
|
||||
Checkout: git clone https://gitlab.com/cryptsetup/cryptsetup.git
|
||||
|
||||
NLS (PO TRANSLATIONS):
|
||||
|
||||
|
||||
78
README.md
Normal file
78
README.md
Normal file
@@ -0,0 +1,78 @@
|
||||

|
||||
|
||||
What the ...?
|
||||
=============
|
||||
**Cryptsetup** is utility used to conveniently setup disk encryption based
|
||||
on [DMCrypt](https://gitlab.com/cryptsetup/cryptsetup/wikis/DMCrypt) kernel module.
|
||||
|
||||
These include **plain** **dm-crypt** volumes, **LUKS** volumes, **loop-AES**
|
||||
and **TrueCrypt** (including **VeraCrypt** extension) format.
|
||||
|
||||
Project also includes **veritysetup** utility used to conveniently setup
|
||||
[DMVerity](https://gitlab.com/cryptsetup/cryptsetup/wikis/DMVerity) block integrity checking kernel module.
|
||||
|
||||
LUKS Design
|
||||
-----------
|
||||
**LUKS** is the standard for Linux hard disk encryption. By providing a standard on-disk-format, it does not
|
||||
only facilitate compatibility among distributions, but also provides secure management of multiple user passwords.
|
||||
In contrast to existing solution, LUKS stores all setup necessary setup information in the partition header,
|
||||
enabling the user to transport or migrate his data seamlessly.
|
||||
|
||||
Why LUKS?
|
||||
---------
|
||||
* compatiblity via standardization,
|
||||
* secure against low entropy attacks,
|
||||
* support for multiple keys,
|
||||
* effective passphrase revocation,
|
||||
* free.
|
||||
|
||||
[Project home page](https://gitlab.com/cryptsetup/cryptsetup/).
|
||||
-----------------
|
||||
|
||||
[Frequently asked questions (FAQ)](https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions)
|
||||
--------------------------------
|
||||
|
||||
Download
|
||||
--------
|
||||
All release tarballs and release notes are hosted on [kernel.org](https://www.kernel.org/pub/linux/utils/cryptsetup/).
|
||||
|
||||
**The latest cryptsetup version is 1.7.4**
|
||||
* [cryptsetup-1.7.4.tar.xz](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/cryptsetup-1.7.4.tar.xz)
|
||||
* Signature [cryptsetup-1.7.4.tar.sign](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/cryptsetup-1.7.4.tar.sign)
|
||||
_(You need to decompress file first to check signature.)_
|
||||
* [Cryptsetup 1.7.4 Release Notes](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/v1.7.4-ReleaseNotes).
|
||||
|
||||
Previous versions
|
||||
* [Version 1.7.3](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/cryptsetup-1.7.3.tar.xz) -
|
||||
[Signature](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/cryptsetup-1.7.3.tar.sign) -
|
||||
[Release Notes](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/v1.7.3-ReleaseNotes).
|
||||
* [Version 1.7.2](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/cryptsetup-1.7.2.tar.xz) -
|
||||
[Signature](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/cryptsetup-1.7.2.tar.sign) -
|
||||
[Release Notes](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/v1.7.2-ReleaseNotes).
|
||||
* [Version 1.7.1](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/cryptsetup-1.7.1.tar.xz) -
|
||||
[Signature](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/cryptsetup-1.7.1.tar.sign) -
|
||||
[Release Notes](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/v1.7.1-ReleaseNotes).
|
||||
* [Version 1.7.0](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/cryptsetup-1.7.0.tar.xz) -
|
||||
[Signature](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/cryptsetup-1.7.0.tar.sign) -
|
||||
[Release Notes](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/v1.7.0-ReleaseNotes).
|
||||
|
||||
Source and API docs
|
||||
-------------------
|
||||
For development version code, please refer to [source](https://gitlab.com/cryptsetup/cryptsetup/tree/master) page,
|
||||
mirror on [kernel.org](https://git.kernel.org/cgit/utils/cryptsetup/cryptsetup.git/) or [GitHub](https://github.com/mbroz/cryptsetup).
|
||||
|
||||
For libcryptsetup documentation see [libcryptsetup API](https://gitlab.com/cryptsetup/cryptsetup/wikis/API/index.html) page.
|
||||
|
||||
The libcryptsetup API/ABI changes are tracked in [compatibility report](https://gitlab.com/cryptsetup/cryptsetup/wikis/ABI-tracker/timeline/libcryptsetup/index.html).
|
||||
|
||||
NLS PO files are maintained by [TranslationProject](http://translationproject.org/domain/cryptsetup.html).
|
||||
|
||||
Help!
|
||||
-----
|
||||
Please always read [FAQ](https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions) first.
|
||||
For cryptsetup and LUKS related questions, please use the dm-crypt mailing list, [dm-crypt@saout.de](mailto:dm-crypt@saout.de).
|
||||
|
||||
If you want to subscribe just send an empty mail to [dm-crypt-subscribe@saout.de](mailto:dm-crypt-subscribe@saout.de).
|
||||
|
||||
You can also browse [list archive](http://www.saout.de/pipermail/dm-crypt/) or read it through
|
||||
[web interface](http://news.gmane.org/gmane.linux.kernel.device-mapper.dm-crypt).
|
||||
4
TODO
4
TODO
@@ -4,5 +4,5 @@ Version 1.7:
|
||||
- TRIM for keyslots
|
||||
- Do we need crypt_data_path() - path to data device (if differs)?
|
||||
- Resync ETA time is not accurate, calculate it better (last minute window?).
|
||||
- Crypt benchmark cannot ttest ECB mode.
|
||||
- Log doesn't work yet in early binary start (FIPS message).
|
||||
- Extend existing LUKS header to use another KDF? (https://password-hashing.net/)
|
||||
- Fix all crazy automake warnings (or switch to Cmake).
|
||||
|
||||
@@ -78,7 +78,7 @@ autopoint --force $AP_OPTS
|
||||
libtoolize --force --copy
|
||||
aclocal -I m4 $AL_OPTS
|
||||
autoheader $AH_OPTS
|
||||
automake --add-missing --gnu $AM_OPTS
|
||||
automake --add-missing --copy --gnu $AM_OPTS
|
||||
autoconf $AC_OPTS
|
||||
|
||||
if test x$NOCONFIGURE = x; then
|
||||
|
||||
127
configure.ac
127
configure.ac
@@ -1,17 +1,22 @@
|
||||
AC_PREREQ([2.67])
|
||||
AC_INIT([cryptsetup],[1.6.1])
|
||||
AC_INIT([cryptsetup],[1.7.5])
|
||||
|
||||
dnl library version from <major>.<minor>.<release>[-<suffix>]
|
||||
LIBCRYPTSETUP_VERSION=$(echo $PACKAGE_VERSION | cut -f1 -d-)
|
||||
LIBCRYPTSETUP_VERSION_INFO=9:0:5
|
||||
dnl library file name for FIPS selfcheck
|
||||
LIBCRYPTSETUP_VERSION_FIPS="libcryptsetup.so.4"
|
||||
LIBCRYPTSETUP_VERSION_INFO=11:0:7
|
||||
|
||||
AM_SILENT_RULES([yes])
|
||||
AC_CONFIG_SRCDIR(src/cryptsetup.c)
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
|
||||
AC_CONFIG_HEADERS([config.h:config.h.in])
|
||||
AM_INIT_AUTOMAKE(dist-bzip2)
|
||||
|
||||
# We do not want to run test in parallel. Really.
|
||||
# http://lists.gnu.org/archive/html/automake/2013-01/msg00060.html
|
||||
|
||||
# For old automake use this
|
||||
#AM_INIT_AUTOMAKE(dist-xz)
|
||||
AM_INIT_AUTOMAKE([dist-xz 1.12 serial-tests])
|
||||
|
||||
if test "x$prefix" = "xNONE"; then
|
||||
sysconfdir=/etc
|
||||
@@ -32,7 +37,7 @@ PKG_PROG_PKG_CONFIG
|
||||
AC_HEADER_DIRENT
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS(fcntl.h malloc.h inttypes.h sys/ioctl.h sys/mman.h \
|
||||
ctype.h unistd.h locale.h)
|
||||
sys/sysmacros.h ctype.h unistd.h locale.h byteswap.h endian.h)
|
||||
|
||||
AC_CHECK_HEADERS(uuid/uuid.h,,[AC_MSG_ERROR([You need the uuid library.])])
|
||||
AC_CHECK_HEADER(libdevmapper.h,,[AC_MSG_ERROR([You need the device-mapper library.])])
|
||||
@@ -42,14 +47,20 @@ AC_CHECK_LIB(uuid, uuid_clear, ,[AC_MSG_ERROR([You need the uuid library.])])
|
||||
AC_SUBST(UUID_LIBS, $LIBS)
|
||||
LIBS=$saved_LIBS
|
||||
|
||||
AC_CHECK_FUNCS([posix_memalign])
|
||||
AC_SEARCH_LIBS([clock_gettime],[rt posix4])
|
||||
AC_CHECK_FUNCS([posix_memalign clock_gettime])
|
||||
|
||||
if test "x$enable_largefile" = "xno" ; then
|
||||
AC_MSG_ERROR([Building with --disable-largefile is not supported, it can cause data corruption.])
|
||||
fi
|
||||
|
||||
AC_C_CONST
|
||||
AC_C_BIGENDIAN
|
||||
AC_TYPE_OFF_T
|
||||
AC_SYS_LARGEFILE
|
||||
|
||||
AC_FUNC_FSEEKO
|
||||
AC_PROG_GCC_TRADITIONAL
|
||||
AC_FUNC_STRERROR_R
|
||||
|
||||
dnl ==========================================================================
|
||||
|
||||
@@ -65,25 +76,17 @@ AC_SUBST(POPT_LIBS, $LIBS)
|
||||
LIBS=$saved_LIBS
|
||||
|
||||
dnl ==========================================================================
|
||||
dnl FIPS extensions
|
||||
dnl FIPS extensions (only for RHEL)
|
||||
AC_ARG_ENABLE([fips], AS_HELP_STRING([--enable-fips],[enable FIPS mode restrictions]),
|
||||
[with_fips=$enableval],
|
||||
[with_fips=no])
|
||||
|
||||
if test "x$with_fips" = "xyes"; then
|
||||
AC_DEFINE(ENABLE_FIPS, 1, [Enable FIPS mode restrictions])
|
||||
AC_DEFINE_UNQUOTED(LIBCRYPTSETUP_VERSION_FIPS, ["$LIBCRYPTSETUP_VERSION_FIPS"],
|
||||
[library file name for FIPS selfcheck])
|
||||
|
||||
if test "x$enable_static" = "xyes" -o "x$enable_static_cryptsetup" = "xyes" ; then
|
||||
AC_MSG_ERROR([Static build is not compatible with FIPS.])
|
||||
fi
|
||||
|
||||
saved_LIBS=$LIBS
|
||||
AC_CHECK_LIB(fipscheck, FIPSCHECK_verify, ,[AC_MSG_ERROR([You need the fipscheck library.])])
|
||||
AC_SUBST(FIPSCHECK_LIBS, $LIBS)
|
||||
LIBS=$saved_LIBS
|
||||
|
||||
fi
|
||||
|
||||
AC_DEFUN([NO_FIPS], [
|
||||
@@ -94,12 +97,14 @@ AC_DEFUN([NO_FIPS], [
|
||||
|
||||
dnl ==========================================================================
|
||||
dnl pwquality library (cryptsetup CLI only)
|
||||
AC_ARG_ENABLE([pwquality], AS_HELP_STRING([--enable-pwquality],[enable password quality checking]),
|
||||
[with_pwquality=$enableval],
|
||||
[with_pwquality=no])
|
||||
AC_ARG_ENABLE([pwquality],
|
||||
AS_HELP_STRING([--enable-pwquality],
|
||||
[enable password quality checking using pwquality library]),
|
||||
[with_pwquality=$enableval],
|
||||
[with_pwquality=no])
|
||||
|
||||
if test "x$with_pwquality" = "xyes"; then
|
||||
AC_DEFINE(ENABLE_PWQUALITY, 1, [Enable password quality checking])
|
||||
AC_DEFINE(ENABLE_PWQUALITY, 1, [Enable password quality checking using pwquality library])
|
||||
PKG_CHECK_MODULES([PWQUALITY], [pwquality >= 1.0.0],,
|
||||
AC_MSG_ERROR([You need pwquality library.]))
|
||||
|
||||
@@ -107,6 +112,31 @@ if test "x$with_pwquality" = "xyes"; then
|
||||
PWQUALITY_STATIC_LIBS="$PWQUALITY_LIBS -lcrack -lz"
|
||||
fi
|
||||
|
||||
dnl ==========================================================================
|
||||
dnl passwdqc library (cryptsetup CLI only)
|
||||
AC_ARG_ENABLE([passwdqc],
|
||||
AS_HELP_STRING([--enable-passwdqc@<:@=CONFIG_PATH@:>@],
|
||||
[enable password quality checking using passwdqc library (optionally with CONFIG_PATH)]),
|
||||
[enable_passwdqc=$enableval],
|
||||
[enable_passwdqc=no])
|
||||
|
||||
case "$enable_passwdqc" in
|
||||
yes|no) use_passwdqc_config="" ;;
|
||||
/*) use_passwdqc_config="$enable_passwdqc"; enable_passwdqc=yes ;;
|
||||
*) AC_MSG_ERROR([Unrecognized --enable-passwdqc parameter.]) ;;
|
||||
esac
|
||||
AC_DEFINE_UNQUOTED([PASSWDQC_CONFIG_FILE], ["$use_passwdqc_config"], [passwdqc library config file])
|
||||
|
||||
if test "x$enable_passwdqc" = "xyes"; then
|
||||
AC_DEFINE(ENABLE_PASSWDQC, 1, [Enable password quality checking using passwdqc library])
|
||||
|
||||
PASSWDQC_LIBS="-lpasswdqc"
|
||||
fi
|
||||
|
||||
if test "x$with_pwquality$enable_passwdqc" = "xyesyes"; then
|
||||
AC_MSG_ERROR([--enable-pwquality and --enable-passwdqc are mutually incompatible.])
|
||||
fi
|
||||
|
||||
dnl ==========================================================================
|
||||
dnl Crypto backend functions
|
||||
|
||||
@@ -118,10 +148,22 @@ AC_DEFUN([CONFIGURE_GCRYPT], [
|
||||
fi
|
||||
dnl Check if we can use gcrypt PBKDF2 (1.6.0 supports empty password)
|
||||
AC_ARG_ENABLE([gcrypt-pbkdf2], AS_HELP_STRING([--enable-gcrypt-pbkdf2],[force enable internal gcrypt PBKDF2]),
|
||||
[use_internal_pbkdf2=0],
|
||||
[AM_PATH_LIBGCRYPT([1.6.0], [use_internal_pbkdf2=0], [use_internal_pbkdf2=1])])
|
||||
if test "x$enableval" = "xyes"; then
|
||||
[use_internal_pbkdf2=0]
|
||||
else
|
||||
[use_internal_pbkdf2=1]
|
||||
fi,
|
||||
[AM_PATH_LIBGCRYPT([1.6.1], [use_internal_pbkdf2=0], [use_internal_pbkdf2=1])])
|
||||
AM_PATH_LIBGCRYPT($GCRYPT_REQ_VERSION,,[AC_MSG_ERROR([You need the gcrypt library.])])
|
||||
|
||||
AC_MSG_CHECKING([if internal cryptsetup PBKDF2 is compiled-in])
|
||||
if test $use_internal_pbkdf2 = 0; then
|
||||
AC_MSG_RESULT([no])
|
||||
else
|
||||
AC_MSG_RESULT([yes])
|
||||
NO_FIPS([])
|
||||
fi
|
||||
|
||||
if test x$enable_static_cryptsetup = xyes; then
|
||||
saved_LIBS=$LIBS
|
||||
LIBS="$saved_LIBS $LIBGCRYPT_LIBS -static"
|
||||
@@ -149,8 +191,8 @@ AC_DEFUN([CONFIGURE_OPENSSL], [
|
||||
if test x$enable_static_cryptsetup = xyes; then
|
||||
saved_PKG_CONFIG=$PKG_CONFIG
|
||||
PKG_CONFIG="$PKG_CONFIG --static"
|
||||
PKG_CHECK_MODULES([OPENSSL], [openssl])
|
||||
CRYPTO_STATIC_LIBS=$OPENSSL_LIBS
|
||||
PKG_CHECK_MODULES([OPENSSL_STATIC], [openssl])
|
||||
CRYPTO_STATIC_LIBS=$OPENSSL_STATIC_LIBS
|
||||
PKG_CONFIG=$saved_PKG_CONFIG
|
||||
fi
|
||||
NO_FIPS([])
|
||||
@@ -192,13 +234,13 @@ AC_DEFUN([CONFIGURE_NETTLE], [
|
||||
[AC_MSG_ERROR([You need Nettle cryptographic library.])])
|
||||
|
||||
saved_LIBS=$LIBS
|
||||
AC_CHECK_LIB(nettle, nettle_ripemd160_init,,
|
||||
[AC_MSG_ERROR([You need Nettle library version 2.4 or more recent.])])
|
||||
AC_CHECK_LIB(nettle, nettle_pbkdf2_hmac_sha256,,
|
||||
[AC_MSG_ERROR([You need Nettle library version 2.6 or more recent.])])
|
||||
CRYPTO_LIBS=$LIBS
|
||||
LIBS=$saved_LIBS
|
||||
|
||||
CRYPTO_STATIC_LIBS=$CRYPTO_LIBS
|
||||
use_internal_pbkdf2=1
|
||||
use_internal_pbkdf2=0
|
||||
NO_FIPS([])
|
||||
])
|
||||
|
||||
@@ -330,13 +372,14 @@ AC_SUBST([DEVMAPPER_STATIC_LIBS])
|
||||
AC_SUBST([PWQUALITY_LIBS])
|
||||
AC_SUBST([PWQUALITY_STATIC_LIBS])
|
||||
|
||||
AC_SUBST([PASSWDQC_LIBS])
|
||||
|
||||
AC_SUBST([CRYPTO_CFLAGS])
|
||||
AC_SUBST([CRYPTO_LIBS])
|
||||
AC_SUBST([CRYPTO_STATIC_LIBS])
|
||||
|
||||
AC_SUBST([LIBCRYPTSETUP_VERSION])
|
||||
AC_SUBST([LIBCRYPTSETUP_VERSION_INFO])
|
||||
AC_SUBST([LIBCRYPTSETUP_VERSION_FIPS])
|
||||
|
||||
dnl ==========================================================================
|
||||
AC_ARG_ENABLE([dev-random], AS_HELP_STRING([--enable-dev-random],
|
||||
@@ -367,15 +410,27 @@ AC_ARG_ENABLE([python], AS_HELP_STRING([--enable-python],[enable Python bindings
|
||||
[with_python=$enableval],
|
||||
[with_python=no])
|
||||
|
||||
if test "x$with_python" = "xyes"; then
|
||||
AM_PATH_PYTHON([2.4])
|
||||
AC_ARG_WITH([python_version],
|
||||
AS_HELP_STRING([--with-python_version=VERSION], [required Python version [2.6]]),
|
||||
[PYTHON_VERSION=$withval], [PYTHON_VERSION=2.6])
|
||||
|
||||
if ! test -x "$PYTHON-config" ; then
|
||||
AC_MSG_ERROR([Cannot find python development packages to build bindings])
|
||||
if test "x$with_python" = "xyes"; then
|
||||
AM_PATH_PYTHON([$PYTHON_VERSION])
|
||||
|
||||
AC_PATH_PROGS([PYTHON_CONFIG], [python${PYTHON_VERSION}-config python-config], [no])
|
||||
if test "${PYTHON_CONFIG}" = "no"; then
|
||||
AC_MSG_ERROR([cannot find python${PYTHON_VERSION}-config or python-config in PATH])
|
||||
fi
|
||||
|
||||
PYTHON_INCLUDES=$($PYTHON-config --includes)
|
||||
AC_MSG_CHECKING(for python headers using $PYTHON_CONFIG --includes)
|
||||
PYTHON_INCLUDES=$($PYTHON_CONFIG --includes)
|
||||
AC_MSG_RESULT($PYTHON_INCLUDES)
|
||||
AC_SUBST(PYTHON_INCLUDES)
|
||||
|
||||
AC_MSG_CHECKING(for python libraries using $PYTHON_CONFIG --libs)
|
||||
PYTHON_LIBS=$($PYTHON_CONFIG --libs)
|
||||
AC_MSG_RESULT($PYTHON_LIBS)
|
||||
AC_SUBST(PYTHON_LIBS)
|
||||
fi
|
||||
AM_CONDITIONAL([PYTHON_CRYPTSETUP], [test "x$with_python" = "xyes"])
|
||||
|
||||
@@ -385,11 +440,11 @@ CS_STR_WITH([plain-cipher], [cipher for plain mode], [aes])
|
||||
CS_STR_WITH([plain-mode], [cipher mode for plain mode], [cbc-essiv:sha256])
|
||||
CS_NUM_WITH([plain-keybits],[key length in bits for plain mode], [256])
|
||||
|
||||
CS_STR_WITH([luks1-hash], [hash function for LUKS1 header], [sha1])
|
||||
CS_STR_WITH([luks1-hash], [hash function for LUKS1 header], [sha256])
|
||||
CS_STR_WITH([luks1-cipher], [cipher for LUKS1], [aes])
|
||||
CS_STR_WITH([luks1-mode], [cipher mode for LUKS1], [xts-plain64])
|
||||
CS_NUM_WITH([luks1-keybits],[key length in bits for LUKS1], [256])
|
||||
CS_NUM_WITH([luks1-iter-time],[PBKDF2 iteration time for LUKS1 (in ms)], [1000])
|
||||
CS_NUM_WITH([luks1-iter-time],[PBKDF2 iteration time for LUKS1 (in ms)], [2000])
|
||||
|
||||
CS_STR_WITH([loopaes-cipher], [cipher for loop-AES mode], [aes])
|
||||
CS_NUM_WITH([loopaes-keybits],[key length in bits for loop-AES mode], [256])
|
||||
|
||||
@@ -834,16 +834,16 @@
|
||||
* lib/utils.c: Add read|write_blockwise functions, to use in
|
||||
O_DIRECT file accesses.
|
||||
|
||||
2004-03-11 Thursday 15:52 Christophe Saout <christophe@saout.de>
|
||||
2004-03-11 Thursday 15:52 Jana Saout <jana@saout.de>
|
||||
|
||||
* lib/blockdev.h: BLKGETSIZE64 really uses size_t as third
|
||||
argument, the rest is wrong.
|
||||
|
||||
2004-03-10 Wednesday 17:50 Christophe Saout <christophe@saout.de>
|
||||
2004-03-10 Wednesday 17:50 Jana Saout <jana@saout.de>
|
||||
|
||||
* lib/: libcryptsetup.h, libdevmapper.c: Small fixes.
|
||||
|
||||
2004-03-09 Tuesday 21:41 Christophe Saout <christophe@saout.de>
|
||||
2004-03-09 Tuesday 21:41 Jana Saout <jana@saout.de>
|
||||
|
||||
* lib/internal.h, lib/libcryptsetup.h, lib/libdevmapper.c,
|
||||
lib/setup.c, po/de.po, src/cryptsetup.c: Added internal flags to
|
||||
@@ -851,7 +851,7 @@
|
||||
add a function to free the memory. Also add a readonly flag to
|
||||
libcryptsetup.
|
||||
|
||||
2004-03-09 Tuesday 16:03 Christophe Saout <christophe@saout.de>
|
||||
2004-03-09 Tuesday 16:03 Jana Saout <jana@saout.de>
|
||||
|
||||
* ChangeLog, configure.in, setup-gettext, lib/Makefile.am,
|
||||
lib/backends.c, lib/blockdev.h, lib/gcrypt.c, lib/internal.h,
|
||||
@@ -859,7 +859,7 @@
|
||||
lib/utils.c, po/de.po, src/Makefile.am, src/cryptsetup.c: More
|
||||
reorganization work.
|
||||
|
||||
2004-03-08 Monday 01:38 Christophe Saout <christophe@saout.de>
|
||||
2004-03-08 Monday 01:38 Jana Saout <jana@saout.de>
|
||||
|
||||
* ChangeLog, Makefile.am, acinclude.m4, configure.in,
|
||||
lib/Makefile.am, lib/backends.c, lib/blockdev.h, lib/gcrypt.c,
|
||||
@@ -867,19 +867,19 @@
|
||||
src/Makefile.am: BLKGETSIZE64 fixes and started modularity
|
||||
enhancements
|
||||
|
||||
2004-03-04 Thursday 21:06 Christophe Saout <christophe@saout.de>
|
||||
2004-03-04 Thursday 21:06 Jana Saout <jana@saout.de>
|
||||
|
||||
* Makefile.am, po/de.po, src/cryptsetup.c, src/cryptsetup.h: First
|
||||
backward compatible working version.
|
||||
|
||||
2004-03-04 Thursday 00:42 Christophe Saout <christophe@saout.de>
|
||||
2004-03-04 Thursday 00:42 Jana Saout <jana@saout.de>
|
||||
|
||||
* NEWS, AUTHORS, ChangeLog, Makefile.am, README, autogen.sh,
|
||||
configure.in, setup-gettext, po/ChangeLog, po/LINGUAS,
|
||||
po/POTFILES.in, po/de.po, src/cryptsetup.c, src/cryptsetup.h,
|
||||
src/Makefile.am (utags: initial): Initial checkin.
|
||||
|
||||
2004-03-04 Thursday 00:42 Christophe Saout <christophe@saout.de>
|
||||
2004-03-04 Thursday 00:42 Jana Saout <jana@saout.de>
|
||||
|
||||
* NEWS, AUTHORS, ChangeLog, Makefile.am, README, autogen.sh,
|
||||
configure.in, setup-gettext, po/ChangeLog, po/LINGUAS,
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
* in a persistent way on the device. Keyslot area is an array beyond LUKS header, where
|
||||
* volume key is stored in the encrypted form using user input passphrase. For more info about
|
||||
* LUKS keyslots and how it's actually protected, please look at
|
||||
* <A HREF="http://code.google.com/p/cryptsetup/wiki/Specification">LUKS specification</A>.
|
||||
* <A HREF="https://gitlab.com/cryptsetup/cryptsetup/wikis/Specification">LUKS specification</A>.
|
||||
* There are two basic methods to create a new keyslot:
|
||||
*
|
||||
* @subsection ckeyslot_vol crypt_keyslot_add_by_volume_key()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* An example of using logging through libcryptsetup API
|
||||
*
|
||||
* Copyright (C) 2011, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2011-2017, Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* An example of using LUKS device through libcryptsetup API
|
||||
*
|
||||
* Copyright (C) 2011, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2011-2017, Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
||||
Binary file not shown.
25
docs/v1.6.2-ReleaseNotes
Normal file
25
docs/v1.6.2-ReleaseNotes
Normal file
@@ -0,0 +1,25 @@
|
||||
Cryptsetup 1.6.2 Release Notes
|
||||
==============================
|
||||
|
||||
Changes since version 1.6.1
|
||||
|
||||
* Print error and fail if more device arguments are present for isLuks command.
|
||||
|
||||
* Fix cipher specification string parsing (found by gcc -fsanitize=address option).
|
||||
|
||||
* Try to map TCRYPT system encryption through partition
|
||||
(allows to activate mapping when other partition on the same device is mounted).
|
||||
|
||||
* Print a warning if system encryption is used and device is a partition.
|
||||
(TCRYPT system encryption uses whole device argument.)
|
||||
|
||||
* Disallow explicit small payload offset for LUKS detached header.
|
||||
LUKS detached header only allows data payload 0 (whole data device is used)
|
||||
or explicit offset larger than header + keyslots size.
|
||||
|
||||
* Fix boundary condition for verity device that caused failure for certain device sizes.
|
||||
|
||||
* Various fixes to documentation, including update FAQ, default modes
|
||||
and TCRYPT description.
|
||||
|
||||
* Workaround for some recent changes in automake (serial-tests).
|
||||
50
docs/v1.6.3-ReleaseNotes
Normal file
50
docs/v1.6.3-ReleaseNotes
Normal file
@@ -0,0 +1,50 @@
|
||||
Cryptsetup 1.6.3 Release Notes
|
||||
==============================
|
||||
|
||||
Changes since version 1.6.2
|
||||
|
||||
* Fix cryptsetup reencryption tool to work properly
|
||||
with devices using 4kB sectors.
|
||||
|
||||
* Always use page size if running through loop device,
|
||||
this fixes failures for external LUKS header and
|
||||
filesystem requiring 4kB block size.
|
||||
|
||||
* Fix TCRYPT system encryption mapping for multiple partitions.
|
||||
Since this commit, one can use partition directly as device parameter.
|
||||
If you need to activate such partition from image in file,
|
||||
please first use map partitioned loop device (losetup -P)
|
||||
on image.
|
||||
(Cryptsetup require partition offsets visible in kernel sysfs
|
||||
in this mode.)
|
||||
|
||||
* Support activation of old TrueCrypt containers using CBC mode
|
||||
and whitening (created in TrueCrypt version < 4.1).
|
||||
This requires Linux kernel 3.13 or later.
|
||||
(Containers with cascade CBC ciphers are not supported.)
|
||||
|
||||
* Properly display keys in dump --dump-master-key command
|
||||
for TrueCrypt CBC containers.
|
||||
|
||||
* Rewrite cipher benchmark loop which was unreliable
|
||||
on very fast machines.
|
||||
|
||||
* Add warning if LUKS device was activated using non-cryptsetup
|
||||
library which did not set UUID properly (e.g. cryptmount).
|
||||
(Some commands, like luksSuspend, are not available then.)
|
||||
|
||||
* Support length limitation also for plain (no hash) length.
|
||||
This can be used for mapping problematic cryptosystems which
|
||||
wipes some key (losetup sometimes set last 32 byte to zero,
|
||||
which can be now configured as --hash plain:31 parameter).
|
||||
|
||||
* Fix hash limit if parameter is not a number.
|
||||
(The whole key was set to zero instead of command failure.)
|
||||
|
||||
* Unify --key-slot behavior in cryptsetup_reencrypt tool.
|
||||
|
||||
* Update dracut example scripts for system reencryption on first boot.
|
||||
|
||||
* Add command line option --tcrypt-backup to access TCRYPT backup header.
|
||||
|
||||
* Fix static compilation with OpenSSL.
|
||||
57
docs/v1.6.4-ReleaseNotes
Normal file
57
docs/v1.6.4-ReleaseNotes
Normal file
@@ -0,0 +1,57 @@
|
||||
Cryptsetup 1.6.4 Release Notes
|
||||
==============================
|
||||
|
||||
Changes since version 1.6.3
|
||||
|
||||
* Implement new erase (with alias luksErase) command.
|
||||
|
||||
The erase cryptsetup command can be used to permanently erase
|
||||
all keyslots and make the LUKS container inaccessible.
|
||||
(The only way to unlock such device is to use LUKS header backup
|
||||
created before erase command was used.)
|
||||
|
||||
You do not need to provide any password for this operation.
|
||||
|
||||
This operation is irreversible.
|
||||
|
||||
* Add internal "whirlpool_gcryptbug hash" for accessing flawed
|
||||
Whirlpool hash in gcrypt (requires gcrypt 1.6.1 or above).
|
||||
|
||||
The gcrypt version of Whirlpool hash algorithm was flawed in some
|
||||
situations.
|
||||
|
||||
This means that if you used Whirlpool in LUKS header and upgraded
|
||||
to new gcrypt library your LUKS container become inaccessible.
|
||||
|
||||
Please refer to cryptsetup FAQ for detail how to fix this situation.
|
||||
|
||||
* Allow to use --disable-gcrypt-pbkdf2 during configuration
|
||||
to force use internal PBKDF2 code.
|
||||
|
||||
* Require gcrypt 1.6.1 for imported implementation of PBKDF2
|
||||
(PBKDF2 in gcrypt 1.6.0 is too slow).
|
||||
|
||||
* Add --keep-key to cryptsetup-reencrypt.
|
||||
|
||||
This allows change of LUKS header hash (and iteration count) without
|
||||
the need to reencrypt the whole data area.
|
||||
(Reencryption of LUKS header only without master key change.)
|
||||
|
||||
* By default verify new passphrase in luksChangeKey and luksAddKey
|
||||
commands (if input is from terminal).
|
||||
|
||||
* Fix memory leak in Nettle crypto backend.
|
||||
|
||||
* Support --tries option even for TCRYPT devices in cryptsetup.
|
||||
|
||||
* Support --allow-discards option even for TCRYPT devices.
|
||||
(Note that this could destroy hidden volume and it is not suggested
|
||||
by original TrueCrypt security model.)
|
||||
|
||||
* Link against -lrt for clock_gettime to fix undefined reference
|
||||
to clock_gettime error (introduced in 1.6.2).
|
||||
|
||||
* Fix misleading error message when some algorithms are not available.
|
||||
|
||||
* Count system time in PBKDF2 benchmark if kernel returns no self usage info.
|
||||
(Workaround to broken getrusage() syscall with some hypervisors.)
|
||||
54
docs/v1.6.5-ReleaseNotes
Normal file
54
docs/v1.6.5-ReleaseNotes
Normal file
@@ -0,0 +1,54 @@
|
||||
Cryptsetup 1.6.5 Release Notes
|
||||
==============================
|
||||
|
||||
Changes since version 1.6.4
|
||||
|
||||
* Allow LUKS header operation handling without requiring root privilege.
|
||||
It means that you can manipulate with keyslots as a regular user, only
|
||||
write access to device (or image) is required.
|
||||
|
||||
This requires kernel crypto wrapper (similar to TrueCrypt device handling)
|
||||
to be available (CRYPTO_USER_API_SKCIPHER kernel option).
|
||||
If this kernel interface is not available, code fallbacks to old temporary
|
||||
keyslot device creation (where root privilege is required).
|
||||
|
||||
Note that activation, deactivation, resize and suspend operations still
|
||||
need root privilege (limitation of kernel device-mapper backend).
|
||||
|
||||
* Fix internal PBKDF2 key derivation function implementation for alternative
|
||||
crypto backends (kernel, NSS) which do not support PBKDF2 directly and have
|
||||
issues with longer HMAC keys.
|
||||
|
||||
This fixes the problem for long keyfiles where either calculation is too slow
|
||||
(because of internal rehashing in every iteration) or there is a limit
|
||||
(kernel backend seems to not support HMAC key longer than 20480 bytes).
|
||||
|
||||
(Note that for recent version of gcrypt, nettle or openssl the internal
|
||||
PBKDF2 code is not compiled in and crypto library internal functions are
|
||||
used instead.)
|
||||
|
||||
* Support for Python3 for simple Python binding.
|
||||
Python >= 2.6 is now required. You can set Python compiled version by setting
|
||||
--with-python_version configure option (together with --enable-python).
|
||||
|
||||
* Use internal PBKDF2 in Nettle library for Nettle crypto backend.
|
||||
Cryptsetup compilation requires Nettle >= 2.6 (if using Nettle crypto backend).
|
||||
|
||||
* Allow simple status of crypt device without providing metadata header.
|
||||
The command "cryptsetup status" will print basic info, even if you
|
||||
do not provide detached header argument.
|
||||
|
||||
* Allow to specify ECB mode in cryptsetup benchmark.
|
||||
|
||||
* Add some LUKS images for regression testing.
|
||||
Note that if image with Whirlpool fails, the most probable cause is that
|
||||
you have old gcrypt library with flawed whirlpool hash.
|
||||
Read FAQ section 8.3 for more info.
|
||||
|
||||
Cryptsetup API NOTE:
|
||||
The direct terminal handling for passphrase entry will be removed from
|
||||
libcryptsetup in next major version (application should handle it itself).
|
||||
|
||||
It means that you have to always either provide password in buffer or set
|
||||
your own password callback function trhough crypt_set_password_callback().
|
||||
See API documentation (or libcryptsetup.h) for more info.
|
||||
29
docs/v1.6.6-ReleaseNotes
Normal file
29
docs/v1.6.6-ReleaseNotes
Normal file
@@ -0,0 +1,29 @@
|
||||
Cryptsetup 1.6.6 Release Notes
|
||||
==============================
|
||||
|
||||
Changes since version 1.6.5
|
||||
|
||||
* LUKS: Fix keyslot device access for devices which
|
||||
do not support direct IO operations. (Regression in 1.6.5.)
|
||||
|
||||
* LUKS: Fallback to old temporary keyslot device mapping method
|
||||
if hash (for ESSIV) is not supported by userspace crypto
|
||||
library. (Regression in 1.6.5.)
|
||||
|
||||
* Properly activate device with discard (TRIM for SSDs)
|
||||
if requested even if dm_crypt module is not yet loaded.
|
||||
Only if discard is not supported by the old kernel then
|
||||
the discard option is ignored.
|
||||
|
||||
* Fix some static analysis build warnings (scan-build).
|
||||
|
||||
* Report crypto lib version only once (and always add kernel
|
||||
version) in debug output.
|
||||
|
||||
Cryptsetup API NOTE:
|
||||
The direct terminal handling for passphrase entry will be removed from
|
||||
libcryptsetup in next major version (application should handle it itself).
|
||||
|
||||
It means that you have to always either provide password in buffer or set
|
||||
your own password callback function through crypt_set_password_callback().
|
||||
See API documentation (or libcryptsetup.h) for more info.
|
||||
84
docs/v1.6.7-ReleaseNotes
Normal file
84
docs/v1.6.7-ReleaseNotes
Normal file
@@ -0,0 +1,84 @@
|
||||
Cryptsetup 1.6.7 Release Notes
|
||||
==============================
|
||||
|
||||
Changes since version 1.6.6
|
||||
|
||||
* Cryptsetup git and wiki are now hosted on GitLab.
|
||||
https://gitlab.com/cryptsetup/cryptsetup
|
||||
|
||||
Repository of stable releases remains on kernel.org site
|
||||
https://www.kernel.org/pub/linux/utils/cryptsetup/
|
||||
|
||||
For more info please see README file.
|
||||
|
||||
* Cryptsetup TCRYPT mode now supports VeraCrypt devices (TrueCrypt extension).
|
||||
|
||||
The VeraCrypt extension only increases iteration count for the key
|
||||
derivation function (on-disk format is the same as TrueCrypt format).
|
||||
|
||||
Note that unlocking of a VeraCrypt device can take very long time if used
|
||||
on slow machines.
|
||||
|
||||
To use this extension, add --veracrypt option, for example
|
||||
cryptsetup open --type tcrypt --veracrypt <container> <name>
|
||||
|
||||
For use through libcryptsetup, just add CRYPT_TCRYPT_VERA_MODES flag.
|
||||
|
||||
* Support keyfile-offset and keyfile-size options even for plain volumes.
|
||||
|
||||
* Support keyfile option for luksAddKey if the master key is specified.
|
||||
|
||||
* For historic reasons, hashing in the plain mode is not used
|
||||
if keyfile is specified (with exception of --key-file=-).
|
||||
Print a warning if these parameters are ignored.
|
||||
|
||||
* Support permanent device decryption for cryptsetup-reencrypt.
|
||||
To remove LUKS encryption from a device, you can now use --decrypt option.
|
||||
|
||||
* Allow to use --header option in all LUKS commands.
|
||||
The --header always takes precedence over positional device argument.
|
||||
|
||||
* Allow luksSuspend without need to specify a detached header.
|
||||
|
||||
* Detect if O_DIRECT is usable on a device allocation.
|
||||
There are some strange storage stack configurations which wrongly allows
|
||||
to open devices with direct-io but fails on all IO operations later.
|
||||
|
||||
Cryptsetup now tries to read the device first sector to ensure it can use
|
||||
direct-io.
|
||||
|
||||
* Add low-level performance options tuning for dmcrypt (for Linux 4.0 and later).
|
||||
|
||||
Linux kernel 4.0 contains rewritten dmcrypt code which tries to better utilize
|
||||
encryption on parallel CPU cores.
|
||||
|
||||
While tests show that this change increases performance on most configurations,
|
||||
dmcrypt now provides some switches to change its new behavior.
|
||||
|
||||
You can use them (per-device) with these cryptsetup switches:
|
||||
--perf-same_cpu_crypt
|
||||
--perf-submit_from_crypt_cpus
|
||||
|
||||
Please use these only in the case of serious performance problems.
|
||||
Refer to the cryptsetup man page and dm-crypt documentation
|
||||
(for same_cpu_crypt and submit_from_crypt_cpus options).
|
||||
https://gitlab.com/cryptsetup/cryptsetup/wikis/DMCrypt
|
||||
|
||||
* Get rid of libfipscheck library.
|
||||
(Note that this option was used only for Red Hat and derived distributions.)
|
||||
With recent FIPS changes we do not need to link to this FIPS monster anymore.
|
||||
Also drop some no longer needed FIPS mode checks.
|
||||
|
||||
* Many fixes and clarifications to man pages.
|
||||
|
||||
* Prevent compiler to optimize-out zeroing of buffers for on-stack variables.
|
||||
|
||||
* Fix a crash if non-GNU strerror_r is used.
|
||||
|
||||
Cryptsetup API NOTE:
|
||||
The direct terminal handling for passphrase entry will be removed from
|
||||
libcryptsetup in next major version (application should handle it itself).
|
||||
|
||||
It means that you have to always either provide password in buffer or set
|
||||
your own password callback function through crypt_set_password_callback().
|
||||
See API documentation (or libcryptsetup.h) for more info.
|
||||
47
docs/v1.6.8-ReleaseNotes
Normal file
47
docs/v1.6.8-ReleaseNotes
Normal file
@@ -0,0 +1,47 @@
|
||||
Cryptsetup 1.6.8 Release Notes
|
||||
==============================
|
||||
|
||||
Changes since version 1.6.7
|
||||
|
||||
* If the null cipher (no encryption) is used, allow only empty password for LUKS.
|
||||
(Previously cryptsetup accepted any password in this case.)
|
||||
|
||||
The null cipher can be used only for testing and it is used temporarily during
|
||||
offline encrypting not yet encrypted device (cryptsetup-reencrypt tool).
|
||||
|
||||
Accepting only empty password prevents situation when someone adds another
|
||||
LUKS device using the same UUID (UUID of existing LUKS device) with faked
|
||||
header containing null cipher.
|
||||
This could force user to use different LUKS device (with no encryption)
|
||||
without noticing.
|
||||
(IOW it prevents situation when attacker intentionally forces
|
||||
user to boot into different system just by LUKS header manipulation.)
|
||||
|
||||
Properly configured systems should have an additional integrity protection
|
||||
in place here (LUKS here provides only confidentiality) but it is better
|
||||
to not allow this situation in the first place.
|
||||
|
||||
(For more info see QubesOS Security Bulletin QSB-019-2015.)
|
||||
|
||||
* Properly support stdin "-" handling for luksAddKey for both new and old
|
||||
keyfile parameters.
|
||||
|
||||
* If encrypted device is file-backed (it uses underlying loop device),
|
||||
cryptsetup resize will try to resize underlying loop device as well.
|
||||
(It can be used to grow up file-backed device in one step.)
|
||||
|
||||
* Cryptsetup now allows to use empty password through stdin pipe.
|
||||
(Intended only for testing in scripts.)
|
||||
|
||||
Cryptsetup API NOTE:
|
||||
|
||||
Direct terminal handling and password calling callback for passphrase
|
||||
entry will be removed from libcryptsetup in next major (2.x) version
|
||||
(application should handle it itself).
|
||||
It means that application have to always provide password in API calls.
|
||||
|
||||
Functions returning last error will be removed in next major version (2.x).
|
||||
These functions did not work properly for early initialization errors
|
||||
and application can implement better function easily using own error callback.
|
||||
|
||||
See comments in libcryptsetup.h for more info about deprecated functions.
|
||||
81
docs/v1.7.0-ReleaseNotes
Normal file
81
docs/v1.7.0-ReleaseNotes
Normal file
@@ -0,0 +1,81 @@
|
||||
Cryptsetup 1.7.0 Release Notes
|
||||
==============================
|
||||
|
||||
The cryptsetup 1.7 release changes defaults for LUKS,
|
||||
there are no API changes.
|
||||
|
||||
Changes since version 1.6.8
|
||||
|
||||
* Default hash function is now SHA256 (used in key derivation function
|
||||
and anti-forensic splitter).
|
||||
|
||||
Note that replacing SHA1 with SHA256 is not for security reasons.
|
||||
(LUKS does not have problems even if collisions are found for SHA1,
|
||||
for details see FAQ item 5.20).
|
||||
|
||||
Using SHA256 as default is mainly to prevent compatibility problems
|
||||
on hardened systems where SHA1 is already be phased out.
|
||||
|
||||
Note that all checks (kernel crypto API availability check) now uses
|
||||
SHA256 as well.
|
||||
|
||||
* Default iteration time for PBKDF2 is now 2 seconds.
|
||||
|
||||
Increasing iteration time is in combination with PBKDF2 benchmark
|
||||
fixes a try to keep PBKDF2 iteration count still high enough and
|
||||
also still acceptable for users.
|
||||
|
||||
N.B. Long term is to replace PBKDF2 algorithm with Password Hashing
|
||||
Competition winner - Argon2.
|
||||
|
||||
Distributions can still change these defaults in compilation time.
|
||||
|
||||
You can change iteration time and used hash function in existing LUKS
|
||||
header with cryptsetup-reencrypt utility even without full reencryption
|
||||
of device (see --keep-key option).
|
||||
|
||||
* Fix PBKDF2 iteration benchmark for longer key sizes.
|
||||
|
||||
The previous PBKDF2 benchmark code did not take into account
|
||||
output key length properly.
|
||||
|
||||
For SHA1 (with 160-bits output) and 256-bit keys (and longer)
|
||||
it means that the final iteration value was higher than it should be.
|
||||
|
||||
For other hash algorithms (like SHA256 or SHA512) it caused
|
||||
that iteration count was lower (in comparison to SHA1) than
|
||||
expected for the requested time period.
|
||||
|
||||
The PBKDF2 benchmark code is now fixed to use the key size for
|
||||
the formatted device (or default LUKS key size if running in informational
|
||||
benchmark mode).
|
||||
|
||||
Thanks to A.Visconti, S.Bossi, A.Calo and H.Ragab
|
||||
(http://www.club.di.unimi.it/) for point this out.
|
||||
(Based on "What users should know about Full Disk Encryption
|
||||
based on LUKS" paper to be presented on CANS2015).
|
||||
|
||||
* Remove experimental warning for reencrypt tool.
|
||||
The strong request for full backup before using reencryption utility
|
||||
still applies :)
|
||||
|
||||
* Add optional libpasswdqc support for new LUKS passwords.
|
||||
|
||||
If password is entered through terminal (no keyfile specified) and
|
||||
cryptsetup is compiled with --enable-passwdqc[=/etc/passwdqc.conf],
|
||||
configured system passwdqc settings are used to check password quality.
|
||||
|
||||
* Update FAQ document.
|
||||
|
||||
Cryptsetup API NOTE:
|
||||
|
||||
Direct terminal handling and password calling callback for passphrase
|
||||
entry will be removed from libcryptsetup in next major (2.x) version
|
||||
(application should handle it itself).
|
||||
It means that application have to always provide password in API calls.
|
||||
|
||||
Functions returning last error will be removed in next major version (2.x).
|
||||
These functions did not work properly for early initialization errors
|
||||
and application can implement better function easily using own error callback.
|
||||
|
||||
See comments in libcryptsetup.h for more info about deprecated functions.
|
||||
36
docs/v1.7.1-ReleaseNotes
Normal file
36
docs/v1.7.1-ReleaseNotes
Normal file
@@ -0,0 +1,36 @@
|
||||
Cryptsetup 1.7.1 Release Notes
|
||||
==============================
|
||||
|
||||
Changes since version 1.7.0
|
||||
|
||||
* Code now uses kernel crypto API backend according to new
|
||||
changes introduced in mainline kernel
|
||||
|
||||
While mainline kernel should contain backward compatible
|
||||
changes, some stable series kernels do not contain fully
|
||||
backported compatibility patches.
|
||||
Without these patches most of cryptsetup operations
|
||||
(like unlocking device) fail.
|
||||
|
||||
This change in cryptsetup ensures that all operations using
|
||||
kernel crypto API works even on these kernels.
|
||||
|
||||
* The cryptsetup-reencrypt utility now properly detects removal
|
||||
of underlying link to block device and does not remove
|
||||
ongoing re-encryption log.
|
||||
This allows proper recovery (resume) of reencrypt operation later.
|
||||
|
||||
NOTE: Never use /dev/disk/by-uuid/ path for reencryption utility,
|
||||
this link disappears once the device metadata is temporarily
|
||||
removed from device.
|
||||
|
||||
* Cryptsetup now allows special "-" (standard input) keyfile handling
|
||||
even for TCRYPT (TrueCrypt and VeraCrypt compatible) devices.
|
||||
|
||||
* Cryptsetup now fails if there are more keyfiles specified
|
||||
for non-TCRYPT device.
|
||||
|
||||
* The luksKillSlot command now does not suppress provided password
|
||||
in batch mode (if password is wrong slot is not destroyed).
|
||||
Note that not providing password in batch mode means that keyslot
|
||||
is destroyed unconditionally.
|
||||
37
docs/v1.7.2-ReleaseNotes
Normal file
37
docs/v1.7.2-ReleaseNotes
Normal file
@@ -0,0 +1,37 @@
|
||||
Cryptsetup 1.7.2 Release Notes
|
||||
==============================
|
||||
|
||||
Changes since version 1.7.1
|
||||
|
||||
* Update LUKS documentation format.
|
||||
Clarify fixed sector size and keyslots alignment.
|
||||
|
||||
* Support activation options for error handling modes in Linux kernel
|
||||
dm-verity module:
|
||||
|
||||
--ignore-corruption - dm-verity just logs detected corruption
|
||||
|
||||
--restart-on-corruption - dm-verity restarts the kernel if corruption is detected
|
||||
|
||||
If the options above are not specified, default behavior for dm-verity remains.
|
||||
Default is that I/O operation fails with I/O error if corrupted block is detected.
|
||||
|
||||
--ignore-zero-blocks - Instructs dm-verity to not verify blocks that are expected
|
||||
to contain zeroes and always return zeroes directly instead.
|
||||
|
||||
NOTE that these options could have security or functional impacts,
|
||||
do not use them without assessing the risks!
|
||||
|
||||
* Fix help text for cipher benchmark specification (mention --cipher option).
|
||||
|
||||
* Fix off-by-one error in maximum keyfile size.
|
||||
Allow keyfiles up to compiled-in default and not that value minus one.
|
||||
|
||||
* Support resume of interrupted decryption in cryptsetup-reencrypt utility.
|
||||
To resume decryption, LUKS device UUID (--uuid option) option must be used.
|
||||
|
||||
* Do not use direct-io for LUKS header with unaligned keyslots.
|
||||
Such headers were used only by the first cryptsetup-luks-1.0.0 release (2005).
|
||||
|
||||
* Fix device block size detection to properly work on particular file-based
|
||||
containers over underlying devices with 4k sectors.
|
||||
24
docs/v1.7.3-ReleaseNotes
Normal file
24
docs/v1.7.3-ReleaseNotes
Normal file
@@ -0,0 +1,24 @@
|
||||
Cryptsetup 1.7.3 Release Notes
|
||||
==============================
|
||||
|
||||
Changes since version 1.7.2
|
||||
|
||||
* Fix device access to hash offsets located beyond the 2GB device boundary in veritysetup.
|
||||
|
||||
* Set configured (compile-time) default iteration time for devices created directly through
|
||||
libcryptsetup (default was hardcoded 1 second, the configured value applied only
|
||||
for cryptsetup application).
|
||||
|
||||
* Fix PBKDF2 benchmark to not double iteration count for specific corner case.
|
||||
If the measurement function returns exactly 500 ms, the iteration calculation loop
|
||||
doubled iteration count but instead of repeating measurement it used this value directly.
|
||||
|
||||
* Verify passphrase in cryptsetup-reencrypt when encrypting a new drive.
|
||||
|
||||
* OpenSSL backend: fix memory leak if hash context was repeatedly reused.
|
||||
|
||||
* OpenSSL backend: add support for OpenSSL 1.1.0.
|
||||
|
||||
* Fix several minor spelling errors.
|
||||
|
||||
* Properly check maximal buffer size when parsing UUID from /dev/disk/.
|
||||
22
docs/v1.7.4-ReleaseNotes
Normal file
22
docs/v1.7.4-ReleaseNotes
Normal file
@@ -0,0 +1,22 @@
|
||||
Cryptsetup 1.7.4 Release Notes
|
||||
==============================
|
||||
|
||||
Changes since version 1.7.3
|
||||
|
||||
* Allow to specify LUKS1 hash algorithm in Python luksFormat wrapper.
|
||||
|
||||
* Use LUKS1 compiled-in defaults also in Python wrapper.
|
||||
|
||||
* OpenSSL backend: Fix OpenSSL 1.1.0 support without backward compatible API.
|
||||
|
||||
* OpenSSL backend: Fix LibreSSL compatibility.
|
||||
|
||||
* Check for data device and hash device area overlap in veritysetup.
|
||||
|
||||
* Fix a possible race while allocating a free loop device.
|
||||
|
||||
* Fix possible file descriptor leaks if libcryptsetup is run from a forked process.
|
||||
|
||||
* Fix missing same_cpu_crypt flag in status command.
|
||||
|
||||
* Various updates to FAQ and man pages.
|
||||
22
docs/v1.7.5-ReleaseNotes
Normal file
22
docs/v1.7.5-ReleaseNotes
Normal file
@@ -0,0 +1,22 @@
|
||||
Cryptsetup 1.7.5 Release Notes
|
||||
==============================
|
||||
|
||||
Changes since version 1.7.5
|
||||
|
||||
* Fixes to luksFormat to properly support recent kernel running in FIPS mode.
|
||||
|
||||
Cryptsetup must never use a weak key even if it is just used for testing
|
||||
of algorithm availability. In FIPS mode, weak keys are always rejected.
|
||||
|
||||
A weak key is for example detected if the XTS encryption mode use
|
||||
the same key for the tweak and the encryption part.
|
||||
|
||||
* Fixes accesses to unaligned hidden legacy TrueCrypt header.
|
||||
|
||||
On a native 4k-sector device the old hidden TrueCrypt header is not
|
||||
aligned with the hw sector size (this problem was fixed in later TrueCrypt
|
||||
on-disk format versions).
|
||||
|
||||
Cryptsetup now properly aligns the read so it does not fail.
|
||||
|
||||
* Fixes to optional dracut ramdisk scripts for offline re-encryption on initial boot.
|
||||
@@ -5,7 +5,7 @@ moduledir = $(libdir)/cryptsetup
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = libcryptsetup.pc
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
AM_CPPFLAGS = -include config.h \
|
||||
-I$(top_srcdir) \
|
||||
-I$(top_srcdir)/lib/crypto_backend \
|
||||
-I$(top_srcdir)/lib/luks1 \
|
||||
@@ -16,10 +16,7 @@ AM_CPPFLAGS = \
|
||||
-DLIBDIR=\""$(libdir)"\" \
|
||||
-DPREFIX=\""$(prefix)"\" \
|
||||
-DSYSCONFDIR=\""$(sysconfdir)"\" \
|
||||
-DVERSION=\""$(VERSION)"\" \
|
||||
-D_GNU_SOURCE \
|
||||
-D_LARGEFILE64_SOURCE \
|
||||
-D_FILE_OFFSET_BITS=64
|
||||
-DVERSION=\""$(VERSION)"\"
|
||||
|
||||
lib_LTLIBRARIES = libcryptsetup.la
|
||||
|
||||
@@ -32,17 +29,16 @@ common_ldadd = \
|
||||
|
||||
libcryptsetup_la_DEPENDENCIES = $(common_ldadd) libcryptsetup.sym
|
||||
|
||||
libcryptsetup_la_LDFLAGS = \
|
||||
libcryptsetup_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined \
|
||||
-Wl,--version-script=$(top_srcdir)/lib/libcryptsetup.sym \
|
||||
-version-info @LIBCRYPTSETUP_VERSION_INFO@
|
||||
|
||||
libcryptsetup_la_CFLAGS = -Wall @CRYPTO_CFLAGS@
|
||||
libcryptsetup_la_CFLAGS = -Wall $(AM_CFLAGS) @CRYPTO_CFLAGS@
|
||||
|
||||
libcryptsetup_la_LIBADD = \
|
||||
@UUID_LIBS@ \
|
||||
@DEVMAPPER_LIBS@ \
|
||||
@CRYPTO_LIBS@ \
|
||||
@FIPSCHECK_LIBS@ \
|
||||
$(common_ldadd)
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* cryptsetup plain device helper functions
|
||||
*
|
||||
* Copyright (C) 2004, Christophe Saout <christophe@saout.de>
|
||||
* Copyright (C) 2010-2012 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2012, Milan Broz
|
||||
* Copyright (C) 2004, Jana Saout <jana@saout.de>
|
||||
* Copyright (C) 2010-2017 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2017, Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "libcryptsetup.h"
|
||||
@@ -83,7 +83,11 @@ int crypt_plain_hash(struct crypt_device *ctx __attribute__((unused)),
|
||||
/* hash[:hash_length] */
|
||||
if ((s = strchr(hash_name_buf, ':'))) {
|
||||
*s = '\0';
|
||||
hash_size = atoi(++s);
|
||||
s++;
|
||||
if (!*s || sscanf(s, "%zd", &hash_size) != 1) {
|
||||
log_dbg("Hash length is not a number");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (hash_size > key_size) {
|
||||
log_dbg("Hash length %zd > key length %zd",
|
||||
hash_size, key_size);
|
||||
@@ -95,7 +99,16 @@ int crypt_plain_hash(struct crypt_device *ctx __attribute__((unused)),
|
||||
pad_size = 0;
|
||||
}
|
||||
|
||||
r = hash(hash_name_buf, hash_size, key, passphrase_size, passphrase);
|
||||
/* No hash, copy passphrase directly */
|
||||
if (!strcmp(hash_name_buf, "plain")) {
|
||||
if (passphrase_size < hash_size) {
|
||||
log_dbg("Too short plain passphrase.");
|
||||
return -EINVAL;
|
||||
}
|
||||
memcpy(key, passphrase, hash_size);
|
||||
r = 0;
|
||||
} else
|
||||
r = hash(hash_name_buf, hash_size, key, passphrase_size, passphrase);
|
||||
|
||||
if (r == 0 && pad_size)
|
||||
memset(key + hash_size, 0, pad_size);
|
||||
|
||||
@@ -2,10 +2,10 @@ moduledir = $(libdir)/cryptsetup
|
||||
|
||||
noinst_LTLIBRARIES = libcrypto_backend.la
|
||||
|
||||
libcrypto_backend_la_CFLAGS = -Wall @CRYPTO_CFLAGS@
|
||||
libcrypto_backend_la_CFLAGS = $(AM_CFLAGS) -Wall @CRYPTO_CFLAGS@
|
||||
|
||||
libcrypto_backend_la_SOURCES = crypto_backend.h \
|
||||
crypto_cipher_kernel.c pbkdf_check.c crc32.c
|
||||
crypto_cipher_kernel.c crypto_storage.c pbkdf_check.c crc32.c
|
||||
|
||||
if CRYPTO_BACKEND_GCRYPT
|
||||
libcrypto_backend_la_SOURCES += crypto_gcrypt.c
|
||||
@@ -27,4 +27,4 @@ if CRYPTO_INTERNAL_PBKDF2
|
||||
libcrypto_backend_la_SOURCES += pbkdf2_generic.c
|
||||
endif
|
||||
|
||||
AM_CPPFLAGS = -D_GNU_SOURCE -I$(top_srcdir)/lib
|
||||
AM_CPPFLAGS = -include config.h -I$(top_srcdir)/lib
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* crypto backend implementation
|
||||
*
|
||||
* Copyright (C) 2010-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2012, Milan Broz
|
||||
* Copyright (C) 2010-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2017, Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -23,12 +23,12 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "config.h"
|
||||
|
||||
struct crypt_device;
|
||||
struct crypt_hash;
|
||||
struct crypt_hmac;
|
||||
struct crypt_cipher;
|
||||
struct crypt_storage;
|
||||
|
||||
int crypt_backend_init(struct crypt_device *ctx);
|
||||
|
||||
@@ -58,9 +58,9 @@ int crypt_backend_rng(char *buffer, size_t length, int quality, int fips);
|
||||
|
||||
/* PBKDF*/
|
||||
int crypt_pbkdf_check(const char *kdf, const char *hash,
|
||||
const char *password, size_t password_size,
|
||||
const char *salt, size_t salt_size,
|
||||
uint64_t *iter_secs);
|
||||
const char *password, size_t password_length,
|
||||
const char *salt, size_t salt_length,
|
||||
size_t key_length, uint64_t *iter_secs);
|
||||
int crypt_pbkdf(const char *kdf, const char *hash,
|
||||
const char *password, size_t password_length,
|
||||
const char *salt, size_t salt_length,
|
||||
@@ -73,13 +73,15 @@ int pkcs5_pbkdf2(const char *hash,
|
||||
const char *P, size_t Plen,
|
||||
const char *S, size_t Slen,
|
||||
unsigned int c,
|
||||
unsigned int dkLen,char *DK);
|
||||
unsigned int dkLen, char *DK,
|
||||
unsigned int hash_block_size);
|
||||
#endif
|
||||
|
||||
/* CRC32 */
|
||||
uint32_t crypt_crc32(uint32_t seed, const unsigned char *buf, size_t len);
|
||||
|
||||
/* ciphers */
|
||||
int crypt_cipher_blocksize(const char *name);
|
||||
int crypt_cipher_init(struct crypt_cipher **ctx, const char *name,
|
||||
const char *mode, const void *buffer, size_t length);
|
||||
int crypt_cipher_destroy(struct crypt_cipher *ctx);
|
||||
@@ -90,4 +92,21 @@ int crypt_cipher_decrypt(struct crypt_cipher *ctx,
|
||||
const char *in, char *out, size_t length,
|
||||
const char *iv, size_t iv_length);
|
||||
|
||||
/* storage encryption wrappers */
|
||||
int crypt_storage_init(struct crypt_storage **ctx, uint64_t sector_start,
|
||||
const char *cipher, const char *cipher_mode,
|
||||
char *key, size_t key_length);
|
||||
int crypt_storage_destroy(struct crypt_storage *ctx);
|
||||
int crypt_storage_decrypt(struct crypt_storage *ctx, uint64_t sector,
|
||||
size_t count, char *buffer);
|
||||
int crypt_storage_encrypt(struct crypt_storage *ctx, uint64_t sector,
|
||||
size_t count, char *buffer);
|
||||
|
||||
/* Memzero helper (memset on stack can be optimized out) */
|
||||
static inline void crypt_backend_memzero(void *s, size_t n)
|
||||
{
|
||||
volatile uint8_t *p = (volatile uint8_t *)s;
|
||||
while(n--) *p++ = 0;
|
||||
}
|
||||
|
||||
#endif /* _CRYPTO_BACKEND_H */
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Linux kernel userspace API crypto backend implementation (skcipher)
|
||||
*
|
||||
* Copyright (C) 2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012, Milan Broz
|
||||
* Copyright (C) 2012-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2017, Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -44,33 +44,52 @@ struct crypt_cipher {
|
||||
int opfd;
|
||||
};
|
||||
|
||||
/* Shared with hash kernel backend */
|
||||
int crypt_kernel_socket_init(struct sockaddr_alg *sa, int *tfmfd, int *opfd);
|
||||
struct cipher_alg {
|
||||
const char *name;
|
||||
int blocksize;
|
||||
};
|
||||
|
||||
int crypt_kernel_socket_init(struct sockaddr_alg *sa, int *tfmfd, int *opfd)
|
||||
/* FIXME: Getting block size should be dynamic from cipher backend. */
|
||||
static struct cipher_alg cipher_algs[] = {
|
||||
{ "cipher_null", 16 },
|
||||
{ "aes", 16 },
|
||||
{ "serpent", 16 },
|
||||
{ "twofish", 16 },
|
||||
{ "anubis", 16 },
|
||||
{ "blowfish", 8 },
|
||||
{ "camellia", 16 },
|
||||
{ "cast5", 8 },
|
||||
{ "cast6", 16 },
|
||||
{ "des", 8 },
|
||||
{ "des3_ede", 8 },
|
||||
{ "khazad", 8 },
|
||||
{ "seed", 16 },
|
||||
{ "tea", 8 },
|
||||
{ "xtea", 8 },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
static struct cipher_alg *_get_alg(const char *name)
|
||||
{
|
||||
*tfmfd = socket(AF_ALG, SOCK_SEQPACKET, 0);
|
||||
if (*tfmfd == -1)
|
||||
return -ENOTSUP;
|
||||
int i = 0;
|
||||
|
||||
if (bind(*tfmfd, (struct sockaddr *)sa, sizeof(*sa)) == -1) {
|
||||
close(*tfmfd);
|
||||
*tfmfd = -1;
|
||||
return -ENOENT;
|
||||
while (name && cipher_algs[i].name) {
|
||||
if (!strcasecmp(name, cipher_algs[i].name))
|
||||
return &cipher_algs[i];
|
||||
i++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*opfd = accept(*tfmfd, NULL, 0);
|
||||
if (*opfd == -1) {
|
||||
close(*tfmfd);
|
||||
*tfmfd = -1;
|
||||
return -EINVAL;
|
||||
}
|
||||
int crypt_cipher_blocksize(const char *name)
|
||||
{
|
||||
struct cipher_alg *ca = _get_alg(name);
|
||||
|
||||
return 0;
|
||||
return ca ? ca->blocksize : -EINVAL;
|
||||
}
|
||||
|
||||
/*
|
||||
*ciphers
|
||||
* ciphers
|
||||
*
|
||||
* ENOENT - algorithm not available
|
||||
* ENOTSUP - AF_ALG family not available
|
||||
@@ -84,7 +103,6 @@ int crypt_cipher_init(struct crypt_cipher **ctx, const char *name,
|
||||
.salg_family = AF_ALG,
|
||||
.salg_type = "skcipher",
|
||||
};
|
||||
int r;
|
||||
|
||||
h = malloc(sizeof(*h));
|
||||
if (!h)
|
||||
@@ -93,13 +111,28 @@ int crypt_cipher_init(struct crypt_cipher **ctx, const char *name,
|
||||
snprintf((char *)sa.salg_name, sizeof(sa.salg_name),
|
||||
"%s(%s)", mode, name);
|
||||
|
||||
r = crypt_kernel_socket_init(&sa, &h->tfmfd, &h->opfd);
|
||||
if (r < 0) {
|
||||
free(h);
|
||||
return r;
|
||||
h->opfd = -1;
|
||||
h->tfmfd = socket(AF_ALG, SOCK_SEQPACKET, 0);
|
||||
if (h->tfmfd < 0) {
|
||||
crypt_cipher_destroy(h);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (setsockopt(h->tfmfd, SOL_ALG, ALG_SET_KEY, buffer, length) == -1) {
|
||||
if (bind(h->tfmfd, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
|
||||
crypt_cipher_destroy(h);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
if (!strcmp(name, "cipher_null"))
|
||||
length = 0;
|
||||
|
||||
if (setsockopt(h->tfmfd, SOL_ALG, ALG_SET_KEY, buffer, length) < 0) {
|
||||
crypt_cipher_destroy(h);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
h->opfd = accept(h->tfmfd, NULL, 0);
|
||||
if (h->opfd < 0) {
|
||||
crypt_cipher_destroy(h);
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -142,6 +175,9 @@ static int crypt_cipher_crypt(struct crypt_cipher *ctx,
|
||||
|
||||
/* Set encrypt/decrypt operation */
|
||||
header = CMSG_FIRSTHDR(&msg);
|
||||
if (!header)
|
||||
return -EINVAL;
|
||||
|
||||
header->cmsg_level = SOL_ALG;
|
||||
header->cmsg_type = ALG_SET_OP;
|
||||
header->cmsg_len = CMSG_LEN(sizeof(*type));
|
||||
@@ -169,7 +205,7 @@ static int crypt_cipher_crypt(struct crypt_cipher *ctx,
|
||||
if (len != (ssize_t)length)
|
||||
r = -EIO;
|
||||
bad:
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
crypt_backend_memzero(buffer, sizeof(buffer));
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -191,9 +227,9 @@ int crypt_cipher_decrypt(struct crypt_cipher *ctx,
|
||||
|
||||
int crypt_cipher_destroy(struct crypt_cipher *ctx)
|
||||
{
|
||||
if (ctx->tfmfd != -1)
|
||||
if (ctx->tfmfd >= 0)
|
||||
close(ctx->tfmfd);
|
||||
if (ctx->opfd != -1)
|
||||
if (ctx->opfd >= 0)
|
||||
close(ctx->opfd);
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
free(ctx);
|
||||
@@ -202,6 +238,11 @@ int crypt_cipher_destroy(struct crypt_cipher *ctx)
|
||||
|
||||
#else /* ENABLE_AF_ALG */
|
||||
|
||||
int crypt_cipher_blocksize(const char *name)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
int crypt_cipher_init(struct crypt_cipher **ctx, const char *name,
|
||||
const char *mode, const void *buffer, size_t length)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* GCRYPT crypto backend implementation
|
||||
*
|
||||
* Copyright (C) 2010-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2012, Milan Broz
|
||||
* Copyright (C) 2010-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2017, Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
static int crypto_backend_initialised = 0;
|
||||
static int crypto_backend_secmem = 1;
|
||||
static int crypto_backend_whirlpool_bug = -1;
|
||||
static char version[64];
|
||||
|
||||
struct crypt_hash {
|
||||
@@ -42,6 +43,44 @@ struct crypt_hmac {
|
||||
int hash_len;
|
||||
};
|
||||
|
||||
/*
|
||||
* Test for wrong Whirlpool variant,
|
||||
* Ref: http://lists.gnupg.org/pipermail/gcrypt-devel/2014-January/002889.html
|
||||
*/
|
||||
static void crypt_hash_test_whirlpool_bug(void)
|
||||
{
|
||||
struct crypt_hash *h;
|
||||
char buf[2] = "\0\0", hash_out1[64], hash_out2[64];
|
||||
int r;
|
||||
|
||||
if (crypto_backend_whirlpool_bug >= 0)
|
||||
return;
|
||||
|
||||
crypto_backend_whirlpool_bug = 0;
|
||||
if (crypt_hash_init(&h, "whirlpool"))
|
||||
return;
|
||||
|
||||
/* One shot */
|
||||
if ((r = crypt_hash_write(h, &buf[0], 2)) ||
|
||||
(r = crypt_hash_final(h, hash_out1, 64))) {
|
||||
crypt_hash_destroy(h);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Split buf (crypt_hash_final resets hash state) */
|
||||
if ((r = crypt_hash_write(h, &buf[0], 1)) ||
|
||||
(r = crypt_hash_write(h, &buf[1], 1)) ||
|
||||
(r = crypt_hash_final(h, hash_out2, 64))) {
|
||||
crypt_hash_destroy(h);
|
||||
return;
|
||||
}
|
||||
|
||||
crypt_hash_destroy(h);
|
||||
|
||||
if (memcmp(hash_out1, hash_out2, 64))
|
||||
crypto_backend_whirlpool_bug = 1;
|
||||
}
|
||||
|
||||
int crypt_backend_init(struct crypt_device *ctx)
|
||||
{
|
||||
if (crypto_backend_initialised)
|
||||
@@ -70,10 +109,15 @@ int crypt_backend_init(struct crypt_device *ctx)
|
||||
gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
|
||||
}
|
||||
|
||||
snprintf(version, 64, "gcrypt %s%s",
|
||||
gcry_check_version(NULL),
|
||||
crypto_backend_secmem ? "" : ", secmem disabled");
|
||||
crypto_backend_initialised = 1;
|
||||
crypt_hash_test_whirlpool_bug();
|
||||
|
||||
snprintf(version, 64, "gcrypt %s%s%s",
|
||||
gcry_check_version(NULL),
|
||||
crypto_backend_secmem ? "" : ", secmem disabled",
|
||||
crypto_backend_whirlpool_bug > 0 ? ", flawed whirlpool" : ""
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -87,6 +131,23 @@ uint32_t crypt_backend_flags(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *crypt_hash_compat_name(const char *name, unsigned int *flags)
|
||||
{
|
||||
const char *hash_name = name;
|
||||
|
||||
/* "whirlpool_gcryptbug" is out shortcut to flawed whirlpool
|
||||
* in libgcrypt < 1.6.0 */
|
||||
if (name && !strcasecmp(name, "whirlpool_gcryptbug")) {
|
||||
#if GCRYPT_VERSION_NUMBER >= 0x010601
|
||||
if (flags)
|
||||
*flags |= GCRY_MD_FLAG_BUGEMU1;
|
||||
#endif
|
||||
hash_name = "whirlpool";
|
||||
}
|
||||
|
||||
return hash_name;
|
||||
}
|
||||
|
||||
/* HASH */
|
||||
int crypt_hash_size(const char *name)
|
||||
{
|
||||
@@ -94,7 +155,7 @@ int crypt_hash_size(const char *name)
|
||||
|
||||
assert(crypto_backend_initialised);
|
||||
|
||||
hash_id = gcry_md_map_name(name);
|
||||
hash_id = gcry_md_map_name(crypt_hash_compat_name(name, NULL));
|
||||
if (!hash_id)
|
||||
return -EINVAL;
|
||||
|
||||
@@ -104,6 +165,7 @@ int crypt_hash_size(const char *name)
|
||||
int crypt_hash_init(struct crypt_hash **ctx, const char *name)
|
||||
{
|
||||
struct crypt_hash *h;
|
||||
unsigned int flags = 0;
|
||||
|
||||
assert(crypto_backend_initialised);
|
||||
|
||||
@@ -111,13 +173,13 @@ int crypt_hash_init(struct crypt_hash **ctx, const char *name)
|
||||
if (!h)
|
||||
return -ENOMEM;
|
||||
|
||||
h->hash_id = gcry_md_map_name(name);
|
||||
h->hash_id = gcry_md_map_name(crypt_hash_compat_name(name, &flags));
|
||||
if (!h->hash_id) {
|
||||
free(h);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (gcry_md_open(&h->hd, h->hash_id, 0)) {
|
||||
if (gcry_md_open(&h->hd, h->hash_id, flags)) {
|
||||
free(h);
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -173,6 +235,7 @@ int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
|
||||
const void *buffer, size_t length)
|
||||
{
|
||||
struct crypt_hmac *h;
|
||||
unsigned int flags = GCRY_MD_FLAG_HMAC;
|
||||
|
||||
assert(crypto_backend_initialised);
|
||||
|
||||
@@ -180,13 +243,13 @@ int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
|
||||
if (!h)
|
||||
return -ENOMEM;
|
||||
|
||||
h->hash_id = gcry_md_map_name(name);
|
||||
h->hash_id = gcry_md_map_name(crypt_hash_compat_name(name, &flags));
|
||||
if (!h->hash_id) {
|
||||
free(h);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (gcry_md_open(&h->hd, h->hash_id, GCRY_MD_FLAG_HMAC)) {
|
||||
if (gcry_md_open(&h->hd, h->hash_id, flags)) {
|
||||
free(h);
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -261,15 +324,17 @@ int crypt_pbkdf(const char *kdf, const char *hash,
|
||||
char *key, size_t key_length,
|
||||
unsigned int iterations)
|
||||
{
|
||||
const char *hash_name = crypt_hash_compat_name(hash, NULL);
|
||||
|
||||
#if USE_INTERNAL_PBKDF2
|
||||
if (!kdf || strncmp(kdf, "pbkdf2", 6))
|
||||
return -EINVAL;
|
||||
|
||||
return pkcs5_pbkdf2(hash, password, password_length, salt, salt_length,
|
||||
iterations, key_length, key);
|
||||
return pkcs5_pbkdf2(hash_name, password, password_length, salt, salt_length,
|
||||
iterations, key_length, key, 0);
|
||||
|
||||
#else /* USE_INTERNAL_PBKDF2 */
|
||||
int hash_id = gcry_md_map_name(hash);
|
||||
int hash_id = gcry_md_map_name(hash_name);
|
||||
int kdf_id;
|
||||
|
||||
if (!hash_id)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Linux kernel userspace API crypto backend implementation
|
||||
*
|
||||
* Copyright (C) 2010-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2012, Milan Broz
|
||||
* Copyright (C) 2010-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2017, Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -44,15 +44,16 @@ struct hash_alg {
|
||||
const char *name;
|
||||
const char *kernel_name;
|
||||
int length;
|
||||
unsigned int block_length;
|
||||
};
|
||||
|
||||
static struct hash_alg hash_algs[] = {
|
||||
{ "sha1", "sha1", 20 },
|
||||
{ "sha256", "sha256", 32 },
|
||||
{ "sha512", "sha512", 64 },
|
||||
{ "ripemd160", "rmd160", 20 },
|
||||
{ "whirlpool", "wp512", 64 },
|
||||
{ NULL, NULL, 0 }
|
||||
{ "sha1", "sha1", 20, 64 },
|
||||
{ "sha256", "sha256", 32, 64 },
|
||||
{ "sha512", "sha512", 64, 128 },
|
||||
{ "ripemd160", "rmd160", 20, 64 },
|
||||
{ "whirlpool", "wp512", 64, 64 },
|
||||
{ NULL, NULL, 0, 0 }
|
||||
};
|
||||
|
||||
struct crypt_hash {
|
||||
@@ -67,8 +68,34 @@ struct crypt_hmac {
|
||||
int hash_len;
|
||||
};
|
||||
|
||||
/* Defined in crypt_kernel_ciphers.c */
|
||||
extern int crypt_kernel_socket_init(struct sockaddr_alg *sa, int *tfmfd, int *opfd);
|
||||
static int crypt_kernel_socket_init(struct sockaddr_alg *sa, int *tfmfd, int *opfd,
|
||||
const void *key, size_t key_length)
|
||||
{
|
||||
*tfmfd = socket(AF_ALG, SOCK_SEQPACKET, 0);
|
||||
if (*tfmfd < 0)
|
||||
return -ENOTSUP;
|
||||
|
||||
if (bind(*tfmfd, (struct sockaddr *)sa, sizeof(*sa)) < 0) {
|
||||
close(*tfmfd);
|
||||
*tfmfd = -1;
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
if (key && setsockopt(*tfmfd, SOL_ALG, ALG_SET_KEY, key, key_length) < 0) {
|
||||
close(*tfmfd);
|
||||
*tfmfd = -1;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
*opfd = accept(*tfmfd, NULL, 0);
|
||||
if (*opfd < 0) {
|
||||
close(*tfmfd);
|
||||
*tfmfd = -1;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int crypt_backend_init(struct crypt_device *ctx)
|
||||
{
|
||||
@@ -76,7 +103,7 @@ int crypt_backend_init(struct crypt_device *ctx)
|
||||
struct sockaddr_alg sa = {
|
||||
.salg_family = AF_ALG,
|
||||
.salg_type = "hash",
|
||||
.salg_name = "sha1",
|
||||
.salg_name = "sha256",
|
||||
};
|
||||
int tfmfd = -1, opfd = -1;
|
||||
|
||||
@@ -86,7 +113,7 @@ int crypt_backend_init(struct crypt_device *ctx)
|
||||
if (uname(&uts) == -1 || strcmp(uts.sysname, "Linux"))
|
||||
return -EINVAL;
|
||||
|
||||
if (crypt_kernel_socket_init(&sa, &tfmfd, &opfd) < 0)
|
||||
if (crypt_kernel_socket_init(&sa, &tfmfd, &opfd, NULL, 0) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
close(tfmfd);
|
||||
@@ -151,7 +178,7 @@ int crypt_hash_init(struct crypt_hash **ctx, const char *name)
|
||||
|
||||
strncpy((char *)sa.salg_name, ha->kernel_name, sizeof(sa.salg_name));
|
||||
|
||||
if (crypt_kernel_socket_init(&sa, &h->tfmfd, &h->opfd) < 0) {
|
||||
if (crypt_kernel_socket_init(&sa, &h->tfmfd, &h->opfd, NULL, 0) < 0) {
|
||||
free(h);
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -187,9 +214,9 @@ int crypt_hash_final(struct crypt_hash *ctx, char *buffer, size_t length)
|
||||
|
||||
int crypt_hash_destroy(struct crypt_hash *ctx)
|
||||
{
|
||||
if (ctx->tfmfd != -1)
|
||||
if (ctx->tfmfd >= 0)
|
||||
close(ctx->tfmfd);
|
||||
if (ctx->opfd != -1)
|
||||
if (ctx->opfd >= 0)
|
||||
close(ctx->opfd);
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
free(ctx);
|
||||
@@ -226,16 +253,11 @@ int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
|
||||
snprintf((char *)sa.salg_name, sizeof(sa.salg_name),
|
||||
"hmac(%s)", ha->kernel_name);
|
||||
|
||||
if (crypt_kernel_socket_init(&sa, &h->tfmfd, &h->opfd) < 0) {
|
||||
if (crypt_kernel_socket_init(&sa, &h->tfmfd, &h->opfd, buffer, length) < 0) {
|
||||
free(h);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (setsockopt(h->tfmfd, SOL_ALG, ALG_SET_KEY, buffer, length) == -1) {
|
||||
crypt_hmac_destroy(h);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
*ctx = h;
|
||||
return 0;
|
||||
}
|
||||
@@ -267,9 +289,9 @@ int crypt_hmac_final(struct crypt_hmac *ctx, char *buffer, size_t length)
|
||||
|
||||
int crypt_hmac_destroy(struct crypt_hmac *ctx)
|
||||
{
|
||||
if (ctx->tfmfd != -1)
|
||||
if (ctx->tfmfd >= 0)
|
||||
close(ctx->tfmfd);
|
||||
if (ctx->opfd != -1)
|
||||
if (ctx->opfd >= 0)
|
||||
close(ctx->opfd);
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
free(ctx);
|
||||
@@ -289,9 +311,11 @@ int crypt_pbkdf(const char *kdf, const char *hash,
|
||||
char *key, size_t key_length,
|
||||
unsigned int iterations)
|
||||
{
|
||||
if (!kdf || strncmp(kdf, "pbkdf2", 6))
|
||||
struct hash_alg *ha = _get_alg(hash);
|
||||
|
||||
if (!ha || !kdf || strncmp(kdf, "pbkdf2", 6))
|
||||
return -EINVAL;
|
||||
|
||||
return pkcs5_pbkdf2(hash, password, password_length, salt, salt_length,
|
||||
iterations, key_length, key);
|
||||
iterations, key_length, key, ha->block_length);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Nettle crypto backend implementation
|
||||
*
|
||||
* Copyright (C) 2011-2012 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2011-2012, Milan Broz
|
||||
* Copyright (C) 2011-2017 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2011-2017, Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -24,14 +24,15 @@
|
||||
#include <errno.h>
|
||||
#include <nettle/sha.h>
|
||||
#include <nettle/hmac.h>
|
||||
#include <nettle/pbkdf2.h>
|
||||
#include "crypto_backend.h"
|
||||
|
||||
static char *version = "Nettle";
|
||||
|
||||
typedef void (*init_func) (void *);
|
||||
typedef void (*update_func) (void *, unsigned, const uint8_t *);
|
||||
typedef void (*digest_func) (void *, unsigned, uint8_t *);
|
||||
typedef void (*set_key_func) (void *, unsigned, const uint8_t *);
|
||||
typedef void (*update_func) (void *, size_t, const uint8_t *);
|
||||
typedef void (*digest_func) (void *, size_t, uint8_t *);
|
||||
typedef void (*set_key_func) (void *, size_t, const uint8_t *);
|
||||
|
||||
struct hash_alg {
|
||||
const char *name;
|
||||
@@ -265,8 +266,8 @@ int crypt_hmac_final(struct crypt_hmac *ctx, char *buffer, size_t length)
|
||||
int crypt_hmac_destroy(struct crypt_hmac *ctx)
|
||||
{
|
||||
memset(ctx->key, 0, ctx->key_length);
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
free(ctx->key);
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
free(ctx);
|
||||
return 0;
|
||||
}
|
||||
@@ -284,10 +285,21 @@ int crypt_pbkdf(const char *kdf, const char *hash,
|
||||
char *key, size_t key_length,
|
||||
unsigned int iterations)
|
||||
{
|
||||
struct crypt_hmac *h;
|
||||
int r;
|
||||
|
||||
if (!kdf || strncmp(kdf, "pbkdf2", 6))
|
||||
return -EINVAL;
|
||||
|
||||
/* FIXME: switch to internal implementation in Nettle 2.6 */
|
||||
return pkcs5_pbkdf2(hash, password, password_length, salt, salt_length,
|
||||
iterations, key_length, key);
|
||||
r = crypt_hmac_init(&h, hash, password, password_length);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
nettle_pbkdf2(&h->nettle_ctx, h->hash->nettle_hmac_update,
|
||||
h->hash->nettle_hmac_digest, h->hash->length, iterations,
|
||||
salt_length, (const uint8_t *)salt, key_length,
|
||||
(uint8_t *)key);
|
||||
crypt_hmac_destroy(h);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* NSS crypto backend implementation
|
||||
*
|
||||
* Copyright (C) 2010-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2012, Milan Broz
|
||||
* Copyright (C) 2010-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2017, Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -35,14 +35,15 @@ struct hash_alg {
|
||||
SECOidTag oid;
|
||||
CK_MECHANISM_TYPE ck_type;
|
||||
int length;
|
||||
unsigned int block_length;
|
||||
};
|
||||
|
||||
static struct hash_alg hash_algs[] = {
|
||||
{ "sha1", SEC_OID_SHA1, CKM_SHA_1_HMAC, 20 },
|
||||
{ "sha256", SEC_OID_SHA256, CKM_SHA256_HMAC, 32 },
|
||||
{ "sha384", SEC_OID_SHA384, CKM_SHA384_HMAC, 48 },
|
||||
{ "sha512", SEC_OID_SHA512, CKM_SHA512_HMAC, 64 },
|
||||
// { "ripemd160", SEC_OID_RIPEMD160, CKM_RIPEMD160_HMAC, 20 },
|
||||
{ "sha1", SEC_OID_SHA1, CKM_SHA_1_HMAC, 20, 64 },
|
||||
{ "sha256", SEC_OID_SHA256, CKM_SHA256_HMAC, 32, 64 },
|
||||
{ "sha384", SEC_OID_SHA384, CKM_SHA384_HMAC, 48, 128 },
|
||||
{ "sha512", SEC_OID_SHA512, CKM_SHA512_HMAC, 64, 128 },
|
||||
// { "ripemd160", SEC_OID_RIPEMD160, CKM_RIPEMD160_HMAC, 20, 64 },
|
||||
{ NULL, 0, 0, 0 }
|
||||
};
|
||||
|
||||
@@ -163,7 +164,7 @@ int crypt_hash_final(struct crypt_hash *ctx, char *buffer, size_t length)
|
||||
return -EINVAL;
|
||||
|
||||
memcpy(buffer, tmp, length);
|
||||
memset(tmp, 0, sizeof(tmp));
|
||||
crypt_backend_memzero(tmp, sizeof(tmp));
|
||||
|
||||
if (tmp_len < length)
|
||||
return -EINVAL;
|
||||
@@ -265,7 +266,7 @@ int crypt_hmac_final(struct crypt_hmac *ctx, char *buffer, size_t length)
|
||||
return -EINVAL;
|
||||
|
||||
memcpy(buffer, tmp, length);
|
||||
memset(tmp, 0, sizeof(tmp));
|
||||
crypt_backend_memzero(tmp, sizeof(tmp));
|
||||
|
||||
if (tmp_len < length)
|
||||
return -EINVAL;
|
||||
@@ -308,9 +309,11 @@ int crypt_pbkdf(const char *kdf, const char *hash,
|
||||
char *key, size_t key_length,
|
||||
unsigned int iterations)
|
||||
{
|
||||
if (!kdf || strncmp(kdf, "pbkdf2", 6))
|
||||
struct hash_alg *ha = _get_alg(hash);
|
||||
|
||||
if (!ha || !kdf || strncmp(kdf, "pbkdf2", 6))
|
||||
return -EINVAL;
|
||||
|
||||
return pkcs5_pbkdf2(hash, password, password_length, salt, salt_length,
|
||||
iterations, key_length, key);
|
||||
iterations, key_length, key, ha->block_length);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* OPENSSL crypto backend implementation
|
||||
*
|
||||
* Copyright (C) 2010-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2012, Milan Broz
|
||||
* Copyright (C) 2010-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2017, Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -38,23 +38,79 @@
|
||||
static int crypto_backend_initialised = 0;
|
||||
|
||||
struct crypt_hash {
|
||||
EVP_MD_CTX md;
|
||||
EVP_MD_CTX *md;
|
||||
const EVP_MD *hash_id;
|
||||
int hash_len;
|
||||
};
|
||||
|
||||
struct crypt_hmac {
|
||||
HMAC_CTX md;
|
||||
HMAC_CTX *md;
|
||||
const EVP_MD *hash_id;
|
||||
int hash_len;
|
||||
};
|
||||
|
||||
/*
|
||||
* Compatible wrappers for OpenSSL < 1.1.0
|
||||
*/
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
|
||||
static void openssl_backend_init(void)
|
||||
{
|
||||
OpenSSL_add_all_algorithms();
|
||||
}
|
||||
|
||||
static const char *openssl_backend_version(void)
|
||||
{
|
||||
return SSLeay_version(SSLEAY_VERSION);
|
||||
}
|
||||
|
||||
static EVP_MD_CTX *EVP_MD_CTX_new(void)
|
||||
{
|
||||
EVP_MD_CTX *md = malloc(sizeof(*md));
|
||||
|
||||
if (md)
|
||||
EVP_MD_CTX_init(md);
|
||||
|
||||
return md;
|
||||
}
|
||||
|
||||
static void EVP_MD_CTX_free(EVP_MD_CTX *md)
|
||||
{
|
||||
EVP_MD_CTX_cleanup(md);
|
||||
free(md);
|
||||
}
|
||||
|
||||
static HMAC_CTX *HMAC_CTX_new(void)
|
||||
{
|
||||
HMAC_CTX *md = malloc(sizeof(*md));
|
||||
|
||||
if (md)
|
||||
HMAC_CTX_init(md);
|
||||
|
||||
return md;
|
||||
}
|
||||
|
||||
static void HMAC_CTX_free(HMAC_CTX *md)
|
||||
{
|
||||
HMAC_CTX_cleanup(md);
|
||||
free(md);
|
||||
}
|
||||
#else
|
||||
static void openssl_backend_init(void)
|
||||
{
|
||||
}
|
||||
|
||||
static const char *openssl_backend_version(void)
|
||||
{
|
||||
return OpenSSL_version(OPENSSL_VERSION);
|
||||
}
|
||||
#endif
|
||||
|
||||
int crypt_backend_init(struct crypt_device *ctx)
|
||||
{
|
||||
if (crypto_backend_initialised)
|
||||
return 0;
|
||||
|
||||
OpenSSL_add_all_algorithms();
|
||||
openssl_backend_init();
|
||||
|
||||
crypto_backend_initialised = 1;
|
||||
return 0;
|
||||
@@ -67,7 +123,7 @@ uint32_t crypt_backend_flags(void)
|
||||
|
||||
const char *crypt_backend_version(void)
|
||||
{
|
||||
return SSLeay_version(SSLEAY_VERSION);
|
||||
return openssl_backend_version();
|
||||
}
|
||||
|
||||
/* HASH */
|
||||
@@ -89,13 +145,21 @@ int crypt_hash_init(struct crypt_hash **ctx, const char *name)
|
||||
if (!h)
|
||||
return -ENOMEM;
|
||||
|
||||
h->md = EVP_MD_CTX_new();
|
||||
if (!h->md) {
|
||||
free(h);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
h->hash_id = EVP_get_digestbyname(name);
|
||||
if (!h->hash_id) {
|
||||
EVP_MD_CTX_free(h->md);
|
||||
free(h);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (EVP_DigestInit(&h->md, h->hash_id) != 1) {
|
||||
if (EVP_DigestInit_ex(h->md, h->hash_id, NULL) != 1) {
|
||||
EVP_MD_CTX_free(h->md);
|
||||
free(h);
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -107,7 +171,7 @@ int crypt_hash_init(struct crypt_hash **ctx, const char *name)
|
||||
|
||||
static int crypt_hash_restart(struct crypt_hash *ctx)
|
||||
{
|
||||
if (EVP_DigestInit(&ctx->md, ctx->hash_id) != 1)
|
||||
if (EVP_DigestInit_ex(ctx->md, ctx->hash_id, NULL) != 1)
|
||||
return -EINVAL;
|
||||
|
||||
return 0;
|
||||
@@ -115,7 +179,7 @@ static int crypt_hash_restart(struct crypt_hash *ctx)
|
||||
|
||||
int crypt_hash_write(struct crypt_hash *ctx, const char *buffer, size_t length)
|
||||
{
|
||||
if (EVP_DigestUpdate(&ctx->md, buffer, length) != 1)
|
||||
if (EVP_DigestUpdate(ctx->md, buffer, length) != 1)
|
||||
return -EINVAL;
|
||||
|
||||
return 0;
|
||||
@@ -129,11 +193,11 @@ int crypt_hash_final(struct crypt_hash *ctx, char *buffer, size_t length)
|
||||
if (length > (size_t)ctx->hash_len)
|
||||
return -EINVAL;
|
||||
|
||||
if (EVP_DigestFinal_ex(&ctx->md, tmp, &tmp_len) != 1)
|
||||
if (EVP_DigestFinal_ex(ctx->md, tmp, &tmp_len) != 1)
|
||||
return -EINVAL;
|
||||
|
||||
memcpy(buffer, tmp, length);
|
||||
memset(tmp, 0, sizeof(tmp));
|
||||
crypt_backend_memzero(tmp, sizeof(tmp));
|
||||
|
||||
if (tmp_len < length)
|
||||
return -EINVAL;
|
||||
@@ -146,7 +210,7 @@ int crypt_hash_final(struct crypt_hash *ctx, char *buffer, size_t length)
|
||||
|
||||
int crypt_hash_destroy(struct crypt_hash *ctx)
|
||||
{
|
||||
EVP_MD_CTX_cleanup(&ctx->md);
|
||||
EVP_MD_CTX_free(ctx->md);
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
free(ctx);
|
||||
return 0;
|
||||
@@ -167,14 +231,20 @@ int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
|
||||
if (!h)
|
||||
return -ENOMEM;
|
||||
|
||||
h->md = HMAC_CTX_new();
|
||||
if (!h->md) {
|
||||
free(h);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
h->hash_id = EVP_get_digestbyname(name);
|
||||
if (!h->hash_id) {
|
||||
HMAC_CTX_free(h->md);
|
||||
free(h);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
HMAC_CTX_init(&h->md);
|
||||
HMAC_Init_ex(&h->md, buffer, length, h->hash_id, NULL);
|
||||
HMAC_Init_ex(h->md, buffer, length, h->hash_id, NULL);
|
||||
|
||||
h->hash_len = EVP_MD_size(h->hash_id);
|
||||
*ctx = h;
|
||||
@@ -183,12 +253,12 @@ int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
|
||||
|
||||
static void crypt_hmac_restart(struct crypt_hmac *ctx)
|
||||
{
|
||||
HMAC_Init_ex(&ctx->md, NULL, 0, ctx->hash_id, NULL);
|
||||
HMAC_Init_ex(ctx->md, NULL, 0, ctx->hash_id, NULL);
|
||||
}
|
||||
|
||||
int crypt_hmac_write(struct crypt_hmac *ctx, const char *buffer, size_t length)
|
||||
{
|
||||
HMAC_Update(&ctx->md, (const unsigned char *)buffer, length);
|
||||
HMAC_Update(ctx->md, (const unsigned char *)buffer, length);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -200,10 +270,10 @@ int crypt_hmac_final(struct crypt_hmac *ctx, char *buffer, size_t length)
|
||||
if (length > (size_t)ctx->hash_len)
|
||||
return -EINVAL;
|
||||
|
||||
HMAC_Final(&ctx->md, tmp, &tmp_len);
|
||||
HMAC_Final(ctx->md, tmp, &tmp_len);
|
||||
|
||||
memcpy(buffer, tmp, length);
|
||||
memset(tmp, 0, sizeof(tmp));
|
||||
crypt_backend_memzero(tmp, sizeof(tmp));
|
||||
|
||||
if (tmp_len < length)
|
||||
return -EINVAL;
|
||||
@@ -215,7 +285,7 @@ int crypt_hmac_final(struct crypt_hmac *ctx, char *buffer, size_t length)
|
||||
|
||||
int crypt_hmac_destroy(struct crypt_hmac *ctx)
|
||||
{
|
||||
HMAC_CTX_cleanup(&ctx->md);
|
||||
HMAC_CTX_free(ctx->md);
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
free(ctx);
|
||||
return 0;
|
||||
@@ -250,7 +320,7 @@ int crypt_pbkdf(const char *kdf, const char *hash,
|
||||
return -EINVAL;
|
||||
|
||||
if (!PKCS5_PBKDF2_HMAC(password, (int)password_length,
|
||||
(unsigned char *)salt, (int)salt_length,
|
||||
(const unsigned char *)salt, (int)salt_length,
|
||||
(int)iterations, hash_id, (int)key_length, (unsigned char *)key))
|
||||
return -EINVAL;
|
||||
|
||||
|
||||
293
lib/crypto_backend/crypto_storage.c
Normal file
293
lib/crypto_backend/crypto_storage.c
Normal file
@@ -0,0 +1,293 @@
|
||||
/*
|
||||
* Generic wrapper for storage encryption modes and Initial Vectors
|
||||
* (reimplementation of some functions from Linux dm-crypt kernel)
|
||||
*
|
||||
* Copyright (C) 2014-2017, Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This file is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this file; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include "bitops.h"
|
||||
#include "crypto_backend.h"
|
||||
|
||||
#define SECTOR_SHIFT 9
|
||||
#define SECTOR_SIZE (1 << SECTOR_SHIFT)
|
||||
|
||||
/*
|
||||
* Internal IV helper
|
||||
* IV documentation: https://gitlab.com/cryptsetup/cryptsetup/wikis/DMCrypt
|
||||
*/
|
||||
struct crypt_sector_iv {
|
||||
enum { IV_NONE, IV_NULL, IV_PLAIN, IV_PLAIN64, IV_ESSIV, IV_BENBI } type;
|
||||
int iv_size;
|
||||
char *iv;
|
||||
struct crypt_cipher *essiv_cipher;
|
||||
int benbi_shift;
|
||||
};
|
||||
|
||||
/* Block encryption storage context */
|
||||
struct crypt_storage {
|
||||
uint64_t sector_start;
|
||||
struct crypt_cipher *cipher;
|
||||
struct crypt_sector_iv cipher_iv;
|
||||
};
|
||||
|
||||
static int int_log2(unsigned int x)
|
||||
{
|
||||
int r = 0;
|
||||
for (x >>= 1; x > 0; x >>= 1)
|
||||
r++;
|
||||
return r;
|
||||
}
|
||||
|
||||
static int crypt_sector_iv_init(struct crypt_sector_iv *ctx,
|
||||
const char *cipher_name, const char *mode_name,
|
||||
const char *iv_name, char *key, size_t key_length)
|
||||
{
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
|
||||
ctx->iv_size = crypt_cipher_blocksize(cipher_name);
|
||||
if (ctx->iv_size < 0)
|
||||
return -ENOENT;
|
||||
|
||||
if (!iv_name ||
|
||||
!strcmp(cipher_name, "cipher_null") ||
|
||||
!strcmp(mode_name, "ecb")) {
|
||||
ctx->type = IV_NONE;
|
||||
ctx->iv_size = 0;
|
||||
return 0;
|
||||
} else if (!strcasecmp(iv_name, "null")) {
|
||||
ctx->type = IV_NULL;
|
||||
} else if (!strcasecmp(iv_name, "plain64")) {
|
||||
ctx->type = IV_PLAIN64;
|
||||
} else if (!strcasecmp(iv_name, "plain")) {
|
||||
ctx->type = IV_PLAIN;
|
||||
} else if (!strncasecmp(iv_name, "essiv:", 6)) {
|
||||
struct crypt_hash *h = NULL;
|
||||
char *hash_name = strchr(iv_name, ':');
|
||||
int hash_size;
|
||||
char tmp[256];
|
||||
int r;
|
||||
|
||||
if (!hash_name)
|
||||
return -EINVAL;
|
||||
|
||||
hash_size = crypt_hash_size(++hash_name);
|
||||
if (hash_size < 0)
|
||||
return -ENOENT;
|
||||
|
||||
if ((unsigned)hash_size > sizeof(tmp))
|
||||
return -EINVAL;
|
||||
|
||||
if (crypt_hash_init(&h, hash_name))
|
||||
return -EINVAL;
|
||||
|
||||
r = crypt_hash_write(h, key, key_length);
|
||||
if (r) {
|
||||
crypt_hash_destroy(h);
|
||||
return r;
|
||||
}
|
||||
|
||||
r = crypt_hash_final(h, tmp, hash_size);
|
||||
crypt_hash_destroy(h);
|
||||
if (r) {
|
||||
crypt_backend_memzero(tmp, sizeof(tmp));
|
||||
return r;
|
||||
}
|
||||
|
||||
r = crypt_cipher_init(&ctx->essiv_cipher, cipher_name, "ecb",
|
||||
tmp, hash_size);
|
||||
crypt_backend_memzero(tmp, sizeof(tmp));
|
||||
if (r)
|
||||
return r;
|
||||
|
||||
ctx->type = IV_ESSIV;
|
||||
} else if (!strncasecmp(iv_name, "benbi", 5)) {
|
||||
int log = int_log2(ctx->iv_size);
|
||||
if (log > SECTOR_SHIFT)
|
||||
return -EINVAL;
|
||||
|
||||
ctx->type = IV_BENBI;
|
||||
ctx->benbi_shift = SECTOR_SHIFT - log;
|
||||
} else
|
||||
return -ENOENT;
|
||||
|
||||
ctx->iv = malloc(ctx->iv_size);
|
||||
if (!ctx->iv)
|
||||
return -ENOMEM;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int crypt_sector_iv_generate(struct crypt_sector_iv *ctx, uint64_t sector)
|
||||
{
|
||||
uint64_t val;
|
||||
|
||||
switch (ctx->type) {
|
||||
case IV_NONE:
|
||||
break;
|
||||
case IV_NULL:
|
||||
memset(ctx->iv, 0, ctx->iv_size);
|
||||
break;
|
||||
case IV_PLAIN:
|
||||
memset(ctx->iv, 0, ctx->iv_size);
|
||||
*(uint32_t *)ctx->iv = cpu_to_le32(sector & 0xffffffff);
|
||||
break;
|
||||
case IV_PLAIN64:
|
||||
memset(ctx->iv, 0, ctx->iv_size);
|
||||
*(uint64_t *)ctx->iv = cpu_to_le64(sector);
|
||||
break;
|
||||
case IV_ESSIV:
|
||||
memset(ctx->iv, 0, ctx->iv_size);
|
||||
*(uint64_t *)ctx->iv = cpu_to_le64(sector);
|
||||
return crypt_cipher_encrypt(ctx->essiv_cipher,
|
||||
ctx->iv, ctx->iv, ctx->iv_size, NULL, 0);
|
||||
break;
|
||||
case IV_BENBI:
|
||||
memset(ctx->iv, 0, ctx->iv_size);
|
||||
val = cpu_to_be64((sector << ctx->benbi_shift) + 1);
|
||||
memcpy(ctx->iv + ctx->iv_size - sizeof(val), &val, sizeof(val));
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int crypt_sector_iv_destroy(struct crypt_sector_iv *ctx)
|
||||
{
|
||||
if (ctx->type == IV_ESSIV)
|
||||
crypt_cipher_destroy(ctx->essiv_cipher);
|
||||
|
||||
if (ctx->iv) {
|
||||
memset(ctx->iv, 0, ctx->iv_size);
|
||||
free(ctx->iv);
|
||||
}
|
||||
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Block encryption storage wrappers */
|
||||
|
||||
int crypt_storage_init(struct crypt_storage **ctx,
|
||||
uint64_t sector_start,
|
||||
const char *cipher,
|
||||
const char *cipher_mode,
|
||||
char *key, size_t key_length)
|
||||
{
|
||||
struct crypt_storage *s;
|
||||
char mode_name[64];
|
||||
char *cipher_iv = NULL;
|
||||
int r = -EIO;
|
||||
|
||||
s = malloc(sizeof(*s));
|
||||
if (!s)
|
||||
return -ENOMEM;
|
||||
memset(s, 0, sizeof(*s));
|
||||
|
||||
/* Remove IV if present */
|
||||
strncpy(mode_name, cipher_mode, sizeof(mode_name));
|
||||
mode_name[sizeof(mode_name) - 1] = 0;
|
||||
cipher_iv = strchr(mode_name, '-');
|
||||
if (cipher_iv) {
|
||||
*cipher_iv = '\0';
|
||||
cipher_iv++;
|
||||
}
|
||||
|
||||
r = crypt_cipher_init(&s->cipher, cipher, mode_name, key, key_length);
|
||||
if (r) {
|
||||
crypt_storage_destroy(s);
|
||||
return r;
|
||||
}
|
||||
|
||||
r = crypt_sector_iv_init(&s->cipher_iv, cipher, mode_name, cipher_iv, key, key_length);
|
||||
if (r) {
|
||||
crypt_storage_destroy(s);
|
||||
return r;
|
||||
}
|
||||
|
||||
s->sector_start = sector_start;
|
||||
|
||||
*ctx = s;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int crypt_storage_decrypt(struct crypt_storage *ctx,
|
||||
uint64_t sector, size_t count,
|
||||
char *buffer)
|
||||
{
|
||||
unsigned int i;
|
||||
int r = 0;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
r = crypt_sector_iv_generate(&ctx->cipher_iv, sector + i);
|
||||
if (r)
|
||||
break;
|
||||
r = crypt_cipher_decrypt(ctx->cipher,
|
||||
&buffer[i * SECTOR_SIZE],
|
||||
&buffer[i * SECTOR_SIZE],
|
||||
SECTOR_SIZE,
|
||||
ctx->cipher_iv.iv,
|
||||
ctx->cipher_iv.iv_size);
|
||||
if (r)
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int crypt_storage_encrypt(struct crypt_storage *ctx,
|
||||
uint64_t sector, size_t count,
|
||||
char *buffer)
|
||||
{
|
||||
unsigned int i;
|
||||
int r = 0;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
r = crypt_sector_iv_generate(&ctx->cipher_iv, sector + i);
|
||||
if (r)
|
||||
break;
|
||||
r = crypt_cipher_encrypt(ctx->cipher,
|
||||
&buffer[i * SECTOR_SIZE],
|
||||
&buffer[i * SECTOR_SIZE],
|
||||
SECTOR_SIZE,
|
||||
ctx->cipher_iv.iv,
|
||||
ctx->cipher_iv.iv_size);
|
||||
if (r)
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int crypt_storage_destroy(struct crypt_storage *ctx)
|
||||
{
|
||||
if (!ctx)
|
||||
return 0;
|
||||
|
||||
crypt_sector_iv_destroy(&ctx->cipher_iv);
|
||||
|
||||
if (ctx->cipher)
|
||||
crypt_cipher_destroy(ctx->cipher);
|
||||
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
free(ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -4,7 +4,8 @@
|
||||
* Copyright (C) 2004 Free Software Foundation
|
||||
*
|
||||
* cryptsetup related changes
|
||||
* Copyright (C) 2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2017, Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -26,6 +27,25 @@
|
||||
#include <alloca.h>
|
||||
#include "crypto_backend.h"
|
||||
|
||||
static int hash_buf(const char *src, size_t src_len,
|
||||
char *dst, size_t dst_len,
|
||||
const char *hash_name)
|
||||
{
|
||||
struct crypt_hash *hd = NULL;
|
||||
int r;
|
||||
|
||||
if (crypt_hash_init(&hd, hash_name))
|
||||
return -EINVAL;
|
||||
|
||||
r = crypt_hash_write(hd, src, src_len);
|
||||
|
||||
if (!r)
|
||||
r = crypt_hash_final(hd, dst, dst_len);
|
||||
|
||||
crypt_hash_destroy(hd);
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
* 5.2 PBKDF2
|
||||
*
|
||||
@@ -52,17 +72,26 @@
|
||||
* Output: DK derived key, a dkLen-octet string
|
||||
*/
|
||||
|
||||
/*
|
||||
* if hash_block_size is not zero, the HMAC key is pre-hashed
|
||||
* inside this function.
|
||||
* This prevents situation when crypto backend doesn't support
|
||||
* long HMAC keys or it tries hash long key in every iteration
|
||||
* (because of crypt_final() cannot do simple key reset.
|
||||
*/
|
||||
|
||||
#define MAX_PRF_BLOCK_LEN 80
|
||||
|
||||
int pkcs5_pbkdf2(const char *hash,
|
||||
const char *P, size_t Plen,
|
||||
const char *S, size_t Slen,
|
||||
unsigned int c, unsigned int dkLen,
|
||||
char *DK)
|
||||
char *DK, unsigned int hash_block_size)
|
||||
{
|
||||
struct crypt_hmac *hmac;
|
||||
char U[MAX_PRF_BLOCK_LEN];
|
||||
char T[MAX_PRF_BLOCK_LEN];
|
||||
char P_hash[MAX_PRF_BLOCK_LEN];
|
||||
int i, k, rc = -EINVAL;
|
||||
unsigned int u, hLen, l, r;
|
||||
size_t tmplen = Slen + 4;
|
||||
@@ -152,8 +181,18 @@ int pkcs5_pbkdf2(const char *hash,
|
||||
*
|
||||
*/
|
||||
|
||||
if (crypt_hmac_init(&hmac, hash, P, Plen))
|
||||
return -EINVAL;
|
||||
/* If hash_block_size is provided, hash password in advance. */
|
||||
if (hash_block_size > 0 && Plen > hash_block_size) {
|
||||
if (hash_buf(P, Plen, P_hash, hLen, hash))
|
||||
return -EINVAL;
|
||||
|
||||
if (crypt_hmac_init(&hmac, hash, P_hash, hLen))
|
||||
return -EINVAL;
|
||||
crypt_backend_memzero(P_hash, sizeof(P_hash));
|
||||
} else {
|
||||
if (crypt_hmac_init(&hmac, hash, P, Plen))
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
for (i = 1; (unsigned int) i <= l; i++) {
|
||||
memset(T, 0, hLen);
|
||||
@@ -185,5 +224,203 @@ int pkcs5_pbkdf2(const char *hash,
|
||||
rc = 0;
|
||||
out:
|
||||
crypt_hmac_destroy(hmac);
|
||||
crypt_backend_memzero(U, sizeof(U));
|
||||
crypt_backend_memzero(T, sizeof(T));
|
||||
crypt_backend_memzero(tmp, tmplen);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
#if 0
|
||||
#include <stdio.h>
|
||||
|
||||
struct test_vector {
|
||||
const char *hash;
|
||||
unsigned int hash_block_length;
|
||||
unsigned int iterations;
|
||||
const char *password;
|
||||
unsigned int password_length;
|
||||
const char *salt;
|
||||
unsigned int salt_length;
|
||||
const char *output;
|
||||
unsigned int output_length;
|
||||
};
|
||||
|
||||
struct test_vector test_vectors[] = {
|
||||
/* RFC 3962 */
|
||||
{
|
||||
"sha1", 64, 1,
|
||||
"password", 8,
|
||||
"ATHENA.MIT.EDUraeburn", 21,
|
||||
"\xcd\xed\xb5\x28\x1b\xb2\xf8\x01"
|
||||
"\x56\x5a\x11\x22\xb2\x56\x35\x15"
|
||||
"\x0a\xd1\xf7\xa0\x4b\xb9\xf3\xa3"
|
||||
"\x33\xec\xc0\xe2\xe1\xf7\x08\x37", 32
|
||||
}, {
|
||||
"sha1", 64, 2,
|
||||
"password", 8,
|
||||
"ATHENA.MIT.EDUraeburn", 21,
|
||||
"\x01\xdb\xee\x7f\x4a\x9e\x24\x3e"
|
||||
"\x98\x8b\x62\xc7\x3c\xda\x93\x5d"
|
||||
"\xa0\x53\x78\xb9\x32\x44\xec\x8f"
|
||||
"\x48\xa9\x9e\x61\xad\x79\x9d\x86", 32
|
||||
}, {
|
||||
"sha1", 64, 1200,
|
||||
"password", 8,
|
||||
"ATHENA.MIT.EDUraeburn", 21,
|
||||
"\x5c\x08\xeb\x61\xfd\xf7\x1e\x4e"
|
||||
"\x4e\xc3\xcf\x6b\xa1\xf5\x51\x2b"
|
||||
"\xa7\xe5\x2d\xdb\xc5\xe5\x14\x2f"
|
||||
"\x70\x8a\x31\xe2\xe6\x2b\x1e\x13", 32
|
||||
}, {
|
||||
"sha1", 64, 5,
|
||||
"password", 8,
|
||||
"\0224VxxV4\022", 8, // "\x1234567878563412
|
||||
"\xd1\xda\xa7\x86\x15\xf2\x87\xe6"
|
||||
"\xa1\xc8\xb1\x20\xd7\x06\x2a\x49"
|
||||
"\x3f\x98\xd2\x03\xe6\xbe\x49\xa6"
|
||||
"\xad\xf4\xfa\x57\x4b\x6e\x64\xee", 32
|
||||
}, {
|
||||
"sha1", 64, 1200,
|
||||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
||||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 64,
|
||||
"pass phrase equals block size", 29,
|
||||
"\x13\x9c\x30\xc0\x96\x6b\xc3\x2b"
|
||||
"\xa5\x5f\xdb\xf2\x12\x53\x0a\xc9"
|
||||
"\xc5\xec\x59\xf1\xa4\x52\xf5\xcc"
|
||||
"\x9a\xd9\x40\xfe\xa0\x59\x8e\xd1", 32
|
||||
}, {
|
||||
"sha1", 64, 1200,
|
||||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
||||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 65,
|
||||
"pass phrase exceeds block size", 30,
|
||||
"\x9c\xca\xd6\xd4\x68\x77\x0c\xd5"
|
||||
"\x1b\x10\xe6\xa6\x87\x21\xbe\x61"
|
||||
"\x1a\x8b\x4d\x28\x26\x01\xdb\x3b"
|
||||
"\x36\xbe\x92\x46\x91\x5e\xc8\x2a", 32
|
||||
}, {
|
||||
"sha1", 64, 50,
|
||||
"\360\235\204\236", 4, // g-clef ("\xf09d849e)
|
||||
"EXAMPLE.COMpianist", 18,
|
||||
"\x6b\x9c\xf2\x6d\x45\x45\x5a\x43"
|
||||
"\xa5\xb8\xbb\x27\x6a\x40\x3b\x39"
|
||||
"\xe7\xfe\x37\xa0\xc4\x1e\x02\xc2"
|
||||
"\x81\xff\x30\x69\xe1\xe9\x4f\x52", 32
|
||||
}, {
|
||||
/* RFC-6070 */
|
||||
"sha1", 64, 1,
|
||||
"password", 8,
|
||||
"salt", 4,
|
||||
"\x0c\x60\xc8\x0f\x96\x1f\x0e\x71\xf3\xa9"
|
||||
"\xb5\x24\xaf\x60\x12\x06\x2f\xe0\x37\xa6", 20
|
||||
}, {
|
||||
"sha1", 64, 2,
|
||||
"password", 8,
|
||||
"salt", 4,
|
||||
"\xea\x6c\x01\x4d\xc7\x2d\x6f\x8c\xcd\x1e"
|
||||
"\xd9\x2a\xce\x1d\x41\xf0\xd8\xde\x89\x57", 20
|
||||
}, {
|
||||
"sha1", 64, 4096,
|
||||
"password", 8,
|
||||
"salt", 4,
|
||||
"\x4b\x00\x79\x01\xb7\x65\x48\x9a\xbe\xad"
|
||||
"\x49\xd9\x26\xf7\x21\xd0\x65\xa4\x29\xc1", 20
|
||||
}, {
|
||||
"sha1", 64, 16777216,
|
||||
"password", 8,
|
||||
"salt", 4,
|
||||
"\xee\xfe\x3d\x61\xcd\x4d\xa4\xe4\xe9\x94"
|
||||
"\x5b\x3d\x6b\xa2\x15\x8c\x26\x34\xe9\x84", 20
|
||||
}, {
|
||||
"sha1", 64, 4096,
|
||||
"passwordPASSWORDpassword", 24,
|
||||
"saltSALTsaltSALTsaltSALTsaltSALTsalt", 36,
|
||||
"\x3d\x2e\xec\x4f\xe4\x1c\x84\x9b\x80\xc8"
|
||||
"\xd8\x36\x62\xc0\xe4\x4a\x8b\x29\x1a\x96"
|
||||
"\x4c\xf2\xf0\x70\x38", 25
|
||||
}, {
|
||||
"sha1", 64, 4096,
|
||||
"pass\0word", 9,
|
||||
"sa\0lt", 5,
|
||||
"\x56\xfa\x6a\xa7\x55\x48\x09\x9d\xcc\x37"
|
||||
"\xd7\xf0\x34\x25\xe0\xc3", 16
|
||||
}, {
|
||||
/* empty password test */
|
||||
"sha1", 64, 2,
|
||||
"", 0,
|
||||
"salt", 4,
|
||||
"\x13\x3a\x4c\xe8\x37\xb4\xd2\x52\x1e\xe2"
|
||||
"\xbf\x03\xe1\x1c\x71\xca\x79\x4e\x07\x97", 20
|
||||
}, {
|
||||
/* Password exceeds block size test */
|
||||
"sha256", 64, 1200,
|
||||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
||||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 65,
|
||||
"pass phrase exceeds block size", 30,
|
||||
"\x22\x34\x4b\xc4\xb6\xe3\x26\x75"
|
||||
"\xa8\x09\x0f\x3e\xa8\x0b\xe0\x1d"
|
||||
"\x5f\x95\x12\x6a\x2c\xdd\xc3\xfa"
|
||||
"\xcc\x4a\x5e\x6d\xca\x04\xec\x58", 32
|
||||
}, {
|
||||
"sha512", 128, 1200,
|
||||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
||||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
||||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
||||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 129,
|
||||
"pass phrase exceeds block size", 30,
|
||||
"\x0f\xb2\xed\x2c\x0e\x6e\xfb\x7d"
|
||||
"\x7d\x8e\xdd\x58\x01\xb4\x59\x72"
|
||||
"\x99\x92\x16\x30\x5e\xa4\x36\x8d"
|
||||
"\x76\x14\x80\xf3\xe3\x7a\x22\xb9", 32
|
||||
}, {
|
||||
"whirlpool", 64, 1200,
|
||||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
||||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 65,
|
||||
"pass phrase exceeds block size", 30,
|
||||
"\x9c\x1c\x74\xf5\x88\x26\xe7\x6a"
|
||||
"\x53\x58\xf4\x0c\x39\xe7\x80\x89"
|
||||
"\x07\xc0\x31\x19\x9a\x50\xa2\x48"
|
||||
"\xf1\xd9\xfe\x78\x64\xe5\x84\x50", 32
|
||||
}
|
||||
};
|
||||
|
||||
static void printhex(const char *s, const char *buf, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
printf("%s: ", s);
|
||||
for (i = 0; i < len; i++)
|
||||
printf("\\x%02x", (unsigned char)buf[i]);
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
static int pkcs5_pbkdf2_test_vectors(void)
|
||||
{
|
||||
char result[64];
|
||||
unsigned int i, j;
|
||||
struct test_vector *vec;
|
||||
|
||||
for (i = 0; i < (sizeof(test_vectors) / sizeof(*test_vectors)); i++) {
|
||||
vec = &test_vectors[i];
|
||||
for (j = 1; j <= vec->output_length; j++) {
|
||||
if (pkcs5_pbkdf2(vec->hash,
|
||||
vec->password, vec->password_length,
|
||||
vec->salt, vec->salt_length,
|
||||
vec->iterations,
|
||||
j, result, vec->hash_block_length)) {
|
||||
printf("pbkdf2 failed, vector %d\n", i);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (memcmp(result, vec->output, j) != 0) {
|
||||
printf("vector %u\n", i);
|
||||
printhex(" got", result, j);
|
||||
printhex("want", vec->output, j);
|
||||
return -EINVAL;
|
||||
}
|
||||
memset(result, 0, sizeof(result));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* PBKDF performance check
|
||||
* Copyright (C) 2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012, Milan Broz
|
||||
* Copyright (C) 2012-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2017, Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -18,6 +18,7 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
@@ -25,12 +26,24 @@
|
||||
|
||||
static long time_ms(struct rusage *start, struct rusage *end)
|
||||
{
|
||||
int count_kernel_time = 0;
|
||||
long ms;
|
||||
|
||||
if (crypt_backend_flags() & CRYPT_BACKEND_KERNEL)
|
||||
count_kernel_time = 1;
|
||||
|
||||
/*
|
||||
* FIXME: if there is no self usage info, count system time.
|
||||
* This seem like getrusage() bug in some hypervisors...
|
||||
*/
|
||||
if (!end->ru_utime.tv_sec && !start->ru_utime.tv_sec &&
|
||||
!end->ru_utime.tv_usec && !start->ru_utime.tv_usec)
|
||||
count_kernel_time = 1;
|
||||
|
||||
ms = (end->ru_utime.tv_sec - start->ru_utime.tv_sec) * 1000;
|
||||
ms += (end->ru_utime.tv_usec - start->ru_utime.tv_usec) / 1000;
|
||||
|
||||
if (crypt_backend_flags() & CRYPT_BACKEND_KERNEL) {
|
||||
if (count_kernel_time) {
|
||||
ms += (end->ru_stime.tv_sec - start->ru_stime.tv_sec) * 1000;
|
||||
ms += (end->ru_stime.tv_usec - start->ru_stime.tv_usec) / 1000;
|
||||
}
|
||||
@@ -40,31 +53,39 @@ static long time_ms(struct rusage *start, struct rusage *end)
|
||||
|
||||
/* This code benchmarks PBKDF and returns iterations/second using specified hash */
|
||||
int crypt_pbkdf_check(const char *kdf, const char *hash,
|
||||
const char *password, size_t password_size,
|
||||
const char *salt, size_t salt_size,
|
||||
uint64_t *iter_secs)
|
||||
const char *password, size_t password_length,
|
||||
const char *salt, size_t salt_length,
|
||||
size_t key_length, uint64_t *iter_secs)
|
||||
{
|
||||
struct rusage rstart, rend;
|
||||
int r = 0, step = 0;
|
||||
long ms = 0;
|
||||
char buf;
|
||||
char *key = NULL;
|
||||
unsigned int iterations;
|
||||
|
||||
if (!kdf || !hash)
|
||||
if (!kdf || !hash || key_length <= 0)
|
||||
return -EINVAL;
|
||||
|
||||
key = malloc(key_length);
|
||||
if (!key)
|
||||
return -ENOMEM;
|
||||
|
||||
iterations = 1 << 15;
|
||||
while (ms < 500) {
|
||||
if (getrusage(RUSAGE_SELF, &rstart) < 0)
|
||||
return -EINVAL;
|
||||
while (1) {
|
||||
if (getrusage(RUSAGE_SELF, &rstart) < 0) {
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
r = crypt_pbkdf(kdf, hash, password, password_size, salt,
|
||||
salt_size, &buf, 1, iterations);
|
||||
r = crypt_pbkdf(kdf, hash, password, password_length, salt,
|
||||
salt_length, key, key_length, iterations);
|
||||
if (r < 0)
|
||||
return r;
|
||||
goto out;
|
||||
|
||||
if (getrusage(RUSAGE_SELF, &rend) < 0)
|
||||
return -EINVAL;
|
||||
if (getrusage(RUSAGE_SELF, &rend) < 0) {
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ms = time_ms(&rstart, &rend);
|
||||
if (ms > 500)
|
||||
@@ -79,11 +100,18 @@ int crypt_pbkdf_check(const char *kdf, const char *hash,
|
||||
else
|
||||
iterations <<= 1;
|
||||
|
||||
if (++step > 10 || !iterations)
|
||||
return -EINVAL;
|
||||
if (++step > 10 || !iterations) {
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
if (iter_secs)
|
||||
*iter_secs = (iterations * 1000) / ms;
|
||||
out:
|
||||
if (key) {
|
||||
crypt_backend_memzero(key, key_length);
|
||||
free(key);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/*
|
||||
* libcryptsetup - cryptsetup library internal
|
||||
*
|
||||
* Copyright (C) 2004, Christophe Saout <christophe@saout.de>
|
||||
* Copyright (C) 2004, Jana Saout <jana@saout.de>
|
||||
* Copyright (C) 2004-2007, Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2012, Milan Broz
|
||||
* Copyright (C) 2009-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2017, Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -24,10 +24,6 @@
|
||||
#ifndef INTERNAL_H
|
||||
#define INTERNAL_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
@@ -61,8 +57,8 @@ struct volume_key {
|
||||
char key[];
|
||||
};
|
||||
|
||||
struct volume_key *crypt_alloc_volume_key(unsigned keylength, const char *key);
|
||||
struct volume_key *crypt_generate_volume_key(struct crypt_device *cd, unsigned keylength);
|
||||
struct volume_key *crypt_alloc_volume_key(size_t keylength, const char *key);
|
||||
struct volume_key *crypt_generate_volume_key(struct crypt_device *cd, size_t keylength);
|
||||
void crypt_free_volume_key(struct volume_key *vk);
|
||||
|
||||
/* Device backend */
|
||||
@@ -79,6 +75,9 @@ int device_block_size(struct device *device);
|
||||
int device_read_ahead(struct device *device, uint32_t *read_ahead);
|
||||
int device_size(struct device *device, uint64_t *size);
|
||||
int device_open(struct device *device, int flags);
|
||||
void device_disable_direct_io(struct device *device);
|
||||
int device_is_identical(struct device *device1, struct device *device2);
|
||||
|
||||
|
||||
enum devcheck { DEV_OK = 0, DEV_EXCL = 1, DEV_SHARED = 2 };
|
||||
int device_block_adjust(struct crypt_device *cd,
|
||||
@@ -96,16 +95,23 @@ struct device *crypt_data_device(struct crypt_device *cd);
|
||||
int crypt_confirm(struct crypt_device *cd, const char *msg);
|
||||
|
||||
char *crypt_lookup_dev(const char *dev_id);
|
||||
int crypt_sysfs_get_rotational(int major, int minor, int *rotational);
|
||||
int crypt_dev_is_rotational(int major, int minor);
|
||||
int crypt_dev_is_partition(const char *dev_path);
|
||||
char *crypt_get_partition_device(const char *dev_path, uint64_t offset, uint64_t size);
|
||||
char *crypt_get_base_device(const char *dev_path);
|
||||
uint64_t crypt_dev_partition_offset(const char *dev_path);
|
||||
|
||||
ssize_t write_buffer(int fd, const void *buf, size_t count);
|
||||
ssize_t read_buffer(int fd, void *buf, size_t count);
|
||||
ssize_t write_blockwise(int fd, int bsize, void *buf, size_t count);
|
||||
ssize_t read_blockwise(int fd, int bsize, void *_buf, size_t count);
|
||||
ssize_t write_lseek_blockwise(int fd, int bsize, char *buf, size_t count, off_t offset);
|
||||
ssize_t read_blockwise(int fd, int bsize, void *buf, size_t count);
|
||||
ssize_t write_lseek_blockwise(int fd, int bsize, void *buf, size_t count, off_t offset);
|
||||
ssize_t read_lseek_blockwise(int fd, int bsize, void *buf, size_t count, off_t offset);
|
||||
|
||||
unsigned crypt_getpagesize(void);
|
||||
int init_crypto(struct crypt_device *ctx);
|
||||
|
||||
void logger(struct crypt_device *cd, int class, const char *file, int line, const char *format, ...);
|
||||
void logger(struct crypt_device *cd, int class, const char *file, int line, const char *format, ...) __attribute__ ((format (printf, 5, 6)));
|
||||
#define log_dbg(x...) logger(NULL, CRYPT_LOG_DEBUG, __FILE__, __LINE__, x)
|
||||
#define log_std(c, x...) logger(c, CRYPT_LOG_NORMAL, __FILE__, __LINE__, x)
|
||||
#define log_verbose(c, x...) logger(c, CRYPT_LOG_VERBOSE, __FILE__, __LINE__, x)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/*
|
||||
* libcryptsetup - cryptsetup library
|
||||
*
|
||||
* Copyright (C) 2004, Christophe Saout <christophe@saout.de>
|
||||
* Copyright (C) 2004, Jana Saout <jana@saout.de>
|
||||
* Copyright (C) 2004-2007, Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2012, Milan Broz
|
||||
* Copyright (C) 2009-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2017, Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -136,7 +136,7 @@ void crypt_log(struct crypt_device *cd, int level, const char *msg);
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* Set confirmation callback (yes/no)
|
||||
* Set confirmation callback (yes/no).
|
||||
*
|
||||
* If code need confirmation (like resetting uuid or restoring LUKS header from file)
|
||||
* this function is called. If not defined, everything is confirmed.
|
||||
@@ -156,7 +156,7 @@ void crypt_set_confirm_callback(struct crypt_device *cd,
|
||||
void *usrptr);
|
||||
|
||||
/**
|
||||
* Set password query callback.
|
||||
* Set password query callback. DEPRECATED
|
||||
*
|
||||
* If code need @e _interactive_ query for password, this callback is called.
|
||||
* If not defined, compiled-in default is called (uses terminal input).
|
||||
@@ -176,6 +176,7 @@ void crypt_set_confirm_callback(struct crypt_device *cd,
|
||||
* @note Only zero terminated passwords can be entered this way, for complex
|
||||
* use API functions directly.
|
||||
* @note Maximal length of password is limited to @e length @e - @e 1 (minimal 511 chars)
|
||||
* @note This function is DEPRECATED and will be removed in future versions.
|
||||
*
|
||||
* @see Callback function is used in these call provided, that certain conditions are met:
|
||||
* @li crypt_keyslot_add_by_passphrase
|
||||
@@ -192,7 +193,7 @@ void crypt_set_password_callback(struct crypt_device *cd,
|
||||
|
||||
/**
|
||||
* Set timeout for interactive password entry using default
|
||||
* password callback
|
||||
* password callback. DEPRECATED
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param timeout_sec timeout in seconds
|
||||
@@ -200,16 +201,18 @@ void crypt_set_password_callback(struct crypt_device *cd,
|
||||
void crypt_set_timeout(struct crypt_device *cd, uint64_t timeout_sec);
|
||||
|
||||
/**
|
||||
* Set number of retries in case password input has been incorrect
|
||||
* Set number of retries in case password input has been incorrect. DEPRECATED.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param tries the number
|
||||
*
|
||||
* @note This function is DEPRECATED and will be removed in future versions.
|
||||
*/
|
||||
void crypt_set_password_retry(struct crypt_device *cd, int tries);
|
||||
|
||||
/**
|
||||
* Set how long should cryptsetup iterate in PBKDF2 function.
|
||||
* Default value heads towards the iterations which takes around 1 second
|
||||
* Default value heads towards the iterations which takes around 1 second.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param iteration_time_ms the time in ms
|
||||
@@ -220,10 +223,12 @@ void crypt_set_iterarion_time(struct crypt_device *cd, uint64_t iteration_time_m
|
||||
|
||||
/**
|
||||
* Set whether passphrase will be verified on input
|
||||
* (user has to input same passphrase twice)
|
||||
* (user has to input same passphrase twice). DEPRECATED
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param password_verify @e 0 = false, @e !0 true
|
||||
*
|
||||
* @note This function is DEPRECATED and will be removed in future versions.
|
||||
*/
|
||||
void crypt_set_password_verify(struct crypt_device *cd, int password_verify);
|
||||
|
||||
@@ -261,7 +266,7 @@ int crypt_set_data_device(struct crypt_device *cd, const char *device);
|
||||
void crypt_set_rng_type(struct crypt_device *cd, int rng_type);
|
||||
|
||||
/**
|
||||
* Get which RNG (random number generator) is used for generating long term key
|
||||
* Get which RNG (random number generator) is used for generating long term key.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @return RNG type on success or negative errno value otherwise.
|
||||
@@ -272,7 +277,7 @@ int crypt_get_rng_type(struct crypt_device *cd);
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* Helper to lock/unlock memory to avoid swap sensitive data to disk
|
||||
* Helper to lock/unlock memory to avoid swap sensitive data to disk.
|
||||
*
|
||||
* @param cd crypt device handle, can be @e NULL
|
||||
* @param lock 0 to unlock otherwise lock memory
|
||||
@@ -304,7 +309,7 @@ int crypt_memory_lock(struct crypt_device *cd, int lock);
|
||||
#define CRYPT_LOOPAES "LOOPAES"
|
||||
/** dm-verity mode */
|
||||
#define CRYPT_VERITY "VERITY"
|
||||
/** TCRYPT (TrueCrypt-compatible) mode */
|
||||
/** TCRYPT (TrueCrypt-compatible and VeraCrypt-compatible) mode */
|
||||
#define CRYPT_TCRYPT "TCRYPT"
|
||||
|
||||
/**
|
||||
@@ -317,7 +322,7 @@ const char *crypt_get_type(struct crypt_device *cd);
|
||||
|
||||
/**
|
||||
*
|
||||
* Structure used as parameter for PLAIN device type
|
||||
* Structure used as parameter for PLAIN device type.
|
||||
*
|
||||
* @see crypt_format
|
||||
*/
|
||||
@@ -329,7 +334,7 @@ struct crypt_params_plain {
|
||||
};
|
||||
|
||||
/**
|
||||
* Structure used as parameter for LUKS device type
|
||||
* Structure used as parameter for LUKS device type.
|
||||
*
|
||||
* @see crypt_format, crypt_load
|
||||
*
|
||||
@@ -345,7 +350,7 @@ struct crypt_params_luks1 {
|
||||
|
||||
/**
|
||||
*
|
||||
* Structure used as parameter for loop-AES device type
|
||||
* Structure used as parameter for loop-AES device type.
|
||||
*
|
||||
* @see crypt_format
|
||||
*
|
||||
@@ -358,7 +363,7 @@ struct crypt_params_loopaes {
|
||||
|
||||
/**
|
||||
*
|
||||
* Structure used as parameter for dm-verity device type
|
||||
* Structure used as parameter for dm-verity device type.
|
||||
*
|
||||
* @see crypt_format, crypt_load
|
||||
*
|
||||
@@ -386,7 +391,7 @@ struct crypt_params_verity {
|
||||
|
||||
/**
|
||||
*
|
||||
* Structure used as parameter for TCRYPT device type
|
||||
* Structure used as parameter for TCRYPT device type.
|
||||
*
|
||||
* @see crypt_load
|
||||
*
|
||||
@@ -403,7 +408,7 @@ struct crypt_params_tcrypt {
|
||||
uint32_t flags; /**< CRYPT_TCRYPT* flags */
|
||||
};
|
||||
|
||||
/** Include legacy modes ehn scannig for header*/
|
||||
/** Include legacy modes when scanning for header */
|
||||
#define CRYPT_TCRYPT_LEGACY_MODES (1 << 0)
|
||||
/** Try to load hidden header (describing hidden device) */
|
||||
#define CRYPT_TCRYPT_HIDDEN_HEADER (1 << 1)
|
||||
@@ -411,11 +416,16 @@ struct crypt_params_tcrypt {
|
||||
#define CRYPT_TCRYPT_BACKUP_HEADER (1 << 2)
|
||||
/** Device contains encrypted system (with boot loader) */
|
||||
#define CRYPT_TCRYPT_SYSTEM_HEADER (1 << 3)
|
||||
/** Include VeraCrypt modes when scanning for header,
|
||||
* all other TCRYPT flags applies as well.
|
||||
* VeraCrypt device is reported as TCRYPT type.
|
||||
*/
|
||||
#define CRYPT_TCRYPT_VERA_MODES (1 << 4)
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* Create (format) new crypt device (and possible header on-disk) but not activates it.
|
||||
* Create (format) new crypt device (and possible header on-disk) but do not activate it.
|
||||
*
|
||||
* @pre @e cd contains initialized and not formatted device context (device type must @b not be set)
|
||||
*
|
||||
@@ -445,7 +455,7 @@ int crypt_format(struct crypt_device *cd,
|
||||
void *params);
|
||||
|
||||
/**
|
||||
* Set new UUID for already existing device
|
||||
* Set new UUID for already existing device.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param uuid requested UUID or @e NULL if it should be generated
|
||||
@@ -458,7 +468,7 @@ int crypt_set_uuid(struct crypt_device *cd,
|
||||
const char *uuid);
|
||||
|
||||
/**
|
||||
* Load crypt device parameters from on-disk header
|
||||
* Load crypt device parameters from on-disk header.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param requested_type @link crypt_type @endlink or @e NULL for all known
|
||||
@@ -477,7 +487,7 @@ int crypt_load(struct crypt_device *cd,
|
||||
void *params);
|
||||
|
||||
/**
|
||||
* Try to repair crypt device on-disk header if invalid
|
||||
* Try to repair crypt device on-disk header if invalid.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param requested_type @link crypt_type @endlink or @e NULL for all known
|
||||
@@ -491,7 +501,7 @@ int crypt_repair(struct crypt_device *cd,
|
||||
void *params);
|
||||
|
||||
/**
|
||||
* Resize crypt device
|
||||
* Resize crypt device.
|
||||
*
|
||||
* @param cd - crypt device handle
|
||||
* @param name - name of device to resize
|
||||
@@ -504,7 +514,7 @@ int crypt_resize(struct crypt_device *cd,
|
||||
uint64_t new_size);
|
||||
|
||||
/**
|
||||
* Suspends crypt device.
|
||||
* Suspend crypt device.
|
||||
*
|
||||
* @param cd crypt device handle, can be @e NULL
|
||||
* @param name name of device to suspend
|
||||
@@ -518,7 +528,7 @@ int crypt_suspend(struct crypt_device *cd,
|
||||
const char *name);
|
||||
|
||||
/**
|
||||
* Resumes crypt device using passphrase.
|
||||
* Resume crypt device using passphrase.
|
||||
*
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
@@ -530,6 +540,8 @@ int crypt_suspend(struct crypt_device *cd,
|
||||
* @return unlocked key slot number or negative errno otherwise.
|
||||
*
|
||||
* @note Only LUKS device type is supported
|
||||
* @note If passphrase is @e NULL always use crypt_set_password_callback.
|
||||
* Internal terminal password query is DEPRECATED and will be removed in next version.
|
||||
*/
|
||||
int crypt_resume_by_passphrase(struct crypt_device *cd,
|
||||
const char *name,
|
||||
@@ -538,7 +550,7 @@ int crypt_resume_by_passphrase(struct crypt_device *cd,
|
||||
size_t passphrase_size);
|
||||
|
||||
/**
|
||||
* Resumes crypt device using key file.
|
||||
* Resume crypt device using key file.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param name name of device to resume
|
||||
@@ -548,6 +560,9 @@ int crypt_resume_by_passphrase(struct crypt_device *cd,
|
||||
* @param keyfile_offset number of bytes to skip at start of keyfile
|
||||
*
|
||||
* @return unlocked key slot number or negative errno otherwise.
|
||||
*
|
||||
* @note If passphrase is @e NULL always use crypt_set_password_callback.
|
||||
* Internal terminal password query is DEPRECATED and will be removed in next version.
|
||||
*/
|
||||
int crypt_resume_by_keyfile_offset(struct crypt_device *cd,
|
||||
const char *name,
|
||||
@@ -565,7 +580,7 @@ int crypt_resume_by_keyfile(struct crypt_device *cd,
|
||||
size_t keyfile_size);
|
||||
|
||||
/**
|
||||
* Releases crypt device context and used memory.
|
||||
* Release crypt device context and used memory.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
*/
|
||||
@@ -582,7 +597,7 @@ void crypt_free(struct crypt_device *cd);
|
||||
#define CRYPT_ANY_SLOT -1
|
||||
|
||||
/**
|
||||
* Add key slot using provided passphrase
|
||||
* Add key slot using provided passphrase.
|
||||
*
|
||||
* @pre @e cd contains initialized and formatted LUKS device context
|
||||
*
|
||||
@@ -594,6 +609,9 @@ void crypt_free(struct crypt_device *cd);
|
||||
* @param new_passphrase_size size of @e new_passphrase (binary data)
|
||||
*
|
||||
* @return allocated key slot number or negative errno otherwise.
|
||||
*
|
||||
* @note If passphrase is @e NULL always use crypt_set_password_callback.
|
||||
* Internal terminal password query is DEPRECATED and will be removed in next version.
|
||||
*/
|
||||
int crypt_keyslot_add_by_passphrase(struct crypt_device *cd,
|
||||
int keyslot,
|
||||
@@ -603,7 +621,7 @@ int crypt_keyslot_add_by_passphrase(struct crypt_device *cd,
|
||||
size_t new_passphrase_size);
|
||||
|
||||
/**
|
||||
* Change defined key slot using provided passphrase
|
||||
* Change defined key slot using provided passphrase.
|
||||
*
|
||||
* @pre @e cd contains initialized and formatted LUKS device context
|
||||
*
|
||||
@@ -620,6 +638,9 @@ int crypt_keyslot_add_by_passphrase(struct crypt_device *cd,
|
||||
* @note This function is just internal implementation of luksChange
|
||||
* command to avoid reading of volume key outside libcryptsetup boundary
|
||||
* in FIPS mode.
|
||||
*
|
||||
* @note If passphrase is @e NULL always use crypt_set_password_callback.
|
||||
* Internal terminal password query is DEPRECATED and will be removed in next version.
|
||||
*/
|
||||
int crypt_keyslot_change_by_passphrase(struct crypt_device *cd,
|
||||
int keyslot_old,
|
||||
@@ -630,7 +651,7 @@ int crypt_keyslot_change_by_passphrase(struct crypt_device *cd,
|
||||
size_t new_passphrase_size);
|
||||
|
||||
/**
|
||||
* Add key slot using provided key file path
|
||||
* Add key slot using provided key file path.
|
||||
*
|
||||
* @pre @e cd contains initialized and formatted LUKS device context
|
||||
*
|
||||
@@ -645,8 +666,8 @@ int crypt_keyslot_change_by_passphrase(struct crypt_device *cd,
|
||||
*
|
||||
* @return allocated key slot number or negative errno otherwise.
|
||||
*
|
||||
* @note Note that @e keyfile can be "-" for STDIN
|
||||
*
|
||||
* @note Note that @e keyfile can be "-" for STDIN. This special handling is DEPRECATED
|
||||
* and will be removed in next version.
|
||||
*/
|
||||
int crypt_keyslot_add_by_keyfile_offset(struct crypt_device *cd,
|
||||
int keyslot,
|
||||
@@ -667,7 +688,7 @@ int crypt_keyslot_add_by_keyfile(struct crypt_device *cd,
|
||||
size_t new_keyfile_size);
|
||||
|
||||
/**
|
||||
* Add key slot using provided volume key
|
||||
* Add key slot using provided volume key.
|
||||
*
|
||||
* @pre @e cd contains initialized and formatted LUKS device context
|
||||
*
|
||||
@@ -680,6 +701,8 @@ int crypt_keyslot_add_by_keyfile(struct crypt_device *cd,
|
||||
*
|
||||
* @return allocated key slot number or negative errno otherwise.
|
||||
*
|
||||
* @note If passphrase is @e NULL always use crypt_set_password_callback.
|
||||
* Internal terminal password query is DEPRECATED and will be removed in next version.
|
||||
*/
|
||||
int crypt_keyslot_add_by_volume_key(struct crypt_device *cd,
|
||||
int keyslot,
|
||||
@@ -689,7 +712,7 @@ int crypt_keyslot_add_by_volume_key(struct crypt_device *cd,
|
||||
size_t passphrase_size);
|
||||
|
||||
/**
|
||||
* Destroy (and disable) key slot
|
||||
* Destroy (and disable) key slot.
|
||||
*
|
||||
* @pre @e cd contains initialized and formatted LUKS device context
|
||||
*
|
||||
@@ -725,6 +748,17 @@ int crypt_keyslot_destroy(struct crypt_device *cd, int keyslot);
|
||||
#define CRYPT_ACTIVATE_PRIVATE (1 << 4)
|
||||
/** corruption detected (verity), output only */
|
||||
#define CRYPT_ACTIVATE_CORRUPTED (1 << 5)
|
||||
/** use same_cpu_crypt option for dm-crypt */
|
||||
#define CRYPT_ACTIVATE_SAME_CPU_CRYPT (1 << 6)
|
||||
/** use submit_from_crypt_cpus for dm-crypt */
|
||||
#define CRYPT_ACTIVATE_SUBMIT_FROM_CRYPT_CPUS (1 << 7)
|
||||
/** dm-verity: ignore_corruption flag - ignore corruption, log it only */
|
||||
#define CRYPT_ACTIVATE_IGNORE_CORRUPTION (1 << 8)
|
||||
/** dm-verity: restart_on_corruption flag - restart kernel on corruption */
|
||||
#define CRYPT_ACTIVATE_RESTART_ON_CORRUPTION (1 << 9)
|
||||
/** dm-verity: ignore_zero_blocks - do not verify zero blocks */
|
||||
#define CRYPT_ACTIVATE_IGNORE_ZERO_BLOCKS (1 << 10)
|
||||
|
||||
|
||||
/**
|
||||
* Active device runtime attributes
|
||||
@@ -737,7 +771,7 @@ struct crypt_active_device {
|
||||
};
|
||||
|
||||
/**
|
||||
* Receives runtime attributes of active crypt device
|
||||
* Receive runtime attributes of active crypt device.
|
||||
*
|
||||
* @param cd crypt device handle (can be @e NULL)
|
||||
* @param name name of active device
|
||||
@@ -753,7 +787,7 @@ int crypt_get_active_device(struct crypt_device *cd,
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* Activate device or check passphrase
|
||||
* Activate device or check passphrase.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param name name of device to create, if @e NULL only check passphrase
|
||||
@@ -763,6 +797,9 @@ int crypt_get_active_device(struct crypt_device *cd,
|
||||
* @param flags activation flags
|
||||
*
|
||||
* @return unlocked key slot number or negative errno otherwise.
|
||||
*
|
||||
* @note If passphrase is @e NULL always use crypt_set_password_callback.
|
||||
* Internal terminal password query is DEPRECATED and will be removed in next version.
|
||||
*/
|
||||
int crypt_activate_by_passphrase(struct crypt_device *cd,
|
||||
const char *name,
|
||||
@@ -772,7 +809,7 @@ int crypt_activate_by_passphrase(struct crypt_device *cd,
|
||||
uint32_t flags);
|
||||
|
||||
/**
|
||||
* Activate device or check using key file
|
||||
* Activate device or check using key file.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param name name of device to create, if @e NULL only check keyfile
|
||||
@@ -802,7 +839,7 @@ int crypt_activate_by_keyfile(struct crypt_device *cd,
|
||||
uint32_t flags);
|
||||
|
||||
/**
|
||||
* Activate device using provided volume key
|
||||
* Activate device using provided volume key.
|
||||
*
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
@@ -842,7 +879,7 @@ int crypt_activate_by_volume_key(struct crypt_device *cd,
|
||||
int crypt_deactivate(struct crypt_device *cd, const char *name);
|
||||
|
||||
/**
|
||||
* Get volume key from of crypt device
|
||||
* Get volume key from crypt device.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param keyslot use this keyslot or @e CRYPT_ANY_SLOT
|
||||
@@ -865,7 +902,7 @@ int crypt_volume_key_get(struct crypt_device *cd,
|
||||
size_t passphrase_size);
|
||||
|
||||
/**
|
||||
* Verify that provided volume key is valid for crypt device
|
||||
* Verify that provided volume key is valid for crypt device.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param volume_key provided volume key
|
||||
@@ -894,7 +931,7 @@ typedef enum {
|
||||
} crypt_status_info;
|
||||
|
||||
/**
|
||||
* Get status info about device name
|
||||
* Get status info about device name.
|
||||
*
|
||||
* @param cd crypt device handle, can be @e NULL
|
||||
* @param name crypt device name
|
||||
@@ -905,7 +942,7 @@ typedef enum {
|
||||
crypt_status_info crypt_status(struct crypt_device *cd, const char *name);
|
||||
|
||||
/**
|
||||
* Dump text-formatted information about crypt or verity device to log output
|
||||
* Dump text-formatted information about crypt or verity device to log output.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
*
|
||||
@@ -914,7 +951,7 @@ crypt_status_info crypt_status(struct crypt_device *cd, const char *name);
|
||||
int crypt_dump(struct crypt_device *cd);
|
||||
|
||||
/**
|
||||
* Get cipher used in device
|
||||
* Get cipher used in device.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
*
|
||||
@@ -924,7 +961,7 @@ int crypt_dump(struct crypt_device *cd);
|
||||
const char *crypt_get_cipher(struct crypt_device *cd);
|
||||
|
||||
/**
|
||||
* Get cipher mode used in device
|
||||
* Get cipher mode used in device.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
*
|
||||
@@ -934,7 +971,7 @@ const char *crypt_get_cipher(struct crypt_device *cd);
|
||||
const char *crypt_get_cipher_mode(struct crypt_device *cd);
|
||||
|
||||
/**
|
||||
* Get device UUID
|
||||
* Get device UUID.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
*
|
||||
@@ -944,7 +981,7 @@ const char *crypt_get_cipher_mode(struct crypt_device *cd);
|
||||
const char *crypt_get_uuid(struct crypt_device *cd);
|
||||
|
||||
/**
|
||||
* Get path to underlaying device
|
||||
* Get path to underlaying device.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
*
|
||||
@@ -954,7 +991,7 @@ const char *crypt_get_uuid(struct crypt_device *cd);
|
||||
const char *crypt_get_device_name(struct crypt_device *cd);
|
||||
|
||||
/**
|
||||
* Get device offset in sectors where real data starts on underlying device)
|
||||
* Get device offset in sectors where real data starts (on underlying device).
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
*
|
||||
@@ -964,7 +1001,7 @@ const char *crypt_get_device_name(struct crypt_device *cd);
|
||||
uint64_t crypt_get_data_offset(struct crypt_device *cd);
|
||||
|
||||
/**
|
||||
* Get IV offset in sectors (skip)
|
||||
* Get IV offset in sectors (skip).
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
*
|
||||
@@ -974,7 +1011,7 @@ uint64_t crypt_get_data_offset(struct crypt_device *cd);
|
||||
uint64_t crypt_get_iv_offset(struct crypt_device *cd);
|
||||
|
||||
/**
|
||||
* Get size (in bytes) of volume key for crypt device
|
||||
* Get size (in bytes) of volume key for crypt device.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
*
|
||||
@@ -984,7 +1021,7 @@ uint64_t crypt_get_iv_offset(struct crypt_device *cd);
|
||||
int crypt_get_volume_key_size(struct crypt_device *cd);
|
||||
|
||||
/**
|
||||
* Get device parameters for VERITY device
|
||||
* Get device parameters for VERITY device.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param vp verity device info
|
||||
@@ -1007,7 +1044,7 @@ int crypt_get_verity_info(struct crypt_device *cd,
|
||||
*/
|
||||
|
||||
/**
|
||||
* Informational benchmark for ciphers
|
||||
* Informational benchmark for ciphers.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param cipher (e.g. "aes")
|
||||
@@ -1019,6 +1056,9 @@ int crypt_get_verity_info(struct crypt_device *cd,
|
||||
* @param decryption_mbs measured decryption speed in MiB/s
|
||||
*
|
||||
* @return @e 0 on success or negative errno value otherwise.
|
||||
*
|
||||
* @note If encryption_buffer_size is too small and encryption time
|
||||
* cannot be properly measured, -ERANGE is returned.
|
||||
*/
|
||||
int crypt_benchmark(struct crypt_device *cd,
|
||||
const char *cipher,
|
||||
@@ -1030,7 +1070,7 @@ int crypt_benchmark(struct crypt_device *cd,
|
||||
double *decryption_mbs);
|
||||
|
||||
/**
|
||||
* Informational benchmark for KDF
|
||||
* Informational benchmark for KDF.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param kdf Key derivation function (e.g. "pbkdf2")
|
||||
@@ -1071,7 +1111,7 @@ typedef enum {
|
||||
} crypt_keyslot_info;
|
||||
|
||||
/**
|
||||
* Get information about particular key slot
|
||||
* Get information about particular key slot.
|
||||
*
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
@@ -1094,7 +1134,7 @@ crypt_keyslot_info crypt_keyslot_status(struct crypt_device *cd, int keyslot);
|
||||
int crypt_keyslot_max(const char *type);
|
||||
|
||||
/**
|
||||
* Get keyslot area pointers (relative to metadata device)
|
||||
* Get keyslot area pointers (relative to metadata device).
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param keyslot keyslot number
|
||||
@@ -1110,7 +1150,7 @@ int crypt_keyslot_area(struct crypt_device *cd,
|
||||
uint64_t *length);
|
||||
|
||||
/**
|
||||
* Backup header and keyslots to file
|
||||
* Backup header and keyslots to file.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param requested_type @link crypt_type @endlink or @e NULL for all known
|
||||
@@ -1124,7 +1164,7 @@ int crypt_header_backup(struct crypt_device *cd,
|
||||
const char *backup_file);
|
||||
|
||||
/**
|
||||
* Restore header and keyslots from backup file
|
||||
* Restore header and keyslots from backup file.
|
||||
*
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
@@ -1139,14 +1179,14 @@ int crypt_header_restore(struct crypt_device *cd,
|
||||
const char *backup_file);
|
||||
|
||||
/**
|
||||
* Receives last reported error
|
||||
* Receive last reported error, DEPRECATED.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param buf buffef for message
|
||||
* @param size size of buffer
|
||||
*
|
||||
* @note Note that this is old API function using global context.
|
||||
* All error messages are reported also through log callback.
|
||||
* @note This function is DEPRECATED and will be removed in future versions.
|
||||
* @note All error messages are reported also through log callback.
|
||||
*/
|
||||
void crypt_last_error(struct crypt_device *cd, char *buf, size_t size);
|
||||
|
||||
@@ -1156,8 +1196,7 @@ void crypt_last_error(struct crypt_device *cd, char *buf, size_t size);
|
||||
* @param buf buffef for message
|
||||
* @param size size of buffer
|
||||
*
|
||||
* @note Note that this is old API function using global context.
|
||||
* All error messages are reported also through log callback.
|
||||
* @note This function is DEPRECATED and will be removed in future versions.
|
||||
*/
|
||||
void crypt_get_error(char *buf, size_t size);
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/*
|
||||
* libdevmapper - device-mapper backend for cryptsetup
|
||||
*
|
||||
* Copyright (C) 2004, Christophe Saout <christophe@saout.de>
|
||||
* Copyright (C) 2004, Jana Saout <jana@saout.de>
|
||||
* Copyright (C) 2004-2007, Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2012, Milan Broz
|
||||
* Copyright (C) 2009-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2017, Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <linux/fs.h>
|
||||
#include <uuid/uuid.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
@@ -85,12 +86,12 @@ static void set_dm_error(int level,
|
||||
va_start(va, f);
|
||||
if (vasprintf(&msg, f, va) > 0) {
|
||||
if (level < 4 && !_quiet_log) {
|
||||
log_err(_context, msg);
|
||||
log_err(_context, "%s", msg);
|
||||
log_err(_context, "\n");
|
||||
} else {
|
||||
/* We do not use DM visual stack backtrace here */
|
||||
if (strncmp(msg, "<backtrace>", 11))
|
||||
log_dbg(msg);
|
||||
log_dbg("%s", msg);
|
||||
}
|
||||
}
|
||||
free(msg);
|
||||
@@ -99,6 +100,18 @@ static void set_dm_error(int level,
|
||||
|
||||
static int _dm_simple(int task, const char *name, int udev_wait);
|
||||
|
||||
static int _dm_satisfies_version(unsigned target_maj, unsigned target_min,
|
||||
unsigned actual_maj, unsigned actual_min)
|
||||
{
|
||||
if (actual_maj > target_maj)
|
||||
return 1;
|
||||
|
||||
if (actual_maj == target_maj && actual_min >= target_min)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void _dm_set_crypt_compat(const char *dm_version, unsigned crypt_maj,
|
||||
unsigned crypt_min, unsigned crypt_patch)
|
||||
{
|
||||
@@ -110,24 +123,32 @@ static void _dm_set_crypt_compat(const char *dm_version, unsigned crypt_maj,
|
||||
log_dbg("Detected dm-crypt version %i.%i.%i, dm-ioctl version %u.%u.%u.",
|
||||
crypt_maj, crypt_min, crypt_patch, dm_maj, dm_min, dm_patch);
|
||||
|
||||
if (crypt_maj >= 1 && crypt_min >= 2)
|
||||
if (_dm_satisfies_version(1, 2, crypt_maj, crypt_min))
|
||||
_dm_crypt_flags |= DM_KEY_WIPE_SUPPORTED;
|
||||
else
|
||||
log_dbg("Suspend and resume disabled, no wipe key support.");
|
||||
|
||||
if (crypt_maj >= 1 && crypt_min >= 10)
|
||||
if (_dm_satisfies_version(1, 10, crypt_maj, crypt_min))
|
||||
_dm_crypt_flags |= DM_LMK_SUPPORTED;
|
||||
|
||||
if (dm_maj >= 4 && dm_min >= 20)
|
||||
if (_dm_satisfies_version(4, 20, dm_maj, dm_min))
|
||||
_dm_crypt_flags |= DM_SECURE_SUPPORTED;
|
||||
|
||||
/* not perfect, 2.6.33 supports with 1.7.0 */
|
||||
if (crypt_maj >= 1 && crypt_min >= 8)
|
||||
if (_dm_satisfies_version(1, 8, crypt_maj, crypt_min))
|
||||
_dm_crypt_flags |= DM_PLAIN64_SUPPORTED;
|
||||
|
||||
if (crypt_maj >= 1 && crypt_min >= 11)
|
||||
if (_dm_satisfies_version(1, 11, crypt_maj, crypt_min))
|
||||
_dm_crypt_flags |= DM_DISCARDS_SUPPORTED;
|
||||
|
||||
if (_dm_satisfies_version(1, 13, crypt_maj, crypt_min))
|
||||
_dm_crypt_flags |= DM_TCW_SUPPORTED;
|
||||
|
||||
if (_dm_satisfies_version(1, 14, crypt_maj, crypt_min)) {
|
||||
_dm_crypt_flags |= DM_SAME_CPU_CRYPT_SUPPORTED;
|
||||
_dm_crypt_flags |= DM_SUBMIT_FROM_CRYPT_CPUS_SUPPORTED;
|
||||
}
|
||||
|
||||
/* Repeat test if dm-crypt is not present */
|
||||
if (crypt_maj > 0)
|
||||
_dm_crypt_checked = 1;
|
||||
@@ -138,6 +159,15 @@ static void _dm_set_verity_compat(const char *dm_version, unsigned verity_maj,
|
||||
{
|
||||
if (verity_maj > 0)
|
||||
_dm_crypt_flags |= DM_VERITY_SUPPORTED;
|
||||
else
|
||||
return;
|
||||
/*
|
||||
* ignore_corruption, restart_on corruption is available since 1.2 (kernel 4.1)
|
||||
* ignore_zero_blocks since 1.3 (kernel 4.5)
|
||||
* (but some dm-verity targets 1.2 don't support it)
|
||||
*/
|
||||
if (_dm_satisfies_version(1, 3, verity_maj, verity_min))
|
||||
_dm_crypt_flags |= DM_VERITY_ON_CORRUPTION_SUPPORTED;
|
||||
|
||||
log_dbg("Detected dm-verity version %i.%i.%i.",
|
||||
verity_maj, verity_min, verity_patch);
|
||||
@@ -277,23 +307,30 @@ static void hex_key(char *hexkey, size_t key_size, const char *key)
|
||||
sprintf(&hexkey[i * 2], "%02x", (unsigned char)key[i]);
|
||||
}
|
||||
|
||||
/* http://code.google.com/p/cryptsetup/wiki/DMCrypt */
|
||||
static char *get_dm_crypt_params(struct crypt_dm_active_device *dmd)
|
||||
/* https://gitlab.com/cryptsetup/cryptsetup/wikis/DMCrypt */
|
||||
static char *get_dm_crypt_params(struct crypt_dm_active_device *dmd, uint32_t flags)
|
||||
{
|
||||
int r, max_size, null_cipher = 0;
|
||||
int r, max_size, null_cipher = 0, num_options = 0;
|
||||
char *params, *hexkey;
|
||||
const char *features = "";
|
||||
char features[256];
|
||||
|
||||
if (!dmd)
|
||||
return NULL;
|
||||
|
||||
if (dmd->flags & CRYPT_ACTIVATE_ALLOW_DISCARDS) {
|
||||
if (dm_flags() & DM_DISCARDS_SUPPORTED) {
|
||||
features = " 1 allow_discards";
|
||||
log_dbg("Discard/TRIM is allowed.");
|
||||
} else
|
||||
log_dbg("Discard/TRIM is not supported by the kernel.");
|
||||
}
|
||||
if (flags & CRYPT_ACTIVATE_ALLOW_DISCARDS)
|
||||
num_options++;
|
||||
if (flags & CRYPT_ACTIVATE_SAME_CPU_CRYPT)
|
||||
num_options++;
|
||||
if (flags & CRYPT_ACTIVATE_SUBMIT_FROM_CRYPT_CPUS)
|
||||
num_options++;
|
||||
|
||||
if (num_options)
|
||||
snprintf(features, sizeof(features)-1, " %d%s%s%s", num_options,
|
||||
(flags & CRYPT_ACTIVATE_ALLOW_DISCARDS) ? " allow_discards" : "",
|
||||
(flags & CRYPT_ACTIVATE_SAME_CPU_CRYPT) ? " same_cpu_crypt" : "",
|
||||
(flags & CRYPT_ACTIVATE_SUBMIT_FROM_CRYPT_CPUS) ? " submit_from_crypt_cpus" : "");
|
||||
else
|
||||
*features = '\0';
|
||||
|
||||
if (!strncmp(dmd->u.crypt.cipher, "cipher_null-", 12))
|
||||
null_cipher = 1;
|
||||
@@ -327,16 +364,37 @@ out:
|
||||
return params;
|
||||
}
|
||||
|
||||
/* http://code.google.com/p/cryptsetup/wiki/DMVerity */
|
||||
/* https://gitlab.com/cryptsetup/cryptsetup/wikis/DMVerity */
|
||||
static char *get_dm_verity_params(struct crypt_params_verity *vp,
|
||||
struct crypt_dm_active_device *dmd)
|
||||
struct crypt_dm_active_device *dmd, uint32_t flags)
|
||||
{
|
||||
int max_size, r;
|
||||
int max_size, r, num_options = 0;
|
||||
char *params = NULL, *hexroot = NULL, *hexsalt = NULL;
|
||||
char features[256];
|
||||
|
||||
if (!vp || !dmd)
|
||||
return NULL;
|
||||
|
||||
/* These flags are not compatible */
|
||||
if ((flags & CRYPT_ACTIVATE_IGNORE_CORRUPTION) &&
|
||||
(flags & CRYPT_ACTIVATE_RESTART_ON_CORRUPTION))
|
||||
flags &= ~CRYPT_ACTIVATE_IGNORE_CORRUPTION;
|
||||
|
||||
if (flags & CRYPT_ACTIVATE_IGNORE_CORRUPTION)
|
||||
num_options++;
|
||||
if (flags & CRYPT_ACTIVATE_RESTART_ON_CORRUPTION)
|
||||
num_options++;
|
||||
if (flags & CRYPT_ACTIVATE_IGNORE_ZERO_BLOCKS)
|
||||
num_options++;
|
||||
|
||||
if (num_options)
|
||||
snprintf(features, sizeof(features)-1, " %d%s%s%s", num_options,
|
||||
(flags & CRYPT_ACTIVATE_IGNORE_CORRUPTION) ? " ignore_corruption" : "",
|
||||
(flags & CRYPT_ACTIVATE_RESTART_ON_CORRUPTION) ? " restart_on_corruption" : "",
|
||||
(flags & CRYPT_ACTIVATE_IGNORE_ZERO_BLOCKS) ? " ignore_zero_blocks" : "");
|
||||
else
|
||||
*features = '\0';
|
||||
|
||||
hexroot = crypt_safe_alloc(dmd->u.verity.root_hash_size * 2 + 1);
|
||||
if (!hexroot)
|
||||
goto out;
|
||||
@@ -353,19 +411,19 @@ static char *get_dm_verity_params(struct crypt_params_verity *vp,
|
||||
max_size = strlen(hexroot) + strlen(hexsalt) +
|
||||
strlen(device_block_path(dmd->data_device)) +
|
||||
strlen(device_block_path(dmd->u.verity.hash_device)) +
|
||||
strlen(vp->hash_name) + 128;
|
||||
strlen(vp->hash_name) + strlen(features) + 128;
|
||||
|
||||
params = crypt_safe_alloc(max_size);
|
||||
if (!params)
|
||||
goto out;
|
||||
|
||||
r = snprintf(params, max_size,
|
||||
"%u %s %s %u %u %" PRIu64 " %" PRIu64 " %s %s %s",
|
||||
"%u %s %s %u %u %" PRIu64 " %" PRIu64 " %s %s %s %s",
|
||||
vp->hash_type, device_block_path(dmd->data_device),
|
||||
device_block_path(dmd->u.verity.hash_device),
|
||||
vp->data_block_size, vp->hash_block_size,
|
||||
vp->data_size, dmd->u.verity.hash_offset,
|
||||
vp->hash_name, hexroot, hexsalt);
|
||||
vp->hash_name, hexroot, hexsalt, features);
|
||||
if (r < 0 || r >= max_size) {
|
||||
crypt_safe_free(params);
|
||||
params = NULL;
|
||||
@@ -406,7 +464,7 @@ static int _dm_simple(int task, const char *name, int udev_wait)
|
||||
if (udev_wait)
|
||||
(void)_dm_udev_wait(cookie);
|
||||
|
||||
out:
|
||||
out:
|
||||
dm_task_destroy(dmt);
|
||||
return r;
|
||||
}
|
||||
@@ -503,7 +561,7 @@ static int dm_prepare_uuid(const char *name, const char *type, const char *uuid,
|
||||
if (uuid) {
|
||||
if (uuid_parse(uuid, uu) < 0) {
|
||||
log_dbg("Requested UUID %s has invalid format.", uuid);
|
||||
return -EINVAL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (ptr = uuid2, i = 0; i < UUID_LEN; i++)
|
||||
@@ -522,7 +580,7 @@ static int dm_prepare_uuid(const char *name, const char *type, const char *uuid,
|
||||
if (i >= buflen)
|
||||
log_err(NULL, _("DM-UUID for device %s was truncated.\n"), name);
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _dm_create_device(const char *name, const char *type,
|
||||
@@ -538,6 +596,9 @@ static int _dm_create_device(const char *name, const char *type,
|
||||
uint32_t cookie = 0;
|
||||
uint16_t udev_flags = 0;
|
||||
|
||||
if (!params)
|
||||
return -EINVAL;
|
||||
|
||||
if (flags & CRYPT_ACTIVATE_PRIVATE)
|
||||
udev_flags = CRYPT_TEMP_UDEV_FLAGS;
|
||||
|
||||
@@ -549,9 +610,8 @@ static int _dm_create_device(const char *name, const char *type,
|
||||
if (!dm_task_set_name(dmt, name))
|
||||
goto out_no_removal;
|
||||
} else {
|
||||
r = dm_prepare_uuid(name, type, uuid, dev_uuid, sizeof(dev_uuid));
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (!dm_prepare_uuid(name, type, uuid, dev_uuid, sizeof(dev_uuid)))
|
||||
goto out_no_removal;
|
||||
|
||||
if (!(dmt = dm_task_create(DM_DEVICE_CREATE)))
|
||||
goto out_no_removal;
|
||||
@@ -561,9 +621,6 @@ static int _dm_create_device(const char *name, const char *type,
|
||||
|
||||
if (!dm_task_set_uuid(dmt, dev_uuid))
|
||||
goto out_no_removal;
|
||||
|
||||
if (_dm_use_udev() && !_dm_task_set_cookie(dmt, &cookie, udev_flags))
|
||||
goto out_no_removal;
|
||||
}
|
||||
|
||||
if ((dm_flags() & DM_SECURE_SUPPORTED) && !dm_task_secure_data(dmt))
|
||||
@@ -580,6 +637,9 @@ static int _dm_create_device(const char *name, const char *type,
|
||||
!dm_task_set_read_ahead(dmt, read_ahead, DM_READ_AHEAD_MINIMUM_FLAG))
|
||||
goto out_no_removal;
|
||||
#endif
|
||||
/* do not set cookie for DM_DEVICE_RELOAD task */
|
||||
if (!reload && _dm_use_udev() && !_dm_task_set_cookie(dmt, &cookie, udev_flags))
|
||||
goto out_no_removal;
|
||||
|
||||
if (!dm_task_run(dmt))
|
||||
goto out_no_removal;
|
||||
@@ -615,12 +675,14 @@ out_no_removal:
|
||||
if (cookie && _dm_use_udev())
|
||||
(void)_dm_udev_wait(cookie);
|
||||
|
||||
if (params)
|
||||
crypt_safe_free(params);
|
||||
if (dmt)
|
||||
dm_task_destroy(dmt);
|
||||
|
||||
dm_task_update_nodes();
|
||||
|
||||
/* If code just loaded target module, update versions */
|
||||
_dm_check_versions();
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -630,7 +692,8 @@ int dm_create_device(struct crypt_device *cd, const char *name,
|
||||
int reload)
|
||||
{
|
||||
char *table_params = NULL;
|
||||
int r = -EINVAL;
|
||||
uint32_t dmd_flags;
|
||||
int r;
|
||||
|
||||
if (!type)
|
||||
return -EINVAL;
|
||||
@@ -638,15 +701,40 @@ int dm_create_device(struct crypt_device *cd, const char *name,
|
||||
if (dm_init_context(cd))
|
||||
return -ENOTSUP;
|
||||
|
||||
if (dmd->target == DM_CRYPT)
|
||||
table_params = get_dm_crypt_params(dmd);
|
||||
else if (dmd->target == DM_VERITY)
|
||||
table_params = get_dm_verity_params(dmd->u.verity.vp, dmd);
|
||||
dmd_flags = dmd->flags;
|
||||
|
||||
if (table_params)
|
||||
r = _dm_create_device(name, type, dmd->data_device,
|
||||
dmd->flags, dmd->uuid, dmd->size,
|
||||
table_params, reload);
|
||||
if (dmd->target == DM_CRYPT)
|
||||
table_params = get_dm_crypt_params(dmd, dmd_flags);
|
||||
else if (dmd->target == DM_VERITY)
|
||||
table_params = get_dm_verity_params(dmd->u.verity.vp, dmd, dmd_flags);
|
||||
|
||||
r = _dm_create_device(name, type, dmd->data_device, dmd_flags,
|
||||
dmd->uuid, dmd->size, table_params, reload);
|
||||
|
||||
/* If discard not supported try to load without discard */
|
||||
if (!reload && r && dmd->target == DM_CRYPT &&
|
||||
(dmd->flags & CRYPT_ACTIVATE_ALLOW_DISCARDS) &&
|
||||
!(dm_flags() & DM_DISCARDS_SUPPORTED)) {
|
||||
log_dbg("Discard/TRIM is not supported, retrying activation.");
|
||||
dmd_flags = dmd_flags & ~CRYPT_ACTIVATE_ALLOW_DISCARDS;
|
||||
crypt_safe_free(table_params);
|
||||
table_params = get_dm_crypt_params(dmd, dmd_flags);
|
||||
r = _dm_create_device(name, type, dmd->data_device, dmd_flags,
|
||||
dmd->uuid, dmd->size, table_params, reload);
|
||||
}
|
||||
|
||||
if (r == -EINVAL &&
|
||||
dmd_flags & (CRYPT_ACTIVATE_SAME_CPU_CRYPT|CRYPT_ACTIVATE_SUBMIT_FROM_CRYPT_CPUS) &&
|
||||
!(dm_flags() & (DM_SAME_CPU_CRYPT_SUPPORTED|DM_SUBMIT_FROM_CRYPT_CPUS_SUPPORTED)))
|
||||
log_err(cd, _("Requested dm-crypt performance options are not supported.\n"));
|
||||
|
||||
if (r == -EINVAL && dmd_flags & (CRYPT_ACTIVATE_IGNORE_CORRUPTION|
|
||||
CRYPT_ACTIVATE_RESTART_ON_CORRUPTION|
|
||||
CRYPT_ACTIVATE_IGNORE_ZERO_BLOCKS) &&
|
||||
!(dm_flags() & DM_VERITY_ON_CORRUPTION_SUPPORTED))
|
||||
log_err(cd, _("Requested dm-verity data corruption handling options are not supported.\n"));
|
||||
|
||||
crypt_safe_free(table_params);
|
||||
dm_exit_context();
|
||||
return r;
|
||||
}
|
||||
@@ -833,11 +921,15 @@ static int _dm_query_crypt(uint32_t get_flags,
|
||||
arg = strsep(¶ms, " ");
|
||||
if (!strcasecmp(arg, "allow_discards"))
|
||||
dmd->flags |= CRYPT_ACTIVATE_ALLOW_DISCARDS;
|
||||
else if (!strcasecmp(arg, "same_cpu_crypt"))
|
||||
dmd->flags |= CRYPT_ACTIVATE_SAME_CPU_CRYPT;
|
||||
else if (!strcasecmp(arg, "submit_from_crypt_cpus"))
|
||||
dmd->flags |= CRYPT_ACTIVATE_SUBMIT_FROM_CRYPT_CPUS;
|
||||
else /* unknown option */
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* All parameters shold be processed */
|
||||
/* All parameters should be processed */
|
||||
if (params)
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -880,7 +972,8 @@ static int _dm_query_verity(uint32_t get_flags,
|
||||
uint32_t val32;
|
||||
uint64_t val64;
|
||||
ssize_t len;
|
||||
char *str, *str2;
|
||||
char *str, *str2, *arg;
|
||||
unsigned int i;
|
||||
int r;
|
||||
|
||||
if (get_flags & DM_ACTIVE_VERITY_PARAMS)
|
||||
@@ -976,8 +1069,6 @@ static int _dm_query_verity(uint32_t get_flags,
|
||||
|
||||
/* salt */
|
||||
str = strsep(¶ms, " ");
|
||||
if (params)
|
||||
return -EINVAL;
|
||||
if (vp) {
|
||||
if (!strcmp(str, "-")) {
|
||||
vp->salt_size = 0;
|
||||
@@ -991,6 +1082,33 @@ static int _dm_query_verity(uint32_t get_flags,
|
||||
}
|
||||
}
|
||||
|
||||
/* Features section, available since verity target version 1.3 */
|
||||
if (params) {
|
||||
/* Number of arguments */
|
||||
val64 = strtoull(params, ¶ms, 10);
|
||||
if (*params != ' ')
|
||||
return -EINVAL;
|
||||
params++;
|
||||
|
||||
for (i = 0; i < val64; i++) {
|
||||
if (!params)
|
||||
return -EINVAL;
|
||||
arg = strsep(¶ms, " ");
|
||||
if (!strcasecmp(arg, "ignore_corruption"))
|
||||
dmd->flags |= CRYPT_ACTIVATE_IGNORE_CORRUPTION;
|
||||
else if (!strcasecmp(arg, "restart_on_corruption"))
|
||||
dmd->flags |= CRYPT_ACTIVATE_RESTART_ON_CORRUPTION;
|
||||
else if (!strcasecmp(arg, "ignore_zero_blocks"))
|
||||
dmd->flags |= CRYPT_ACTIVATE_IGNORE_ZERO_BLOCKS;
|
||||
else /* unknown option */
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* All parameters should be processed */
|
||||
if (params)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,15 +2,13 @@ moduledir = $(libdir)/cryptsetup
|
||||
|
||||
noinst_LTLIBRARIES = libloopaes.la
|
||||
|
||||
libloopaes_la_CFLAGS = -Wall @CRYPTO_CFLAGS@
|
||||
libloopaes_la_CFLAGS = -Wall $(AM_CFLAGS) @CRYPTO_CFLAGS@
|
||||
|
||||
libloopaes_la_SOURCES = \
|
||||
loopaes.c \
|
||||
loopaes.h
|
||||
|
||||
AM_CPPFLAGS = -D_GNU_SOURCE \
|
||||
-D_LARGEFILE64_SOURCE \
|
||||
-D_FILE_OFFSET_BITS=64 \
|
||||
AM_CPPFLAGS = -include config.h \
|
||||
-I$(top_srcdir)/lib \
|
||||
-I$(top_srcdir)/lib/crypto_backend
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* loop-AES compatible volume handling
|
||||
*
|
||||
* Copyright (C) 2011-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2011-2013, Milan Broz
|
||||
* Copyright (C) 2011-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2011-2017, Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -137,7 +137,7 @@ int LOOPAES_parse_keyfile(struct crypt_device *cd,
|
||||
unsigned int key_lengths[LOOPAES_KEYS_MAX];
|
||||
unsigned int i, key_index, key_len, offset;
|
||||
|
||||
log_dbg("Parsing loop-AES keyfile of size %d.", buffer_len);
|
||||
log_dbg("Parsing loop-AES keyfile of size %zu.", buffer_len);
|
||||
|
||||
if (!buffer_len)
|
||||
return -EINVAL;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* loop-AES compatible volume handling
|
||||
*
|
||||
* Copyright (C) 2011-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2011-2013, Milan Broz
|
||||
* Copyright (C) 2011-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2011-2017, Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -23,7 +23,6 @@
|
||||
#define _LOOPAES_H
|
||||
|
||||
#include <unistd.h>
|
||||
#include "config.h"
|
||||
|
||||
struct crypt_device;
|
||||
struct volume_key;
|
||||
|
||||
@@ -2,7 +2,7 @@ moduledir = $(libdir)/cryptsetup
|
||||
|
||||
noinst_LTLIBRARIES = libluks1.la
|
||||
|
||||
libluks1_la_CFLAGS = -Wall @CRYPTO_CFLAGS@
|
||||
libluks1_la_CFLAGS = -Wall $(AM_CFLAGS) @CRYPTO_CFLAGS@
|
||||
|
||||
libluks1_la_SOURCES = \
|
||||
af.c \
|
||||
@@ -11,9 +11,7 @@ libluks1_la_SOURCES = \
|
||||
af.h \
|
||||
luks.h
|
||||
|
||||
AM_CPPFLAGS = -D_GNU_SOURCE \
|
||||
-D_LARGEFILE64_SOURCE \
|
||||
-D_FILE_OFFSET_BITS=64 \
|
||||
AM_CPPFLAGS = -include config.h \
|
||||
-I$(top_srcdir)/lib \
|
||||
-I$(top_srcdir)/lib/crypto_backend
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* AFsplitter - Anti forensic information splitter
|
||||
*
|
||||
* Copyright (C) 2004, Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2017, Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* AFsplitter diffuses information over a large stripe of data,
|
||||
* therefor supporting secure data destruction.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* AFsplitter - Anti forensic information splitter
|
||||
*
|
||||
* Copyright (C) 2004, Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2017, Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* AFsplitter diffuses information over a large stripe of data,
|
||||
* therefor supporting secure data destruction.
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
* LUKS - Linux Unified Key Setup
|
||||
*
|
||||
* Copyright (C) 2004-2006, Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2017, Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -26,8 +27,13 @@
|
||||
#include "internal.h"
|
||||
|
||||
static void _error_hint(struct crypt_device *ctx, const char *device,
|
||||
const char *cipher_spec, const char *mode, size_t keyLength)
|
||||
const char *cipher, const char *mode, size_t keyLength)
|
||||
{
|
||||
char cipher_spec[MAX_CIPHER_LEN * 3];
|
||||
|
||||
if (snprintf(cipher_spec, sizeof(cipher_spec), "%s-%s", cipher, mode) < 0)
|
||||
return;
|
||||
|
||||
log_err(ctx, _("Failed to setup dm-crypt key mapping for device %s.\n"
|
||||
"Check that kernel supports %s cipher (check syslog for more info).\n"),
|
||||
device, cipher_spec);
|
||||
@@ -60,6 +66,8 @@ static int LUKS_endec_template(char *src, size_t srcLength,
|
||||
};
|
||||
int r, bsize, devfd = -1;
|
||||
|
||||
log_dbg("Using dmcrypt to access keyslot area.");
|
||||
|
||||
bsize = device_block_size(dmd.data_device);
|
||||
if (bsize <= 0)
|
||||
return -EINVAL;
|
||||
@@ -94,7 +102,7 @@ static int LUKS_endec_template(char *src, size_t srcLength,
|
||||
if (r < 0) {
|
||||
if (r != -EACCES && r != -ENOTSUP)
|
||||
_error_hint(ctx, device_path(dmd.data_device),
|
||||
cipher_spec, cipher_mode, vk->keylength * 8);
|
||||
cipher, cipher_mode, vk->keylength * 8);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
@@ -125,8 +133,64 @@ int LUKS_encrypt_to_storage(char *src, size_t srcLength,
|
||||
unsigned int sector,
|
||||
struct crypt_device *ctx)
|
||||
{
|
||||
return LUKS_endec_template(src, srcLength, cipher, cipher_mode,
|
||||
vk, sector, write_blockwise, O_RDWR, ctx);
|
||||
|
||||
struct device *device = crypt_metadata_device(ctx);
|
||||
struct crypt_storage *s;
|
||||
int devfd = -1, bsize, r = 0;
|
||||
|
||||
/* Only whole sector writes supported */
|
||||
if (srcLength % SECTOR_SIZE)
|
||||
return -EINVAL;
|
||||
|
||||
/* Encrypt buffer */
|
||||
r = crypt_storage_init(&s, 0, cipher, cipher_mode, vk->key, vk->keylength);
|
||||
|
||||
if (r)
|
||||
log_dbg("Userspace crypto wrapper cannot use %s-%s (%d).",
|
||||
cipher, cipher_mode, r);
|
||||
|
||||
/* Fallback to old temporary dmcrypt device */
|
||||
if (r == -ENOTSUP || r == -ENOENT)
|
||||
return LUKS_endec_template(src, srcLength, cipher, cipher_mode,
|
||||
vk, sector, write_blockwise, O_RDWR, ctx);
|
||||
|
||||
if (r) {
|
||||
_error_hint(ctx, device_path(device), cipher, cipher_mode,
|
||||
vk->keylength * 8);
|
||||
return r;
|
||||
}
|
||||
|
||||
log_dbg("Using userspace crypto wrapper to access keyslot area.");
|
||||
|
||||
r = crypt_storage_encrypt(s, 0, srcLength / SECTOR_SIZE, src);
|
||||
crypt_storage_destroy(s);
|
||||
|
||||
if (r)
|
||||
return r;
|
||||
|
||||
r = -EIO;
|
||||
|
||||
/* Write buffer to device */
|
||||
bsize = device_block_size(device);
|
||||
if (bsize <= 0)
|
||||
goto out;
|
||||
|
||||
devfd = device_open(device, O_RDWR);
|
||||
if (devfd == -1)
|
||||
goto out;
|
||||
|
||||
if (lseek(devfd, sector * SECTOR_SIZE, SEEK_SET) == -1 ||
|
||||
write_blockwise(devfd, bsize, src, srcLength) == -1)
|
||||
goto out;
|
||||
|
||||
r = 0;
|
||||
out:
|
||||
if(devfd != -1)
|
||||
close(devfd);
|
||||
if (r)
|
||||
log_err(ctx, _("IO error while encrypting keyslot.\n"));
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int LUKS_decrypt_from_storage(char *dst, size_t dstLength,
|
||||
@@ -136,6 +200,61 @@ int LUKS_decrypt_from_storage(char *dst, size_t dstLength,
|
||||
unsigned int sector,
|
||||
struct crypt_device *ctx)
|
||||
{
|
||||
return LUKS_endec_template(dst, dstLength, cipher, cipher_mode,
|
||||
vk, sector, read_blockwise, O_RDONLY, ctx);
|
||||
struct device *device = crypt_metadata_device(ctx);
|
||||
struct crypt_storage *s;
|
||||
int devfd = -1, bsize, r = 0;
|
||||
|
||||
/* Only whole sector reads supported */
|
||||
if (dstLength % SECTOR_SIZE)
|
||||
return -EINVAL;
|
||||
|
||||
r = crypt_storage_init(&s, 0, cipher, cipher_mode, vk->key, vk->keylength);
|
||||
|
||||
if (r)
|
||||
log_dbg("Userspace crypto wrapper cannot use %s-%s (%d).",
|
||||
cipher, cipher_mode, r);
|
||||
|
||||
/* Fallback to old temporary dmcrypt device */
|
||||
if (r == -ENOTSUP || r == -ENOENT)
|
||||
return LUKS_endec_template(dst, dstLength, cipher, cipher_mode,
|
||||
vk, sector, read_blockwise, O_RDONLY, ctx);
|
||||
|
||||
if (r) {
|
||||
_error_hint(ctx, device_path(device), cipher, cipher_mode,
|
||||
vk->keylength * 8);
|
||||
return r;
|
||||
}
|
||||
|
||||
log_dbg("Using userspace crypto wrapper to access keyslot area.");
|
||||
|
||||
r = -EIO;
|
||||
|
||||
/* Read buffer from device */
|
||||
bsize = device_block_size(device);
|
||||
if (bsize <= 0)
|
||||
goto bad;
|
||||
|
||||
devfd = device_open(device, O_RDONLY);
|
||||
if (devfd == -1)
|
||||
goto bad;
|
||||
|
||||
if (lseek(devfd, sector * SECTOR_SIZE, SEEK_SET) == -1 ||
|
||||
read_blockwise(devfd, bsize, dst, dstLength) == -1)
|
||||
goto bad;
|
||||
|
||||
close(devfd);
|
||||
|
||||
/* Decrypt buffer */
|
||||
r = crypt_storage_decrypt(s, 0, dstLength / SECTOR_SIZE, dst);
|
||||
crypt_storage_destroy(s);
|
||||
|
||||
return r;
|
||||
bad:
|
||||
if(devfd != -1)
|
||||
close(devfd);
|
||||
|
||||
log_err(ctx, _("IO error while decrypting keyslot.\n"));
|
||||
crypt_storage_destroy(s);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
* LUKS - Linux Unified Key Setup
|
||||
*
|
||||
* Copyright (C) 2004-2006, Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2013-2017, Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -61,7 +62,7 @@ int LUKS_keyslot_area(struct luks_phdr *hdr,
|
||||
if(keyslot >= LUKS_NUMKEYS || keyslot < 0)
|
||||
return -EINVAL;
|
||||
|
||||
*offset = hdr->keyblock[keyslot].keyMaterialOffset * SECTOR_SIZE;
|
||||
*offset = (uint64_t)hdr->keyblock[keyslot].keyMaterialOffset * SECTOR_SIZE;
|
||||
*length = AF_split_sectors(hdr->keyBytes, LUKS_STRIPES) * SECTOR_SIZE;
|
||||
|
||||
return 0;
|
||||
@@ -82,11 +83,12 @@ static int LUKS_check_device_size(struct crypt_device *ctx, size_t keyLength)
|
||||
|
||||
dev_sectors >>= SECTOR_SHIFT;
|
||||
hdr_sectors = LUKS_device_sectors(keyLength);
|
||||
log_dbg("Key length %u, device size %" PRIu64 " sectors, header size %"
|
||||
log_dbg("Key length %zu, device size %" PRIu64 " sectors, header size %"
|
||||
PRIu64 " sectors.",keyLength, dev_sectors, hdr_sectors);
|
||||
|
||||
if (hdr_sectors > dev_sectors) {
|
||||
log_err(ctx, _("Device %s is too small.\n"), device_path(device));
|
||||
log_err(ctx, _("Device %s is too small. (LUKS requires at least %" PRIu64 " bytes.)\n"),
|
||||
device_path(device), hdr_sectors * SECTOR_SIZE);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -146,29 +148,32 @@ static const char *dbg_slot_state(crypt_keyslot_info ki)
|
||||
}
|
||||
}
|
||||
|
||||
int LUKS_hdr_backup(
|
||||
const char *backup_file,
|
||||
struct luks_phdr *hdr,
|
||||
struct crypt_device *ctx)
|
||||
int LUKS_hdr_backup(const char *backup_file, struct crypt_device *ctx)
|
||||
{
|
||||
struct device *device = crypt_metadata_device(ctx);
|
||||
struct luks_phdr hdr;
|
||||
int r = 0, devfd = -1;
|
||||
ssize_t hdr_size;
|
||||
ssize_t buffer_size;
|
||||
char *buffer = NULL;
|
||||
|
||||
r = LUKS_read_phdr(hdr, 1, 0, ctx);
|
||||
r = LUKS_read_phdr(&hdr, 1, 0, ctx);
|
||||
if (r)
|
||||
return r;
|
||||
|
||||
buffer_size = LUKS_device_sectors(hdr->keyBytes) << SECTOR_SHIFT;
|
||||
hdr_size = LUKS_device_sectors(hdr.keyBytes) << SECTOR_SHIFT;
|
||||
buffer_size = size_round_up(hdr_size, crypt_getpagesize());
|
||||
|
||||
buffer = crypt_safe_alloc(buffer_size);
|
||||
if (!buffer || buffer_size < LUKS_ALIGN_KEYSLOTS) {
|
||||
if (!buffer || hdr_size < LUKS_ALIGN_KEYSLOTS || hdr_size > buffer_size) {
|
||||
r = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
log_dbg("Storing backup of header (%u bytes) and keyslot area (%u bytes).",
|
||||
sizeof(*hdr), buffer_size - LUKS_ALIGN_KEYSLOTS);
|
||||
log_dbg("Storing backup of header (%zu bytes) and keyslot area (%zu bytes).",
|
||||
sizeof(hdr), hdr_size - LUKS_ALIGN_KEYSLOTS);
|
||||
|
||||
log_dbg("Output backup file size: %zu bytes.", buffer_size);
|
||||
|
||||
devfd = device_open(device, O_RDONLY);
|
||||
if(devfd == -1) {
|
||||
@@ -177,15 +182,15 @@ int LUKS_hdr_backup(
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (read_blockwise(devfd, device_block_size(device), buffer, buffer_size) < buffer_size) {
|
||||
if (read_blockwise(devfd, device_block_size(device), buffer, hdr_size) < hdr_size) {
|
||||
r = -EIO;
|
||||
goto out;
|
||||
}
|
||||
close(devfd);
|
||||
|
||||
/* Wipe unused area, so backup cannot contain old signatures */
|
||||
if (hdr->keyblock[0].keyMaterialOffset * SECTOR_SIZE == LUKS_ALIGN_KEYSLOTS)
|
||||
memset(buffer + sizeof(*hdr), 0, LUKS_ALIGN_KEYSLOTS - sizeof(*hdr));
|
||||
if (hdr.keyblock[0].keyMaterialOffset * SECTOR_SIZE == LUKS_ALIGN_KEYSLOTS)
|
||||
memset(buffer + sizeof(hdr), 0, LUKS_ALIGN_KEYSLOTS - sizeof(hdr));
|
||||
|
||||
devfd = open(backup_file, O_CREAT|O_EXCL|O_WRONLY, S_IRUSR);
|
||||
if (devfd == -1) {
|
||||
@@ -196,17 +201,17 @@ int LUKS_hdr_backup(
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
if (write(devfd, buffer, buffer_size) < buffer_size) {
|
||||
if (write_buffer(devfd, buffer, buffer_size) < buffer_size) {
|
||||
log_err(ctx, _("Cannot write header backup file %s.\n"), backup_file);
|
||||
r = -EIO;
|
||||
goto out;
|
||||
}
|
||||
close(devfd);
|
||||
|
||||
r = 0;
|
||||
out:
|
||||
if (devfd != -1)
|
||||
close(devfd);
|
||||
crypt_memzero(&hdr, sizeof(hdr));
|
||||
crypt_safe_free(buffer);
|
||||
return r;
|
||||
}
|
||||
@@ -248,12 +253,13 @@ int LUKS_hdr_restore(
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (read(devfd, buffer, buffer_size) < buffer_size) {
|
||||
if (read_buffer(devfd, buffer, buffer_size) < buffer_size) {
|
||||
log_err(ctx, _("Cannot read header backup file %s.\n"), backup_file);
|
||||
r = -EIO;
|
||||
goto out;
|
||||
}
|
||||
close(devfd);
|
||||
devfd = -1;
|
||||
|
||||
r = LUKS_read_phdr(hdr, 0, 0, ctx);
|
||||
if (r == 0) {
|
||||
@@ -281,7 +287,7 @@ int LUKS_hdr_restore(
|
||||
goto out;
|
||||
}
|
||||
|
||||
log_dbg("Storing backup of header (%u bytes) and keyslot area (%u bytes) to device %s.",
|
||||
log_dbg("Storing backup of header (%zu bytes) and keyslot area (%zu bytes) to device %s.",
|
||||
sizeof(*hdr), buffer_size - LUKS_ALIGN_KEYSLOTS, device_path(device));
|
||||
|
||||
devfd = device_open(device, O_RDWR);
|
||||
@@ -300,6 +306,7 @@ int LUKS_hdr_restore(
|
||||
goto out;
|
||||
}
|
||||
close(devfd);
|
||||
devfd = -1;
|
||||
|
||||
/* Be sure to reload new data */
|
||||
r = LUKS_read_phdr(hdr, 1, 0, ctx);
|
||||
@@ -392,7 +399,7 @@ static int _keyslot_repair(struct luks_phdr *phdr, struct crypt_device *ctx)
|
||||
}
|
||||
out:
|
||||
crypt_free_volume_key(vk);
|
||||
memset(&temp_phdr, 0, sizeof(temp_phdr));
|
||||
crypt_memzero(&temp_phdr, sizeof(temp_phdr));
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -465,6 +472,13 @@ static void LUKS_fix_header_compatible(struct luks_phdr *header)
|
||||
/* Old cryptsetup expects "sha1", gcrypt allows case insensistive names,
|
||||
* so always convert hash to lower case in header */
|
||||
_to_lower(header->hashSpec, LUKS_HASHSPEC_L);
|
||||
|
||||
/* ECB mode does not use IV but dmcrypt silently allows it.
|
||||
* Drop any IV here if ECB is used (that is not secure anyway).*/
|
||||
if (!strncmp(header->cipherMode, "ecb-", 4)) {
|
||||
memset(header->cipherMode, 0, LUKS_CIPHERMODE_L);
|
||||
strcpy(header->cipherMode, "ecb");
|
||||
}
|
||||
}
|
||||
|
||||
int LUKS_read_phdr_backup(const char *backup_file,
|
||||
@@ -484,7 +498,7 @@ int LUKS_read_phdr_backup(const char *backup_file,
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
if (read(devfd, hdr, hdr_size) < hdr_size)
|
||||
if (read_buffer(devfd, hdr, hdr_size) < hdr_size)
|
||||
r = -EIO;
|
||||
else {
|
||||
LUKS_fix_header_compatible(hdr);
|
||||
@@ -514,7 +528,7 @@ int LUKS_read_phdr(struct luks_phdr *hdr,
|
||||
if (repair && !require_luks_device)
|
||||
return -EINVAL;
|
||||
|
||||
log_dbg("Reading LUKS header of size %d from device %s",
|
||||
log_dbg("Reading LUKS header of size %zu from device %s",
|
||||
hdr_size, device_path(device));
|
||||
|
||||
devfd = device_open(device, O_RDONLY);
|
||||
@@ -532,6 +546,16 @@ int LUKS_read_phdr(struct luks_phdr *hdr,
|
||||
if (!r)
|
||||
r = LUKS_check_device_size(ctx, hdr->keyBytes);
|
||||
|
||||
/*
|
||||
* Cryptsetup 1.0.0 did not align keyslots to 4k (very rare version).
|
||||
* Disable direct-io to avoid possible IO errors if underlying device
|
||||
* has bigger sector size.
|
||||
*/
|
||||
if (!r && hdr->keyblock[0].keyMaterialOffset * SECTOR_SIZE < LUKS_ALIGN_KEYSLOTS) {
|
||||
log_dbg("Old unaligned LUKS keyslot detected, disabling direct-io.");
|
||||
device_disable_direct_io(device);
|
||||
}
|
||||
|
||||
close(devfd);
|
||||
return r;
|
||||
}
|
||||
@@ -546,7 +570,7 @@ int LUKS_write_phdr(struct luks_phdr *hdr,
|
||||
struct luks_phdr convHdr;
|
||||
int r;
|
||||
|
||||
log_dbg("Updating LUKS header of size %d on device %s",
|
||||
log_dbg("Updating LUKS header of size %zu on device %s",
|
||||
sizeof(struct luks_phdr), device_path(device));
|
||||
|
||||
r = LUKS_check_device_size(ctx, hdr->keyBytes);
|
||||
@@ -594,6 +618,30 @@ int LUKS_write_phdr(struct luks_phdr *hdr,
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Check that kernel supports requested cipher by decryption of one sector */
|
||||
static int LUKS_check_cipher(struct luks_phdr *hdr, struct crypt_device *ctx)
|
||||
{
|
||||
int r;
|
||||
struct volume_key *empty_key;
|
||||
char buf[SECTOR_SIZE];
|
||||
|
||||
log_dbg("Checking if cipher %s-%s is usable.", hdr->cipherName, hdr->cipherMode);
|
||||
|
||||
empty_key = crypt_alloc_volume_key(hdr->keyBytes, NULL);
|
||||
if (!empty_key)
|
||||
return -ENOMEM;
|
||||
|
||||
/* No need to get KEY quality random but it must avoid known weak keys. */
|
||||
r = crypt_random_get(ctx, empty_key->key, empty_key->keylength, CRYPT_RND_NORMAL);
|
||||
if (!r)
|
||||
r = LUKS_decrypt_from_storage(buf, sizeof(buf), hdr->cipherName,
|
||||
hdr->cipherMode, empty_key, 0, ctx);
|
||||
|
||||
crypt_free_volume_key(empty_key);
|
||||
crypt_memzero(buf, sizeof(buf));
|
||||
return r;
|
||||
}
|
||||
|
||||
int LUKS_generate_phdr(struct luks_phdr *header,
|
||||
const struct volume_key *vk,
|
||||
const char *cipherName, const char *cipherMode, const char *hashSpec,
|
||||
@@ -605,7 +653,7 @@ int LUKS_generate_phdr(struct luks_phdr *header,
|
||||
int detached_metadata_device,
|
||||
struct crypt_device *ctx)
|
||||
{
|
||||
unsigned int i=0;
|
||||
unsigned int i = 0, hdr_sectors = LUKS_device_sectors(vk->keylength);
|
||||
size_t blocksPerStripeSet, currentSector;
|
||||
int r;
|
||||
uuid_t partitionUuid;
|
||||
@@ -615,6 +663,13 @@ int LUKS_generate_phdr(struct luks_phdr *header,
|
||||
if (alignPayload == 0 && !detached_metadata_device)
|
||||
alignPayload = DEFAULT_DISK_ALIGNMENT / SECTOR_SIZE;
|
||||
|
||||
if (alignPayload && detached_metadata_device && alignPayload < hdr_sectors) {
|
||||
log_err(ctx, _("Data offset for detached LUKS header must be "
|
||||
"either 0 or higher than header size (%d sectors).\n"),
|
||||
hdr_sectors);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (crypt_hmac_size(hashSpec) < LUKS_DIGESTSIZE) {
|
||||
log_err(ctx, _("Requested LUKS hash %s is not supported.\n"), hashSpec);
|
||||
return -EINVAL;
|
||||
@@ -632,14 +687,18 @@ int LUKS_generate_phdr(struct luks_phdr *header,
|
||||
/* Set Magic */
|
||||
memcpy(header->magic,luksMagic,LUKS_MAGIC_L);
|
||||
header->version=1;
|
||||
strncpy(header->cipherName,cipherName,LUKS_CIPHERNAME_L);
|
||||
strncpy(header->cipherMode,cipherMode,LUKS_CIPHERMODE_L);
|
||||
strncpy(header->hashSpec,hashSpec,LUKS_HASHSPEC_L);
|
||||
strncpy(header->cipherName,cipherName,LUKS_CIPHERNAME_L-1);
|
||||
strncpy(header->cipherMode,cipherMode,LUKS_CIPHERMODE_L-1);
|
||||
strncpy(header->hashSpec,hashSpec,LUKS_HASHSPEC_L-1);
|
||||
|
||||
header->keyBytes=vk->keylength;
|
||||
|
||||
LUKS_fix_header_compatible(header);
|
||||
|
||||
r = LUKS_check_cipher(header, ctx);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
log_dbg("Generating LUKS header version %d using hash %s, %s, %s, MK %d bytes",
|
||||
header->version, header->hashSpec ,header->cipherName, header->cipherMode,
|
||||
header->keyBytes);
|
||||
@@ -758,14 +817,14 @@ int LUKS_set_key(unsigned int keyIndex,
|
||||
* Avoid floating point operation
|
||||
* Final iteration count is at least LUKS_SLOT_ITERATIONS_MIN
|
||||
*/
|
||||
PBKDF2_temp = (*PBKDF2_per_sec / 2) * (uint64_t)iteration_time_ms;
|
||||
PBKDF2_temp = *PBKDF2_per_sec * (uint64_t)iteration_time_ms;
|
||||
PBKDF2_temp /= 1024;
|
||||
if (PBKDF2_temp > UINT32_MAX)
|
||||
PBKDF2_temp = UINT32_MAX;
|
||||
hdr->keyblock[keyIndex].passwordIterations = at_least((uint32_t)PBKDF2_temp,
|
||||
LUKS_SLOT_ITERATIONS_MIN);
|
||||
|
||||
log_dbg("Key slot %d use %d password iterations.", keyIndex, hdr->keyblock[keyIndex].passwordIterations);
|
||||
log_dbg("Key slot %d use %" PRIu32 " password iterations.", keyIndex, hdr->keyblock[keyIndex].passwordIterations);
|
||||
|
||||
derived_key = crypt_alloc_volume_key(hdr->keyBytes, NULL);
|
||||
if (!derived_key)
|
||||
@@ -900,6 +959,11 @@ static int LUKS_open_key(unsigned int keyIndex,
|
||||
goto out;
|
||||
|
||||
r = LUKS_verify_volume_key(hdr, vk);
|
||||
|
||||
/* Allow only empty passphrase with null cipher */
|
||||
if (!r && !strcmp(hdr->cipherName, "cipher_null") && passwordLen)
|
||||
r = -EPERM;
|
||||
|
||||
if (!r)
|
||||
log_verbose(ctx, _("Key slot %d unlocked.\n"), keyIndex);
|
||||
out:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* LUKS - Linux Unified Key Setup
|
||||
*
|
||||
* Copyright (C) 2004-2006, Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2017, Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -130,7 +130,6 @@ int LUKS_hdr_uuid_set(
|
||||
|
||||
int LUKS_hdr_backup(
|
||||
const char *backup_file,
|
||||
struct luks_phdr *hdr,
|
||||
struct crypt_device *ctx);
|
||||
|
||||
int LUKS_hdr_restore(
|
||||
|
||||
15
lib/random.c
15
lib/random.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* cryptsetup kernel RNG access functions
|
||||
*
|
||||
* Copyright (C) 2010-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2017, Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -28,6 +28,10 @@
|
||||
#include "libcryptsetup.h"
|
||||
#include "internal.h"
|
||||
|
||||
#ifndef O_CLOEXEC
|
||||
#define O_CLOEXEC 0
|
||||
#endif
|
||||
|
||||
static int random_initialised = 0;
|
||||
|
||||
#define URANDOM_DEVICE "/dev/urandom"
|
||||
@@ -152,16 +156,19 @@ int crypt_random_init(struct crypt_device *ctx)
|
||||
|
||||
/* Used for CRYPT_RND_NORMAL */
|
||||
if(urandom_fd == -1)
|
||||
urandom_fd = open(URANDOM_DEVICE, O_RDONLY);
|
||||
urandom_fd = open(URANDOM_DEVICE, O_RDONLY | O_CLOEXEC);
|
||||
if(urandom_fd == -1)
|
||||
goto fail;
|
||||
|
||||
/* Used for CRYPT_RND_KEY */
|
||||
if(random_fd == -1)
|
||||
random_fd = open(RANDOM_DEVICE, O_RDONLY | O_NONBLOCK);
|
||||
random_fd = open(RANDOM_DEVICE, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
|
||||
if(random_fd == -1)
|
||||
goto fail;
|
||||
|
||||
if (crypt_fips_mode())
|
||||
log_verbose(ctx, _("Running in FIPS mode.\n"));
|
||||
|
||||
random_initialised = 1;
|
||||
return 0;
|
||||
fail:
|
||||
@@ -231,9 +238,11 @@ void crypt_random_exit(void)
|
||||
|
||||
int crypt_random_default_key_rng(void)
|
||||
{
|
||||
/* coverity[pointless_string_compare] */
|
||||
if (!strcmp(DEFAULT_RNG, RANDOM_DEVICE))
|
||||
return CRYPT_RNG_RANDOM;
|
||||
|
||||
/* coverity[pointless_string_compare] */
|
||||
if (!strcmp(DEFAULT_RNG, URANDOM_DEVICE))
|
||||
return CRYPT_RNG_URANDOM;
|
||||
|
||||
|
||||
309
lib/setup.c
309
lib/setup.c
@@ -1,10 +1,10 @@
|
||||
/*
|
||||
* libcryptsetup - cryptsetup library
|
||||
*
|
||||
* Copyright (C) 2004, Christophe Saout <christophe@saout.de>
|
||||
* Copyright (C) 2004, Jana Saout <jana@saout.de>
|
||||
* Copyright (C) 2004-2007, Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2013, Milan Broz
|
||||
* Copyright (C) 2009-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2017, Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
@@ -78,6 +79,13 @@ struct crypt_device {
|
||||
struct crypt_params_tcrypt params;
|
||||
struct tcrypt_phdr hdr;
|
||||
} tcrypt;
|
||||
struct { /* used if initialized without header by name */
|
||||
char *active_name;
|
||||
/* buffers, must refresh from kernel on every query */
|
||||
char cipher[MAX_CIPHER_LEN];
|
||||
char cipher_mode[MAX_CIPHER_LEN];
|
||||
unsigned int key_size;
|
||||
} none;
|
||||
} u;
|
||||
|
||||
/* callbacks definitions */
|
||||
@@ -92,6 +100,9 @@ struct crypt_device {
|
||||
char error[MAX_ERROR_LENGTH];
|
||||
};
|
||||
|
||||
/* Just to suppress redundant messages about crypto backend */
|
||||
static int _crypto_logged = 0;
|
||||
|
||||
/* Global error */
|
||||
/* FIXME: not thread safe, remove this later */
|
||||
static char global_error[MAX_ERROR_LENGTH] = {0};
|
||||
@@ -181,10 +192,9 @@ struct device *crypt_data_device(struct crypt_device *cd)
|
||||
|
||||
int init_crypto(struct crypt_device *ctx)
|
||||
{
|
||||
struct utsname uts;
|
||||
int r;
|
||||
|
||||
crypt_fips_libcryptsetup_check(ctx);
|
||||
|
||||
r = crypt_random_init(ctx);
|
||||
if (r < 0) {
|
||||
log_err(ctx, _("Cannot initialize crypto RNG backend.\n"));
|
||||
@@ -195,7 +205,15 @@ int init_crypto(struct crypt_device *ctx)
|
||||
if (r < 0)
|
||||
log_err(ctx, _("Cannot initialize crypto backend.\n"));
|
||||
|
||||
log_dbg("Crypto backend (%s) initialized.", crypt_backend_version());
|
||||
if (!r && !_crypto_logged) {
|
||||
log_dbg("Crypto backend (%s) initialized in cryptsetup library version %s.",
|
||||
crypt_backend_version(), PACKAGE_VERSION);
|
||||
if (!uname(&uts))
|
||||
log_dbg("Detected kernel %s %s %s.",
|
||||
uts.sysname, uts.release, uts.machine);
|
||||
_crypto_logged = 1;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -259,6 +277,41 @@ static int isTCRYPT(const char *type)
|
||||
return (type && !strcmp(CRYPT_TCRYPT, type));
|
||||
}
|
||||
|
||||
static int onlyLUKS(struct crypt_device *cd)
|
||||
{
|
||||
int r = 0;
|
||||
|
||||
if (cd && !cd->type) {
|
||||
log_err(cd, _("Cannot determine device type. Incompatible activation of device?\n"));
|
||||
r = -EINVAL;
|
||||
}
|
||||
if (!cd || !isLUKS(cd->type)) {
|
||||
log_err(cd, _("This operation is supported only for LUKS device.\n"));
|
||||
r = -EINVAL;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static void crypt_set_null_type(struct crypt_device *cd)
|
||||
{
|
||||
if (!cd->type)
|
||||
return;
|
||||
|
||||
free(cd->type);
|
||||
cd->type = NULL;
|
||||
cd->u.none.active_name = NULL;
|
||||
}
|
||||
|
||||
static void crypt_reset_null_type(struct crypt_device *cd)
|
||||
{
|
||||
if (cd->type)
|
||||
return;
|
||||
|
||||
free(cd->u.none.active_name);
|
||||
cd->u.none.active_name = NULL;
|
||||
}
|
||||
|
||||
/* keyslot helpers */
|
||||
static int keyslot_verify_or_find_empty(struct crypt_device *cd, int *keyslot)
|
||||
{
|
||||
@@ -316,6 +369,36 @@ static int crypt_uuid_cmp(const char *dm_uuid, const char *hdr_uuid)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* compares type of active device to provided string (only if there is no explicit type)
|
||||
*/
|
||||
static int crypt_uuid_type_cmp(struct crypt_device *cd, const char *type)
|
||||
{
|
||||
struct crypt_dm_active_device dmd = {};
|
||||
size_t len;
|
||||
int r;
|
||||
|
||||
/* Must user header-on-disk if we know type here */
|
||||
if (cd->type || !cd->u.none.active_name)
|
||||
return -EINVAL;
|
||||
|
||||
log_dbg("Checking if active device %s without header has UUID type %s.",
|
||||
cd->u.none.active_name, type);
|
||||
|
||||
r = dm_query_device(cd, cd->u.none.active_name, DM_ACTIVE_UUID, &dmd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = -ENODEV;
|
||||
len = strlen(type);
|
||||
if (dmd.uuid && strlen(dmd.uuid) > len &&
|
||||
!strncmp(dmd.uuid, type, len) && dmd.uuid[len] == '-')
|
||||
r = 0;
|
||||
|
||||
free(CONST_CAST(void*)dmd.uuid);
|
||||
return r;
|
||||
}
|
||||
|
||||
int PLAIN_activate(struct crypt_device *cd,
|
||||
const char *name,
|
||||
struct volume_key *vk,
|
||||
@@ -543,7 +626,7 @@ int crypt_init(struct crypt_device **cd, const char *device)
|
||||
|
||||
dm_backend_init();
|
||||
|
||||
h->iteration_time = 1000;
|
||||
h->iteration_time = DEFAULT_LUKS1_ITER_TIME;
|
||||
h->password_verify = 0;
|
||||
h->tries = 3;
|
||||
h->rng_type = crypt_random_default_key_rng();
|
||||
@@ -706,6 +789,8 @@ static int _init_by_name_crypt(struct crypt_device *cd, const char *name)
|
||||
DM_ACTIVE_CRYPT_KEYSIZE, &dmd);
|
||||
if (r < 0)
|
||||
goto out;
|
||||
if (r > 0)
|
||||
r = 0;
|
||||
|
||||
if (isPLAIN(cd->type)) {
|
||||
cd->u.plain.hdr.hash = NULL; /* no way to get this */
|
||||
@@ -736,8 +821,7 @@ static int _init_by_name_crypt(struct crypt_device *cd, const char *name)
|
||||
r = _crypt_load_luks1(cd, 0, 0);
|
||||
if (r < 0) {
|
||||
log_dbg("LUKS device header does not match active device.");
|
||||
free(cd->type);
|
||||
cd->type = NULL;
|
||||
crypt_set_null_type(cd);
|
||||
r = 0;
|
||||
goto out;
|
||||
}
|
||||
@@ -746,14 +830,12 @@ static int _init_by_name_crypt(struct crypt_device *cd, const char *name)
|
||||
if (r < 0) {
|
||||
log_dbg("LUKS device header uuid: %s mismatches DM returned uuid %s",
|
||||
cd->u.luks1.hdr.uuid, dmd.uuid);
|
||||
free(cd->type);
|
||||
cd->type = NULL;
|
||||
crypt_set_null_type(cd);
|
||||
r = 0;
|
||||
}
|
||||
} else {
|
||||
log_dbg("LUKS device header not available.");
|
||||
free(cd->type);
|
||||
cd->type = NULL;
|
||||
crypt_set_null_type(cd);
|
||||
r = 0;
|
||||
}
|
||||
} else if (isTCRYPT(cd->type)) {
|
||||
@@ -783,6 +865,8 @@ static int _init_by_name_verity(struct crypt_device *cd, const char *name)
|
||||
DM_ACTIVE_VERITY_PARAMS, &dmd);
|
||||
if (r < 0)
|
||||
goto out;
|
||||
if (r > 0)
|
||||
r = 0;
|
||||
|
||||
if (isVERITY(cd->type)) {
|
||||
cd->u.verity.uuid = NULL; // FIXME
|
||||
@@ -885,7 +969,11 @@ out:
|
||||
if (r < 0) {
|
||||
crypt_free(*cd);
|
||||
*cd = NULL;
|
||||
} else if (!(*cd)->type) {
|
||||
/* For anonymous device (no header found) remember initialized name */
|
||||
(*cd)->u.none.active_name = strdup(name);
|
||||
}
|
||||
|
||||
device_free(dmd.data_device);
|
||||
free(CONST_CAST(void*)dmd.uuid);
|
||||
return r;
|
||||
@@ -985,13 +1073,8 @@ static int _crypt_format_luks1(struct crypt_device *cd,
|
||||
&required_alignment,
|
||||
&alignment_offset, DEFAULT_DISK_ALIGNMENT);
|
||||
|
||||
/* Check early if we cannot allocate block device for key slot access */
|
||||
r = device_block_adjust(cd, cd->device, DEV_OK, 0, NULL, NULL);
|
||||
if(r < 0)
|
||||
return r;
|
||||
|
||||
r = LUKS_generate_phdr(&cd->u.luks1.hdr, cd->volume_key, cipher, cipher_mode,
|
||||
(params && params->hash) ? params->hash : "sha1",
|
||||
(params && params->hash) ? params->hash : DEFAULT_LUKS1_HASH,
|
||||
uuid, LUKS_STRIPES,
|
||||
required_alignment / SECTOR_SIZE,
|
||||
alignment_offset / SECTOR_SIZE,
|
||||
@@ -1105,6 +1188,12 @@ static int _crypt_format_verity(struct crypt_device *cd,
|
||||
} else
|
||||
cd->u.verity.hdr.data_size = params->data_size;
|
||||
|
||||
if (device_is_identical(crypt_metadata_device(cd), crypt_data_device(cd)) &&
|
||||
(cd->u.verity.hdr.data_size * params->data_block_size) > params->hash_area_offset) {
|
||||
log_err(cd, _("Data area overlaps with hash area.\n"));
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
hash_size = crypt_hash_size(params->hash_name);
|
||||
if (hash_size <= 0) {
|
||||
log_err(cd, _("Hash algorithm %s not supported.\n"),
|
||||
@@ -1183,6 +1272,8 @@ int crypt_format(struct crypt_device *cd,
|
||||
|
||||
log_dbg("Formatting device %s as type %s.", mdata_device_path(cd) ?: "(none)", type);
|
||||
|
||||
crypt_reset_null_type(cd);
|
||||
|
||||
r = init_crypto(cd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -1203,8 +1294,7 @@ int crypt_format(struct crypt_device *cd,
|
||||
}
|
||||
|
||||
if (r < 0) {
|
||||
free(cd->type);
|
||||
cd->type = NULL;
|
||||
crypt_set_null_type(cd);
|
||||
crypt_free_volume_key(cd->volume_key);
|
||||
cd->volume_key = NULL;
|
||||
}
|
||||
@@ -1224,6 +1314,8 @@ int crypt_load(struct crypt_device *cd,
|
||||
if (!crypt_metadata_device(cd))
|
||||
return -EINVAL;
|
||||
|
||||
crypt_reset_null_type(cd);
|
||||
|
||||
if (!requested_type || isLUKS(requested_type)) {
|
||||
if (cd->type && !isLUKS(cd->type)) {
|
||||
log_dbg("Context is already initialised to type %s", cd->type);
|
||||
@@ -1272,10 +1364,8 @@ int crypt_repair(struct crypt_device *cd,
|
||||
|
||||
/* cd->type and header must be set in context */
|
||||
r = crypt_check_data_device_size(cd);
|
||||
if (r < 0) {
|
||||
free(cd->type);
|
||||
cd->type = NULL;
|
||||
}
|
||||
if (r < 0)
|
||||
crypt_set_null_type(cd);
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -1304,6 +1394,14 @@ int crypt_resize(struct crypt_device *cd, const char *name, uint64_t new_size)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (crypt_loop_device(crypt_get_device_name(cd))) {
|
||||
log_dbg("Trying to resize underlying loop device %s.",
|
||||
crypt_get_device_name(cd));
|
||||
/* Here we always use default size not new_size */
|
||||
if (crypt_loop_resize(crypt_get_device_name(cd)))
|
||||
log_err(NULL, _("Cannot resize loop device.\n"));
|
||||
}
|
||||
|
||||
r = device_block_adjust(cd, dmd.data_device, DEV_OK,
|
||||
dmd.u.crypt.offset, &new_size, &dmd.flags);
|
||||
if (r)
|
||||
@@ -1364,6 +1462,9 @@ int crypt_header_backup(struct crypt_device *cd,
|
||||
if ((requested_type && !isLUKS(requested_type)) || !backup_file)
|
||||
return -EINVAL;
|
||||
|
||||
if (cd->type && !isLUKS(cd->type))
|
||||
return -EINVAL;
|
||||
|
||||
r = init_crypto(cd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -1371,13 +1472,15 @@ int crypt_header_backup(struct crypt_device *cd,
|
||||
log_dbg("Requested header backup of device %s (%s) to "
|
||||
"file %s.", mdata_device_path(cd), requested_type, backup_file);
|
||||
|
||||
return LUKS_hdr_backup(backup_file, &cd->u.luks1.hdr, cd);
|
||||
r = LUKS_hdr_backup(backup_file, cd);
|
||||
return r;
|
||||
}
|
||||
|
||||
int crypt_header_restore(struct crypt_device *cd,
|
||||
const char *requested_type,
|
||||
const char *backup_file)
|
||||
{
|
||||
struct luks_phdr hdr;
|
||||
int r;
|
||||
|
||||
if (requested_type && !isLUKS(requested_type))
|
||||
@@ -1393,7 +1496,10 @@ int crypt_header_restore(struct crypt_device *cd,
|
||||
log_dbg("Requested header restore to device %s (%s) from "
|
||||
"file %s.", mdata_device_path(cd), requested_type, backup_file);
|
||||
|
||||
return LUKS_hdr_restore(backup_file, &cd->u.luks1.hdr, cd);
|
||||
r = LUKS_hdr_restore(backup_file, isLUKS(cd->type) ? &cd->u.luks1.hdr : &hdr, cd);
|
||||
|
||||
crypt_memzero(&hdr, sizeof(hdr));
|
||||
return r;
|
||||
}
|
||||
|
||||
void crypt_free(struct crypt_device *cd)
|
||||
@@ -1419,11 +1525,13 @@ void crypt_free(struct crypt_device *cd)
|
||||
free(CONST_CAST(void*)cd->u.verity.hdr.salt);
|
||||
free(cd->u.verity.root_hash);
|
||||
free(cd->u.verity.uuid);
|
||||
} else if (!cd->type) {
|
||||
free(cd->u.none.active_name);
|
||||
}
|
||||
|
||||
free(cd->type);
|
||||
/* Some structures can contain keys (TCRYPT), wipe it */
|
||||
memset(cd, 0, sizeof(*cd));
|
||||
crypt_memzero(cd, sizeof(*cd));
|
||||
free(cd);
|
||||
}
|
||||
}
|
||||
@@ -1436,12 +1544,17 @@ int crypt_suspend(struct crypt_device *cd,
|
||||
|
||||
log_dbg("Suspending volume %s.", name);
|
||||
|
||||
if (!cd || !isLUKS(cd->type)) {
|
||||
log_err(cd, _("This operation is supported only for LUKS device.\n"));
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
if (cd->type) {
|
||||
r = onlyLUKS(cd);
|
||||
} else {
|
||||
r = crypt_uuid_type_cmp(cd, CRYPT_LUKS1);
|
||||
if (r < 0)
|
||||
log_err(cd, _("This operation is supported only for LUKS device.\n"));
|
||||
}
|
||||
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
ci = crypt_status(NULL, name);
|
||||
if (ci < CRYPT_ACTIVE) {
|
||||
log_err(cd, _("Volume %s is not active.\n"), name);
|
||||
@@ -1481,11 +1594,9 @@ int crypt_resume_by_passphrase(struct crypt_device *cd,
|
||||
|
||||
log_dbg("Resuming volume %s.", name);
|
||||
|
||||
if (!isLUKS(cd->type)) {
|
||||
log_err(cd, _("This operation is supported only for LUKS device.\n"));
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
r = onlyLUKS(cd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = dm_status_suspended(cd, name);
|
||||
if (r < 0)
|
||||
@@ -1511,7 +1622,7 @@ int crypt_resume_by_passphrase(struct crypt_device *cd,
|
||||
log_err(cd, _("Error during resuming device %s.\n"), name);
|
||||
} else
|
||||
r = keyslot;
|
||||
out:
|
||||
|
||||
crypt_free_volume_key(vk);
|
||||
return r < 0 ? r : keyslot;
|
||||
}
|
||||
@@ -1530,11 +1641,9 @@ int crypt_resume_by_keyfile_offset(struct crypt_device *cd,
|
||||
|
||||
log_dbg("Resuming volume %s.", name);
|
||||
|
||||
if (!isLUKS(cd->type)) {
|
||||
log_err(cd, _("This operation is supported only for LUKS device.\n"));
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
r = onlyLUKS(cd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = dm_status_suspended(cd, name);
|
||||
if (r < 0)
|
||||
@@ -1596,10 +1705,9 @@ int crypt_keyslot_add_by_passphrase(struct crypt_device *cd,
|
||||
"new passphrase %sprovided.",
|
||||
passphrase ? "" : "not ", new_passphrase ? "" : "not ");
|
||||
|
||||
if (!isLUKS(cd->type)) {
|
||||
log_err(cd, _("This operation is supported only for LUKS device.\n"));
|
||||
return -EINVAL;
|
||||
}
|
||||
r = onlyLUKS(cd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = keyslot_verify_or_find_empty(cd, &keyslot);
|
||||
if (r)
|
||||
@@ -1645,14 +1753,15 @@ int crypt_keyslot_add_by_passphrase(struct crypt_device *cd,
|
||||
|
||||
r = LUKS_set_key(keyslot, new_password, new_passwordLen,
|
||||
&cd->u.luks1.hdr, vk, cd->iteration_time, &cd->u.luks1.PBKDF2_per_sec, cd);
|
||||
if(r < 0) goto out;
|
||||
if(r < 0)
|
||||
goto out;
|
||||
|
||||
r = 0;
|
||||
out:
|
||||
if (!new_passphrase)
|
||||
crypt_safe_free(new_password);
|
||||
crypt_free_volume_key(vk);
|
||||
return r ?: keyslot;
|
||||
return r < 0 ? r : keyslot;
|
||||
}
|
||||
|
||||
int crypt_keyslot_change_by_passphrase(struct crypt_device *cd,
|
||||
@@ -1664,15 +1773,14 @@ int crypt_keyslot_change_by_passphrase(struct crypt_device *cd,
|
||||
size_t new_passphrase_size)
|
||||
{
|
||||
struct volume_key *vk = NULL;
|
||||
int r = -EINVAL;
|
||||
int r;
|
||||
|
||||
log_dbg("Changing passphrase from old keyslot %d to new %d.",
|
||||
keyslot_old, keyslot_new);
|
||||
|
||||
if (!isLUKS(cd->type)) {
|
||||
log_err(cd, _("This operation is supported only for LUKS device.\n"));
|
||||
return -EINVAL;
|
||||
}
|
||||
r = onlyLUKS(cd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = LUKS_open_key_with_hdr(keyslot_old, passphrase, passphrase_size,
|
||||
&cd->u.luks1.hdr, &vk, cd);
|
||||
@@ -1702,10 +1810,10 @@ int crypt_keyslot_change_by_passphrase(struct crypt_device *cd,
|
||||
|
||||
if (keyslot_old == keyslot_new) {
|
||||
if (r >= 0)
|
||||
log_verbose(cd, _("Key slot %d changed.\n"), r);
|
||||
log_verbose(cd, _("Key slot %d changed.\n"), keyslot_new);
|
||||
} else {
|
||||
if (r >= 0) {
|
||||
log_verbose(cd, _("Replaced with key slot %d.\n"), r);
|
||||
log_verbose(cd, _("Replaced with key slot %d.\n"), keyslot_new);
|
||||
r = crypt_keyslot_destroy(cd, keyslot_old);
|
||||
}
|
||||
}
|
||||
@@ -1713,7 +1821,7 @@ int crypt_keyslot_change_by_passphrase(struct crypt_device *cd,
|
||||
log_err(cd, _("Failed to swap new key slot.\n"));
|
||||
out:
|
||||
crypt_free_volume_key(vk);
|
||||
return r ?: keyslot_new;
|
||||
return r < 0 ? r : keyslot_new;
|
||||
}
|
||||
|
||||
int crypt_keyslot_add_by_keyfile_offset(struct crypt_device *cd,
|
||||
@@ -1733,10 +1841,9 @@ int crypt_keyslot_add_by_keyfile_offset(struct crypt_device *cd,
|
||||
log_dbg("Adding new keyslot, existing keyfile %s, new keyfile %s.",
|
||||
keyfile ?: "[none]", new_keyfile ?: "[none]");
|
||||
|
||||
if (!isLUKS(cd->type)) {
|
||||
log_err(cd, _("This operation is supported only for LUKS device.\n"));
|
||||
return -EINVAL;
|
||||
}
|
||||
r = onlyLUKS(cd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = keyslot_verify_or_find_empty(cd, &keyslot);
|
||||
if (r)
|
||||
@@ -1809,15 +1916,14 @@ int crypt_keyslot_add_by_volume_key(struct crypt_device *cd,
|
||||
size_t passphrase_size)
|
||||
{
|
||||
struct volume_key *vk = NULL;
|
||||
int r = -EINVAL;
|
||||
int r;
|
||||
char *new_password = NULL; size_t new_passwordLen;
|
||||
|
||||
log_dbg("Adding new keyslot %d using volume key.", keyslot);
|
||||
|
||||
if (!isLUKS(cd->type)) {
|
||||
log_err(cd, _("This operation is supported only for LUKS device.\n"));
|
||||
return -EINVAL;
|
||||
}
|
||||
r = onlyLUKS(cd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (volume_key)
|
||||
vk = crypt_alloc_volume_key(volume_key_size, volume_key);
|
||||
@@ -1857,13 +1963,13 @@ out:
|
||||
int crypt_keyslot_destroy(struct crypt_device *cd, int keyslot)
|
||||
{
|
||||
crypt_keyslot_info ki;
|
||||
int r;
|
||||
|
||||
log_dbg("Destroying keyslot %d.", keyslot);
|
||||
|
||||
if (!isLUKS(cd->type)) {
|
||||
log_err(cd, _("This operation is supported only for LUKS device.\n"));
|
||||
return -EINVAL;
|
||||
}
|
||||
r = onlyLUKS(cd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
ki = crypt_keyslot_status(cd, keyslot);
|
||||
if (ki == CRYPT_SLOT_INVALID) {
|
||||
@@ -2115,7 +2221,7 @@ int crypt_activate_by_volume_key(struct crypt_device *cd,
|
||||
}
|
||||
|
||||
r = VERITY_activate(cd, name, volume_key, volume_key_size,
|
||||
&cd->u.verity.hdr, CRYPT_ACTIVATE_READONLY);
|
||||
&cd->u.verity.hdr, flags|CRYPT_ACTIVATE_READONLY);
|
||||
|
||||
if (r == -EPERM) {
|
||||
free(cd->u.verity.root_hash);
|
||||
@@ -2234,10 +2340,9 @@ int crypt_volume_key_verify(struct crypt_device *cd,
|
||||
struct volume_key *vk;
|
||||
int r;
|
||||
|
||||
if (!isLUKS(cd->type)) {
|
||||
log_err(cd, _("This operation is supported only for LUKS device.\n"));
|
||||
return -EINVAL;
|
||||
}
|
||||
r = onlyLUKS(cd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
vk = crypt_alloc_volume_key(volume_key_size, volume_key);
|
||||
if (!vk)
|
||||
@@ -2267,7 +2372,7 @@ void crypt_set_password_retry(struct crypt_device *cd, int tries)
|
||||
|
||||
void crypt_set_iteration_time(struct crypt_device *cd, uint64_t iteration_time_ms)
|
||||
{
|
||||
log_dbg("Iteration time set to %" PRIu64 " miliseconds.", iteration_time_ms);
|
||||
log_dbg("Iteration time set to %" PRIu64 " milliseconds.", iteration_time_ms);
|
||||
cd->iteration_time = iteration_time_ms;
|
||||
}
|
||||
void crypt_set_iterarion_time(struct crypt_device *cd, uint64_t iteration_time_ms)
|
||||
@@ -2341,12 +2446,12 @@ static int _luks_dump(struct crypt_device *cd)
|
||||
int i;
|
||||
|
||||
log_std(cd, "LUKS header information for %s\n\n", mdata_device_path(cd));
|
||||
log_std(cd, "Version: \t%d\n", cd->u.luks1.hdr.version);
|
||||
log_std(cd, "Version: \t%" PRIu16 "\n", cd->u.luks1.hdr.version);
|
||||
log_std(cd, "Cipher name: \t%s\n", cd->u.luks1.hdr.cipherName);
|
||||
log_std(cd, "Cipher mode: \t%s\n", cd->u.luks1.hdr.cipherMode);
|
||||
log_std(cd, "Hash spec: \t%s\n", cd->u.luks1.hdr.hashSpec);
|
||||
log_std(cd, "Payload offset:\t%d\n", cd->u.luks1.hdr.payloadOffset);
|
||||
log_std(cd, "MK bits: \t%d\n", cd->u.luks1.hdr.keyBytes * 8);
|
||||
log_std(cd, "Payload offset:\t%" PRIu32 "\n", cd->u.luks1.hdr.payloadOffset);
|
||||
log_std(cd, "MK bits: \t%" PRIu32 "\n", cd->u.luks1.hdr.keyBytes * 8);
|
||||
log_std(cd, "MK digest: \t");
|
||||
hexprint(cd, cd->u.luks1.hdr.mkDigest, LUKS_DIGESTSIZE, " ");
|
||||
log_std(cd, "\n");
|
||||
@@ -2355,12 +2460,12 @@ static int _luks_dump(struct crypt_device *cd)
|
||||
log_std(cd, "\n \t");
|
||||
hexprint(cd, cd->u.luks1.hdr.mkDigestSalt+LUKS_SALTSIZE/2, LUKS_SALTSIZE/2, " ");
|
||||
log_std(cd, "\n");
|
||||
log_std(cd, "MK iterations: \t%d\n", cd->u.luks1.hdr.mkDigestIterations);
|
||||
log_std(cd, "MK iterations: \t%" PRIu32 "\n", cd->u.luks1.hdr.mkDigestIterations);
|
||||
log_std(cd, "UUID: \t%s\n\n", cd->u.luks1.hdr.uuid);
|
||||
for(i = 0; i < LUKS_NUMKEYS; i++) {
|
||||
if(cd->u.luks1.hdr.keyblock[i].active == LUKS_KEY_ENABLED) {
|
||||
log_std(cd, "Key Slot %d: ENABLED\n",i);
|
||||
log_std(cd, "\tIterations: \t%d\n",
|
||||
log_std(cd, "\tIterations: \t%" PRIu32 "\n",
|
||||
cd->u.luks1.hdr.keyblock[i].passwordIterations);
|
||||
log_std(cd, "\tSalt: \t");
|
||||
hexprint(cd, cd->u.luks1.hdr.keyblock[i].passwordSalt,
|
||||
@@ -2370,9 +2475,9 @@ static int _luks_dump(struct crypt_device *cd)
|
||||
LUKS_SALTSIZE/2, LUKS_SALTSIZE/2, " ");
|
||||
log_std(cd, "\n");
|
||||
|
||||
log_std(cd, "\tKey material offset:\t%d\n",
|
||||
log_std(cd, "\tKey material offset:\t%" PRIu32 "\n",
|
||||
cd->u.luks1.hdr.keyblock[i].keyMaterialOffset);
|
||||
log_std(cd, "\tAF stripes: \t%d\n",
|
||||
log_std(cd, "\tAF stripes: \t%" PRIu32 "\n",
|
||||
cd->u.luks1.hdr.keyblock[i].stripes);
|
||||
}
|
||||
else
|
||||
@@ -2417,6 +2522,31 @@ int crypt_dump(struct crypt_device *cd)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
||||
static int _init_by_name_crypt_none(struct crypt_device *cd)
|
||||
{
|
||||
struct crypt_dm_active_device dmd = {};
|
||||
int r;
|
||||
|
||||
if (cd->type || !cd->u.none.active_name)
|
||||
return -EINVAL;
|
||||
|
||||
r = dm_query_device(cd, cd->u.none.active_name,
|
||||
DM_ACTIVE_CRYPT_CIPHER |
|
||||
DM_ACTIVE_CRYPT_KEYSIZE, &dmd);
|
||||
if (r >= 0)
|
||||
r = crypt_parse_name_and_mode(dmd.u.crypt.cipher,
|
||||
cd->u.none.cipher, NULL,
|
||||
cd->u.none.cipher_mode);
|
||||
|
||||
if (!r)
|
||||
cd->u.none.key_size = dmd.u.crypt.vk->keylength;
|
||||
|
||||
crypt_free_volume_key(dmd.u.crypt.vk);
|
||||
free(CONST_CAST(void*)dmd.u.crypt.cipher);
|
||||
return r;
|
||||
}
|
||||
|
||||
const char *crypt_get_cipher(struct crypt_device *cd)
|
||||
{
|
||||
if (isPLAIN(cd->type))
|
||||
@@ -2431,6 +2561,9 @@ const char *crypt_get_cipher(struct crypt_device *cd)
|
||||
if (isTCRYPT(cd->type))
|
||||
return cd->u.tcrypt.params.cipher;
|
||||
|
||||
if (!cd->type && !_init_by_name_crypt_none(cd))
|
||||
return cd->u.none.cipher;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -2448,6 +2581,9 @@ const char *crypt_get_cipher_mode(struct crypt_device *cd)
|
||||
if (isTCRYPT(cd->type))
|
||||
return cd->u.tcrypt.params.mode;
|
||||
|
||||
if (!cd->type && !_init_by_name_crypt_none(cd))
|
||||
return cd->u.none.cipher_mode;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -2489,6 +2625,9 @@ int crypt_get_volume_key_size(struct crypt_device *cd)
|
||||
if (isTCRYPT(cd->type))
|
||||
return cd->u.tcrypt.params.key_size;
|
||||
|
||||
if (!cd->type && !_init_by_name_crypt_none(cd))
|
||||
return cd->u.none.key_size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2528,10 +2667,8 @@ uint64_t crypt_get_iv_offset(struct crypt_device *cd)
|
||||
|
||||
crypt_keyslot_info crypt_keyslot_status(struct crypt_device *cd, int keyslot)
|
||||
{
|
||||
if (!isLUKS(cd->type)) {
|
||||
log_err(cd, _("This operation is supported only for LUKS device.\n"));
|
||||
if (onlyLUKS(cd) < 0)
|
||||
return CRYPT_SLOT_INVALID;
|
||||
}
|
||||
|
||||
return LUKS_keyslot_info(&cd->u.luks1.hdr, keyslot);
|
||||
}
|
||||
|
||||
@@ -2,15 +2,13 @@ moduledir = $(libdir)/cryptsetup
|
||||
|
||||
noinst_LTLIBRARIES = libtcrypt.la
|
||||
|
||||
libtcrypt_la_CFLAGS = -Wall @CRYPTO_CFLAGS@
|
||||
libtcrypt_la_CFLAGS = -Wall $(AM_CFLAGS) @CRYPTO_CFLAGS@
|
||||
|
||||
libtcrypt_la_SOURCES = \
|
||||
tcrypt.c \
|
||||
tcrypt.h
|
||||
|
||||
AM_CPPFLAGS = -D_GNU_SOURCE \
|
||||
-D_LARGEFILE64_SOURCE \
|
||||
-D_FILE_OFFSET_BITS=64 \
|
||||
AM_CPPFLAGS = -include config.h \
|
||||
-I$(top_srcdir)/lib \
|
||||
-I$(top_srcdir)/lib/crypto_backend
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* TCRYPT (TrueCrypt-compatible) volume handling
|
||||
* TCRYPT (TrueCrypt-compatible) and VeraCrypt volume handling
|
||||
*
|
||||
* Copyright (C) 2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2013, Milan Broz
|
||||
* Copyright (C) 2012-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2017, Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -33,16 +33,23 @@
|
||||
/* TCRYPT PBKDF variants */
|
||||
static struct {
|
||||
unsigned int legacy:1;
|
||||
unsigned int veracrypt:1;
|
||||
const char *name;
|
||||
const char *hash;
|
||||
unsigned int iterations;
|
||||
} tcrypt_kdf[] = {
|
||||
{ 0, "pbkdf2", "ripemd160", 2000 },
|
||||
{ 0, "pbkdf2", "ripemd160", 1000 },
|
||||
{ 0, "pbkdf2", "sha512", 1000 },
|
||||
{ 0, "pbkdf2", "whirlpool", 1000 },
|
||||
{ 1, "pbkdf2", "sha1", 2000 },
|
||||
{ 0, NULL, NULL, 0 }
|
||||
{ 0, 0, "pbkdf2", "ripemd160", 2000 },
|
||||
{ 0, 0, "pbkdf2", "ripemd160", 1000 },
|
||||
{ 0, 0, "pbkdf2", "sha512", 1000 },
|
||||
{ 0, 0, "pbkdf2", "whirlpool", 1000 },
|
||||
{ 1, 0, "pbkdf2", "sha1", 2000 },
|
||||
{ 0, 1, "pbkdf2", "sha512", 500000 },
|
||||
{ 0, 1, "pbkdf2", "ripemd160", 655331 },
|
||||
{ 0, 1, "pbkdf2", "ripemd160", 327661 }, // boot only
|
||||
{ 0, 1, "pbkdf2", "whirlpool", 500000 },
|
||||
{ 0, 1, "pbkdf2", "sha256", 500000 }, // VeraCrypt 1.0f
|
||||
{ 0, 1, "pbkdf2", "sha256", 200000 }, // boot only
|
||||
{ 0, 0, NULL, NULL, 0 }
|
||||
};
|
||||
|
||||
struct tcrypt_alg {
|
||||
@@ -51,6 +58,7 @@ struct tcrypt_alg {
|
||||
unsigned int iv_size;
|
||||
unsigned int key_offset;
|
||||
unsigned int iv_offset; /* or tweak key offset */
|
||||
unsigned int key_extra_size;
|
||||
};
|
||||
|
||||
struct tcrypt_algs {
|
||||
@@ -66,101 +74,107 @@ struct tcrypt_algs {
|
||||
static struct tcrypt_algs tcrypt_cipher[] = {
|
||||
/* XTS mode */
|
||||
{0,1,64,"aes","xts-plain64",
|
||||
{{"aes", 64,16,0,32}}},
|
||||
{{"aes", 64,16,0,32,0}}},
|
||||
{0,1,64,"serpent","xts-plain64",
|
||||
{{"serpent",64,16,0,32}}},
|
||||
{{"serpent",64,16,0,32,0}}},
|
||||
{0,1,64,"twofish","xts-plain64",
|
||||
{{"twofish",64,16,0,32}}},
|
||||
{{"twofish",64,16,0,32,0}}},
|
||||
{0,2,128,"twofish-aes","xts-plain64",
|
||||
{{"twofish",64,16, 0,64},
|
||||
{"aes", 64,16,32,96}}},
|
||||
{{"twofish",64,16, 0,64,0},
|
||||
{"aes", 64,16,32,96,0}}},
|
||||
{0,3,192,"serpent-twofish-aes","xts-plain64",
|
||||
{{"serpent",64,16, 0, 96},
|
||||
{"twofish",64,16,32,128},
|
||||
{"aes", 64,16,64,160}}},
|
||||
{{"serpent",64,16, 0, 96,0},
|
||||
{"twofish",64,16,32,128,0},
|
||||
{"aes", 64,16,64,160,0}}},
|
||||
{0,2,128,"aes-serpent","xts-plain64",
|
||||
{{"aes", 64,16, 0,64},
|
||||
{"serpent",64,16,32,96}}},
|
||||
{{"aes", 64,16, 0,64,0},
|
||||
{"serpent",64,16,32,96,0}}},
|
||||
{0,3,192,"aes-twofish-serpent","xts-plain64",
|
||||
{{"aes", 64,16, 0, 96},
|
||||
{"twofish",64,16,32,128},
|
||||
{"serpent",64,16,64,160}}},
|
||||
{{"aes", 64,16, 0, 96,0},
|
||||
{"twofish",64,16,32,128,0},
|
||||
{"serpent",64,16,64,160,0}}},
|
||||
{0,2,128,"serpent-twofish","xts-plain64",
|
||||
{{"serpent",64,16, 0,64},
|
||||
{"twofish",64,16,32,96}}},
|
||||
{{"serpent",64,16, 0,64,0},
|
||||
{"twofish",64,16,32,96,0}}},
|
||||
|
||||
/* LRW mode */
|
||||
{0,1,48,"aes","lrw-benbi",
|
||||
{{"aes", 48,16,32,0}}},
|
||||
{{"aes", 48,16,32,0,0}}},
|
||||
{0,1,48,"serpent","lrw-benbi",
|
||||
{{"serpent",48,16,32,0}}},
|
||||
{{"serpent",48,16,32,0,0}}},
|
||||
{0,1,48,"twofish","lrw-benbi",
|
||||
{{"twofish",48,16,32,0}}},
|
||||
{{"twofish",48,16,32,0,0}}},
|
||||
{0,2,96,"twofish-aes","lrw-benbi",
|
||||
{{"twofish",48,16,32,0},
|
||||
{"aes", 48,16,64,0}}},
|
||||
{{"twofish",48,16,32,0,0},
|
||||
{"aes", 48,16,64,0,0}}},
|
||||
{0,3,144,"serpent-twofish-aes","lrw-benbi",
|
||||
{{"serpent",48,16,32,0},
|
||||
{"twofish",48,16,64,0},
|
||||
{"aes", 48,16,96,0}}},
|
||||
{{"serpent",48,16,32,0,0},
|
||||
{"twofish",48,16,64,0,0},
|
||||
{"aes", 48,16,96,0,0}}},
|
||||
{0,2,96,"aes-serpent","lrw-benbi",
|
||||
{{"aes", 48,16,32,0},
|
||||
{"serpent",48,16,64,0}}},
|
||||
{{"aes", 48,16,32,0,0},
|
||||
{"serpent",48,16,64,0,0}}},
|
||||
{0,3,144,"aes-twofish-serpent","lrw-benbi",
|
||||
{{"aes", 48,16,32,0},
|
||||
{"twofish",48,16,64,0},
|
||||
{"serpent",48,16,96,0}}},
|
||||
{{"aes", 48,16,32,0,0},
|
||||
{"twofish",48,16,64,0,0},
|
||||
{"serpent",48,16,96,0,0}}},
|
||||
{0,2,96,"serpent-twofish", "lrw-benbi",
|
||||
{{"serpent",48,16,32,0},
|
||||
{"twofish",48,16,64,0}}},
|
||||
{{"serpent",48,16,32,0,0},
|
||||
{"twofish",48,16,64,0,0}}},
|
||||
|
||||
/* Kernel LRW block size is fixed to 16 bytes for GF(2^128)
|
||||
* thus cannot be used with blowfish where block is 8 bytes.
|
||||
* There also no GF(2^64) support.
|
||||
{1,1,64,"blowfish_le","lrw-benbi",
|
||||
{{"blowfish_le",64,8,32,0}}},
|
||||
{{"blowfish_le",64,8,32,0,0}}},
|
||||
{1,2,112,"blowfish_le-aes","lrw-benbi",
|
||||
{{"blowfish_le",64, 8,32,0},
|
||||
{"aes", 48,16,88,0}}},
|
||||
{{"blowfish_le",64, 8,32,0,0},
|
||||
{"aes", 48,16,88,0,0}}},
|
||||
{1,3,160,"serpent-blowfish_le-aes","lrw-benbi",
|
||||
{{"serpent", 48,16, 32,0},
|
||||
{"blowfish_le",64, 8, 64,0},
|
||||
{"aes", 48,16,120,0}}},*/
|
||||
/* CBC + "outer" CBC (both with whitening) */
|
||||
{1,1,32,"aes","cbc-tcrypt",
|
||||
{{"aes", 32,16,32,0}}},
|
||||
{1,1,32,"serpent","cbc-tcrypt",
|
||||
{{"serpent",32,16,32,0}}},
|
||||
{1,1,32,"twofish","cbc-tcrypt",
|
||||
{{"twofish",32,16,32,0}}},
|
||||
{1,2,64,"twofish-aes","cbci-tcrypt",
|
||||
{{"twofish",32,16,32,0},
|
||||
{"aes", 32,16,64,0}}},
|
||||
{1,3,96,"serpent-twofish-aes","cbci-tcrypt",
|
||||
{{"serpent",32,16,32,0},
|
||||
{"twofish",32,16,64,0},
|
||||
{"aes", 32,16,96,0}}},
|
||||
{1,2,64,"aes-serpent","cbci-tcrypt",
|
||||
{{"aes", 32,16,32,0},
|
||||
{"serpent",32,16,64,0}}},
|
||||
{1,3,96,"aes-twofish-serpent", "cbci-tcrypt",
|
||||
{{"aes", 32,16,32,0},
|
||||
{"twofish",32,16,64,0},
|
||||
{"serpent",32,16,96,0}}},
|
||||
{1,2,64,"serpent-twofish", "cbci-tcrypt",
|
||||
{{"serpent",32,16,32,0},
|
||||
{"twofish",32,16,64,0}}},
|
||||
{1,1,16,"cast5","cbc-tcrypt",
|
||||
{{"cast5", 16,8,32,0}}},
|
||||
{1,1,24,"des3_ede","cbc-tcrypt",
|
||||
{{"des3_ede",24,8,32,0}}},
|
||||
{1,1,56,"blowfish_le","cbc-tcrypt",
|
||||
{{"blowfish_le",56,8,32,0}}},
|
||||
{1,2,88,"blowfish_le-aes","cbc-tcrypt",
|
||||
{{"blowfish_le",56, 8,32,0},
|
||||
{"aes", 32,16,88,0}}},
|
||||
{1,3,120,"serpent-blowfish_le-aes","cbc-tcrypt",
|
||||
{{"serpent", 32,16, 32,0},
|
||||
{"blowfish_le",56, 8, 64,0},
|
||||
{"aes", 32,16,120,0}}},
|
||||
{{"serpent", 48,16, 32,0,0},
|
||||
{"blowfish_le",64, 8, 64,0,0},
|
||||
{"aes", 48,16,120,0,0}}},*/
|
||||
|
||||
/*
|
||||
* CBC + "outer" CBC (both with whitening)
|
||||
* chain_key_size: alg_keys_bytes + IV_seed_bytes + whitening_bytes
|
||||
*/
|
||||
{1,1,32+16+16,"aes","cbc-tcw",
|
||||
{{"aes", 32,16,32,0,32}}},
|
||||
{1,1,32+16+16,"serpent","cbc-tcw",
|
||||
{{"serpent",32,16,32,0,32}}},
|
||||
{1,1,32+16+16,"twofish","cbc-tcw",
|
||||
{{"twofish",32,16,32,0,32}}},
|
||||
{1,2,64+16+16,"twofish-aes","cbci-tcrypt",
|
||||
{{"twofish",32,16,32,0,0},
|
||||
{"aes", 32,16,64,0,32}}},
|
||||
{1,3,96+16+16,"serpent-twofish-aes","cbci-tcrypt",
|
||||
{{"serpent",32,16,32,0,0},
|
||||
{"twofish",32,16,64,0,0},
|
||||
{"aes", 32,16,96,0,32}}},
|
||||
{1,2,64+16+16,"aes-serpent","cbci-tcrypt",
|
||||
{{"aes", 32,16,32,0,0},
|
||||
{"serpent",32,16,64,0,32}}},
|
||||
{1,3,96+16+16,"aes-twofish-serpent", "cbci-tcrypt",
|
||||
{{"aes", 32,16,32,0,0},
|
||||
{"twofish",32,16,64,0,0},
|
||||
{"serpent",32,16,96,0,32}}},
|
||||
{1,2,64+16+16,"serpent-twofish", "cbci-tcrypt",
|
||||
{{"serpent",32,16,32,0,0},
|
||||
{"twofish",32,16,64,0,32}}},
|
||||
{1,1,16+8+16,"cast5","cbc-tcw",
|
||||
{{"cast5", 16,8,32,0,24}}},
|
||||
{1,1,24+8+16,"des3_ede","cbc-tcw",
|
||||
{{"des3_ede",24,8,32,0,24}}},
|
||||
{1,1,56+8+16,"blowfish_le","cbc-tcrypt",
|
||||
{{"blowfish_le",56,8,32,0,24}}},
|
||||
{1,2,88+16+16,"blowfish_le-aes","cbc-tcrypt",
|
||||
{{"blowfish_le",56, 8,32,0,0},
|
||||
{"aes", 32,16,88,0,32}}},
|
||||
{1,3,120+16+16,"serpent-blowfish_le-aes","cbc-tcrypt",
|
||||
{{"serpent", 32,16, 32,0,0},
|
||||
{"blowfish_le",56, 8, 64,0,0},
|
||||
{"aes", 32,16,120,0,32}}},
|
||||
{}
|
||||
};
|
||||
|
||||
@@ -189,7 +203,7 @@ static int TCRYPT_hdr_from_disk(struct tcrypt_phdr *hdr,
|
||||
|
||||
/* Convert header to cpu format */
|
||||
hdr->d.version = be16_to_cpu(hdr->d.version);
|
||||
hdr->d.version_tc = le16_to_cpu(hdr->d.version_tc);
|
||||
hdr->d.version_tc = be16_to_cpu(hdr->d.version_tc);
|
||||
|
||||
hdr->d.keys_crc32 = be32_to_cpu(hdr->d.keys_crc32);
|
||||
|
||||
@@ -262,8 +276,8 @@ static int decrypt_blowfish_le_cbc(struct tcrypt_alg *alg,
|
||||
}
|
||||
|
||||
crypt_cipher_destroy(cipher);
|
||||
memset(iv, 0, bs);
|
||||
memset(iv_old, 0, bs);
|
||||
crypt_memzero(iv, bs);
|
||||
crypt_memzero(iv_old, bs);
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -289,6 +303,9 @@ static void TCRYPT_copy_key(struct tcrypt_alg *alg, const char *mode,
|
||||
memcpy(&out_key[ks2], key, TCRYPT_LRW_IKEY_LEN);
|
||||
} else if (!strncmp(mode, "cbc", 3)) {
|
||||
memcpy(out_key, &key[alg->key_offset], alg->key_size);
|
||||
/* IV + whitening */
|
||||
memcpy(&out_key[alg->key_size], &key[alg->iv_offset],
|
||||
alg->key_extra_size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,12 +314,13 @@ static int TCRYPT_decrypt_hdr_one(struct tcrypt_alg *alg, const char *mode,
|
||||
{
|
||||
char backend_key[TCRYPT_HDR_KEY_LEN];
|
||||
char iv[TCRYPT_HDR_IV_LEN] = {};
|
||||
char mode_name[MAX_CIPHER_LEN];
|
||||
char mode_name[MAX_CIPHER_LEN + 1];
|
||||
struct crypt_cipher *cipher;
|
||||
char *c, *buf = (char*)&hdr->e;
|
||||
int r;
|
||||
|
||||
/* Remove IV if present */
|
||||
mode_name[MAX_CIPHER_LEN] = '\0';
|
||||
strncpy(mode_name, mode, MAX_CIPHER_LEN);
|
||||
c = strchr(mode_name, '-');
|
||||
if (c)
|
||||
@@ -326,8 +344,8 @@ static int TCRYPT_decrypt_hdr_one(struct tcrypt_alg *alg, const char *mode,
|
||||
crypt_cipher_destroy(cipher);
|
||||
}
|
||||
|
||||
memset(backend_key, 0, sizeof(backend_key));
|
||||
memset(iv, 0, TCRYPT_HDR_IV_LEN);
|
||||
crypt_memzero(backend_key, sizeof(backend_key));
|
||||
crypt_memzero(iv, TCRYPT_HDR_IV_LEN);
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -377,19 +395,19 @@ out:
|
||||
if (cipher[j])
|
||||
crypt_cipher_destroy(cipher[j]);
|
||||
|
||||
memset(iv, 0, bs);
|
||||
memset(iv_old, 0, bs);
|
||||
crypt_memzero(iv, bs);
|
||||
crypt_memzero(iv_old, bs);
|
||||
return r;
|
||||
}
|
||||
|
||||
static int TCRYPT_decrypt_hdr(struct crypt_device *cd, struct tcrypt_phdr *hdr,
|
||||
const char *key, int legacy_modes)
|
||||
const char *key, uint32_t flags)
|
||||
{
|
||||
struct tcrypt_phdr hdr2;
|
||||
int i, j, r = -EINVAL;
|
||||
|
||||
for (i = 0; tcrypt_cipher[i].chain_count; i++) {
|
||||
if (!legacy_modes && tcrypt_cipher[i].legacy)
|
||||
if (!(flags & CRYPT_TCRYPT_LEGACY_MODES) && tcrypt_cipher[i].legacy)
|
||||
continue;
|
||||
log_dbg("TCRYPT: trying cipher %s-%s",
|
||||
tcrypt_cipher[i].long_name, tcrypt_cipher[i].mode);
|
||||
@@ -421,10 +439,17 @@ static int TCRYPT_decrypt_hdr(struct crypt_device *cd, struct tcrypt_phdr *hdr,
|
||||
r = i;
|
||||
break;
|
||||
}
|
||||
if ((flags & CRYPT_TCRYPT_VERA_MODES) &&
|
||||
!strncmp(hdr2.d.magic, VCRYPT_HDR_MAGIC, TCRYPT_HDR_MAGIC_LEN)) {
|
||||
log_dbg("TCRYPT: Signature magic detected (Veracrypt).");
|
||||
memcpy(&hdr->e, &hdr2.e, TCRYPT_HDR_LEN);
|
||||
r = i;
|
||||
break;
|
||||
}
|
||||
r = -EPERM;
|
||||
}
|
||||
|
||||
memset(&hdr2, 0, sizeof(hdr2));
|
||||
crypt_memzero(&hdr2, sizeof(hdr2));
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -444,8 +469,7 @@ static int TCRYPT_pool_keyfile(struct crypt_device *cd,
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* FIXME: add while */
|
||||
data_size = read(fd, data, TCRYPT_KEYFILE_LEN);
|
||||
data_size = read_buffer(fd, data, TCRYPT_KEYFILE_LEN);
|
||||
close(fd);
|
||||
if (data_size < 0) {
|
||||
log_err(cd, _("Error reading keyfile %s.\n"), keyfile);
|
||||
@@ -461,8 +485,8 @@ static int TCRYPT_pool_keyfile(struct crypt_device *cd,
|
||||
j %= TCRYPT_KEY_POOL_LEN;
|
||||
}
|
||||
|
||||
memset(&crc, 0, sizeof(crc));
|
||||
memset(data, 0, TCRYPT_KEYFILE_LEN);
|
||||
crypt_memzero(&crc, sizeof(crc));
|
||||
crypt_memzero(data, TCRYPT_KEYFILE_LEN);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -475,7 +499,7 @@ static int TCRYPT_init_hdr(struct crypt_device *cd,
|
||||
size_t passphrase_size;
|
||||
char *key;
|
||||
unsigned int i, skipped = 0;
|
||||
int r = -EINVAL, legacy_modes;
|
||||
int r = -EPERM;
|
||||
|
||||
if (posix_memalign((void*)&key, crypt_getpagesize(), TCRYPT_HDR_KEY_LEN))
|
||||
return -ENOMEM;
|
||||
@@ -488,7 +512,7 @@ static int TCRYPT_init_hdr(struct crypt_device *cd,
|
||||
if (params->passphrase_size > TCRYPT_KEY_POOL_LEN) {
|
||||
log_err(cd, _("Maximum TCRYPT passphrase length (%d) exceeded.\n"),
|
||||
TCRYPT_KEY_POOL_LEN);
|
||||
return -EPERM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Calculate pool content from keyfiles */
|
||||
@@ -502,9 +526,10 @@ static int TCRYPT_init_hdr(struct crypt_device *cd,
|
||||
for (i = 0; i < params->passphrase_size; i++)
|
||||
pwd[i] += params->passphrase[i];
|
||||
|
||||
legacy_modes = params->flags & CRYPT_TCRYPT_LEGACY_MODES ? 1 : 0;
|
||||
for (i = 0; tcrypt_kdf[i].name; i++) {
|
||||
if (!legacy_modes && tcrypt_kdf[i].legacy)
|
||||
if (!(params->flags & CRYPT_TCRYPT_LEGACY_MODES) && tcrypt_kdf[i].legacy)
|
||||
continue;
|
||||
if (!(params->flags & CRYPT_TCRYPT_VERA_MODES) && tcrypt_kdf[i].veracrypt)
|
||||
continue;
|
||||
/* Derive header key */
|
||||
log_dbg("TCRYPT: trying KDF: %s-%s-%d.",
|
||||
@@ -523,16 +548,16 @@ static int TCRYPT_init_hdr(struct crypt_device *cd,
|
||||
break;
|
||||
|
||||
/* Decrypt header */
|
||||
r = TCRYPT_decrypt_hdr(cd, hdr, key, legacy_modes);
|
||||
r = TCRYPT_decrypt_hdr(cd, hdr, key, params->flags);
|
||||
if (r == -ENOENT) {
|
||||
skipped++;
|
||||
continue;
|
||||
r = -EPERM;
|
||||
}
|
||||
if (r != -EPERM)
|
||||
break;
|
||||
}
|
||||
|
||||
if ((skipped && skipped == i) || r == -ENOTSUP) {
|
||||
if ((r < 0 && r != -EPERM && skipped && skipped == i) || r == -ENOTSUP) {
|
||||
log_err(cd, _("Required kernel crypto interface not available.\n"));
|
||||
#ifdef ENABLE_AF_ALG
|
||||
log_err(cd, _("Ensure you have algif_skcipher kernel module loaded.\n"));
|
||||
@@ -543,18 +568,19 @@ static int TCRYPT_init_hdr(struct crypt_device *cd,
|
||||
|
||||
r = TCRYPT_hdr_from_disk(hdr, params, i, r);
|
||||
if (!r) {
|
||||
log_dbg("TCRYPT: Header version: %d, req. %d, sector %d"
|
||||
log_dbg("TCRYPT: Magic: %s, Header version: %d, req. %d, sector %d"
|
||||
", mk_offset %" PRIu64 ", hidden_size %" PRIu64
|
||||
", volume size %" PRIu64, (int)hdr->d.version,
|
||||
(int)hdr->d.version_tc, (int)hdr->d.sector_size,
|
||||
", volume size %" PRIu64, tcrypt_kdf[i].veracrypt ?
|
||||
VCRYPT_HDR_MAGIC : TCRYPT_HDR_MAGIC,
|
||||
(int)hdr->d.version, (int)hdr->d.version_tc, (int)hdr->d.sector_size,
|
||||
hdr->d.mk_offset, hdr->d.hidden_volume_size, hdr->d.volume_size);
|
||||
log_dbg("TCRYPT: Header cipher %s-%s, key size %d",
|
||||
log_dbg("TCRYPT: Header cipher %s-%s, key size %zu",
|
||||
params->cipher, params->mode, params->key_size);
|
||||
}
|
||||
out:
|
||||
memset(pwd, 0, TCRYPT_KEY_POOL_LEN);
|
||||
crypt_memzero(pwd, TCRYPT_KEY_POOL_LEN);
|
||||
if (key)
|
||||
memset(key, 0, TCRYPT_HDR_KEY_LEN);
|
||||
crypt_memzero(key, TCRYPT_HDR_KEY_LEN);
|
||||
free(key);
|
||||
return r;
|
||||
}
|
||||
@@ -563,20 +589,37 @@ int TCRYPT_read_phdr(struct crypt_device *cd,
|
||||
struct tcrypt_phdr *hdr,
|
||||
struct crypt_params_tcrypt *params)
|
||||
{
|
||||
struct device *device = crypt_metadata_device(cd);
|
||||
struct device *base_device, *device = crypt_metadata_device(cd);
|
||||
ssize_t hdr_size = sizeof(struct tcrypt_phdr);
|
||||
char *base_device_path;
|
||||
int devfd = 0, r, bs;
|
||||
|
||||
assert(sizeof(struct tcrypt_phdr) == 512);
|
||||
|
||||
log_dbg("Reading TCRYPT header of size %d bytes from device %s.",
|
||||
log_dbg("Reading TCRYPT header of size %zu bytes from device %s.",
|
||||
hdr_size, device_path(device));
|
||||
|
||||
bs = device_block_size(device);
|
||||
if (bs < 0)
|
||||
return bs;
|
||||
|
||||
devfd = device_open(device, O_RDONLY);
|
||||
if (params->flags & CRYPT_TCRYPT_SYSTEM_HEADER &&
|
||||
crypt_dev_is_partition(device_path(device))) {
|
||||
base_device_path = crypt_get_base_device(device_path(device));
|
||||
|
||||
log_dbg("Reading TCRYPT system header from device %s.", base_device_path ?: "?");
|
||||
if (!base_device_path)
|
||||
return -EINVAL;
|
||||
|
||||
r = device_alloc(&base_device, base_device_path);
|
||||
free(base_device_path);
|
||||
if (r < 0)
|
||||
return r;
|
||||
devfd = device_open(base_device, O_RDONLY);
|
||||
device_free(base_device);
|
||||
} else
|
||||
devfd = device_open(device, O_RDONLY);
|
||||
|
||||
if (devfd == -1) {
|
||||
log_err(cd, _("Cannot open device %s.\n"), device_path(device));
|
||||
return -EINVAL;
|
||||
@@ -584,26 +627,26 @@ int TCRYPT_read_phdr(struct crypt_device *cd,
|
||||
|
||||
r = -EIO;
|
||||
if (params->flags & CRYPT_TCRYPT_SYSTEM_HEADER) {
|
||||
if (lseek(devfd, TCRYPT_HDR_SYSTEM_OFFSET, SEEK_SET) >= 0 &&
|
||||
read_blockwise(devfd, bs, hdr, hdr_size) == hdr_size)
|
||||
if (read_lseek_blockwise(devfd, bs, hdr, hdr_size,
|
||||
TCRYPT_HDR_SYSTEM_OFFSET) == hdr_size) {
|
||||
r = TCRYPT_init_hdr(cd, hdr, params);
|
||||
}
|
||||
} else if (params->flags & CRYPT_TCRYPT_HIDDEN_HEADER) {
|
||||
if (params->flags & CRYPT_TCRYPT_BACKUP_HEADER) {
|
||||
if (lseek(devfd, TCRYPT_HDR_HIDDEN_OFFSET_BCK, SEEK_END) >= 0 &&
|
||||
read_blockwise(devfd, bs, hdr, hdr_size) == hdr_size)
|
||||
if (read_lseek_blockwise(devfd, bs, hdr, hdr_size,
|
||||
TCRYPT_HDR_HIDDEN_OFFSET_BCK) == hdr_size)
|
||||
r = TCRYPT_init_hdr(cd, hdr, params);
|
||||
} else {
|
||||
if (lseek(devfd, TCRYPT_HDR_HIDDEN_OFFSET, SEEK_SET) >= 0 &&
|
||||
read_blockwise(devfd, bs, hdr, hdr_size) == hdr_size)
|
||||
if (read_lseek_blockwise(devfd, bs, hdr, hdr_size,
|
||||
TCRYPT_HDR_HIDDEN_OFFSET) == hdr_size)
|
||||
r = TCRYPT_init_hdr(cd, hdr, params);
|
||||
if (r &&
|
||||
lseek(devfd, TCRYPT_HDR_HIDDEN_OFFSET_OLD, SEEK_END) >= 0 &&
|
||||
read_blockwise(devfd, bs, hdr, hdr_size) == hdr_size)
|
||||
if (r && read_lseek_blockwise(devfd, bs, hdr, hdr_size,
|
||||
TCRYPT_HDR_HIDDEN_OFFSET_OLD) == hdr_size)
|
||||
r = TCRYPT_init_hdr(cd, hdr, params);
|
||||
}
|
||||
} else if (params->flags & CRYPT_TCRYPT_BACKUP_HEADER) {
|
||||
if (lseek(devfd, TCRYPT_HDR_OFFSET_BCK, SEEK_END) >= 0 &&
|
||||
read_blockwise(devfd, bs, hdr, hdr_size) == hdr_size)
|
||||
if (read_lseek_blockwise(devfd, bs, hdr, hdr_size,
|
||||
TCRYPT_HDR_OFFSET_BCK) == hdr_size)
|
||||
r = TCRYPT_init_hdr(cd, hdr, params);
|
||||
} else if (read_blockwise(devfd, bs, hdr, hdr_size) == hdr_size)
|
||||
r = TCRYPT_init_hdr(cd, hdr, params);
|
||||
@@ -636,10 +679,13 @@ int TCRYPT_activate(struct crypt_device *cd,
|
||||
uint32_t flags)
|
||||
{
|
||||
char cipher[MAX_CIPHER_LEN], dm_name[PATH_MAX], dm_dev_name[PATH_MAX];
|
||||
struct device *device = NULL;
|
||||
char *part_path;
|
||||
struct device *device = NULL, *part_device = NULL;
|
||||
unsigned int i;
|
||||
int r;
|
||||
uint32_t req_flags;
|
||||
struct tcrypt_algs *algs;
|
||||
enum devcheck device_check;
|
||||
struct crypt_dm_active_device dmd = {
|
||||
.target = DM_CRYPT,
|
||||
.size = 0,
|
||||
@@ -667,28 +713,69 @@ int TCRYPT_activate(struct crypt_device *cd,
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (strstr(params->mode, "-tcw"))
|
||||
req_flags = DM_TCW_SUPPORTED;
|
||||
else
|
||||
req_flags = DM_PLAIN64_SUPPORTED;
|
||||
|
||||
algs = TCRYPT_get_algs(params->cipher, params->mode);
|
||||
if (!algs)
|
||||
return -EINVAL;
|
||||
|
||||
if (params->flags & CRYPT_TCRYPT_HIDDEN_HEADER)
|
||||
if (hdr->d.sector_size == 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (params->flags & CRYPT_TCRYPT_SYSTEM_HEADER)
|
||||
dmd.size = 0;
|
||||
else if (params->flags & CRYPT_TCRYPT_HIDDEN_HEADER)
|
||||
dmd.size = hdr->d.hidden_volume_size / hdr->d.sector_size;
|
||||
else
|
||||
dmd.size = hdr->d.volume_size / hdr->d.sector_size;
|
||||
|
||||
r = device_block_adjust(cd, dmd.data_device, DEV_EXCL,
|
||||
if (dmd.flags & CRYPT_ACTIVATE_SHARED)
|
||||
device_check = DEV_SHARED;
|
||||
else
|
||||
device_check = DEV_EXCL;
|
||||
|
||||
if ((params->flags & CRYPT_TCRYPT_SYSTEM_HEADER) &&
|
||||
!crypt_dev_is_partition(device_path(dmd.data_device))) {
|
||||
part_path = crypt_get_partition_device(device_path(dmd.data_device),
|
||||
dmd.u.crypt.offset, dmd.size);
|
||||
if (part_path) {
|
||||
if (!device_alloc(&part_device, part_path)) {
|
||||
log_verbose(cd, _("Activating TCRYPT system encryption for partition %s.\n"),
|
||||
part_path);
|
||||
dmd.data_device = part_device;
|
||||
dmd.u.crypt.offset = 0;
|
||||
}
|
||||
free(part_path);
|
||||
} else
|
||||
/*
|
||||
* System encryption use the whole device mapping, there can
|
||||
* be active partitions.
|
||||
*/
|
||||
device_check = DEV_SHARED;
|
||||
}
|
||||
|
||||
r = device_block_adjust(cd, dmd.data_device, device_check,
|
||||
dmd.u.crypt.offset, &dmd.size, &dmd.flags);
|
||||
if (r)
|
||||
if (r) {
|
||||
device_free(part_device);
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Frome here, key size for every cipher must be the same */
|
||||
dmd.u.crypt.vk = crypt_alloc_volume_key(algs->cipher[0].key_size, NULL);
|
||||
if (!dmd.u.crypt.vk)
|
||||
dmd.u.crypt.vk = crypt_alloc_volume_key(algs->cipher[0].key_size +
|
||||
algs->cipher[0].key_extra_size, NULL);
|
||||
if (!dmd.u.crypt.vk) {
|
||||
device_free(part_device);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
for (i = algs->chain_count; i > 0; i--) {
|
||||
if (i == 1) {
|
||||
strncpy(dm_name, name, sizeof(dm_name));
|
||||
dm_name[sizeof(dm_name)-1] = '\0';
|
||||
strncpy(dm_name, name, sizeof(dm_name)-1);
|
||||
dmd.flags = flags;
|
||||
} else {
|
||||
snprintf(dm_name, sizeof(dm_name), "%s_%d", name, i-1);
|
||||
@@ -722,11 +809,12 @@ int TCRYPT_activate(struct crypt_device *cd,
|
||||
break;
|
||||
}
|
||||
|
||||
if (r < 0 && !(dm_flags() & DM_PLAIN64_SUPPORTED)) {
|
||||
log_err(cd, _("Kernel doesn't support plain64 IV.\n"));
|
||||
if (r < 0 && !(dm_flags() & req_flags)) {
|
||||
log_err(cd, _("Kernel doesn't support TCRYPT compatible mapping.\n"));
|
||||
r = -ENOTSUP;
|
||||
}
|
||||
|
||||
device_free(part_device);
|
||||
crypt_free_volume_key(dmd.u.crypt.vk);
|
||||
return r;
|
||||
}
|
||||
@@ -829,7 +917,7 @@ int TCRYPT_init_by_name(struct crypt_device *cd, const char *name,
|
||||
struct tcrypt_phdr *tcrypt_hdr)
|
||||
{
|
||||
struct tcrypt_algs *algs;
|
||||
char cipher[MAX_CIPHER_LEN * 4], mode[MAX_CIPHER_LEN], *tmp;
|
||||
char cipher[MAX_CIPHER_LEN * 4], mode[MAX_CIPHER_LEN+1], *tmp;
|
||||
size_t key_size;
|
||||
int r;
|
||||
|
||||
@@ -843,6 +931,7 @@ int TCRYPT_init_by_name(struct crypt_device *cd, const char *name,
|
||||
if (!tmp)
|
||||
return -EINVAL;
|
||||
*tmp = '\0';
|
||||
mode[MAX_CIPHER_LEN] = '\0';
|
||||
strncpy(mode, ++tmp, MAX_CIPHER_LEN);
|
||||
|
||||
key_size = dmd->u.crypt.vk->keylength;
|
||||
@@ -876,8 +965,11 @@ uint64_t TCRYPT_get_data_offset(struct crypt_device *cd,
|
||||
goto hdr_offset;
|
||||
|
||||
/* Mapping through whole device, not partition! */
|
||||
if (params->flags & CRYPT_TCRYPT_SYSTEM_HEADER)
|
||||
if (params->flags & CRYPT_TCRYPT_SYSTEM_HEADER) {
|
||||
if (crypt_dev_is_partition(device_path(crypt_metadata_device(cd))))
|
||||
return 0;
|
||||
goto hdr_offset;
|
||||
}
|
||||
|
||||
if (params->mode && !strncmp(params->mode, "xts", 3)) {
|
||||
if (hdr->d.version < 3)
|
||||
@@ -907,15 +999,21 @@ hdr_offset:
|
||||
|
||||
uint64_t TCRYPT_get_iv_offset(struct crypt_device *cd,
|
||||
struct tcrypt_phdr *hdr,
|
||||
struct crypt_params_tcrypt *params
|
||||
)
|
||||
struct crypt_params_tcrypt *params)
|
||||
{
|
||||
if (params->mode && !strncmp(params->mode, "xts", 3))
|
||||
return TCRYPT_get_data_offset(cd, hdr, params);
|
||||
else if (params->mode && !strncmp(params->mode, "lrw", 3))
|
||||
return 0;
|
||||
uint64_t iv_offset;
|
||||
|
||||
return hdr->d.mk_offset / hdr->d.sector_size;
|
||||
if (params->mode && !strncmp(params->mode, "xts", 3))
|
||||
iv_offset = TCRYPT_get_data_offset(cd, hdr, params);
|
||||
else if (params->mode && !strncmp(params->mode, "lrw", 3))
|
||||
iv_offset = 0;
|
||||
else
|
||||
iv_offset = hdr->d.mk_offset / hdr->d.sector_size;
|
||||
|
||||
if (params->flags & CRYPT_TCRYPT_SYSTEM_HEADER)
|
||||
iv_offset += crypt_dev_partition_offset(device_path(crypt_metadata_device(cd)));
|
||||
|
||||
return iv_offset;
|
||||
}
|
||||
|
||||
int TCRYPT_get_volume_key(struct crypt_device *cd,
|
||||
@@ -952,11 +1050,13 @@ int TCRYPT_dump(struct crypt_device *cd,
|
||||
struct tcrypt_phdr *hdr,
|
||||
struct crypt_params_tcrypt *params)
|
||||
{
|
||||
log_std(cd, "TCRYPT header information for %s\n",
|
||||
log_std(cd, "%s header information for %s\n",
|
||||
hdr->d.magic[0] == 'T' ? "TCRYPT" : "VERACRYPT",
|
||||
device_path(crypt_metadata_device(cd)));
|
||||
if (hdr->d.version) {
|
||||
log_std(cd, "Version: \t%d\n", hdr->d.version);
|
||||
log_std(cd, "Driver req.:\t%d\n", hdr->d.version_tc);
|
||||
log_std(cd, "Driver req.:\t%x.%x\n", hdr->d.version_tc >> 8,
|
||||
hdr->d.version_tc & 0xFF);
|
||||
|
||||
log_std(cd, "Sector size:\t%" PRIu32 "\n", hdr->d.sector_size);
|
||||
log_std(cd, "MK offset:\t%" PRIu64 "\n", hdr->d.mk_offset);
|
||||
@@ -964,6 +1064,6 @@ int TCRYPT_dump(struct crypt_device *cd,
|
||||
}
|
||||
log_std(cd, "Cipher chain:\t%s\n", params->cipher);
|
||||
log_std(cd, "Cipher mode:\t%s\n", params->mode);
|
||||
log_std(cd, "MK bits: \t%d\n", params->key_size * 8);
|
||||
log_std(cd, "MK bits: \t%zu\n", params->key_size * 8);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* TCRYPT (TrueCrypt-compatible) header defitinion
|
||||
*
|
||||
* Copyright (C) 2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2013, Milan Broz
|
||||
* Copyright (C) 2012-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2017, Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -29,6 +29,7 @@
|
||||
#define TCRYPT_HDR_LEN 448
|
||||
#define TCRYPT_HDR_KEY_LEN 192
|
||||
#define TCRYPT_HDR_MAGIC "TRUE"
|
||||
#define VCRYPT_HDR_MAGIC "VERA"
|
||||
#define TCRYPT_HDR_MAGIC_LEN 4
|
||||
|
||||
#define TCRYPT_HDR_HIDDEN_OFFSET_OLD -1536
|
||||
|
||||
165
lib/utils.c
165
lib/utils.c
@@ -1,10 +1,10 @@
|
||||
/*
|
||||
* utils - miscellaneous device utilities for cryptsetup
|
||||
*
|
||||
* Copyright (C) 2004, Christophe Saout <christophe@saout.de>
|
||||
* Copyright (C) 2004, Jana Saout <jana@saout.de>
|
||||
* Copyright (C) 2004-2007, Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2012, Milan Broz
|
||||
* Copyright (C) 2009-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2017, Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -56,22 +56,70 @@ static void *aligned_malloc(void **base, int size, int alignment)
|
||||
/* Credits go to Michal's padlock patches for this alignment code */
|
||||
char *ptr;
|
||||
|
||||
ptr = malloc(size + alignment);
|
||||
if(ptr == NULL) return NULL;
|
||||
ptr = malloc(size + alignment);
|
||||
if (!ptr)
|
||||
return NULL;
|
||||
|
||||
*base = ptr;
|
||||
if(alignment > 1 && ((long)ptr & (alignment - 1))) {
|
||||
if (alignment > 1 && ((long)ptr & (alignment - 1)))
|
||||
ptr += alignment - ((long)(ptr) & (alignment - 1));
|
||||
}
|
||||
|
||||
return ptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
ssize_t read_buffer(int fd, void *buf, size_t count)
|
||||
{
|
||||
size_t read_size = 0;
|
||||
ssize_t r;
|
||||
|
||||
if (fd < 0 || !buf)
|
||||
return -EINVAL;
|
||||
|
||||
do {
|
||||
r = read(fd, buf, count - read_size);
|
||||
if (r == -1 && errno != EINTR)
|
||||
return r;
|
||||
if (r == 0)
|
||||
return (ssize_t)read_size;
|
||||
if (r > 0) {
|
||||
read_size += (size_t)r;
|
||||
buf = (uint8_t*)buf + r;
|
||||
}
|
||||
} while (read_size != count);
|
||||
|
||||
return (ssize_t)count;
|
||||
}
|
||||
|
||||
ssize_t write_buffer(int fd, const void *buf, size_t count)
|
||||
{
|
||||
size_t write_size = 0;
|
||||
ssize_t w;
|
||||
|
||||
if (fd < 0 || !buf || !count)
|
||||
return -EINVAL;
|
||||
|
||||
do {
|
||||
w = write(fd, buf, count - write_size);
|
||||
if (w < 0 && errno != EINTR)
|
||||
return w;
|
||||
if (w == 0)
|
||||
return (ssize_t)write_size;
|
||||
if (w > 0) {
|
||||
write_size += (size_t) w;
|
||||
buf = (const uint8_t*)buf + w;
|
||||
}
|
||||
} while (write_size != count);
|
||||
|
||||
return (ssize_t)write_size;
|
||||
}
|
||||
|
||||
ssize_t write_blockwise(int fd, int bsize, void *orig_buf, size_t count)
|
||||
{
|
||||
void *hangover_buf, *hangover_buf_base = NULL;
|
||||
void *buf, *buf_base = NULL;
|
||||
int r, hangover, solid, alignment;
|
||||
int r, alignment;
|
||||
size_t hangover, solid;
|
||||
ssize_t ret = -1;
|
||||
|
||||
if (fd == -1 || !orig_buf || bsize <= 0)
|
||||
@@ -89,29 +137,31 @@ ssize_t write_blockwise(int fd, int bsize, void *orig_buf, size_t count)
|
||||
} else
|
||||
buf = orig_buf;
|
||||
|
||||
r = write(fd, buf, solid);
|
||||
if (r < 0 || r != solid)
|
||||
goto out;
|
||||
if (solid) {
|
||||
r = write_buffer(fd, buf, solid);
|
||||
if (r < 0 || r != (ssize_t)solid)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (hangover) {
|
||||
hangover_buf = aligned_malloc(&hangover_buf_base, bsize, alignment);
|
||||
if (!hangover_buf)
|
||||
goto out;
|
||||
|
||||
r = read(fd, hangover_buf, bsize);
|
||||
if (r < 0 || r < hangover)
|
||||
r = read_buffer(fd, hangover_buf, bsize);
|
||||
if (r < 0 || r < (ssize_t)hangover)
|
||||
goto out;
|
||||
|
||||
if (r < bsize)
|
||||
bsize = r;
|
||||
|
||||
r = lseek(fd, -bsize, SEEK_CUR);
|
||||
if (r < 0)
|
||||
if (lseek(fd, -bsize, SEEK_CUR) < 0)
|
||||
goto out;
|
||||
|
||||
memcpy(hangover_buf, (char*)buf + solid, hangover);
|
||||
|
||||
r = write(fd, hangover_buf, bsize);
|
||||
if (r < 0 || r < hangover)
|
||||
r = write_buffer(fd, hangover_buf, bsize);
|
||||
if (r < 0 || r < (ssize_t)hangover)
|
||||
goto out;
|
||||
}
|
||||
ret = count;
|
||||
@@ -122,10 +172,12 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t read_blockwise(int fd, int bsize, void *orig_buf, size_t count) {
|
||||
ssize_t read_blockwise(int fd, int bsize, void *orig_buf, size_t count)
|
||||
{
|
||||
void *hangover_buf, *hangover_buf_base = NULL;
|
||||
void *buf, *buf_base = NULL;
|
||||
int r, hangover, solid, alignment;
|
||||
int r, alignment;
|
||||
size_t hangover, solid;
|
||||
ssize_t ret = -1;
|
||||
|
||||
if (fd == -1 || !orig_buf || bsize <= 0)
|
||||
@@ -142,16 +194,16 @@ ssize_t read_blockwise(int fd, int bsize, void *orig_buf, size_t count) {
|
||||
} else
|
||||
buf = orig_buf;
|
||||
|
||||
r = read(fd, buf, solid);
|
||||
if(r < 0 || r != solid)
|
||||
r = read_buffer(fd, buf, solid);
|
||||
if (r < 0 || r != (ssize_t)solid)
|
||||
goto out;
|
||||
|
||||
if (hangover) {
|
||||
hangover_buf = aligned_malloc(&hangover_buf_base, bsize, alignment);
|
||||
if (!hangover_buf)
|
||||
goto out;
|
||||
r = read(fd, hangover_buf, bsize);
|
||||
if (r < 0 || r < hangover)
|
||||
r = read_buffer(fd, hangover_buf, bsize);
|
||||
if (r < 0 || r < (ssize_t)hangover)
|
||||
goto out;
|
||||
|
||||
memcpy((char *)buf + solid, hangover_buf, hangover);
|
||||
@@ -172,7 +224,8 @@ out:
|
||||
* is implicitly included in the read/write offset, which can not be set to non-aligned
|
||||
* boundaries. Hence, we combine llseek with write.
|
||||
*/
|
||||
ssize_t write_lseek_blockwise(int fd, int bsize, char *buf, size_t count, off_t offset) {
|
||||
ssize_t write_lseek_blockwise(int fd, int bsize, void *buf, size_t count, off_t offset)
|
||||
{
|
||||
char *frontPadBuf;
|
||||
void *frontPadBuf_base = NULL;
|
||||
int r, frontHang;
|
||||
@@ -182,6 +235,12 @@ ssize_t write_lseek_blockwise(int fd, int bsize, char *buf, size_t count, off_t
|
||||
if (fd == -1 || !buf || bsize <= 0)
|
||||
return -1;
|
||||
|
||||
if (offset < 0)
|
||||
offset = lseek(fd, offset, SEEK_END);
|
||||
|
||||
if (offset < 0)
|
||||
return -1;
|
||||
|
||||
frontHang = offset % bsize;
|
||||
|
||||
if (lseek(fd, offset - frontHang, SEEK_SET) < 0)
|
||||
@@ -193,7 +252,7 @@ ssize_t write_lseek_blockwise(int fd, int bsize, char *buf, size_t count, off_t
|
||||
if (!frontPadBuf)
|
||||
goto out;
|
||||
|
||||
r = read(fd, frontPadBuf, bsize);
|
||||
r = read_buffer(fd, frontPadBuf, bsize);
|
||||
if (r < 0 || r != bsize)
|
||||
goto out;
|
||||
|
||||
@@ -206,11 +265,11 @@ ssize_t write_lseek_blockwise(int fd, int bsize, char *buf, size_t count, off_t
|
||||
if (lseek(fd, offset - frontHang, SEEK_SET) < 0)
|
||||
goto out;
|
||||
|
||||
r = write(fd, frontPadBuf, bsize);
|
||||
r = write_buffer(fd, frontPadBuf, bsize);
|
||||
if (r < 0 || r != bsize)
|
||||
goto out;
|
||||
|
||||
buf += innerCount;
|
||||
buf = (char*)buf + innerCount;
|
||||
count -= innerCount;
|
||||
}
|
||||
|
||||
@@ -223,6 +282,58 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t read_lseek_blockwise(int fd, int bsize, void *buf, size_t count, off_t offset)
|
||||
{
|
||||
char *frontPadBuf;
|
||||
void *frontPadBuf_base = NULL;
|
||||
int r, frontHang;
|
||||
size_t innerCount = 0;
|
||||
ssize_t ret = -1;
|
||||
|
||||
if (fd == -1 || !buf || bsize <= 0)
|
||||
return -1;
|
||||
|
||||
if (offset < 0)
|
||||
offset = lseek(fd, offset, SEEK_END);
|
||||
|
||||
if (offset < 0)
|
||||
return -1;
|
||||
|
||||
frontHang = offset % bsize;
|
||||
|
||||
if (lseek(fd, offset - frontHang, SEEK_SET) < 0)
|
||||
return ret;
|
||||
|
||||
if (frontHang) {
|
||||
frontPadBuf = aligned_malloc(&frontPadBuf_base,
|
||||
bsize, get_alignment(fd));
|
||||
|
||||
if (!frontPadBuf)
|
||||
return ret;
|
||||
|
||||
r = read_buffer(fd, frontPadBuf, bsize);
|
||||
if (r < 0 || r != bsize)
|
||||
goto out;
|
||||
|
||||
innerCount = bsize - frontHang;
|
||||
if (innerCount > count)
|
||||
innerCount = count;
|
||||
|
||||
memcpy(buf, frontPadBuf + frontHang, innerCount);
|
||||
|
||||
buf = (char*)buf + innerCount;
|
||||
count -= innerCount;
|
||||
}
|
||||
|
||||
ret = read_blockwise(fd, bsize, buf, count);
|
||||
if (ret >= 0)
|
||||
ret += innerCount;
|
||||
out:
|
||||
free(frontPadBuf_base);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* MEMLOCK */
|
||||
#define DEFAULT_PROCESS_PRIORITY -18
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* libcryptsetup - cryptsetup library, cipher bechmark
|
||||
*
|
||||
* Copyright (C) 2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012, Milan Broz
|
||||
* Copyright (C) 2012-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2017, Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -21,8 +21,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
@@ -32,6 +31,12 @@
|
||||
*/
|
||||
#define CIPHER_BLOCK_BYTES 65536
|
||||
|
||||
/*
|
||||
* If the measured value is lower, encrypted buffer is probably too small
|
||||
* and calculated values are not reliable.
|
||||
*/
|
||||
#define CIPHER_TIME_MIN_MS 0.001
|
||||
|
||||
/*
|
||||
* The whole test depends on Linux kernel usermode crypto API for now.
|
||||
* (The same implementations are used in dm-crypt though.)
|
||||
@@ -47,19 +52,15 @@ struct cipher_perf {
|
||||
size_t buffer_size;
|
||||
};
|
||||
|
||||
static long time_ms(struct rusage *start, struct rusage *end)
|
||||
static int time_ms(struct timespec *start, struct timespec *end, double *ms)
|
||||
{
|
||||
long ms = 0;
|
||||
double start_ms, end_ms;
|
||||
|
||||
/* For kernel backend, we need to measure only tim in kernel.
|
||||
ms = (end->ru_utime.tv_sec - start->ru_utime.tv_sec) * 1000;
|
||||
ms += (end->ru_utime.tv_usec - start->ru_utime.tv_usec) / 1000;
|
||||
*/
|
||||
start_ms = start->tv_sec * 1000.0 + start->tv_nsec / (1000.0 * 1000);
|
||||
end_ms = end->tv_sec * 1000.0 + end->tv_nsec / (1000.0 * 1000);
|
||||
|
||||
ms += (end->ru_stime.tv_sec - start->ru_stime.tv_sec) * 1000;
|
||||
ms += (end->ru_stime.tv_usec - start->ru_stime.tv_usec) / 1000;
|
||||
|
||||
return ms;
|
||||
*ms = end_ms - start_ms;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cipher_perf_one(struct cipher_perf *cp, char *buf,
|
||||
@@ -98,26 +99,39 @@ static int cipher_perf_one(struct cipher_perf *cp, char *buf,
|
||||
|
||||
return r;
|
||||
}
|
||||
static long cipher_measure(struct cipher_perf *cp, char *buf,
|
||||
size_t buf_size, int encrypt)
|
||||
static int cipher_measure(struct cipher_perf *cp, char *buf,
|
||||
size_t buf_size, int encrypt, double *ms)
|
||||
{
|
||||
struct rusage rstart, rend;
|
||||
struct timespec start, end;
|
||||
int r;
|
||||
|
||||
if (getrusage(RUSAGE_SELF, &rstart) < 0)
|
||||
/*
|
||||
* Using getrusage would be better here but the precision
|
||||
* is not adequate, so better stick with CLOCK_MONOTONIC
|
||||
*/
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &start) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
r = cipher_perf_one(cp, buf, buf_size, encrypt);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (getrusage(RUSAGE_SELF, &rend) < 0)
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &end) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
return time_ms(&rstart, &rend);
|
||||
r = time_ms(&start, &end, ms);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (*ms < CIPHER_TIME_MIN_MS) {
|
||||
log_dbg("Measured cipher runtime (%1.6f) is too low.", *ms);
|
||||
return -ERANGE;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static double speed_mbs(unsigned long bytes, unsigned long ms)
|
||||
static double speed_mbs(unsigned long bytes, double ms)
|
||||
{
|
||||
double speed = bytes, s = ms / 1000.;
|
||||
|
||||
@@ -127,32 +141,32 @@ static double speed_mbs(unsigned long bytes, unsigned long ms)
|
||||
static int cipher_perf(struct cipher_perf *cp,
|
||||
double *encryption_mbs, double *decryption_mbs)
|
||||
{
|
||||
long ms_enc, ms_dec, ms;
|
||||
int repeat_enc, repeat_dec;
|
||||
double ms_enc, ms_dec, ms;
|
||||
int r, repeat_enc, repeat_dec;
|
||||
void *buf = NULL;
|
||||
|
||||
if (posix_memalign(&buf, crypt_getpagesize(), cp->buffer_size))
|
||||
return -ENOMEM;
|
||||
|
||||
ms_enc = 0;
|
||||
ms_enc = 0.0;
|
||||
repeat_enc = 1;
|
||||
while (ms_enc < 1000) {
|
||||
ms = cipher_measure(cp, buf, cp->buffer_size, 1);
|
||||
if (ms < 0) {
|
||||
while (ms_enc < 1000.0) {
|
||||
r = cipher_measure(cp, buf, cp->buffer_size, 1, &ms);
|
||||
if (r < 0) {
|
||||
free(buf);
|
||||
return (int)ms;
|
||||
return r;
|
||||
}
|
||||
ms_enc += ms;
|
||||
repeat_enc++;
|
||||
}
|
||||
|
||||
ms_dec = 0;
|
||||
ms_dec = 0.0;
|
||||
repeat_dec = 1;
|
||||
while (ms_dec < 1000) {
|
||||
ms = cipher_measure(cp, buf, cp->buffer_size, 0);
|
||||
if (ms < 0) {
|
||||
while (ms_dec < 1000.0) {
|
||||
r = cipher_measure(cp, buf, cp->buffer_size, 0, &ms);
|
||||
if (r < 0) {
|
||||
free(buf);
|
||||
return (int)ms;
|
||||
return r;
|
||||
}
|
||||
ms_dec += ms;
|
||||
repeat_dec++;
|
||||
@@ -226,7 +240,7 @@ int crypt_benchmark_kdf(struct crypt_device *cd,
|
||||
size_t salt_size,
|
||||
uint64_t *iterations_sec)
|
||||
{
|
||||
int r;
|
||||
int r, key_length = 0;
|
||||
|
||||
if (!iterations_sec)
|
||||
return -EINVAL;
|
||||
@@ -235,14 +249,21 @@ int crypt_benchmark_kdf(struct crypt_device *cd,
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
// FIXME: this should be in KDF check API parameters later
|
||||
if (cd)
|
||||
key_length = crypt_get_volume_key_size(cd);
|
||||
|
||||
if (key_length == 0)
|
||||
key_length = DEFAULT_LUKS1_KEYBITS / 8;
|
||||
|
||||
if (!strncmp(kdf, "pbkdf2", 6))
|
||||
r = crypt_pbkdf_check(kdf, hash, password, password_size,
|
||||
salt, salt_size, iterations_sec);
|
||||
salt, salt_size, key_length, iterations_sec);
|
||||
else
|
||||
r = -EINVAL;
|
||||
|
||||
if (!r)
|
||||
log_dbg("KDF %s, hash %s: %" PRIu64 " iterations per second.",
|
||||
kdf, hash, *iterations_sec);
|
||||
log_dbg("KDF %s, hash %s: %" PRIu64 " iterations per second (%d-bits key).",
|
||||
kdf, hash, *iterations_sec, key_length * 8);
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
* utils_crypt - cipher utilities for cryptsetup
|
||||
*
|
||||
* Copyright (C) 2004-2007, Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2012, Milan Broz
|
||||
* Copyright (C) 2009-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2017, Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
@@ -81,12 +82,24 @@ int crypt_parse_name_and_mode(const char *s, char *cipher, int *key_nums,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Replacement for memset(s, 0, n) on stack that can be optimized out
|
||||
* Also used in safe allocations for explicit memory wipe.
|
||||
*/
|
||||
void crypt_memzero(void *s, size_t n)
|
||||
{
|
||||
volatile uint8_t *p = (volatile uint8_t *)s;
|
||||
|
||||
while(n--)
|
||||
*p++ = 0;
|
||||
}
|
||||
|
||||
/* safe allocations */
|
||||
void *crypt_safe_alloc(size_t size)
|
||||
{
|
||||
struct safe_allocation *alloc;
|
||||
|
||||
if (!size)
|
||||
if (!size || size > (SIZE_MAX - offsetof(struct safe_allocation, data)))
|
||||
return NULL;
|
||||
|
||||
alloc = malloc(size + offsetof(struct safe_allocation, data));
|
||||
@@ -94,7 +107,7 @@ void *crypt_safe_alloc(size_t size)
|
||||
return NULL;
|
||||
|
||||
alloc->size = size;
|
||||
memset(&alloc->data, 0, size);
|
||||
crypt_memzero(&alloc->data, size);
|
||||
|
||||
/* coverity[leaked_storage] */
|
||||
return &alloc->data;
|
||||
@@ -110,7 +123,7 @@ void crypt_safe_free(void *data)
|
||||
alloc = (struct safe_allocation *)
|
||||
((char *)data - offsetof(struct safe_allocation, data));
|
||||
|
||||
memset(data, 0, alloc->size);
|
||||
crypt_memzero(data, alloc->size);
|
||||
|
||||
alloc->size = 0x55aa55aa;
|
||||
free(alloc);
|
||||
@@ -157,7 +170,7 @@ static int untimed_read(int fd, char *pass, size_t maxlen)
|
||||
static int timed_read(int fd, char *pass, size_t maxlen, long timeout)
|
||||
{
|
||||
struct timeval t;
|
||||
fd_set fds;
|
||||
fd_set fds = {}; /* Just to avoid scan-build false report for FD_SET */
|
||||
int failed = -1;
|
||||
|
||||
FD_ZERO(&fds);
|
||||
@@ -176,16 +189,18 @@ static int interactive_pass(const char *prompt, char *pass, size_t maxlen,
|
||||
{
|
||||
struct termios orig, tmp;
|
||||
int failed = -1;
|
||||
int infd = STDIN_FILENO, outfd;
|
||||
int infd, outfd;
|
||||
|
||||
if (maxlen < 1)
|
||||
goto out_err;
|
||||
return failed;
|
||||
|
||||
/* Read and write to /dev/tty if available */
|
||||
if ((infd = outfd = open("/dev/tty", O_RDWR)) == -1) {
|
||||
infd = open("/dev/tty", O_RDWR);
|
||||
if (infd == -1) {
|
||||
infd = STDIN_FILENO;
|
||||
outfd = STDERR_FILENO;
|
||||
}
|
||||
} else
|
||||
outfd = infd;
|
||||
|
||||
if (tcgetattr(infd, &orig))
|
||||
goto out_err;
|
||||
@@ -320,7 +335,7 @@ int crypt_get_key(const char *prompt,
|
||||
struct crypt_device *cd)
|
||||
{
|
||||
int fd, regular_file, read_stdin, char_read, unlimited_read = 0;
|
||||
int r = -EINVAL;
|
||||
int r = -EINVAL, newline;
|
||||
char *pass = NULL;
|
||||
size_t buflen, i, file_read_size;
|
||||
struct stat st;
|
||||
@@ -346,7 +361,7 @@ int crypt_get_key(const char *prompt,
|
||||
|
||||
/* If not requsted otherwise, we limit input to prevent memory exhaustion */
|
||||
if (keyfile_size_max == 0) {
|
||||
keyfile_size_max = DEFAULT_KEYFILE_SIZE_MAXKB * 1024;
|
||||
keyfile_size_max = DEFAULT_KEYFILE_SIZE_MAXKB * 1024 + 1;
|
||||
unlimited_read = 1;
|
||||
}
|
||||
|
||||
@@ -394,7 +409,7 @@ int crypt_get_key(const char *prompt,
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
for(i = 0; i < keyfile_size_max; i++) {
|
||||
for(i = 0, newline = 0; i < keyfile_size_max; i++) {
|
||||
if(i == buflen) {
|
||||
buflen += 4096;
|
||||
pass = crypt_safe_realloc(pass, buflen);
|
||||
@@ -412,12 +427,17 @@ int crypt_get_key(const char *prompt,
|
||||
}
|
||||
|
||||
/* Stop on newline only if not requested read from keyfile */
|
||||
if(char_read == 0 || (!key_file && pass[i] == '\n'))
|
||||
if (char_read == 0)
|
||||
break;
|
||||
if (!key_file && pass[i] == '\n') {
|
||||
newline = 1;
|
||||
pass[i] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fail if piped input dies reading nothing */
|
||||
if(!i && !regular_file) {
|
||||
if(!i && !regular_file && !newline) {
|
||||
log_dbg("Nothing read on input.");
|
||||
r = -EPIPE;
|
||||
goto out_err;
|
||||
@@ -471,68 +491,3 @@ ssize_t crypt_hex_to_bytes(const char *hex, char **result, int safe_alloc)
|
||||
*result = bytes;
|
||||
return i;
|
||||
}
|
||||
|
||||
/*
|
||||
* Device size string parsing, suffixes:
|
||||
* s|S - 512 bytes sectors
|
||||
* k |K |m |M |g |G |t |T - 1024 base
|
||||
* kiB|KiB|miB|MiB|giB|GiB|tiB|TiB - 1024 base
|
||||
* kb |KB |mM |MB |gB |GB |tB |TB - 1000 base
|
||||
*/
|
||||
int crypt_string_to_size(struct crypt_device *cd, const char *s, uint64_t *size)
|
||||
{
|
||||
char *endp = NULL;
|
||||
size_t len;
|
||||
uint64_t mult_base, mult, tmp;
|
||||
|
||||
*size = strtoull(s, &endp, 10);
|
||||
if (!isdigit(s[0]) ||
|
||||
(errno == ERANGE && *size == ULLONG_MAX) ||
|
||||
(errno != 0 && *size == 0))
|
||||
return -EINVAL;
|
||||
|
||||
if (!endp || !*endp)
|
||||
return 0;
|
||||
|
||||
len = strlen(endp);
|
||||
/* Allow "B" and "iB" suffixes */
|
||||
if (len > 3 ||
|
||||
(len == 3 && (endp[1] != 'i' || endp[2] != 'B')) ||
|
||||
(len == 2 && endp[1] != 'B'))
|
||||
return -EINVAL;
|
||||
|
||||
if (len == 1 || len == 3)
|
||||
mult_base = 1024;
|
||||
else
|
||||
mult_base = 1000;
|
||||
|
||||
mult = 1;
|
||||
switch (endp[0]) {
|
||||
case 's':
|
||||
case 'S': mult = 512;
|
||||
break;
|
||||
case 't':
|
||||
case 'T': mult *= mult_base;
|
||||
/* Fall through */
|
||||
case 'g':
|
||||
case 'G': mult *= mult_base;
|
||||
/* Fall through */
|
||||
case 'm':
|
||||
case 'M': mult *= mult_base;
|
||||
/* Fall through */
|
||||
case 'k':
|
||||
case 'K': mult *= mult_base;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
tmp = *size * mult;
|
||||
if ((tmp / *size) != mult) {
|
||||
log_dbg("Device size overflow.");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
*size = tmp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
* utils_crypt - cipher utilities for cryptsetup
|
||||
*
|
||||
* Copyright (C) 2004-2007, Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2012, Milan Broz
|
||||
* Copyright (C) 2009-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2017, Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -24,10 +24,9 @@
|
||||
#define _UTILS_CRYPT_H
|
||||
|
||||
#include <unistd.h>
|
||||
#include "config.h"
|
||||
|
||||
#define MAX_CIPHER_LEN 32
|
||||
#define MAX_CIPHER_LEN_STR "32"
|
||||
#define MAX_CIPHER_LEN_STR "31"
|
||||
#define MAX_KEYFILES 32
|
||||
|
||||
struct crypt_device;
|
||||
@@ -46,7 +45,8 @@ void *crypt_safe_alloc(size_t size);
|
||||
void crypt_safe_free(void *data);
|
||||
void *crypt_safe_realloc(void *data, size_t size);
|
||||
|
||||
void crypt_memzero(void *s, size_t n);
|
||||
|
||||
ssize_t crypt_hex_to_bytes(const char *hex, char **result, int safe_alloc);
|
||||
int crypt_string_to_size(struct crypt_device *cd, const char *s, uint64_t *size);
|
||||
|
||||
#endif /* _UTILS_CRYPT_H */
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/*
|
||||
* device backend utilities
|
||||
*
|
||||
* Copyright (C) 2004, Christophe Saout <christophe@saout.de>
|
||||
* Copyright (C) 2004, Jana Saout <jana@saout.de>
|
||||
* Copyright (C) 2004-2007, Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2012, Milan Broz
|
||||
* Copyright (C) 2009-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2017, Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -38,20 +38,108 @@ struct device {
|
||||
char *file_path;
|
||||
int loop_fd;
|
||||
|
||||
int o_direct:1;
|
||||
int init_done:1;
|
||||
};
|
||||
|
||||
static int device_ready(const char *device)
|
||||
static int device_block_size_fd(int fd, size_t *min_size)
|
||||
{
|
||||
int devfd, r = 0;
|
||||
struct stat st;
|
||||
int bsize = 0, r = -EINVAL;
|
||||
|
||||
if (fstat(fd, &st) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (S_ISREG(st.st_mode)) {
|
||||
r = (int)crypt_getpagesize();
|
||||
bsize = r;
|
||||
}
|
||||
else if (ioctl(fd, BLKSSZGET, &bsize) >= 0)
|
||||
r = bsize;
|
||||
else
|
||||
r = -EINVAL;
|
||||
|
||||
if (r < 0 || !min_size)
|
||||
return r;
|
||||
|
||||
if (S_ISREG(st.st_mode)) {
|
||||
/* file can be empty as well */
|
||||
if (st.st_size > bsize)
|
||||
*min_size = bsize;
|
||||
else
|
||||
*min_size = st.st_size;
|
||||
} else {
|
||||
/* block device must have at least one block */
|
||||
*min_size = bsize;
|
||||
}
|
||||
|
||||
return bsize;
|
||||
}
|
||||
|
||||
static int device_read_test(int devfd)
|
||||
{
|
||||
char buffer[512];
|
||||
int blocksize, r = -EIO;
|
||||
size_t minsize = 0;
|
||||
|
||||
blocksize = device_block_size_fd(devfd, &minsize);
|
||||
|
||||
if (blocksize < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (minsize == 0)
|
||||
return 0;
|
||||
|
||||
if (minsize > sizeof(buffer))
|
||||
minsize = sizeof(buffer);
|
||||
|
||||
if (read_blockwise(devfd, blocksize, buffer, minsize) == (ssize_t)minsize)
|
||||
r = 0;
|
||||
|
||||
crypt_memzero(buffer, sizeof(buffer));
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
* The direct-io is always preferred. The header is usually mapped to the same
|
||||
* device and can be accessed when the rest of device is mapped to data device.
|
||||
* Using dirct-io encsures that we do not mess with data in cache.
|
||||
* (But proper alignment should prevent this in the first place.)
|
||||
* The read test is needed to detect broken configurations (seen with remote
|
||||
* block devices) that allow open with direct-io but then fails on read.
|
||||
*/
|
||||
static int device_ready(struct device *device, int check_directio)
|
||||
{
|
||||
int devfd = -1, r = 0;
|
||||
struct stat st;
|
||||
|
||||
log_dbg("Trying to open and read device %s.", device);
|
||||
devfd = open(device, O_RDONLY);
|
||||
device->o_direct = 0;
|
||||
if (check_directio) {
|
||||
log_dbg("Trying to open and read device %s with direct-io.",
|
||||
device_path(device));
|
||||
devfd = open(device_path(device), O_RDONLY | O_DIRECT);
|
||||
if (devfd >= 0) {
|
||||
if (device_read_test(devfd) == 0) {
|
||||
device->o_direct = 1;
|
||||
} else {
|
||||
close(devfd);
|
||||
devfd = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (devfd < 0) {
|
||||
log_err(NULL, _("Device %s doesn't exist or access denied.\n"), device);
|
||||
log_dbg("Trying to open device %s without direct-io.",
|
||||
device_path(device));
|
||||
devfd = open(device_path(device), O_RDONLY);
|
||||
}
|
||||
|
||||
if (devfd < 0) {
|
||||
log_err(NULL, _("Device %s doesn't exist or access denied.\n"),
|
||||
device_path(device));
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (fstat(devfd, &st) < 0)
|
||||
r = -EINVAL;
|
||||
else if (!S_ISBLK(st.st_mode))
|
||||
@@ -65,12 +153,14 @@ int device_open(struct device *device, int flags)
|
||||
{
|
||||
int devfd;
|
||||
|
||||
devfd = open(device_path(device), flags | O_DIRECT | O_SYNC);
|
||||
if (devfd < 0 && errno == EINVAL) {
|
||||
log_dbg("Trying to open device %s without direct-io.",
|
||||
device_path(device));
|
||||
devfd = open(device_path(device), flags | O_SYNC);
|
||||
}
|
||||
flags |= O_SYNC;
|
||||
if (device->o_direct)
|
||||
flags |= O_DIRECT;
|
||||
|
||||
devfd = open(device_path(device), flags);
|
||||
|
||||
if (devfd < 0)
|
||||
log_dbg("Cannot open device %s.", device_path(device));
|
||||
|
||||
return devfd;
|
||||
}
|
||||
@@ -90,24 +180,24 @@ int device_alloc(struct device **device, const char *path)
|
||||
return -ENOMEM;
|
||||
|
||||
memset(dev, 0, sizeof(struct device));
|
||||
dev->path = strdup(path);
|
||||
if (!dev->path) {
|
||||
free(dev);
|
||||
return -ENOMEM;
|
||||
}
|
||||
dev->loop_fd = -1;
|
||||
|
||||
r = device_ready(path);
|
||||
r = device_ready(dev, 1);
|
||||
if (!r) {
|
||||
dev->init_done = 1;
|
||||
} else if (r == -ENOTBLK) {
|
||||
/* alloc loop later */
|
||||
} else if (r < 0) {
|
||||
free(dev->path);
|
||||
free(dev);
|
||||
return -ENOTBLK;
|
||||
}
|
||||
|
||||
dev->path = strdup(path);
|
||||
if (!dev->path) {
|
||||
free(dev);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
*device = dev;
|
||||
return 0;
|
||||
}
|
||||
@@ -208,27 +298,23 @@ out:
|
||||
|
||||
int device_block_size(struct device *device)
|
||||
{
|
||||
struct stat st;
|
||||
int fd, bsize = 0, r = -EINVAL;
|
||||
int fd, r = -EINVAL;
|
||||
|
||||
if (!device)
|
||||
return 0;
|
||||
|
||||
if (device->file_path)
|
||||
return (int)crypt_getpagesize();
|
||||
|
||||
fd = open(device->path, O_RDONLY);
|
||||
if(fd < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (fstat(fd, &st) < 0)
|
||||
goto out;
|
||||
r = device_block_size_fd(fd, NULL);
|
||||
|
||||
if (S_ISREG(st.st_mode)) {
|
||||
r = (int)crypt_getpagesize();
|
||||
goto out;
|
||||
}
|
||||
if (r <= 0)
|
||||
log_dbg("Cannot get block size for device %s.", device_path(device));
|
||||
|
||||
if (ioctl(fd, BLKSSZGET, &bsize) >= 0)
|
||||
r = bsize;
|
||||
out:
|
||||
close(fd);
|
||||
return r;
|
||||
}
|
||||
@@ -333,25 +419,22 @@ out:
|
||||
|
||||
static int device_internal_prepare(struct crypt_device *cd, struct device *device)
|
||||
{
|
||||
char *loop_device;
|
||||
char *loop_device = NULL, *file_path = NULL;
|
||||
int r, loop_fd, readonly = 0;
|
||||
|
||||
if (device->init_done)
|
||||
return 0;
|
||||
|
||||
log_dbg("Allocating a free loop device.");
|
||||
loop_device = crypt_loop_get_device();
|
||||
if (!loop_device) {
|
||||
if (getuid() || geteuid())
|
||||
log_err(cd, _("Cannot use a loopback device, "
|
||||
"running as non-root user.\n"));
|
||||
else
|
||||
log_err(cd, _("Cannot find a free loopback device.\n"));
|
||||
if (getuid() || geteuid()) {
|
||||
log_err(cd, _("Cannot use a loopback device, "
|
||||
"running as non-root user.\n"));
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
log_dbg("Allocating a free loop device.");
|
||||
|
||||
/* Keep the loop open, dettached on last close. */
|
||||
loop_fd = crypt_loop_attach(loop_device, device->path, 0, 1, &readonly);
|
||||
loop_fd = crypt_loop_attach(&loop_device, device->path, 0, 1, &readonly);
|
||||
if (loop_fd == -1) {
|
||||
log_err(cd, _("Attaching loopback device failed "
|
||||
"(loop device with autoclear flag is required).\n"));
|
||||
@@ -359,15 +442,19 @@ static int device_internal_prepare(struct crypt_device *cd, struct device *devic
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
r = device_ready(loop_device);
|
||||
file_path = device->path;
|
||||
device->path = loop_device;
|
||||
|
||||
r = device_ready(device, device->o_direct);
|
||||
if (r < 0) {
|
||||
device->path = file_path;
|
||||
crypt_loop_detach(loop_device);
|
||||
free(loop_device);
|
||||
return r;
|
||||
}
|
||||
|
||||
device->loop_fd = loop_fd;
|
||||
device->file_path = device->path;
|
||||
device->path = loop_device;
|
||||
device->file_path = file_path;
|
||||
device->init_done = 1;
|
||||
|
||||
return 0;
|
||||
@@ -440,3 +527,23 @@ size_t size_round_up(size_t size, unsigned int block)
|
||||
size_t s = (size + (block - 1)) / block;
|
||||
return s * block;
|
||||
}
|
||||
|
||||
void device_disable_direct_io(struct device *device)
|
||||
{
|
||||
device->o_direct = 0;
|
||||
}
|
||||
|
||||
int device_is_identical(struct device *device1, struct device *device2)
|
||||
{
|
||||
if (device1 == device2)
|
||||
return 1;
|
||||
|
||||
if (!device1 || !device2 || !device_path(device1) || !device_path(device2))
|
||||
return 0;
|
||||
|
||||
/* This should be better check - major/minor for block device etc */
|
||||
if (!strcmp(device_path(device1), device_path(device2)))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/*
|
||||
* devname - search for device name
|
||||
*
|
||||
* Copyright (C) 2004, Christophe Saout <christophe@saout.de>
|
||||
* Copyright (C) 2004, Jana Saout <jana@saout.de>
|
||||
* Copyright (C) 2004-2007, Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2013, Milan Broz
|
||||
* Copyright (C) 2009-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2017, Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -31,10 +31,10 @@
|
||||
#include <limits.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include "utils_dm.h"
|
||||
|
||||
char *crypt_lookup_dev(const char *dev_id);
|
||||
int crypt_sysfs_get_rotational(int major, int minor, int *rotational);
|
||||
#ifdef HAVE_SYS_SYSMACROS_H
|
||||
# include <sys/sysmacros.h> /* for major, minor */
|
||||
#endif
|
||||
#include "internal.h"
|
||||
|
||||
static char *__lookup_dev(char *path, dev_t dev, int dir_level, const int max_level)
|
||||
{
|
||||
@@ -170,16 +170,12 @@ char *crypt_lookup_dev(const char *dev_id)
|
||||
return devpath;
|
||||
}
|
||||
|
||||
int crypt_sysfs_get_rotational(int major, int minor, int *rotational)
|
||||
static int _read_uint64(const char *sysfs_path, uint64_t *value)
|
||||
{
|
||||
char path[PATH_MAX], tmp[64] = {0};
|
||||
char tmp[64] = {0};
|
||||
int fd, r;
|
||||
|
||||
if (snprintf(path, sizeof(path), "/sys/dev/block/%d:%d/queue/rotational",
|
||||
major, minor) < 0)
|
||||
return 0;
|
||||
|
||||
if ((fd = open(path, O_RDONLY)) < 0)
|
||||
if ((fd = open(sysfs_path, O_RDONLY)) < 0)
|
||||
return 0;
|
||||
r = read(fd, tmp, sizeof(tmp));
|
||||
close(fd);
|
||||
@@ -187,8 +183,191 @@ int crypt_sysfs_get_rotational(int major, int minor, int *rotational)
|
||||
if (r <= 0)
|
||||
return 0;
|
||||
|
||||
if (sscanf(tmp, "%d", rotational) != 1)
|
||||
if (sscanf(tmp, "%" PRIu64, value) != 1)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _sysfs_get_uint64(int major, int minor, uint64_t *value, const char *attr)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
|
||||
if (snprintf(path, sizeof(path), "/sys/dev/block/%d:%d/%s",
|
||||
major, minor, attr) < 0)
|
||||
return 0;
|
||||
|
||||
return _read_uint64(path, value);
|
||||
}
|
||||
|
||||
static int _path_get_uint64(const char *sysfs_path, uint64_t *value, const char *attr)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
|
||||
if (snprintf(path, sizeof(path), "%s/%s",
|
||||
sysfs_path, attr) < 0)
|
||||
return 0;
|
||||
|
||||
return _read_uint64(path, value);
|
||||
}
|
||||
|
||||
int crypt_dev_is_rotational(int major, int minor)
|
||||
{
|
||||
uint64_t val;
|
||||
|
||||
if (!_sysfs_get_uint64(major, minor, &val, "queue/rotational"))
|
||||
return 1; /* if failed, expect rotational disk */
|
||||
|
||||
return val ? 1 : 0;
|
||||
}
|
||||
|
||||
int crypt_dev_is_partition(const char *dev_path)
|
||||
{
|
||||
uint64_t val;
|
||||
struct stat st;
|
||||
|
||||
if (stat(dev_path, &st) < 0)
|
||||
return 0;
|
||||
|
||||
if (!S_ISBLK(st.st_mode))
|
||||
return 0;
|
||||
|
||||
if (!_sysfs_get_uint64(major(st.st_rdev), minor(st.st_rdev),
|
||||
&val, "partition"))
|
||||
return 0;
|
||||
|
||||
return val ? 1 : 0;
|
||||
}
|
||||
|
||||
uint64_t crypt_dev_partition_offset(const char *dev_path)
|
||||
{
|
||||
uint64_t val;
|
||||
struct stat st;
|
||||
|
||||
if (!crypt_dev_is_partition(dev_path))
|
||||
return 0;
|
||||
|
||||
if (stat(dev_path, &st) < 0)
|
||||
return 0;
|
||||
|
||||
if (!_sysfs_get_uint64(major(st.st_rdev), minor(st.st_rdev),
|
||||
&val, "start"))
|
||||
return 0;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/* Try to find partition which match offset and size on top level device */
|
||||
char *crypt_get_partition_device(const char *dev_path, uint64_t offset, uint64_t size)
|
||||
{
|
||||
char link[PATH_MAX], path[PATH_MAX], part_path[PATH_MAX], *devname;
|
||||
char *result = NULL;
|
||||
struct stat st;
|
||||
size_t devname_len;
|
||||
ssize_t len;
|
||||
struct dirent *entry;
|
||||
DIR *dir;
|
||||
uint64_t part_offset, part_size;
|
||||
|
||||
if (stat(dev_path, &st) < 0)
|
||||
return NULL;
|
||||
|
||||
if (!S_ISBLK(st.st_mode))
|
||||
return NULL;
|
||||
|
||||
if (snprintf(path, sizeof(path), "/sys/dev/block/%d:%d",
|
||||
major(st.st_rdev), minor(st.st_rdev)) < 0)
|
||||
return NULL;
|
||||
|
||||
dir = opendir(path);
|
||||
if (!dir)
|
||||
return NULL;
|
||||
|
||||
len = readlink(path, link, sizeof(link) - 1);
|
||||
if (len < 0) {
|
||||
closedir(dir);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Get top level disk name for sysfs search */
|
||||
link[len] = '\0';
|
||||
devname = strrchr(link, '/');
|
||||
if (!devname) {
|
||||
closedir(dir);
|
||||
return NULL;
|
||||
}
|
||||
devname++;
|
||||
|
||||
/* DM devices do not use kernel partitions. */
|
||||
if (dm_is_dm_kernel_name(devname)) {
|
||||
closedir(dir);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
devname_len = strlen(devname);
|
||||
while((entry = readdir(dir))) {
|
||||
if (strncmp(entry->d_name, devname, devname_len))
|
||||
continue;
|
||||
|
||||
if (snprintf(part_path, sizeof(part_path), "%s/%s",
|
||||
path, entry->d_name) < 0)
|
||||
continue;
|
||||
|
||||
if (stat(part_path, &st) < 0)
|
||||
continue;
|
||||
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
if (!_path_get_uint64(part_path, &part_offset, "start") ||
|
||||
!_path_get_uint64(part_path, &part_size, "size"))
|
||||
continue;
|
||||
if (part_offset == offset && part_size == size &&
|
||||
snprintf(part_path, sizeof(part_path), "/dev/%s",
|
||||
entry->d_name) > 0) {
|
||||
result = strdup(part_path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Try to find base device from partition */
|
||||
char *crypt_get_base_device(const char *dev_path)
|
||||
{
|
||||
char link[PATH_MAX], path[PATH_MAX], part_path[PATH_MAX], *devname;
|
||||
struct stat st;
|
||||
ssize_t len;
|
||||
|
||||
if (!crypt_dev_is_partition(dev_path))
|
||||
return NULL;
|
||||
|
||||
if (stat(dev_path, &st) < 0)
|
||||
return NULL;
|
||||
|
||||
if (snprintf(path, sizeof(path), "/sys/dev/block/%d:%d",
|
||||
major(st.st_rdev), minor(st.st_rdev)) < 0)
|
||||
return NULL;
|
||||
|
||||
len = readlink(path, link, sizeof(link) - 1);
|
||||
if (len < 0)
|
||||
return NULL;
|
||||
|
||||
/* Get top level disk name for sysfs search */
|
||||
link[len] = '\0';
|
||||
devname = strrchr(link, '/');
|
||||
if (!devname)
|
||||
return NULL;
|
||||
*devname = '\0';
|
||||
devname = strrchr(link, '/');
|
||||
if (!devname)
|
||||
return NULL;
|
||||
devname++;
|
||||
|
||||
if (dm_is_dm_kernel_name(devname))
|
||||
return NULL;
|
||||
|
||||
snprintf(part_path, sizeof(part_path), "/dev/%s", devname);
|
||||
return strdup(part_path);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/*
|
||||
* libdevmapper - device-mapper backend for cryptsetup
|
||||
*
|
||||
* Copyright (C) 2004, Christophe Saout <christophe@saout.de>
|
||||
* Copyright (C) 2004, Jana Saout <jana@saout.de>
|
||||
* Copyright (C) 2004-2007, Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2012, Milan Broz
|
||||
* Copyright (C) 2009-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2017, Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -39,6 +39,11 @@ struct device;
|
||||
#define DM_PLAIN64_SUPPORTED (1 << 3) /* plain64 IV */
|
||||
#define DM_DISCARDS_SUPPORTED (1 << 4) /* discards/TRIM option is supported */
|
||||
#define DM_VERITY_SUPPORTED (1 << 5) /* dm-verity target supported */
|
||||
#define DM_TCW_SUPPORTED (1 << 6) /* tcw (TCRYPT CBC with whitening) */
|
||||
#define DM_SAME_CPU_CRYPT_SUPPORTED (1 << 7) /* same_cpu_crypt */
|
||||
#define DM_SUBMIT_FROM_CRYPT_CPUS_SUPPORTED (1 << 8) /* submit_from_crypt_cpus */
|
||||
#define DM_VERITY_ON_CORRUPTION_SUPPORTED (1 << 9) /* ignore/restart_on_corruption, ignore_zero_block */
|
||||
|
||||
uint32_t dm_flags(void);
|
||||
|
||||
#define DM_ACTIVE_DEVICE (1 << 0)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* FIPS mode utilities
|
||||
*
|
||||
* Copyright (C) 2011-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2011-2017, Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -18,46 +18,29 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "libcryptsetup.h"
|
||||
#include "nls.h"
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include "utils_fips.h"
|
||||
#include "config.h"
|
||||
|
||||
#if !ENABLE_FIPS
|
||||
int crypt_fips_mode(void) { return 0; }
|
||||
void crypt_fips_libcryptsetup_check(struct crypt_device *cd) {}
|
||||
void crypt_fips_self_check(struct crypt_device *cd) {}
|
||||
#else
|
||||
#include <fipscheck.h>
|
||||
static int kernel_fips_mode(void)
|
||||
{
|
||||
int fd;
|
||||
char buf[1] = "";
|
||||
|
||||
if ((fd = open("/proc/sys/crypto/fips_enabled", O_RDONLY)) >= 0) {
|
||||
while (read(fd, buf, sizeof(buf)) < 0 && errno == EINTR);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
return (buf[0] == '1') ? 1 : 0;
|
||||
}
|
||||
|
||||
int crypt_fips_mode(void)
|
||||
{
|
||||
return FIPSCHECK_kernel_fips_mode();
|
||||
}
|
||||
|
||||
static void crypt_fips_verify(struct crypt_device *cd,
|
||||
const char *name, const char *function)
|
||||
{
|
||||
if (!crypt_fips_mode())
|
||||
return;
|
||||
|
||||
if (!FIPSCHECK_verify(name, function)) {
|
||||
crypt_log(cd, CRYPT_LOG_ERROR, _("FIPS checksum verification failed.\n"));
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
crypt_log(cd, CRYPT_LOG_VERBOSE, _("Running in FIPS mode.\n"));
|
||||
}
|
||||
|
||||
void crypt_fips_libcryptsetup_check(struct crypt_device *cd)
|
||||
{
|
||||
crypt_fips_verify(cd, LIBCRYPTSETUP_VERSION_FIPS, "crypt_init");
|
||||
}
|
||||
|
||||
void crypt_fips_self_check(struct crypt_device *cd)
|
||||
{
|
||||
crypt_fips_verify(cd, NULL, NULL);
|
||||
return kernel_fips_mode() && !access("/etc/system-fips", F_OK);
|
||||
}
|
||||
#endif /* ENABLE_FIPS */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* FIPS mode utilities
|
||||
*
|
||||
* Copyright (C) 2011-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2011-2017, Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -21,10 +21,6 @@
|
||||
#ifndef _UTILS_FIPS_H
|
||||
#define _UTILS_FIPS_H
|
||||
|
||||
struct crypt_device;
|
||||
|
||||
int crypt_fips_mode(void);
|
||||
void crypt_fips_libcryptsetup_check(struct crypt_device *cd);
|
||||
void crypt_fips_self_check(struct crypt_device *cd);
|
||||
|
||||
#endif /* _UTILS_FIPS_H */
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* loopback block device utilities
|
||||
*
|
||||
* Copyright (C) 2011-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2012, Milan Broz
|
||||
* Copyright (C) 2009-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2017, Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -19,6 +19,7 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
@@ -28,6 +29,9 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef HAVE_SYS_SYSMACROS_H
|
||||
# include <sys/sysmacros.h> /* for major, minor */
|
||||
#endif
|
||||
#include <linux/loop.h>
|
||||
|
||||
#include "utils_loop.h"
|
||||
@@ -42,6 +46,10 @@
|
||||
#define LOOP_CTL_GET_FREE 0x4C82
|
||||
#endif
|
||||
|
||||
#ifndef LOOP_SET_CAPACITY
|
||||
#define LOOP_SET_CAPACITY 0x4C07
|
||||
#endif
|
||||
|
||||
static char *crypt_loop_get_device_old(void)
|
||||
{
|
||||
char dev[20];
|
||||
@@ -66,7 +74,7 @@ static char *crypt_loop_get_device_old(void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *crypt_loop_get_device(void)
|
||||
static char *crypt_loop_get_device(void)
|
||||
{
|
||||
char dev[64];
|
||||
int i, loop_fd;
|
||||
@@ -92,12 +100,15 @@ char *crypt_loop_get_device(void)
|
||||
return strdup(dev);
|
||||
}
|
||||
|
||||
int crypt_loop_attach(const char *loop, const char *file, int offset,
|
||||
int crypt_loop_attach(char **loop, const char *file, int offset,
|
||||
int autoclear, int *readonly)
|
||||
{
|
||||
struct loop_info64 lo64 = {0};
|
||||
char *lo_file_name;
|
||||
int loop_fd = -1, file_fd = -1, r = 1;
|
||||
|
||||
*loop = NULL;
|
||||
|
||||
file_fd = open(file, (*readonly ? O_RDONLY : O_RDWR) | O_EXCL);
|
||||
if (file_fd < 0 && (errno == EROFS || errno == EACCES) && !*readonly) {
|
||||
*readonly = 1;
|
||||
@@ -106,18 +117,33 @@ int crypt_loop_attach(const char *loop, const char *file, int offset,
|
||||
if (file_fd < 0)
|
||||
goto out;
|
||||
|
||||
loop_fd = open(loop, *readonly ? O_RDONLY : O_RDWR);
|
||||
if (loop_fd < 0)
|
||||
goto out;
|
||||
while (loop_fd < 0) {
|
||||
*loop = crypt_loop_get_device();
|
||||
if (!*loop)
|
||||
goto out;
|
||||
|
||||
strncpy((char*)lo64.lo_file_name, file, LO_NAME_SIZE);
|
||||
loop_fd = open(*loop, *readonly ? O_RDONLY : O_RDWR);
|
||||
if (loop_fd < 0)
|
||||
goto out;
|
||||
|
||||
if (ioctl(loop_fd, LOOP_SET_FD, file_fd) < 0) {
|
||||
if (errno != EBUSY)
|
||||
goto out;
|
||||
free(*loop);
|
||||
*loop = NULL;
|
||||
|
||||
close(loop_fd);
|
||||
loop_fd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
lo_file_name = (char*)lo64.lo_file_name;
|
||||
lo_file_name[LO_NAME_SIZE-1] = '\0';
|
||||
strncpy(lo_file_name, file, LO_NAME_SIZE-1);
|
||||
lo64.lo_offset = offset;
|
||||
if (autoclear)
|
||||
lo64.lo_flags |= LO_FLAGS_AUTOCLEAR;
|
||||
|
||||
if (ioctl(loop_fd, LOOP_SET_FD, file_fd) < 0)
|
||||
goto out;
|
||||
|
||||
if (ioctl(loop_fd, LOOP_SET_STATUS64, &lo64) < 0) {
|
||||
(void)ioctl(loop_fd, LOOP_CLR_FD, 0);
|
||||
goto out;
|
||||
@@ -139,6 +165,10 @@ out:
|
||||
close(loop_fd);
|
||||
if (file_fd >= 0)
|
||||
close(file_fd);
|
||||
if (r && *loop) {
|
||||
free(*loop);
|
||||
*loop = NULL;
|
||||
}
|
||||
return r ? -1 : loop_fd;
|
||||
}
|
||||
|
||||
@@ -157,6 +187,21 @@ int crypt_loop_detach(const char *loop)
|
||||
return r;
|
||||
}
|
||||
|
||||
int crypt_loop_resize(const char *loop)
|
||||
{
|
||||
int loop_fd = -1, r = 1;
|
||||
|
||||
loop_fd = open(loop, O_RDONLY);
|
||||
if (loop_fd < 0)
|
||||
return 1;
|
||||
|
||||
if (!ioctl(loop_fd, LOOP_SET_CAPACITY, 0))
|
||||
r = 0;
|
||||
|
||||
close(loop_fd);
|
||||
return r;
|
||||
}
|
||||
|
||||
static char *_ioctl_backing_file(const char *loop)
|
||||
{
|
||||
struct loop_info64 lo64 = {0};
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
/*
|
||||
* loopback block device utilities
|
||||
*
|
||||
* Copyright (C) 2011-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2017, Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -23,11 +24,11 @@
|
||||
|
||||
/* loopback device helpers */
|
||||
|
||||
char *crypt_loop_get_device(void);
|
||||
char *crypt_loop_backing_file(const char *loop);
|
||||
int crypt_loop_device(const char *loop);
|
||||
int crypt_loop_attach(const char *loop, const char *file, int offset,
|
||||
int crypt_loop_attach(char **loop, const char *file, int offset,
|
||||
int autoclear, int *readonly);
|
||||
int crypt_loop_detach(const char *loop);
|
||||
int crypt_loop_resize(const char *loop);
|
||||
|
||||
#endif /* _UTILS_LOOP_H */
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
* utils_wipe - wipe a device
|
||||
*
|
||||
* Copyright (C) 2004-2007, Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2011-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2012, Milan Broz
|
||||
* Copyright (C) 2009-2017, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2017, Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -29,6 +29,9 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef HAVE_SYS_SYSMACROS_H
|
||||
# include <sys/sysmacros.h> /* for major, minor */
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "libcryptsetup.h"
|
||||
@@ -124,11 +127,11 @@ int crypt_wipe(struct device *device,
|
||||
{
|
||||
struct stat st;
|
||||
char *buffer;
|
||||
int devfd, flags, rotational, bsize;
|
||||
int devfd, flags, bsize;
|
||||
ssize_t written;
|
||||
|
||||
if (!size || size % SECTOR_SIZE || (size > MAXIMUM_WIPE_BYTES)) {
|
||||
log_dbg("Unsuported wipe size for device %s: %ld.",
|
||||
log_dbg("Unsupported wipe size for device %s: %ld.",
|
||||
device_path(device), (unsigned long)size);
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -139,14 +142,12 @@ int crypt_wipe(struct device *device,
|
||||
}
|
||||
|
||||
if (type == CRYPT_WIPE_DISK && S_ISBLK(st.st_mode)) {
|
||||
rotational = 0;
|
||||
if (!crypt_sysfs_get_rotational(major(st.st_rdev),
|
||||
minor(st.st_rdev),
|
||||
&rotational))
|
||||
rotational = 1;
|
||||
log_dbg("Rotational flag is %d.", rotational);
|
||||
if (!rotational)
|
||||
if (!crypt_dev_is_rotational(major(st.st_rdev),
|
||||
minor(st.st_rdev))) {
|
||||
type = CRYPT_WIPE_SSD;
|
||||
log_dbg("Non-rotational device, using SSD wipe mode.");
|
||||
} else
|
||||
log_dbg("Rotational device, using normal wipe mode.");
|
||||
}
|
||||
|
||||
bsize = device_block_size(device);
|
||||
@@ -185,7 +186,7 @@ int crypt_wipe(struct device *device,
|
||||
written = _crypt_wipe_random(devfd, bsize, buffer, offset, size);
|
||||
break;
|
||||
default:
|
||||
log_dbg("Unsuported wipe type requested: (%d)", type);
|
||||
log_dbg("Unsupported wipe type requested: (%d)", type);
|
||||
written = -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,15 +2,13 @@ moduledir = $(libdir)/cryptsetup
|
||||
|
||||
noinst_LTLIBRARIES = libverity.la
|
||||
|
||||
libverity_la_CFLAGS = -Wall @CRYPTO_CFLAGS@
|
||||
libverity_la_CFLAGS = -Wall $(AM_CFLAGS) @CRYPTO_CFLAGS@
|
||||
|
||||
libverity_la_SOURCES = \
|
||||
verity_hash.c \
|
||||
verity.c \
|
||||
verity.h
|
||||
|
||||
AM_CPPFLAGS = -D_GNU_SOURCE \
|
||||
-D_LARGEFILE64_SOURCE \
|
||||
-D_FILE_OFFSET_BITS=64 \
|
||||
AM_CPPFLAGS = -include config.h \
|
||||
-I$(top_srcdir)/lib \
|
||||
-I$(top_srcdir)/lib/crypto_backend
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* dm-verity volume handling
|
||||
*
|
||||
* Copyright (C) 2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2017, Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
#define VERITY_SIGNATURE "verity\0\0"
|
||||
|
||||
/* http://code.google.com/p/cryptsetup/wiki/DMVerity#Verity_superblock_format */
|
||||
/* https://gitlab.com/cryptsetup/cryptsetup/wikis/DMVerity#verity-superblock-format */
|
||||
struct verity_sb {
|
||||
uint8_t signature[8]; /* "verity\0\0" */
|
||||
uint32_t version; /* superblock version */
|
||||
@@ -63,11 +63,11 @@ int VERITY_read_sb(struct crypt_device *cd,
|
||||
ssize_t hdr_size = sizeof(struct verity_sb);
|
||||
int devfd = 0, sb_version;
|
||||
|
||||
log_dbg("Reading VERITY header of size %u on device %s, offset %" PRIu64 ".",
|
||||
log_dbg("Reading VERITY header of size %zu on device %s, offset %" PRIu64 ".",
|
||||
sizeof(struct verity_sb), device_path(device), sb_offset);
|
||||
|
||||
if (params->flags & CRYPT_VERITY_NO_HEADER) {
|
||||
log_err(cd, _("Verity device doesn't use on-disk header.\n"),
|
||||
log_err(cd, _("Verity device %s doesn't use on-disk header.\n"),
|
||||
device_path(device));
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -156,20 +156,21 @@ int VERITY_write_sb(struct crypt_device *cd,
|
||||
int bsize = device_block_size(device);
|
||||
struct verity_sb sb = {};
|
||||
ssize_t hdr_size = sizeof(struct verity_sb);
|
||||
char *algorithm;
|
||||
uuid_t uuid;
|
||||
int r, devfd = 0;
|
||||
|
||||
log_dbg("Updating VERITY header of size %u on device %s, offset %" PRIu64 ".",
|
||||
log_dbg("Updating VERITY header of size %zu on device %s, offset %" PRIu64 ".",
|
||||
sizeof(struct verity_sb), device_path(device), sb_offset);
|
||||
|
||||
if (!uuid_string || uuid_parse(uuid_string, uuid) == -1) {
|
||||
log_err(cd, _("Wrong VERITY UUID format provided.\n"),
|
||||
log_err(cd, _("Wrong VERITY UUID format provided on device %s.\n"),
|
||||
device_path(device));
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (params->flags & CRYPT_VERITY_NO_HEADER) {
|
||||
log_err(cd, _("Verity device doesn't use on-disk header.\n"),
|
||||
log_err(cd, _("Verity device %s doesn't use on-disk header.\n"),
|
||||
device_path(device));
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -187,7 +188,9 @@ int VERITY_write_sb(struct crypt_device *cd,
|
||||
sb.hash_block_size = cpu_to_le32(params->hash_block_size);
|
||||
sb.salt_size = cpu_to_le16(params->salt_size);
|
||||
sb.data_blocks = cpu_to_le64(params->data_size);
|
||||
strncpy((char *)sb.algorithm, params->hash_name, sizeof(sb.algorithm));
|
||||
algorithm = (char *)sb.algorithm;
|
||||
algorithm[sizeof(sb.algorithm)-1] = '\0';
|
||||
strncpy(algorithm, params->hash_name, sizeof(sb.algorithm)-1);
|
||||
memcpy(sb.salt, params->salt, params->salt_size);
|
||||
memcpy(sb.uuid, uuid, sizeof(sb.uuid));
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* dm-verity volume handling
|
||||
*
|
||||
* Copyright (C) 2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2017, Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -22,7 +22,6 @@
|
||||
#define _VERITY_H
|
||||
|
||||
#include <unistd.h>
|
||||
#include "config.h"
|
||||
|
||||
#define VERITY_MAX_HASH_TYPE 1
|
||||
#define VERITY_BLOCK_SIZE_OK(x) ((x) % 512 || (x) < 512 || \
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* dm-verity volume handling
|
||||
*
|
||||
* Copyright (C) 2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2017, Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -220,7 +220,7 @@ static int VERITY_create_or_verify_hash(struct crypt_device *cd,
|
||||
off_t hash_level_block[VERITY_MAX_LEVELS];
|
||||
off_t hash_level_size[VERITY_MAX_LEVELS];
|
||||
off_t data_file_blocks, s;
|
||||
size_t hash_per_block, hash_per_block_bits;
|
||||
size_t hash_per_block_bits;
|
||||
off_t data_device_size = 0, hash_device_size = 0;
|
||||
uint64_t dev_size;
|
||||
int levels, i, r;
|
||||
@@ -251,7 +251,6 @@ static int VERITY_create_or_verify_hash(struct crypt_device *cd,
|
||||
}
|
||||
|
||||
hash_per_block_bits = get_bits_down(hash_block_size / digest_size);
|
||||
hash_per_block = 1 << hash_per_block_bits;
|
||||
if (!hash_per_block_bits)
|
||||
return -EINVAL;
|
||||
|
||||
@@ -271,8 +270,7 @@ static int VERITY_create_or_verify_hash(struct crypt_device *cd,
|
||||
for (i = levels - 1; i >= 0; i--) {
|
||||
hash_level_block[i] = hash_position;
|
||||
// verity position of block data_file_blocks at level i
|
||||
s = data_file_blocks >> (i * hash_per_block_bits);
|
||||
s = (s + hash_per_block - 1) / hash_per_block;
|
||||
s = (data_file_blocks + ((off_t)1 << ((i + 1) * hash_per_block_bits)) - 1) >> ((i + 1) * hash_per_block_bits);
|
||||
hash_level_size[i] = s;
|
||||
if ((hash_position + s) < hash_position ||
|
||||
(hash_position + s) < 0) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* cryptsetup volume key implementation
|
||||
*
|
||||
* Copyright (C) 2004-2006, Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2010-2012, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2017, Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -20,22 +20,31 @@
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
struct volume_key *crypt_alloc_volume_key(unsigned keylength, const char *key)
|
||||
struct volume_key *crypt_alloc_volume_key(size_t keylength, const char *key)
|
||||
{
|
||||
struct volume_key *vk = malloc(sizeof(*vk) + keylength);
|
||||
struct volume_key *vk;
|
||||
|
||||
if (keylength > (SIZE_MAX - sizeof(*vk)))
|
||||
return NULL;
|
||||
|
||||
vk = malloc(sizeof(*vk) + keylength);
|
||||
if (!vk)
|
||||
return NULL;
|
||||
|
||||
vk->keylength = keylength;
|
||||
if (key)
|
||||
memcpy(&vk->key, key, keylength);
|
||||
else
|
||||
memset(&vk->key, 0, keylength);
|
||||
|
||||
/* keylength 0 is valid => no key */
|
||||
if (vk->keylength) {
|
||||
if (key)
|
||||
memcpy(&vk->key, key, keylength);
|
||||
else
|
||||
crypt_memzero(&vk->key, keylength);
|
||||
}
|
||||
|
||||
return vk;
|
||||
}
|
||||
@@ -43,13 +52,13 @@ struct volume_key *crypt_alloc_volume_key(unsigned keylength, const char *key)
|
||||
void crypt_free_volume_key(struct volume_key *vk)
|
||||
{
|
||||
if (vk) {
|
||||
memset(vk->key, 0, vk->keylength);
|
||||
crypt_memzero(vk->key, vk->keylength);
|
||||
vk->keylength = 0;
|
||||
free(vk);
|
||||
}
|
||||
}
|
||||
|
||||
struct volume_key *crypt_generate_volume_key(struct crypt_device *cd, unsigned keylength)
|
||||
struct volume_key *crypt_generate_volume_key(struct crypt_device *cd, size_t keylength)
|
||||
{
|
||||
int r;
|
||||
struct volume_key *vk;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.TH CRYPTSETUP-REENCRYPT "8" "June 2012" "cryptsetup-reencrypt" "Maintenance Commands"
|
||||
.TH CRYPTSETUP-REENCRYPT "8" "March 2017" "cryptsetup-reencrypt" "Maintenance Commands"
|
||||
.SH NAME
|
||||
cryptsetup-reencrypt - tool for offline LUKS device re-encryption
|
||||
.SH SYNOPSIS
|
||||
@@ -19,8 +19,6 @@ or kernel failures during reencryption (you can lose you data in this case).
|
||||
|
||||
\fIALWAYS BE SURE YOU HAVE RELIABLE BACKUP BEFORE USING THIS TOOL.\fR
|
||||
.br
|
||||
\fITHIS TOOL IS EXPERIMENTAL.\fR
|
||||
|
||||
The reencryption can be temporarily suspended (by TERM signal or by
|
||||
using ctrl+c) but you need to retain temporary files named LUKS-<uuid>.[log|org|new].
|
||||
LUKS device is unavailable until reencryption is finished though.
|
||||
@@ -36,9 +34,16 @@ To start (or continue) re-encryption for <device> use:
|
||||
.PP
|
||||
\fIcryptsetup-reencrypt\fR <device>
|
||||
|
||||
\fB<options>\fR can be [\-\-block-size, \-\-cipher, \-\-hash, \-\-iter-time,
|
||||
\-\-use-random | \-\-use-urandom, \-\-key-file, \-\-key-slot, \-\-keyfile-offset,
|
||||
\-\-keyfile-size, \-\-tries, \-\-use-directio, \-\-use-fsync, \-\-write-log]
|
||||
\fB<options>\fR can be [\-\-batch-mode, \-\-block-size, \-\-cipher, \-\-debug,
|
||||
\-\-device-size, \-\-hash, \-\-iter-time, \-\-use-random | \-\-use-urandom,
|
||||
\-\-keep-key, \-\-key-size, \-\-key-file, \-\-key-slot, \-\-keyfile-offset,
|
||||
\-\-keyfile-size, \-\-tries, \-\-use-directio, \-\-use-fsync, \-\-verbose, \-\-write-log,
|
||||
\-\-uuid]
|
||||
|
||||
To encrypt data on (not yet encrypted) device, use \fI\-\-new\fR with combination
|
||||
with \fI\-\-reduce-device-size\fR.
|
||||
|
||||
To remove encryption from device, use \fI\-\-decrypt\fR.
|
||||
|
||||
For detailed description of encryption and key file options see \fIcryptsetup(8)\fR
|
||||
man page.
|
||||
@@ -56,7 +61,7 @@ Set the cipher specification string.
|
||||
.B "\-\-key-size, \-s \fI<bits>\fR"
|
||||
Set key size in bits. The argument has to be a multiple of 8.
|
||||
|
||||
The possible key-sizes are limited by the cipher and mode used.
|
||||
The possible key-sizes are limited by the cipher and mode used.
|
||||
|
||||
If you are increasing key size, there must be enough space in the LUKS header
|
||||
for enlarged keyslots (data offset must be large enough) or reencryption
|
||||
@@ -67,6 +72,9 @@ you can destructively shrink device with \-\-reduce-device-size option.
|
||||
.TP
|
||||
.B "\-\-hash, \-h \fI<hash-spec>\fR"
|
||||
Specifies the hash used in the LUKS key setup scheme and volume key digest.
|
||||
|
||||
\fBNOTE:\fR if this parameter is not specified, default hash algorithm is always used
|
||||
for new device header.
|
||||
.TP
|
||||
.B "\-\-iter-time, \-i \fI<milliseconds>\fR"
|
||||
The number of milliseconds to spend with PBKDF2 passphrase processing for the
|
||||
@@ -80,7 +88,7 @@ Define which kernel random number generator will be used to create the volume ke
|
||||
.B "\-\-key-file, \-d \fIname\fR"
|
||||
Read the passphrase from file.
|
||||
|
||||
WARNING: \-\-key-file option can be used only if there only one active keyslot,
|
||||
\fBWARNING:\fR \-\-key-file option can be used only if there only one active keyslot,
|
||||
or alternatively, also if \-\-key-slot option is specified (then all other keyslots
|
||||
will be disabled in new LUKS device).
|
||||
|
||||
@@ -90,7 +98,7 @@ passphrases.
|
||||
.B "\-\-key-slot, \-S <0-7>"
|
||||
Specify which key slot is used.
|
||||
|
||||
WARNING: All other keyslots will be disabled if this option is used.
|
||||
\fBWARNING:\fR All other keyslots will be disabled if this option is used.
|
||||
.TP
|
||||
.B "\-\-keyfile-offset \fIvalue\fR"
|
||||
Skip \fIvalue\fR bytes at the beginning of the key file.
|
||||
@@ -100,6 +108,12 @@ Read a maximum of \fIvalue\fR bytes from the key file.
|
||||
Default is to read the whole file up to the compiled-in
|
||||
maximum.
|
||||
.TP
|
||||
.B "\-\-keep-key"
|
||||
Do not change encryption key, just reencrypt the LUKS header and keyslots.
|
||||
|
||||
This option can be combined only with \fI\-\-hash\fR or \fI\-\-iter-time\fR
|
||||
options.
|
||||
.TP
|
||||
.B "\-\-tries, \-T"
|
||||
Number of retries for invalid passphrase entry.
|
||||
.TP
|
||||
@@ -114,14 +128,14 @@ Instead of real device size, use specified value.
|
||||
It means that only specified area (from the start of the device
|
||||
to the specified size) will be reencrypted.
|
||||
|
||||
WARNING: This is destructive operation.
|
||||
\fBWARNING:\fR This is destructive operation.
|
||||
|
||||
If no unit suffix is specified, the size is in bytes.
|
||||
|
||||
Unit suffix can be S for 512 byte sectors, K/M/G/T (or KiB,MiB,GiB,TiB)
|
||||
for units with 1024 base or KB/MB/GB/TB for 1000 base (SI scale).
|
||||
|
||||
WARNING: This is destructive operation.
|
||||
\fBWARNING:\fR This is destructive operation.
|
||||
.TP
|
||||
.B "\-\-reduce-device-size \fIsize[units]\fR"
|
||||
Enlarge data offset to specified value by shrinking device size.
|
||||
@@ -130,37 +144,49 @@ This means that last sectors on the original device will be lost,
|
||||
ciphertext data will be effectively shifted by specified
|
||||
number of sectors.
|
||||
|
||||
It can be usefull if you e.g. added some space to underlying
|
||||
It can be useful if you e.g. added some space to underlying
|
||||
partition (so last sectors contains no data).
|
||||
|
||||
For units suffix see \-\-device-size parameter description.
|
||||
|
||||
WARNING: This is destructive operation and cannot be reverted.
|
||||
\fBWARNING:\fR This is destructive operation and cannot be reverted.
|
||||
Use with extreme care - shrinked filesystems are usually unrecoverable.
|
||||
|
||||
You cannot shrink device more than by 64 MiB (131072 sectors).
|
||||
.TP
|
||||
.B "\-\-new, N"
|
||||
.B "\-\-new, \-N"
|
||||
Create new header (encrypt not yet encrypted device).
|
||||
|
||||
This option must be used together with \-\-reduce-device-size.
|
||||
|
||||
WARNING: This is destructive operation and cannot be reverted.
|
||||
\fBWARNING:\fR This is destructive operation and cannot be reverted.
|
||||
.TP
|
||||
.B "\-\-decrypt"
|
||||
Remove encryption (decrypt already encrypted device and remove LUKS header).
|
||||
|
||||
\fBWARNING:\fR This is destructive operation and cannot be reverted.
|
||||
.TP
|
||||
.B "\-\-use-directio"
|
||||
Use direct-io (O_DIRECT) for all read/write data operations.
|
||||
Use direct-io (O_DIRECT) for all read/write data operations related
|
||||
to block device undergoing reencryption.
|
||||
|
||||
Usefull if direct-io operations perform better than normal buffered
|
||||
Useful if direct-io operations perform better than normal buffered
|
||||
operations (e.g. in virtual environments).
|
||||
.TP
|
||||
.B "\-\-use-fsync"
|
||||
Use fsync call after every written block.
|
||||
Use fsync call after every written block. This applies for reencryption
|
||||
log files as well.
|
||||
.TP
|
||||
.B "\-\-write-log"
|
||||
Update log file after every block write. This can slow down reencryption
|
||||
but will minimize data loss in the case of system crash.
|
||||
.TP
|
||||
.B "\-\-uuid" \fI<uuid>\fR
|
||||
Use only while resuming an interrupted decryption process (see \-\-decrypt).
|
||||
|
||||
To find out what \fI<uuid>\fR to pass look for temporary files LUKS-<uuid>.[|log|org|new]
|
||||
of the interrupted decryption process.
|
||||
.TP
|
||||
.B "\-\-batch-mode, \-q"
|
||||
Suppresses all warnings and reencryption progress output.
|
||||
.TP
|
||||
@@ -178,18 +204,24 @@ Reencrypt /dev/sdb1 (change volume key)
|
||||
cryptsetup-reencrypt /dev/sdb1
|
||||
.TP
|
||||
Reencrypt and also change cipher and cipher mode
|
||||
cryptsetup-reencrypt /dev/sdb1 -c aes-xts-plain64
|
||||
cryptsetup-reencrypt /dev/sdb1 \-c aes-xts-plain64
|
||||
.TP
|
||||
Add LUKS encryption to not yet encrypted device
|
||||
|
||||
First, be sure you have space added to disk.
|
||||
|
||||
Or alternatively shrink filesystem in advance.
|
||||
.br
|
||||
Here we need 4096 512-bytes sectors (enough for 2x128 bit key).
|
||||
|
||||
fdisk -u /dev/sdb # move sdb1 partition end + 4096 sectors
|
||||
fdisk \-u /dev/sdb # move sdb1 partition end + 4096 sectors
|
||||
(or use resize2fs or tool for your filesystem and shrink it)
|
||||
|
||||
cryptsetup-reencrypt /dev/sdb1 --new --reduce-device-size 4096
|
||||
cryptsetup-reencrypt /dev/sdb1 \-\-new \-\-reduce-device-size 4096S
|
||||
.TP
|
||||
Remove LUKS encryption completely
|
||||
|
||||
cryptsetup-reencrypt /dev/sdb1 \-\-decrypt
|
||||
|
||||
.SH REPORTING BUGS
|
||||
Report bugs, including ones in the documentation, on
|
||||
@@ -200,11 +232,11 @@ Please attach the output of the failed command with the
|
||||
.SH AUTHORS
|
||||
Cryptsetup-reencrypt was written by Milan Broz <gmazyland@gmail.com>.
|
||||
.SH COPYRIGHT
|
||||
Copyright \(co 2012 Milan Broz
|
||||
Copyright \(co 2012-2017 Milan Broz
|
||||
.br
|
||||
Copyright \(co 2012 Red Hat, Inc.
|
||||
Copyright \(co 2012-2017 Red Hat, Inc.
|
||||
|
||||
This is free software; see the source for copying conditions. There is NO
|
||||
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
.SH SEE ALSO
|
||||
The project website at \fBhttp://code.google.com/p/cryptsetup/\fR
|
||||
The project website at \fBhttps://gitlab.com/cryptsetup/cryptsetup\fR
|
||||
|
||||
402
man/cryptsetup.8
402
man/cryptsetup.8
@@ -1,4 +1,4 @@
|
||||
.TH CRYPTSETUP "8" "May 2012" "cryptsetup" "Maintenance Commands"
|
||||
.TH CRYPTSETUP "8" "March 2017" "cryptsetup" "Maintenance Commands"
|
||||
.SH NAME
|
||||
cryptsetup - manage plain dm-crypt and LUKS encrypted volumes
|
||||
.SH SYNOPSIS
|
||||
@@ -10,6 +10,10 @@ device-mapper mappings. These include plain dm-crypt volumes and
|
||||
LUKS volumes. The difference is that LUKS uses a metadata header
|
||||
and can hence offer more features than plain dm-crypt. On the other
|
||||
hand, the header is visible and vulnerable to damage.
|
||||
|
||||
In addition, cryptsetup provides limited support for the use of
|
||||
historic loopaes volumes and for TrueCrypt compatible volumes.
|
||||
|
||||
.SH PLAIN DM-CRYPT OR LUKS?
|
||||
.PP
|
||||
Unless you understand the cryptographic background well, use LUKS.
|
||||
@@ -51,27 +55,27 @@ secure wiping by just overwriting header and key-slot area.
|
||||
|
||||
\fBPreviously used partitions:\fR If a partition was previously used,
|
||||
it is a very good idea to wipe filesystem signatures, data, etc. before
|
||||
creating a LUKS or plain dm-crypt container on it.
|
||||
For a quick removal of filesystem signatures, use "wipefs". Take care
|
||||
though that this may not remove everything. In particular md (RAID)
|
||||
signatures at the end of a device may survive. It also does not
|
||||
remove data. For a full wipe, overwrite the whole partition before
|
||||
creating a LUKS or plain dm-crypt container on it.
|
||||
For a quick removal of filesystem signatures, use "wipefs". Take care
|
||||
though that this may not remove everything. In particular md (RAID)
|
||||
signatures at the end of a device may survive. It also does not
|
||||
remove data. For a full wipe, overwrite the whole partition before
|
||||
container creation. If you do not know how to to that, the
|
||||
cryptsetup FAQ describes several options.
|
||||
|
||||
.SH BASIC COMMANDS
|
||||
The following are valid actions for all supported device types.
|
||||
|
||||
\fIopen\fR <name> <device> \-\-type <device_type>
|
||||
\fIopen\fR <device> <name> \-\-type <device_type>
|
||||
.IP
|
||||
Opens (creates a mapping) with <name> backed by device <device>.
|
||||
Opens (creates a mapping with) <name> backed by device <device>.
|
||||
|
||||
Device type can be \fIplain\fR, \fIluks\fR (default), \fIloopaes\fR
|
||||
or \fItcrypt\fR.
|
||||
|
||||
For backward compatibility there are \fBopen\fR command aliases:
|
||||
|
||||
\fBcreate\fR: open \-\-type plain <device> <name>\fR switched arguments)
|
||||
\fBcreate\fR (argument-order <name> <device>): open \-\-type plain
|
||||
.br
|
||||
\fBplainOpen\fR: open \-\-type plain
|
||||
.br
|
||||
@@ -82,7 +86,9 @@ For backward compatibility there are \fBopen\fR command aliases:
|
||||
\fBtcryptOpen\fR: open \-\-type tcrypt
|
||||
|
||||
\fB<options>\fR are type specific and are described below
|
||||
for individual device types.
|
||||
for individual device types. For \fBcreate\fR, the order of the <name>
|
||||
and <device> options is inverted for historical reasons, all other
|
||||
aliases use the standard \fB<device> <name>\fR order.
|
||||
.PP
|
||||
\fIclose\fR <name>
|
||||
.IP
|
||||
@@ -101,15 +107,20 @@ Reports the status for the mapping <name>.
|
||||
.IP
|
||||
Resizes an active mapping <name>.
|
||||
|
||||
If \-\-size (in sectors) is not specified, the size of the
|
||||
underlying block device is used. Note that this does not
|
||||
change the raw device geometry, it just changes how many
|
||||
sectors of the raw device are represented in the mapped device.
|
||||
If \-\-size (in sectors) is not specified, the size is computed
|
||||
from the underlying device. For LUKS it is the size of the
|
||||
underlying device without the area reserved for LUKS header
|
||||
(see data payload offset in \fBluksDump\fR command).
|
||||
For plain crypt device the whole device size is used.
|
||||
|
||||
Note that this does not change the raw device geometry, it just
|
||||
changes how many sectors of the raw device are represented
|
||||
in the mapped device.
|
||||
.SH PLAIN MODE
|
||||
Plain dm-crypt encrypts the device sector-by-sector with a
|
||||
single, non-salted hash of the passphrase. No checks
|
||||
are performed, no metadata is used. There is no formatting operation.
|
||||
When the raw device is mapped (created), the usual device operations
|
||||
When the raw device is mapped (opened), the usual device operations
|
||||
can be used on the mapped device, including filesystem creation.
|
||||
Mapped devices usually reside in /dev/mapper/<name>.
|
||||
|
||||
@@ -119,13 +130,13 @@ The following are valid plain device type actions:
|
||||
.br
|
||||
\fIcreate\fR <name> <device> (\fBOBSOLETE syntax\fR)
|
||||
.IP
|
||||
Creates a mapping with <name> backed by device <device>.
|
||||
Opens (creates a mapping with) <name> backed by device <device>.
|
||||
|
||||
\fB<options>\fR can be [\-\-hash, \-\-cipher, \-\-verify-passphrase,
|
||||
\-\-key-file, \-\-keyfile-offset, \-\-key-size, \-\-offset, \-\-skip, \-\-size,
|
||||
\-\-readonly, \-\-shared, \-\-allow-discards]
|
||||
|
||||
Example: 'cryptsetup open --type plain /dev/sda10 e1' maps the raw
|
||||
Example: 'cryptsetup open \-\-type plain /dev/sda10 e1' maps the raw
|
||||
encrypted device /dev/sda10 to the mapped (decrypted) device
|
||||
/dev/mapper/e1, which can then be mounted, fsck-ed or have a
|
||||
filesystem created on it.
|
||||
@@ -154,12 +165,20 @@ Key operations that do not specify a slot affect the first slot
|
||||
that matches the supplied passphrase or the first empty slot if
|
||||
a new passphrase is added.
|
||||
|
||||
The \fB<device>\fR parameter can be also specified by a LUKS UUID in the
|
||||
format UUID=<uuid>. Translation to real device name uses symlinks
|
||||
in /dev/disk/by-uuid directory.
|
||||
|
||||
To specify a detached header, the \fB\-\-header\fR parameter can be used
|
||||
in all LUKS commands and always takes precedence over positional \fB<device>\fR
|
||||
parameter.
|
||||
|
||||
The following are valid LUKS actions:
|
||||
|
||||
\fIluksFormat\fR <device> [<key file>]
|
||||
.IP
|
||||
Initializes a LUKS partition and sets the initial passphrase
|
||||
(for key-slot 0),
|
||||
(for key-slot 0),
|
||||
either via prompting or via <key file>. Note that
|
||||
if the second argument is present, then the passphrase
|
||||
is taken from the file given there, without the need
|
||||
@@ -170,10 +189,12 @@ from stdin and the safety-question being skipped.
|
||||
|
||||
You can only call luksFormat on a LUKS device that is not mapped.
|
||||
|
||||
\fB<options>\fR can be [\-\-cipher, \-\-verify-passphrase, \-\-key-size,
|
||||
\-\-key-slot, \-\-key-file (takes precedence over optional second argument),
|
||||
\-\-keyfile-offset, \-\-keyfile-size, \-\-use-random | \-\-use-urandom,
|
||||
\-\-uuid, \-\-master-key-file].
|
||||
\fB<options>\fR can be [\-\-hash, \-\-cipher, \-\-verify\-passphrase,
|
||||
\-\-key\-size, \-\-key\-slot,
|
||||
\-\-key\-file (takes precedence over optional second argument),
|
||||
\-\-keyfile\-offset, \-\-keyfile\-size, \-\-use\-random | \-\-use\-urandom,
|
||||
\-\-uuid, \-\-master\-key\-file, \-\-iter\-time, \-\-header,
|
||||
\-\-force\-password].
|
||||
|
||||
\fBWARNING:\fR Doing a luksFormat on an existing LUKS container will
|
||||
make all data the old container permanently irretrievable, unless
|
||||
@@ -188,12 +209,9 @@ successful verification of the supplied passphrase.
|
||||
If the passphrase is not supplied via \-\-key-file, the command
|
||||
prompts for it interactively.
|
||||
|
||||
The <device> parameter can be also specified by LUKS UUID in the
|
||||
format UUID=<uuid>, which uses the symlinks in /dev/disk/by-uuid.
|
||||
|
||||
\fB<options>\fR can be [\-\-key-file, \-\-keyfile-offset,
|
||||
\-\-keyfile-size, \-\-readonly, \-\-test-passphrase,
|
||||
\-\-allow-discards, \-\-header, \-\-key-slot, \-\-master-key-file].
|
||||
\fB<options>\fR can be [\-\-key\-file, \-\-keyfile\-offset,
|
||||
\-\-keyfile\-size, \-\-readonly, \-\-test\-passphrase,
|
||||
\-\-allow\-discards, \-\-header, \-\-key-slot, \-\-master\-key\-file].
|
||||
.PP
|
||||
\fIluksSuspend\fR <name>
|
||||
.IP
|
||||
@@ -215,7 +233,7 @@ the mapped device.
|
||||
Resumes a suspended device and reinstates the encryption key.
|
||||
Prompts interactively for a passphrase if \-\-key-file is not given.
|
||||
|
||||
\fB<options>\fR can be [\-\-key-file, \-\-keyfile-size, \-\-header]
|
||||
\fB<options>\fR can be [\-\-key\-file, \-\-keyfile\-size, \-\-header]
|
||||
.PP
|
||||
\fIluksAddKey\fR <device> [<key file with new key>]
|
||||
.IP
|
||||
@@ -224,9 +242,10 @@ interactively or via \-\-key-file.
|
||||
The new passphrase to be added can be specified interactively
|
||||
or read from the file given as positional argument.
|
||||
|
||||
\fB<options>\fR can be [\-\-key-file, \-\-keyfile-offset,
|
||||
\-\-keyfile-size, \-\-new-keyfile-offset,
|
||||
\-\-new-keyfile-size, \-\-key-slot, \-\-master-key-file].
|
||||
\fB<options>\fR can be [\-\-key\-file, \-\-keyfile\-offset,
|
||||
\-\-keyfile\-size, \-\-new\-keyfile\-offset,
|
||||
\-\-new\-keyfile\-size, \-\-key\-slot, \-\-master\-key\-file,
|
||||
\-\-iter\-time, \-\-force\-password, \-\-header].
|
||||
.PP
|
||||
\fIluksRemoveKey\fR <device> [<key file with passphrase to be removed>]
|
||||
.IP
|
||||
@@ -234,12 +253,12 @@ Removes the supplied passphrase from the LUKS device. The
|
||||
passphrase to be removed can be specified interactively,
|
||||
as positional argument or via \-\-key-file.
|
||||
|
||||
\fB<options>\fR can be [\-\-key-file, \-\-keyfile-offset,
|
||||
\-\-keyfile-size]
|
||||
\fB<options>\fR can be [\-\-key\-file, \-\-keyfile\-offset,
|
||||
\-\-keyfile\-size, \-\-header]
|
||||
|
||||
\fBWARNING:\fR If you read the passphrase from stdin
|
||||
(without further argument or with '-' as argument
|
||||
to \-\-key-file), batch-mode (-q) will be implicitely
|
||||
(without further argument or with '-' as argument
|
||||
to \-\-key\-file), batch-mode (\-q) will be implicitly
|
||||
switched on and no warning will be given when you remove the
|
||||
last remaining passphrase from a LUKS container. Removing
|
||||
the last passphrase makes the LUKS container permanently
|
||||
@@ -248,7 +267,7 @@ inaccessible.
|
||||
\fIluksChangeKey\fR <device> [<new key file>]
|
||||
.IP
|
||||
Changes an existing passphrase. The passphrase
|
||||
to be changed must be supplied interactively or via \-\-key-file.
|
||||
to be changed must be supplied interactively or via \-\-key\-file.
|
||||
The new passphrase can be supplied interactively or in
|
||||
a file given as positional argument.
|
||||
|
||||
@@ -266,27 +285,43 @@ during this operation can cause the overwrite to fail after
|
||||
the old passphrase has been wiped and make the LUKS container
|
||||
inaccessible.
|
||||
|
||||
\fB<options>\fR can be [\-\-key-file, \-\-keyfile-offset,
|
||||
\-\-keyfile-size, \-\-new-keyfile-offset,
|
||||
\-\-new-keyfile-size, \-\-key-slot].
|
||||
\fB<options>\fR can be [\-\-key\-file, \-\-keyfile\-offset,
|
||||
\-\-keyfile\-size, \-\-new\-keyfile\-offset,
|
||||
\-\-new\-keyfile\-size, \-\-key\-slot, \-\-force\-password, \-\-header].
|
||||
.PP
|
||||
\fIluksKillSlot\fR <device> <key slot number>
|
||||
.IP
|
||||
Wipe the key-slot number <key slot> from the LUKS device. A remaining
|
||||
passphrase must be supplied, either interactively or via \-\-key-file.
|
||||
Wipe the key-slot number <key slot> from the LUKS device. Except running
|
||||
in batch-mode (\-q) a remaining passphrase must be supplied,
|
||||
either interactively or via \-\-key-file.
|
||||
This command can remove the last remaining key-slot, but requires
|
||||
an interactive confirmation when doing so. Removing the last
|
||||
passphrase makes a LUKS container permanently inaccessible.
|
||||
|
||||
\fB<options>\fR can be [\-\-key-file, \-\-keyfile-offset, \-\-keyfile-size].
|
||||
\fB<options>\fR can be [\-\-key\-file, \-\-keyfile\-offset,
|
||||
\-\-keyfile\-size, \-\-header].
|
||||
|
||||
\fBWARNING:\fR If you read the passphrase from stdin
|
||||
(without further argument or with '-' as argument
|
||||
to \-\-key-file), batch-mode (-q) will be implicitely
|
||||
to \-\-key-file), batch-mode (\-q) will be implicitly
|
||||
switched on and no warning will be given when you remove the
|
||||
last remaining passphrase from a LUKS container. Removing
|
||||
the last passphrase makes the LUKS container permanently
|
||||
inaccessible.
|
||||
|
||||
\fBNOTE:\fR If there is no passphrase provided (on stdin or through
|
||||
\-\-key-file argument) and batch-mode (\-q) is active, the
|
||||
key-slot is removed without any other warning.
|
||||
|
||||
.PP
|
||||
\fIerase\fR <device>
|
||||
.br
|
||||
\fIluksErase\fR <device>
|
||||
.IP
|
||||
Erase all keyslots and make the LUKS container permanently inaccessible.
|
||||
You do not need to provide any password for this operation.
|
||||
|
||||
\fBWARNING:\fR This operation is irreversible.
|
||||
.PP
|
||||
\fIluksUUID\fR <device>
|
||||
.IP
|
||||
@@ -304,7 +339,7 @@ means the device is a LUKS device.
|
||||
.IP
|
||||
Dump the header information of a LUKS device.
|
||||
|
||||
If the \-\-dump-master-key option is used, the LUKS device master key is
|
||||
If the \-\-dump\-master\-key option is used, the LUKS device master key is
|
||||
dumped instead of the keyslot info. Beware that the master key cannot be
|
||||
changed and can be used to decrypt the data stored in the LUKS container
|
||||
without a passphrase and even without the LUKS header. This means
|
||||
@@ -312,16 +347,16 @@ that if the master key is compromised, the whole device has to be
|
||||
erased to prevent further access. Use this option carefully.
|
||||
|
||||
In order to dump the master key, a passphrase has to be supplied,
|
||||
either interactively or via \-\-key-file.
|
||||
either interactively or via \-\-key\-file.
|
||||
|
||||
\fB<options>\fR can be [\-\-dump-master-key, \-\-key-file,
|
||||
\-\-keyfile-offset, \-\-keyfile-size].
|
||||
\fB<options>\fR can be [\-\-dump\-master\-key, \-\-key\-file,
|
||||
\-\-keyfile\-offset, \-\-keyfile\-size, \-\-header].
|
||||
|
||||
\fBWARNING:\fR If \-\-dump-master-key is used with \-\-key-file
|
||||
and the argument to \-\-key-file is '-', no validation question
|
||||
\fBWARNING:\fR If \-\-dump\-master\-key is used with \-\-key\-file
|
||||
and the argument to \-\-key\-file is '-', no validation question
|
||||
will be asked and no warning given.
|
||||
.PP
|
||||
\fIluksHeaderBackup\fR <device> \-\-header-backup-file <file>
|
||||
\fIluksHeaderBackup\fR <device> \-\-header\-backup\-file <file>
|
||||
.IP
|
||||
Stores a binary backup of the LUKS header and keyslot area.
|
||||
.br
|
||||
@@ -338,7 +373,7 @@ addition or overwrite the encrypted data area as well.
|
||||
The second option is less secure, as some sectors
|
||||
can survive, e.g. due to defect management.
|
||||
.PP
|
||||
\fIluksHeaderRestore\fR <device> \-\-header-backup-file <file>
|
||||
\fIluksHeaderRestore\fR <device> \-\-header\-backup\-file <file>
|
||||
.IP
|
||||
Restores a binary backup of the LUKS header and keyslot area
|
||||
from the specified file.
|
||||
@@ -356,18 +391,27 @@ the backup will also be written to it.
|
||||
cryptsetup supports mapping loop-AES encrypted partition using
|
||||
a compatibility mode.
|
||||
.PP
|
||||
\fIopen\fR \-\-type loopaes <device> <name> \-\-key-file <keyfile>
|
||||
\fIopen\fR \-\-type loopaes <device> <name> \-\-key\-file <keyfile>
|
||||
.br
|
||||
\fIloopaesOpen\fR <device> <name> \-\-key-file <keyfile> (\fBold syntax\fR)
|
||||
\fIloopaesOpen\fR <device> <name> \-\-key\-file <keyfile> (\fBold syntax\fR)
|
||||
.IP
|
||||
Opens the loop-AES <device> and sets up a mapping <name>.
|
||||
|
||||
If the key file is encrypted with GnuPG, then you have to use
|
||||
\-\-key-file=- and decrypt it before use, e.g. like this:
|
||||
\-\-key\-file=\- and decrypt it before use, e.g. like this:
|
||||
.br
|
||||
gpg \-\-decrypt <keyfile> | cryptsetup loopaesOpen \-\-key-file=- <device> <name>
|
||||
gpg \-\-decrypt <keyfile> | cryptsetup loopaesOpen \-\-key\-file=\-
|
||||
<device> <name>
|
||||
|
||||
Use \fB\-\-keyfile-size\fR to specify the proper key length if needed.
|
||||
\fBWARNING:\fR The loop-AES extension cannot use direct input of key file
|
||||
on real terminal because the keys are separated by end-of-line and only part
|
||||
of the multi-key file would be read.
|
||||
.br
|
||||
If you need it in script, just use the pipe redirection:
|
||||
.br
|
||||
echo $keyfile | cryptsetup loopaesOpen \-\-key\-file=\- <device> <name>
|
||||
|
||||
Use \fB\-\-keyfile\-size\fR to specify the proper key length if needed.
|
||||
|
||||
Use \fB\-\-offset\fR to specify device offset. Note that the units
|
||||
need to be specified in number of 512 byte sectors.
|
||||
@@ -381,13 +425,14 @@ Use \fB\-\-hash\fR to override the default hash function for
|
||||
passphrase hashing (otherwise it is detected according to key
|
||||
size).
|
||||
|
||||
\fB<options>\fR can be [\-\-key-file, \-\-key-size, \-\-offset, \-\-skip,
|
||||
\-\-hash, \-\-readonly, \-\-allow-discards].
|
||||
\fB<options>\fR can be [\-\-key\-file, \-\-key\-size, \-\-offset, \-\-skip,
|
||||
\-\-hash, \-\-readonly, \-\-allow\-discards].
|
||||
.PP
|
||||
See also section 7 of the FAQ and \fBhttp://loop-aes.sourceforge.net\fR
|
||||
for more information regarding loop-AES.
|
||||
.SH TCRYPT (TrueCrypt-compatible) EXTENSION
|
||||
cryptsetup supports mapping of TrueCrypt or tcplay encrypted partition
|
||||
.SH TCRYPT (TrueCrypt-compatible and VeraCrypt) EXTENSION
|
||||
cryptsetup supports mapping of TrueCrypt, tcplay or VeraCrypt
|
||||
(with \fB\-\-veracrypt\fR option) encrypted partition
|
||||
using a native Linux kernel API.
|
||||
Header formatting and TCRYPT header change is not supported, cryptsetup
|
||||
never changes TCRYPT header on-device.
|
||||
@@ -405,6 +450,11 @@ Cryptsetup should recognize all header variants, except legacy cipher chains
|
||||
using LRW encryption mode with 64 bits encryption block (namely Blowfish
|
||||
in LRW mode is not recognized, this is limitation of kernel crypto API).
|
||||
|
||||
To recognize VeraCrypt device use \fB\-\-veracrypt\fR option.
|
||||
VeraCrypt is just extension of TrueCrypt header with increased
|
||||
iteration count so unlocking can take quite a lot of time (in comparison
|
||||
with TCRYPT device).
|
||||
|
||||
\fBNOTE:\fR Activation with \fBtcryptOpen\fR is supported only for cipher chains
|
||||
using LRW or XTS encryption modes.
|
||||
|
||||
@@ -412,44 +462,73 @@ The \fBtcryptDump\fR command should work for all recognized TCRYPT devices
|
||||
and doesn't require superuser privilege.
|
||||
|
||||
To map system device (device with boot loader where the whole encrypted
|
||||
system resides) use \fB\-\-tcrypt-system\fR option. Use the whole
|
||||
device not the system partition as the device parameter.
|
||||
system resides) use \fB\-\-tcrypt\-system\fR option.
|
||||
You can use partition device as the parameter (parameter must be real partition
|
||||
device, not image in file), then only this partition is mapped.
|
||||
|
||||
If you have whole TCRYPT device as a file image and you want to map multiple
|
||||
partition encrypted with system encryption, please create loopback mapping
|
||||
with partitions first (\fBlosetup \-P\fR, see \fPlosetup(8)\fR man page for more info),
|
||||
and use loop partition as the device parameter.
|
||||
|
||||
If you use whole base device as parameter, one device for the whole system
|
||||
encryption is mapped. This mode is available only for backward compatibility
|
||||
with older cryptsetup versions which mapped TCRYPT system encryption
|
||||
using whole device.
|
||||
|
||||
To use hidden header (and map hidden device, if available),
|
||||
use \fB\-\-tcrypt-hidden\fR option.
|
||||
use \fB\-\-tcrypt\-hidden\fR option.
|
||||
|
||||
To explicitly use backup (secondary) header, use \fB\-\-tcrypt\-backup\fR
|
||||
option.
|
||||
|
||||
\fBNOTE:\fR There is no protection for a hidden volume if
|
||||
the outer volume is mounted. The reason is that if there
|
||||
were any protection, it would require some metadata describing
|
||||
what to protect in the outer volume and the hidden volume would
|
||||
become detectable.
|
||||
|
||||
.PP
|
||||
\fIopen\fR \-\-type tcrypt <device> <name>
|
||||
.br
|
||||
\fItcryptOpen\fR <device> <name> (\fBold syntax\fR)
|
||||
.IP
|
||||
Opens the TCRYPT (a TrueCrypt-compatible) <device> and sets up a mapping <name>.
|
||||
Opens the TCRYPT (a TrueCrypt-compatible) <device> and sets up
|
||||
a mapping <name>.
|
||||
|
||||
\fB<options>\fR can be [\-\-key-file, \-\-tcrypt-hidden, \-\-tcrypt-system,
|
||||
\-\-readonly, \-\-test-passphrase].
|
||||
\fB<options>\fR can be [\-\-key\-file, \-\-tcrypt\-hidden,
|
||||
\-\-tcrypt\-system, \-\-tcrypt\-backup, \-\-readonly, \-\-test\-passphrase,
|
||||
\-\-allow-discards].
|
||||
|
||||
The keyfile parameter allows combination of file content with the
|
||||
passphrase and can be repeated. Note that using keyfiles is compatible
|
||||
with TCRYPT and is different from LUKS keyfile logic.
|
||||
|
||||
\fBWARNING:\fR Option \fB\-\-allow\-discards\fR cannot be combined with
|
||||
option \fB\-\-tcrypt\-hidden\fR. For normal mapping it can cause
|
||||
\fBdestruction of hidden volume\fR (hidden volume appears as unused space
|
||||
for outer volume so this space can be discarded).
|
||||
|
||||
.PP
|
||||
\fItcryptDump\fR <device>
|
||||
.IP
|
||||
Dump the header information of a TCRYPT device.
|
||||
|
||||
If the \-\-dump-master-key option is used, the TCRYPT device master key is
|
||||
dumped instead of TCRYPT header info. Beware that the master key
|
||||
If the \-\-dump\-master\-key option is used, the TCRYPT device master key
|
||||
is dumped instead of TCRYPT header info. Beware that the master key
|
||||
(or concatenated master keys if cipher chain is used)
|
||||
can be used to decrypt the data stored in the TCRYPT container without
|
||||
a passphrase.
|
||||
This means that if the master key is compromised, the whole device has
|
||||
to be erased to prevent further access. Use this option carefully.
|
||||
|
||||
\fB<options>\fR can be [\-\-dump-master-key, \-\-key-file, \-\-tcrypt-hidden,
|
||||
\-\-tcrypt-system].
|
||||
\fB<options>\fR can be [\-\-dump\-master\-key, \-\-key\-file,
|
||||
\-\-tcrypt\-hidden, \-\-tcrypt\-system, \-\-tcrypt\-backup].
|
||||
|
||||
The keyfile parameter allows combination of file content with the
|
||||
passphrase and can be repeated.
|
||||
.PP
|
||||
See also \fBhttp://www.truecrypt.org\fR for more information regarding
|
||||
See also \fBhttps://en.wikipedia.org/wiki/TrueCrypt\fR for more information regarding
|
||||
TrueCrypt.
|
||||
|
||||
Please note that cryptsetup does not use TrueCrypt code, please report
|
||||
@@ -475,7 +554,7 @@ Benchmarks ciphers and KDF (key derivation function).
|
||||
Without parameters it tries to measure few common configurations.
|
||||
|
||||
To benchmark other ciphers or modes, you need to specify \fB\-\-cipher\fR
|
||||
and \fB\-\-key-size\fR options or \fB\-\-hash\fR for KDF test.
|
||||
and \fB\-\-key\-size\fR options or \fB\-\-hash\fR for KDF test.
|
||||
|
||||
\fBNOTE:\fR This benchmark is using memory only and is only informative.
|
||||
You cannot directly predict real storage encryption speed from it.
|
||||
@@ -486,7 +565,7 @@ If you are configuring kernel yourself, enable
|
||||
"User-space interface for symmetric key cipher algorithms" in
|
||||
"Cryptographic API" section (CRYPTO_USER_API_SKCIPHER .config option).
|
||||
|
||||
\fB<options>\fR can be [\-\-cipher, \-\-key-size, \-\-hash].
|
||||
\fB<options>\fR can be [\-\-cipher, \-\-key\-size, \-\-hash].
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B "\-\-verbose, \-v"
|
||||
@@ -496,15 +575,17 @@ Print more information on command execution.
|
||||
Run in debug mode with full diagnostic logs. Debug output
|
||||
lines are always prefixed by '#'.
|
||||
.TP
|
||||
.B "\-\-hash, \-h \fI<hash-spec>\fR"
|
||||
Specifies the passphrase hash for \fIopen\fR (for plain and loopaes device types).
|
||||
.B "\-\-hash, \-h \fI<hash\-spec>\fR"
|
||||
Specifies the passphrase hash for \fIopen\fR (for plain and
|
||||
loopaes device types).
|
||||
|
||||
Specifies the hash used in the LUKS key setup scheme and volume key digest
|
||||
for \fIluksFormat\fR.
|
||||
for \fIluksFormat\fR. The specified hash is used as hash-parameter
|
||||
for PBKDF2 and for the AF splitter.
|
||||
|
||||
The specified hash name is passed to the compiled-in crypto backend.
|
||||
Different backends may support different hashes.
|
||||
For \fIluksFormat\fR, the hash
|
||||
For \fIluksFormat\fR, the hash
|
||||
algorithm must provide at least 160 bits of output, which
|
||||
excludes, e.g., MD5. Do not use a non-crypto hash like
|
||||
\fB"crc32"\fR as this breaks security.
|
||||
@@ -515,16 +596,20 @@ Values compatible with old version of cryptsetup are
|
||||
|
||||
Use \fIcryptsetup \-\-help\fR to show the defaults.
|
||||
.TP
|
||||
.B "\-\-cipher, \-c \fI<cipher-spec>\fR"
|
||||
.B "\-\-cipher, \-c \fI<cipher\-spec>\fR"
|
||||
Set the cipher specification string.
|
||||
|
||||
\fIcryptsetup \-\-help\fR shows the compiled-in defaults.
|
||||
The current default in the distributed sources is
|
||||
"aes-cbc-essiv:sha256" for both plain dm-crypt and LUKS.
|
||||
"aes-cbc-essiv:sha256" for plain dm-crypt and
|
||||
"aes-xts-plain64" for LUKS.
|
||||
|
||||
For XTS mode (a possible future default), use "aes-xts-plain"
|
||||
or better "aes-xts-plain64"
|
||||
as cipher specification and optionally set a key size of
|
||||
If a hash is part of the cipher specification, then it is
|
||||
used as part of the IV generation. For example, ESSIV
|
||||
needs a hash function, while "plain64" does not and
|
||||
hence none is specified.
|
||||
|
||||
For XTS mode you can optionally set a key size of
|
||||
512 bits with the \-s option. Key size for XTS
|
||||
mode is twice that for other modes for the same
|
||||
security level.
|
||||
@@ -536,7 +621,7 @@ kernel 2.6.33 or later. More information can be found in the FAQ.
|
||||
When interactively asking for a passphrase, ask for it twice
|
||||
and complain if both inputs do not match. Advised when creating
|
||||
a regular mapping for the first time, or when running
|
||||
\fIluksFormat\fR. Ignores on input from file or stdin.
|
||||
\fIluksFormat\fR. Ignored on input from file or stdin.
|
||||
.TP
|
||||
.B "\-\-key-file, \-d \fIname\fR"
|
||||
Read the passphrase from file.
|
||||
@@ -544,9 +629,9 @@ Read the passphrase from file.
|
||||
If the name given is "-", then the passphrase will be read from stdin.
|
||||
In this case, reading will not stop at newline characters.
|
||||
|
||||
With LUKS, passphrases supplied via \-\-key-file are always
|
||||
With LUKS, passphrases supplied via \-\-key\-file are always
|
||||
the existing passphrases requested by a command, except in
|
||||
the case of \fIluksFormat\fR where \-\-key-file is equivalent
|
||||
the case of \fIluksFormat\fR where \-\-key\-file is equivalent
|
||||
to the positional key file argument.
|
||||
|
||||
If you want to set a new passphrase via key file, you have to
|
||||
@@ -554,37 +639,37 @@ use a positional argument to \fIluksAddKey\fR.
|
||||
|
||||
See section \fBNOTES ON PASSPHRASE PROCESSING\fR for more information.
|
||||
.TP
|
||||
.B "\-\-keyfile-offset \fIvalue\fR"
|
||||
.B "\-\-keyfile\-offset \fIvalue\fR"
|
||||
Skip \fIvalue\fR bytes at the beginning of the key file.
|
||||
Works with all commands that accepts key files.
|
||||
.TP
|
||||
.B "\-\-keyfile-size, \-l \fIvalue\fR"
|
||||
.B "\-\-keyfile\-size, \-l \fIvalue\fR"
|
||||
Read a maximum of \fIvalue\fR bytes from the key file.
|
||||
Default is to read the whole file up to the compiled-in
|
||||
maximum that can be queried with \-\-help. Supplying more
|
||||
data than the compiled-in maximum aborts the operation.
|
||||
|
||||
This option is useful
|
||||
to cut trailing newlines, for example. If \-\-keyfile-offset
|
||||
to cut trailing newlines, for example. If \-\-keyfile\-offset
|
||||
is also given, the size count starts after the offset.
|
||||
Works with all commands that accepts key files.
|
||||
.TP
|
||||
.B "\-\-new-keyfile-offset \fIvalue\fR"
|
||||
.B "\-\-new\-keyfile\-offset \fIvalue\fR"
|
||||
Skip \fIvalue\fR bytes at the start when
|
||||
adding a new passphrase from key file with
|
||||
\fIluksAddKey\fR.
|
||||
.TP
|
||||
.B "\-\-new-keyfile-size \fIvalue\fR"
|
||||
.B "\-\-new\-keyfile\-size \fIvalue\fR"
|
||||
Read a maximum of \fIvalue\fR bytes when adding
|
||||
a new passphrase from key file with \fIluksAddKey\fR.
|
||||
Default is to read the whole file up to the compiled-in
|
||||
maximum length that can be queried with \-\-help.
|
||||
Supplying more than the compiled in maximum aborts the
|
||||
operation.
|
||||
When \-\-new-keyfile-offset is also given, reading starts
|
||||
When \-\-new\-keyfile\-offset is also given, reading starts
|
||||
after the offset.
|
||||
.TP
|
||||
.B "\-\-master-key-file"
|
||||
.B "\-\-master\-key\-file"
|
||||
Use a master key stored in a file.
|
||||
|
||||
For \fIluksFormat\fR this
|
||||
@@ -594,20 +679,25 @@ LUKS header and all other parameters are the same,
|
||||
then the new header decrypts the data encrypted with the
|
||||
header the master key was taken from.
|
||||
|
||||
\fBWARNING:\fR If you create your own master key, you
|
||||
need to make sure to do it right. Otherwise you can end
|
||||
up with a low-entropy or otherwise partially predictable
|
||||
master key which will compromise security.
|
||||
|
||||
For \fIluksAddKey\fR this allows adding a new passphrase
|
||||
without having to know an exiting one.
|
||||
|
||||
For \fIopen\fR this allows to open the LUKS device
|
||||
For \fIopen\fR this allows one to open the LUKS device
|
||||
without giving a passphrase.
|
||||
.TP
|
||||
.B "\-\-dump-master-key"
|
||||
.B "\-\-dump\-master\-key"
|
||||
For \fIluksDump\fR this option includes the master key in the displayed
|
||||
information. Use with care, as the master key can be used to
|
||||
bypass the passphrases, see also option \-\-master-key-file.
|
||||
bypass the passphrases, see also option \-\-master\-key\-file.
|
||||
.TP
|
||||
.B "\-\-use-random"
|
||||
.B "\-\-use\-random"
|
||||
.TP
|
||||
.B "\-\-use-urandom"
|
||||
.B "\-\-use\-urandom"
|
||||
For \fIluksFormat\fR these options define which kernel random number
|
||||
generator will be used to create the master key (which is a
|
||||
long-term key).
|
||||
@@ -623,7 +713,7 @@ Using /dev/random can block a long time, potentially
|
||||
forever, if not enough entropy can be harvested by
|
||||
the kernel.
|
||||
.TP
|
||||
.B "\-\-key-slot, \-S <0-7>"
|
||||
.B "\-\-key\-slot, \-S <0\-7>"
|
||||
For LUKS operations that add key material, this options allows you
|
||||
to specify which key slot is selected for the new key.
|
||||
This option can be used for \fIluksFormat\fR,
|
||||
@@ -634,7 +724,7 @@ specific key-slot to compare the passphrase against.
|
||||
If the given passphrase would only match a different key-slot,
|
||||
the operation fails.
|
||||
.TP
|
||||
.B "\-\-key-size, \-s <bits>"
|
||||
.B "\-\-key\-size, \-s <bits>"
|
||||
Sets key size in bits. The argument has to be a multiple of
|
||||
8. The possible key-sizes are limited by the cipher and
|
||||
mode used.
|
||||
@@ -647,7 +737,7 @@ All other LUKS actions will use the key-size specified in the LUKS header.
|
||||
Use \fIcryptsetup \-\-help\fR to show the compiled-in defaults.
|
||||
.TP
|
||||
.B "\-\-size, \-b <number of 512 byte sectors>"
|
||||
Force the size of the underlying device in sectors of 512 bytes.
|
||||
Set the size of the device in sectors of 512 bytes.
|
||||
This option is only relevant for the \fIopen\fR and \fIresize\fR
|
||||
actions.
|
||||
.TP
|
||||
@@ -657,17 +747,14 @@ This option is only relevant for the \fIopen\fR action with plain
|
||||
or loopaes device types.
|
||||
.TP
|
||||
.B "\-\-skip, \-p <number of 512 byte sectors>"
|
||||
How many sectors of the encrypted data to skip at the beginning.
|
||||
Start offset used in IV calculation in 512-byte sectors
|
||||
(how many sectors of the encrypted data to skip at the beginning).
|
||||
This option is only relevant for the \fIopen\fR action with plain
|
||||
or loopaes device types.
|
||||
|
||||
This is different from the \-\-offset options with respect to
|
||||
the sector numbers used in IV calculation.
|
||||
Using \-\-offset will shift the IV calculation by the same negative amount.
|
||||
Hence, if \-\-offset \fIn\fR, sector \fIn\fR will get a sector
|
||||
number of \fI0\fR for the IV calculation.
|
||||
Using \-\-skip causes sector \fIn\fR to also be the first sector
|
||||
of the mapped device, but with its number for IV generation is \fIn\fR.
|
||||
Hence, if \-\-offset \fIn\fR, and \-\-skip \fIs\fR, sector \fIn\fR
|
||||
(the first sector of encrypted device) will get a sector number
|
||||
of \fIs\fR for the IV calculation.
|
||||
.TP
|
||||
.B "\-\-readonly, \-r"
|
||||
set up a read-only mapping.
|
||||
@@ -675,17 +762,17 @@ set up a read-only mapping.
|
||||
.B "\-\-shared"
|
||||
Creates an additional mapping for one common
|
||||
ciphertext device. Arbitrary mappings are supported.
|
||||
This option is only relevant for the
|
||||
This option is only relevant for the
|
||||
\fIopen \-\-type plain\fR action. Use \-\-offset, \-\-size and \-\-skip to
|
||||
specify the mapped area.
|
||||
.TP
|
||||
.B "\-\-iter-time, \-i <number of milliseconds>"
|
||||
.B "\-\-iter\-time, \-i <number of milliseconds>"
|
||||
The number of milliseconds to spend with PBKDF2 passphrase processing.
|
||||
This option is only relevant for LUKS operations that set or change
|
||||
passphrases, such as \fIluksFormat\fR or \fIluksAddKey\fR.
|
||||
Specifying 0 as parameter selects the compiled-in default.
|
||||
.TP
|
||||
.B "\-\-batch-mode, \-q"
|
||||
.B "\-\-batch\-mode, \-q"
|
||||
Suppresses all confirmation questions. Use with care!
|
||||
|
||||
If the \-y option is not specified, this option also switches off
|
||||
@@ -697,7 +784,7 @@ via terminal. It is relevant every time a passphrase is asked,
|
||||
for example for \fIopen\fR, \fIluksFormat\fR or \fIluksAddKey\fR.
|
||||
It has no effect if used in conjunction with \-\-key-file.
|
||||
.br
|
||||
This option is useful when the system
|
||||
This option is useful when the system
|
||||
should not stall if the user does not input a passphrase,
|
||||
e.g. during boot. The default is a value of 0 seconds,
|
||||
which means to wait forever.
|
||||
@@ -709,7 +796,7 @@ every time a passphrase is asked, for example for
|
||||
\fIopen\fR, \fIluksFormat\fR or \fIluksAddKey\fR.
|
||||
The default is 3 tries.
|
||||
.TP
|
||||
.B "\-\-align-payload <number of 512 byte sectors>"
|
||||
.B "\-\-align\-payload <number of 512 byte sectors>"
|
||||
Align payload at a boundary of \fIvalue\fR 512-byte sectors.
|
||||
This option is relevant for \fIluksFormat\fR.
|
||||
|
||||
@@ -729,7 +816,7 @@ used with the \fIluksUUID\fR command.
|
||||
The UUID must be provided in the standard UUID format,
|
||||
e.g. 12345678-1234-1234-1234-123456789abc.
|
||||
.TP
|
||||
.B "\-\-allow-discards\fR"
|
||||
.B "\-\-allow\-discards\fR"
|
||||
Allow the use of discard (TRIM) requests for device.
|
||||
This option is only relevant for \fIopen\fR action.
|
||||
|
||||
@@ -738,22 +825,44 @@ because it can make filesystem-level operations visible on
|
||||
the physical device. For example, information leaking
|
||||
filesystem type, used space, etc. may be extractable from
|
||||
the physical device if the discarded blocks can be located
|
||||
later. If in doubt, do no use it.
|
||||
later. If in doubt, do not use it.
|
||||
|
||||
A kernel version of 3.1 or later is needed. For earlier kernels
|
||||
this option is ignored.
|
||||
.TP
|
||||
.B "\-\-test-passphrase\fR"
|
||||
.B "\-\-perf\-same_cpu_crypt\fR"
|
||||
Perform encryption using the same cpu that IO was submitted on.
|
||||
The default is to use an unbound workqueue so that encryption work
|
||||
is automatically balanced between available CPUs.
|
||||
This option is only relevant for \fIopen\fR action.
|
||||
|
||||
\fBNOTE:\fR This option is available only for low-level dm-crypt
|
||||
performance tuning, use only if you need a change to default dm-crypt
|
||||
behaviour. Needs kernel 4.0 or later.
|
||||
.TP
|
||||
.B "\-\-perf\-submit_from_crypt_cpus\fR"
|
||||
Disable offloading writes to a separate thread after encryption.
|
||||
There are some situations where offloading write bios from the
|
||||
encryption threads to a single thread degrades performance
|
||||
significantly. The default is to offload write bios to the same
|
||||
thread.
|
||||
This option is only relevant for \fIopen\fR action.
|
||||
|
||||
\fBNOTE:\fR This option is available only for low-level dm-crypt
|
||||
performance tuning, use only if you need a change to default dm-crypt
|
||||
behaviour. Needs kernel 4.0 or later.
|
||||
.TP
|
||||
.B "\-\-test\-passphrase\fR"
|
||||
Do not activate device, just verify passphrase.
|
||||
This option is only relevant for \fIopen\fR action (the device
|
||||
mapping name is not mandatory if this option is used).
|
||||
.TP
|
||||
.B "\-\-header\fR <device or file storing the LUKS header>"
|
||||
Use a detached (separated) metadata device or file where the
|
||||
LUKS header is stored. This options allows to store ciphertext
|
||||
LUKS header is stored. This options allows one to store ciphertext
|
||||
and LUKS header on different devices.
|
||||
|
||||
This option is only relevant for LUKS devices and can be
|
||||
This option is only relevant for LUKS devices and can be
|
||||
used with the \fIluksFormat\fR, \fIopen\fR, \fIluksSuspend\fR,
|
||||
\fIluksResume\fR, \fIstatus\fR and \fIresize\fR commands.
|
||||
|
||||
@@ -765,7 +874,7 @@ For other commands that change the LUKS header (e.g. \fIluksAddKey\fR),
|
||||
specify the device or file with the LUKS header directly as the
|
||||
LUKS device.
|
||||
|
||||
If used with \fIluksFormat\fR, the \-\-align-payload option is taken
|
||||
If used with \fIluksFormat\fR, the \-\-align\-payload option is taken
|
||||
as absolute sector alignment on ciphertext device and can be zero.
|
||||
|
||||
\fBWARNING:\fR There is no check whether the ciphertext device specified
|
||||
@@ -773,7 +882,7 @@ actually belongs to the header given. In fact you can specify an
|
||||
arbitrary device as the ciphertext device for \fIopen\fR
|
||||
with the \-\-header option. Use with care.
|
||||
.TP
|
||||
.B "\-\-force-password\fR"
|
||||
.B "\-\-force\-password\fR"
|
||||
Do not use password quality checking for new LUKS passwords.
|
||||
|
||||
This option applies only to \fIluksFormat\fR, \fIluksAddKey\fR and
|
||||
@@ -781,7 +890,7 @@ This option applies only to \fIluksFormat\fR, \fIluksAddKey\fR and
|
||||
password quality checking support.
|
||||
|
||||
For more info about password quality check, see manual page
|
||||
for \fBpwquality.conf(5)\fR.
|
||||
for \fBpwquality.conf(5)\fR and \fBpasswdqc.conf(5)\fR.
|
||||
.TP
|
||||
.B "\-\-version"
|
||||
Show the program version.
|
||||
@@ -806,18 +915,18 @@ low-entropy passphrases are easy to attack in plain mode.
|
||||
first newline, i.e. '\\n'.
|
||||
The input without the newline character is processed with
|
||||
the default hash or the hash specified with \-\-hash.
|
||||
The has result will be truncated to the key size
|
||||
The hash result will be truncated to the key size
|
||||
of the used cipher, or the size specified with \-s.
|
||||
|
||||
\fBFrom stdin\fR: Reading will continue until a newline (or until
|
||||
the maximum input size is reached), with the trailing newline
|
||||
stripped. The maximum input size is defined by the same
|
||||
compiled-in default as for the maximum key file size and can
|
||||
compiled-in default as for the maximum key file size and can
|
||||
be overwritten using \-\-keyfile-size option.
|
||||
|
||||
The data read will be hashed with the default hash
|
||||
or the hash specified with \-\-hash.
|
||||
The has result will be truncated to the key size
|
||||
The hash result will be truncated to the key size
|
||||
of the used cipher, or the size specified with \-s.
|
||||
|
||||
Note that if \-\-key-file=- is used for reading the key
|
||||
@@ -831,11 +940,19 @@ directly specifying a binary key.
|
||||
No warning will be given if the amount of data read from stdin is
|
||||
less than the key size.
|
||||
|
||||
\fBFrom a key file\fR: It will be truncated to the
|
||||
\fBFrom a key file\fR: It will be truncated to the
|
||||
key size of the used cipher or the size given by \-s
|
||||
and directly used as binary key.
|
||||
if the key file is shorter than the key, cryptsetup
|
||||
|
||||
\fBWARNING\fR: The \-\-hash argument is being ignored.
|
||||
The \-\-hash option is usable only for stdin input in plain mode.
|
||||
|
||||
If the key file is shorter than the key, cryptsetup
|
||||
will quit with an error.
|
||||
The maximum input size is defined by the same
|
||||
compiled-in default as for the maximum key file size and can
|
||||
be overwritten using \-\-keyfile-size option.
|
||||
|
||||
|
||||
.SH NOTES ON PASSPHRASE PROCESSING FOR LUKS
|
||||
LUKS uses PBKDF2 to protect against dictionary attacks
|
||||
@@ -849,13 +966,13 @@ the newline character.
|
||||
\fBFrom stdin\fR:
|
||||
LUKS will read passphrases from stdin up to the
|
||||
first newline character or the compiled-in
|
||||
maximum key file length. If \-\-keyfile-size is
|
||||
maximum key file length. If \-\-keyfile\-size is
|
||||
given, it is ignored.
|
||||
|
||||
\fBFrom key file\fR:
|
||||
The complete keyfile is read up to the compiled-in
|
||||
maximum size. Newline characters do not terminate the
|
||||
input. The \-\-keyfile-size option can be used to limit
|
||||
input. The \-\-keyfile\-size option can be used to limit
|
||||
what is read.
|
||||
|
||||
\fBPassphrase processing\fR:
|
||||
@@ -869,7 +986,12 @@ used key length, higher iteration times will not increase security.
|
||||
|
||||
The default setting of one second is sufficient for most
|
||||
practical cases. The only exception is a low-entropy
|
||||
passphrase used on a slow device.
|
||||
passphrase used on a device with a slow CPU, as this will
|
||||
result in a low iteration count. On a slow device it may
|
||||
be advisable to increase the iteration time using the
|
||||
\-\-iter\-time option in order to obtain a higher
|
||||
iteration count. This does slow down all later luksOpen
|
||||
operations accordingly.
|
||||
.SH INCOHERENT BEHAVIOR FOR INVALID PASSPHRASES/KEYS
|
||||
LUKS checks for a valid passphrase when an encrypted partition
|
||||
is unlocked. The behavior of plain dm-crypt is different.
|
||||
@@ -905,12 +1027,12 @@ and for wiping deleted keyslots.
|
||||
|
||||
The second type is used for the volume (master) key. You can switch
|
||||
between using /dev/random and /dev/urandom here, see
|
||||
\fP\-\-use-random\fR and \fP\-\-use-urandom\fR
|
||||
\fP\-\-use\-random\fR and \fP\-\-use\-urandom\fR
|
||||
options. Using /dev/random on a system without enough entropy sources
|
||||
can cause \fPluksFormat\fR to block until the requested amount of
|
||||
random data is gathered. In a low-entropy situation (embedded system),
|
||||
this can take a very long time and potentially forever. At the same
|
||||
time, using /dev/urandom in a low-entropy situation will
|
||||
time, using /dev/urandom in a low-entropy situation will
|
||||
produce low-quality keys. This is a serious problem, but solving
|
||||
it is out of scope for a mere man-page.
|
||||
See \fPurandom(4)\fR for more information.
|
||||
@@ -941,7 +1063,7 @@ or in the 'Issues' section on LUKS website.
|
||||
Please attach the output of the failed command with the
|
||||
\-\-debug option added.
|
||||
.SH AUTHORS
|
||||
cryptsetup originally written by Christophe Saout <christophe@saout.de>
|
||||
cryptsetup originally written by Jana Saout <jana@saout.de>
|
||||
.br
|
||||
The LUKS extensions and original man page were written by
|
||||
Clemens Fruhwirth <clemens@endorphin.org>.
|
||||
@@ -950,26 +1072,26 @@ Man page extensions by Milan Broz <gmazyland@gmail.com>.
|
||||
.br
|
||||
Man page rewrite and extension by Arno Wagner <arno@wagner.name>.
|
||||
.SH COPYRIGHT
|
||||
Copyright \(co 2004 Christophe Saout
|
||||
Copyright \(co 2004 Jana Saout
|
||||
.br
|
||||
Copyright \(co 2004-2006 Clemens Fruhwirth
|
||||
.br
|
||||
Copyright \(co 2009-2012 Red Hat, Inc.
|
||||
Copyright \(co 2009-2017 Red Hat, Inc.
|
||||
.br
|
||||
Copyright \(co 2009-2012 Milan Broz
|
||||
Copyright \(co 2009-2017 Milan Broz
|
||||
.br
|
||||
Copyright \(co 2012 Arno Wagner
|
||||
Copyright \(co 2012-2014 Arno Wagner
|
||||
|
||||
This is free software; see the source for copying conditions. There is NO
|
||||
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
.SH SEE ALSO
|
||||
The LUKS website at \fBhttp://code.google.com/p/cryptsetup/\fR
|
||||
The LUKS website at \fBhttps://gitlab.com/cryptsetup/cryptsetup/\fR
|
||||
|
||||
The cryptsetup FAQ, contained in the distribution package and
|
||||
online at
|
||||
\fBhttp://code.google.com/p/cryptsetup/wiki/FrequentlyAskedQuestions\fR
|
||||
\fBhttps://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions\fR
|
||||
|
||||
The cryptsetup mailing list and list archive, see FAQ entry 1.6.
|
||||
|
||||
The LUKS on-disk format specification available at
|
||||
\fBhttp://code.google.com/p/cryptsetup/wiki/Specification\fR
|
||||
\fBhttps://gitlab.com/cryptsetup/cryptsetup/wikis/Specification\fR
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.TH VERITYSETUP "8" "June 2012" "veritysetup" "Maintenance Commands"
|
||||
.TH VERITYSETUP "8" "March 2017" "veritysetup" "Maintenance Commands"
|
||||
.SH NAME
|
||||
veritysetup - manage dm-verity (block level verification) volumes
|
||||
.SH SYNOPSIS
|
||||
@@ -37,7 +37,8 @@ Creates a mapping with <name> backed by device <data_device> and using
|
||||
|
||||
The <root_hash> is a hexadecimal string.
|
||||
|
||||
\fB<options>\fR can be [\-\-hash-offset, \-\-no-superblock]
|
||||
\fB<options>\fR can be [\-\-hash-offset, \-\-no-superblock,
|
||||
\-\-ignore-corruption or \-\-restart-on-corruption, \-\-ignore-zero-blocks]
|
||||
|
||||
If option \-\-no-superblock is used, you have to use as the same options
|
||||
as in initial format operation.
|
||||
@@ -82,7 +83,7 @@ Create or use dm-verity without permanent on-disk superblock.
|
||||
.TP
|
||||
.B "\-\-format=number"
|
||||
Specifies the hash version type.
|
||||
Format type 0 is original Chrome OS verion. Format type 1 is current version.
|
||||
Format type 0 is original Chrome OS version. Format type 1 is current version.
|
||||
.TP
|
||||
.B "\-\-data-block-size=bytes"
|
||||
Used block size for the data device.
|
||||
@@ -110,14 +111,63 @@ Use the provided UUID for format command instead of generating new one.
|
||||
The UUID must be provided in standard UUID format,
|
||||
e.g. 12345678-1234-1234-1234-123456789abc.
|
||||
.TP
|
||||
.B "\-\-ignore-corruption", "\-\-restart-on-corruption"
|
||||
Defines what to do if data integrity problem is detected (data corruption).
|
||||
|
||||
Without these options kernel fails the IO operation with I/O error.
|
||||
With \-\-ignore-corruption option the corruption is only logged.
|
||||
With \-\-restart-on-corruption the kernel is restarted immediatelly.
|
||||
(You have to provide way how to avoid restart loops.)
|
||||
|
||||
\fBWARNING:\fR Use these options only for very specific cases.
|
||||
These options are available since Linux kernel version 4.1.
|
||||
.TP
|
||||
.B "\-\-ignore-zero-blocks"
|
||||
Instruct kernel to not verify blocks that are expected to contain zeroes
|
||||
and always directly return zeroes instead.
|
||||
|
||||
\fBWARNING:\fR Use this option only in very specific cases.
|
||||
This option is available since Linux kernel version 4.5.
|
||||
.TP
|
||||
.B "\-\-hash=hash"
|
||||
Hash algorithm for dm-verity. For default see \-\-help option.
|
||||
.TP
|
||||
.B "\-\-version"
|
||||
Show the program version.
|
||||
.SH RETURN CODES
|
||||
Veritysetup returns 0 on success and a non-zero value on error.
|
||||
|
||||
Error codes are: 1 wrong parameters, 2 no permission,
|
||||
3 out of memory, 4 wrong device specified, 5 device already exists
|
||||
or device is busy.
|
||||
Error codes are:
|
||||
1 wrong parameters
|
||||
2 no permission
|
||||
3 out of memory
|
||||
4 wrong device specified
|
||||
5 device already exists or device is busy.
|
||||
|
||||
.SH EXAMPLES
|
||||
.B "veritysetup \-\-data-blocks=256 format <data_device> <hash_device>"
|
||||
|
||||
Calculates and stores verification data on hash_device for the first 256 blocks (of block-size).
|
||||
If hash_device does not exist, it is created (as file image).
|
||||
|
||||
.B "veritysetup format <data_device> <hash_device>"
|
||||
|
||||
Calculates and stores verification data on hash_device for the whole data_device.
|
||||
|
||||
.B "veritysetup \-\-data-blocks=256 \-\-hash-offset=1052672 format <device> <device>"
|
||||
|
||||
Verification data (hashes) is stored on the same device as data (starting at hash-offset).
|
||||
Hash-offset must be greater than number of blocks in data-area.
|
||||
|
||||
.B "veritysetup \-\-data-blocks=256 \-\-hash-offset=1052672 create test-device <device> <device> <root_hash>"
|
||||
|
||||
Acivatees the verity device named test-device. Options \-\-data-blocks and \-\-hash-offset are the same
|
||||
as in the format command. The <root_hash> was calculated in format command.
|
||||
|
||||
.B "veritysetup \-\-data-blocks=256 \-\-hash-offset=1052672 verify <data_device> <hash_device> <root_hash>"
|
||||
|
||||
Verifies device without activation (in userspace).
|
||||
|
||||
.SH REPORTING BUGS
|
||||
Report bugs, including ones in the documentation, on
|
||||
the cryptsetup mailing list at <dm-crypt@saout.de>
|
||||
@@ -130,12 +180,14 @@ The first implementation of veritysetup was written by Chrome OS authors.
|
||||
This version is based on verification code written by Mikulas Patocka <mpatocka@redhat.com>
|
||||
and rewritten for libcryptsetup by Milan Broz <gmazyland@gmail.com>.
|
||||
.SH COPYRIGHT
|
||||
Copyright \(co 2012 Red Hat, Inc.
|
||||
Copyright \(co 2012-2017 Red Hat, Inc.
|
||||
.br
|
||||
Copyright \(co 2012-2017 Milan Broz
|
||||
|
||||
This is free software; see the source for copying conditions. There is NO
|
||||
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
.SH SEE ALSO
|
||||
The project website at \fBhttp://code.google.com/p/cryptsetup/\fR
|
||||
The project website at \fBhttps://gitlab.com/cryptsetup/cryptsetup\fR
|
||||
|
||||
The verity on-disk format specification available at
|
||||
\fBhttp://code.google.com/p/cryptsetup/wiki/DMVerity\fR
|
||||
\fBhttps://gitlab.com/cryptsetup/cryptsetup/wikis/DMVerity\fR
|
||||
|
||||
17
misc/11-dm-crypt.rules
Normal file
17
misc/11-dm-crypt.rules
Normal file
@@ -0,0 +1,17 @@
|
||||
# Old udev rules historically used in device-mapper.
|
||||
# No need to install these until you have some weird configuration.
|
||||
# (Code internally set the same flags.)
|
||||
|
||||
ACTION!="add|change", GOTO="crypt_end"
|
||||
ENV{DM_UDEV_RULES_VSN}!="?*", GOTO="crypt_end"
|
||||
|
||||
ENV{DM_UUID}=="CRYPT-TEMP-?*", GOTO="crypt_disable"
|
||||
ENV{DM_UUID}!="?*", ENV{DM_NAME}=="temporary-cryptsetup-?*", GOTO="crypt_disable"
|
||||
GOTO="crypt_end"
|
||||
|
||||
LABEL="crypt_disable"
|
||||
ENV{DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG}="1"
|
||||
ENV{DM_UDEV_DISABLE_DISK_RULES_FLAG}="1"
|
||||
ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}="1"
|
||||
|
||||
LABEL="crypt_end"
|
||||
@@ -2,13 +2,30 @@ Example of simple dracut module for reencryption of system
|
||||
LUKS drive on-the-fly.
|
||||
|
||||
Install in /usr/[share|lib]/dracut/modules.d/90reencrypt, then
|
||||
rebuild intramfs "with dracut -f -a reencrypt".
|
||||
build special intramfs "with dracut -a reencrypt -o crypt".
|
||||
Reencrypt module doesn't work (has a conflict) with crypt module as
|
||||
of now. After successfull reencryption reboot using original initramfs.
|
||||
|
||||
Dracut then recognize argument rd_REENCRYPT=name:size,
|
||||
e.g. rd_REENCRYPT=sda2:52G means only 52G of device
|
||||
Dracut then recognize argument rd.luks.reencrypt=name:size,
|
||||
e.g. rd.luks.reencrypt=sda2:52G means only 52G of device
|
||||
will be reencrypted (default is whole device).
|
||||
(Name is kernel name of device.)
|
||||
|
||||
If there's more than single active keyslot in the target luks device
|
||||
you're required to select one keyslot explicitly for reencryption via
|
||||
rd.luks.reencrypt_keyslot=<keyslot_number> option. Bear in mind that
|
||||
if you use this option, all other keyslots will get deactivated in the
|
||||
process.
|
||||
|
||||
Another argument, rd.luks.reencrypt_key=/dev/sda:/path/to/keyfile
|
||||
can be used to read password for specific keyslot from device containing
|
||||
filesystem with a keyfile (file with a password). If you omit reencrypt_key
|
||||
argument, reencryption would work only in case a LUKS container has
|
||||
exactly one keyslot activated.
|
||||
|
||||
Arguments rd.luks.reencrypt_keyslot and rd.luks.reencrypt_key are not
|
||||
mandatory.
|
||||
|
||||
Note that reencryption context is stored in ramdisk, any
|
||||
fail can mean complete lost of data!
|
||||
|
||||
|
||||
@@ -7,16 +7,25 @@ check() {
|
||||
|
||||
depends() {
|
||||
echo dm rootfs-block
|
||||
return 0
|
||||
}
|
||||
|
||||
installkernel() {
|
||||
instmods dm_crypt =crypto
|
||||
# requires hostonly='' override so that loop module is pulled in initramfs
|
||||
# even if not loaded in actual kernel. dracut bug?
|
||||
hostonly='' instmods dm_crypt =crypto loop
|
||||
}
|
||||
|
||||
install() {
|
||||
if dracut_module_included crypt; then
|
||||
derror "'reencrypt' can't be installed together with 'crypt'."
|
||||
derror "Add '-o crypt' option to install reencrypt module."
|
||||
return 1
|
||||
fi
|
||||
|
||||
dracut_install cryptsetup-reencrypt
|
||||
|
||||
# moddir variable is assigned in dracut general shell lib
|
||||
# shellcheck disable=SC2154
|
||||
inst_hook cmdline 30 "$moddir/parse-reencrypt.sh"
|
||||
inst_simple "$moddir"/reencrypt.sh /sbin/reencrypt
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,33 @@
|
||||
#!/bin/sh
|
||||
|
||||
REENC=$(getargs rd_REENCRYPT=)
|
||||
REENC=$(getargs rd.luks.reencrypt=)
|
||||
REENC_DEV=$(echo $REENC | sed 's/:.*//')
|
||||
REENC_SIZE=$(echo $REENC | sed -n 's/.*://p')
|
||||
|
||||
REENC_KEY=$(getargs rd_REENCRYPT_KEY=)
|
||||
REENC_KEY=$(getargs rd.luks.reencrypt_key=)
|
||||
if [ -z "$REENC_KEY" ] ; then
|
||||
REENC_KEY=none
|
||||
fi
|
||||
|
||||
REENC_SLOT=$(getargs rd.luks.reencrypt_keyslot=)
|
||||
if [ -z "$REENC_SLOT" ] ; then
|
||||
REENC_SLOT=any
|
||||
fi
|
||||
|
||||
if [ -n "$REENC_DEV" ] ; then
|
||||
{
|
||||
printf 'SUBSYSTEM!="block", GOTO="reenc_end"\n'
|
||||
printf 'ACTION!="add|change", GOTO="reenc_end"\n'
|
||||
printf 'KERNEL!="%s", GOTO="reenc_end"\n' $REENC_DEV
|
||||
printf 'KERNEL=="%s", ' $REENC_DEV
|
||||
printf 'ENV{ID_FS_TYPE}=="crypto_LUKS", RUN+="/sbin/initqueue \
|
||||
--unique --onetime --name crypt-reencrypt-%%k \
|
||||
/sbin/reencrypt $env{DEVNAME} %s"\n' "$REENC_KEY $REENC_SIZE"
|
||||
--unique --onetime --settled --name crypt-reencrypt-%%k \
|
||||
/sbin/reencrypt $env{DEVNAME} %s"\n' "$REENC_KEY $REENC_SLOT $REENC_SIZE"
|
||||
|
||||
printf 'ENV{ID_FS_UUID}=="*%s*", ' $REENC_DEV
|
||||
printf 'ENV{ID_FS_TYPE}=="crypto_LUKS", RUN+="/sbin/initqueue \
|
||||
--unique --onetime --settled --name crypt-reencrypt-%%k \
|
||||
/sbin/reencrypt $env{DEVNAME} %s"\n' "$REENC_KEY $REENC_SLOT $REENC_SIZE"
|
||||
printf 'LABEL="reenc_end"\n'
|
||||
} > /etc/udev/rules.d/69-reencryption.rules
|
||||
initqueue --unique --finished --name crypt-reencrypt-finished-${REENC_DEV} [ -e /tmp/reencrypted ]
|
||||
fi
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# $1=$device [$2=keyfile|none [$3=size]]
|
||||
# $1=$device [$2=keyfile|none [$3=keyslot|any [$4=size]]]
|
||||
#
|
||||
|
||||
[ -d /sys/module/dm_crypt ] || modprobe dm_crypt
|
||||
|
||||
[ -d /sys/module/loop ] || modprobe loop
|
||||
|
||||
[ -f /tmp/reencrypted ] && exit 0
|
||||
|
||||
. /lib/dracut-lib.sh
|
||||
@@ -17,8 +19,12 @@ else
|
||||
fi
|
||||
|
||||
PARAMS="$device -T 1 --use-fsync -B 32"
|
||||
if [ -n "$3" ]; then
|
||||
PARAMS="$PARAMS --device-size $3"
|
||||
if [ "$3" != "any" ]; then
|
||||
PARAMS="$PARAMS -S $3"
|
||||
fi
|
||||
|
||||
if [ -n "$4" ]; then
|
||||
PARAMS="$PARAMS --device-size $4"
|
||||
fi
|
||||
|
||||
reenc_readkey() {
|
||||
@@ -33,26 +39,43 @@ reenc_readkey() {
|
||||
}
|
||||
|
||||
reenc_run() {
|
||||
local cwd=$(pwd)
|
||||
local cwd
|
||||
cwd=$(pwd)
|
||||
local _prompt="LUKS password for REENCRYPTING $device"
|
||||
cd /tmp
|
||||
udevadm settle
|
||||
if [ "$1" = "none" ] ; then
|
||||
if [ "$2" != "any" ]; then
|
||||
_prompt="$_prompt, using keyslot $2"
|
||||
fi
|
||||
/bin/plymouth ask-for-password \
|
||||
--prompt "LUKS password for REENCRYPTING $device" \
|
||||
--prompt "$_prompt" \
|
||||
--command="/sbin/cryptsetup-reencrypt $PARAMS"
|
||||
else
|
||||
info "REENCRYPT using key $1"
|
||||
reenc_readkey "$1" | /sbin/cryptsetup-reencrypt -d - $PARAMS
|
||||
fi
|
||||
_ret=$?
|
||||
cd $cwd
|
||||
}
|
||||
|
||||
info "REENCRYPT $device requested"
|
||||
# flock against other interactive activities
|
||||
{ flock -s 9;
|
||||
reenc_run $2
|
||||
} 9>/.console.lock
|
||||
reenc_run $2 $3
|
||||
} 9>/.console_lock
|
||||
|
||||
# do not ask again
|
||||
>> /tmp/reencrypted
|
||||
if [ $_ret -eq 0 ]; then
|
||||
# do not ask again
|
||||
>> /tmp/reencrypted
|
||||
warn "Reencryption of device $device has finished successfully. Use previous"
|
||||
warn "initramfs image (without reencrypt module) to boot the system. When"
|
||||
warn "you leave the emergency shell, the system will reboot."
|
||||
|
||||
exit 0
|
||||
emergency_shell -n "(reboot)"
|
||||
[ -x /usr/bin/systemctl ] && /usr/bin/systemctl reboot
|
||||
[ -x /sbin/shutdown ] && /sbin/shutdown -r now
|
||||
fi
|
||||
|
||||
# panic the kernel otherwise
|
||||
exit 1
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
cs
|
||||
da
|
||||
de
|
||||
es
|
||||
fi
|
||||
fr
|
||||
id
|
||||
it
|
||||
nl
|
||||
pl
|
||||
pt_BR
|
||||
sr
|
||||
sv
|
||||
uk
|
||||
vi
|
||||
zh_CN
|
||||
|
||||
1
po/id.po
1
po/id.po
@@ -11,6 +11,7 @@ msgstr ""
|
||||
"PO-Revision-Date: 2010-01-27 07:30+0700\n"
|
||||
"Last-Translator: Arif E. Nugroho <arif_endro@yahoo.com>\n"
|
||||
"Language-Team: Indonesian <translation-team-id@lists.sourceforge.net>\n"
|
||||
"X-Bugs: Report translation errors to the Language-Team address.\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=ISO-8859-1\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
1840
po/pt_BR.po
Normal file
1840
po/pt_BR.po
Normal file
File diff suppressed because it is too large
Load Diff
1790
po/zh_CN.po
Normal file
1790
po/zh_CN.po
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/lib $(PYTHON_INCLUDES)
|
||||
AM_CPPFLAGS = -include $(top_srcdir)/config.h -I$(top_srcdir)/lib $(PYTHON_INCLUDES)
|
||||
EXTRA_DIST = pycryptsetup-test.py
|
||||
CLEANFILES = *.img
|
||||
|
||||
@@ -9,8 +9,8 @@ pyexec_LTLIBRARIES = pycryptsetup.la
|
||||
|
||||
pycryptsetup_la_SOURCES = pycryptsetup.c
|
||||
pycryptsetup_la_CPPFLAGS = $(AM_CPPFLAGS) $(PYTHON_CPPFLAGS) -fno-strict-aliasing
|
||||
pycryptsetup_la_LDFLAGS = -avoid-version -module
|
||||
pycryptsetup_la_LIBADD = $(top_builddir)/lib/libcryptsetup.la -lpython$(PYTHON_VERSION)
|
||||
pycryptsetup_la_LDFLAGS = -avoid-version -module -shared -export-dynamic
|
||||
pycryptsetup_la_LIBADD = $(top_builddir)/lib/libcryptsetup.la $(PYTHON_LIBS)
|
||||
else
|
||||
all:
|
||||
endif
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#
|
||||
# Python bindings to libcryptsetup test
|
||||
#
|
||||
# Copyright (C) 2011, Red Hat, Inc. All rights reserved.
|
||||
# Copyright (C) 2011-2017, Red Hat, Inc. All rights reserved.
|
||||
#
|
||||
# This file is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
@@ -18,6 +18,8 @@
|
||||
# License along with this file; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
@@ -31,11 +33,11 @@ DEVICE = "pycryptsetup_test_dev"
|
||||
|
||||
def log(level, txt):
|
||||
if level == pycryptsetup.CRYPT_LOG_ERROR:
|
||||
print txt,
|
||||
print(txt,end="")
|
||||
return
|
||||
|
||||
def askyes(txt):
|
||||
print "Question:", txt
|
||||
print("Question:", txt)
|
||||
return 1
|
||||
|
||||
def askpassword(txt):
|
||||
@@ -43,17 +45,17 @@ def askpassword(txt):
|
||||
|
||||
def print_status(c):
|
||||
r = c.status()
|
||||
print "status :",
|
||||
print("status :",end="")
|
||||
if r == pycryptsetup.CRYPT_ACTIVE:
|
||||
print "ACTIVE"
|
||||
print("ACTIVE")
|
||||
elif r == pycryptsetup.CRYPT_INACTIVE:
|
||||
print "INACTIVE"
|
||||
print("INACTIVE")
|
||||
else:
|
||||
print "ERROR"
|
||||
print("ERROR")
|
||||
return
|
||||
|
||||
if os.geteuid() != 0:
|
||||
print "WARNING: You must be root to run this test, test skipped."
|
||||
print("WARNING: You must be root to run this test, test skipped.")
|
||||
sys.exit(0)
|
||||
|
||||
os.system("dd if=/dev/zero of=" + IMG + " bs=1M count=32 >/dev/null 2>&1")
|
||||
@@ -69,36 +71,36 @@ c = pycryptsetup.CryptSetup(
|
||||
c.debugLevel(pycryptsetup.CRYPT_DEBUG_NONE);
|
||||
c.iterationTime(1)
|
||||
r = c.isLuks()
|
||||
print "isLuks :", r
|
||||
print("isLuks :", r)
|
||||
c.askyes(message = "Is there anybody out there?")
|
||||
c.log(priority = pycryptsetup.CRYPT_LOG_ERROR, message = "Nobody there...\n")
|
||||
c.luksFormat(cipher = "aes", cipherMode= "xts-plain64", keysize = 512)
|
||||
print "isLuks :", c.isLuks()
|
||||
print "luksUUID:", c.luksUUID()
|
||||
print "addKeyVK:", c.addKeyByVolumeKey(newPassphrase = PASSWORD, slot = 2)
|
||||
print "addKeyP :", c.addKeyByPassphrase(passphrase = PASSWORD,
|
||||
newPassphrase = PASSWORD2, slot = 3)
|
||||
print "removeP :", c.removePassphrase(passphrase = PASSWORD2)
|
||||
print "addKeyP :", c.addKeyByPassphrase(PASSWORD, PASSWORD2)
|
||||
c.luksFormat(cipher = "aes", cipherMode= "xts-plain64", keysize = 512, hashMode = "sha256")
|
||||
print("isLuks :", c.isLuks())
|
||||
print("luksUUID:", c.luksUUID())
|
||||
print("addKeyVK:", c.addKeyByVolumeKey(newPassphrase = PASSWORD, slot = 2))
|
||||
print("addKeyP :", c.addKeyByPassphrase(passphrase = PASSWORD,
|
||||
newPassphrase = PASSWORD2, slot = 3))
|
||||
print("removeP :", c.removePassphrase(passphrase = PASSWORD2))
|
||||
print("addKeyP :", c.addKeyByPassphrase(PASSWORD, PASSWORD2))
|
||||
# original api required wrong passphrase parameter here
|
||||
# print "killSlot:", c.killSlot(passphrase = "xxx", slot = 0)
|
||||
print "killSlot:", c.killSlot(slot = 0)
|
||||
print "activate:", c.activate(name = DEVICE, passphrase = PASSWORD)
|
||||
print "suspend :", c.suspend()
|
||||
print("killSlot:", c.killSlot(slot = 0))
|
||||
print("activate:", c.activate(name = DEVICE, passphrase = PASSWORD))
|
||||
print("suspend :", c.suspend())
|
||||
# os.system("dmsetup info -c " + DEVICE)
|
||||
print "resume :", c.resume(passphrase = PASSWORD)
|
||||
print("resume :", c.resume(passphrase = PASSWORD))
|
||||
print_status(c)
|
||||
info = c.info()
|
||||
print "cipher :", info["cipher"]
|
||||
print "cmode :", info["cipher_mode"]
|
||||
print "keysize :", info["keysize"]
|
||||
print "dir :", info["dir"]
|
||||
print "device :", info["device"]
|
||||
print "offset :", info["offset"]
|
||||
print "name :", info["name"]
|
||||
print "uuid :", info["uuid"]
|
||||
print("cipher :", info["cipher"])
|
||||
print("cmode :", info["cipher_mode"])
|
||||
print("keysize :", info["keysize"])
|
||||
print("dir :", info["dir"])
|
||||
print("device :", info["device"])
|
||||
print("offset :", info["offset"])
|
||||
print("name :", info["name"])
|
||||
print("uuid :", info["uuid"])
|
||||
# os.system("cryptsetup luksDump " + info["device"])
|
||||
print "deact. :", c.deactivate()
|
||||
print("deact. :", c.deactivate())
|
||||
|
||||
del c
|
||||
|
||||
@@ -109,7 +111,7 @@ c = pycryptsetup.CryptSetup(
|
||||
logFunc = log,
|
||||
passwordDialog = askpassword)
|
||||
|
||||
print "activate:", c.activate(name = DEVICE, passphrase = PASSWORD)
|
||||
print("activate:", c.activate(name = DEVICE, passphrase = PASSWORD))
|
||||
|
||||
c2 = pycryptsetup.CryptSetup(
|
||||
name = DEVICE,
|
||||
@@ -118,13 +120,13 @@ c2 = pycryptsetup.CryptSetup(
|
||||
passwordDialog = askpassword)
|
||||
|
||||
info = c2.info()
|
||||
print "cipher :", info["cipher"]
|
||||
print "cmode :", info["cipher_mode"]
|
||||
print "keysize :", info["keysize"]
|
||||
print("cipher :", info["cipher"])
|
||||
print("cmode :", info["cipher_mode"])
|
||||
print("keysize :", info["keysize"])
|
||||
|
||||
print "deact. :", c.deactivate()
|
||||
print("deact. :", c.deactivate())
|
||||
r = c2.deactivate()
|
||||
print "deact. :", r
|
||||
print("deact. :", r)
|
||||
del c
|
||||
del c2
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user