base-d 3.0.34

Universal base encoder: Encode binary data to 33+ dictionaries including RFC standards, hieroglyphs, emoji, and more
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
use ascon_hash::{AsconHash256, Digest as AsconDigest};
use blake2::{Blake2b512, Blake2s256};
use blake3::Hasher as Blake3Hasher;
use k12::KangarooTwelve;
use md5::Md5;
use sha2::{Sha224, Sha256, Sha384, Sha512};
use sha3::{Keccak224, Keccak256, Keccak384, Keccak512, Sha3_224, Sha3_256, Sha3_384, Sha3_512};
use std::hash::Hasher;
use twox_hash::xxhash3_64::Hasher as Xxh3Hash64;
use twox_hash::xxhash3_128::Hasher as Xxh3Hash128;
use twox_hash::{XxHash32, XxHash64};

/// Configuration for xxHash algorithms.
#[derive(Debug, Clone, Default)]
pub struct XxHashConfig {
    /// Seed value (0-u64::MAX)
    pub seed: u64,
    /// Secret for XXH3 variants (must be >= 136 bytes)
    pub secret: Option<Vec<u8>>,
}

impl XxHashConfig {
    /// Create config with a custom seed.
    pub fn with_seed(seed: u64) -> Self {
        Self { seed, secret: None }
    }

    /// Create config with seed and secret for XXH3 variants.
    /// Secret must be at least 136 bytes.
    pub fn with_secret(seed: u64, secret: Vec<u8>) -> Result<Self, String> {
        if secret.len() < 136 {
            return Err(format!(
                "XXH3 secret must be >= 136 bytes, got {}",
                secret.len()
            ));
        }
        Ok(Self {
            seed,
            secret: Some(secret),
        })
    }
}

/// Supported hash algorithms.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HashAlgorithm {
    Md5,
    Sha224,
    Sha256,
    Sha384,
    Sha512,
    Sha3_224,
    Sha3_256,
    Sha3_384,
    Sha3_512,
    Keccak224,
    Keccak256,
    Keccak384,
    Keccak512,
    Blake2b,
    Blake2s,
    Blake3,
    // CRC variants
    Crc32,
    Crc32c,
    Crc16,
    Crc64,
    // xxHash variants
    XxHash32,
    XxHash64,
    XxHash3_64,
    XxHash3_128,
    // Modern hash algorithms
    Ascon,
    K12,
}

impl HashAlgorithm {
    /// Returns all available hash algorithms.
    pub fn all() -> Vec<HashAlgorithm> {
        vec![
            HashAlgorithm::Md5,
            HashAlgorithm::Sha224,
            HashAlgorithm::Sha256,
            HashAlgorithm::Sha384,
            HashAlgorithm::Sha512,
            HashAlgorithm::Sha3_224,
            HashAlgorithm::Sha3_256,
            HashAlgorithm::Sha3_384,
            HashAlgorithm::Sha3_512,
            HashAlgorithm::Keccak224,
            HashAlgorithm::Keccak256,
            HashAlgorithm::Keccak384,
            HashAlgorithm::Keccak512,
            HashAlgorithm::Blake2b,
            HashAlgorithm::Blake2s,
            HashAlgorithm::Blake3,
            HashAlgorithm::Crc32,
            HashAlgorithm::Crc32c,
            HashAlgorithm::Crc16,
            HashAlgorithm::Crc64,
            HashAlgorithm::XxHash32,
            HashAlgorithm::XxHash64,
            HashAlgorithm::XxHash3_64,
            HashAlgorithm::XxHash3_128,
            HashAlgorithm::Ascon,
            HashAlgorithm::K12,
        ]
    }

    /// Select a random hash algorithm.
    pub fn random() -> HashAlgorithm {
        use rand::prelude::IndexedRandom;
        let all = Self::all();
        *all.choose(&mut rand::rng()).unwrap()
    }

    /// Parse hash algorithm from string.
    #[allow(clippy::should_implement_trait)]
    pub fn from_str(s: &str) -> Result<Self, String> {
        match s.to_lowercase().as_str() {
            "md5" => Ok(HashAlgorithm::Md5),
            "sha224" | "sha-224" => Ok(HashAlgorithm::Sha224),
            "sha256" | "sha-256" => Ok(HashAlgorithm::Sha256),
            "sha384" | "sha-384" => Ok(HashAlgorithm::Sha384),
            "sha512" | "sha-512" => Ok(HashAlgorithm::Sha512),
            "sha3-224" | "sha3_224" => Ok(HashAlgorithm::Sha3_224),
            "sha3-256" | "sha3_256" => Ok(HashAlgorithm::Sha3_256),
            "sha3-384" | "sha3_384" => Ok(HashAlgorithm::Sha3_384),
            "sha3-512" | "sha3_512" => Ok(HashAlgorithm::Sha3_512),
            "keccak224" | "keccak-224" => Ok(HashAlgorithm::Keccak224),
            "keccak256" | "keccak-256" => Ok(HashAlgorithm::Keccak256),
            "keccak384" | "keccak-384" => Ok(HashAlgorithm::Keccak384),
            "keccak512" | "keccak-512" => Ok(HashAlgorithm::Keccak512),
            "blake2b" | "blake2b-512" => Ok(HashAlgorithm::Blake2b),
            "blake2s" | "blake2s-256" => Ok(HashAlgorithm::Blake2s),
            "blake3" => Ok(HashAlgorithm::Blake3),
            "crc32" => Ok(HashAlgorithm::Crc32),
            "crc32c" => Ok(HashAlgorithm::Crc32c),
            "crc16" => Ok(HashAlgorithm::Crc16),
            "crc64" => Ok(HashAlgorithm::Crc64),
            "xxhash32" | "xxh32" => Ok(HashAlgorithm::XxHash32),
            "xxhash64" | "xxh64" => Ok(HashAlgorithm::XxHash64),
            "xxhash3" | "xxh3" | "xxhash3-64" | "xxh3-64" => Ok(HashAlgorithm::XxHash3_64),
            "xxhash3-128" | "xxh3-128" => Ok(HashAlgorithm::XxHash3_128),
            "ascon" => Ok(HashAlgorithm::Ascon),
            "k12" | "kangarootwelve" => Ok(HashAlgorithm::K12),
            _ => Err(format!("Unknown hash algorithm: {}", s)),
        }
    }

    pub fn as_str(&self) -> &str {
        match self {
            HashAlgorithm::Md5 => "md5",
            HashAlgorithm::Sha224 => "sha224",
            HashAlgorithm::Sha256 => "sha256",
            HashAlgorithm::Sha384 => "sha384",
            HashAlgorithm::Sha512 => "sha512",
            HashAlgorithm::Sha3_224 => "sha3-224",
            HashAlgorithm::Sha3_256 => "sha3-256",
            HashAlgorithm::Sha3_384 => "sha3-384",
            HashAlgorithm::Sha3_512 => "sha3-512",
            HashAlgorithm::Keccak224 => "keccak224",
            HashAlgorithm::Keccak256 => "keccak256",
            HashAlgorithm::Keccak384 => "keccak384",
            HashAlgorithm::Keccak512 => "keccak512",
            HashAlgorithm::Blake2b => "blake2b",
            HashAlgorithm::Blake2s => "blake2s",
            HashAlgorithm::Blake3 => "blake3",
            HashAlgorithm::Crc32 => "crc32",
            HashAlgorithm::Crc32c => "crc32c",
            HashAlgorithm::Crc16 => "crc16",
            HashAlgorithm::Crc64 => "crc64",
            HashAlgorithm::XxHash32 => "xxhash32",
            HashAlgorithm::XxHash64 => "xxhash64",
            HashAlgorithm::XxHash3_64 => "xxhash3-64",
            HashAlgorithm::XxHash3_128 => "xxhash3-128",
            HashAlgorithm::Ascon => "ascon",
            HashAlgorithm::K12 => "k12",
        }
    }

    /// Get the output size in bytes for this algorithm.
    pub fn output_size(&self) -> usize {
        match self {
            HashAlgorithm::Md5 => 16,
            HashAlgorithm::Sha224 => 28,
            HashAlgorithm::Sha256 => 32,
            HashAlgorithm::Sha384 => 48,
            HashAlgorithm::Sha512 => 64,
            HashAlgorithm::Sha3_224 => 28,
            HashAlgorithm::Sha3_256 => 32,
            HashAlgorithm::Sha3_384 => 48,
            HashAlgorithm::Sha3_512 => 64,
            HashAlgorithm::Keccak224 => 28,
            HashAlgorithm::Keccak256 => 32,
            HashAlgorithm::Keccak384 => 48,
            HashAlgorithm::Keccak512 => 64,
            HashAlgorithm::Blake2b => 64,
            HashAlgorithm::Blake2s => 32,
            HashAlgorithm::Blake3 => 32,
            HashAlgorithm::Crc16 => 2,
            HashAlgorithm::Crc32 => 4,
            HashAlgorithm::Crc32c => 4,
            HashAlgorithm::Crc64 => 8,
            HashAlgorithm::XxHash32 => 4,
            HashAlgorithm::XxHash64 => 8,
            HashAlgorithm::XxHash3_64 => 8,
            HashAlgorithm::XxHash3_128 => 16,
            HashAlgorithm::Ascon => 32,
            HashAlgorithm::K12 => 32,
        }
    }
}

/// Compute hash of data using the specified algorithm.
/// Uses default configuration (seed = 0, no secret).
pub fn hash(data: &[u8], algorithm: HashAlgorithm) -> Vec<u8> {
    hash_with_config(data, algorithm, &XxHashConfig::default())
}

/// Compute hash of data using the specified algorithm with custom configuration.
pub fn hash_with_config(data: &[u8], algorithm: HashAlgorithm, config: &XxHashConfig) -> Vec<u8> {
    match algorithm {
        HashAlgorithm::Md5 => {
            let mut hasher = Md5::new();
            hasher.update(data);
            hasher.finalize().to_vec()
        }
        HashAlgorithm::Sha224 => {
            let mut hasher = Sha224::new();
            hasher.update(data);
            hasher.finalize().to_vec()
        }
        HashAlgorithm::Sha256 => {
            let mut hasher = Sha256::new();
            hasher.update(data);
            hasher.finalize().to_vec()
        }
        HashAlgorithm::Sha384 => {
            let mut hasher = Sha384::new();
            hasher.update(data);
            hasher.finalize().to_vec()
        }
        HashAlgorithm::Sha512 => {
            let mut hasher = Sha512::new();
            hasher.update(data);
            hasher.finalize().to_vec()
        }
        HashAlgorithm::Sha3_224 => {
            let mut hasher = Sha3_224::new();
            hasher.update(data);
            hasher.finalize().to_vec()
        }
        HashAlgorithm::Sha3_256 => {
            let mut hasher = Sha3_256::new();
            hasher.update(data);
            hasher.finalize().to_vec()
        }
        HashAlgorithm::Sha3_384 => {
            let mut hasher = Sha3_384::new();
            hasher.update(data);
            hasher.finalize().to_vec()
        }
        HashAlgorithm::Sha3_512 => {
            let mut hasher = Sha3_512::new();
            hasher.update(data);
            hasher.finalize().to_vec()
        }
        HashAlgorithm::Keccak224 => {
            let mut hasher = Keccak224::new();
            hasher.update(data);
            hasher.finalize().to_vec()
        }
        HashAlgorithm::Keccak256 => {
            let mut hasher = Keccak256::new();
            hasher.update(data);
            hasher.finalize().to_vec()
        }
        HashAlgorithm::Keccak384 => {
            let mut hasher = Keccak384::new();
            hasher.update(data);
            hasher.finalize().to_vec()
        }
        HashAlgorithm::Keccak512 => {
            let mut hasher = Keccak512::new();
            hasher.update(data);
            hasher.finalize().to_vec()
        }
        HashAlgorithm::Blake2b => {
            let mut hasher = Blake2b512::new();
            hasher.update(data);
            hasher.finalize().to_vec()
        }
        HashAlgorithm::Blake2s => {
            let mut hasher = Blake2s256::new();
            hasher.update(data);
            hasher.finalize().to_vec()
        }
        HashAlgorithm::Blake3 => {
            let mut hasher = Blake3Hasher::new();
            hasher.update(data);
            hasher.finalize().as_bytes().to_vec()
        }
        HashAlgorithm::Crc16 => {
            let crc = crc::Crc::<u16>::new(&crc::CRC_16_IBM_SDLC);
            let result = crc.checksum(data);
            result.to_be_bytes().to_vec()
        }
        HashAlgorithm::Crc32 => {
            let crc = crc::Crc::<u32>::new(&crc::CRC_32_ISO_HDLC);
            let result = crc.checksum(data);
            result.to_be_bytes().to_vec()
        }
        HashAlgorithm::Crc32c => {
            let crc = crc::Crc::<u32>::new(&crc::CRC_32_ISCSI);
            let result = crc.checksum(data);
            result.to_be_bytes().to_vec()
        }
        HashAlgorithm::Crc64 => {
            let crc = crc::Crc::<u64>::new(&crc::CRC_64_ECMA_182);
            let result = crc.checksum(data);
            result.to_be_bytes().to_vec()
        }
        HashAlgorithm::XxHash32 => {
            let mut hasher = XxHash32::with_seed(config.seed as u32);
            hasher.write(data);
            (hasher.finish() as u32).to_be_bytes().to_vec()
        }
        HashAlgorithm::XxHash64 => {
            let mut hasher = XxHash64::with_seed(config.seed);
            hasher.write(data);
            hasher.finish().to_be_bytes().to_vec()
        }
        HashAlgorithm::XxHash3_64 => {
            let mut hasher = if let Some(ref secret) = config.secret {
                Xxh3Hash64::with_seed_and_secret(config.seed, secret.as_slice()).expect(
                    "XXH3 secret validation should have been done in XxHashConfig::with_secret",
                )
            } else {
                Xxh3Hash64::with_seed(config.seed)
            };
            hasher.write(data);
            hasher.finish().to_be_bytes().to_vec()
        }
        HashAlgorithm::XxHash3_128 => {
            let mut hasher = if let Some(ref secret) = config.secret {
                Xxh3Hash128::with_seed_and_secret(config.seed, secret.as_slice()).expect(
                    "XXH3 secret validation should have been done in XxHashConfig::with_secret",
                )
            } else {
                Xxh3Hash128::with_seed(config.seed)
            };
            hasher.write(data);
            hasher.finish_128().to_be_bytes().to_vec()
        }
        HashAlgorithm::Ascon => {
            let mut hasher = AsconHash256::new();
            hasher.update(data);
            hasher.finalize().to_vec()
        }
        HashAlgorithm::K12 => {
            use k12::digest::ExtendableOutput;
            use k12::digest::Update;
            use k12::digest::XofReader;
            let mut hasher = KangarooTwelve::new();
            hasher.update(data);
            let mut reader = hasher.finalize_xof();
            let mut output = vec![0u8; 32];
            reader.read(&mut output);
            output
        }
    }
}

#[cfg(test)]
#[allow(deprecated)]
mod tests {
    use super::*;

    #[test]
    fn test_md5() {
        let data = b"hello world";
        let hash = hash(data, HashAlgorithm::Md5);
        assert_eq!(hash.len(), 16);
        // MD5 of "hello world" is 5eb63bbbe01eeed093cb22bb8f5acdc3
        assert_eq!(hex::encode(&hash), "5eb63bbbe01eeed093cb22bb8f5acdc3");
    }

    #[test]
    fn test_sha256() {
        let data = b"hello world";
        let hash = hash(data, HashAlgorithm::Sha256);
        assert_eq!(hash.len(), 32);
        // SHA-256 of "hello world"
        assert_eq!(
            hex::encode(&hash),
            "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"
        );
    }

    #[test]
    fn test_sha512() {
        let data = b"hello world";
        let hash = hash(data, HashAlgorithm::Sha512);
        assert_eq!(hash.len(), 64);
    }

    #[test]
    fn test_sha3_256() {
        let data = b"hello world";
        let hash = hash(data, HashAlgorithm::Sha3_256);
        assert_eq!(hash.len(), 32);
    }

    #[test]
    fn test_blake2b() {
        let data = b"hello world";
        let hash = hash(data, HashAlgorithm::Blake2b);
        assert_eq!(hash.len(), 64);
    }

    #[test]
    fn test_blake2s() {
        let data = b"hello world";
        let hash = hash(data, HashAlgorithm::Blake2s);
        assert_eq!(hash.len(), 32);
    }

    #[test]
    fn test_blake3() {
        let data = b"hello world";
        let hash = hash(data, HashAlgorithm::Blake3);
        assert_eq!(hash.len(), 32);
    }

    #[test]
    fn test_empty_input() {
        let data = b"";
        let hash = hash(data, HashAlgorithm::Sha256);
        assert_eq!(hash.len(), 32);
        // SHA-256 of empty string
        assert_eq!(
            hex::encode(&hash),
            "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
        );
    }

    #[test]
    fn test_output_sizes() {
        assert_eq!(HashAlgorithm::Md5.output_size(), 16);
        assert_eq!(HashAlgorithm::Sha256.output_size(), 32);
        assert_eq!(HashAlgorithm::Sha512.output_size(), 64);
        assert_eq!(HashAlgorithm::Blake3.output_size(), 32);
        assert_eq!(HashAlgorithm::Crc16.output_size(), 2);
        assert_eq!(HashAlgorithm::Crc32.output_size(), 4);
        assert_eq!(HashAlgorithm::Crc64.output_size(), 8);
        assert_eq!(HashAlgorithm::XxHash32.output_size(), 4);
        assert_eq!(HashAlgorithm::XxHash64.output_size(), 8);
        assert_eq!(HashAlgorithm::XxHash3_64.output_size(), 8);
        assert_eq!(HashAlgorithm::XxHash3_128.output_size(), 16);
        assert_eq!(HashAlgorithm::Ascon.output_size(), 32);
        assert_eq!(HashAlgorithm::K12.output_size(), 32);
    }

    #[test]
    fn test_crc32() {
        let data = b"hello world";
        let result = hash(data, HashAlgorithm::Crc32);
        assert_eq!(result.len(), 4);
        // CRC32 is deterministic
        let result2 = hash(data, HashAlgorithm::Crc32);
        assert_eq!(result, result2);
    }

    #[test]
    fn test_crc32c() {
        let data = b"hello world";
        let result = hash(data, HashAlgorithm::Crc32c);
        assert_eq!(result.len(), 4);
    }

    #[test]
    fn test_crc16() {
        let data = b"hello world";
        let result = hash(data, HashAlgorithm::Crc16);
        assert_eq!(result.len(), 2);
    }

    #[test]
    fn test_crc64() {
        let data = b"hello world";
        let result = hash(data, HashAlgorithm::Crc64);
        assert_eq!(result.len(), 8);
    }

    #[test]
    fn test_xxhash32() {
        let data = b"hello world";
        let result = hash(data, HashAlgorithm::XxHash32);
        assert_eq!(result.len(), 4);
        // xxHash is deterministic with same seed
        let result2 = hash(data, HashAlgorithm::XxHash32);
        assert_eq!(result, result2);
    }

    #[test]
    fn test_xxhash64() {
        let data = b"hello world";
        let result = hash(data, HashAlgorithm::XxHash64);
        assert_eq!(result.len(), 8);
    }

    #[test]
    fn test_xxhash3_64() {
        let data = b"hello world";
        let result = hash(data, HashAlgorithm::XxHash3_64);
        assert_eq!(result.len(), 8);
    }

    #[test]
    fn test_xxhash3_128() {
        let data = b"hello world";
        let result = hash(data, HashAlgorithm::XxHash3_128);
        assert_eq!(result.len(), 16);
    }

    #[test]
    fn test_xxhash_config_default() {
        let config = XxHashConfig::default();
        assert_eq!(config.seed, 0);
        assert!(config.secret.is_none());
    }

    #[test]
    fn test_xxhash_config_secret_too_short() {
        let result = XxHashConfig::with_secret(0, vec![0u8; 100]);
        assert!(result.is_err());
        assert!(result.unwrap_err().contains("136 bytes"));
    }

    #[test]
    fn test_xxhash_config_secret_valid() {
        let result = XxHashConfig::with_secret(42, vec![0u8; 136]);
        assert!(result.is_ok());
        let config = result.unwrap();
        assert_eq!(config.seed, 42);
        assert_eq!(config.secret.as_ref().unwrap().len(), 136);
    }

    #[test]
    fn test_hash_seed_changes_output() {
        let data = b"test";
        let h1 = hash_with_config(data, HashAlgorithm::XxHash64, &XxHashConfig::with_seed(0));
        let h2 = hash_with_config(data, HashAlgorithm::XxHash64, &XxHashConfig::with_seed(42));
        assert_ne!(h1, h2);
    }

    #[test]
    fn test_backward_compatibility() {
        let data = b"test";
        let old = hash(data, HashAlgorithm::XxHash64);
        let new = hash_with_config(data, HashAlgorithm::XxHash64, &XxHashConfig::default());
        assert_eq!(old, new);
    }

    #[test]
    fn test_xxhash3_with_seed() {
        let data = b"test data for secret hashing";

        // Test that different seeds produce different hashes
        let h1 = hash_with_config(data, HashAlgorithm::XxHash3_64, &XxHashConfig::with_seed(0));
        let h2 = hash_with_config(
            data,
            HashAlgorithm::XxHash3_64,
            &XxHashConfig::with_seed(123),
        );
        assert_ne!(h1, h2, "Different seeds should produce different hashes");

        // Test that same seed produces same hash
        let h3 = hash_with_config(
            data,
            HashAlgorithm::XxHash3_64,
            &XxHashConfig::with_seed(123),
        );
        assert_eq!(h2, h3, "Same seed should produce same hash");
    }

    #[test]
    fn test_xxhash32_with_seed() {
        let data = b"test";
        let h1 = hash_with_config(data, HashAlgorithm::XxHash32, &XxHashConfig::with_seed(0));
        let h2 = hash_with_config(data, HashAlgorithm::XxHash32, &XxHashConfig::with_seed(999));
        assert_ne!(h1, h2);
    }

    #[test]
    fn test_ascon() {
        let data = b"hello world";
        let result = hash(data, HashAlgorithm::Ascon);
        assert_eq!(result.len(), 32);
        // Ascon is deterministic
        let result2 = hash(data, HashAlgorithm::Ascon);
        assert_eq!(result, result2);
    }

    #[test]
    fn test_k12() {
        let data = b"hello world";
        let result = hash(data, HashAlgorithm::K12);
        assert_eq!(result.len(), 32);
        // K12 is deterministic
        let result2 = hash(data, HashAlgorithm::K12);
        assert_eq!(result, result2);
    }
}