digest-crc 0.5.1 → 0.6.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -0
  3. data/.travis.yml +8 -0
  4. data/ChangeLog.md +69 -0
  5. data/README.md +3 -0
  6. data/Rakefile +25 -1
  7. data/benchmarks.rb +8 -4
  8. data/ext/digest/Rakefile +51 -0
  9. data/ext/digest/compat/ruby.h +11 -0
  10. data/ext/digest/crc12_3gpp/crc12_3gpp.c +66 -0
  11. data/ext/digest/crc12_3gpp/crc12_3gpp.h +11 -0
  12. data/ext/digest/crc12_3gpp/crc12_3gpp_ext.c +27 -0
  13. data/ext/digest/crc12_3gpp/extconf.rb +7 -0
  14. data/ext/digest/crc15/crc15.c +53 -0
  15. data/ext/digest/crc15/crc15.h +11 -0
  16. data/ext/digest/crc15/crc15_ext.c +28 -0
  17. data/ext/digest/crc15/extconf.rb +7 -0
  18. data/ext/digest/crc16/crc16.c +69 -0
  19. data/ext/digest/crc16/crc16.h +11 -0
  20. data/ext/digest/crc16/crc16_ext.c +28 -0
  21. data/ext/digest/crc16/extconf.rb +7 -0
  22. data/ext/digest/crc16_ccitt/crc16_ccitt.c +69 -0
  23. data/ext/digest/crc16_ccitt/crc16_ccitt.h +8 -0
  24. data/ext/digest/crc16_ccitt/crc16_ccitt_ext.c +28 -0
  25. data/ext/digest/crc16_ccitt/extconf.rb +7 -0
  26. data/ext/digest/crc16_dnp/crc16_dnp.c +53 -0
  27. data/ext/digest/crc16_dnp/crc16_dnp.h +8 -0
  28. data/ext/digest/crc16_dnp/crc16_dnp_ext.c +28 -0
  29. data/ext/digest/crc16_dnp/extconf.rb +7 -0
  30. data/ext/digest/crc16_genibus/crc16_genibus.c +69 -0
  31. data/ext/digest/crc16_genibus/crc16_genibus.h +8 -0
  32. data/ext/digest/crc16_genibus/crc16_genibus_ext.c +28 -0
  33. data/ext/digest/crc16_genibus/extconf.rb +7 -0
  34. data/ext/digest/crc16_kermit/crc16_kermit.c +69 -0
  35. data/ext/digest/crc16_kermit/crc16_kermit.h +8 -0
  36. data/ext/digest/crc16_kermit/crc16_kermit_ext.c +28 -0
  37. data/ext/digest/crc16_kermit/extconf.rb +7 -0
  38. data/ext/digest/crc16_modbus/crc16_modbus.c +69 -0
  39. data/ext/digest/crc16_modbus/crc16_modbus.h +8 -0
  40. data/ext/digest/crc16_modbus/crc16_modbus_ext.c +28 -0
  41. data/ext/digest/crc16_modbus/extconf.rb +7 -0
  42. data/ext/digest/crc16_usb/crc16_usb.c +69 -0
  43. data/ext/digest/crc16_usb/crc16_usb.h +8 -0
  44. data/ext/digest/crc16_usb/crc16_usb_ext.c +28 -0
  45. data/ext/digest/crc16_usb/extconf.rb +7 -0
  46. data/ext/digest/crc16_x_25/crc16_x_25.c +69 -0
  47. data/ext/digest/crc16_x_25/crc16_x_25.h +8 -0
  48. data/ext/digest/crc16_x_25/crc16_x_25_ext.c +28 -0
  49. data/ext/digest/crc16_x_25/extconf.rb +7 -0
  50. data/ext/digest/crc16_xmodem/crc16_xmodem.c +69 -0
  51. data/ext/digest/crc16_xmodem/crc16_xmodem.h +8 -0
  52. data/ext/digest/crc16_xmodem/crc16_xmodem_ext.c +28 -0
  53. data/ext/digest/crc16_xmodem/extconf.rb +7 -0
  54. data/ext/digest/crc16_zmodem/crc16_zmodem.c +69 -0
  55. data/ext/digest/crc16_zmodem/crc16_zmodem.h +8 -0
  56. data/ext/digest/crc16_zmodem/crc16_zmodem_ext.c +28 -0
  57. data/ext/digest/crc16_zmodem/extconf.rb +7 -0
  58. data/ext/digest/crc24/crc24.c +69 -0
  59. data/ext/digest/crc24/crc24.h +11 -0
  60. data/ext/digest/crc24/crc24_ext.c +27 -0
  61. data/ext/digest/crc24/extconf.rb +7 -0
  62. data/ext/digest/crc32/crc32.c +68 -0
  63. data/ext/digest/crc32/crc32.h +11 -0
  64. data/ext/digest/crc32/crc32_ext.c +27 -0
  65. data/ext/digest/crc32/extconf.rb +7 -0
  66. data/ext/digest/crc32_bzip2/crc32_bzip2.c +69 -0
  67. data/ext/digest/crc32_bzip2/crc32_bzip2.h +8 -0
  68. data/ext/digest/crc32_bzip2/crc32_bzip2_ext.c +27 -0
  69. data/ext/digest/crc32_bzip2/extconf.rb +7 -0
  70. data/ext/digest/crc32_jam/crc32_jam.c +69 -0
  71. data/ext/digest/crc32_jam/crc32_jam.h +8 -0
  72. data/ext/digest/crc32_jam/crc32_jam_ext.c +27 -0
  73. data/ext/digest/crc32_jam/extconf.rb +7 -0
  74. data/ext/digest/crc32_mpeg/crc32_mpeg.c +69 -0
  75. data/ext/digest/crc32_mpeg/crc32_mpeg.h +8 -0
  76. data/ext/digest/crc32_mpeg/crc32_mpeg_ext.c +27 -0
  77. data/ext/digest/crc32_mpeg/extconf.rb +7 -0
  78. data/ext/digest/crc32_posix/crc32_posix.c +69 -0
  79. data/ext/digest/crc32_posix/crc32_posix.h +8 -0
  80. data/ext/digest/crc32_posix/crc32_posix_ext.c +27 -0
  81. data/ext/digest/crc32_posix/extconf.rb +7 -0
  82. data/ext/digest/crc32_xfer/crc32_xfer.c +69 -0
  83. data/ext/digest/crc32_xfer/crc32_xfer.h +8 -0
  84. data/ext/digest/crc32_xfer/crc32_xfer_ext.c +27 -0
  85. data/ext/digest/crc32_xfer/extconf.rb +7 -0
  86. data/ext/digest/crc32c/crc32c.c +69 -0
  87. data/ext/digest/crc32c/crc32c.h +8 -0
  88. data/ext/digest/crc32c/crc32c_ext.c +27 -0
  89. data/ext/digest/crc32c/extconf.rb +7 -0
  90. data/ext/digest/crc5/crc5.c +53 -0
  91. data/ext/digest/crc5/crc5.h +11 -0
  92. data/ext/digest/crc5/crc5_ext.c +27 -0
  93. data/ext/digest/crc5/extconf.rb +7 -0
  94. data/ext/digest/crc64/crc64.c +102 -0
  95. data/ext/digest/crc64/crc64.h +11 -0
  96. data/ext/digest/crc64/crc64_ext.c +27 -0
  97. data/ext/digest/crc64/extconf.rb +7 -0
  98. data/ext/digest/crc64_jones/crc64_jones.c +102 -0
  99. data/ext/digest/crc64_jones/crc64_jones.h +8 -0
  100. data/ext/digest/crc64_jones/crc64_jones_ext.c +27 -0
  101. data/ext/digest/crc64_jones/extconf.rb +7 -0
  102. data/ext/digest/crc64_xz/crc64_xz.c +102 -0
  103. data/ext/digest/crc64_xz/crc64_xz.h +8 -0
  104. data/ext/digest/crc64_xz/crc64_xz_ext.c +27 -0
  105. data/ext/digest/crc64_xz/extconf.rb +7 -0
  106. data/ext/digest/crc8/crc8.c +53 -0
  107. data/ext/digest/crc8/crc8.h +11 -0
  108. data/ext/digest/crc8/crc8_ext.c +27 -0
  109. data/ext/digest/crc8/extconf.rb +7 -0
  110. data/ext/digest/crc8_1wire/crc8_1wire.c +53 -0
  111. data/ext/digest/crc8_1wire/crc8_1wire.h +8 -0
  112. data/ext/digest/crc8_1wire/crc8_1wire_ext.c +27 -0
  113. data/ext/digest/crc8_1wire/extconf.rb +7 -0
  114. data/gemspec.yml +4 -1
  115. data/lib/digest/crc15.rb +4 -0
  116. data/lib/digest/crc16.rb +4 -0
  117. data/lib/digest/crc16_ccitt.rb +4 -0
  118. data/lib/digest/crc16_dnp.rb +4 -0
  119. data/lib/digest/crc16_genibus.rb +4 -0
  120. data/lib/digest/crc16_kermit.rb +4 -0
  121. data/lib/digest/crc16_modbus.rb +4 -0
  122. data/lib/digest/crc16_usb.rb +4 -0
  123. data/lib/digest/crc16_x_25.rb +4 -0
  124. data/lib/digest/crc16_xmodem.rb +4 -0
  125. data/lib/digest/crc16_zmodem.rb +4 -0
  126. data/lib/digest/crc24.rb +4 -0
  127. data/lib/digest/crc32.rb +4 -0
  128. data/lib/digest/crc32_bzip2.rb +4 -0
  129. data/lib/digest/crc32_mpeg.rb +4 -0
  130. data/lib/digest/crc32_posix.rb +4 -0
  131. data/lib/digest/crc32_xfer.rb +4 -0
  132. data/lib/digest/crc32c.rb +4 -0
  133. data/lib/digest/crc5.rb +4 -0
  134. data/lib/digest/crc64.rb +4 -0
  135. data/lib/digest/crc64_jones.rb +4 -0
  136. data/lib/digest/crc64_xz.rb +4 -0
  137. data/lib/digest/crc8.rb +4 -0
  138. data/lib/digest/crc8_1wire.rb +4 -0
  139. metadata +110 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f92ef55b3e61da5d83aca365fabce146aaa938ff0ee7f380496f30b2909cd8c
4
- data.tar.gz: a34bfa0d5c6b86e29ee5cc27d157a8ea45596e03ffdd7d7d740eaeb9ccca8e6f
3
+ metadata.gz: 6f3a74146b25bc84927e5f441f7a31a23a4465aafeba993d7d9b0b390f81afde
4
+ data.tar.gz: d7a9d4dc7e435698dfc8e784464f16c1e2dbf394e93c6889bcaaf00fd3e1887e
5
5
  SHA512:
6
- metadata.gz: cafe8835843afd7873891d6a8c85ba294b8cb846a63641a273844aa50801071d77a92a6e1391e82b9921b199163ab87f9864885ba94f1efaf5a241448a9c0143
7
- data.tar.gz: 3787c83078142822c4d7ff198abbcd5a148061612079877ed8f4e4a3b828a4addb9484c4eb36beb417f30c570c336e1a708d7d9a3735342b3553f1d18e69fb8a
6
+ metadata.gz: 4ba2b78693fb9af7e7eda4950fcf5d0e46d5c8ed6ad1469d1da444212396a2cf28308e97a055504cf0d04f0f1cfa6f192b2a4414ab9c6328a0d7a285048e5926
7
+ data.tar.gz: d04e97f73061f3617bab9d4371fb03463a2b366103ca4e4c8344a9b6d4ccb80e7919c76443cdb311a64a856c951980732e34289bab5fa69b3d3070aa3c8a4130
data/.gitignore CHANGED
@@ -3,3 +3,8 @@ doc
3
3
  pkg
4
4
  .bundle
5
5
  .yardoc
6
+ /ext/digest/crc*/Makefile
7
+ /ext/digest/crc*/mkmf.log
8
+ /ext/digest/crc*/extconf.h
9
+ /ext/digest/crc*/*.o
10
+ /ext/digest/crc*/*.so
@@ -2,15 +2,23 @@
2
2
  before_install:
3
3
  - gem update --system
4
4
  - gem install bundler -v "~> 2.0"
5
+
5
6
  language: ruby
6
7
  sudo: false
7
8
  cache:
8
9
  - bundler
10
+
9
11
  rvm:
10
12
  - 2.5
11
13
  - 2.6
14
+ - 2.7
12
15
  - jruby
16
+
13
17
  matrix:
18
+ include:
19
+ - os: linux
20
+ - os: osx
14
21
  allow_failures:
15
22
  - rvm: jruby
23
+
16
24
  script: bundle exec rake spec
@@ -1,3 +1,72 @@
1
+ ### 0.6.0 / 2020-06-16
2
+
3
+ * Implement _optional_ C extensions for all CRC algorithms, resulting in an
4
+ average performance improvement of ~40x. Note, if for whatever reason the
5
+ C extensions cannot be compiled, they will be skipped and the pure-Ruby
6
+ CRC algorithms will be used instead. If the C extensions were successfully
7
+ compiled, then they will be loaded and override the pure-Ruby CRC methods with
8
+ the C equivalents.
9
+
10
+ #### Pure Ruby
11
+
12
+ user system total real
13
+ Digest::CRC1#update 0.412953 0.000000 0.412953 ( 0.414688)
14
+ Digest::CRC5#update 1.116375 0.000003 1.116378 ( 1.120741)
15
+ Digest::CRC8#update 0.994263 0.000013 0.994276 ( 1.001079)
16
+ Digest::CRC8_1Wire#update 0.974115 0.000004 0.974119 ( 0.978186)
17
+ Digest::CRC15#update 1.139402 0.000927 1.140329 ( 1.146608)
18
+ Digest::CRC16#update 0.967836 0.000000 0.967836 ( 0.971792)
19
+ Digest::CRC16CCITT#update 1.118851 0.000000 1.118851 ( 1.123217)
20
+ Digest::CRC16DNP#update 0.922211 0.000000 0.922211 ( 0.925739)
21
+ Digest::CRC16Genibus#update 1.120580 0.000000 1.120580 ( 1.124771)
22
+ Digest::CRC16Modbus#update 0.955612 0.000000 0.955612 ( 0.959463)
23
+ Digest::CRC16QT#update 8.153403 0.000012 8.153415 ( 8.189977)
24
+ Digest::CRC16USB#update 0.952557 0.000000 0.952557 ( 0.956145)
25
+ Digest::CRC16X25#update 0.962295 0.000000 0.962295 ( 0.970401)
26
+ Digest::CRC16XModem#update 1.120531 0.000000 1.120531 ( 1.124494)
27
+ Digest::CRC16ZModem#update 1.124226 0.000000 1.124226 ( 1.128632)
28
+ Digest::CRC24#update 1.126317 0.000000 1.126317 ( 1.130794)
29
+ Digest::CRC32#update 0.960015 0.000000 0.960015 ( 0.964803)
30
+ Digest::CRC32BZip2#update 1.128626 0.000000 1.128626 ( 1.133641)
31
+ Digest::CRC32c#update 0.964047 0.000000 0.964047 ( 0.967456)
32
+ Digest::CRC32Jam#update 0.959141 0.000972 0.960113 ( 0.967444)
33
+ Digest::CRC32MPEG#update 1.131119 0.000002 1.131121 ( 1.137440)
34
+ Digest::CRC32POSIX#update 1.126019 0.000000 1.126019 ( 1.130549)
35
+ Digest::CRC32XFER#update 1.116598 0.000000 1.116598 ( 1.120595)
36
+ Digest::CRC64#update 2.665880 0.000928 2.666808 ( 2.680942)
37
+ Digest::CRC64Jones#update 2.678003 0.000000 2.678003 ( 2.691390)
38
+ Digest::CRC64XZ#update 2.671395 0.000000 2.671395 ( 2.682684)
39
+
40
+ #### C extensions
41
+
42
+ user system total real
43
+ Digest::CRC1#update 0.407438 0.000000 0.407438 ( 0.410495)
44
+ Digest::CRC5#update 0.022873 0.000000 0.022873 ( 0.023796)
45
+ Digest::CRC8#update 0.020129 0.000000 0.020129 ( 0.020887)
46
+ Digest::CRC8_1Wire#update 0.020106 0.000000 0.020106 ( 0.020897)
47
+ Digest::CRC15#update 0.028765 0.000003 0.028768 ( 0.029549)
48
+ Digest::CRC16#update 0.022176 0.000856 0.023032 ( 0.023153)
49
+ Digest::CRC16CCITT#update 0.028570 0.000000 0.028570 ( 0.028691)
50
+ Digest::CRC16DNP#update 0.023240 0.000001 0.023241 ( 0.024008)
51
+ Digest::CRC16Genibus#update 0.028692 0.000000 0.028692 ( 0.029575)
52
+ Digest::CRC16Modbus#update 0.023928 0.000000 0.023928 ( 0.024859)
53
+ Digest::CRC16QT#update 7.965822 0.000968 7.966790 ( 8.001781)
54
+ Digest::CRC16USB#update 0.023448 0.000001 0.023449 ( 0.024420)
55
+ Digest::CRC16X25#update 0.023061 0.000000 0.023061 ( 0.023861)
56
+ Digest::CRC16XModem#update 0.029407 0.000000 0.029407 ( 0.030583)
57
+ Digest::CRC16ZModem#update 0.029522 0.000000 0.029522 ( 0.030438)
58
+ Digest::CRC24#update 0.029528 0.000000 0.029528 ( 0.030504)
59
+ Digest::CRC32#update 0.023306 0.000000 0.023306 ( 0.024278)
60
+ Digest::CRC32BZip2#update 0.026346 0.000000 0.026346 ( 0.027293)
61
+ Digest::CRC32c#update 0.023525 0.000000 0.023525 ( 0.024489)
62
+ Digest::CRC32Jam#update 0.023348 0.000000 0.023348 ( 0.023477)
63
+ Digest::CRC32MPEG#update 0.026287 0.000000 0.026287 ( 0.027394)
64
+ Digest::CRC32POSIX#update 0.026063 0.000000 0.026063 ( 0.026986)
65
+ Digest::CRC32XFER#update 0.026374 0.000000 0.026374 ( 0.027314)
66
+ Digest::CRC64#update 0.023523 0.000000 0.023523 ( 0.024484)
67
+ Digest::CRC64Jones#update 0.023479 0.000000 0.023479 ( 0.024432)
68
+ Digest::CRC64XZ#update 0.024146 0.000000 0.024146 ( 0.025129)
69
+
1
70
  ### 0.5.1 / 2020-03-03
2
71
 
3
72
  * Fixed XOR logic in {Digest::CRC16Genibus}.
data/README.md CHANGED
@@ -44,6 +44,9 @@ module.
44
44
  * {Digest::CRC64XZ CRC64 XZ}
45
45
  * Pure Ruby implementation.
46
46
  * Provides CRC Tables for optimized calculations.
47
+ * Supports _optional_ C extensions which increases performance by ~40x.
48
+ * If the C extensions cannot be compiled for whatever reason, digest-crc
49
+ will automatically fallback to the pure-Ruby implementation.
47
50
 
48
51
  ## Install
49
52
 
data/Rakefile CHANGED
@@ -10,8 +10,32 @@ require 'rake'
10
10
  require 'rubygems/tasks'
11
11
  Gem::Tasks.new
12
12
 
13
+ namespace :build do
14
+ desc "Builds the C extensions"
15
+ task :c_exts do
16
+ Dir.chdir('ext/digest') { sh 'rake' }
17
+ end
18
+ end
19
+
20
+ require 'rake/clean'
21
+ CLEAN.include('ext/digest/crc*/extconf.h')
22
+ CLEAN.include('ext/digest/crc*/Makefile')
23
+ CLEAN.include('ext/digest/crc*/*.o')
24
+ CLEAN.include('ext/digest/crc*/*.so')
25
+
13
26
  require 'rspec/core/rake_task'
14
- RSpec::Core::RakeTask.new
27
+ namespace :spec do
28
+ RSpec::Core::RakeTask.new(:pure)
29
+ task :pure => :clean
30
+
31
+ if RUBY_ENGINE == 'ruby'
32
+ RSpec::Core::RakeTask.new(:c_exts)
33
+ task :c_exts => 'build:c_exts'
34
+ end
35
+ end
36
+
37
+ task :spec => 'spec:pure'
38
+ task :spec => 'spec:c_exts' if RUBY_ENGINE == 'ruby'
15
39
  task :test => :spec
16
40
  task :default => :spec
17
41
 
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'benchmark'
3
- $LOAD_PATH.unshift(File.expand_path('lib'))
3
+ $LOAD_PATH.unshift(File.expand_path('../ext',__FILE__))
4
+ $LOAD_PATH.unshift(File.expand_path('../lib',__FILE__))
4
5
 
5
6
  CRCs = {
6
7
  'crc1' => 'CRC1',
@@ -34,9 +35,12 @@ CRCs = {
34
35
  puts "Loading Digest::CRC classes ..."
35
36
  CRCs.each_key { |crc| require "digest/#{crc}" }
36
37
 
37
- puts "Generating random lengthed strings ..."
38
- SAMPLES = Array.new(100) do
39
- Array.new(100 * rand(1024)) { rand(256).chr }.join
38
+ N = 1000
39
+ BLOCK_SIZE = 8 * 1024
40
+
41
+ puts "Generating #{N} #{BLOCK_SIZE / 1024}Kb lengthed strings ..."
42
+ SAMPLES = Array.new(N) do
43
+ Array.new(BLOCK_SIZE) { rand(256).chr }.join
40
44
  end
41
45
 
42
46
  puts "Benchmarking Digest::CRC classes ..."
@@ -0,0 +1,51 @@
1
+ def fail_gracefully(message)
2
+ warn "#{message}. Failing gracefully ..."
3
+ exit
4
+ end
5
+
6
+ unless RUBY_ENGINE == 'ruby'
7
+ fail_gracefully "C extensions for #{RUBY_ENGINE} currently not supported"
8
+ end
9
+
10
+ begin
11
+ require "mkmf"
12
+ rescue LoadError
13
+ fail_gracefully "mkmf is not installed"
14
+ end
15
+
16
+ MAKE = $make # set by mkmf
17
+
18
+ def make(target=nil)
19
+ if target then sh(MAKE,target)
20
+ else sh(MAKE)
21
+ end
22
+ end
23
+
24
+ CRCS = Dir['crc*']
25
+ DLEXT = MakeMakefile::CONFIG['DLEXT']
26
+
27
+ CRCS.each do |crc|
28
+ crc_ext = "#{crc}_ext"
29
+
30
+ file "#{crc}/Makefile" => "#{crc}/extconf.rb" do
31
+ Dir.chdir(crc) do
32
+ unless ruby('-S', 'extconf.rb')
33
+ fail_gracefully "extconf.rb failed"
34
+ end
35
+ end
36
+ end
37
+
38
+ crc_ext_lib = "#{crc}_ext.#{DLEXT}"
39
+
40
+ file "#{crc}/#{crc_ext_lib}" => "#{crc}/Makefile" do
41
+ Dir.chdir(crc) do
42
+ make 'clean'
43
+
44
+ unless make
45
+ fail_gracefully "Unable to build C extensions"
46
+ end
47
+ end
48
+ end
49
+
50
+ task :default => "#{crc}/#{crc_ext_lib}"
51
+ end
@@ -0,0 +1,11 @@
1
+ #ifndef _DIGEST_COMPAT_RUBY_H_
2
+ #define _DIGEST_COMPAT_RUBY_H_
3
+
4
+ #include <ruby.h>
5
+
6
+ // HACK: define USHORT2NUM for Ruby < 2.6
7
+ #ifndef USHORT2NUM
8
+ #define USHORT2NUM(x) RB_INT2FIX(x)
9
+ #endif
10
+
11
+ #endif
@@ -0,0 +1,66 @@
1
+ /**
2
+ * \file
3
+ * Functions and types for CRC checks.
4
+ *
5
+ * Generated on Sat Feb 29 02:30:42 2020
6
+ * by pycrc v0.9.2, https://pycrc.org
7
+ * using the configuration:
8
+ * - Width = 12
9
+ * - Poly = 0x80f
10
+ * - XorIn = 0x000
11
+ * - ReflectIn = False
12
+ * - XorOut = 0x000
13
+ * - ReflectOut = True
14
+ * - Algorithm = table-driven
15
+ */
16
+
17
+ #include "crc12_3gpp.h"
18
+
19
+ /**
20
+ * Static table used for the table_driven implementation.
21
+ */
22
+ static const crc12_t crc12_table[256] = {
23
+ 0x000, 0x80f, 0x811, 0x01e, 0x82d, 0x022, 0x03c, 0x833, 0x855, 0x05a, 0x044, 0x84b, 0x078, 0x877, 0x869, 0x066,
24
+ 0x8a5, 0x0aa, 0x0b4, 0x8bb, 0x088, 0x887, 0x899, 0x096, 0x0f0, 0x8ff, 0x8e1, 0x0ee, 0x8dd, 0x0d2, 0x0cc, 0x8c3,
25
+ 0x945, 0x14a, 0x154, 0x95b, 0x168, 0x967, 0x979, 0x176, 0x110, 0x91f, 0x901, 0x10e, 0x93d, 0x132, 0x12c, 0x923,
26
+ 0x1e0, 0x9ef, 0x9f1, 0x1fe, 0x9cd, 0x1c2, 0x1dc, 0x9d3, 0x9b5, 0x1ba, 0x1a4, 0x9ab, 0x198, 0x997, 0x989, 0x186,
27
+ 0xa85, 0x28a, 0x294, 0xa9b, 0x2a8, 0xaa7, 0xab9, 0x2b6, 0x2d0, 0xadf, 0xac1, 0x2ce, 0xafd, 0x2f2, 0x2ec, 0xae3,
28
+ 0x220, 0xa2f, 0xa31, 0x23e, 0xa0d, 0x202, 0x21c, 0xa13, 0xa75, 0x27a, 0x264, 0xa6b, 0x258, 0xa57, 0xa49, 0x246,
29
+ 0x3c0, 0xbcf, 0xbd1, 0x3de, 0xbed, 0x3e2, 0x3fc, 0xbf3, 0xb95, 0x39a, 0x384, 0xb8b, 0x3b8, 0xbb7, 0xba9, 0x3a6,
30
+ 0xb65, 0x36a, 0x374, 0xb7b, 0x348, 0xb47, 0xb59, 0x356, 0x330, 0xb3f, 0xb21, 0x32e, 0xb1d, 0x312, 0x30c, 0xb03,
31
+ 0xd05, 0x50a, 0x514, 0xd1b, 0x528, 0xd27, 0xd39, 0x536, 0x550, 0xd5f, 0xd41, 0x54e, 0xd7d, 0x572, 0x56c, 0xd63,
32
+ 0x5a0, 0xdaf, 0xdb1, 0x5be, 0xd8d, 0x582, 0x59c, 0xd93, 0xdf5, 0x5fa, 0x5e4, 0xdeb, 0x5d8, 0xdd7, 0xdc9, 0x5c6,
33
+ 0x440, 0xc4f, 0xc51, 0x45e, 0xc6d, 0x462, 0x47c, 0xc73, 0xc15, 0x41a, 0x404, 0xc0b, 0x438, 0xc37, 0xc29, 0x426,
34
+ 0xce5, 0x4ea, 0x4f4, 0xcfb, 0x4c8, 0xcc7, 0xcd9, 0x4d6, 0x4b0, 0xcbf, 0xca1, 0x4ae, 0xc9d, 0x492, 0x48c, 0xc83,
35
+ 0x780, 0xf8f, 0xf91, 0x79e, 0xfad, 0x7a2, 0x7bc, 0xfb3, 0xfd5, 0x7da, 0x7c4, 0xfcb, 0x7f8, 0xff7, 0xfe9, 0x7e6,
36
+ 0xf25, 0x72a, 0x734, 0xf3b, 0x708, 0xf07, 0xf19, 0x716, 0x770, 0xf7f, 0xf61, 0x76e, 0xf5d, 0x752, 0x74c, 0xf43,
37
+ 0xec5, 0x6ca, 0x6d4, 0xedb, 0x6e8, 0xee7, 0xef9, 0x6f6, 0x690, 0xe9f, 0xe81, 0x68e, 0xebd, 0x6b2, 0x6ac, 0xea3,
38
+ 0x660, 0xe6f, 0xe71, 0x67e, 0xe4d, 0x642, 0x65c, 0xe53, 0xe35, 0x63a, 0x624, 0xe2b, 0x618, 0xe17, 0xe09, 0x606
39
+ };
40
+
41
+ crc12_t crc_reflect(crc12_t data, size_t data_len)
42
+ {
43
+ unsigned int i;
44
+ crc12_t ret;
45
+
46
+ ret = data & 0x01;
47
+ for (i = 1; i < data_len; i++) {
48
+ data >>= 1;
49
+ ret = (ret << 1) | (data & 0x01);
50
+ }
51
+ return ret;
52
+ }
53
+
54
+
55
+ crc12_t crc12_3gpp_update(crc12_t crc, const void *data, size_t data_len)
56
+ {
57
+ const unsigned char *d = (const unsigned char *)data;
58
+ unsigned int tbl_idx;
59
+
60
+ while (data_len--) {
61
+ tbl_idx = ((crc >> 4) ^ *d) & 0xff;
62
+ crc = (crc12_table[tbl_idx] ^ (crc << 8)) & 0xfff;
63
+ d++;
64
+ }
65
+ return crc & 0xfff;
66
+ }
@@ -0,0 +1,11 @@
1
+ #ifndef _CRC12_3GPP_H_
2
+ #define _CRC12_3GPP_H_
3
+
4
+ #include <stdint.h>
5
+ #include <stddef.h>
6
+
7
+ typedef uint16_t crc12_t;
8
+
9
+ crc12_t crc12_3gpp_update(crc12_t crc, const void *data, size_t data_len);
10
+
11
+ #endif
@@ -0,0 +1,27 @@
1
+ #include "ruby.h"
2
+ #include "extconf.h"
3
+
4
+ #include "crc12_3gpp.h"
5
+
6
+ VALUE Digest_CRC12_3GPP_update(VALUE self, VALUE data)
7
+ {
8
+ VALUE crc_ivar_name = rb_intern("@crc");
9
+ VALUE crc_ivar = rb_ivar_get(self, crc_ivar_name);
10
+ crc12_t crc = NUM2UINT(crc_ivar);
11
+
12
+ const char *data_ptr = StringValuePtr(data);
13
+ size_t length = RSTRING_LEN(data);
14
+
15
+ crc = crc12_3gpp_update(crc,data_ptr,length);
16
+
17
+ rb_ivar_set(self, crc_ivar_name, UINT2NUM(crc));
18
+ return self;
19
+ }
20
+
21
+ void Init_crc12_3gpp_ext()
22
+ {
23
+ VALUE mDigest = rb_const_get(rb_cObject, rb_intern("Digest"));
24
+ VALUE cCRC12_3GPP = rb_const_get(mDigest, rb_intern("CRC12_3GPP"));
25
+
26
+ rb_define_method(cCRC12_3GPP, "update", Digest_CRC12_3GPP_update, 1);
27
+ }
@@ -0,0 +1,7 @@
1
+ require 'mkmf'
2
+
3
+ have_header("stdint.h")
4
+ have_header('stddef.h')
5
+
6
+ create_header
7
+ create_makefile "crc12_3gpp_ext"
@@ -0,0 +1,53 @@
1
+ /**
2
+ * \file
3
+ * Functions and types for CRC checks.
4
+ *
5
+ * Generated on Sat Feb 29 02:30:57 2020
6
+ * by pycrc v0.9.2, https://pycrc.org
7
+ * using the configuration:
8
+ * - Width = 15
9
+ * - Poly = 0x4599
10
+ * - XorIn = 0x0000
11
+ * - ReflectIn = False
12
+ * - XorOut = 0x0000
13
+ * - ReflectOut = False
14
+ * - Algorithm = table-driven
15
+ */
16
+
17
+ #include "crc15.h"
18
+
19
+ /**
20
+ * Static table used for the table_driven implementation.
21
+ */
22
+ static const crc15_t crc15_table[256] = {
23
+ 0x0000, 0x4599, 0x4eab, 0x0b32, 0x58cf, 0x1d56, 0x1664, 0x53fd, 0x7407, 0x319e, 0x3aac, 0x7f35, 0x2cc8, 0x6951, 0x6263, 0x27fa,
24
+ 0x2d97, 0x680e, 0x633c, 0x26a5, 0x7558, 0x30c1, 0x3bf3, 0x7e6a, 0x5990, 0x1c09, 0x173b, 0x52a2, 0x015f, 0x44c6, 0x4ff4, 0x0a6d,
25
+ 0x5b2e, 0x1eb7, 0x1585, 0x501c, 0x03e1, 0x4678, 0x4d4a, 0x08d3, 0x2f29, 0x6ab0, 0x6182, 0x241b, 0x77e6, 0x327f, 0x394d, 0x7cd4,
26
+ 0x76b9, 0x3320, 0x3812, 0x7d8b, 0x2e76, 0x6bef, 0x60dd, 0x2544, 0x02be, 0x4727, 0x4c15, 0x098c, 0x5a71, 0x1fe8, 0x14da, 0x5143,
27
+ 0x73c5, 0x365c, 0x3d6e, 0x78f7, 0x2b0a, 0x6e93, 0x65a1, 0x2038, 0x07c2, 0x425b, 0x4969, 0x0cf0, 0x5f0d, 0x1a94, 0x11a6, 0x543f,
28
+ 0x5e52, 0x1bcb, 0x10f9, 0x5560, 0x069d, 0x4304, 0x4836, 0x0daf, 0x2a55, 0x6fcc, 0x64fe, 0x2167, 0x729a, 0x3703, 0x3c31, 0x79a8,
29
+ 0x28eb, 0x6d72, 0x6640, 0x23d9, 0x7024, 0x35bd, 0x3e8f, 0x7b16, 0x5cec, 0x1975, 0x1247, 0x57de, 0x0423, 0x41ba, 0x4a88, 0x0f11,
30
+ 0x057c, 0x40e5, 0x4bd7, 0x0e4e, 0x5db3, 0x182a, 0x1318, 0x5681, 0x717b, 0x34e2, 0x3fd0, 0x7a49, 0x29b4, 0x6c2d, 0x671f, 0x2286,
31
+ 0x2213, 0x678a, 0x6cb8, 0x2921, 0x7adc, 0x3f45, 0x3477, 0x71ee, 0x5614, 0x138d, 0x18bf, 0x5d26, 0x0edb, 0x4b42, 0x4070, 0x05e9,
32
+ 0x0f84, 0x4a1d, 0x412f, 0x04b6, 0x574b, 0x12d2, 0x19e0, 0x5c79, 0x7b83, 0x3e1a, 0x3528, 0x70b1, 0x234c, 0x66d5, 0x6de7, 0x287e,
33
+ 0x793d, 0x3ca4, 0x3796, 0x720f, 0x21f2, 0x646b, 0x6f59, 0x2ac0, 0x0d3a, 0x48a3, 0x4391, 0x0608, 0x55f5, 0x106c, 0x1b5e, 0x5ec7,
34
+ 0x54aa, 0x1133, 0x1a01, 0x5f98, 0x0c65, 0x49fc, 0x42ce, 0x0757, 0x20ad, 0x6534, 0x6e06, 0x2b9f, 0x7862, 0x3dfb, 0x36c9, 0x7350,
35
+ 0x51d6, 0x144f, 0x1f7d, 0x5ae4, 0x0919, 0x4c80, 0x47b2, 0x022b, 0x25d1, 0x6048, 0x6b7a, 0x2ee3, 0x7d1e, 0x3887, 0x33b5, 0x762c,
36
+ 0x7c41, 0x39d8, 0x32ea, 0x7773, 0x248e, 0x6117, 0x6a25, 0x2fbc, 0x0846, 0x4ddf, 0x46ed, 0x0374, 0x5089, 0x1510, 0x1e22, 0x5bbb,
37
+ 0x0af8, 0x4f61, 0x4453, 0x01ca, 0x5237, 0x17ae, 0x1c9c, 0x5905, 0x7eff, 0x3b66, 0x3054, 0x75cd, 0x2630, 0x63a9, 0x689b, 0x2d02,
38
+ 0x276f, 0x62f6, 0x69c4, 0x2c5d, 0x7fa0, 0x3a39, 0x310b, 0x7492, 0x5368, 0x16f1, 0x1dc3, 0x585a, 0x0ba7, 0x4e3e, 0x450c, 0x0095
39
+ };
40
+
41
+
42
+ crc15_t crc15_update(crc15_t crc, const void *data, size_t data_len)
43
+ {
44
+ const unsigned char *d = (const unsigned char *)data;
45
+ unsigned int tbl_idx;
46
+
47
+ while (data_len--) {
48
+ tbl_idx = ((crc >> 7) ^ *d) & 0xff;
49
+ crc = (crc15_table[tbl_idx] ^ (crc << 8)) & 0x7fff;
50
+ d++;
51
+ }
52
+ return crc & 0x7fff;
53
+ }
@@ -0,0 +1,11 @@
1
+ #ifndef _CRC15_H_
2
+ #define _CRC15_H_
3
+
4
+ #include <stdint.h>
5
+ #include <stddef.h>
6
+
7
+ typedef uint16_t crc15_t;
8
+
9
+ crc15_t crc15_update(crc15_t crc, const void *data, size_t data_len);
10
+
11
+ #endif
@@ -0,0 +1,28 @@
1
+ #include <ruby.h>
2
+ #include "../compat/ruby.h"
3
+
4
+ #include "extconf.h"
5
+ #include "crc15.h"
6
+
7
+ VALUE Digest_CRC15_update(VALUE self, VALUE data)
8
+ {
9
+ VALUE crc_ivar_name = rb_intern("@crc");
10
+ VALUE crc_ivar = rb_ivar_get(self, crc_ivar_name);
11
+ crc15_t crc = NUM2USHORT(crc_ivar);
12
+
13
+ const char *data_ptr = StringValuePtr(data);
14
+ size_t length = RSTRING_LEN(data);
15
+
16
+ crc = crc15_update(crc,data_ptr,length);
17
+
18
+ rb_ivar_set(self, crc_ivar_name, USHORT2NUM(crc));
19
+ return self;
20
+ }
21
+
22
+ void Init_crc15_ext()
23
+ {
24
+ VALUE mDigest = rb_const_get(rb_cObject, rb_intern("Digest"));
25
+ VALUE cCRC15 = rb_const_get(mDigest, rb_intern("CRC15"));
26
+
27
+ rb_define_method(cCRC15, "update", Digest_CRC15_update, 1);
28
+ }