toy-ore 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/toy_ore/scheme.rb +18 -31
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b52bfdbda823e03bbfbef5111caf2422988a52a2caaae198696c6bb3aafce99d
|
4
|
+
data.tar.gz: 445ffb7611ae5b3db64c2a35b3fbda44e591df45ac4b22b08f97b2d0d7aafc4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2605cbacc5cf5088385173cb8b93c25e8133b6d119bf8f8d046c1f02991c65646458e4fa9951748aba24db2c3964c4a6653eb75b659525779b2bcafabeca83b2
|
7
|
+
data.tar.gz: a90e4baead02c90c9d3bfaab5a2b9f209fa33012c4762f9aabdcd2ca7e43f9fa7e9ef84815605f83a81935a4cf09f36d378b0541b0d7d06716270d4a12ef3e6b
|
data/lib/toy_ore/scheme.rb
CHANGED
@@ -17,13 +17,12 @@ module ToyOre
|
|
17
17
|
# @return [Integer]
|
18
18
|
def self.encrypt(iv, key, cmp_result)
|
19
19
|
(iv ^ key) ^ cmp_result
|
20
|
-
# binding.pry
|
21
20
|
end
|
22
21
|
|
23
22
|
# Compares 2 plaintexts and returns a cmp_result.
|
24
|
-
# If a < b -1
|
25
|
-
# If a == b 0
|
26
|
-
# if a > b 1
|
23
|
+
# If a < b = -1
|
24
|
+
# If a == b = 0
|
25
|
+
# if a > b = 1
|
27
26
|
#
|
28
27
|
# @param a [Integer] A plaintext integer value
|
29
28
|
#
|
@@ -49,6 +48,7 @@ module ToyOre
|
|
49
48
|
#
|
50
49
|
#
|
51
50
|
# @ return [Integer] The comparison result
|
51
|
+
#
|
52
52
|
# -1 if the left ciphertext is less than the right ciphertext
|
53
53
|
#
|
54
54
|
# 0 if the left ciphertext is equal to the right ciphertext
|
@@ -112,27 +112,28 @@ module ToyOre
|
|
112
112
|
end
|
113
113
|
|
114
114
|
class OreScheme
|
115
|
-
def initialize
|
116
|
-
|
115
|
+
def initialize(domain_size = 0..255)
|
116
|
+
@domain_size = domain_size
|
117
|
+
|
117
118
|
# PRF key
|
118
|
-
@
|
119
|
+
@prf = (domain_size).to_a.shuffle()
|
119
120
|
# PRP key
|
120
|
-
@prp = (
|
121
|
+
@prp = (domain_size).to_a.shuffle()
|
121
122
|
end
|
122
123
|
|
123
124
|
def encrypt(plaintext)
|
124
|
-
iv = rand(
|
125
|
-
# This represents all the values in the domain.
|
125
|
+
iv = rand(@domain_size)
|
126
126
|
|
127
|
+
# This represents all the values in the domain.
|
127
128
|
# This is a small domain example.
|
128
129
|
# This is 1 block, 1 byte, 8 bits, total value is 256.
|
129
|
-
domain = (
|
130
|
+
domain = (@domain_size).to_a
|
130
131
|
|
131
132
|
# Array to hold the encrypted value of the cmp result for each value in the domain.
|
132
133
|
encryptions = []
|
133
134
|
|
134
135
|
domain.each do |d|
|
135
|
-
# The offset is what ever index d (
|
136
|
+
# The offset is what ever index d (domain value) is in the shuffled PRP array.
|
136
137
|
# If we used the plaintext value as the offset, this would give away the value of the plaintext.
|
137
138
|
# Using the PRP, swaps the plaintext value for a random number in the PRP to store the encrypted
|
138
139
|
# comparison result in the right ciphertext encryptions array.
|
@@ -154,40 +155,26 @@ module ToyOre
|
|
154
155
|
# random shuffled key array.
|
155
156
|
#
|
156
157
|
#
|
157
|
-
encryptions[offset] = ToyOre::Scheme.encrypt(iv, @
|
158
|
+
encryptions[offset] = ToyOre::Scheme.encrypt(iv, @prf[offset], cmp_result)
|
158
159
|
end
|
159
160
|
|
160
161
|
# The left ciphertext:
|
161
|
-
# Query ciphertext
|
162
162
|
# 1. Stores the value of the offset.
|
163
|
-
|
163
|
+
#
|
164
164
|
# The offset is the index of the encrypted comparison result,
|
165
165
|
# in the encryptions array.
|
166
166
|
#
|
167
|
-
# 2. Stores the key that was used to encrypt the comparison result
|
167
|
+
# 2. Stores the key that was used to encrypt the comparison result
|
168
|
+
# at the offset in the right ciphertext.
|
168
169
|
#
|
169
170
|
# The right ciphertext:
|
170
|
-
# Persisted
|
171
171
|
#
|
172
172
|
# 1. Stores the IV used in the encryption
|
173
173
|
# 2. Stores an array of all encrypted comparison results.
|
174
174
|
#
|
175
175
|
#
|
176
|
-
OreCiphertext.new(@prp[plaintext], @
|
176
|
+
OreCiphertext.new(@prp[plaintext], @prf[@prp[plaintext]], iv, encryptions)
|
177
177
|
end
|
178
178
|
end
|
179
179
|
end
|
180
180
|
end
|
181
|
-
|
182
|
-
|
183
|
-
# TODO make ciphertext a class.
|
184
|
-
# make left a class and right a class
|
185
|
-
# on the left ciphertext implement the comparison
|
186
|
-
|
187
|
-
# class LeftCiphertext
|
188
|
-
# def <=>(right_ciphertext)
|
189
|
-
# ToyOre::Scheme.compare_ciphertexts(self, right_ciphertext
|
190
|
-
|
191
|
-
# )
|
192
|
-
# end
|
193
|
-
# end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toy-ore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fiona McCawley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -72,7 +72,9 @@ description: A toy library to get an understanding of how ore encryption works.
|
|
72
72
|
email: fimccawley@gmail.com
|
73
73
|
executables: []
|
74
74
|
extensions: []
|
75
|
-
extra_rdoc_files:
|
75
|
+
extra_rdoc_files:
|
76
|
+
- lib/toy_ore.rb
|
77
|
+
- lib/toy_ore/scheme.rb
|
76
78
|
files:
|
77
79
|
- lib/toy_ore.rb
|
78
80
|
- lib/toy_ore/scheme.rb
|
@@ -84,7 +86,11 @@ metadata:
|
|
84
86
|
source_code_uri: https://github.com/fimac/toy_ore_rb
|
85
87
|
documentation_uri: https://rubydoc.info/gems/toy-ore
|
86
88
|
post_install_message:
|
87
|
-
rdoc_options:
|
89
|
+
rdoc_options:
|
90
|
+
- "--main"
|
91
|
+
- README.rdoc
|
92
|
+
- "--title"
|
93
|
+
- 'Ruby Toy ORE Library: Educational tool to learn about Order Revealing Encryption'
|
88
94
|
require_paths:
|
89
95
|
- lib
|
90
96
|
required_ruby_version: !ruby/object:Gem::Requirement
|