fast-rsa-engine 0.2.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
+ SHA1:
3
+ metadata.gz: 2e56f7cc7015152e2a7728fa6f60248bd92d7df8
4
+ data.tar.gz: 13364603be73bc8463c93eb601519b90286c3b31
5
+ SHA512:
6
+ metadata.gz: d4fe8c846948f14b0643d2579a8e42403c9e24b9c0b76c3b337a1466cbfd6bdb85a573018dda6a2859a3fc7c78b43758628c5d330f662489243fcfffc2b9d051
7
+ data.tar.gz: f2b2c4bb8c4ce4b233141c8e73e26dfadd0022ab0a5f822851ab06d255aa82c3d83f1176d0fcc65ebc471f9d839cb377aa2abec3edce71d6a097f691c818e957
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg
2
+ pom*
3
+ *jar
4
+ *lock
data/.travis.yml ADDED
@@ -0,0 +1,18 @@
1
+ language: ruby
2
+ install: gem install bundler -v '~>1.10'; bundle install
3
+ gemfile:
4
+ - Gemfile
5
+ - Gemfile096
6
+ - Gemfile098
7
+ rvm:
8
+ - jruby-1.7.19
9
+ - jruby-1.7.21
10
+ - jruby-9.0.0.0
11
+ jdk:
12
+ - openjdk7
13
+ - oraclejdk8
14
+ matrix:
15
+ include:
16
+ - rvm: 1.9.3
17
+ gemfile: Gemfile
18
+ jdk: openjdk7
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+
4
+ gemspec
data/Gemfile096 ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+
4
+ gemspec
5
+
6
+ gem 'jruby-openssl', '0.9.6'
7
+
data/Gemfile098 ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+
4
+ gemspec
5
+
6
+ gem 'jruby-openssl', '0.9.8'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Lookout Inc.
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.
22
+
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Fast RSA Engine for jruby-openssl gem
2
+
3
+ [![Build Status](https://travis-ci.org/lookout/fast-rsa-engine.svg?branch=master)](https://travis-ci.org/lookout/fast-rsa-engine)
4
+
5
+ This gem replaces the RSA signature and RSA ciphers from jruby-openssl by the much faster implementation of them. See [corner.squareup.com/2014/02/faster-rsa-jnagmp.html](https://corner.squareup.com/2014/02/faster-rsa-jnagmp.html)
6
+
7
+ but this works only for **darwin** and **linux-x84_64** platforms due to the library used from squareup.
8
+
9
+ The improvement in performance brings JRuby verify and decrypy using RSA close to MRI.
10
+
11
+ ## installation
12
+
13
+ via rubygems
14
+ ```
15
+ gem install fast-rsa-engine
16
+ ```
17
+ or add to your Gemfile
18
+ ```
19
+ gem 'fast-rsa-engine'
20
+ ```
21
+
22
+ installing the gem also takes care of the jar dependencies with jruby-1.7.16+
23
+
24
+ ## usage
25
+
26
+ with bundler its auto-require magic will be sufficient. otherwise just
27
+
28
+ require 'fast-rsa-engine'
29
+
30
+ ## running the benchmark
31
+
32
+ ruby benchmark/benchmark-with-fast-rsa.rb
33
+
34
+ or
35
+ ruby benchmark/benchmark-with-builtin-rsa.rb
36
+
37
+ ## developement
38
+
39
+ get all the gems and jars in place
40
+
41
+ gem install jar-dependencies --development
42
+ bundle install
43
+
44
+ for running all specs
45
+
46
+ rake
47
+
48
+ ## meta-fu
49
+
50
+ enjoy :)
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ #-*- mode: ruby -*-
2
+
3
+ require 'bundler/gem_tasks'
4
+
5
+ if RUBY_PLATFORM == 'java'
6
+ require 'ruby-maven'
7
+
8
+ desc "Pack fast-rsa-engine.jar with the compiled classes"
9
+ task :jar do
10
+ raise unless RubyMaven.exec('-f', 'fast-rsa-engine.gemspec', 'prepare-package', '-Dmaven.test.skip')
11
+ end
12
+ else
13
+ task :jar do
14
+ end
15
+ end
16
+
17
+ require "rspec/core/rake_task"
18
+ RSpec::Core::RakeTask.new
19
+
20
+ require 'rubygems/package_task'
21
+ Gem::PackageTask.new( eval File.read( './fast-rsa-engine.gemspec' ) ) do
22
+ desc 'Pack fast-rsa-engine.gem'
23
+ task :package => [:jar]
24
+ end
25
+
26
+ task :default => [ :jar, :spec ]
27
+
28
+ # vim: syntax=ruby
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative 'benchmark'
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH << File.expand_path('../../lib', __FILE__)
4
+ if defined? JRUBY_VERSION
5
+ require 'fast-rsa-engine'
6
+ end
7
+ require_relative 'benchmark'
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ count = (ARGV[0] || 1000).to_i
4
+ path = File.dirname(__FILE__)
5
+
6
+ require 'base64'
7
+ require 'benchmark'
8
+ require 'openssl'
9
+
10
+ # configure keys
11
+ public_key_file = "#{path}/foo_cert.pem" # public key in cert file
12
+ private_key_file = "#{path}/foo.pem" # private key file
13
+
14
+ $public_key = OpenSSL::X509::Certificate.new(File.read(public_key_file)).public_key
15
+ $private_key = OpenSSL::PKey::RSA.new(File.read(private_key_file))
16
+
17
+ # example msg
18
+ msg = "THIS IS A TEST"
19
+
20
+ # example key for encrypt operation
21
+ aes = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
22
+ aes.encrypt
23
+ key = aes.random_key
24
+
25
+ def sign(msg)
26
+ $private_key.sign(OpenSSL::Digest.new('sha512'), msg)
27
+ end
28
+
29
+ def verify(msg, signature)
30
+ $public_key.verify(OpenSSL::Digest.new('sha512'), signature, msg)
31
+ end
32
+
33
+ def encrypt(content)
34
+ $public_key.public_encrypt(content)
35
+ end
36
+
37
+ def decrypt(encrypted_msg)
38
+ $private_key.private_decrypt(encrypted_msg)
39
+ end
40
+
41
+ # signature, encrypted key for verify, decrypt tests
42
+ signature = sign(msg)
43
+ encrypted_key = encrypt(msg)
44
+
45
+ puts "#{RUBY_ENGINE} N = #{count}"
46
+ Benchmark.bm(17) do |x|
47
+ x.report('sign') { count.times { sign(msg) } }
48
+ x.report('verify') { count.times { verify(msg, signature) } }
49
+ x.report('encrypt') { count.times { encrypt(key) } }
50
+ x.report('decrypt') { count.times { decrypt(encrypted_key) } }
51
+ end
52
+ puts
53
+ p verify(msg, signature)
54
+ p decrypt(encrypted_key)
data/benchmark/foo.pem ADDED
@@ -0,0 +1,51 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ MIIJKgIBAAKCAgEAtPhHvStOVd29e7ElR3+uUeFYDdmVJ9OW1XQOs2QPpxSnpWbe
3
+ ++NNoqroCGCliRbXHYoX+WpnbtdMDmLhSq4w4jmvL9CotFhfwhOtNY87GrEtMi2k
4
+ +//OHz7hBZ5FqxEgNuC/vCZoGFZvnGRLmtU0Q2B/7VV4zG9CiEumBdvZ6K40471X
5
+ L1c2W/AOyXXcGHVAO8PYF91CHu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LiXW9oBCjk6eA/kHM/FMCAwEAATANBgkqhkiG9w0BAQsF
18
+ AAOCAgEAdcnH4rVynCQWGYfR/n2XC0j34d058kfTqFuIYuTwEkY0jkIZqRBZuzwm
19
+ F88BKlRPk4qkkMXjRmvBisdcyFQiyvlf+fJlDuNKk21Dae+4P3HMz6xPK6vathKS
20
+ pAzQr9KDOp628c/8rGoxCV2hAkSyzHBC5WUwP8yBxWVG6QzqFrnUkTEo6x9S6RkG
21
+ 10g7YWi594L3RoJ/gFWKuqn3sGCetrqhQfrdskS5FaCEGLrs7/h74AJnjs6aVJCZ
22
+ LklsjPJpadd+WSFIRCGQhTWQUKVc8bil9vDxfIPW5Kj/DJvirbeJinGEIc7gR9WI
23
+ bYdje5UCphWlJr5ePGreyZvyDUElgTjhiiqWlUAgG5eJYJ2NEvH4g70laIDJZYt2
24
+ PZA0egp29+EKG3U3CXJkOoW8/z4mFgReYpWh/pqZesLePh4dbBrK/WCdAprKImZc
25
+ ymOD6K5IY9A0CeN6uW9VBnI0ed8KEGagfKCpCEBgbkhq27y7FVke1/oVXkWrXIFt
26
+ WfDd1hAJwUbxAeQXEwyAqDoCyKIvDqksGW+NL2o0N9DCP5cTMgho34WeUVdAuezM
27
+ 6wznqkkK9TB8mOtiJhPomlO2YL5/ShVVX0FoyQQ+ox2WMYIurbwguRVUAUNnfIdf
28
+ EqvJtVogFDekF8bxVA5RoiON8Dr8cDxSMU5eoH0Ixp3id5zsxQI=
29
+ -----END CERTIFICATE-----
@@ -0,0 +1,36 @@
1
+ #-*- mode: ruby -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'fast-rsa-engine'
5
+ s.version = '0.2.0'
6
+ s.author = 'Christian Meier'
7
+ s.email = [ 'christian.meier@lookout.com', 'rtyler.croy@lookout.com' ]
8
+
9
+ s.license = 'MIT'
10
+ s.summary = %q(replaces the RSA signature and RSA ciphers from jruby-openssl by a faster implementation of them)
11
+ s.homepage = 'https://github.com/lookout/fast-rsa-engine'
12
+ s.description = %q(this gem replaces the RSA signature and RSA ciphers from jruby-openssl by a faster implementation of them. see https://corner.squareup.com/2014/02/faster-rsa-jnagmp.html)
13
+
14
+ s.files = `git ls-files`.split($/)
15
+
16
+ if RUBY_PLATFORM == 'java'
17
+ unless defined?(BC_VERSION)
18
+ BC_VERSION = '1.50'
19
+ end
20
+ s.platform = 'java'
21
+ # needed for runtime
22
+ s.requirements << "jar com.squareup.jnagmp:bouncycastle-rsa, 1.0.0"
23
+ # needed for compilation
24
+ s.requirements << "jar org.bouncycastle:bcpkix-jdk15on, #{BC_VERSION}, :scope => :provided"
25
+ s.requirements << "jar org.bouncycastle:bcprov-jdk15on, #{BC_VERSION}, :scope => :provided"
26
+ s.requirements << "pom org.jruby:jruby-core, 1.7.21, :scope => :provided"
27
+
28
+ s.add_runtime_dependency 'jar-dependencies', '~> 0.1'
29
+ s.add_development_dependency 'ruby-maven', '~> 3.3'
30
+ end
31
+
32
+ s.add_development_dependency 'rspec', '~> 3.3'
33
+ s.add_development_dependency 'rake', '~> 10.2'
34
+ end
35
+
36
+ # vim: syntax=ruby
@@ -0,0 +1,32 @@
1
+ if RUBY_PLATFORM == 'java'
2
+ require 'fast-rsa-engine_jars.rb'
3
+ begin
4
+ Java::OrgJrubyExtOpenssl::SecurityHelper
5
+ warn 'openssl loaded before fast-rsa-engine'
6
+ rescue NameError
7
+ require 'fast-rsa-engine.jar'
8
+ end
9
+ require 'openssl'
10
+
11
+ # lexical compare is sufficient here
12
+ if Jopenssl::Version::VERSION > '0.9.5'
13
+ # keep the default name space clean and use tap
14
+ tap do
15
+ sign_names = [ "MD2", "MD4", "MD5",
16
+ "RIPEMD128", "RIPEMD160", "RIPEMD256",
17
+ "SHA1", "SHA224", "SHA256", "SHA384", "SHA512" ]
18
+ sign_names.each do |name|
19
+ full = "#{name}WITHRSA"
20
+ clazz = JRuby.runtime.jruby_class_loader.load_class( "com.github.lookout.fastrsa.FastDigestSignatureSpi$#{name}" )
21
+ Java::OrgJrubyExtOpenssl::SecurityHelper.add_signature(full, clazz)
22
+ end
23
+
24
+ Java::OrgJrubyExtOpenssl::SecurityHelper.add_cipher('RSA',
25
+ com.github.lookout.fastrsa.FastCipherSpi::NoPadding.java_class)
26
+ end
27
+ else
28
+ warn "jruby-openssl gem #{Jopenssl::Version::VERSION} is too old"
29
+ end
30
+ else
31
+ warn "fast-rsa-engine does not affect MRI"
32
+ end
@@ -0,0 +1,6 @@
1
+ # this is a generated file, to avoid over-writing it just delete this comment
2
+ require 'jar_dependencies'
3
+
4
+ require_jar( 'com.squareup.jnagmp', 'bouncycastle-rsa', '1.0.0' )
5
+ require_jar( 'net.java.dev.jna', 'jna', '4.0.0' )
6
+ require_jar( 'com.squareup.jnagmp', 'jnagmp', '1.0.0' )
@@ -0,0 +1,45 @@
1
+ require_relative 'setup'
2
+
3
+ describe 'Cipher' do
4
+
5
+ let( :this ) { File.expand_path( '..', __FILE__) }
6
+
7
+ let( :private_key ) {
8
+ file = File.read("#{this}/foo.pem")
9
+ OpenSSL::PKey::RSA.new(file)
10
+ }
11
+
12
+ let( :msg ) {
13
+ file = File.read("#{this}/foo_cert.pem")
14
+ public_key = OpenSSL::X509::Certificate.new(file).public_key
15
+ public_key.public_encrypt("THIS IS A TEST")
16
+ }
17
+
18
+ let( :rounds ) { 100 }
19
+
20
+ it 'is faster the regular cipher' do
21
+ skip( 'jruby too old' ) if too_old
22
+ # clear the fast engines
23
+ engines.clear
24
+
25
+ start = Time.new.to_f
26
+ rounds.times do
27
+ private_key.private_decrypt(msg)
28
+ end
29
+ delta1 = Time.new.to_f - start
30
+
31
+ # setup the fast engines
32
+ engines.clear
33
+ # this creates a warning
34
+ load( "${this}/../lib/fast-rsa-engine.rb" )
35
+
36
+ start = Time.new.to_f
37
+ rounds.times do
38
+ private_key.private_decrypt(msg)
39
+ end
40
+ delta2 = Time.new.to_f - start
41
+
42
+ expect( delta1 ).to be > 2 * delta2
43
+ end
44
+
45
+ end
data/spec/foo.pem ADDED
@@ -0,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