toy-ore 0.4.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/toy_ore/scheme.rb +18 -31
  3. metadata +13 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14c402bcf1c22a95a7b4d60495aedbe250cd3a3275fa6188b1e37bc27d9687ea
4
- data.tar.gz: 48f52855952c1a3e99abb71f6ad83f150a9e34740d5975b7b9633b8513284bf4
3
+ metadata.gz: 81f6a8809de85037a1fa3cbe0b9cc87f1294fd16e20ce5d4013bf129cbf02269
4
+ data.tar.gz: 8d7c2e1dd6dd66aea8506675c99e84de98cc8d48e363c753afd9703f36499a27
5
5
  SHA512:
6
- metadata.gz: 75ea2afab70dc8ea9c8f6f955afc39cd061e4cb2ad8a273e4cd642417c8d492d57951091810886d72b165c11bb8e5117aa8f8700b297e8eb6c2b35ee577609ca
7
- data.tar.gz: 17c96f1c99be3bf54be7bbde61125f1d1ecffe342d65e7e47b36e58f103b4b6bab07246316d5e246124802abd874f9219eed93d90dfd2f53a84ef2a1c47b2ec9
6
+ metadata.gz: 185e32105b0624161dbe1fff23cd5a58872595d3a0db3a630f387dd164a2f3deec2e9f080059c333bf931b14f387c1db203ca60a09fae75178011585b5abd567
7
+ data.tar.gz: b26ca8b171b0d4cac8910570b2dc853250c3897dfa426930c0a35f561dc5d6af20d78f0187e3c7c0f646c207740565b6aa1354b66c1879a7026673e1375331ed
@@ -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
- # Highlight that these are secrets.
115
+ def initialize(domain_size = 0..255)
116
+ @domain_size = domain_size
117
+
117
118
  # PRF key
118
- @keys = (0..255).to_a.shuffle()
119
+ @prf = (domain_size).to_a.shuffle()
119
120
  # PRP key
120
- @prp = (0..255).to_a.shuffle()
121
+ @prp = (domain_size).to_a.shuffle()
121
122
  end
122
123
 
123
124
  def encrypt(plaintext)
124
- iv = rand(0..255)
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 = (0..255).to_a
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 (the plaintext) is in the shuffled PRP array.
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, @keys[offset], cmp_result)
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], @keys[@prp[plaintext]], iv, encryptions)
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.0
4
+ version: 0.6.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-02 00:00:00.000000000 Z
11
+ date: 2023-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -66,13 +66,15 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: A toy library to get an understanding of how ore encryption works. This
70
- is an unsafe implementation, only to be used for educational purposes. DO NOT USE
71
- IN PRODUCTION.
69
+ description: A toy library to get an understanding of how order revealing encryption
70
+ works. This is an unsafe implementation, only to be used for educational purposes.
71
+ DO NOT USE IN PRODUCTION.
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