~pr0gg3d/ubuntu/oneiric/util-linux/bug-805886

« back to all changes in this revision

Viewing changes to shlibs/blkid/src/probers/luks.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant
  • Date: 2009-07-16 15:48:23 UTC
  • mfrom: (1.3.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20090716154823-i26fshvs4v8h90qh
Tags: 2.16-1ubuntu1
* Merge from Debian, remaining changes:
  - Since udev is required in Ubuntu, the hwclock.sh init script is
    not called on startup and the hwclockfirst.sh init script is
    removed.
  - Remove /etc/adjtime on upgrade if it was not used.
  - Install custom blkid.conf to use /dev/.blkid.tab since we don't
    expect device names to survive a reboot
  - No lsb_release call in mount.preinst since we'd need Pre-Depends
    (LP: #383697).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
 
3
 *
 
4
 * Inspired by libvolume_id by
 
5
 *     Kay Sievers <kay.sievers@vrfy.org>
 
6
 *
 
7
 * This file may be redistributed under the terms of the
 
8
 * GNU Lesser General Public License.
 
9
 */
 
10
#include <stdio.h>
 
11
#include <stdlib.h>
 
12
#include <unistd.h>
 
13
#include <string.h>
 
14
#include <errno.h>
 
15
#include <ctype.h>
 
16
#include <stdint.h>
 
17
 
 
18
#include "blkidP.h"
 
19
 
 
20
#define LUKS_CIPHERNAME_L               32
 
21
#define LUKS_CIPHERMODE_L               32
 
22
#define LUKS_HASHSPEC_L                 32
 
23
#define LUKS_DIGESTSIZE                 20
 
24
#define LUKS_SALTSIZE                   32
 
25
#define LUKS_MAGIC_L                    6
 
26
#define UUID_STRING_L                   40
 
27
 
 
28
struct luks_phdr {
 
29
        uint8_t         magic[LUKS_MAGIC_L];
 
30
        uint16_t        version;
 
31
        uint8_t         cipherName[LUKS_CIPHERNAME_L];
 
32
        uint8_t         cipherMode[LUKS_CIPHERMODE_L];
 
33
        uint8_t         hashSpec[LUKS_HASHSPEC_L];
 
34
        uint32_t        payloadOffset;
 
35
        uint32_t        keyBytes;
 
36
        uint8_t         mkDigest[LUKS_DIGESTSIZE];
 
37
        uint8_t         mkDigestSalt[LUKS_SALTSIZE];
 
38
        uint32_t        mkDigestIterations;
 
39
        uint8_t         uuid[UUID_STRING_L];
 
40
};
 
41
 
 
42
static int probe_luks(blkid_probe pr, const struct blkid_idmag *mag)
 
43
{
 
44
        struct luks_phdr *header;
 
45
 
 
46
        header = blkid_probe_get_sb(pr, mag, struct luks_phdr);
 
47
        if (header == NULL)
 
48
                return -1;
 
49
 
 
50
        blkid_probe_strncpy_uuid(pr, (unsigned char *) header->uuid,
 
51
                        sizeof(header->uuid));
 
52
        blkid_probe_sprintf_version(pr, "%u", le16_to_cpu(header->version));
 
53
        return 0;
 
54
}
 
55
 
 
56
const struct blkid_idinfo luks_idinfo =
 
57
{
 
58
        .name           = "crypto_LUKS",
 
59
        .usage          = BLKID_USAGE_CRYPTO,
 
60
        .probefunc      = probe_luks,
 
61
        .magics         =
 
62
        {
 
63
                { .magic = "LUKS\xba\xbe", .len = 6 },
 
64
                { NULL }
 
65
        }
 
66
};