Debian Codegraph @

src/lib/plugin_apis/crypto.api

raw
1 #include <glib.h>
2 #include <blockdev/utils.h>
3
4 #ifndef BD_CRYPTO_API
5 #define BD_CRYPTO_API
6
7 GQuark bd_crypto_error_quark (void) {
8 return g_quark_from_static_string ("g-bd-crypto-error-quark");
9 }
10
11 #define BD_CRYPTO_ERROR bd_crypto_error_quark ()
12 typedef enum {
13 BD_CRYPTO_ERROR_TECH_UNAVAIL,
14 BD_CRYPTO_ERROR_DEVICE,
15 BD_CRYPTO_ERROR_STATE,
16 BD_CRYPTO_ERROR_INVALID_SPEC,
17 BD_CRYPTO_ERROR_FORMAT_FAILED,
18 BD_CRYPTO_ERROR_RESIZE_FAILED,
19 BD_CRYPTO_ERROR_RESIZE_PERM,
20 BD_CRYPTO_ERROR_ADD_KEY,
21 BD_CRYPTO_ERROR_REMOVE_KEY,
22 BD_CRYPTO_ERROR_NO_KEY,
23 BD_CRYPTO_ERROR_KEY_SLOT,
24 BD_CRYPTO_ERROR_NSS_INIT_FAILED,
25 BD_CRYPTO_ERROR_CERT_DECODE,
26 BD_CRYPTO_ERROR_ESCROW_FAILED,
27 BD_CRYPTO_ERROR_INVALID_PARAMS,
28 BD_CRYPTO_ERROR_KEYRING,
29 BD_CRYPTO_ERROR_KEYFILE_FAILED,
30 BD_CRYPTO_ERROR_INVALID_CONTEXT,
31 } BDCryptoError;
32
33 typedef enum {
34 BD_CRYPTO_TECH_LUKS = 0,
35 BD_CRYPTO_TECH_TRUECRYPT,
36 BD_CRYPTO_TECH_ESCROW,
37 BD_CRYPTO_TECH_INTEGRITY,
38 BD_CRYPTO_TECH_BITLK,
39 BD_CRYPTO_TECH_KEYRING,
40 BD_CRYPTO_TECH_FVAULT2,
41 BD_CRYPTO_TECH_SED_OPAL,
42 } BDCryptoTech;
43
44 typedef enum {
45 BD_CRYPTO_TECH_MODE_CREATE = 1 << 0,
46 BD_CRYPTO_TECH_MODE_OPEN_CLOSE = 1 << 1,
47 BD_CRYPTO_TECH_MODE_QUERY = 1 << 2,
48 BD_CRYPTO_TECH_MODE_ADD_KEY = 1 << 3,
49 BD_CRYPTO_TECH_MODE_REMOVE_KEY = 1 << 4,
50 BD_CRYPTO_TECH_MODE_RESIZE = 1 << 5,
51 BD_CRYPTO_TECH_MODE_SUSPEND_RESUME = 1 << 6,
52 BD_CRYPTO_TECH_MODE_BACKUP_RESTORE = 1 << 7,
53 BD_CRYPTO_TECH_MODE_MODIFY = 1 << 8,
54 } BDCryptoTechMode;
55
56 typedef enum {
57 BD_CRYPTO_LUKS_VERSION_LUKS1 = 0,
58 BD_CRYPTO_LUKS_VERSION_LUKS2,
59 } BDCryptoLUKSVersion;
60
61 #define BD_CRYPTO_TYPE_LUKS_PBKDF (bd_crypto_luks_pbkdf_get_type ())
62 GType bd_crypto_luks_pbkdf_get_type();
63
64 /**
65 * BDCryptoLUKSPBKDF
66 * @type: PBKDF algorithm
67 * @hash: hash for LUKS header or NULL
68 * @max_memory_kb: requested memory cost (in KiB) or 0 for default (benchmark)
69 * @iterations: requested iterations or 0 for default (benchmark)
70 * @time_ms: requested time cost or 0 for default (benchmark)
71 * @parallel_threads: requested parallel cost (threads) or 0 for default (benchmark)
72 */
73 typedef struct BDCryptoLUKSPBKDF {
74 gchar *type;
75 gchar *hash;
76 guint32 max_memory_kb;
77 guint32 iterations;
78 guint32 time_ms;
79 guint32 parallel_threads;
80 } BDCryptoLUKSPBKDF;
81
82 /**
83 * bd_crypto_luks_pbkdf_copy: (skip)
84 * @pbkdf: (nullable): %BDCryptoLUKSPBKDF to copy
85 *
86 * Creates a new copy of @pbkdf.
87 */
88 BDCryptoLUKSPBKDF* bd_crypto_luks_pbkdf_copy (BDCryptoLUKSPBKDF *pbkdf) {
89 if (pbkdf == NULL)
90 return NULL;
91
92 BDCryptoLUKSPBKDF *new_pbkdf = g_new0 (BDCryptoLUKSPBKDF, 1);
93 new_pbkdf->type = g_strdup (pbkdf->type);
94 new_pbkdf->hash = g_strdup (pbkdf->hash);
95 new_pbkdf->max_memory_kb = pbkdf->max_memory_kb;
96 new_pbkdf->iterations = pbkdf->iterations;
97 new_pbkdf->time_ms = pbkdf->time_ms;
98 new_pbkdf->parallel_threads = pbkdf->parallel_threads;
99
100 return new_pbkdf;
101 }
102
103 /**
104 * bd_crypto_luks_pbkdf_free: (skip)
105 * @pbkdf: (nullable): %BDCryptoLUKSPBKDF to free
106 *
107 * Frees @pbkdf.
108 */
109 void bd_crypto_luks_pbkdf_free (BDCryptoLUKSPBKDF *pbkdf) {
110 if (pbkdf == NULL)
111 return;
112
113 g_free (pbkdf->type);
114 g_free (pbkdf->hash);
115 g_free (pbkdf);
116 }
117
118 /**
119 * bd_crypto_luks_pbkdf_new: (constructor)
120 * @type: (nullable): PBKDF algorithm
121 * @hash: (nullable): hash for LUKS header or NULL for default
122 * @max_memory_kb: requested memory cost (in KiB) or 0 for default (benchmark)
123 * @iterations: requested iterations or 0 for default (benchmark)
124 * @time_ms: requested time cost or 0 for default (benchmark)
125 * @parallel_threads: requested parallel cost (threads) or 0 for default (benchmark)
126 *
127 * Returns: (transfer full): a new pbkdf argument
128 */
129 BDCryptoLUKSPBKDF* bd_crypto_luks_pbkdf_new (const gchar *type, const gchar *hash, guint32 max_memory_kb, guint32 iterations, guint32 time_ms, guint32 parallel_threads) {
130 BDCryptoLUKSPBKDF *ret = g_new0 (BDCryptoLUKSPBKDF, 1);
131 ret->type = g_strdup (type);
132 ret->hash = g_strdup (hash);
133 ret->max_memory_kb = max_memory_kb;
134 ret->iterations = iterations;
135 ret->time_ms = time_ms;
136 ret->parallel_threads = parallel_threads;
137
138 return ret;
139 }
140
141 GType bd_crypto_luks_pbkdf_get_type () {
142 static GType type = 0;
143
144 if (G_UNLIKELY(type == 0)) {
145 type = g_boxed_type_register_static("BDCryptoLUKSPBKDF",
146 (GBoxedCopyFunc) bd_crypto_luks_pbkdf_copy,
147 (GBoxedFreeFunc) bd_crypto_luks_pbkdf_free);
148 }
149
150 return type;
151 }
152
153 #define BD_CRYPTO_TYPE_LUKS_EXTRA (bd_crypto_luks_extra_get_type ())
154 GType bd_crypto_luks_extra_get_type();
155
156 /**
157 * BDCryptoLUKSExtra:
158 * @data_alignment: data alignment in sectors, 0 for default/auto detection
159 * @data_device: detached encrypted data device or NULL
160 * @integrity: integrity algorithm (e.g. "hmac-sha256") or NULL for no integrity support
161 * Note: this field is valid only for LUKS 2
162 * @sector_size: encryption sector size, 0 for default (512)
163 * Note: this field is valid only for LUKS 2
164 * @label: LUKS header label or NULL
165 * Note: this field is valid only for LUKS 2
166 * @subsystem: LUKS header subsystem or NULL
167 * Note: this field is valid only for LUKS 2
168 * @pbkdf: key derivation function specification or NULL for default
169 * Note: this field is valid only for LUKS 2
170 */
171 typedef struct BDCryptoLUKSExtra {
172 guint64 data_alignment;
173 gchar *data_device;
174 gchar *integrity;
175 guint32 sector_size;
176 gchar *label;
177 gchar *subsystem;
178 BDCryptoLUKSPBKDF *pbkdf;
179 } BDCryptoLUKSExtra;
180
181 /**
182 * bd_crypto_luks_extra_copy: (skip)
183 * @extra: (nullable): %BDCryptoLUKSExtra to copy
184 *
185 * Creates a new copy of @extra.
186 */
187 BDCryptoLUKSExtra* bd_crypto_luks_extra_copy (BDCryptoLUKSExtra *extra) {
188 if (extra == NULL)
189 return NULL;
190
191 BDCryptoLUKSExtra *new_extra = g_new0 (BDCryptoLUKSExtra, 1);
192
193 new_extra->integrity = g_strdup (extra->integrity);
194 new_extra->data_alignment = extra->data_alignment;
195 new_extra->data_device = g_strdup (extra->data_device);
196 new_extra->sector_size = extra->sector_size;
197 new_extra->label = g_strdup (extra->label);
198 new_extra->subsystem = g_strdup (extra->subsystem);
199 new_extra->pbkdf = bd_crypto_luks_pbkdf_copy (extra->pbkdf);
200
201 return new_extra;
202 }
203
204 /**
205 * bd_crypto_luks_extra_free: (skip)
206 * @extra: (nullable): %BDCryptoLUKSExtra to free
207 *
208 * Frees @extra.
209 */
210 void bd_crypto_luks_extra_free (BDCryptoLUKSExtra *extra) {
211 if (extra == NULL)
212 return;
213
214 g_free (extra->integrity);
215 g_free (extra->data_device);
216 g_free (extra->label);
217 g_free (extra->subsystem);
218 bd_crypto_luks_pbkdf_free (extra->pbkdf);
219 g_free (extra);
220 }
221
222 /**
223 * bd_crypto_luks_extra_new: (constructor)
224 * @data_alignment: data alignment in sectors, 0 for default/auto detection
225 * @data_device: (nullable): detached encrypted data device or NULL
226 * @integrity: (nullable): integrity algorithm (e.g. "hmac-sha256") or NULL for no integrity support
227 * @sector_size: encryption sector size, 0 for default (512)
228 * @label: (nullable): LUKS header label or NULL
229 * @subsystem: (nullable): LUKS header subsystem or NULL
230 * @pbkdf: (nullable): key derivation function specification or NULL for default
231 *
232 * Returns: (transfer full): a new LUKS extra argument
233 */
234 BDCryptoLUKSExtra* bd_crypto_luks_extra_new (guint64 data_alignment, const gchar *data_device, const gchar *integrity, guint32 sector_size, const gchar *label, const gchar *subsystem, BDCryptoLUKSPBKDF *pbkdf) {
235 BDCryptoLUKSExtra *ret = g_new0 (BDCryptoLUKSExtra, 1);
236 ret->integrity = g_strdup (integrity);
237 ret->data_alignment = data_alignment;
238 ret->data_device = g_strdup (data_device);
239 ret->sector_size = sector_size;
240 ret->label = g_strdup (label);
241 ret->subsystem = g_strdup (subsystem);
242 ret->pbkdf = bd_crypto_luks_pbkdf_copy (pbkdf);
243
244 return ret;
245 }
246
247 GType bd_crypto_luks_extra_get_type () {
248 static GType type = 0;
249
250 if (G_UNLIKELY(type == 0)) {
251 type = g_boxed_type_register_static("BDCryptoLUKSExtra",
252 (GBoxedCopyFunc) bd_crypto_luks_extra_copy,
253 (GBoxedFreeFunc) bd_crypto_luks_extra_free);
254 }
255
256 return type;
257 }
258
259 #define BD_CRYPTO_TYPE_INTEGRITY_EXTRA (bd_crypto_integrity_extra_get_type ())
260 GType bd_crypto_integrity_extra_get_type();
261
262 /**
263 * BDCryptoIntegrityExtra:
264 * @sector_size: integrity sector size
265 * @journal_size: size of journal in bytes
266 * @journal_watermark: journal flush watermark in percents; in bitmap mode sectors-per-bit
267 * @journal_commit_time: journal commit time (or bitmap flush time) in ms
268 * @interleave_sectors: number of interleave sectors (power of two)
269 * @tag_size: tag size per-sector in bytes
270 * @buffer_sectors: number of sectors in one buffer
271 */
272 typedef struct BDCryptoIntegrityExtra {
273 guint32 sector_size;
274 guint64 journal_size;
275 guint journal_watermark;
276 guint journal_commit_time;
277 guint32 interleave_sectors;
278 guint32 tag_size;
279 guint32 buffer_sectors;
280 } BDCryptoIntegrityExtra;
281
282 /**
283 * bd_crypto_integrity_extra_copy: (skip)
284 * @extra: (nullable): %BDCryptoIntegrityExtra to copy
285 *
286 * Creates a new copy of @extra.
287 */
288 BDCryptoIntegrityExtra* bd_crypto_integrity_extra_copy (BDCryptoIntegrityExtra *extra) {
289 if (extra == NULL)
290 return NULL;
291
292 BDCryptoIntegrityExtra *new_extra = g_new0 (BDCryptoIntegrityExtra, 1);
293
294 new_extra->sector_size = extra->sector_size;
295 new_extra->journal_size = extra->journal_size;
296 new_extra->journal_watermark = extra->journal_watermark;
297 new_extra->journal_commit_time = extra->journal_commit_time;
298 new_extra->interleave_sectors = extra->interleave_sectors;
299 new_extra->tag_size = extra->tag_size;
300 new_extra->buffer_sectors = extra->buffer_sectors;
301
302 return new_extra;
303 }
304
305 /**
306 * bd_crypto_integrity_extra_free: (skip)
307 * @extra: (nullable): %BDCryptoIntegrityExtra to free
308 *
309 * Frees @extra.
310 */
311 void bd_crypto_integrity_extra_free (BDCryptoIntegrityExtra *extra) {
312 if (extra == NULL)
313 return;
314
315 g_free (extra);
316 }
317
318 /**
319 * bd_crypto_integrity_extra_new: (constructor)
320 * @sector_size: integrity sector size, 0 for default (512)
321 * @journal_size: size of journal in bytes
322 * @journal_watermark: journal flush watermark in percents; in bitmap mode sectors-per-bit
323 * @journal_commit_time: journal commit time (or bitmap flush time) in ms
324 * @interleave_sectors: number of interleave sectors (power of two)
325 * @tag_size: tag size per-sector in bytes
326 * @buffer_sectors: number of sectors in one buffer
327 *
328 * Returns: (transfer full): a new Integrity extra argument
329 */
330 BDCryptoIntegrityExtra* bd_crypto_integrity_extra_new (guint32 sector_size, guint64 journal_size, guint journal_watermark, guint journal_commit_time, guint64 interleave_sectors, guint64 tag_size, guint64 buffer_sectors) {
331 BDCryptoIntegrityExtra *ret = g_new0 (BDCryptoIntegrityExtra, 1);
332 ret->sector_size = sector_size;
333 ret->journal_size = journal_size;
334 ret->journal_watermark = journal_watermark;
335 ret->journal_commit_time = journal_commit_time;
336 ret->interleave_sectors = interleave_sectors;
337 ret->tag_size = tag_size;
338 ret->buffer_sectors = buffer_sectors;
339
340 return ret;
341 }
342
343 GType bd_crypto_integrity_extra_get_type () {
344 static GType type = 0;
345
346 if (G_UNLIKELY(type == 0)) {
347 type = g_boxed_type_register_static("BDCryptoIntegrityExtra",
348 (GBoxedCopyFunc) bd_crypto_integrity_extra_copy,
349 (GBoxedFreeFunc) bd_crypto_integrity_extra_free);
350 }
351
352 return type;
353 }
354
355 typedef enum {
356 BD_CRYPTO_INTEGRITY_OPEN_NO_JOURNAL = 1 << 0,
357 BD_CRYPTO_INTEGRITY_OPEN_RECOVERY = 1 << 1,
358 BD_CRYPTO_INTEGRITY_OPEN_NO_JOURNAL_BITMAP = 1 << 2,
359 BD_CRYPTO_INTEGRITY_OPEN_RECALCULATE = 1 << 3,
360 BD_CRYPTO_INTEGRITY_OPEN_RECALCULATE_RESET = 1 << 4,
361 BD_CRYPTO_INTEGRITY_OPEN_ALLOW_DISCARDS = 1 << 5,
362 } BDCryptoIntegrityOpenFlags;
363
364 typedef enum {
365 BD_CRYPTO_OPEN_ALLOW_DISCARDS = 1 << 0,
366 BD_CRYPTO_OPEN_READONLY = 1 << 1,
367 } BDCryptoOpenFlags;
368
369 #define BD_CRYPTO_TYPE_LUKS_INFO (bd_crypto_luks_info_get_type ())
370 GType bd_crypto_luks_info_get_type();
371
372 /**
373 * BDCryptoLUKSHWEncryptionType:
374 * @BD_CRYPTO_LUKS_HW_ENCRYPTION_UNKNOWN: used for unknown/unsupported hardware encryption or when
375 * error was detected when getting the information
376 * @BD_CRYPTO_LUKS_HW_ENCRYPTION_SW_ONLY: hardware encryption is not configured on this device
377 * @BD_CRYPTO_LUKS_HW_ENCRYPTION_OPAL_HW_ONLY: only OPAL hardware encryption is configured on this device
378 * @BD_CRYPTO_LUKS_HW_ENCRYPTION_OPAL_HW_AND_SW: both OPAL hardware encryption and software encryption
379 * (using LUKS/dm-crypt) is configured on this device
380 */
381 typedef enum {
382 BD_CRYPTO_LUKS_HW_ENCRYPTION_UNKNOWN = 0,
383 BD_CRYPTO_LUKS_HW_ENCRYPTION_SW_ONLY,
384 BD_CRYPTO_LUKS_HW_ENCRYPTION_OPAL_HW_ONLY,
385 BD_CRYPTO_LUKS_HW_ENCRYPTION_OPAL_HW_AND_SW,
386 } BDCryptoLUKSHWEncryptionType;
387
388 typedef enum {
389 BD_CRYPTO_LUKS_ACTIVATE_ALLOW_DISCARDS = 1 << 0,
390 BD_CRYPTO_LUKS_ACTIVATE_SAME_CPU_CRYPT = 1 << 1,
391 BD_CRYPTO_LUKS_ACTIVATE_SUBMIT_FROM_CRYPT_CPUS = 1 << 2,
392 BD_CRYPTO_LUKS_ACTIVATE_NO_JOURNAL = 1 << 3,
393 BD_CRYPTO_LUKS_ACTIVATE_NO_READ_WORKQUEUE = 1 << 4,
394 BD_CRYPTO_LUKS_ACTIVATE_NO_WRITE_WORKQUEUE = 1 << 5,
395 BD_CRYPTO_LUKS_ACTIVATE_HIGH_PRIORITY = 1 << 6,
396 } BDCryptoLUKSPersistentFlags;
397
398 /**
399 * BDCryptoLUKSInfo:
400 * @version: LUKS version
401 * @cipher: used cipher (e.g. "aes")
402 * @mode: used cipher mode (e.g. "xts-plain")
403 * @uuid: UUID of the LUKS device
404 * @backing_device: name of the underlying block device
405 * @sector_size: size (in bytes) of encryption sector
406 * Note: sector size is valid only for LUKS 2
407 * @metadata_size: LUKS metadata size
408 * @label: label of the LUKS device (valid only for LUKS 2)
409 * @subsystem: subsystem of the LUKS device (valid only for LUKS 2)
410 * @hw_encryption: hardware encryption type
411 */
412 typedef struct BDCryptoLUKSInfo {
413 BDCryptoLUKSVersion version;
414 gchar *cipher;
415 gchar *mode;
416 gchar *uuid;
417 gchar *backing_device;
418 guint32 sector_size;
419 guint64 metadata_size;
420 gchar *label;
421 gchar *subsystem;
422 BDCryptoLUKSHWEncryptionType hw_encryption;
423 } BDCryptoLUKSInfo;
424
425 /**
426 * bd_crypto_luks_info_free: (skip)
427 * @info: (nullable): %BDCryptoLUKSInfo to free
428 *
429 * Frees @info.
430 */
431 void bd_crypto_luks_info_free (BDCryptoLUKSInfo *info) {
432 if (info == NULL)
433 return;
434
435 g_free (info->cipher);
436 g_free (info->mode);
437 g_free (info->uuid);
438 g_free (info->backing_device);
439 g_free (info->label);
440 g_free (info->subsystem);
441 g_free (info);
442 }
443
444 /**
445 * bd_crypto_luks_info_copy: (skip)
446 * @info: (nullable): %BDCryptoLUKSInfo to copy
447 *
448 * Creates a new copy of @info.
449 */
450 BDCryptoLUKSInfo* bd_crypto_luks_info_copy (BDCryptoLUKSInfo *info) {
451 if (info == NULL)
452 return NULL;
453
454 BDCryptoLUKSInfo *new_info = g_new0 (BDCryptoLUKSInfo, 1);
455
456 new_info->version = info->version;
457 new_info->cipher = g_strdup (info->cipher);
458 new_info->mode = g_strdup (info->mode);
459 new_info->uuid = g_strdup (info->uuid);
460 new_info->backing_device = g_strdup (info->backing_device);
461 new_info->sector_size = info->sector_size;
462 new_info->metadata_size = info->metadata_size;
463 new_info->label = g_strdup (info->label);
464 new_info->subsystem = g_strdup (info->subsystem);
465 new_info->hw_encryption = info->hw_encryption;
466
467 return new_info;
468 }
469
470 GType bd_crypto_luks_info_get_type () {
471 static GType type = 0;
472
473 if (G_UNLIKELY(type == 0)) {
474 type = g_boxed_type_register_static("BDCryptoLUKSInfo",
475 (GBoxedCopyFunc) bd_crypto_luks_info_copy,
476 (GBoxedFreeFunc) bd_crypto_luks_info_free);
477 }
478
479 return type;
480 }
481
482 #define BD_CRYPTO_TYPE_BITLK_INFO (bd_crypto_bitlk_info_get_type ())
483 GType bd_crypto_bitlk_info_get_type();
484
485 /**
486 * BDCryptoBITLKInfo:
487 * @cipher: used cipher (e.g. "aes")
488 * @mode: used cipher mode (e.g. "xts-plain")
489 * @uuid: UUID of the BITLK device
490 * @backing_device: name of the underlying block device
491 * @sector_size: size (in bytes) of encryption sector
492 */
493 typedef struct BDCryptoBITLKInfo {
494 gchar *cipher;
495 gchar *mode;
496 gchar *uuid;
497 gchar *backing_device;
498 guint32 sector_size;
499 } BDCryptoBITLKInfo;
500
501 /**
502 * bd_crypto_bitlk_info_free: (skip)
503 * @info: (nullable): %BDCryptoBITLKInfo to free
504 *
505 * Frees @info.
506 */
507 void bd_crypto_bitlk_info_free (BDCryptoBITLKInfo *info) {
508 if (info == NULL)
509 return;
510
511 g_free (info->cipher);
512 g_free (info->mode);
513 g_free (info->uuid);
514 g_free (info->backing_device);
515 g_free (info);
516 }
517
518 /**
519 * bd_crypto_bitlk_info_copy: (skip)
520 * @info: (nullable): %BDCryptoBITLKInfo to copy
521 *
522 * Creates a new copy of @info.
523 */
524 BDCryptoBITLKInfo* bd_crypto_bitlk_info_copy (BDCryptoBITLKInfo *info) {
525 if (info == NULL)
526 return NULL;
527
528 BDCryptoBITLKInfo *new_info = g_new0 (BDCryptoBITLKInfo, 1);
529
530 new_info->cipher = g_strdup (info->cipher);
531 new_info->mode = g_strdup (info->mode);
532 new_info->uuid = g_strdup (info->uuid);
533 new_info->backing_device = g_strdup (info->backing_device);
534 new_info->sector_size = info->sector_size;
535
536 return new_info;
537 }
538
539 GType bd_crypto_bitlk_info_get_type () {
540 static GType type = 0;
541
542 if (G_UNLIKELY(type == 0)) {
543 type = g_boxed_type_register_static("BDCryptoBITLKInfo",
544 (GBoxedCopyFunc) bd_crypto_bitlk_info_copy,
545 (GBoxedFreeFunc) bd_crypto_bitlk_info_free);
546 }
547
548 return type;
549 }
550
551 #define BD_CRYPTO_TYPE_INTEGRITY_INFO (bd_crypto_integrity_info_get_type ())
552 GType bd_crypto_integrity_info_get_type();
553
554 /**
555 * BDCryptoIntegrityInfo:
556 * @algorithm: integrity algorithm
557 * @key_size: integrity key size in bytes
558 * @sector_size: sector size in bytes
559 * @tag_size: tag size per-sector in bytes
560 * @interleave_sectors: number of interleave sectors
561 * @journal_size: size of journal in bytes
562 * @journal_crypt: journal encryption algorithm
563 * @journal_integrity: journal integrity algorithm
564 */
565 typedef struct BDCryptoIntegrityInfo {
566 gchar *algorithm;
567 guint32 key_size;
568 guint32 sector_size;
569 guint32 tag_size;
570 guint32 interleave_sectors;
571 guint64 journal_size;
572 gchar *journal_crypt;
573 gchar *journal_integrity;
574 } BDCryptoIntegrityInfo;
575
576 /**
577 * bd_crypto_integrity_info_free: (skip)
578 * @info: (nullable): %BDCryptoIntegrityInfo to free
579 *
580 * Frees @info.
581 */
582 void bd_crypto_integrity_info_free (BDCryptoIntegrityInfo *info) {
583 if (info == NULL)
584 return;
585
586 g_free (info->algorithm);
587 g_free (info->journal_crypt);
588 g_free (info->journal_integrity);
589 g_free (info);
590 }
591
592 /**
593 * bd_crypto_integrity_info_copy: (skip)
594 * @info: (nullable): %BDCryptoIntegrityInfo to copy
595 *
596 * Creates a new copy of @info.
597 */
598 BDCryptoIntegrityInfo* bd_crypto_integrity_info_copy (BDCryptoIntegrityInfo *info) {
599 if (info == NULL)
600 return NULL;
601
602 BDCryptoIntegrityInfo *new_info = g_new0 (BDCryptoIntegrityInfo, 1);
603
604 new_info->algorithm = g_strdup (info->algorithm);
605 new_info->key_size = info->key_size;
606 new_info->sector_size = info->sector_size;
607 new_info->tag_size = info->tag_size;
608 new_info->interleave_sectors = info->interleave_sectors;
609 new_info->journal_size = info->journal_size;
610 new_info->journal_crypt = g_strdup (info->journal_crypt);
611 new_info->journal_integrity = g_strdup (info->journal_integrity);
612
613 return new_info;
614 }
615
616 GType bd_crypto_integrity_info_get_type () {
617 static GType type = 0;
618
619 if (G_UNLIKELY(type == 0)) {
620 type = g_boxed_type_register_static("BDCryptoIntegrityInfo",
621 (GBoxedCopyFunc) bd_crypto_integrity_info_copy,
622 (GBoxedFreeFunc) bd_crypto_integrity_info_free);
623 }
624
625 return type;
626 }
627
628 #define BD_CRYPTO_TYPE_LUKS_TOKEN_INFO (bd_crypto_luks_token_info_get_type ())
629 GType bd_crypto_luks_token_info_get_type();
630
631 /**
632 * BDCryptoLUKSTokenInfo:
633 * @id: ID of the token
634 * @type: type of the token
635 * @keyslot: keyslot this token is assigned to or -1 for inactive/unassigned tokens
636 */
637 typedef struct BDCryptoLUKSTokenInfo {
638 guint id;
639 gchar *type;
640 gint keyslot;
641 } BDCryptoLUKSTokenInfo;
642
643 /**
644 * bd_crypto_luks_token_info_free: (skip)
645 * @info: (nullable): %BDCryptoLUKSTokenInfo to free
646 *
647 * Frees @info.
648 */
649 void bd_crypto_luks_token_info_free (BDCryptoLUKSTokenInfo *info) {
650 if (info == NULL)
651 return;
652
653 g_free (info->type);
654 g_free (info);
655 }
656
657 /**
658 * bd_crypto_luks_token_info_copy: (skip)
659 * @info: (nullable): %BDCryptoLUKSTokenInfo to copy
660 *
661 * Creates a new copy of @info.
662 */
663 BDCryptoLUKSTokenInfo* bd_crypto_luks_token_info_copy (BDCryptoLUKSTokenInfo *info) {
664 if (info == NULL)
665 return NULL;
666
667 BDCryptoLUKSTokenInfo *new_info = g_new0 (BDCryptoLUKSTokenInfo, 1);
668
669 new_info->id = info->id;
670 new_info->type = g_strdup (info->type);
671 new_info->keyslot = info->keyslot;
672
673 return new_info;
674 }
675
676 GType bd_crypto_luks_token_info_get_type () {
677 static GType type = 0;
678
679 if (G_UNLIKELY(type == 0)) {
680 type = g_boxed_type_register_static("BDCryptoLUKSTokenInfo",
681 (GBoxedCopyFunc) bd_crypto_luks_token_info_copy,
682 (GBoxedFreeFunc) bd_crypto_luks_token_info_free);
683 }
684
685 return type;
686 }
687
688 /**
689 * bd_crypto_is_tech_avail:
690 * @tech: the queried tech
691 * @mode: a bit mask of queried modes of operation (#BDCryptoTechMode) for @tech
692 * @error: (out) (optional): place to store error (details about why the @tech-@mode combination is not available)
693 *
694 * Returns: whether the @tech-@mode combination is available -- supported by the
695 * plugin implementation and having all the runtime dependencies available
696 */
697 gboolean bd_crypto_is_tech_avail (BDCryptoTech tech, guint64 mode, GError **error);
698
699 /**
700 * bd_crypto_generate_backup_passphrase:
701 * @error: (out) (optional): place to store error (if any)
702 *
703 * Returns: A newly generated %BD_CRYPTO_BACKUP_PASSPHRASE_LENGTH-long passphrase.
704 *
705 * See %BD_CRYPTO_BACKUP_PASSPHRASE_CHARSET for the definition of the charset used for the passphrase.
706 *
707 * Tech category: always available
708 */
709 gchar* bd_crypto_generate_backup_passphrase(GError **error);
710
711 /**
712 * bd_crypto_device_is_luks:
713 * @device: the queried device
714 * @error: (out) (optional): place to store error (if any)
715 *
716 * Returns: %TRUE if the given @device is a LUKS device or %FALSE if not or
717 * failed to determine (the @error) is populated with the error in such
718 * cases)
719 *
720 * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_QUERY
721 */
722 gboolean bd_crypto_device_is_luks (const gchar *device, GError **error);
723
724 /**
725 * bd_crypto_luks_status:
726 * @luks_device: the queried LUKS device
727 * @error: (out) (optional): place to store error (if any)
728 *
729 * Returns: (transfer none): one of "invalid", "inactive", "active" or "busy" or
730 * %NULL if failed to determine (@error is populated with the error in
731 * such cases)
732 *
733 * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_QUERY
734 */
735 const gchar* bd_crypto_luks_status (const gchar *luks_device, GError **error);
736
737
738 typedef enum {
739 BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_NONE = 0,
740 BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_PASSPHRASE,
741 BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_KEYFILE,
742 BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_KEYRING,
743 BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_VOLUME_KEY,
744 } BDCryptoKeyslotContextType;
745
746 struct _BDCryptoKeyslotContext {
747 BDCryptoKeyslotContextType type;
748
749 union {
750 struct {
751 guint8 *pass_data;
752 gsize data_len;
753 } passphrase;
754
755 struct {
756 gchar *keyfile;
757 guint64 keyfile_offset;
758 gsize key_size;
759 } keyfile;
760
761 struct {
762 gchar *key_desc;
763 } keyring;
764
765 struct {
766 guint8 *volume_key;
767 gsize volume_key_size;
768 } volume_key;
769 } u;
770 };
771 typedef struct _BDCryptoKeyslotContext BDCryptoKeyslotContext;
772
773 #define BD_CRYPTO_TYPE_KEYSLOT_CONTEXT (bd_crypto_keyslot_context_get_type ())
774 GType bd_crypto_keyslot_context_get_type();
775
776 /**
777 * bd_crypto_keyslot_context_free: (skip)
778 * @context: (nullable): %BDCryptoKeyslotContext to free
779 *
780 * Frees @context.
781 */
782 void bd_crypto_keyslot_context_free (BDCryptoKeyslotContext *context) {
783 if (context == NULL)
784 return;
785
786 if (context->type == BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_PASSPHRASE)
787 g_free (context->u.passphrase.pass_data);
788 else if (context->type == BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_KEYFILE)
789 g_free (context->u.keyfile.keyfile);
790 else if (context->type == BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_KEYRING)
791 g_free (context->u.keyring.key_desc);
792 else if (context->type == BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_VOLUME_KEY)
793 g_free (context->u.volume_key.volume_key);
794
795 g_free (context);
796 }
797
798 /**
799 * bd_crypto_keyslot_context_copy: (skip)
800 * @context: (nullable): %BDCryptoKeyslotContext to copy
801 *
802 * Creates a new copy of @context.
803 */
804 BDCryptoKeyslotContext* bd_crypto_keyslot_context_copy (BDCryptoKeyslotContext *context) {
805 if (context == NULL)
806 return NULL;
807
808 BDCryptoKeyslotContext *new_context = g_new0 (BDCryptoKeyslotContext, 1);
809 new_context->type = context->type;
810
811 if (context->type == BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_PASSPHRASE) {
812 new_context->u.passphrase.pass_data = g_new0 (guint8, context->u.passphrase.data_len);
813 memcpy (new_context->u.passphrase.pass_data, context->u.passphrase.pass_data, context->u.passphrase.data_len);
814 new_context->u.passphrase.data_len = context->u.passphrase.data_len;
815 } else if (context->type == BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_KEYFILE) {
816 new_context->u.keyfile.keyfile = g_strdup (context->u.keyfile.keyfile);
817 new_context->u.keyfile.keyfile_offset = context->u.keyfile.keyfile_offset;
818 new_context->u.keyfile.key_size = context->u.keyfile.key_size;
819 } else if (context->type == BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_KEYRING)
820 new_context->u.keyring.key_desc = g_strdup (context->u.keyring.key_desc);
821 else if (context->type == BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_VOLUME_KEY) {
822 new_context->u.volume_key.volume_key = g_new0 (guint8, context->u.volume_key.volume_key_size);
823 memcpy (new_context->u.volume_key.volume_key, context->u.volume_key.volume_key, context->u.volume_key.volume_key_size);
824 new_context->u.volume_key.volume_key_size = context->u.volume_key.volume_key_size;
825 }
826
827 return new_context;
828 }
829
830 GType bd_crypto_keyslot_context_get_type () {
831 static GType type = 0;
832
833 if (G_UNLIKELY(type == 0)) {
834 type = g_boxed_type_register_static("BDCryptoKeyslotContext",
835 (GBoxedCopyFunc) bd_crypto_keyslot_context_copy,
836 (GBoxedFreeFunc) bd_crypto_keyslot_context_free);
837 }
838
839 return type;
840 }
841
842 /**
843 * bd_crypto_keyslot_context_new_passphrase:
844 * @pass_data: (array length=data_len): a passphrase for the new context (may contain arbitrary binary data)
845 * @data_len: length of the @pass_data buffer
846 * @error: (out) (optional): place to store error (if any)
847 *
848 * Returns (transfer full): new %BDCryptoKeyslotContext initialized by passphrase or
849 * %NULL in case of error
850 *
851 * Tech category: always available
852 */
853 BDCryptoKeyslotContext* bd_crypto_keyslot_context_new_passphrase (const guint8 *pass_data, gsize data_len, GError **error);
854
855 /**
856 * bd_crypto_keyslot_context_new_keyfile:
857 * @keyfile: a key file for the new context
858 * @keyfile_offset: number of bytes to skip at start of @keyfile
859 * @key_size: number of bytes to read from @keyfile or 0 for unlimited
860 * @error: (out) (optional): place to store error (if any)
861 *
862 * Returns (transfer full): new %BDCryptoKeyslotContext initialized by key file or
863 * %NULL in case of error
864 *
865 * Tech category: always available
866 */
867 BDCryptoKeyslotContext* bd_crypto_keyslot_context_new_keyfile (const gchar *keyfile, guint64 keyfile_offset, gsize key_size, GError **error);
868
869 /**
870 * bd_crypto_keyslot_context_new_keyring:
871 * @key_desc: kernel keyring key description
872 * @error: (out) (optional): place to store error (if any)
873 *
874 * Returns (transfer full): new %BDCryptoKeyslotContext initialized by @key_desc or
875 * %NULL in case of error
876 *
877 * Note: Keyslot passphrase must be stored in 'user' key type and the key has to be reachable
878 * by process context on behalf of which this function is called.
879 *
880 * Tech category: always available
881 */
882 BDCryptoKeyslotContext* bd_crypto_keyslot_context_new_keyring (const gchar *key_desc, GError **error);
883
884 /**
885 * bd_crypto_keyslot_context_new_volume_key:
886 * @volume_key: (array length=volume_key_size): a volume key for the new context (may contain arbitrary binary data)
887 * @volume_key_size: length of the @volume_key_size buffer
888 * @error: (out) (optional): place to store error (if any)
889 *
890 * Returns (transfer full): new %BDCryptoKeyslotContext initialized by volume key or
891 * %NULL in case of error
892 *
893 * Tech category: always available
894 */
895 BDCryptoKeyslotContext* bd_crypto_keyslot_context_new_volume_key (const guint8 *volume_key, gsize volume_key_size, GError **error);
896
897 /**
898 * bd_crypto_luks_format:
899 * @device: a device to format as LUKS
900 * @cipher: (nullable): cipher specification (type-mode, e.g. "aes-xts-plain64") or %NULL to use the default
901 * @key_size: size of the volume key in bits or 0 to use the default
902 * @context: key slot context (passphrase/keyfile/token...) for this LUKS device
903 * @min_entropy: minimum random data entropy (in bits) required to format @device as LUKS
904 * @luks_version: whether to use LUKS v1 or LUKS v2
905 * @extra: (nullable): extra arguments for LUKS format creation
906 * @error: (out) (optional): place to store error (if any)
907 *
908 * Formats the given @device as LUKS according to the other parameters given. If
909 * @min_entropy is specified (greater than 0), the function waits for enough
910 * entropy to be available in the random data pool (WHICH MAY POTENTIALLY TAKE
911 * FOREVER).
912 *
913 * Supported @context types for this function: passphrase, key file
914 *
915 * Returns: whether the given @device was successfully formatted as LUKS or not
916 * (the @error) contains the error in such cases)
917 *
918 * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_CREATE
919 */
920 gboolean bd_crypto_luks_format (const gchar *device, const gchar *cipher, guint64 key_size, BDCryptoKeyslotContext *context, guint64 min_entropy, BDCryptoLUKSVersion luks_version, BDCryptoLUKSExtra *extra,GError **error);
921
922 /**
923 * bd_crypto_luks_open:
924 * @device: the device to open
925 * @name: name for the LUKS device
926 * @context: key slot context (passphrase/keyfile/token...) to open this LUKS @device
927 * @read_only: whether to open as read-only or not (meaning read-write)
928 * @error: (out) (optional): place to store error (if any)
929 *
930 * Supported @context types for this function: passphrase, key file, keyring
931 *
932 * Returns: whether the @device was successfully opened or not
933 *
934 * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_OPEN_CLOSE
935 *
936 * Example of using %bd_crypto_luks_open with %BDCryptoKeyslotContext:
937 *
938 * |[<!-- language="C" -->
939 * BDCryptoKeyslotContext *context = NULL;
940 *
941 * context = bd_crypto_keyslot_context_new_passphrase ("passphrase", 10, NULL);
942 * bd_crypto_luks_open ("/dev/vda1", "luks-device", context, FALSE, NULL);
943 * ]|
944 */
945 gboolean bd_crypto_luks_open (const gchar *device, const gchar *name, BDCryptoKeyslotContext *context, gboolean read_only, GError **error);
946
947 /**
948 * bd_crypto_luks_open_flags:
949 * @device: the device to open
950 * @name: name for the LUKS device
951 * @context: key slot context (passphrase/keyfile/token...) to open this LUKS @device
952 * @flags: activation flags for the LUKS device
953 * @error: (out) (optional): place to store error (if any)
954 *
955 * Supported @context types for this function: passphrase, key file, keyring
956 *
957 * Returns: whether the @device was successfully opened or not
958 *
959 * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_OPEN_CLOSE
960 *
961 * Example of using %bd_crypto_luks_open_flags with %BDCryptoKeyslotContext:
962 *
963 * |[<!-- language="C" -->
964 * BDCryptoKeyslotContext *context = NULL;
965 *
966 * context = bd_crypto_keyslot_context_new_passphrase ("passphrase", 10, NULL);
967 * bd_crypto_luks_open_flags ("/dev/vda1", "luks-device", context, 0, NULL);
968 * ]|
969 */
970 gboolean bd_crypto_luks_open_flags (const gchar *device, const gchar *name, BDCryptoKeyslotContext *context, BDCryptoOpenFlags flags, GError **error);
971
972 /**
973 * bd_crypto_luks_close:
974 * @luks_device: LUKS device to close
975 * @error: (out) (optional): place to store error (if any)
976 *
977 * Returns: whether the given @luks_device was successfully closed or not
978 *
979 * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_OPEN_CLOSE
980 */
981 gboolean bd_crypto_luks_close (const gchar *luks_device, GError **error);
982
983 /**
984 * bd_crypto_luks_add_key:
985 * @device: device to add new key to
986 * @context: key slot context (passphrase/keyfile/token...) to for this LUKS @device
987 * @ncontext: new key slot context (passphrase/keyfile/token...) to add to this LUKS @device
988 * @error: (out) (optional): place to store error (if any)
989 *
990 * Supported @context types for this function: passphrase, key file
991 *
992 * Returns: whether the @ncontext was successfully added to @device
993 * or not
994 *
995 * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_ADD_KEY
996 */
997 gboolean bd_crypto_luks_add_key (const gchar *device, BDCryptoKeyslotContext *context, BDCryptoKeyslotContext *ncontext, GError **error);
998
999 /**
1000 * bd_crypto_luks_remove_key:
1001 * @device: device to add new key to
1002 * @context: key slot context (passphrase/keyfile/token...) to remove from this LUKS @device
1003 * @error: (out) (optional): place to store error (if any)
1004 *
1005 * Supported @context types for this function: passphrase, key file
1006 *
1007 * Returns: whether the key was successfully removed or not
1008 *
1009 * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_REMOVE_KEY
1010 */
1011 gboolean bd_crypto_luks_remove_key (const gchar *device, BDCryptoKeyslotContext *context, GError **error);
1012
1013 /**
1014 * bd_crypto_luks_change_key:
1015 * @device: device to change key of
1016 * @context: key slot context (passphrase/keyfile/token...) for this LUKS @device
1017 * @ncontext: new key slot context (passphrase/keyfile/token...) to add to this LUKS @device
1018 * @error: (out) (optional): place to store error (if any)
1019 *
1020 * Supported @context types for this function: passphrase, key file
1021 *
1022 * Returns: whether the key was successfully changed or not
1023 *
1024 * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_ADD_KEY&%BD_CRYPTO_TECH_MODE_REMOVE_KEY
1025 */
1026 gboolean bd_crypto_luks_change_key (const gchar *device, BDCryptoKeyslotContext *context, BDCryptoKeyslotContext *ncontext, GError **error);
1027
1028 /**
1029 * bd_crypto_luks_resize:
1030 * @luks_device: opened LUKS device to resize
1031 * @size: requested size in sectors or 0 to adapt to the backing device
1032 * @context: (nullable): key slot context (passphrase/keyfile/token...) for this LUKS @device
1033 * @error: (out) (optional): place to store error (if any)
1034 *
1035 * Supported @context types for this function: passphrase, key file
1036 *
1037 * Returns: whether the @luks_device was successfully resized or not
1038 *
1039 * You need to specify either @context for LUKS 2 devices that
1040 * don't have verified key loaded in kernel.
1041 * For LUKS 1 devices you can set @context %NULL.
1042 *
1043 * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_RESIZE
1044 */
1045 gboolean bd_crypto_luks_resize (const gchar *luks_device, guint64 size, BDCryptoKeyslotContext *context, GError **error);
1046
1047 /**
1048 * bd_crypto_luks_suspend:
1049 * @luks_device: LUKS device to suspend
1050 * @error: (out) (optional): place to store error (if any)
1051 *
1052 * Returns: whether the given @luks_device was successfully suspended or not
1053 *
1054 * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_SUSPEND_RESUME
1055 */
1056 gboolean bd_crypto_luks_suspend (const gchar *luks_device, GError **error);
1057
1058 /**
1059 * bd_crypto_luks_resume:
1060 * @luks_device: LUKS device to resume
1061 * @context: key slot context (passphrase/keyfile/token...) for @luks_device
1062 * @error: (out) (optional): place to store error (if any)
1063 *
1064 * Supported @context types for this function: passphrase, key file
1065 *
1066 * Returns: whether the given @luks_device was successfully resumed or not
1067 *
1068 * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_SUSPEND_RESUME
1069 */
1070 gboolean bd_crypto_luks_resume (const gchar *luks_device, BDCryptoKeyslotContext *context, GError **error);
1071
1072 /**
1073 * bd_crypto_luks_kill_slot:
1074 * @device: device to kill slot on
1075 * @slot: keyslot to destroy
1076 * @error: (out) (optional): place to store error (if any)
1077 *
1078 * Note: This can destroy last remaining keyslot without confirmation making
1079 * the LUKS device permanently inaccessible.
1080 *
1081 * Returns: whether the given @slot was successfully destroyed or not
1082 *
1083 * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_REMOVE_KEY
1084 */
1085 gboolean bd_crypto_luks_kill_slot (const gchar *device, gint slot, GError **error);
1086
1087 /**
1088 * bd_crypto_luks_header_backup:
1089 * @device: device to backup the LUKS header
1090 * @backup_file: file to save the header backup to
1091 * @error: (out) (optional): place to store error (if any)
1092 *
1093 * Returns: whether the given backup of @device was successfully written to
1094 * @backup_file or not
1095 *
1096 * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_BACKUP_RESTORE
1097 */
1098 gboolean bd_crypto_luks_header_backup (const gchar *device, const gchar *backup_file, GError **error);
1099
1100 /**
1101 * bd_crypto_luks_header_restore:
1102 * @device: device to restore the LUKS header to
1103 * @backup_file: existing file with a LUKS header backup
1104 * @error: (out) (optional): place to store error (if any)
1105 *
1106 * Returns: whether the given @device LUKS header was successfully restored
1107 * from @backup_file
1108 *
1109 *
1110 * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_BACKUP_RESTORE
1111 */
1112 gboolean bd_crypto_luks_header_restore (const gchar *device, const gchar *backup_file, GError **error);
1113
1114 /**
1115 * bd_crypto_luks_set_label:
1116 * @device: device to set label on
1117 * @label: (nullable): label to set
1118 * @subsystem: (nullable): subsystem to set
1119 * @error: (out) (optional): place to store error (if any)
1120 *
1121 * Returns: whether the given @label and @subsystem were successfully set or not
1122 *
1123 * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_MODIFY
1124 */
1125 gboolean bd_crypto_luks_set_label (const gchar *device, const gchar *label, const gchar *subsystem, GError **error);
1126
1127 /**
1128 * bd_crypto_luks_check_label:
1129 * @label: (nullable): label to check
1130 * @subsystem: (nullable): subsystem to check
1131 * @error: (out) (optional): place to store error
1132 *
1133 * Returns: whether @label and @subsystem are valid for LUKS2 or not
1134 * (reason is provided in @error)
1135 *
1136 * Tech category: always available
1137 */
1138 gboolean bd_crypto_luks_check_label (const gchar *label, const gchar *subsystem, GError **error);
1139
1140 /**
1141 * bd_crypto_luks_set_uuid:
1142 * @device: device to set UUID on
1143 * @uuid: (nullable): UUID to set or %NULL to generate a new one
1144 * @error: (out) (optional): place to store error (if any)
1145 *
1146 * Returns: whether the given @uuid was successfully set or not
1147 *
1148 * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_MODIFY
1149 */
1150 gboolean bd_crypto_luks_set_uuid (const gchar *device, const gchar *uuid, GError **error);
1151
1152 /**
1153 * bd_crypto_luks_convert:
1154 * @device: a LUKS device to convert to a different version of LUKS
1155 * @target_version: the LUKS version to convert to
1156 * @error: (out) (optional): place to store error (if any)
1157 *
1158 * Returns: whether the @device was converted to @target_version.
1159 * False, if the @device is already in the @target_version format.
1160 *
1161 * Warning: LUKS header loss is possible. See bd_crypto_luks_header_backup() and bd_crypto_luks_header_restore()
1162 *
1163 * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_MODIFY
1164 */
1165 gboolean bd_crypto_luks_convert (const gchar *device, BDCryptoLUKSVersion target_version, GError **error);
1166
1167 /**
1168 * bd_crypto_luks_set_persistent_flags:
1169 * @device: a LUKS device to set the persistent flags on
1170 * @flags: flags to set
1171 * @error: (out) (optional): place to store error (if any)
1172 *
1173 * Note: This function is valid only for LUKS2.
1174 *
1175 * Returns: whether the given @flags were successfully set or not
1176 *
1177 * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_MODIFY
1178 */
1179 gboolean bd_crypto_luks_set_persistent_flags (const gchar *device, BDCryptoLUKSPersistentFlags flags, GError **error);
1180
1181 /**
1182 * bd_crypto_luks_info:
1183 * @device: a device to get information about
1184 * @error: (out) (optional): place to store error (if any)
1185 *
1186 * Returns: (transfer full): information about the @device or %NULL in case of error
1187 *
1188 * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_QUERY
1189 */
1190 BDCryptoLUKSInfo* bd_crypto_luks_info (const gchar *device, GError **error);
1191
1192 /**
1193 * bd_crypto_bitlk_info:
1194 * @device: a device to get information about
1195 * @error: (out) (optional): place to store error (if any)
1196 *
1197 * Returns (transfer full): information about the @device or %NULL in case of error
1198 *
1199 * Tech category: %BD_CRYPTO_TECH_BITLK-%BD_CRYPTO_TECH_MODE_QUERY
1200 */
1201 BDCryptoBITLKInfo* bd_crypto_bitlk_info (const gchar *device, GError **error);
1202
1203 /**
1204 * bd_crypto_integrity_info:
1205 * @device: a device to get information about
1206 * @error: (out) (optional): place to store error (if any)
1207 *
1208 * Returns: (transfer full): information about the @device or %NULL in case of error
1209 *
1210 * Tech category: %BD_CRYPTO_TECH_INTEGRITY-%BD_CRYPTO_TECH_MODE_QUERY
1211 */
1212 BDCryptoIntegrityInfo* bd_crypto_integrity_info (const gchar *device, GError **error);
1213
1214 /**
1215 * bd_crypto_luks_token_info:
1216 * @device: a device to get LUKS2 token information about
1217 * @error: (out) (optional): place to store error (if any)
1218 *
1219 * Returns: (array zero-terminated=1) (transfer full): information about tokens on @device
1220 *
1221 * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_QUERY
1222 */
1223 BDCryptoLUKSTokenInfo** bd_crypto_luks_token_info (const gchar *device, GError **error);
1224
1225 /**
1226 * bd_crypto_integrity_format:
1227 * @device: a device to format as integrity
1228 * @algorithm: integrity algorithm specification (e.g. "crc32c" or "sha256")
1229 * @wipe: whether to wipe the device after format; a device that is not initially wiped will contain invalid checksums
1230 * @context: (nullable): key slot context (passphrase/keyfile/token...) for this device
1231 * @extra: (nullable): extra arguments for integrity format creation
1232 * @error: (out) (optional): place to store error (if any)
1233 *
1234 * Formats the given @device as integrity according to the other parameters given.
1235 *
1236 * Supported @context types for this function: volume key
1237 *
1238 * Returns: whether the given @device was successfully formatted as integrity or not
1239 * (the @error) contains the error in such cases)
1240 *
1241 * Tech category: %BD_CRYPTO_TECH_INTEGRITY-%BD_CRYPTO_TECH_MODE_CREATE
1242 */
1243 gboolean bd_crypto_integrity_format (const gchar *device, const gchar *algorithm, gboolean wipe, BDCryptoKeyslotContext *context, BDCryptoIntegrityExtra *extra, GError **error);
1244
1245 /**
1246 * bd_crypto_integrity_open:
1247 * @device: integrity device to open
1248 * @name: name for the opened @device
1249 * @algorithm: integrity algorithm specification (e.g. "crc32c" or "sha256")
1250 * @context: (nullable): key slot context (passphrase/keyfile/token...) for this device
1251 * @flags: flags for the integrity device activation
1252 * @extra: (nullable): extra arguments for integrity open
1253 * @error: (out) (optional): place to store error (if any)
1254 *
1255 * Supported @context types for this function: volume key
1256 *
1257 * Returns: whether the @device was successfully opened or not
1258 *
1259 * Tech category: %BD_CRYPTO_TECH_INTEGRITY-%BD_CRYPTO_TECH_MODE_OPEN_CLOSE
1260 */
1261 gboolean bd_crypto_integrity_open (const gchar *device, const gchar *name, const gchar *algorithm, BDCryptoKeyslotContext *context, BDCryptoIntegrityOpenFlags flags, BDCryptoIntegrityExtra *extra, GError **error);
1262
1263 /**
1264 * bd_crypto_integrity_close:
1265 * @integrity_device: integrity device to close
1266 * @error: (out) (optional): place to store error (if any)
1267 *
1268 * Returns: whether the given @integrity_device was successfully closed or not
1269 *
1270 * Tech category: %BD_CRYPTO_TECH_INTEGRITY-%BD_CRYPTO_TECH_MODE_OPEN_CLOSE
1271 */
1272 gboolean bd_crypto_integrity_close (const gchar *integrity_device, GError **error);
1273
1274 /**
1275 * bd_crypto_keyring_add_key:
1276 * @key_desc: kernel keyring key description
1277 * @key_data: (array length=data_len): a key to add to kernel keyring (may contain arbitrary binary data)
1278 * @data_len: length of the @key_data buffer
1279 * @error: (out) (optional): place to store error (if any)
1280 * *
1281 * Returns: whether the given key was successfully saved to kernel keyring or not
1282 *
1283 * Tech category: %BD_CRYPTO_TECH_KEYRING-%BD_CRYPTO_TECH_MODE_ADD_KEY
1284 */
1285 gboolean bd_crypto_keyring_add_key (const gchar *key_desc, const guint8 *key_data, gsize data_len, GError **error);
1286
1287 /**
1288 * bd_crypto_device_seems_encrypted:
1289 * @device: the queried device
1290 * @error: (out) (optional): place to store error (if any)
1291 *
1292 * Determines whether a block device seems to be encrypted.
1293 *
1294 * TCRYPT volumes are not easily identifiable, because they have no
1295 * cleartext header, but are completely encrypted. This function is
1296 * used to determine whether a block device is a candidate for being
1297 * TCRYPT encrypted.
1298 *
1299 * To achieve this, we calculate the chi square value of the first
1300 * 512 Bytes and treat devices with a chi square value between 136
1301 * and 426 as candidates for being encrypted.
1302 * For the reasoning, see: https://gitlab.tails.boum.org/tails/blueprints/-/wikis/veracrypt/#detecting-veracrypt-volumes
1303 *
1304 * Returns: %TRUE if the given @device seems to be encrypted or %FALSE if not or
1305 * failed to determine (the @error) is populated with the error in such
1306 * cases)
1307 *
1308 * Tech category: %BD_CRYPTO_TECH_TRUECRYPT-%BD_CRYPTO_TECH_MODE_QUERY
1309 */
1310 gboolean bd_crypto_device_seems_encrypted (const gchar *device, GError **error);
1311
1312 /**
1313 * bd_crypto_tc_open:
1314 * @device: the device to open
1315 * @name: name for the TrueCrypt/VeraCrypt device
1316 * @context: (nullable): passphrase key slot context for this TrueCrypt/VeraCrypt volume
1317 * @read_only: whether to open as read-only or not (meaning read-write)
1318 * @keyfiles: (nullable) (array zero-terminated=1): paths to the keyfiles for the TrueCrypt/VeraCrypt volume
1319 * @hidden: whether a hidden volume inside the volume should be opened
1320 * @system: whether to try opening as an encrypted system (with boot loader)
1321 * @veracrypt: whether to try VeraCrypt modes (TrueCrypt modes are tried anyway)
1322 * @veracrypt_pim: VeraCrypt PIM value (only used if @veracrypt is %TRUE)
1323 * @error: (out) (optional): place to store error (if any)
1324 *
1325 * Supported @context types for this function: passphrase
1326 *
1327 * Returns: whether the @device was successfully opened or not
1328 *
1329 * Tech category: %BD_CRYPTO_TECH_TRUECRYPT-%BD_CRYPTO_TECH_MODE_OPEN_CLOSE
1330 */
1331 gboolean bd_crypto_tc_open (const gchar *device, const gchar *name, BDCryptoKeyslotContext *context, const gchar **keyfiles, gboolean hidden, gboolean system, gboolean veracrypt, guint32 veracrypt_pim, gboolean read_only, GError **error);
1332
1333 /**
1334 * bd_crypto_tc_open_flags:
1335 * @device: the device to open
1336 * @name: name for the TrueCrypt/VeraCrypt device
1337 * @context: (nullable): passphrase key slot context for this TrueCrypt/VeraCrypt volume
1338 * @flags: activation flags for the TrueCrypt/VeraCrypt device
1339 * @keyfiles: (nullable) (array zero-terminated=1): paths to the keyfiles for the TrueCrypt/VeraCrypt volume
1340 * @hidden: whether a hidden volume inside the volume should be opened
1341 * @system: whether to try opening as an encrypted system (with boot loader)
1342 * @veracrypt: whether to try VeraCrypt modes (TrueCrypt modes are tried anyway)
1343 * @veracrypt_pim: VeraCrypt PIM value (only used if @veracrypt is %TRUE)
1344 * @error: (out) (optional): place to store error (if any)
1345 *
1346 * Supported @context types for this function: passphrase
1347 *
1348 * Returns: whether the @device was successfully opened or not
1349 *
1350 * Tech category: %BD_CRYPTO_TECH_TRUECRYPT-%BD_CRYPTO_TECH_MODE_OPEN_CLOSE
1351 */
1352 gboolean bd_crypto_tc_open_flags (const gchar *device, const gchar *name, BDCryptoKeyslotContext *context, const gchar **keyfiles, gboolean hidden, gboolean system, gboolean veracrypt, guint32 veracrypt_pim, BDCryptoOpenFlags flags, GError **error);
1353
1354 /**
1355 * bd_crypto_tc_close:
1356 * @tc_device: TrueCrypt/VeraCrypt device to close
1357 * @error: (out) (optional): place to store error (if any)
1358 *
1359 * Returns: whether the given @tc_device was successfully closed or not
1360 *
1361 * Tech category: %BD_CRYPTO_TECH_TRUECRYPT-%BD_CRYPTO_TECH_MODE_OPEN_CLOSE
1362 */
1363 gboolean bd_crypto_tc_close (const gchar *tc_device, GError **error);
1364
1365 /**
1366 * bd_crypto_escrow_device:
1367 * @device: path of the device to create escrow data for
1368 * @passphrase: passphrase used for the device
1369 * @cert_data: (array zero-terminated=1) (element-type gchar): certificate data to use for escrow
1370 * @directory: directory to put escrow data into
1371 * @backup_passphrase: (nullable): backup passphrase for the device or %NULL
1372 * @error: (out) (optional): place to store error (if any)
1373 *
1374 * Returns: whether the escrow data was successfully created for @device or not
1375 *
1376 * Tech category: %BD_CRYPTO_TECH_ESCROW-%BD_CRYPTO_TECH_MODE_CREATE
1377 */
1378 gboolean bd_crypto_escrow_device (const gchar *device, const gchar *passphrase, const gchar *cert_data, const gchar *directory, const gchar *backup_passphrase, GError **error);
1379
1380 /**
1381 * bd_crypto_bitlk_open:
1382 * @device: the device to open
1383 * @name: name for the BITLK device
1384 * @context: key slot context (passphrase/keyfile/token...) for this BITLK device
1385 * @read_only: whether to open as read-only or not (meaning read-write)
1386 * @error: (out) (optional): place to store error (if any)
1387 *
1388 * Supported @context types for this function: passphrase, key file
1389 *
1390 * Returns: whether the @device was successfully opened or not
1391 *
1392 * Tech category: %BD_CRYPTO_TECH_BITLK-%BD_CRYPTO_TECH_MODE_OPEN_CLOSE
1393 */
1394 gboolean bd_crypto_bitlk_open (const gchar *device, const gchar *name, BDCryptoKeyslotContext *context, gboolean read_only, GError **error);
1395
1396 /**
1397 * bd_crypto_bitlk_open_flags:
1398 * @device: the device to open
1399 * @name: name for the BITLK device
1400 * @context: key slot context (passphrase/keyfile/token...) for this BITLK device
1401 * @flags: activation flags for the BITLK device
1402 * @error: (out) (optional): place to store error (if any)
1403 *
1404 * Supported @context types for this function: passphrase, key file
1405 *
1406 * Returns: whether the @device was successfully opened or not
1407 *
1408 * Tech category: %BD_CRYPTO_TECH_BITLK-%BD_CRYPTO_TECH_MODE_OPEN_CLOSE
1409 */
1410 gboolean bd_crypto_bitlk_open_flags (const gchar *device, const gchar *name, BDCryptoKeyslotContext *context, BDCryptoOpenFlags flags, GError **error);
1411
1412 /**
1413 * bd_crypto_bitlk_close:
1414 * @bitlk_device: BITLK device to close
1415 * @error: (out) (optional): place to store error (if any)
1416 *
1417 * Returns: whether the given @bitlk_device was successfully closed or not
1418 *
1419 * Tech category: %BD_CRYPTO_TECH_BITLK-%BD_CRYPTO_TECH_MODE_OPEN_CLOSE
1420 */
1421 gboolean bd_crypto_bitlk_close (const gchar *bitlk_device, GError **error);
1422
1423 /**
1424 * bd_crypto_fvault2_open:
1425 * @device: the device to open
1426 * @name: name for the FVAULT2 device
1427 * @context: key slot context (passphrase/keyfile/token...) for this FVAULT2 volume
1428 * @read_only: whether to open as read-only or not (meaning read-write)
1429 * @error: (out) (optional): place to store error (if any)
1430 *
1431 * Supported @context types for this function: passphrase, key file
1432 *
1433 * Returns: whether the @device was successfully opened or not
1434 *
1435 * Tech category: %BD_CRYPTO_TECH_FVAULT2-%BD_CRYPTO_TECH_MODE_OPEN_CLOSE
1436 */
1437 gboolean bd_crypto_fvault2_open (const gchar *device, const gchar *name, BDCryptoKeyslotContext *context, gboolean read_only, GError **error);
1438
1439 /**
1440 * bd_crypto_fvault2_open_flags:
1441 * @device: the device to open
1442 * @name: name for the FVAULT2 device
1443 * @context: key slot context (passphrase/keyfile/token...) for this FVAULT2 volume
1444 * @flags: activation flags for the FVAULT2 device
1445 * @error: (out) (optional): place to store error (if any)
1446 *
1447 * Supported @context types for this function: passphrase, key file
1448 *
1449 * Returns: whether the @device was successfully opened or not
1450 *
1451 * Tech category: %BD_CRYPTO_TECH_FVAULT2-%BD_CRYPTO_TECH_MODE_OPEN_CLOSE
1452 */
1453 gboolean bd_crypto_fvault2_open_flags (const gchar *device, const gchar *name, BDCryptoKeyslotContext *context, BDCryptoOpenFlags flags, GError **error);
1454
1455 /**
1456 * bd_crypto_fvault2_close:
1457 * @fvault2_device: FVAULT2 device to close
1458 * @error: (out) (optional): place to store error (if any)
1459 *
1460 * Returns: whether the given @fvault2_device was successfully closed or not
1461 *
1462 * Tech category: %BD_CRYPTO_TECH_FVAULT2-%BD_CRYPTO_TECH_MODE_OPEN_CLOSE
1463 */
1464 gboolean bd_crypto_fvault2_close (const gchar *fvault2_device, GError **error);
1465
1466 /**
1467 * bd_crypto_opal_is_supported:
1468 * @device: device to check for OPAL support
1469 * @error: (out) (optional): place to store error (if any)
1470 *
1471 * Returns: %TRUE if the given @device supports OPAL or %FALSE if not or
1472 * failed to determine (the @error is populated with the error in such
1473 * cases).
1474 *
1475 * Tech category: %BD_CRYPTO_TECH_SED_OPAL-%BD_CRYPTO_TECH_MODE_QUERY
1476 */
1477 gboolean bd_crypto_opal_is_supported (const gchar *device, GError **error);
1478
1479 /**
1480 * bd_crypto_opal_wipe_device:
1481 * @device: LUKS HW-OPAL device to wipe
1482 * @context: OPAL admin passphrase context
1483 * @error: (out) (optional): place to store error (if any)
1484 *
1485 * Returns: whether @device was successfully wiped or not.
1486 *
1487 * Supported @context types for this function: passphrase
1488 *
1489 * Tech category: %BD_CRYPTO_TECH_SED_OPAL-%BD_CRYPTO_TECH_MODE_MODIFY
1490 */
1491 gboolean bd_crypto_opal_wipe_device (const gchar *device, BDCryptoKeyslotContext *context, GError **error);
1492
1493 /**
1494 * bd_crypto_opal_format:
1495 * @device: a device to format as LUKS HW-OPAL
1496 * @cipher: (nullable): cipher specification (type-mode, e.g. "aes-xts-plain64") or %NULL to use the default
1497 * @key_size: size of the volume key in bits or 0 to use the default
1498 * @context: key slot context (passphrase/keyfile/token...) for this LUKS device
1499 * @min_entropy: minimum random data entropy (in bits) required to format @device as LUKS
1500 * @hw_encryption: type of hardware encryption (SW+HW or HW only)
1501 * @opal_context: OPAL admin passphrase
1502 * @extra: (nullable): extra arguments for LUKS format creation
1503 * @error: (out) (optional): place to store error (if any)
1504 *
1505 * Formats the given @device as LUKS HW-OPAL according to the other parameters given. If
1506 * @min_entropy is specified (greater than 0), the function waits for enough
1507 * entropy to be available in the random data pool (WHICH MAY POTENTIALLY TAKE
1508 * FOREVER).
1509 *
1510 * Supported @context types for this function: passphrase, key file
1511 * Supported @opal_context types for this function: passphrase
1512 *
1513 * Returns: whether the given @device was successfully formatted as LUKS HW-OPAL or not
1514 * (the @error contains the error in such cases)
1515 *
1516 * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_CREATE
1517 */
1518 gboolean bd_crypto_opal_format (const gchar *device, const gchar *cipher, guint64 key_size, BDCryptoKeyslotContext *context, guint64 min_entropy, BDCryptoLUKSHWEncryptionType hw_encryption, BDCryptoKeyslotContext *opal_context, BDCryptoLUKSExtra *extra, GError **error);
1519
1520 /**
1521 * bd_crypto_opal_reset_device:
1522 * @device: LUKS HW-OPAL device to run PSID reset on
1523 * @context: PSID context
1524 * @error: (out) (optional): place to store error (if any)
1525 *
1526 * Returns: whether PSI reset on @device was successful or not.
1527 *
1528 * Warning: PSID reset will remove all data from @device!
1529 *
1530 * Supported @context types for this function: passphrase, key file
1531 *
1532 * Tech category: %BD_CRYPTO_TECH_SED_OPAL-%BD_CRYPTO_TECH_MODE_MODIFY
1533 */
1534 gboolean bd_crypto_opal_reset_device (const gchar *device, BDCryptoKeyslotContext *context, GError **error);
1535
1536 #endif /* BD_CRYPTO_API */