/
CRC.pm6
913 lines (596 loc) · 24.6 KB
/
CRC.pm6
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
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
use Sum;
=begin pod
=head1 NAME
Sum::CRC
=head1 SYNOPSIS
=end pod
=begin pod
=head1 DESCRIPTION
The C<Sum::CRC> module provides roles for generating types of C<Sum>
that calculate a cyclic redundancy checksum. Many subroles are provided
for convenient access to well-standardized CRC parameter sets.
The base C<Sum::CRC> role variant is a bitwise implementation which
focuses on versatility. Based on the parameters used, alternate optimized
implementations may be composed instead (when they are eventually
implemented.) In some cases, forcing the use of optimizations may
require providing additional parameters.
=head1 ROLES
=head2 role Sum::CRC [ :@header?, :@footer?, :$residual = 0,
:$iniv = Bool::False, :$finv = Bool::False,
:$columns = 8, :$poly, :$reflect = Bool::False ]
does Sum does Sum::Partial
The C<Sum::CRC> parametric role is used to create a type of C<Sum>
that calculates a particular kind of cyclic redundancy checksum
based on the provided parameters. The resulting C<Sum> expects
single bit addends and will simply check the truth value of each
provided addend, unless a C<Sum::Marshal> role is mixed in.
The C<$columns> parameter specifies the number of bits in the final
checksum, and thus also the number of bits in many of the other
parameters.
The C<$poly> parameter defines the generator polynomial. The
format should be an integer where each bit represents a coefficient,
least significant coefficient mapped to least significant bit, with the
most significant term's coefficient truncated. The most significant
term is deduced from C<$columns> and is assumed to have a coefficient
of 1. This is sometimes called the "MSB-first code" or "normal code"
for a generator polynomial.
When C<:reflect> is specified, the remainder is swabbed bitwise
to produce final results. To swab input addends, mix in
appropriate C<Sum::Marshal> role(s) such as a C<Sum::Marshal::Bits>.
When C<:finv> is specified, the final result is bitwise inverted.
When a non-boolean value is specified for C<$finv>, the remainder
and this value are combined in a bitwise XOR when a result is
finalized. This happens after C<:reflect> swabbing, if any.
When C<:iniv> is specified, the remainder is set to all 1s at the
start of the checksum. When a non-boolean value is specified for
C<$iniv>, the remainder is initialized to the provided value.
This value is not adjusted to accomodate any C<:reflect> swabbing.
Note that a non-boolean value passed in C<:iniv> is assigned directly
to the remainder, which is not a typed attribute, so the value type is
assigned along with the value. This is left this way to provide
optimization flexibility, but is a potential gotcha if one were to
provide a type narrower than C<$columns> bits or which does not support
the required bitwise operations. Likewise a non-boolean value
provided in C<:finv> is used directly. When in doubt, coerce such
values to Int.
When C<@header> is provided, the addends it contains are provided
to the sum immediately upon initialization, after the remainder
is initialized according to the value of C<$iniv>. When C<@footer>
is provided, the addends it contains are provided to the sum before
a final result is produced. As partial sums are supported, the
remainder is then restored such that more addends may be provided.
Both C<@header> and C<@footer> are subject to the same marshalling
as provided by any C<Sum::Marshal> roles for normal addends.
The C<$residual> parameter is used in the C<.check> method, described
below.
=head2 METHODS
=head3 method check(*@addends)
The check method is intended to be used when verifying data
that includes an embedded precaculated CRC, such that the
sum of the original data and the CRC should produce a constant.
This method simply calls C<.finalize> and, if that succeeds,
returns C<True> if the resulting value is the same as the value
provided to the role in the C<$residual> role parameter.
=end pod
role Sum::CRC [ :@header?, :@footer?, :$residual = 0,
:$iniv = Bool::False, :$finv = Bool::False,
:$columns = 8, :$poly, :$reflect = Bool::False ]
does Sum does Sum::Partial {
# Eventually we want $.rem's type (from :iniv when not Bool)
# to be predictable enough for optimization, and really it
# should only be rw from inside the class.
has $.rem is rw = ( ($iniv.WHAT === Bool) ?? (-$iniv +& ((1 +< $columns) - 1)) !! $iniv );
method add (*@addends) {
for (@addends) -> $a {
my $b = $.rem +& (1 +< ($columns - 1));
$.rem +<= 1;
$.rem +&= (1 +< $columns) - 1;
$.rem +^= $poly if $a xor $b;
}
};
method finalize(*@addends) {
self.push(@addends);
my $rev = $.rem;
if (+@footer) {
my $c = self.clone();
$c.push(@footer);
$rev = $c.rem;
}
if ($reflect) {
my $rev2 = $rev +& 0; # Think types.
for (1 «+<« [0 ..^ $columns]) {
$rev2 +<= 1;
$rev2 +|= 1 if $rev +& $_;
}
$rev = $rev2;
}
if ($finv) {
return $rev +^ ((1 +< $columns) - 1) if ($finv.WHAT === Bool);
return $rev +^ $finv;
}
return $rev;
}
method Numeric () { self.finalize };
method check(*@addends) {
given self.finalize(@addends) {
when Failure { return $_ };
default { return so $_ == $residual };
}
}
}
=begin pod
=head2 role Sum::CRC_3_ROHC
does Sum::CRC[ :reflect, :columns(3), :poly(0x3) ]
Implements a 3-bit CRC used in RFC 3095 header compression.
=end pod
# Note that the reveng catalogue seems to have :iniv but the checksum
# presented for the test vector there works for :!iniv
role Sum::CRC_3_ROHC
does Sum::CRC[ :reflect, :columns(3), :poly(0x3) ] { }
=begin pod
=head2 role Sum::CRC_4_ITU
does Sum::CRC[ :reflect, :columns(4), :poly(0x3) ]
Implements a 4-bit CRC used in ITU G.704
=end pod
role Sum::CRC_4_ITU
does Sum::CRC[ :reflect, :columns(4), :poly(0x3) ] { }
=begin pod
=head2 role Sum::CRC_5_EPC
does Sum::CRC[ :iniv(9), :columns(5), :poly(0x9) ]
Implements a 5-bit CRC used in RFID.
=end pod
role Sum::CRC_5_EPC
does Sum::CRC[ :iniv(9), :columns(5), :poly(0x9) ] { }
=begin pod
=head2 role Sum::CRC_5_ITU
does Sum::CRC[ :reflect, :columns(5), :poly(0x15) ]
Implements a 5-bit CRC used in ITU G.704
=end pod
role Sum::CRC_5_ITU
does Sum::CRC[ :reflect, :columns(5), :poly(0x15) ] { }
=begin pod
=head2 role Sum::CRC_5_USB
does Sum::CRC[ :iniv, :finv, :columns(5), :poly(0x5),
:residual(0x13) ]
Implements a 5-bit CRC used in the USB protocol.
=end pod
role Sum::CRC_5_USB
does Sum::CRC[ :iniv, :finv, :columns(5), :poly(0x5),
:residual(0x13) ] { }
=begin pod
=head2 role Sum::CRC_6_DARC
does Sum::CRC[ :reflect, :columns(6), :poly(0x19) ]
Implements a 6-bit CRC used in the DARC radio protocol.
=end pod
role Sum::CRC_6_DARC
does Sum::CRC[ :reflect, :columns(6), :poly(0x19) ] { }
=begin pod
=head2 role Sum::CRC_6_ITU
does Sum::CRC[ :reflect, :columns(6), :poly(0x3) ]
Implements a 6-bit CRC used in ITU G.704
=end pod
role Sum::CRC_6_ITU
does Sum::CRC[ :reflect, :columns(6), :poly(0x3) ] { }
=begin pod
=head2 role Sum::CRC_7_JEDEC
does Sum::CRC[ :columns(7), :poly(0x9) ]
Implements a 7-bit CRC used in JEDEC multimedia cards.
=end pod
role Sum::CRC_7_JEDEC
does Sum::CRC[ :columns(7), :poly(0x9) ] { }
=begin pod
=head2 role Sum::CRC_7_ROHC
does Sum::CRC[ :reflect, :iniv, :columns(7), :poly(0x4f) ]
Implements a 7-bit CRC used in RFC 3095 header compression.
=end pod
role Sum::CRC_7_ROHC
does Sum::CRC[ :reflect, :iniv, :columns(7), :poly(0x4f) ] { }
=begin pod
=head2 role Sum::CRC_8_CCITT
does Sum::CRC[ :columns(8), :poly(0x7) ] { }
Implements a standardized 8-bit CRC used e.g. in SmBus.
=end pod
role Sum::CRC_8_CCITT
does Sum::CRC[ :columns(8), :poly(0x7) ] { }
=begin pod
=head2 role Sum::CRC_8_DARC
does Sum::CRC[ :reflect, :columns(8), :poly(0x39) ]
Implements an 8-bit CRC used in the DARC radio protocol.
=end pod
role Sum::CRC_8_DARC
does Sum::CRC[ :reflect, :columns(8), :poly(0x39) ] { }
=begin pod
=head2 role Sum::CRC_8_EBU
does Sum::CRC[ :reflect, :iniv, :columns(8), :poly(0x1d) ] { }
Implements an 8-bit CRC used in european digital audio
=end pod
role Sum::CRC_8_EBU
does Sum::CRC[ :reflect, :iniv, :columns(8), :poly(0x1d) ] { }
=begin pod
=head2 role Sum::CRC_8_I_CODE
does Sum::CRC[ :iniv(0xfd), :columns(8), :poly(0x1d) ] { }
Implements an 8-bit CRC used in I-CODE labels.
=end pod
role Sum::CRC_8_I_CODE
does Sum::CRC[ :iniv(0xfd), :columns(8), :poly(0x1d) ] { }
=begin pod
=head2 role Sum::CRC_8_ITU
does Sum::CRC[ :finv(0x55), :columns(8), :poly(0x7), :residual(0xf9) ]
Implements an 8-bit CRC used in ATM HEC codes.
=end pod
role Sum::CRC_8_ITU
does Sum::CRC[ :finv(0x55), :columns(8), :poly(0x7), :residual(0xf9) ] { }
=begin pod
=head2 role Sum::CRC_8_1_Wire
does Sum::CRC[ :reflect, :columns(8), :poly(0x31) ] { }
Implements an 8-bit CRC used in the 1-Wire bus standard.
=end pod
role Sum::CRC_8_1_Wire
does Sum::CRC[ :reflect, :columns(8), :poly(0x31) ] { }
=begin pod
=head2 role Sum::CRC_8_ROHC
does Sum::CRC[ :reflect, :iniv, :columns(8), :poly(0x7) ]
Implements an 8-bit CRC used in RFC 3095 header compression.
=end pod
role Sum::CRC_8_ROHC
does Sum::CRC[ :reflect, :iniv, :columns(8), :poly(0x7) ] { }
=begin pod
=head2 role Sum::CRC_8_WCDMA
does Sum::CRC[ :reflect, :columns(8), :poly(0x9b) ] { }
Implements an 8-bit CRC used in WDCMA wireless protocol.
=end pod
role Sum::CRC_8_WCDMA
does Sum::CRC[ :reflect, :columns(8), :poly(0x9b) ] { }
=begin pod
=head2 role Sum::CRC_8_SAE_J1850
does Sum::CRC[ :iniv, :finv, :columns(8), :poly(0x1d),
:residual(0x3b) ] { }
Implements an 8-bit CRC used on the SAE J1850 automotive data bus.
=end pod
# Note that the AUTOSAR document incorrectly says :iniv(0), :finv(0) but
# then it goes on to give a test vector that is valid when :iniv, :finv
role Sum::CRC_8_SAE_J1850
does Sum::CRC[ :iniv, :finv, :columns(8), :poly(0x1d),
:residual(0x3b) ] { }
=begin pod
=head2 role Sum::CRC_8_AUTOSAR
does Sum::CRC[ :iniv, :finv, :columns(8), :poly(0x2f),
:residual(0xbd) ]
Implements an 8-bit CRC used in automotive applications.
=end pod
role Sum::CRC_8_AUTOSAR
does Sum::CRC[ :iniv, :finv, :columns(8), :poly(0x2f),
:residual(0xbd) ] { }
# Koopman suggestion. Need to look for test vectors / 3rd party implementation
#role Sum::CRC_8K
# does Sum::CRC[ :columns(8), :poly(0xd5) ] { }
=begin pod
=head2 role Sum::CRC_10_AAL
does Sum::CRC[ :columns(10), :poly(0x233) ]
Implements a 10-bit CRC used in ATM AAL 3/4.
=end pod
role Sum::CRC_10_AAL
does Sum::CRC[ :columns(10), :poly(0x233) ] { }
=begin pod
=head2 role Sum::CRC_11_FlexRay
does Sum::CRC[ :iniv(0x1a), :columns(11), :poly(0x385) ]
Implements an 11-bit CRC used in FlexRay automotive systems.
=end pod
role Sum::CRC_11_FlexRay
does Sum::CRC[ :iniv(0x1a), :columns(11), :poly(0x385) ] { }
=begin pod
=head2 role Sum::CRC_12_3GPP
does Sum::CRC[ :reflect, :columns(12), :poly(0x80f) ]
Implements a 12-bit CRC used in 3G mobile systems.
=end pod
role Sum::CRC_12_3GPP
does Sum::CRC[ :reflect, :columns(12), :poly(0x80f) ] { }
=begin pod
=head2 role Sum::CRC_12_DECT
does Sum::CRC[ :columns(12), :poly(0x80f) ]
Implements a 12-bit CRC used in Digital Enhanced Cordless
Telecommunications.
=end pod
role Sum::CRC_12_DECT
does Sum::CRC[ :columns(12), :poly(0x80f) ] { }
=begin pod
=head2 role Sum::CRC_14_DARC
does Sum::CRC[ :reflect, :columns(14), :poly(0x805) ]
Implements a 14-bit CRC used in Digital Radio Communications.
=end pod
role Sum::CRC_14_DARC
does Sum::CRC[ :reflect, :columns(14), :poly(0x805) ] { }
=begin pod
=head2 role Sum::CRC_15_CAN
does Sum::CRC[ :columns(15), :poly(0x4599) ]
Implements a 15-bit CRC used in the Controller Area Network protocol.
=end pod
role Sum::CRC_15_CAN
does Sum::CRC[ :columns(15), :poly(0x4599) ] { }
=begin pod
=head2 role Sum::CRC_15_MPT1327
does Sum::CRC[ :finv(1), :columns(15), :poly(0x6815), :residual(0x6814)]
Implements a 15-bit CRC used in MPT1327 mobile communications.
=end pod
role Sum::CRC_15_MPT1327
does Sum::CRC[ :finv(1), :columns(15), :poly(0x6815),
:residual(0x6814) ] { }
=begin pod
=head2 role Sum::CRC_16_ANSI
does Sum::CRC[ :columns(16), :poly(0x8005) ]
Implements the ANSI 16-Bit CRC polynomial without any inversion or
reflection. Note this will be subject to problems with leading and
trailing zeros.
=end pod
role Sum::CRC_16_ANSI
does Sum::CRC[ :columns(16), :poly(0x8005) ] { }
=begin pod
=head2 role Sum::CRC_16_LHA
does Sum::CRC[ :reflect, :columns(16), :poly(0x8005) ]
Implements a 16-Bit CRC using the ANSI 16-bit polynomial with
reflection of the result, as used by the lha data compression
utility. Note this will be subject to problems with leading
and trailing zeros.
=end pod
# python mod has 1..9 checksum as 0xbb3d
role Sum::CRC_16_LHA
does Sum::CRC[ :reflect, :columns(16), :poly(0x8005) ] { }
=begin pod
=head2 role Sum::CRC_16_USB
does Sum::CRC[ :reflect, :iniv, :finv, :columns(16), :poly(0x8005),
:residual(0x4ffe) ]
Implements a 16-bit CRC used in the USB protocol. The result
is in host order, reflected from what appears on the wire.
=end pod
# Specs seem perhaps not to agree with :reflect, which is what some sources say
role Sum::CRC_16_USB
does Sum::CRC[ :reflect, :iniv, :finv, :columns(16), :poly(0x8005),
:residual(0x4ffe) ] { }
=begin pod
=head2 role Sum::CRC_16_USB_WIRE
does Sum::CRC[ :iniv, :finv, :columns(16), :poly(0x8005),
:residual(0x7ff2) ]
Implements a 16-bit CRC used in the USB protocol. The result
is as it appears on the wire, unreflected.
=end pod
# Specs seem perhaps not to agree with :reflect, which is what some sources say
role Sum::CRC_16_USB_WIRE
does Sum::CRC[ :iniv, :finv, :columns(16), :poly(0x8005),
:residual(0x7ff2) ] { }
=begin pod
=head2 role Sum::CRC_16_1_Wire
does Sum::CRC[ :finv, :reflect, :columns(16), :poly(0x8005),
:residual(0x8d1d) ]
Implements an 16-bit CRC used on the 1-Wire bus standard.
=end pod
role Sum::CRC_16_1_Wire
does Sum::CRC[ :finv, :reflect, :columns(16), :poly(0x8005),
:residual(0x8d1d) ] { }
=begin pod
=head2 role Sum::CRC_16_Modbus
does Sum::CRC[ :iniv, :reflect, :columns(16), :poly(0x8005) ]
Implements a 16-bit CRC used in the Modbus protocol.
=end pod
role Sum::CRC_16_Modbus
does Sum::CRC[ :iniv, :reflect, :columns(16), :poly(0x8005) ] { }
=begin pod
=head2 role Sum::CRC_16_DDS_110
does Sum::CRC[ :iniv(0x800d), :columns(16), :poly(0x8005) ]
Implements a 16-bit CRC used in the ELV DDS-110 function generator.
=end pod
role Sum::CRC_16_DDS_110
does Sum::CRC[ :iniv(0x800d), :columns(16), :poly(0x8005) ] { }
=begin pod
=head2
=end pod
# below still todo tests and doc
role Sum::CRC_16_CCITT_FALSE
does Sum::CRC[ :iniv, :columns(16), :poly(0x1021) ] { }
role Sum::CRC_16_Genibus
does Sum::CRC[ :finv, :columns(16), :poly(0x1021) ] { }
role Sum::CRC_16_AUG_CCITT
does Sum::CRC[ :iniv(0x1d0f), :columns(16), :poly(0x1021) ] { }
role Sum::CRC_16_CCITT
does Sum::CRC[ :reflect, :columns(16), :poly(0x1021) ] { }
role Sum::CRC_16_mcrf4xx
does Sum::CRC[ :reflect, :iniv, :columns(16), :poly(0x1021) ] { }
role Sum::CRC_16_X25
does Sum::CRC[ :reflect, :iniv, :finv, :columns(16), :poly(0x1021) ] { }
role Sum::CRC_16_riello
does Sum::CRC[ :reflect, :iniv(0x554d), :columns(16), :poly(0x1021) ] { }
=begin pod
=head2 role Sum::CRC_16_EPC
does Sum::CRC[ :iniv, :finv, :columns(16), :poly(0x1021),
:residual(0xe2f0) ]
Implements a 16-bit CRC used in RFID.
=end pod
role Sum::CRC_16_EPC
does Sum::CRC[ :iniv, :finv, :columns(16), :poly(0x1021),
:residual(0xe2f0) ] { }
# below todo tests and doc
role Sum::CRC_16_XModem does Sum::CRC[ :columns(16), :poly(0x1021) ] { }
role Sum::CRC_16_Kermit does Sum::CRC[ :reflect, :columns(16), :poly(0x1021) ] { } # result may be byte swabbed
role Sum::CRC_16_DECT does Sum::CRC[ :iniv(1), :finv(1), :columns(16), :poly(0x589) ] { }
role Sum::CRC_16_DECT does Sum::CRC[ :columns(16), :poly(0x589) ] { }
# note that result may be byte-swabbed, need to check standard
#role Sum::CRC_16_DNP
# does Sum::CRC[ :finv, :reflect, :columns(16), :poly(0x3d65) ] { }
#role Sum::CRC_16_DNP does Sum::CRC[ :reflect, :iniv, :finv, :poly(0x3d65) ] { }
role Sum::CRC_16_EN_13757 does Sum::CRC[ :iniv, :finv, :poly(0x3d65) ] { }
# linux kernel has impl.
role Sum::CRC_16_T10_DIF does Sum::CRC[ :columns(16), :poly(0x8bb7) ] { }
role Sum::CRC_16_TeleDisk
does Sum::CRC[ :columns(16), :poly(0xa097) ] { }
role Sum::CRC_16_ARINC does Sum::CRC[ :columns(16), :poly(0xa02b) ] { }
#role Sum::CRC_24
# does Sum::CRC[ :columns(24), :poly(0x5d6dcb) ] { }
=begin pod
=head2 role Sum::CRC_24_PGP
does Sum::CRC[ :iniv(0xb704ce), :columns(24), :poly(0x864cfb) ]
Implements the CRC defined in PGP RFC 4880.
=end pod
role Sum::CRC_24_PGP
does Sum::CRC[ :iniv(0xb704ce), :columns(24), :poly(0x864cfb) ] { }
# unconvinced these merit distribution with the base code
# from python module, claims 1..9 checksum 0x7979BD
#role Sum::CRC_24_FLexray_A
# does Sum::CRC[ :iniv(0xfedcba), :columns(24), :poly(0x5d6dcb) ] { }
# from python module, claims 1..9 checksum 0x1f23b8
#role Sum::CRC_24_Flexray_B
# does Sum::CRC[ :iniv(0xabcdef), :columns(24), :poly(0x5d6dcb) ] { }
# cannot find spec for this
#role Sum::CRC_30_CDMA does Sum::CRC[ :columns(30), :poly(0x2030b9c7) ] { }
=begin pod
=head2 role Sum::CRC_32
does Sum::CRC[ :iniv, :finv, :reflect, :columns(32), :poly(0x4c11db7),
:residual(0x2144df1c) ]
Implements one of the most prevalent 32-bit CRC sums, used in many
Internet standards.
=end pod
# note python module claims no iniv but has same 1..9 checksum 0xCBF43926
role Sum::CRC_32
does Sum::CRC[ :iniv, :finv, :reflect, :columns(32), :poly(0x4c11db7),
:residual(0x2144df1c) ] { }
=begin pod
=head2 role Sum::CRC_32_IEEE does Sum::CRC_32 { }
This is just a more specific name for C<Sum::CRC_32>.
=end pod
role Sum::CRC_32_IEEE does Sum::CRC_32 { }
=begin pod
=head2 role Sum::CRC_32C
does Sum::CRC[ :reflect, :iniv, :finv, :columns(32), :poly(0x1edc6f41),
:residual(0x48674bc7) ]
Implements a 32 bit CRC as used in iSCSI.
=end pod
role Sum::CRC_32C
does Sum::CRC[ :reflect, :iniv, :finv, :columns(32), :poly(0x1edc6f41),
:residual(0x48674bc7) ] { }
=begin pod
=head2 role Sum::CRC_32D
does Sum::CRC[ :reflect, :iniv, :finv, :columns(32), :poly(0xa833982b),
:residual(0xbad8faae) ]
Implements a 32 bit CRC used in Base91 ASCII armor.
=end pod
role Sum::CRC_32D
does Sum::CRC[ :reflect, :iniv, :finv, :columns(32), :poly(0xa833982b),
:residual(0xbad8faae) ] { }
=begin pod
=head2 role Sum::CRC_32_BZ2
does Sum::CRC[ :iniv, :finv, :columns(32), :poly(0x04c11db7),
:residual(0x38fb2284) ]
Implements a 32 bit CRC used e.g. in BZIP2, ATM-AAL5, and DECT.
=end pod
role Sum::CRC_32_BZ2
does Sum::CRC[ :iniv, :finv, :columns(32), :poly(0x04c11db7),
:residual(0x38fb2284) ] { }
=begin pod
=head2 role Sum::CRC_32_MPEG2
does Sum::CRC[ :iniv, :columns(32), :poly(0x04c11db7) ]
Implements a 32 bit CRC used in MPEG-2 streams. Note that this
CRC does not use a final inversion and is thus vulnerable to the
insertion of trailing bits.
=end pod
role Sum::CRC_32_MPEG2
does Sum::CRC[ :iniv, :columns(32), :poly(0x04c11db7) ] { }
# CRC_32_POSIX aka cksum todo, needs to count elems and use a length tag
# Koopman suggestion. Need to look for test vectors / 3rd party implementation
#role Sum::CRC_32K
# does Sum::CRC[ :columns(32), :poly(0x741b8cd7) ] { }
=begin pod
=head2 role Sum::CRC_32Q
does Sum::CRC[ :columns(32), :poly(0x814141ab) ]
Implements the CRC-32Q sum as used in some aviation systems.
Note this CRC does not include inversions and as such is vulnerable
to the addition of leading and trailing zeros.
=end pod
role Sum::CRC_32Q
does Sum::CRC[ :columns(32), :poly(0x814141ab) ] { }
=begin pod
=head2 role Sum::CRC_32_XFER
does Sum::CRC[ :columns(32), :poly(0xaf) ]
Implements a CRC used by the XFER serial transfer protocol.
Note this CRC does not include inversions and as such is vulnerable
to the addition of leading and trailing zeros.
=end pod
role Sum::CRC_32_XFER
does Sum::CRC[ :columns(32), :poly(0xaf) ] { }
=begin pod
=head2 role Sum::CRC_40_GSM
does Sum::CRC[ :columns(40), :poly(0x4820009) ] { }
Implements the GSM FIRE code CRC. Note this CRC does not include
inversions and as such is vulnerable to the addition of leading
and trailing zeros.
=end pod
role Sum::CRC_40_GSM
does Sum::CRC[ :columns(40), :poly(0x4820009) ] { }
=begin pod
=head2 role Sum::CRC_64_ISO
does Sum::CRC[ :reflect, :columns(64), :poly(0x1b) ]
Implements the ISO 3309 64 bit CRC. Note this CRC does not include
inversions and as such is vulnerable to the addition of leading and
trailing zeros.
=end pod
role Sum::CRC_64_ISO
does Sum::CRC[ :reflect, :columns(64), :poly(0x1b) ] { }
# Need to look for test vectors / 3rd party implementation
# Note: python module claims :!iniv, reveng says :iniv
# 1..9 checksum 0x62EC59E3F1A4F00A
#role Sum::CRC_64_WE
# does Sum::CRC[ :iniv, :finv, :columns(64), :poly(0x42f0e1eba9ea3693) ] { }
=begin pod
=head2 role Sum::CRC_64_DLT
does Sum::CRC[ :columns(64), :poly(0x42f0e1eba9ea3693) ]
Implements a CRC using the ECMA-182 polynomial as used in DLT-1 tapes.
Note this CRC does not include inversions and as such is vulnerable
to the addition of leading and trailing zeros.
=end pod
role Sum::CRC_64_DLT
does Sum::CRC[ :columns(64), :poly(0x42f0e1eba9ea3693) ] { }
=begin pod
=head2 role Sum::CRC_64_XZ
does Sum::CRC[ :iniv, :finv, :reflect, :columns(64),
:poly(0x42f0e1eba9ea3693),
:residual(0xb66a73654282cac0) ]
Implements a CRC using the ECMA/DLT polynomial as used in the C<.xz>
file format. This adds the customary codeword inversions to provide
protection against leading and trailing zeros, and also reflects the
input values and codewords.
=end pod
role Sum::CRC_64_XZ
does Sum::CRC[ :iniv, :finv, :reflect, :columns(64),
:poly(0x42f0e1eba9ea3693),
:residual(0xb66a73654282cac0) ] { }
=begin pod
=head2 role Sum::CRC_64_Jones
does Sum::CRC[ :reflect, :iniv, :columns(64), :poly(0xad93d23594c935a9) ]
Implements a CRC as proposed in
http://www.cs.ucl.ac.uk/staff/d.jones/crcnote.pdf. Note this
implementation does not include C<:finv> and as such, does not
use a residual and is thus vulnerable to the addition of trailing zeros.
=end pod
role Sum::CRC_64_Jones
does Sum::CRC[ :reflect, :iniv, :columns(64),
:poly(0xad93d23594c935a9) ] { }
=begin pod
=head2 role Sum::CRC_82_DARC
does Sum::CRC[ :reflect, :iniv, :columns(64), :poly(0xad93d23594c935a9) ]
Implements a CRC used in Digital Radio Communications (DARC).
=end pod
role Sum::CRC_82_DARC
does Sum::CRC[ :reflect, :columns(82), :poly(0x0308c0111011401440411) ] { }
=begin pod
=head1 AUTHOR
Written by Brian S. Julin
=head1 COPYRIGHT
Copyright (c) 2012 Brian S. Julin. All rights reserved. This program is
free software; you can redistribute it and/or modify it under the terms
of the Perl Artistic License 2.0.
=head1 REFERENCES
http://reveng.sourceforge.net/crc-catalogue
http://crcmod.sourceforge.net/crcmod.predefined.html Python crc modules
http://www.ece.cmu.edu/~koopman/roses/dsn04/koopman04_crc_poly_embedded.pdf
"SAE Standard J1850 Class B Data Communication Network Interface" 2/15/94
"Specification of CRC Routines" V3.3.0 R3.2 Rev 2 AUTOSAR document ID 016
=head1 SEE ALSO
C<Sum::(pm3)>
=end pod