Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 1 | /* |
| 2 | * volume_id - reads filesystem label and uuid |
| 3 | * |
| 4 | * Copyright (C) 2005 W. Michael Petullo <mike@flyn.org> |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | #include "volume_id_internal.h" |
| 22 | |
Denis Vlasenko | d5e3059 | 2008-10-12 11:17:49 +0000 | [diff] [blame] | 23 | #define LUKS_MAGIC_L 6 |
| 24 | #define UUID_STRING_L 40 |
| 25 | #define LUKS_CIPHERNAME_L 32 |
| 26 | #define LUKS_CIPHERMODE_L 32 |
| 27 | #define LUKS_HASHSPEC_L 32 |
| 28 | #define LUKS_DIGESTSIZE 20 |
| 29 | #define LUKS_SALTSIZE 32 |
| 30 | #define LUKS_NUMKEYS 8 |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 31 | |
| 32 | static const uint8_t LUKS_MAGIC[] = { 'L','U','K','S', 0xba, 0xbe }; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 33 | |
| 34 | struct luks_phdr { |
| 35 | uint8_t magic[LUKS_MAGIC_L]; |
| 36 | uint16_t version; |
| 37 | uint8_t cipherName[LUKS_CIPHERNAME_L]; |
| 38 | uint8_t cipherMode[LUKS_CIPHERMODE_L]; |
| 39 | uint8_t hashSpec[LUKS_HASHSPEC_L]; |
| 40 | uint32_t payloadOffset; |
| 41 | uint32_t keyBytes; |
| 42 | uint8_t mkDigest[LUKS_DIGESTSIZE]; |
| 43 | uint8_t mkDigestSalt[LUKS_SALTSIZE]; |
| 44 | uint32_t mkDigestIterations; |
| 45 | uint8_t uuid[UUID_STRING_L]; |
| 46 | struct { |
| 47 | uint32_t active; |
| 48 | uint32_t passwordIterations; |
| 49 | uint8_t passwordSalt[LUKS_SALTSIZE]; |
| 50 | uint32_t keyMaterialOffset; |
| 51 | uint32_t stripes; |
| 52 | } keyblock[LUKS_NUMKEYS]; |
| 53 | }; |
| 54 | |
Denis Vlasenko | d5e3059 | 2008-10-12 11:17:49 +0000 | [diff] [blame] | 55 | enum { |
| 56 | EXPECTED_SIZE_luks_phdr = 0 |
| 57 | + 1 * LUKS_MAGIC_L |
| 58 | + 2 |
| 59 | + 1 * LUKS_CIPHERNAME_L |
| 60 | + 1 * LUKS_CIPHERMODE_L |
| 61 | + 1 * LUKS_HASHSPEC_L |
| 62 | + 4 |
| 63 | + 4 |
| 64 | + 1 * LUKS_DIGESTSIZE |
| 65 | + 1 * LUKS_SALTSIZE |
| 66 | + 4 |
| 67 | + 1 * UUID_STRING_L |
| 68 | + LUKS_NUMKEYS * (0 |
| 69 | + 4 |
| 70 | + 4 |
| 71 | + 1 * LUKS_SALTSIZE |
| 72 | + 4 |
| 73 | + 4 |
| 74 | ) |
| 75 | }; |
| 76 | |
| 77 | struct BUG_bad_size_luks_phdr { |
| 78 | char BUG_bad_size_luks_phdr[ |
| 79 | sizeof(struct luks_phdr) == EXPECTED_SIZE_luks_phdr ? |
| 80 | 1 : -1]; |
| 81 | }; |
| 82 | |
Denis Vlasenko | 28ea429 | 2009-02-15 05:51:19 +0000 | [diff] [blame] | 83 | int volume_id_probe_luks(struct volume_id *id /*,uint64_t off*/) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 84 | { |
Denis Vlasenko | 28ea429 | 2009-02-15 05:51:19 +0000 | [diff] [blame] | 85 | #define off ((uint64_t)0) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 86 | struct luks_phdr *header; |
| 87 | |
Denis Vlasenko | d5e3059 | 2008-10-12 11:17:49 +0000 | [diff] [blame] | 88 | header = volume_id_get_buffer(id, off, sizeof(*header)); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 89 | if (header == NULL) |
| 90 | return -1; |
| 91 | |
| 92 | if (memcmp(header->magic, LUKS_MAGIC, LUKS_MAGIC_L)) |
| 93 | return -1; |
| 94 | |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 95 | // volume_id_set_usage(id, VOLUME_ID_CRYPTO); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 96 | volume_id_set_uuid(id, header->uuid, UUID_DCE_STRING); |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 97 | // id->type = "crypto_LUKS"; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 98 | |
| 99 | return 0; |
| 100 | } |