afsplitter 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5fcd1489dd788aa2d0b9cbe4b7b36b98fbd9a9b5
4
+ data.tar.gz: 8d8f199beee6ff749939cba86a8c1f0cd697087e
5
+ SHA512:
6
+ metadata.gz: c65bf55f79be5a3bab596f17b99e9220546dbe2345b837b6e5e0d299b2c7fdffdb529a2835128a5da9ef5409d770f9a4c2ee9c361862ed41ef0c17cc41934742
7
+ data.tar.gz: fbca410d5c9c876e17fff5a8bc17566799016a49f9459ab99cc7e3c571a6efcd9689c7371b339c50e11b73938fe38cfcf3d079a3c4768b17e46c34dab7bd5f64
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .*.un~
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in afsplitter.gemspec
4
+ gemspec
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2014 John Lane
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ http://www.opensource.org/licenses/mit-license.php
@@ -0,0 +1,110 @@
1
+ # Afsplitter - Anti-forensic Information Splitter
2
+
3
+ This is a Ruby implementation of the [AFsplitter][1] used by `cryptsetup`
4
+ when storing encrypted key data in a [LUKS][2] volume header.
5
+
6
+ There are two implementations:
7
+
8
+ * A version using [FFI][3] bindings to the AFsplitter library;
9
+ * A pure Ruby implementation.
10
+
11
+ RubyGems: https://rubygems.org/gems/afsplitter
12
+ Github: https://github.com/johnlane/afsplitter
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'afsplitter'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install afsplitter
29
+
30
+ Using the FFI version requires the `libafsplit.so` AFSPlitter library to
31
+ be installed in the system's library search path (typically in the `/usr/lib`
32
+ directory) but it is not included in this package.
33
+
34
+ The library source code can be [downloaded][4] from the [official website][1]
35
+ or from Git:
36
+
37
+ $ git clone https://github.com/johnlane/libafsplit
38
+
39
+ To build the library
40
+
41
+ $ cd libafsplit
42
+ $ make
43
+ $ cp libafsplit.so $GEM_HOME...
44
+
45
+ The official version is [AFsplitter-0.1.tar.bz2][4] ( SHA1: baf2857b3c87f369a36a67bb8603a6c417eba43e)
46
+
47
+ **Note:** the official version's `Makefile` only builds a stand-alone test executable; it does not
48
+ build the `libafsplit.so` library. The [Makefile][6] in the Git [repository][5] builds the
49
+ shared library, however.
50
+
51
+ ## Usage
52
+
53
+ For the FFI implementation
54
+
55
+ require 'afsplitter_ffi'
56
+
57
+ For the Ruby implementation:
58
+
59
+ require 'afsplitter'
60
+
61
+ Then, to split
62
+
63
+ str_split = Afsplitter.split(str, iterations)
64
+
65
+ And to merge:
66
+
67
+ str_merged = Afsplitter.merge(str_split, iterations)
68
+
69
+ Which should result in
70
+
71
+ str_merged == str
72
+
73
+ Refer to the tests in the `test` subdirectory for working examples.
74
+
75
+ ## Tests
76
+
77
+ There are two tests:
78
+
79
+ * `test_afsplitter.rb` split and merge test using the native Ruby implementation.
80
+ * `test_afsplitter_ffi.rb` split and merge test using the `libafsplit.so` FFI implementation.
81
+
82
+ To run all tests
83
+
84
+ $ rake
85
+
86
+ To run individual tests
87
+
88
+ $ rake native
89
+ $ rake ffi
90
+
91
+ ## License
92
+
93
+ MIT License: see the `LICENSE.txt` file.
94
+
95
+ The `libafsplit.so` library is licensed as described on its [web site][4].
96
+
97
+ ## Contributing
98
+
99
+ 1. Fork it ( https://github.com/johnlane/afsplitter )
100
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
101
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
102
+ 4. Push to the branch (`git push origin my-new-feature`)
103
+ 5. Create a new Pull Request
104
+
105
+ [1]:http://clemens.endorphin.org/AFsplitter
106
+ [2]:https://code.google.com/p/cryptsetup
107
+ [3]:https://github.com/ffi/ffi "Foreign Function Interface"
108
+ [4]:http://clemens.endorphin.org/AFsplitter-0.1.tar.bz2 "AFsplitter-0.1.tar.bz2"
109
+ [5]:https://github.com/johnlane/libafsplit
110
+ [6]:https://raw.githubusercontent.com/johnlane/libafsplit/master/Makefile "Makefile"
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:ffi) { |t| t.test_files = %w(test/test_afsplitter_ffi.rb) }
5
+ Rake::TestTask.new(:native) { |t| t.test_files = %w(test/test_afsplitter.rb) }
6
+
7
+ desc "Run all tests"
8
+ task :default => [:ffi, :native]
9
+
10
+ desc "Run FFI test"
11
+ task :ffi
12
+
13
+ desc "Test native Ruby implementation"
14
+ task :native
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'afsplitter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "afsplitter"
8
+ spec.version = Afsplitter::VERSION
9
+ spec.authors = ["John Lane"]
10
+ spec.email = ["john@lane.uk.net"]
11
+ spec.summary = Afsplitter::SUMMARY
12
+ spec.description = Afsplitter::DESCRIPTION
13
+ spec.homepage = "https://github.com/johnlane/afsplitter"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_dependency "ffi", '~> 1.9', '>= 1.9.6'
25
+ end
@@ -0,0 +1,76 @@
1
+ # https://rubygems.org/gems/afsplitter
2
+ require 'afsplitter/version'
3
+ require 'openssl'
4
+
5
+ module Afsplitter
6
+
7
+ def self.merge(data,stripes,digest='sha1')
8
+
9
+ puts "Blocksize mismatch" unless data.size % stripes == 0
10
+
11
+ blocksize = data.size / stripes
12
+ bufblock = "\0" * blocksize
13
+
14
+ (0...stripes-1).each do |i|
15
+ bufblock = _xor(data[i*blocksize,blocksize], bufblock)
16
+ bufblock = _diffuse(bufblock, blocksize, digest)
17
+ end
18
+
19
+ return _xor(data[(stripes-1)*blocksize..-1], bufblock)
20
+ end
21
+
22
+ def self.split(data,stripes,digest='sha1')
23
+
24
+ blocksize = data.size
25
+ rand = Random.new
26
+ bufblock = "\0" * blocksize
27
+
28
+ ret = ''
29
+ (stripes-1).times do
30
+
31
+ # Get some random data
32
+ r = rand.bytes(blocksize)
33
+ ret += r
34
+
35
+ bufblock = _xor(r, bufblock)
36
+ bufblock = _diffuse(bufblock, blocksize, digest)
37
+ end
38
+
39
+ ret += _xor(bufblock, data)
40
+
41
+ end
42
+
43
+ private
44
+
45
+ def self._xor(a,b)
46
+ a.unpack('C*').zip(b.unpack('C*')).map{ |a,b| a^b }.pack('C*')
47
+ end
48
+
49
+ def self._diffuse(block,size,digest)
50
+ digest = OpenSSL::Digest.new(digest)
51
+ digest_size = digest.digest_length
52
+ full_blocks = block.size / digest_size
53
+ padding = block.size % digest_size
54
+
55
+ # hash the full blocks
56
+ ret = ''
57
+ (0..full_blocks-1).each do |i|
58
+ digest.reset
59
+ digest << [i].pack('N')
60
+ digest << block[i*digest_size,digest_size]
61
+ ret+=digest.digest
62
+ end
63
+
64
+ # Hash the remaining data
65
+ if padding > 0
66
+ digest.reset
67
+ digest << [full_blocks].pack('N')
68
+ digest << block[full_blocks * digest_size..-1]
69
+ ret += digest.digest[0,padding]
70
+ end
71
+
72
+ ret
73
+
74
+ end
75
+
76
+ end
@@ -0,0 +1,17 @@
1
+ module Afsplitter
2
+ VERSION = "0.1"
3
+
4
+ SUMMARY = "AFsplitter - Anti-forensic Information Splitter"
5
+
6
+ DESCRIPTION = <<-EOS
7
+
8
+ The AFsplitter is used by LUKS to store encrypted keys in its header.
9
+
10
+ There is a native Ruby implementation and a FFI implementation that
11
+ binds the "libafsplit.so" shared library.
12
+
13
+ AFsplitter is documented at http://clemens.endorphin.org/AFsplitter.
14
+
15
+ EOS
16
+
17
+ end
@@ -0,0 +1,38 @@
1
+ # https://rubygems.org/gems/afsplitter
2
+ require "afsplitter/version"
3
+ require "ffi"
4
+
5
+ module Afsplitter
6
+
7
+ extend FFI::Library
8
+
9
+ def self.split(str,iterations,digest=nil)
10
+ size=str.size
11
+ original = FFI::MemoryPointer.from_string(str)
12
+ result = FFI::MemoryPointer.from_string(Random.new.bytes(size*iterations))
13
+ af_split(original,result,size,iterations)
14
+ return result.read_string(size*iterations)
15
+ end
16
+
17
+ def self.merge(str,iterations,digest=nil)
18
+ size=str.size / iterations
19
+ original = FFI::MemoryPointer.from_string(str)
20
+ result = FFI::MemoryPointer.from_string(Random.new.bytes(size))
21
+ af_merge(original,result,size,iterations)
22
+ return result.read_string(size)
23
+ end
24
+
25
+ private
26
+
27
+ ffi_lib 'libafsplit.so'
28
+
29
+ typedef :pointer, :src
30
+ typedef :pointer, :dest
31
+
32
+ #int AF_split(char *src, char *dst, int blocksize, int blocknumbers);
33
+ attach_function :af_split, :AF_split, [:src, :dest, :int, :int], :int
34
+
35
+ #int AF_merge(char *src, char *dst, int blocksize, int blocknumbers);
36
+ attach_function :af_merge, :AF_merge, [:src, :dest, :int, :int], :int
37
+
38
+ end
@@ -0,0 +1,21 @@
1
+ # https://rubygems.org/gems/afsplitter
2
+ require 'afsplitter'
3
+
4
+ SIZE = 10000
5
+ TIMES = 3000
6
+
7
+ str_orig = Random.new.bytes(SIZE)
8
+
9
+ print "Splitting..."
10
+ str_split = Afsplitter.split(str_orig, TIMES)
11
+ puts "split size=#{str_split.size}"
12
+
13
+ print "Merging..."
14
+ str_merged = Afsplitter.merge(str_split, TIMES)
15
+ puts "merged size=#{str_merged.size}"
16
+
17
+ if str_merged == str_orig
18
+ puts "The strings match"
19
+ else
20
+ puts "The strings do not match"
21
+ end
@@ -0,0 +1,21 @@
1
+ # https://rubygems.org/gems/afsplitter
2
+ require 'afsplitter_ffi'
3
+
4
+ SIZE = 10000
5
+ TIMES = 3000
6
+
7
+ str_orig = Random.new.bytes(SIZE)
8
+
9
+ print "Splitting..."
10
+ str_split = Afsplitter.split(str_orig, TIMES)
11
+ puts "split size=#{str_split.size}"
12
+
13
+ print "Merging..."
14
+ str_merged = Afsplitter.merge(str_split, TIMES)
15
+ puts "merged size=#{str_merged.size}"
16
+
17
+ if str_merged == str_orig
18
+ puts "The strings match"
19
+ else
20
+ puts "The strings do not match"
21
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: afsplitter
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - John Lane
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ffi
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.9'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 1.9.6
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '1.9'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 1.9.6
61
+ description: |2+
62
+
63
+ The AFsplitter is used by LUKS to store encrypted keys in its header.
64
+
65
+ There is a native Ruby implementation and a FFI implementation that
66
+ binds the "libafsplit.so" shared library.
67
+
68
+ AFsplitter is documented at http://clemens.endorphin.org/AFsplitter.
69
+
70
+ email:
71
+ - john@lane.uk.net
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - afsplitter.gemspec
82
+ - lib/afsplitter.rb
83
+ - lib/afsplitter/version.rb
84
+ - lib/afsplitter_ffi.rb
85
+ - test/test_afsplitter.rb
86
+ - test/test_afsplitter_ffi.rb
87
+ homepage: https://github.com/johnlane/afsplitter
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.2.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: AFsplitter - Anti-forensic Information Splitter
111
+ test_files:
112
+ - test/test_afsplitter.rb
113
+ - test/test_afsplitter_ffi.rb