3
0

luks.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #include "volume_id_internal.h"
  21. #define SECTOR_SHIFT 9
  22. #define SECTOR_SIZE (1 << SECTOR_SHIFT)
  23. #define LUKS_CIPHERNAME_L 32
  24. #define LUKS_CIPHERMODE_L 32
  25. #define LUKS_HASHSPEC_L 32
  26. #define LUKS_DIGESTSIZE 20
  27. #define LUKS_SALTSIZE 32
  28. #define LUKS_NUMKEYS 8
  29. static const uint8_t LUKS_MAGIC[] = { 'L','U','K','S', 0xba, 0xbe };
  30. #define LUKS_MAGIC_L 6
  31. #define LUKS_PHDR_SIZE (sizeof(struct luks_phdr)/SECTOR_SIZE+1)
  32. #define UUID_STRING_L 40
  33. struct luks_phdr {
  34. uint8_t magic[LUKS_MAGIC_L];
  35. uint16_t version;
  36. uint8_t cipherName[LUKS_CIPHERNAME_L];
  37. uint8_t cipherMode[LUKS_CIPHERMODE_L];
  38. uint8_t hashSpec[LUKS_HASHSPEC_L];
  39. uint32_t payloadOffset;
  40. uint32_t keyBytes;
  41. uint8_t mkDigest[LUKS_DIGESTSIZE];
  42. uint8_t mkDigestSalt[LUKS_SALTSIZE];
  43. uint32_t mkDigestIterations;
  44. uint8_t uuid[UUID_STRING_L];
  45. struct {
  46. uint32_t active;
  47. uint32_t passwordIterations;
  48. uint8_t passwordSalt[LUKS_SALTSIZE];
  49. uint32_t keyMaterialOffset;
  50. uint32_t stripes;
  51. } keyblock[LUKS_NUMKEYS];
  52. };
  53. int volume_id_probe_luks(struct volume_id *id, uint64_t off)
  54. {
  55. struct luks_phdr *header;
  56. header = volume_id_get_buffer(id, off, LUKS_PHDR_SIZE);
  57. if (header == NULL)
  58. return -1;
  59. if (memcmp(header->magic, LUKS_MAGIC, LUKS_MAGIC_L))
  60. return -1;
  61. // volume_id_set_usage(id, VOLUME_ID_CRYPTO);
  62. volume_id_set_uuid(id, header->uuid, UUID_DCE_STRING);
  63. // id->type = "crypto_LUKS";
  64. return 0;
  65. }