@@ -27,12 +27,14 @@ pub enum CrcFastAlgorithm {
27
27
Crc32Bzip2 ,
28
28
Crc32CdRomEdc ,
29
29
Crc32Cksum ,
30
+ Crc32Custom ,
30
31
Crc32Iscsi ,
31
32
Crc32IsoHdlc ,
32
33
Crc32Jamcrc ,
33
34
Crc32Mef ,
34
35
Crc32Mpeg2 ,
35
36
Crc32Xfer ,
37
+ Crc64Custom ,
36
38
Crc64Ecma182 ,
37
39
Crc64GoIso ,
38
40
Crc64Ms ,
@@ -52,12 +54,14 @@ impl From<CrcFastAlgorithm> for CrcAlgorithm {
52
54
CrcFastAlgorithm :: Crc32Bzip2 => CrcAlgorithm :: Crc32Bzip2 ,
53
55
CrcFastAlgorithm :: Crc32CdRomEdc => CrcAlgorithm :: Crc32CdRomEdc ,
54
56
CrcFastAlgorithm :: Crc32Cksum => CrcAlgorithm :: Crc32Cksum ,
57
+ CrcFastAlgorithm :: Crc32Custom => CrcAlgorithm :: Crc32Custom ,
55
58
CrcFastAlgorithm :: Crc32Iscsi => CrcAlgorithm :: Crc32Iscsi ,
56
59
CrcFastAlgorithm :: Crc32IsoHdlc => CrcAlgorithm :: Crc32IsoHdlc ,
57
60
CrcFastAlgorithm :: Crc32Jamcrc => CrcAlgorithm :: Crc32Jamcrc ,
58
61
CrcFastAlgorithm :: Crc32Mef => CrcAlgorithm :: Crc32Mef ,
59
62
CrcFastAlgorithm :: Crc32Mpeg2 => CrcAlgorithm :: Crc32Mpeg2 ,
60
63
CrcFastAlgorithm :: Crc32Xfer => CrcAlgorithm :: Crc32Xfer ,
64
+ CrcFastAlgorithm :: Crc64Custom => CrcAlgorithm :: Crc64Custom ,
61
65
CrcFastAlgorithm :: Crc64Ecma182 => CrcAlgorithm :: Crc64Ecma182 ,
62
66
CrcFastAlgorithm :: Crc64GoIso => CrcAlgorithm :: Crc64GoIso ,
63
67
CrcFastAlgorithm :: Crc64Ms => CrcAlgorithm :: Crc64Ms ,
@@ -310,6 +314,66 @@ pub extern "C" fn crc_fast_checksum_combine(
310
314
crate :: checksum_combine ( algorithm. into ( ) , checksum1, checksum2, checksum2_len)
311
315
}
312
316
317
+ /// Combine two CRC checksums using custom parameters
318
+ #[ no_mangle]
319
+ pub extern "C" fn crc_fast_checksum_combine_with_custom_params (
320
+ params : CrcFastParams ,
321
+ checksum1 : u64 ,
322
+ checksum2 : u64 ,
323
+ checksum2_len : u64 ,
324
+ ) -> u64 {
325
+ crate :: checksum_combine_with_custom_params ( params. into ( ) , checksum1, checksum2, checksum2_len)
326
+ }
327
+
328
+ /// Returns the custom CRC parameters for a given set of Rocksoft CRC parameters
329
+ #[ no_mangle]
330
+ pub extern "C" fn crc_fast_get_custom_params (
331
+ name_ptr : * const c_char ,
332
+ width : u8 ,
333
+ poly : u64 ,
334
+ init : u64 ,
335
+ reflected : bool ,
336
+ xorout : u64 ,
337
+ check : u64 ,
338
+ ) -> CrcFastParams {
339
+ let name = if name_ptr. is_null ( ) {
340
+ "custom"
341
+ } else {
342
+ unsafe {
343
+ CStr :: from_ptr ( name_ptr) . to_str ( ) . unwrap_or ( "custom" )
344
+ }
345
+ } ;
346
+
347
+ // Get the custom params from the library
348
+ let params = crate :: get_custom_params (
349
+ // We need to use a static string for the name field
350
+ Box :: leak ( name. to_string ( ) . into_boxed_str ( ) ) ,
351
+ width,
352
+ poly,
353
+ init,
354
+ reflected,
355
+ xorout,
356
+ check,
357
+ ) ;
358
+
359
+ // Convert to FFI struct
360
+ CrcFastParams {
361
+ algorithm : match width {
362
+ 32 => CrcFastAlgorithm :: Crc32Custom ,
363
+ 64 => CrcFastAlgorithm :: Crc64Custom ,
364
+ _ => panic ! ( "Unsupported width: {}" , width) ,
365
+ } ,
366
+ width : params. width ,
367
+ poly : params. poly ,
368
+ init : params. init ,
369
+ refin : params. refin ,
370
+ refout : params. refout ,
371
+ xorout : params. xorout ,
372
+ check : params. check ,
373
+ keys : params. keys ,
374
+ }
375
+ }
376
+
313
377
/// Gets the target build properties (CPU architecture and fine-tuning parameters) for this algorithm
314
378
#[ no_mangle]
315
379
pub extern "C" fn crc_fast_get_calculator_target ( algorithm : CrcFastAlgorithm ) -> * const c_char {
0 commit comments