ruby_clang_fpe 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3115aa40a5c4002b75f0c8019ffeed1bb14c34b6fc2a977feff25e8d0651fcf4
4
+ data.tar.gz: d7c11ef5ba9837c4e5e8bc1ba799dfbaa7388b1f20ed98ab7e28c09ebffadd3f
5
+ SHA512:
6
+ metadata.gz: bdf47ab3683a21cee73005bdddc1fcabacdde7e5cc5d1498422deaff3c09586f738f237be396ab00133d5b839fea801893f54ff8027c6377b5254f78db5952ab
7
+ data.tar.gz: 35fffea86cff3d243ff9976fd5bcacc8f941eedb6ee10a4ac31aebcb195c5342109e8a9faf7ead663f7b29a7024b6a0fd5f3eecbd0669724ac149a25c86410e2
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.3
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in ruby_clang_fpe.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rake-compiler"
11
+
12
+ gem "minitest", "~> 5.0"
13
+
14
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,78 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ruby_clang_fpe (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ base64 (0.1.1)
11
+ binding_of_caller (1.0.0)
12
+ debug_inspector (>= 0.0.1)
13
+ coderay (1.1.3)
14
+ debug_inspector (1.1.0)
15
+ interception (0.5)
16
+ json (2.6.3)
17
+ language_server-protocol (3.17.0.3)
18
+ method_source (1.0.0)
19
+ minitest (5.20.0)
20
+ parallel (1.23.0)
21
+ parser (3.2.2.4)
22
+ ast (~> 2.4.1)
23
+ racc
24
+ pry (0.14.2)
25
+ coderay (~> 1.1)
26
+ method_source (~> 1.0)
27
+ pry-doc (1.2.0)
28
+ pry (~> 0.11)
29
+ yard (~> 0.9.11)
30
+ pry-rescue (1.5.2)
31
+ interception (>= 0.5)
32
+ pry (>= 0.12.0)
33
+ pry-stack_explorer (0.6.1)
34
+ binding_of_caller (~> 1.0)
35
+ pry (~> 0.13)
36
+ racc (1.7.1)
37
+ rainbow (3.1.1)
38
+ rake (13.0.6)
39
+ rake-compiler (1.2.5)
40
+ rake
41
+ regexp_parser (2.8.2)
42
+ rexml (3.2.6)
43
+ rubocop (1.57.1)
44
+ base64 (~> 0.1.1)
45
+ json (~> 2.3)
46
+ language_server-protocol (>= 3.17.0)
47
+ parallel (~> 1.10)
48
+ parser (>= 3.2.2.4)
49
+ rainbow (>= 2.2.2, < 4.0)
50
+ regexp_parser (>= 1.8, < 3.0)
51
+ rexml (>= 3.2.5, < 4.0)
52
+ rubocop-ast (>= 1.28.1, < 2.0)
53
+ ruby-progressbar (~> 1.7)
54
+ unicode-display_width (>= 2.4.0, < 3.0)
55
+ rubocop-ast (1.29.0)
56
+ parser (>= 3.2.1.0)
57
+ ruby-progressbar (1.13.0)
58
+ unicode-display_width (2.5.0)
59
+ webrick (1.7.0)
60
+ yard (0.9.27)
61
+ webrick (~> 1.7.0)
62
+
63
+ PLATFORMS
64
+ ruby
65
+
66
+ DEPENDENCIES
67
+ minitest (~> 5.0)
68
+ pry
69
+ pry-doc
70
+ pry-rescue
71
+ pry-stack_explorer
72
+ rake (~> 13.0)
73
+ rake-compiler
74
+ rubocop (~> 1.21)
75
+ ruby_clang_fpe!
76
+
77
+ BUNDLED WITH
78
+ 2.2.32
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Daniel Luna
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Daniel Luna
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # RubyClangFpe
2
+
3
+ Format-preserving encryption for Ruby, based on https://github.com/mysto/clang-fpe.
4
+
5
+ ## Installation
6
+
7
+ Add the following to the application's Gemfile:
8
+
9
+ gem 'ruby_clang_fpe', github: 'dcluna/ruby-clang-fpe', submodules: true
10
+
11
+ ## Usage
12
+
13
+ ```ruby
14
+ fpe3_key = RubyClangFpe::FpeKey.generate_key(:ff3, "EF4359D8D580AA4F7F036D6F04FC6A942B7E151628AED2A6ABF7158809CF4F3C", "9A768A92F60E12D8", 26)
15
+
16
+ fpe3_key.encrypt("89012123456789000000789000000") # => "30859239999374053872365555822"
17
+ fpe3_key.decrypt("30859239999374053872365555822") # => "89012123456789000000789000000"
18
+ ```
19
+
20
+ ## Development
21
+
22
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
23
+
24
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
25
+
26
+ ## Contributing
27
+
28
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dcluna/ruby-clang-fpe.
29
+
30
+ ## License
31
+
32
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ require "rake/extensiontask"
17
+
18
+ task build: :compile
19
+
20
+ Rake::ExtensionTask.new("ruby_clang_fpe") do |ext|
21
+ ext.lib_dir = "lib/ruby_clang_fpe"
22
+ end
23
+
24
+ task default: %i[clobber compile test rubocop]
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: TRUE
2
+
3
+ require "mkmf"
4
+
5
+ openssl_include_dir, openssl_lib_dir = dir_config("openssl", "include", "lib")
6
+
7
+ openssl_dir = File.dirname openssl_include_dir
8
+
9
+ find_header "string.h"
10
+ find_header "openssl/bn.h"
11
+ find_header "openssl/aes.h"
12
+
13
+ clang_fpe_include_dir, clang_fpe_lib_dir = dir_config("clang-fpe", "src", "./")
14
+
15
+ clang_fpe_dir = File.dirname clang_fpe_include_dir
16
+
17
+ if clang_fpe_dir == "."
18
+ clang_fpe_dir = (File.expand_path File.dirname(__FILE__) + "/../../vendor/clang-fpe" )
19
+ clang_fpe_lib_dir = clang_fpe_dir
20
+ clang_fpe_include_dir = clang_fpe_dir + "/src"
21
+ end
22
+
23
+ Dir.chdir clang_fpe_dir do
24
+ system "CFLAGS='-I#{openssl_include_dir}' LDFLAGS='-L#{openssl_lib_dir}' make" if Dir["**/libfpe.a"].empty?
25
+ end
26
+
27
+ libfpe = Dir[clang_fpe_dir + "/**/libfpe.a"].first
28
+
29
+ $LOCAL_LIBS << "'#{libfpe}'"
30
+
31
+ find_header "fpe.h", clang_fpe_include_dir
32
+ find_header "fpe_locl.h", clang_fpe_include_dir
33
+
34
+ create_makefile("ruby_clang_fpe/ruby_clang_fpe")
@@ -0,0 +1,134 @@
1
+ #include "ruby_clang_fpe.h"
2
+ #include "fpe.h"
3
+ #include "fpe_locl.h"
4
+
5
+ VALUE rb_mRubyClangFpe;
6
+
7
+ size_t
8
+ fpe_get_size (const void *dsize){ return sizeof(dsize); };
9
+
10
+ static const rb_data_type_t fpe_type = {
11
+ "fpe",
12
+ { 0, RUBY_DEFAULT_FREE, fpe_get_size, },
13
+ 0, 0,
14
+ RUBY_TYPED_FREE_IMMEDIATELY,
15
+ };
16
+
17
+ static VALUE ffpe_alloc(VALUE);
18
+
19
+ static VALUE rb_cFpe; // RubyClangFpe::FpeKey class
20
+ static VALUE rb_cFpe3; // RubyClangFpe::Fpe3Key class
21
+ static VALUE rb_cFpe3_1; // RubyClangFpe::Fpe31Key class
22
+ static VALUE rb_cFpe1; // RubyClangFpe::Fpe1Key class
23
+
24
+ static VALUE t_gen_ff3_key(VALUE self, VALUE key, VALUE tweak, VALUE radix)
25
+ {
26
+ FPE_KEY *fpe_key;
27
+ fpe_key = FPE_ff3_create_key(StringValuePtr(key), StringValuePtr(tweak), NUM2UINT(radix));
28
+ if (fpe_key != NULL) {
29
+ return TypedData_Wrap_Struct(rb_cFpe3, &fpe_type, fpe_key);
30
+ } else {
31
+ return Qnil;
32
+ }
33
+ };
34
+
35
+ static VALUE t_gen_ff3_1_key(VALUE self, VALUE key, VALUE tweak, VALUE radix)
36
+ {
37
+ FPE_KEY *fpe_key;
38
+ fpe_key = FPE_ff3_1_create_key(StringValuePtr(key), StringValuePtr(tweak), NUM2UINT(radix));
39
+ if (fpe_key != NULL) {
40
+ return TypedData_Wrap_Struct(rb_cFpe3_1, &fpe_type, fpe_key);
41
+ } else {
42
+ return Qnil;
43
+ }
44
+ };
45
+
46
+ static VALUE t_gen_ff1_key(VALUE self, VALUE key, VALUE tweak, VALUE radix)
47
+ {
48
+ FPE_KEY *fpe_key;
49
+ fpe_key = FPE_ff1_create_key(StringValuePtr(key), StringValuePtr(tweak), NUM2UINT(radix));
50
+ if (fpe_key != NULL) {
51
+ return TypedData_Wrap_Struct(rb_cFpe1, &fpe_type, fpe_key);
52
+ } else {
53
+ return Qnil;
54
+ }
55
+ };
56
+
57
+ static VALUE t_ff3_encrypt(VALUE self, VALUE plaintext)
58
+ {
59
+ FPE_KEY *fpe_key_ptr;
60
+ TypedData_Get_Struct(self, FPE_KEY, &fpe_type, fpe_key_ptr);
61
+ char *plaintext_str = StringValueCStr(plaintext);
62
+ char ciphertext[strlen(plaintext_str)];
63
+ FPE_ff3_encrypt(plaintext_str, ciphertext, fpe_key_ptr);
64
+ return rb_str_new_cstr(ciphertext);
65
+ };
66
+
67
+ static VALUE t_ff3_decrypt(VALUE self, VALUE ciphertext)
68
+ {
69
+ FPE_KEY *fpe_key_ptr;
70
+ TypedData_Get_Struct(self, FPE_KEY, &fpe_type, fpe_key_ptr);
71
+ char plaintext[strlen(StringValueCStr(ciphertext))];
72
+ FPE_ff3_decrypt(StringValuePtr(ciphertext), plaintext, fpe_key_ptr);
73
+ return rb_str_new_cstr(plaintext);
74
+ };
75
+
76
+ static VALUE t_ff1_encrypt(VALUE self, VALUE plaintext)
77
+ {
78
+ FPE_KEY *fpe_key_ptr;
79
+ TypedData_Get_Struct(self, FPE_KEY, &fpe_type, fpe_key_ptr);
80
+ char ciphertext[strlen(StringValueCStr(plaintext))];
81
+ FPE_ff1_encrypt(StringValuePtr(plaintext), ciphertext, fpe_key_ptr);
82
+ return rb_str_new_cstr(ciphertext);
83
+ };
84
+
85
+ static VALUE t_ff1_decrypt(VALUE self, VALUE ciphertext)
86
+ {
87
+ FPE_KEY *fpe_key_ptr;
88
+ TypedData_Get_Struct(self, FPE_KEY, &fpe_type, fpe_key_ptr);
89
+ char plaintext[strlen(StringValueCStr(ciphertext))];
90
+ FPE_ff1_decrypt(StringValueCStr(ciphertext), plaintext, fpe_key_ptr);
91
+ return rb_str_new_cstr(plaintext);
92
+ };
93
+
94
+ /*
95
+ * call-seq:
96
+ * FpeKey.radix -> Integer
97
+ *
98
+ * Returns the integer value of the radix used to generate the key.
99
+ *
100
+ */
101
+ static VALUE t_radix(VALUE self)
102
+ {
103
+ FPE_KEY *fpe_key_ptr;
104
+ TypedData_Get_Struct(self, FPE_KEY, &fpe_type, fpe_key_ptr);
105
+ return UINT2NUM(fpe_key_ptr->radix);
106
+ };
107
+
108
+ static VALUE t_tweak(VALUE self)
109
+ {
110
+ FPE_KEY *fpe_key_ptr;
111
+ TypedData_Get_Struct(self, FPE_KEY, &fpe_type, fpe_key_ptr);
112
+ return rb_str_new_cstr(fpe_key_ptr->tweak);
113
+ };
114
+
115
+ void
116
+ Init_ruby_clang_fpe(void)
117
+ {
118
+ rb_mRubyClangFpe = rb_define_module("RubyClangFpe");
119
+ rb_cFpe = rb_define_class_under(rb_mRubyClangFpe, "FpeKey", rb_cObject);
120
+ rb_cFpe3 = rb_define_class_under(rb_mRubyClangFpe, "Fpe3Key", rb_cFpe);
121
+ rb_cFpe3_1 = rb_define_class_under(rb_mRubyClangFpe, "Fpe31Key", rb_cFpe);
122
+ rb_cFpe1 = rb_define_class_under(rb_mRubyClangFpe, "Fpe1Key", rb_cFpe);
123
+ rb_define_singleton_method(rb_cFpe, "generate_ff3_key", t_gen_ff3_key, 3);
124
+ rb_define_singleton_method(rb_cFpe, "generate_ff3_1_key", t_gen_ff3_1_key, 3);
125
+ rb_define_singleton_method(rb_cFpe, "generate_ff1_key", t_gen_ff1_key, 3);
126
+ rb_define_method(rb_cFpe, "radix", t_radix, 0);
127
+ rb_define_method(rb_cFpe, "tweak", t_tweak, 0);
128
+ rb_define_method(rb_cFpe3, "encrypt", t_ff3_encrypt, 1);
129
+ rb_define_method(rb_cFpe3_1, "encrypt", t_ff3_encrypt, 1);
130
+ rb_define_method(rb_cFpe1, "encrypt", t_ff1_encrypt, 1);
131
+ rb_define_method(rb_cFpe3, "decrypt", t_ff3_decrypt, 1);
132
+ rb_define_method(rb_cFpe3_1, "decrypt", t_ff3_decrypt, 1);
133
+ rb_define_method(rb_cFpe1, "decrypt", t_ff1_decrypt, 1);
134
+ }
@@ -0,0 +1,6 @@
1
+ #ifndef RUBY_CLANG_FPE_H
2
+ #define RUBY_CLANG_FPE_H 1
3
+
4
+ #include "ruby.h"
5
+
6
+ #endif /* RUBY_CLANG_FPE_H */
@@ -0,0 +1,20 @@
1
+ module RubyClangFpe
2
+ class FpeKey
3
+ def self.generate_key(type, key, tweak, radix)
4
+ new_key = case type
5
+ when :ff3
6
+ if (tweak.size / 2) == 7
7
+ generate_ff3_1_key(key, tweak, radix)
8
+ else
9
+ generate_ff3_key(key, tweak, radix)
10
+ end
11
+ when :ff1
12
+ generate_ff1_key(key, tweak, radix)
13
+ end
14
+
15
+ new_key
16
+ end
17
+
18
+ private_class_method :generate_ff3_key, :generate_ff1_key, :generate_ff3_1_key
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyClangFpe
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ruby_clang_fpe/version"
4
+ require_relative "ruby_clang_fpe/ruby_clang_fpe"
5
+ require_relative "ruby_clang_fpe/fpe_key"
6
+
7
+ module RubyClangFpe
8
+ class Error < StandardError; end
9
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/ruby_clang_fpe/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ruby_clang_fpe"
7
+ spec.version = RubyClangFpe::VERSION
8
+ spec.authors = ["Daniel Luna"]
9
+ spec.email = ["dancluna@gmail.com"]
10
+
11
+ spec.summary = "Ruby bindings for the Clang FPE library."
12
+ spec.description = "Format-preserving encryption for Ruby, based on https://github.com/mysto/clang-fpe."
13
+ spec.homepage = "https://github.com/dcluna/ruby_clang_fpe"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/dcluna/ruby_clang_fpe"
21
+ spec.metadata["changelog_uri"] = "https://github.com/dcluna/ruby_clang_fpe"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z --recurse-submodules`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
28
+ end
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+ spec.extensions = ["ext/ruby_clang_fpe/extconf.rb"]
34
+
35
+ # Uncomment to register a new dependency of your gem
36
+ # spec.add_dependency "example-gem", "~> 1.0"
37
+
38
+ # For more information and examples about making a new gem, check out our
39
+ # guide at: https://bundler.io/guides/creating_gem.html
40
+
41
+ spec.add_development_dependency "pry"
42
+ spec.add_development_dependency "pry-doc"
43
+ spec.add_development_dependency "pry-rescue"
44
+ spec.add_development_dependency "pry-stack_explorer"
45
+ end
@@ -0,0 +1,4 @@
1
+ module RubyClangFpe
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
@@ -0,0 +1,22 @@
1
+ name: C/C++ CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ "master", "git-actions" ]
6
+ pull_request:
7
+ branches: [ "master", "git-actions" ]
8
+
9
+ jobs:
10
+ build:
11
+
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - uses: actions/checkout@v3
16
+ - name: configure
17
+ run: ./configure
18
+ - name: make
19
+ run: make
20
+ - name: make test
21
+ run: make test
22
+
@@ -0,0 +1,3 @@
1
+ *.a
2
+ *.dylib
3
+ src/*.o
@@ -0,0 +1,2 @@
1
+ os: freebsd
2
+ language: c
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,60 @@
1
+ CFLAGS := $(shell printenv CFLAGS) -O2 -Wall -fPIC -Wno-deprecated-declarations
2
+ SO_LINKS = $(shell printenv LDFLAGS) -lm -lcrypto
3
+
4
+ UNAME := $(shell uname -s)
5
+ ifeq ($(UNAME),Darwin)
6
+ LIB = libfpe.a libfpe.dylib
7
+ else
8
+ LIB = libfpe.a libfpe.so
9
+ endif
10
+
11
+ EXAMPLE_SRC = example.c
12
+ EXAMPLE_EXE = example
13
+ OBJS = src/ff1.o src/ff3.o src/fpe_locl.o
14
+
15
+
16
+ all: $(LIB) $(EXAMPLE_EXE)
17
+
18
+ libfpe.a: $(OBJS)
19
+ ar rcs $@ $(OBJS)
20
+
21
+ ifeq ($(UNAME),Darwin)
22
+ libfpe.dylib: $(OBJS)
23
+ gcc -shared -fPIC -Wl,-install_name,libfpe.dylib $(OBJS) $(SO_LINKS) -o $@
24
+ else
25
+ libfpe.so: $(OBJS)
26
+ gcc -shared -fPIC -Wl,-soname,libfpe.so $(OBJS) $(SO_LINKS) -o $@
27
+ endif
28
+
29
+ .PHONY = all clean install
30
+
31
+ src/ff1.o: src/ff1.c
32
+ gcc $(CFLAGS) -c src/ff1.c -o $@
33
+
34
+ src/ff3.o: src/ff3.c
35
+ gcc $(CFLAGS) -c src/ff3.c -o $@
36
+
37
+ src/fpe_locl.o: src/fpe_locl.c
38
+ gcc $(CFLAGS) -c src/fpe_locl.c -o $@
39
+
40
+ $(EXAMPLE_EXE): $(EXAMPLE_SRC) $(LIB)
41
+ ifeq ($(UNAME),Darwin)
42
+ gcc $(CFLAGS) -Wl, $(EXAMPLE_SRC) -L. -lfpe $(SO_LINKS) -Isrc -o $@
43
+ else
44
+ gcc $(CFLAGS) -Wl,-rpath=\$$ORIGIN $(EXAMPLE_SRC) -L. -lfpe $(SO_LINKS) -Isrc -o $@
45
+ endif
46
+
47
+ test:
48
+ python test.py
49
+
50
+ # MacOS
51
+ leaks:
52
+ leaks -atExit -- ./example EF4359D8D580AA4F7F036D6F04FC6A94 D8E7920AFA330A73 10 890121234567890000
53
+
54
+ clean:
55
+ rm $(OBJS) $(EXAMPLE_EXE) $(LIB)
56
+
57
+ install:
58
+ cp libfpe.so /usr/local/lib
59
+ cp src/*.h /usr/local/include
60
+