~ubuntu-branches/debian/jessie/cryptsetup/jessie

« back to all changes in this revision

Viewing changes to lib/luks1/keyencryption.c

  • Committer: Package Import Robot
  • Author(s): Jonas Meurer
  • Date: 2012-02-05 03:17:59 UTC
  • mfrom: (0.2.9)
  • Revision ID: package-import@ubuntu.com-20120205031759-kua3bplwunj0q2zl
Tags: 2:1.4.1-1
* new upstream release (1.4.0 + 1.4.1) (closes: #647851)
  - fixes typo in german translation. (closes: #645528)
  - remove patches, all incorporated upstream.
  - soname bump, rename library package to libcryptsetup4
* check for busybox in initramfs cryptroot hook, and install the sed binary
  in case it's either not installed or not activated. (closes: #591853)
* add checks for 'type $KEYSCRIPT' to initscripts cryptdisks.functions, and
  to cryptroot initramfs script/hook. this adds support for keyscripts inside
  $PATH. thanks to Ian Jackson for the suggestion. (closes: #597583)
* use argument '--sysinit' for vgchange in cryptroot initramfs script. Thanks
  to Christoph Anton Mitterer for the suggestion.
* add option for discard/trim features to crypttab and initramfs scripts.
  Thanks to intrigeri and Peter Colberg for patches. (closes: #648868)
* print $target on error in initramfs hook. Thanks to Daniel Hahler for the
  bugreport. (closes: #648192)
* add a warning about using decrypt_derived keyscript for devices with
  persistent data. Thanks to Arno Wagner for pointing this out.
* remove quotes from resume device candidates at get_resume_devs() in
  initramfs hook script. Thanks to Johannes Rohr. (closes: #634017)
* support custom $TABFILE, thanks to Douglas Huff. (closes: #638317)
* fix get_lvm_deps() in initramfs cryptroot hook to add all physical volumes
  of lvm volume group that contains the rootfs logical volume, even if the
  rootfs is lv is not spread over all physical volumes. Thanks to Christian
  Pernegger for bugreport and patch. (closes: #634109)
* debian/initramfs/cryptroot-script: Move check for maximum number of tries
  behind the while loop, to make the warning appear in case that maximum
  number of tries is reached. Thanks to Chistian Lamparter for bugreport and
  patch. (closes: #646083)
* incorporate changes to package descriptions and debconf templates that
  suggested by debian-l10n-english people. Special thanks go to Justin B Rye.
* acknowledge NMU, thanks a lot to Christian Perrier for his great work on
  the i18n front. (closes: #633105, #641719, #641839, #641947, #642470,
  #640056, #642540, #643633, #643962, #644853)
* add and update debconf translations:
  - italian, thanks to Milo Casagrande, Francesca Ciceri. (closes: #656933)
  - german, thanks to Erik Pfannenstein. (closes: #642147)
  - spanish, thanks to Camaleón. (closes: #658360)
  - russian, thanks to Yuri Kuzlov (closes: #654676)
* set architecture to linux-any, depends on linux kernel anyway. Thanks to
  Christoph Egger. (closes: #638257)
* small updates to the copyright file.
* add targets build-indep and build-arch to debian/rules, thanks to lintian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 *
15
15
 * You should have received a copy of the GNU General Public License
16
16
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
18
 */
19
19
 
20
20
#include <string.h>
50
50
static int devfd=-1;
51
51
 
52
52
static int setup_mapping(const char *cipher, const char *name,
53
 
                         const char *device, unsigned int payloadOffset,
54
 
                         const char *key, size_t keyLength,
 
53
                         const char *device,
 
54
                         struct volume_key *vk,
55
55
                         unsigned int sector, size_t srcLength,
56
56
                         int mode, struct crypt_device *ctx)
57
57
{
58
58
        int device_sector_size = sector_size_for_device(device);
59
 
        uint64_t size;
 
59
        struct crypt_dm_active_device dmd = {
 
60
                .device = device,
 
61
                .cipher = cipher,
 
62
                .uuid   = NULL,
 
63
                .vk     = vk,
 
64
                .offset = sector,
 
65
                .iv_offset = 0,
 
66
                .size   = 0,
 
67
                .flags  = (mode == O_RDONLY) ? CRYPT_ACTIVATE_READONLY : 0
 
68
        };
60
69
 
61
70
        /*
62
71
         * we need to round this to nearest multiple of the underlying
66
75
                log_err(ctx, _("Unable to obtain sector size for %s"), device);
67
76
                return -EINVAL;
68
77
        }
69
 
        size = round_up_modulo(srcLength,device_sector_size)/SECTOR_SIZE;
70
 
        cleaner_size = size;
71
 
 
72
 
        return dm_create_device(name, device, cipher, "TEMP", NULL, size, 0, sector,
73
 
                                keyLength, key, (mode == O_RDONLY), 0);
 
78
 
 
79
        dmd.size = round_up_modulo(srcLength,device_sector_size)/SECTOR_SIZE;
 
80
        cleaner_size = dmd.size;
 
81
 
 
82
        return dm_create_device(name, "TEMP", &dmd, 0);
74
83
}
75
84
 
76
 
static void sigint_handler(int sig)
 
85
static void sigint_handler(int sig __attribute__((unused)))
77
86
{
78
87
        if(devfd >= 0)
79
88
                close(devfd);
85
94
        kill(getpid(), SIGINT);
86
95
}
87
96
 
88
 
static char *_error_hint(char *cipherName, char *cipherMode, size_t keyLength)
 
97
static const char *_error_hint(char *cipherMode, size_t keyLength)
89
98
{
90
 
        char *hint = "";
91
 
#ifdef __linux__
92
 
        char c, tmp[4] = {0};
93
 
        struct utsname uts;
94
 
        int i = 0, kernel_minor;
95
 
 
96
 
        /* Nothing to suggest here */
97
 
        if (uname(&uts) || strncmp(uts.release, "2.6.", 4))
98
 
                return hint;
99
 
 
100
 
        /* Get kernel minor without suffixes */
101
 
        while (i < 3 && (c = uts.release[i + 4]))
102
 
                tmp[i++] = isdigit(c) ? c : '\0';
103
 
        kernel_minor = atoi(tmp);
 
99
        const char *hint= "";
104
100
 
105
101
        if (!strncmp(cipherMode, "xts", 3) && (keyLength != 256 && keyLength != 512))
106
102
                hint = _("Key size in XTS mode must be 256 or 512 bits.\n");
107
 
        else if (!strncmp(cipherMode, "xts", 3) && kernel_minor < 24)
108
 
                hint = _("Block mode XTS is available since kernel 2.6.24.\n");
109
 
        if (!strncmp(cipherMode, "lrw", 3) && (keyLength != 256 && keyLength != 512))
110
 
                hint = _("Key size in LRW mode must be 256 or 512 bits.\n");
111
 
        else if (!strncmp(cipherMode, "lrw", 3) && kernel_minor < 20)
112
 
                hint = _("Block mode LRW is available since kernel 2.6.20.\n");
113
 
#endif
 
103
 
114
104
        return hint;
115
105
}
116
106
 
118
108
   handler and global vars for cleaning */
119
109
static int LUKS_endec_template(char *src, size_t srcLength,
120
110
                               struct luks_phdr *hdr,
121
 
                               char *key, size_t keyLength,
 
111
                               struct volume_key *vk,
122
112
                               const char *device,
123
113
                               unsigned int sector,
124
114
                               ssize_t (*func)(int, void *, size_t),
145
135
        signal(SIGINT, sigint_handler);
146
136
        cleaner_name = name;
147
137
 
148
 
        r = setup_mapping(dmCipherSpec, name, device, hdr->payloadOffset,
149
 
                          key, keyLength, sector, srcLength, mode, ctx);
 
138
        r = setup_mapping(dmCipherSpec, name, device,
 
139
                          vk, sector, srcLength, mode, ctx);
150
140
        if(r < 0) {
151
141
                log_err(ctx, _("Failed to setup dm-crypt key mapping for device %s.\n"
152
142
                        "Check that kernel supports %s cipher (check syslog for more info).\n%s"),
153
143
                        device, dmCipherSpec,
154
 
                        _error_hint(hdr->cipherName, hdr->cipherMode, keyLength * 8));
 
144
                        _error_hint(hdr->cipherMode, vk->keylength * 8));
155
145
                r = -EIO;
156
146
                goto out1;
157
147
        }
188
178
 
189
179
int LUKS_encrypt_to_storage(char *src, size_t srcLength,
190
180
                            struct luks_phdr *hdr,
191
 
                            char *key, size_t keyLength,
 
181
                            struct volume_key *vk,
192
182
                            const char *device,
193
183
                            unsigned int sector,
194
184
                            struct crypt_device *ctx)
195
185
{
196
 
        return LUKS_endec_template(src,srcLength,hdr,key,keyLength, device, sector,
197
 
                                   (ssize_t (*)(int, void *, size_t)) write_blockwise,
198
 
                                   O_RDWR, ctx);
 
186
        return LUKS_endec_template(src,srcLength,hdr,vk, device,
 
187
                                   sector, write_blockwise, O_RDWR, ctx);
199
188
}
200
189
 
201
190
int LUKS_decrypt_from_storage(char *dst, size_t dstLength,
202
191
                              struct luks_phdr *hdr,
203
 
                              char *key, size_t keyLength,
 
192
                              struct volume_key *vk,
204
193
                              const char *device,
205
194
                              unsigned int sector,
206
195
                              struct crypt_device *ctx)
207
196
{
208
 
        return LUKS_endec_template(dst,dstLength,hdr,key,keyLength, device,
 
197
        return LUKS_endec_template(dst,dstLength,hdr,vk, device,
209
198
                                   sector, read_blockwise, O_RDONLY, ctx);
210
199
}