|
18 | 18 | #include "libcryptsetup.h" |
19 | 19 | #include "utils_crypt.h" |
20 | 20 |
|
21 | | -#define MAX_CAPI_LEN_STR "143" /* for sscanf of crypto API string + 16 + \0 */ |
22 | | - |
23 | 21 | int crypt_parse_name_and_mode(const char *s, char *cipher, int *key_nums, |
24 | 22 | char *cipher_mode) |
25 | 23 | { |
@@ -285,89 +283,3 @@ bool crypt_is_cipher_null(const char *cipher_spec) |
285 | 283 | return false; |
286 | 284 | return (strstr(cipher_spec, "cipher_null") || !strcmp(cipher_spec, "null")); |
287 | 285 | } |
288 | | - |
289 | | -int crypt_capi_to_cipher(char **org_c, char **org_i, const char *c_dm, const char *i_dm) |
290 | | -{ |
291 | | - char cipher[MAX_CAPI_ONE_LEN], mode[MAX_CAPI_ONE_LEN], iv[MAX_CAPI_ONE_LEN], |
292 | | - auth[MAX_CAPI_ONE_LEN], tmp[MAX_CAPI_LEN], dmcrypt_tmp[MAX_CAPI_LEN*2], |
293 | | - capi[MAX_CAPI_LEN+1]; |
294 | | - size_t len; |
295 | | - int i; |
296 | | - |
297 | | - if (!c_dm) |
298 | | - return -EINVAL; |
299 | | - |
300 | | - /* legacy mode */ |
301 | | - if (strncmp(c_dm, "capi:", 5)) { |
302 | | - if (!(*org_c = strdup(c_dm))) |
303 | | - return -ENOMEM; |
304 | | - if (i_dm) { |
305 | | - if (!(*org_i = strdup(i_dm))) { |
306 | | - free(*org_c); |
307 | | - *org_c = NULL; |
308 | | - return -ENOMEM; |
309 | | - } |
310 | | - } else |
311 | | - *org_i = NULL; |
312 | | - return 0; |
313 | | - } |
314 | | - |
315 | | - /* modes with capi: prefix */ |
316 | | - i = sscanf(c_dm, "capi:%" MAX_CAPI_LEN_STR "[^-]-%" MAX_CAPI_ONE_LEN_STR "s", tmp, iv); |
317 | | - if (i != 2) |
318 | | - return -EINVAL; |
319 | | - |
320 | | - /* non-cryptsetup compatible mode (generic driver with dash?) */ |
321 | | - if (strrchr(iv, ')')) { |
322 | | - if (i_dm) |
323 | | - return -EINVAL; |
324 | | - if (!(*org_c = strdup(c_dm))) |
325 | | - return -ENOMEM; |
326 | | - return 0; |
327 | | - } |
328 | | - |
329 | | - len = strlen(tmp); |
330 | | - if (len < 2) |
331 | | - return -EINVAL; |
332 | | - |
333 | | - if (tmp[len-1] == ')') |
334 | | - tmp[len-1] = '\0'; |
335 | | - |
336 | | - if (sscanf(tmp, "rfc4309(%" MAX_CAPI_LEN_STR "s", capi) == 1) { |
337 | | - if (!(*org_i = strdup("aead"))) |
338 | | - return -ENOMEM; |
339 | | - } else if (sscanf(tmp, "rfc7539(%" MAX_CAPI_LEN_STR "[^,],%" MAX_CAPI_ONE_LEN_STR "s", capi, auth) == 2) { |
340 | | - if (!(*org_i = strdup(auth))) |
341 | | - return -ENOMEM; |
342 | | - } else if (sscanf(tmp, "authenc(%" MAX_CAPI_ONE_LEN_STR "[^,],%" MAX_CAPI_LEN_STR "s", auth, capi) == 2) { |
343 | | - if (!(*org_i = strdup(auth))) |
344 | | - return -ENOMEM; |
345 | | - } else { |
346 | | - if (i_dm) { |
347 | | - if (!(*org_i = strdup(i_dm))) |
348 | | - return -ENOMEM; |
349 | | - } else |
350 | | - *org_i = NULL; |
351 | | - memset(capi, 0, sizeof(capi)); |
352 | | - strncpy(capi, tmp, sizeof(capi)-1); |
353 | | - } |
354 | | - |
355 | | - i = sscanf(capi, "%" MAX_CAPI_ONE_LEN_STR "[^(](%" MAX_CAPI_ONE_LEN_STR "[^)])", mode, cipher); |
356 | | - if (i == 2) |
357 | | - i = snprintf(dmcrypt_tmp, sizeof(dmcrypt_tmp), "%s-%s-%s", cipher, mode, iv); |
358 | | - else |
359 | | - i = snprintf(dmcrypt_tmp, sizeof(dmcrypt_tmp), "%s-%s", capi, iv); |
360 | | - if (i < 0 || (size_t)i >= sizeof(dmcrypt_tmp)) { |
361 | | - free(*org_i); |
362 | | - *org_i = NULL; |
363 | | - return -EINVAL; |
364 | | - } |
365 | | - |
366 | | - if (!(*org_c = strdup(dmcrypt_tmp))) { |
367 | | - free(*org_i); |
368 | | - *org_i = NULL; |
369 | | - return -ENOMEM; |
370 | | - } |
371 | | - |
372 | | - return 0; |
373 | | -} |
0 commit comments