-
Notifications
You must be signed in to change notification settings - Fork 287
/
checksum_plugin_demo.h
716 lines (680 loc) · 26.4 KB
/
checksum_plugin_demo.h
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
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
//checksum_plugin_demo.h
// checksum plugin demo for HDiffz\HPatchz
/*
The MIT License (MIT)
Copyright (c) 2018-2021 HouSisong
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef HPatch_checksum_plugin_demo_h
#define HPatch_checksum_plugin_demo_h
//checksum plugin demo:
// crc32ChecksumPlugin
// adler32ChecksumPlugin
// adler64ChecksumPlugin
// fadler32ChecksumPlugin
// fadler64ChecksumPlugin
// fadler128ChecksumPlugin
// md5ChecksumPlugin
// blake3ChecksumPlugin
// sha256ChecksumPlugin
// sha512ChecksumPlugin
// xxh3ChecksumPlugin
// xxh128ChecksumPlugin
#include "libHDiffPatch/HPatch/checksum_plugin.h"
#ifndef _IsNeedIncludeDefaultChecksumHead
# define _IsNeedIncludeDefaultChecksumHead 1
#endif
#define __out_checksum4__(out_code,i0,v,shr) { \
(out_code)[i0 ]=(unsigned char)((v)>>(shr)); \
(out_code)[i0+1]=(unsigned char)((v)>>(shr+8)); \
(out_code)[i0+2]=(unsigned char)((v)>>(shr+16));\
(out_code)[i0+3]=(unsigned char)((v)>>(shr+24));\
}
#define __out_checksum4(out_code,v) __out_checksum4__(out_code,0,v,0)
#define __out_checksum8(out_code,v) { __out_checksum4__(out_code,0,v,0); \
__out_checksum4__(out_code,4,v,32); }
#ifdef _ChecksumPlugin_crc32
#if (_IsNeedIncludeDefaultChecksumHead)
# ifndef _IS_USED_LIBDEFLATE_CRC32
# define _IS_USED_LIBDEFLATE_CRC32 0
#endif
#if (_IS_USED_LIBDEFLATE_CRC32)
# include "libdeflate.h" // https://github.com/ebiggers/libdeflate
# else
# include "zlib.h" // http://zlib.net/ https://github.com/madler/zlib
# endif
#endif
#if (_IS_USED_LIBDEFLATE_CRC32)
# define _crc32 libdeflate_crc32
#else
# define _crc32 crc32
#endif
static const char* _crc32_checksumType(void){
static const char* type="crc32";
return type;
}
static size_t _crc32_checksumByteSize(void){
return sizeof(hpatch_uint32_t);
}
static hpatch_checksumHandle _crc32_open(hpatch_TChecksum* plugin){
return malloc(sizeof(hpatch_uint32_t));
}
static void _crc32_close(hpatch_TChecksum* plugin,hpatch_checksumHandle handle){
if (handle) free(handle);
}
static void _crc32_begin(hpatch_checksumHandle handle){
hpatch_uint32_t* pv=(hpatch_uint32_t*)handle;
*pv=(hpatch_uint32_t)_crc32(0,0,0);
}
static void _crc32_append(hpatch_checksumHandle handle,
const unsigned char* part_data,const unsigned char* part_data_end){
hpatch_uint32_t* pv=(hpatch_uint32_t*)handle;
#if (_IS_USED_LIBDEFLATE_CRC32)
*pv=_crc32(*pv,part_data,part_data_end-part_data);
#else
uLong v=*pv;
while (part_data!=part_data_end) {
size_t dataSize=(size_t)(part_data_end-part_data);
uInt len=~(uInt)0;
//assert(len>0);
if (len>dataSize)
len=(uInt)dataSize;
v=_crc32(v,part_data,len);
part_data+=len;
}
*pv=(hpatch_uint32_t)v;
#endif
}
static void _crc32_end(hpatch_checksumHandle handle,
unsigned char* checksum,unsigned char* checksum_end){
hpatch_uint32_t v=*(hpatch_uint32_t*)handle;
assert(4==checksum_end-checksum);
__out_checksum4(checksum,v);
}
static hpatch_TChecksum crc32ChecksumPlugin={ _crc32_checksumType,_crc32_checksumByteSize,_crc32_open,
_crc32_close,_crc32_begin,_crc32_append,_crc32_end};
#endif//_ChecksumPlugin_crc32
#ifdef _ChecksumPlugin_adler32
# ifndef _ChecksumPlugin_crc32
# include "libHDiffPatch/HDiff/private_diff/limit_mem_diff/adler_roll.h"
# endif
static const char* _adler32_checksumType(void){
static const char* type="adler32";
return type;
}
static size_t _adler32_checksumByteSize(void){
return sizeof(hpatch_uint32_t);
}
static hpatch_checksumHandle _adler32_open(hpatch_TChecksum* plugin){
return malloc(sizeof(hpatch_uint32_t));
}
static void _adler32_close(hpatch_TChecksum* plugin,hpatch_checksumHandle handle){
if (handle) free(handle);
}
static void _adler32_begin(hpatch_checksumHandle handle){
hpatch_uint32_t* pv=(hpatch_uint32_t*)handle;
#ifdef _ChecksumPlugin_crc32
*pv=(hpatch_uint32_t)adler32(0,0,0);
#else
*pv=adler32_start(0,0);
#endif
}
static void _adler32_append(hpatch_checksumHandle handle,
const unsigned char* part_data,const unsigned char* part_data_end){
hpatch_uint32_t* pv=(hpatch_uint32_t*)handle;
#ifdef _ChecksumPlugin_crc32
uLong v=*pv;
while (part_data!=part_data_end) {
size_t dataSize=(size_t)(part_data_end-part_data);
uInt len=~(uInt)0;
//assert(len>0);
if (len>dataSize)
len=(uInt)dataSize;
v=adler32(v,part_data,len);
part_data+=len;
}
*pv=(hpatch_uint32_t)v;
#else
*pv=_adler32_append(*pv,part_data,(size_t)(part_data_end-part_data));
#endif
}
static void _adler32_end(hpatch_checksumHandle handle,
unsigned char* checksum,unsigned char* checksum_end){
hpatch_uint32_t v=*(hpatch_uint32_t*)handle;
assert(4==checksum_end-checksum);
__out_checksum4(checksum,v);
}
static hpatch_TChecksum adler32ChecksumPlugin={ _adler32_checksumType,_adler32_checksumByteSize,_adler32_open,
_adler32_close,_adler32_begin,_adler32_append,_adler32_end};
#endif//_ChecksumPlugin_adler32
#ifdef _ChecksumPlugin_adler64
#include "libHDiffPatch/HDiff/private_diff/limit_mem_diff/adler_roll.h"
static const char* _adler64_checksumType(void){
static const char* type="adler64";
return type;
}
static size_t _adler64_checksumByteSize(void){
return sizeof(hpatch_uint64_t);
}
static hpatch_checksumHandle _adler64_open(hpatch_TChecksum* plugin){
return malloc(sizeof(hpatch_uint64_t));
}
static void _adler64_close(hpatch_TChecksum* plugin,hpatch_checksumHandle handle){
if (handle) free(handle);
}
static void _adler64_begin(hpatch_checksumHandle handle){
hpatch_uint64_t* pv=(hpatch_uint64_t*)handle;
*pv=adler64_start(0,0);
}
static void _adler64_append(hpatch_checksumHandle handle,
const unsigned char* part_data,const unsigned char* part_data_end){
hpatch_uint64_t* pv=(hpatch_uint64_t*)handle;
*pv=adler64_append(*pv,part_data,part_data_end-part_data);
}
static void _adler64_end(hpatch_checksumHandle handle,
unsigned char* checksum,unsigned char* checksum_end){
hpatch_uint64_t v=*(hpatch_uint64_t*)handle;
assert(8==checksum_end-checksum);
__out_checksum8(checksum,v);
}
static hpatch_TChecksum adler64ChecksumPlugin={ _adler64_checksumType,_adler64_checksumByteSize,_adler64_open,
_adler64_close,_adler64_begin,_adler64_append,_adler64_end};
#endif//_ChecksumPlugin_adler64
#ifdef _ChecksumPlugin_fadler32
#include "libHDiffPatch/HDiff/private_diff/limit_mem_diff/adler_roll.h"
static const char* _fadler32_checksumType(void){
static const char* type="fadler32";
return type;
}
static size_t _fadler32_checksumByteSize(void){
return sizeof(hpatch_uint32_t);
}
static hpatch_checksumHandle _fadler32_open(hpatch_TChecksum* plugin){
return malloc(sizeof(hpatch_uint32_t));
}
static void _fadler32_close(hpatch_TChecksum* plugin,hpatch_checksumHandle handle){
if (handle) free(handle);
}
static void _fadler32_begin(hpatch_checksumHandle handle){
hpatch_uint32_t* pv=(hpatch_uint32_t*)handle;
*pv=*pv=fast_adler32_start(0,0);
}
static void _fadler32_append(hpatch_checksumHandle handle,
const unsigned char* part_data,const unsigned char* part_data_end){
hpatch_uint32_t* pv=(hpatch_uint32_t*)handle;
*pv=fast_adler32_append(*pv,part_data,part_data_end-part_data);
}
static void _fadler32_end(hpatch_checksumHandle handle,
unsigned char* checksum,unsigned char* checksum_end){
hpatch_uint32_t v=*(hpatch_uint32_t*)handle;
assert(4==checksum_end-checksum);
__out_checksum4(checksum,v);
}
static hpatch_TChecksum fadler32ChecksumPlugin={ _fadler32_checksumType,_fadler32_checksumByteSize,_fadler32_open,
_fadler32_close,_fadler32_begin,_fadler32_append,_fadler32_end};
#endif//_ChecksumPlugin_fadler32
#ifdef _ChecksumPlugin_fadler64
#include "libHDiffPatch/HDiff/private_diff/limit_mem_diff/adler_roll.h"
static const char* _fadler64_checksumType(void){
static const char* type="fadler64";
return type;
}
static size_t _fadler64_checksumByteSize(void){
return sizeof(hpatch_uint64_t);
}
static hpatch_checksumHandle _fadler64_open(hpatch_TChecksum* plugin){
return malloc(sizeof(hpatch_uint64_t));
}
static void _fadler64_close(hpatch_TChecksum* plugin,hpatch_checksumHandle handle){
if (handle) free(handle);
}
static void _fadler64_begin(hpatch_checksumHandle handle){
hpatch_uint64_t* pv=(hpatch_uint64_t*)handle;
*pv=fast_adler64_start(0,0);
}
static void _fadler64_append(hpatch_checksumHandle handle,
const unsigned char* part_data,const unsigned char* part_data_end){
hpatch_uint64_t* pv=(hpatch_uint64_t*)handle;
*pv=fast_adler64_append(*pv,part_data,part_data_end-part_data);
}
static void _fadler64_end(hpatch_checksumHandle handle,
unsigned char* checksum,unsigned char* checksum_end){
hpatch_uint64_t v=*(hpatch_uint64_t*)handle;
assert(8==checksum_end-checksum);
__out_checksum8(checksum,v);
}
static hpatch_TChecksum fadler64ChecksumPlugin={ _fadler64_checksumType,_fadler64_checksumByteSize,_fadler64_open,
_fadler64_close,_fadler64_begin,_fadler64_append,_fadler64_end};
#endif//_ChecksumPlugin_fadler64
#ifdef _ChecksumPlugin_fadler128
#include "libHDiffPatch/HDiff/private_diff/limit_mem_diff/adler_roll.h"
static const char* _fadler128_checksumType(void){
static const char* type="fadler128";
return type;
}
static size_t _fadler128_checksumByteSize(void){
return sizeof(adler128_t);
}
static hpatch_checksumHandle _fadler128_open(hpatch_TChecksum* plugin){
return malloc(sizeof(adler128_t));
}
static void _fadler128_close(hpatch_TChecksum* plugin,hpatch_checksumHandle handle){
if (handle) free(handle);
}
static void _fadler128_begin(hpatch_checksumHandle handle){
adler128_t* pv=(adler128_t*)handle;
*pv=fast_adler128_start(0,0);
}
static void _fadler128_append(hpatch_checksumHandle handle,
const unsigned char* part_data,const unsigned char* part_data_end){
adler128_t* pv=(adler128_t*)handle;
*pv=fast_adler128_append(*pv,part_data,part_data_end-part_data);
}
static void _fadler128_end(hpatch_checksumHandle handle,
unsigned char* checksum,unsigned char* checksum_end){
const adler128_t* pv=(const adler128_t*)handle;
assert(16==checksum_end-checksum);
__out_checksum8(checksum,pv->adler);
__out_checksum8(checksum+8,pv->sum);
}
static hpatch_TChecksum fadler128ChecksumPlugin={ _fadler128_checksumType,_fadler128_checksumByteSize,
_fadler128_open,_fadler128_close,_fadler128_begin,_fadler128_append,_fadler128_end};
#endif//_ChecksumPlugin_fadler128
#ifdef _ChecksumPlugin_md5
#if (_IsNeedIncludeDefaultChecksumHead)
# include "md5.h" // https://sourceforge.net/projects/libmd5-rfc https://github.com/sisong/libmd5
#endif
static const char* _md5_checksumType(void){
static const char* type="md5";
return type;
}
static size_t _md5_checksumByteSize(void){
return 16;
}
static hpatch_checksumHandle _md5_open(hpatch_TChecksum* plugin){
return malloc(sizeof(md5_state_t));
}
static void _md5_close(hpatch_TChecksum* plugin,hpatch_checksumHandle handle){
if (handle) free(handle);
}
static void _md5_begin(hpatch_checksumHandle handle){
md5_state_t* ps=(md5_state_t*)handle;
md5_init(ps);
}
static void _md5_append(hpatch_checksumHandle handle,
const unsigned char* part_data,const unsigned char* part_data_end){
md5_state_t* ps=(md5_state_t*)handle;
while (part_data!=part_data_end) {
size_t dataSize=(size_t)(part_data_end-part_data);
int len=(int)((~(unsigned int)0)>>1);
//assert(len>0);
if ((unsigned int)len>dataSize)
len=(int)dataSize;
md5_append(ps,part_data,len);
part_data+=len;
}
}
static void _md5_end(hpatch_checksumHandle handle,
unsigned char* checksum,unsigned char* checksum_end){
md5_state_t* ps=(md5_state_t*)handle;
assert(16==checksum_end-checksum);
md5_finish(ps,checksum);
}
static hpatch_TChecksum md5ChecksumPlugin={ _md5_checksumType,_md5_checksumByteSize,_md5_open,
_md5_close,_md5_begin,_md5_append,_md5_end};
#endif//_ChecksumPlugin_md5
#ifdef _ChecksumPlugin_blake3
#if (_IsNeedIncludeDefaultChecksumHead)
# include "blake3.h" // https://github.com/BLAKE3-team/BLAKE3
#endif
static const char* _blake3_checksumType(void){
static const char* type="blake3";
return type;
}
static size_t _blake3_checksumByteSize(void){
return BLAKE3_OUT_LEN;
}
static hpatch_checksumHandle _blake3_open(hpatch_TChecksum* plugin){
return malloc(sizeof(blake3_hasher));
}
static void _blake3_close(hpatch_TChecksum* plugin,hpatch_checksumHandle handle){
if (handle) free(handle);
}
static void _blake3_begin(hpatch_checksumHandle handle){
blake3_hasher* ps=(blake3_hasher*)handle;
blake3_hasher_init(ps);
}
static void _blake3_append(hpatch_checksumHandle handle,
const unsigned char* part_data,const unsigned char* part_data_end){
blake3_hasher* ps=(blake3_hasher*)handle;
blake3_hasher_update(ps,part_data,(size_t)(part_data_end-part_data));
}
static void _blake3_end(hpatch_checksumHandle handle,
unsigned char* checksum,unsigned char* checksum_end){
blake3_hasher* ps=(blake3_hasher*)handle;
assert(BLAKE3_OUT_LEN==checksum_end-checksum);
blake3_hasher_finalize(ps,checksum,(size_t)(checksum_end-checksum));
}
static hpatch_TChecksum blake3ChecksumPlugin={ _blake3_checksumType,_blake3_checksumByteSize,_blake3_open,
_blake3_close,_blake3_begin,_blake3_append,_blake3_end};
#endif//_ChecksumPlugin_blake3
#ifdef _ChecksumPlugin_curl_md5
#if (_IsNeedIncludeDefaultChecksumHead)
#ifdef __cplusplus
extern "C" {
#endif
# include "curl_md5.h" // https://github.com/curl/curl/blob/master/lib/curl_md5.h
#ifdef __cplusplus
}
#endif
#endif
static const struct MD5_params* _curl_MD5_params=&Curl_DIGEST_MD5[0];
static const char* _md5_checksumType(void){
static const char* type="md5";
return type;
}
static size_t _md5_checksumByteSize(void){
return _curl_MD5_params->md5_resultlen;
}
static hpatch_checksumHandle _md5_open(hpatch_TChecksum* plugin){
return malloc(_curl_MD5_params->md5_ctxtsize);
}
static void _md5_close(hpatch_TChecksum* plugin,hpatch_checksumHandle handle){
if (handle) free(handle);
}
static void _md5_begin(hpatch_checksumHandle handle){
CURLcode ret=_curl_MD5_params->md5_init_func(handle);
assert(ret==CURLE_OK);
}
static void _md5_append(hpatch_checksumHandle handle,
const unsigned char* part_data,const unsigned char* part_data_end){
while (part_data!=part_data_end) {
size_t dataSize=(size_t)(part_data_end-part_data);
int len=(int)((~(unsigned int)0)>>1);
//assert(len>0);
if ((unsigned int)len>dataSize)
len=(int)dataSize;
_curl_MD5_params->md5_update_func(handle,part_data,len);
part_data+=len;
}
}
static void _md5_end(hpatch_checksumHandle handle,
unsigned char* checksum,unsigned char* checksum_end){
assert(_curl_MD5_params->md5_resultlen==checksum_end-checksum);
_curl_MD5_params->md5_final_func(checksum,handle);
}
static hpatch_TChecksum md5ChecksumPlugin={ _md5_checksumType,_md5_checksumByteSize,_md5_open,
_md5_close,_md5_begin,_md5_append,_md5_end};
#endif//_ChecksumPlugin_curl_md5
#ifdef _ChecksumPlugin_curl_sha256
#if (_IsNeedIncludeDefaultChecksumHead)
#ifdef __cplusplus
extern "C" {
#endif
# include "curl_sha256.h" // https://github.com/curl/curl/blob/master/lib/curl_sha256.h
#ifdef __cplusplus
}
#endif
#endif
static const struct HMAC_params* _curl_sha256_params=&Curl_HMAC_SHA256[0];
static const char* _sha256_checksumType(void){
static const char* type="sha256";
return type;
}
static size_t _sha256_checksumByteSize(void){
return _curl_sha256_params->hmac_resultlen;
}
static hpatch_checksumHandle _sha256_open(hpatch_TChecksum* plugin){
return malloc(_curl_sha256_params->hmac_ctxtsize);
}
static void _sha256_close(hpatch_TChecksum* plugin,hpatch_checksumHandle handle){
if (handle) free(handle);
}
static void _sha256_begin(hpatch_checksumHandle handle){
CURLcode ret=_curl_sha256_params->hmac_hinit(handle);
assert(ret==CURLE_OK);
}
static void _sha256_append(hpatch_checksumHandle handle,
const unsigned char* part_data,const unsigned char* part_data_end){
while (part_data!=part_data_end) {
size_t dataSize=(size_t)(part_data_end-part_data);
int len=(int)((~(unsigned int)0)>>1);
//assert(len>0);
if ((unsigned int)len>dataSize)
len=(int)dataSize;
_curl_sha256_params->hmac_hupdate(handle,part_data,len);
part_data+=len;
}
}
static void _sha256_end(hpatch_checksumHandle handle,
unsigned char* checksum,unsigned char* checksum_end){
assert(_curl_sha256_params->hmac_resultlen==checksum_end-checksum);
_curl_sha256_params->hmac_hfinal(checksum,handle);
}
static hpatch_TChecksum sha256ChecksumPlugin={ _sha256_checksumType,_sha256_checksumByteSize,_sha256_open,
_sha256_close,_sha256_begin,_sha256_append,_sha256_end};
#endif//_ChecksumPlugin_curl_sha256
#ifdef _ChecksumPlugin_mbedtls_md5
#if (_IsNeedIncludeDefaultChecksumHead)
#ifdef __cplusplus
extern "C" {
#endif
# include "mbedtls/md5.h" // https://github.com/ARMmbed/mbedtls/blob/master/include/mbedtls/md5.h
#ifdef __cplusplus
}
#endif
#endif
static const char* _md5_checksumType(void){
static const char* type="md5";
return type;
}
static size_t _md5_checksumByteSize(void){
return 16;
}
static hpatch_checksumHandle _md5_open(hpatch_TChecksum* plugin){
return malloc(sizeof(mbedtls_md5_context));
}
static void _md5_close(hpatch_TChecksum* plugin,hpatch_checksumHandle handle){
if (handle) free(handle);
}
static void _md5_begin(hpatch_checksumHandle handle){
mbedtls_md5_init((mbedtls_md5_context*)handle);
mbedtls_md5_starts_ret((mbedtls_md5_context*)handle);
}
static void _md5_append(hpatch_checksumHandle handle,
const unsigned char* part_data,const unsigned char* part_data_end){
mbedtls_md5_update_ret((mbedtls_md5_context*)handle,part_data,part_data_end-part_data);
}
static void _md5_end(hpatch_checksumHandle handle,
unsigned char* checksum,unsigned char* checksum_end){
assert(16==checksum_end-checksum);
mbedtls_md5_finish_ret((mbedtls_md5_context*)handle,checksum);
}
static hpatch_TChecksum md5ChecksumPlugin={ _md5_checksumType,_md5_checksumByteSize,_md5_open,
_md5_close,_md5_begin,_md5_append,_md5_end};
#endif//_ChecksumPlugin_mbedtls_md5
#ifdef _ChecksumPlugin_mbedtls_sha256
#if (_IsNeedIncludeDefaultChecksumHead)
#ifdef __cplusplus
extern "C" {
#endif
# include "mbedtls/sha256.h" // https://github.com/ARMmbed/mbedtls/blob/master/include/mbedtls/sha256.h
#ifdef __cplusplus
}
#endif
#endif
static const char* _sha256_checksumType(void){
static const char* type="sha256";
return type;
}
static size_t _sha256_checksumByteSize(void){
return 32;
}
static hpatch_checksumHandle _sha256_open(hpatch_TChecksum* plugin){
return malloc(sizeof(mbedtls_sha256_context));
}
static void _sha256_close(hpatch_TChecksum* plugin,hpatch_checksumHandle handle){
if (handle) free(handle);
}
static void _sha256_begin(hpatch_checksumHandle handle){
mbedtls_sha256_init((mbedtls_sha256_context*)handle);
mbedtls_sha256_starts_ret((mbedtls_sha256_context*)handle,0);
}
static void _sha256_append(hpatch_checksumHandle handle,
const unsigned char* part_data,const unsigned char* part_data_end){
mbedtls_sha256_update_ret((mbedtls_sha256_context*)handle,part_data,part_data_end-part_data);
}
static void _sha256_end(hpatch_checksumHandle handle,
unsigned char* checksum,unsigned char* checksum_end){
assert(32==checksum_end-checksum);
mbedtls_sha256_finish_ret((mbedtls_sha256_context*)handle,checksum);
}
static hpatch_TChecksum sha256ChecksumPlugin={ _sha256_checksumType,_sha256_checksumByteSize,_sha256_open,
_sha256_close,_sha256_begin,_sha256_append,_sha256_end};
#endif//_ChecksumPlugin_mbedtls_sha256
#ifdef _ChecksumPlugin_mbedtls_sha512
#if (_IsNeedIncludeDefaultChecksumHead)
#ifdef __cplusplus
extern "C" {
#endif
# include "mbedtls/sha512.h" // https://github.com/ARMmbed/mbedtls/blob/master/include/mbedtls/sha512.h
#ifdef __cplusplus
}
#endif
#endif
static const char* _sha512_checksumType(void){
static const char* type="sha512";
return type;
}
static size_t _sha512_checksumByteSize(void){
return 64;
}
static hpatch_checksumHandle _sha512_open(hpatch_TChecksum* plugin){
return malloc(sizeof(mbedtls_sha512_context));
}
static void _sha512_close(hpatch_TChecksum* plugin,hpatch_checksumHandle handle){
if (handle) free(handle);
}
static void _sha512_begin(hpatch_checksumHandle handle){
mbedtls_sha512_init((mbedtls_sha512_context*)handle);
mbedtls_sha512_starts_ret((mbedtls_sha512_context*)handle,0);
}
static void _sha512_append(hpatch_checksumHandle handle,
const unsigned char* part_data,const unsigned char* part_data_end){
mbedtls_sha512_update_ret((mbedtls_sha512_context*)handle,part_data,part_data_end-part_data);
}
static void _sha512_end(hpatch_checksumHandle handle,
unsigned char* checksum,unsigned char* checksum_end){
assert(64==checksum_end-checksum);
mbedtls_sha512_finish_ret((mbedtls_sha512_context*)handle,checksum);
}
static hpatch_TChecksum sha512ChecksumPlugin={ _sha512_checksumType,_sha512_checksumByteSize,_sha512_open,
_sha512_close,_sha512_begin,_sha512_append,_sha512_end};
#endif//_ChecksumPlugin_mbedtls_sha512
#ifdef _ChecksumPlugin_xxh3
#if (_IsNeedIncludeDefaultChecksumHead)
#ifdef __cplusplus
extern "C" {
#endif
# include "xxh3.h" // https://github.com/Cyan4973/xxHash/blob/master/xxh3.h
#ifdef __cplusplus
}
#endif
#endif
static const char* _xxh3_checksumType(void){
static const char* type="xxh3";
return type;
}
static size_t _xxh3_checksumByteSize(void){
return 8;
}
static hpatch_checksumHandle _xxh3_open(hpatch_TChecksum* plugin){
return XXH3_createState();
}
static void _xxh3_close(hpatch_TChecksum* plugin,hpatch_checksumHandle handle){
if (handle){
XXH_errorcode ret=XXH3_freeState((XXH3_state_t*)handle);
assert(ret==XXH_OK);
}
}
static void _xxh3_begin(hpatch_checksumHandle handle){
XXH_errorcode ret=XXH3_64bits_reset((XXH3_state_t*)handle);
assert(ret==XXH_OK);
}
static void _xxh3_append(hpatch_checksumHandle handle,
const unsigned char* part_data,const unsigned char* part_data_end){
XXH_errorcode ret=XXH3_64bits_update((XXH3_state_t*)handle,part_data,part_data_end-part_data);
assert(ret==XXH_OK);
}
static void _xxh3_end(hpatch_checksumHandle handle,
unsigned char* checksum,unsigned char* checksum_end){
assert(8==checksum_end-checksum);
XXH64_hash_t h64=XXH3_64bits_digest((XXH3_state_t*)handle);
XXH_writeLE64(checksum,h64);
}
static hpatch_TChecksum xxh3ChecksumPlugin={ _xxh3_checksumType,_xxh3_checksumByteSize,_xxh3_open,
_xxh3_close,_xxh3_begin,_xxh3_append,_xxh3_end};
#endif//_ChecksumPlugin_xxh3
#ifdef _ChecksumPlugin_xxh128
#if (_IsNeedIncludeDefaultChecksumHead)
#ifdef __cplusplus
extern "C" {
#endif
# include "xxh3.h" // https://github.com/Cyan4973/xxHash/blob/master/xxh3.h
#ifdef __cplusplus
}
#endif
#endif
static const char* _xxh128_checksumType(void){
static const char* type="xxh128";
return type;
}
static size_t _xxh128_checksumByteSize(void){
return 16;
}
static hpatch_checksumHandle _xxh128_open(hpatch_TChecksum* plugin){
return XXH3_createState();
}
static void _xxh128_close(hpatch_TChecksum* plugin,hpatch_checksumHandle handle){
if (handle){
XXH_errorcode ret=XXH3_freeState((XXH3_state_t*)handle);
assert(ret==XXH_OK);
}
}
static void _xxh128_begin(hpatch_checksumHandle handle){
XXH_errorcode ret=XXH3_128bits_reset((XXH3_state_t*)handle);
assert(ret==XXH_OK);
}
static void _xxh128_append(hpatch_checksumHandle handle,
const unsigned char* part_data,const unsigned char* part_data_end){
XXH_errorcode ret=XXH3_128bits_update((XXH3_state_t*)handle,part_data,part_data_end-part_data);
assert(ret==XXH_OK);
}
static void _xxh128_end(hpatch_checksumHandle handle,
unsigned char* checksum,unsigned char* checksum_end){
assert(16==checksum_end-checksum);
XXH128_hash_t h128=XXH3_128bits_digest((XXH3_state_t*)handle);
XXH_writeLE64(checksum,h128.low64);
XXH_writeLE64(checksum+8,h128.high64);
}
static hpatch_TChecksum xxh128ChecksumPlugin={ _xxh128_checksumType,_xxh128_checksumByteSize,_xxh128_open,
_xxh128_close,_xxh128_begin,_xxh128_append,_xxh128_end};
#endif//_ChecksumPlugin_xxh128
#endif