@@ -28,6 +28,7 @@ typedef enum {
28
28
BD_CRYPTO_ERROR_KEYRING,
29
29
BD_CRYPTO_ERROR_KEYFILE_FAILED,
30
30
BD_CRYPTO_ERROR_INVALID_CONTEXT,
31
+ BD_CRYPTO_ERROR_REENCRYPT_FAILED,
31
32
} BDCryptoError;
32
33
33
34
typedef enum {
@@ -1111,6 +1112,193 @@ gboolean bd_crypto_luks_set_uuid (const gchar *device, const gchar *uuid, GError
1111
1112
*/
1112
1113
gboolean bd_crypto_luks_convert (const gchar *device, BDCryptoLUKSVersion target_version, GError **error);
1113
1114
1115
+
1116
+ #define BD_CRYPTO_TYPE_LUKS_REENCRYPT_PARAMS (bd_crypto_luks_reencrypt_params_get_type ())
1117
+ GType bd_crypto_luks_reencrypt_params_get_type();
1118
+
1119
+ /**
1120
+ * BDCryptoLUKSReencryptParams:
1121
+ * @key_size new volume key size if @new_volume_key is true. Ignored otherwise
1122
+ * @cipher new cipher
1123
+ * @cipher_mode new cipher mode
1124
+ * @resilience resilience mode to be used during reencryption
1125
+ * @hash used hash for "checksum" resilience type, ignored otherwise
1126
+ * @max_hotzone_size max hotzone size
1127
+ * @sector_size sector size. Note that 0 is not a valid value
1128
+ * @new_volume_key whether to generate a new volume key or keep the existing one
1129
+ * @offline whether to perform an offline or online reencryption,
1130
+ * i.e. whether a device is active in the time of reencryption or not
1131
+ * @pbkdf PBDKF function parameters for a new keyslot
1132
+ */
1133
+ typedef struct BDCryptoLUKSReencryptParams {
1134
+ guint32 key_size;
1135
+ gchar *cipher;
1136
+ gchar *cipher_mode;
1137
+ gchar *resilience;
1138
+ gchar *hash;
1139
+ guint64 max_hotzone_size;
1140
+ guint32 sector_size;
1141
+ gboolean new_volume_key;
1142
+ gboolean offline;
1143
+ BDCryptoLUKSPBKDF *pbkdf;
1144
+ } BDCryptoLUKSReencryptParams;
1145
+
1146
+ /**
1147
+ * bd_crypto_luks_reencrypt_params_copy: (skip)
1148
+ * @params: (nullable): %BDCryptoLUKSReencryptParams to copy
1149
+ *
1150
+ * Creates a copy of @params.
1151
+ */
1152
+ BDCryptoLUKSReencryptParams* bd_crypto_luks_reencrypt_params_copy (BDCryptoLUKSReencryptParams* params) {
1153
+ if (params == NULL)
1154
+ return NULL;
1155
+
1156
+ BDCryptoLUKSReencryptParams *new_params = g_new0 (BDCryptoLUKSReencryptParams, 1);
1157
+ new_params->key_size = params->key_size;
1158
+ new_params->cipher = g_strdup (params->cipher);
1159
+ new_params->cipher_mode = g_strdup (params->cipher_mode);
1160
+ new_params->resilience = g_strdup (params->resilience);
1161
+ new_params->hash = g_strdup (params->hash);
1162
+ new_params->max_hotzone_size = params->max_hotzone_size;
1163
+ new_params->sector_size = params->sector_size;
1164
+ new_params->new_volume_key = params->new_volume_key;
1165
+ new_params->offline = params->offline;
1166
+ new_params->pbkdf = bd_crypto_luks_pbkdf_copy(params->pbkdf);
1167
+
1168
+ return new_params;
1169
+ }
1170
+
1171
+ /**
1172
+ * bd_crypto_luks_reencrypt_params_free: (skip)
1173
+ * @params: (nullable): %BDCryptoLUKSReencryptParams to free
1174
+ *
1175
+ * Frees @params.
1176
+ */
1177
+ void bd_crypto_luks_reencrypt_params_free (BDCryptoLUKSReencryptParams* params) {
1178
+ if (params == NULL)
1179
+ return;
1180
+
1181
+ g_free (params->cipher);
1182
+ g_free (params->cipher_mode);
1183
+ g_free (params->resilience);
1184
+ g_free (params->hash);
1185
+ bd_crypto_luks_pbkdf_free(params->pbkdf);
1186
+ }
1187
+
1188
+ /**
1189
+ * bd_crypto_luks_reencrypt_params_new: (constructor)
1190
+ * @key_size new volume key size if @new_volume_key is true. Ignored otherwise
1191
+ * @cipher: (nullable): new cipher
1192
+ * @cipher_mode: (nullable): new cipher mode
1193
+ * @resilience: (nullable): resilience mode to be used during reencryption
1194
+ * @hash: (nullable): used hash for "checksum" resilience type, ignored otherwise
1195
+ * @max_hotzone_size max hotzone size
1196
+ * @sector_size sector size. Note that 0 is not a valid value
1197
+ * @new_volume_key whether to generate a new volume key or keep the existing one
1198
+ * @offline whether to perform an offline or online reencryption,
1199
+ * i.e. whether a device is active in the time of reencryption or not
1200
+ * @pbkdf: (nullable): PBDKF function parameters for a new keyslot
1201
+ */
1202
+ BDCryptoLUKSReencryptParams* bd_crypto_luks_reencrypt_params_new (guint32 key_size, gchar *cipher, gchar *cipher_mode, gchar *resilience, gchar *hash, guint64 max_hotzone_size, guint32 sector_size, gboolean new_volume_key, gboolean offline, BDCryptoLUKSPBKDF *pbkdf) {
1203
+ BDCryptoLUKSReencryptParams *ret = g_new0 (BDCryptoLUKSReencryptParams, 1);
1204
+ ret->key_size = key_size;
1205
+ ret->cipher = g_strdup (cipher);
1206
+ ret->cipher_mode = g_strdup (cipher_mode);
1207
+ ret->resilience = g_strdup (resilience);
1208
+ ret->hash = g_strdup (hash);
1209
+ ret->max_hotzone_size = max_hotzone_size;
1210
+ ret->sector_size = sector_size;
1211
+ ret->new_volume_key = new_volume_key;
1212
+ ret->offline = offline;
1213
+ ret->pbkdf = bd_crypto_luks_pbkdf_copy(pbkdf);
1214
+
1215
+ return ret;
1216
+ }
1217
+
1218
+ GType bd_crypto_luks_reencrypt_params_get_type () {
1219
+ static GType type = 0;
1220
+
1221
+ if (G_UNLIKELY(type == 0)) {
1222
+ type = g_boxed_type_register_static("BDCryptoLUKSReencryptParams",
1223
+ (GBoxedCopyFunc) bd_crypto_luks_reencrypt_params_copy,
1224
+ (GBoxedFreeFunc) bd_crypto_luks_reencrypt_params_free);
1225
+ }
1226
+
1227
+ return type;
1228
+ }
1229
+
1230
+ /**
1231
+ * BDCryptoLUKSReencryptProgFunc:
1232
+ * @size size of the device being reencrypted
1233
+ * @offset current offset
1234
+ *
1235
+ * A callback function called during reencryption to report progress. Also used to possibly stop reencryption.
1236
+ *
1237
+ * Returns: 0, if the reencryption should continue.
1238
+ * A non-zero value to stop the reencryption
1239
+ */
1240
+ typedef int (*BDCryptoLUKSReencryptProgFunc) (guint64 size, guint64 offset);
1241
+
1242
+ typedef enum {
1243
+ BD_CRYPTO_LUKS_REENCRYPT_NONE = 0,
1244
+ BD_CRYPTO_LUKS_REENCRYPT_CLEAN,
1245
+ BD_CRYPTO_LUKS_REENCRYPT_CRASH,
1246
+ BD_CRYPTO_LUKS_REENCRYPT_INVALID
1247
+ } BDCryptoLUKSReencryptStatus;
1248
+
1249
+ typedef enum {
1250
+ BD_CRYPTO_LUKS_REENCRYPT = 0,
1251
+ BD_CRYPTO_LUKS_ENCRYPT,
1252
+ BD_CRYPTO_LUKS_DECRYPT,
1253
+ } BDCryptoLUKSReencryptMode;
1254
+
1255
+ /**
1256
+ * bd_crypto_luks_reencrypt:
1257
+ * @device: device to reencrypt. Either an active device name for online reencryption, or a block device for offline reencryption.
1258
+ * Must match the @params's "offline" parameter
1259
+ * @params: reencryption parameters
1260
+ * @context: key slot context to unlock @device. The newly created keyslot will use the same context
1261
+ * @prog_func: (scope call) (nullable): progress function. Also used to possibly stop reencryption
1262
+ * @error: (out) (optional): place to store error (if any)
1263
+ *
1264
+ * Reencrypts @device. This could mean a change of cipher, cipher mode, or volume key, based on @params
1265
+ *
1266
+ * Returns: true, if the reencryption was successful or gracefully stopped with @prog_func.
1267
+ * false, if an error occurred.
1268
+ *
1269
+ * Supported @context types for this function: passphrase
1270
+ *
1271
+ * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_MODIFY
1272
+ */
1273
+ gboolean bd_crypto_luks_reencrypt(const gchar *device, BDCryptoLUKSReencryptParams *params, BDCryptoKeyslotContext *context, BDCryptoLUKSReencryptProgFunc prog_func, GError **error);
1274
+
1275
+ /**
1276
+ * bd_crypto_luks_reencrypt_status:
1277
+ * @device: an active device name or a block device
1278
+ * @mode: (out): the exact operation in the "reencryption family"
1279
+ * Has no meaning if the return value is BD_CRYPTO_LUKS_REENCRYPT_NONE
1280
+ * @error: (out) (optional): place to store error (if any)
1281
+ *
1282
+ * Returns: state of @device's reencryption
1283
+ *
1284
+ * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_QUERY
1285
+ */
1286
+ BDCryptoLUKSReencryptStatus bd_crypto_luks_reencrypt_status (const gchar *device, BDCryptoLUKSReencryptMode *mode, GError **error);
1287
+
1288
+ /**
1289
+ * bd_crypto_luks_reencrypt_resume:
1290
+ * @device: device with a stopped reencryption. An active device name or a block device
1291
+ * @context: key slot context to unlock @device
1292
+ * @prog_func: (scope call) (nullable): progress function. Also used to possibly stop reencryption
1293
+ * @error: (out) (optional): place to store error (if any)
1294
+ *
1295
+ * Returns: true, if the reencryption finished successfully or was gracefully stopped with @prog_func.
1296
+ * false, if an error occurred.
1297
+ *
1298
+ * Tech category: %BD_CRYPTO_TECH_LUKS-%BD_CRYPTO_TECH_MODE_MODIFY
1299
+ */
1300
+ gboolean bd_crypto_luks_reencrypt_resume (const gchar *device, BDCryptoKeyslotContext *context, BDCryptoLUKSReencryptProgFunc prog_func, GError **error);
1301
+
1114
1302
/**
1115
1303
* bd_crypto_luks_info:
1116
1304
* @device: a device to get information about
0 commit comments