test-lm-big.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80: */
  2. /*
  3. * Copyright (c) 2016 Red Hat, Inc.
  4. * Author: Nathaniel McCallum <npmccallum@redhat.com>
  5. *
  6. * This program is free software: you can redistribute it and/or modify it
  7. * under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation, either version 2.1 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program 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
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "test.h"
  20. #include <errno.h>
  21. #include <error.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. static const luksmeta_uuid_t UUID = {
  25. 0xd3, 0xd5, 0xf1, 0xe0, 0xa4, 0x6c, 0xbd, 0xf4,
  26. 0xca, 0x20, 0x30, 0x1f, 0xdd, 0xa0, 0xf7, 0xa8
  27. };
  28. static const uint8_t DATA[] = "DATADATADATADATADATADATADATADATADATADATADATA"
  29. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  30. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  31. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  32. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  33. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  34. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  35. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  36. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  37. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  38. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  39. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  40. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  41. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  42. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  43. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  44. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  45. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  46. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  47. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  48. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  49. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  50. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  51. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  52. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  53. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  54. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  55. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  56. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  57. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  58. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  59. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  60. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  61. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  62. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  63. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  64. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  65. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  66. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  67. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  68. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  69. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  70. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  71. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  72. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  73. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  74. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  75. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  76. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  77. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  78. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  79. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  80. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  81. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  82. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  83. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  84. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  85. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  86. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  87. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA"
  88. "DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA";
  89. int
  90. main(int argc, char *argv[])
  91. {
  92. uint8_t data[sizeof(DATA)] = {};
  93. struct crypt_device *cd = NULL;
  94. luksmeta_uuid_t uuid = {};
  95. uint32_t offset = 0;
  96. uint32_t length = 0;
  97. int r;
  98. crypt_free(test_format());
  99. cd = test_init();
  100. test_hole(cd, &offset, &length);
  101. /* Set the data. */
  102. r = luksmeta_save(cd, CRYPT_ANY_SLOT, UUID, DATA, sizeof(DATA));
  103. if (r < 0)
  104. error(EXIT_FAILURE, -r, "luksmeta_save()");
  105. assert(test_layout((range_t[]) {
  106. { 0, 1024 }, /* LUKS header */
  107. { 1024, offset - 1024, true }, /* Keyslot Area */
  108. { offset, 4096 }, /* luksmeta header */
  109. { offset + 4096, 4096 }, /* luksmeta slot 0 */
  110. { offset + 8192, 4096 }, /* luksmeta slot 0 (cont) */
  111. END(offset + 12288), /* Rest of the file */
  112. }));
  113. assert(luksmeta_load(cd, r, uuid, data, sizeof(data)) == sizeof(data));
  114. assert(memcmp(uuid, UUID, sizeof(UUID)) == 0);
  115. assert(memcmp(data, DATA, sizeof(DATA)) == 0);
  116. /* Delete the data. */
  117. assert(luksmeta_wipe(cd, r, UUID) == 0);
  118. assert(test_layout((range_t[]) {
  119. { 0, 1024 }, /* LUKS header */
  120. { 1024, offset - 1024, true }, /* Keyslot Area */
  121. { offset, 4096 }, /* luksmeta header */
  122. END(offset + 4096), /* Rest of the file */
  123. }));
  124. crypt_free(cd);
  125. unlink(filename);
  126. return 0;
  127. }