ed25519 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "java"
4
+
5
+ module Ed25519
6
+ # Core functionality provided by an Ed25519 library
7
+ module Engine
8
+ module_function
9
+
10
+ def create_keypair(seed)
11
+ raise ArgumentError, "seed must be 32 bytes long" unless seed.length == 32
12
+
13
+ verify_key = org.cryptosphere.ed25519.publickey(seed.to_java_bytes)
14
+ verify_key = String.from_java_bytes(verify_key)
15
+ [verify_key, seed + verify_key]
16
+ end
17
+
18
+ def sign(signing_key, message)
19
+ verify_key = signing_key[32...64].to_java_bytes
20
+ signing_key = signing_key[0...32].to_java_bytes
21
+
22
+ signature = org.cryptosphere.ed25519.signature(message.to_java_bytes, signing_key, verify_key)
23
+ String.from_java_bytes(signature)
24
+ end
25
+
26
+ def verify(verify_key, signature, message)
27
+ org.cryptosphere.ed25519.checkvalid(signature.to_java_bytes, message.to_java_bytes, verify_key.to_java_bytes)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "securerandom"
4
+
5
+ module Ed25519
6
+ # Private key for producing digital signatures
7
+ class SigningKey
8
+ attr_reader :verify_key
9
+
10
+ def self.generate
11
+ new SecureRandom.random_bytes(Ed25519::SECRET_KEY_BYTES)
12
+ end
13
+
14
+ def initialize(seed)
15
+ raise ArgumentError, "seed must be 32 bytes long" unless seed.length == SECRET_KEY_BYTES
16
+ @seed = seed
17
+
18
+ verify_key, @signing_key = Ed25519::Engine.create_keypair(seed)
19
+ @verify_key = VerifyKey.new(verify_key)
20
+ end
21
+
22
+ def sign(message)
23
+ Ed25519::Engine.sign(@signing_key, message)
24
+ end
25
+
26
+ def inspect
27
+ to_s
28
+ end
29
+
30
+ def to_bytes
31
+ @seed
32
+ end
33
+ alias to_str to_bytes
34
+ end
35
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ed25519
4
+ # Public key for verifying digital signatures
5
+ class VerifyKey
6
+ def initialize(key)
7
+ raise ArgumentError, "seed must be 32 bytes long" unless key.length == PUBLIC_KEY_BYTES
8
+ @key = key
9
+ end
10
+
11
+ def verify(signature, message)
12
+ if signature.length != SIGNATURE_BYTES
13
+ raise ArgumentError, "expected #{SIGNATURE_BYTES} byte signature, got #{signature.length}"
14
+ end
15
+
16
+ Ed25519::Engine.verify(@key, signature, message)
17
+ end
18
+
19
+ def inspect
20
+ to_s
21
+ end
22
+
23
+ def to_bytes
24
+ @key
25
+ end
26
+ alias to_str to_bytes
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ed25519
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ if defined? JRUBY_VERSION
4
+ require "rake/javaextensiontask"
5
+ Rake::JavaExtensionTask.new("ed25519_engine") do |ext|
6
+ ext.ext_dir = "ext/ed25519"
7
+ end
8
+ else
9
+ require "rake/extensiontask"
10
+
11
+ Rake::ExtensionTask.new("ed25519_engine") do |ext|
12
+ ext.ext_dir = "ext/ed25519"
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ RSpec::Core::RakeTask.new(:rcov) do |task|
8
+ task.rcov = true
9
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ed25519
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tony Arcieri
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-11 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ description: A Ruby binding to the Ed25519 elliptic curve public-key signature system
28
+ described in RFC 8032.
29
+ email:
30
+ - tony.arcieri@gmail.com
31
+ executables: []
32
+ extensions:
33
+ - ext/ed25519/extconf.rb
34
+ extra_rdoc_files: []
35
+ files:
36
+ - ".gitignore"
37
+ - ".rspec"
38
+ - ".rubocop.yml"
39
+ - ".travis.yml"
40
+ - CHANGES.md
41
+ - CODE_OF_CONDUCT.md
42
+ - Gemfile
43
+ - LICENSE
44
+ - README.md
45
+ - Rakefile
46
+ - ed25519.gemspec
47
+ - ed25519.png
48
+ - ext/ed25519/api.h
49
+ - ext/ed25519/crypto_int32.h
50
+ - ext/ed25519/crypto_sign.h
51
+ - ext/ed25519/crypto_uint32.h
52
+ - ext/ed25519/crypto_verify_32.h
53
+ - ext/ed25519/ed25519.c
54
+ - ext/ed25519/ed25519_engine.c
55
+ - ext/ed25519/extconf.rb
56
+ - ext/ed25519/fe25519.c
57
+ - ext/ed25519/fe25519.h
58
+ - ext/ed25519/ge25519.c
59
+ - ext/ed25519/ge25519.h
60
+ - ext/ed25519/ge25519_base.data
61
+ - ext/ed25519/org/cryptosphere/ed25519.java
62
+ - ext/ed25519/sc25519.c
63
+ - ext/ed25519/sc25519.h
64
+ - ext/ed25519/sha512-blocks.c
65
+ - ext/ed25519/sha512-hash.c
66
+ - ext/ed25519/sha512.h
67
+ - ext/ed25519/verify.c
68
+ - lib/ed25519.rb
69
+ - lib/ed25519/jruby_engine.rb
70
+ - lib/ed25519/signing_key.rb
71
+ - lib/ed25519/verify_key.rb
72
+ - lib/ed25519/version.rb
73
+ - tasks/extension.rake
74
+ - tasks/rspec.rake
75
+ homepage: https://github.com/cryptosphere/ed25519
76
+ licenses: []
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 2.2.2
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.6.13
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: An efficient digital signature library providing the Ed25519 algorithm
98
+ test_files: []