ccipher_factory 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/Gemfile +30 -0
  4. data/Gemfile.lock-java +65 -0
  5. data/Gemfile.lock-ruby +67 -0
  6. data/README.md +80 -0
  7. data/Rakefile +10 -0
  8. data/bin/console +15 -0
  9. data/bin/setup +8 -0
  10. data/ccipher_factory.gemspec +46 -0
  11. data/lib/ccipher_factory/asymkey/asymkey.rb +16 -0
  12. data/lib/ccipher_factory/asymkey/asymkey_generator.rb +87 -0
  13. data/lib/ccipher_factory/asymkey/ecc_keypair.rb +56 -0
  14. data/lib/ccipher_factory/asymkey_cipher/asymkey_cipher.rb +63 -0
  15. data/lib/ccipher_factory/asymkey_cipher/asymkey_signer.rb +44 -0
  16. data/lib/ccipher_factory/asymkey_cipher/ecc/ecc_att_decrypt.rb +55 -0
  17. data/lib/ccipher_factory/asymkey_cipher/ecc/ecc_att_encrypt.rb +70 -0
  18. data/lib/ccipher_factory/asymkey_cipher/ecc/ecc_att_signer.rb +88 -0
  19. data/lib/ccipher_factory/asymkey_cipher/ecc/ecc_att_verifier.rb +100 -0
  20. data/lib/ccipher_factory/asymkey_cipher/ecc/ecc_decrypt.rb +80 -0
  21. data/lib/ccipher_factory/asymkey_cipher/ecc/ecc_encrypt.rb +101 -0
  22. data/lib/ccipher_factory/asymkey_cipher/ecc/ecc_signer.rb +80 -0
  23. data/lib/ccipher_factory/asymkey_cipher/ecc/ecc_verifier.rb +56 -0
  24. data/lib/ccipher_factory/composite_cipher/composite_cipher.rb +28 -0
  25. data/lib/ccipher_factory/composite_cipher/decrypt_verifier.rb +116 -0
  26. data/lib/ccipher_factory/composite_cipher/sign_encryptor.rb +100 -0
  27. data/lib/ccipher_factory/compression/compression_helper.rb +103 -0
  28. data/lib/ccipher_factory/compression/compressor.rb +55 -0
  29. data/lib/ccipher_factory/compression/zlib_compressor.rb +48 -0
  30. data/lib/ccipher_factory/compression/zlib_decompressor.rb +67 -0
  31. data/lib/ccipher_factory/digest/digest.rb +180 -0
  32. data/lib/ccipher_factory/digest/supported_digest.rb +47 -0
  33. data/lib/ccipher_factory/encoding/asn1.rb +43 -0
  34. data/lib/ccipher_factory/encoding/bin_struct.rb +207 -0
  35. data/lib/ccipher_factory/encoding/binenc_constant.rb +149 -0
  36. data/lib/ccipher_factory/helpers/common.rb +124 -0
  37. data/lib/ccipher_factory/kcv/kcv.rb +89 -0
  38. data/lib/ccipher_factory/kdf/hkdf.rb +114 -0
  39. data/lib/ccipher_factory/kdf/kdf.rb +73 -0
  40. data/lib/ccipher_factory/kdf/pbkdf2.rb +82 -0
  41. data/lib/ccipher_factory/kdf/scrypt.rb +105 -0
  42. data/lib/ccipher_factory/shamir/shamir_sharing.rb +293 -0
  43. data/lib/ccipher_factory/shamir/shamir_sharing_helper.rb +88 -0
  44. data/lib/ccipher_factory/symkey/derived_symkey.rb +110 -0
  45. data/lib/ccipher_factory/symkey/hardware_symkey.rb +0 -0
  46. data/lib/ccipher_factory/symkey/soft_symkey.rb +63 -0
  47. data/lib/ccipher_factory/symkey/symkey.rb +122 -0
  48. data/lib/ccipher_factory/symkey/symkey_generator.rb +70 -0
  49. data/lib/ccipher_factory/symkey_cipher/symkey_att_decrypt.rb +64 -0
  50. data/lib/ccipher_factory/symkey_cipher/symkey_att_encrypt.rb +65 -0
  51. data/lib/ccipher_factory/symkey_cipher/symkey_att_sign.rb +84 -0
  52. data/lib/ccipher_factory/symkey_cipher/symkey_att_verify.rb +85 -0
  53. data/lib/ccipher_factory/symkey_cipher/symkey_cipher.rb +101 -0
  54. data/lib/ccipher_factory/symkey_cipher/symkey_decrypt.rb +144 -0
  55. data/lib/ccipher_factory/symkey_cipher/symkey_encrypt.rb +164 -0
  56. data/lib/ccipher_factory/symkey_cipher/symkey_sign.rb +70 -0
  57. data/lib/ccipher_factory/symkey_cipher/symkey_signer.rb +59 -0
  58. data/lib/ccipher_factory/symkey_cipher/symkey_verify.rb +76 -0
  59. data/lib/ccipher_factory/version.rb +5 -0
  60. data/lib/ccipher_factory.rb +52 -0
  61. data/run_test.rb +27 -0
  62. metadata +172 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8e882748e988af57209ddc3342a3c791b60fcb8d78ad22ae83eaa607f1645d12
4
+ data.tar.gz: a2e9baaef537e4ede9201d677c8054e06c24344b2d8687481b13f0d31f8aa9b0
5
+ SHA512:
6
+ metadata.gz: 95101b641134a18fcdab9627ec321806ca71cf7ce6b90927e4e71f5929a20e9ecf7bb1d3bed32489bde32cc0aee3fb560030d80f7e79693d4fc47e1bc0eacfca
7
+ data.tar.gz: '0559a64e2c0e866fdbd6fcdd6f2c6bf850be2cf4d67770175a019b3b0e7f867820e970bce678396c8a05266fcb6d9f938afba4747910f7bbae3c66bf80891a93'
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in ccipher_factory.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ #gem 'ccrypto', git: 'ccrypto', branch: 'main'
13
+ #
14
+ #gem 'binenc', git: "binenc", branch: "master"
15
+
16
+ require 'toolrack'
17
+ if TR::RTUtils.on_jruby?
18
+ #gem 'ccrypto-java', git: 'ccrypto-java', branch: 'main'
19
+ #gem 'binenc-java', git: 'binenc-java', branch: 'master'
20
+ gem 'ccrypto-java'
21
+ gem 'binenc-java'
22
+ else
23
+ #gem 'ccrypto-ruby', git: 'ccrypto-ruby', branch: 'main'
24
+ #gem 'binenc-ruby', git: 'binenc-ruby', branch: 'master'
25
+ gem 'ccrypto-ruby'
26
+ gem 'binenc-ruby'
27
+ end
28
+
29
+
30
+
data/Gemfile.lock-java ADDED
@@ -0,0 +1,65 @@
1
+ GIT
2
+ remote: ccrypto
3
+ revision: beace29ef4e6eb76d77fcd90aea0f15bc5238e9f
4
+ branch: master
5
+ specs:
6
+ ccrypto (0.1.0)
7
+ tlogger
8
+ toolrack
9
+
10
+ GIT
11
+ remote: ccrypto-java
12
+ revision: d2fd06975696f958fa989ac41274583433d9b0c3
13
+ branch: master
14
+ specs:
15
+ ccrypto-java (0.1.0)
16
+
17
+ PATH
18
+ remote: .
19
+ specs:
20
+ ccipher_factory (0.1.0)
21
+ tlogger
22
+
23
+ GIT
24
+ remote: toolrack
25
+ revision: 8e1c8caf8bee89abc3759528b8f5bb22a3128e48
26
+ branch: master
27
+ specs:
28
+ toolrack (0.18.3)
29
+ base58
30
+ tlogger
31
+
32
+ GEM
33
+ remote: https://rubygems.org/
34
+ specs:
35
+ base58 (0.2.3)
36
+ diff-lcs (1.5.0)
37
+ rake (13.0.6)
38
+ rspec (3.11.0)
39
+ rspec-core (~> 3.11.0)
40
+ rspec-expectations (~> 3.11.0)
41
+ rspec-mocks (~> 3.11.0)
42
+ rspec-core (3.11.0)
43
+ rspec-support (~> 3.11.0)
44
+ rspec-expectations (3.11.0)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.11.0)
47
+ rspec-mocks (3.11.0)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.11.0)
50
+ rspec-support (3.11.0)
51
+ tlogger (0.26.3)
52
+
53
+ PLATFORMS
54
+ universal-java-11
55
+
56
+ DEPENDENCIES
57
+ ccipher_factory!
58
+ ccrypto!
59
+ ccrypto-java!
60
+ rake (~> 13.0)
61
+ rspec (~> 3.0)
62
+ toolrack!
63
+
64
+ BUNDLED WITH
65
+ 2.3.6
data/Gemfile.lock-ruby ADDED
@@ -0,0 +1,67 @@
1
+ GIT
2
+ remote: ccrypto
3
+ revision: beace29ef4e6eb76d77fcd90aea0f15bc5238e9f
4
+ branch: master
5
+ specs:
6
+ ccrypto (0.1.0)
7
+ tlogger
8
+ toolrack
9
+
10
+ GIT
11
+ remote: ccrypto-ruby
12
+ revision: e432e434e28bde01689a7b364cd08782f091120e
13
+ branch: master
14
+ specs:
15
+ ccrypto-ruby (0.1.0)
16
+ tlogger
17
+ toolrack
18
+
19
+ PATH
20
+ remote: .
21
+ specs:
22
+ ccipher_factory (0.1.0)
23
+ tlogger
24
+
25
+ GIT
26
+ remote: toolrack
27
+ revision: 8e1c8caf8bee89abc3759528b8f5bb22a3128e48
28
+ branch: master
29
+ specs:
30
+ toolrack (0.18.3)
31
+ base58
32
+ tlogger
33
+
34
+ GEM
35
+ remote: https://rubygems.org/
36
+ specs:
37
+ base58 (0.2.3)
38
+ diff-lcs (1.5.0)
39
+ rake (13.0.6)
40
+ rspec (3.11.0)
41
+ rspec-core (~> 3.11.0)
42
+ rspec-expectations (~> 3.11.0)
43
+ rspec-mocks (~> 3.11.0)
44
+ rspec-core (3.11.0)
45
+ rspec-support (~> 3.11.0)
46
+ rspec-expectations (3.11.0)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.11.0)
49
+ rspec-mocks (3.11.0)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.11.0)
52
+ rspec-support (3.11.0)
53
+ tlogger (0.26.3)
54
+
55
+ PLATFORMS
56
+ x86_64-linux
57
+
58
+ DEPENDENCIES
59
+ ccipher_factory!
60
+ ccrypto!
61
+ ccrypto-ruby!
62
+ rake (~> 13.0)
63
+ rspec (~> 3.0)
64
+ toolrack!
65
+
66
+ BUNDLED WITH
67
+ 2.2.28
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # CcipherFactory
2
+
3
+ CcipherFactory is the library that encapsulated all related parameters for a specific set of a cryptographic algorithms for operational requirement.
4
+
5
+ Cryptographic algorithms mostly have some parameters which are configurable during a specific operation. For example for AES encryption, there are different _modes_ and an _iv_ that could be provided by the caller application (or the _iv_ could be generated internally). The same value is required during decryption however, which is expected that the same _iv_ and _mode_ info is to be used during decryption or the decryption shall failed.
6
+
7
+ Normally those parameters are pre-selected by application, like AES with key size 256 bits and GCM mode. However this resulted in a cryptosystem that is rigid because those selection will be likely hard coded and when there is a broken algorithm come into light by researcher for example, or any reasons that a mode is more preferable than the pre-selected mode, the crypto system will requires update and testing. By this time, there is likely also a higher level of applications already has some assumption about the cipher text and once some parameters changed, it might affect those application too.
8
+
9
+ If the application has provision of the dynamicity of the cryptographic algorithms, those pre-selected parameters shall be stored in external files such as xml/yaml/text/database or anything that make sense. However, we think that a binaray coding is a more appropriate way to deliver the purpose since the cipher text is mostly a set of binary data.
10
+
11
+ Therefore the library upon signing/encryption cryptographic call, shall produce two outputs: the cipher text and the header.
12
+
13
+ The header is basically binary encoded structure of the cryptographic parameters. The cipher text is the actual output of the cryptographic algorithm.
14
+
15
+ During the reverse operations : verification / decryption, both pieces of the data shall be needed to be passed into the library in order for the operation to be successful.
16
+
17
+ Currently the supported algorithms including:
18
+ * Symmetric key
19
+ * Key generation / derivation from password
20
+ * Signing / verification (attached / detached)
21
+ * Encrypt / decrypt (attached / detached) with zlib compression option
22
+ * Asymmetric key (currently ECC only)
23
+ * Keypair generation
24
+ * Signing / verification (attached / detached)
25
+ * Encrypt / decryption (attached / detached) with zlib compression option
26
+ * Digest
27
+ * Key derivation function
28
+ * scrypt
29
+ * hkdf
30
+ * Shamir secret sharing
31
+
32
+
33
+ ## Attached vs. Detached
34
+
35
+ Attached mode is where the final output is the combination of the header and the cipher text. Therefore there is no separate storage required for the header and cipher text, instead a single file is what is needed for the cryptographic operation to operate.
36
+
37
+ However, in the event that the combined output is not preferable, the application can store the header and cipher text in any location as wished and pass into the library whenever it is requested.
38
+
39
+ Note that there is no implicit linkage info between the header and the cipher text is generated for detached mode. It means that the library has no way to check if the header is corresponding to the cipher text being processed and if there is a mixed up, recursive way is the only way to see if the header is correct with the help of the correct key material.
40
+
41
+
42
+ ## Actual Supported Cryptographic Algorithms
43
+
44
+ The actual supported cryptographic algorithms such as for symmetric, asymmetric etc is depending on the underlying cryptographic API. The project is integrated with [ccrypto](https://github.com/cameronian/ccrypto) which normalized the cryptographic API between Ruby and Java runtime.
45
+
46
+ At CcipherFactory effort has been done to tag as much algorithms as supported by the Ccrypto libraries implemented runtime as possible, which the tagging is done inside lib/ccipher\_factory/encoding/binenc\_constant.rb and its binary structure is defined in lib/ccipher\_factory/encoding/bin\_struct.rb
47
+
48
+
49
+ ## Installation
50
+
51
+ Add this line to your application's Gemfile:
52
+
53
+ ```ruby
54
+ # pre-requisite
55
+ gem 'ccrypto'
56
+
57
+ # if Ruby runtime
58
+ gem 'ccrypto-ruby'
59
+ # if Java runtime
60
+ #gem 'ccrypto-java'
61
+
62
+ # then include this
63
+ gem 'ccipher_factory'
64
+ ```
65
+
66
+ And then execute:
67
+
68
+ $ bundle install
69
+
70
+ Or install it yourself as:
71
+
72
+ $ gem install ccipher_factory
73
+
74
+
75
+ ## Usage Examples
76
+
77
+ Refers to files inside directory spec/ for more usage examples
78
+
79
+
80
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ require 'devops_assist'
7
+
8
+ RSpec::Core::RakeTask.new(:spec)
9
+
10
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "ccipher_factory"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/ccipher_factory/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ccipher_factory"
7
+ spec.version = CcipherFactory::VERSION
8
+ spec.authors = ["Ian"]
9
+ spec.email = ["cameronian0@protonmail.com"]
10
+
11
+ spec.summary = ""
12
+ spec.description = ""
13
+ spec.homepage = "https://github.com/cameronian/ccipher_factory"
14
+ spec.required_ruby_version = ">= 2.4.0"
15
+
16
+ #spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
17
+
18
+ #spec.metadata["homepage_uri"] = spec.homepage
19
+ #spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
20
+ #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
27
+ end
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency 'toolrack'
34
+ spec.add_dependency 'teLogger'
35
+
36
+ spec.add_dependency 'ccrypto'
37
+ spec.add_dependency 'binenc'
38
+
39
+ spec.add_development_dependency 'devops_assist'
40
+
41
+ # Uncomment to register a new dependency of your gem
42
+ # spec.add_dependency "example-gem", "~> 1.0"
43
+
44
+ # For more information and examples about making a new gem, checkout our
45
+ # guide at: https://bundler.io/guides/creating_gem.html
46
+ end
@@ -0,0 +1,16 @@
1
+
2
+
3
+ module CcipherFactory
4
+
5
+ module AsymKey
6
+
7
+ class AsymKeyError < StandardError; end
8
+
9
+ attr_accessor :keypair
10
+ def initialize(keypair = nil)
11
+ @keypair = keypair
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,87 @@
1
+
2
+
3
+ require 'openssl'
4
+ require_relative 'ecc_keypair'
5
+
6
+ module CcipherFactory
7
+ module AsymKeyGenerator
8
+ include TR::CondUtils
9
+
10
+ class AsymKeyGeneratorError < StandardError; end
11
+
12
+ def self.supported_asymkey
13
+ {
14
+ #ecc: Ccrypto::KeypairGenerator.instance(:ecc).curves
15
+ ecc: Ccrypto::AlgoFactory.engine(Ccrypto::ECCConfig).supported_curves
16
+ }
17
+ end
18
+
19
+ def self.set_default(keytype, opts = { }, &block)
20
+
21
+ defVal = algo_default(keytype)
22
+ defVal.merge!(opts)
23
+ defVal
24
+
25
+ end
26
+
27
+ def self.algo_default(keytype)
28
+ case keytype
29
+ when :ecc
30
+ @algoDef = { } if is_empty?(@algoDef)
31
+ @algoDef[:ecc] = { } if is_empty?(@algoDef[:ecc])
32
+ # default is NIST P-256
33
+ @algoDef[:ecc][:curve] = 'prime256v1' if is_empty?(@algoDef[:ecc][:curve])
34
+
35
+ @algoDef[:ecc]
36
+ else
37
+ raise AsymKeyGeneratorError, "Unknown default for '#{keytype}'"
38
+ end
39
+
40
+ end
41
+
42
+ def self.generate(keytype, opts = { }, &block)
43
+
44
+ raise AsymKeyGeneratorError, "Given key type '#{keytype}' is not supported. Supported key type are: #{supported_asymkey.keys.join(",")}" if not supported_asymkey.keys.include?(keytype)
45
+
46
+ case keytype
47
+ when :ecc
48
+
49
+ curve = opts[:curve]
50
+ curve = algo_default(:ecc)[:curve] if is_empty?(curve)
51
+
52
+ #raise AsymKeyGeneratorError, "Curve '#{curve}' is not supported. Supported curves are #{supported_asymkey[:ecc].join(", ")}" if not supported_asymkey[:ecc].include?(curve)
53
+
54
+ case curve
55
+ when Ccrypto::ECCConfig
56
+ logger.debug "ECCConfig"
57
+ key = Ccrypto::AlgoFactory.engine(curve).generate_keypair
58
+ ecKey = KeyPair::ECCKeyPair.new(key)
59
+ ecKey.curve = curve.curve
60
+ when String
61
+ logger.debug "String to ECCConfig"
62
+ key = Ccrypto::AlgoFactory.engine(Ccrypto::ECCConfig.new(curve)).generate_keypair
63
+ ecKey = KeyPair::ECCKeyPair.new(key)
64
+ ecKey.curve = curve
65
+ else
66
+ raise AsymKeyGeneratorError, "Unknown curve value type #{curve.class}"
67
+ end
68
+
69
+ logger.debug "Generated key : #{ecKey.inspect}"
70
+ ecKey
71
+
72
+ else
73
+ raise AsymKeyGeneratorError, "Unknown asymmetric key type '#{keytype}'"
74
+ end
75
+
76
+ end
77
+
78
+ def self.logger
79
+ if @logger.nil?
80
+ @logger = Tlogger.new
81
+ @logger.tag = :asym_keygen
82
+ end
83
+ @logger
84
+ end
85
+
86
+ end
87
+ end
@@ -0,0 +1,56 @@
1
+
2
+ require_relative 'asymkey'
3
+
4
+
5
+ module CcipherFactory
6
+ module KeyPair
7
+ class ECCKeyPair
8
+ include AsymKey
9
+ include TR::CondUtils
10
+
11
+ attr_writer :curve
12
+
13
+ def curve
14
+ if is_empty?(@curve) and not_empty?(@key)
15
+ @curve = @key.group.curve_name
16
+ end
17
+ @curve
18
+ end
19
+
20
+ def to_signer_info
21
+ bs = BinStruct.instance.struct(:ecc_signer_info)
22
+ bs.signer_info_value = @keypair.public_key.to_bin
23
+ bs.encoded
24
+ end
25
+
26
+ def self.from_signer_info(bin)
27
+
28
+ bs = BinStruct.instance.struct(:ecc_signer_info)
29
+ ts = bs.from_bin(bin)
30
+ siType = ts.signer_info_type
31
+ val = ts.signer_info_value
32
+ case BTag.value_constant(siType)
33
+ when :public_key
34
+ Ccrypto::AlgoFactory.engine(Ccrypto::ECCPublicKey).to_key(val)
35
+ else
36
+ raise AsymKeyError, "Unknown signer info type #{BTag.value_constant(siType)}"
37
+ end
38
+
39
+ end
40
+
41
+ def method_missing(mtd, *args, &block)
42
+ logger.debug "sending method #{mtd} to #{@keypair}"
43
+ @keypair.send(mtd, *args, &block)
44
+ end
45
+
46
+ def logger
47
+ if @logger.nil?
48
+ @logger = Tlogger.new
49
+ @logger.tag = :cf_ecc_keypair
50
+ end
51
+ @logger
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,63 @@
1
+
2
+
3
+ module CcipherFactory
4
+ module AsymKeyCipher
5
+ include TR::CondUtils
6
+
7
+ class ASKCipher; end
8
+
9
+ class AsymKeyCipherError < StandardError; end
10
+
11
+ def self.encryptor(eng = :ecc)
12
+ c = ASKCipher.new
13
+ case eng
14
+ when :ecc
15
+ c.extend(ECCEncrypt)
16
+ else
17
+ raise AsymKeyCipherError, "Not supported encryptor engine '#{eng}'"
18
+ end
19
+ c
20
+ end
21
+
22
+ def self.decryptor(eng = :ecc)
23
+ c = ASKCipher.new
24
+ case eng
25
+ when :ecc
26
+ c.extend(ECCDecrypt)
27
+ else
28
+ raise AsymKeyCipherError, "Not supoprted decryptor engine '#{eng}'"
29
+ end
30
+ c
31
+ end
32
+
33
+ def self.att_encryptor(eng = :ecc)
34
+ c = ASKCipher.new
35
+ case eng
36
+ when :ecc
37
+ c.extend(ECCAttEncrypt)
38
+ else
39
+ raise AsymKeyCipherError, "Not supported encryptor engine '#{eng}'"
40
+ end
41
+ c
42
+ end
43
+
44
+ def self.att_decryptor(eng = :ecc)
45
+ c = ASKCipher.new
46
+ case eng
47
+ when :ecc
48
+ c.extend(ECCAttDecrypt)
49
+ else
50
+ raise AsymKeyCipherError, "Not supoprted decryptor engine '#{eng}'"
51
+ end
52
+ c
53
+ end
54
+
55
+ end
56
+ end
57
+
58
+ require_relative 'ecc/ecc_encrypt'
59
+ require_relative 'ecc/ecc_decrypt'
60
+
61
+ require_relative 'ecc/ecc_att_encrypt'
62
+ require_relative 'ecc/ecc_att_decrypt'
63
+
@@ -0,0 +1,44 @@
1
+
2
+
3
+ module CcipherFactory
4
+ module AsymKeySigner
5
+
6
+ class ASKSigner; end
7
+ class ASKVerifier; end
8
+
9
+ class AsymKeySignerError < StandardError; end
10
+
11
+ def self.signer(eng = :ecc)
12
+ s = ASKSigner.new
13
+ s.extend(ECCSigner)
14
+ s
15
+ end
16
+
17
+ def self.verifier(eng = :ecc)
18
+ s = ASKSigner.new
19
+ s.extend(ECCVerifier)
20
+ s
21
+ end
22
+
23
+ def self.att_signer(eng = :ecc)
24
+ s = ASKSigner.new
25
+ s.extend(ECCAttSigner)
26
+ s
27
+ end
28
+
29
+ def self.att_verifier(eng = :ecc)
30
+ s = ASKSigner.new
31
+ s.extend(ECCAttVerifier)
32
+ s
33
+ end
34
+
35
+
36
+ end
37
+ end
38
+
39
+ require_relative 'ecc/ecc_signer'
40
+ require_relative 'ecc/ecc_verifier'
41
+
42
+ require_relative 'ecc/ecc_att_signer'
43
+ require_relative 'ecc/ecc_att_verifier'
44
+
@@ -0,0 +1,55 @@
1
+
2
+
3
+ module CcipherFactory
4
+ module AsymKeyCipher
5
+ module ECCAttDecrypt
6
+ include Common
7
+
8
+ attr_accessor :decryption_key
9
+ def att_decrypt_init(opts = { }, &block)
10
+
11
+ if block
12
+ instance_eval(&block)
13
+ att_decrypt_final
14
+ else
15
+ self
16
+ end
17
+
18
+ end
19
+
20
+ def att_decrypt_update(val)
21
+
22
+ if @dec.nil?
23
+ intOutputBuf.write(val)
24
+ begin
25
+ Encoding.extract_meta(intOutputBuf) do |meta, bal|
26
+
27
+ @dec = AsymKeyCipher.decryptor(:ecc)
28
+ @dec.output(@output)
29
+ @dec.decryption_key = @decryption_key
30
+ @dec.decrypt_init
31
+ @dec.decrypt_update_meta(meta)
32
+
33
+ att_decrypt_update(bal) if bal.length > 0
34
+
35
+ intOutputBuf.rewind
36
+ intOutputBuf = nil
37
+
38
+ end
39
+ rescue Encoding::InsufficientData => e
40
+ end
41
+
42
+ else
43
+ @dec.decrypt_update_cipher(val)
44
+ end
45
+ end
46
+
47
+ def att_decrypt_final
48
+ @dec.decrypt_final
49
+ end
50
+
51
+ end
52
+ end
53
+ end
54
+
55
+