x25519 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES.md +6 -0
- data/README.md +29 -31
- data/lib/x25519.rb +2 -0
- data/lib/x25519/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea3f150ae564aadb87e3bb463b2f4b7d8d8756b9
|
4
|
+
data.tar.gz: be24c272b97043d3f1385def5543fca88b9ff859
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b598f77e90d1fafbcb0b820d29966ba259a68c3bc1b44674f955a6ccbf010c30a8cc4339321bb55ddc3d27b3b3bce5e19ff1b4540855ee81235e8a55bf85675
|
7
|
+
data.tar.gz: 577ed0233e0a4a73452798c344531df9fbb498625c85526c02ca6658782559dce24538574b23a8eafb2f5adaf500331243ebd0a29dfb80a5bef6c03ee264c2e8
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -70,68 +70,66 @@ bob_secret = bob_sk.diffie_hellman(alice_pk).to_bytes
|
|
70
70
|
alice_secret == bob_secret # true
|
71
71
|
```
|
72
72
|
|
73
|
-
##
|
74
|
-
|
75
|
-
### `X25519::Scalar`: private keys
|
73
|
+
## X25519::Scalar: private keys
|
76
74
|
|
77
75
|
The `X25519::Scalar` class represents secret integers used as X25519 private
|
78
76
|
keys. These secret integers are multiplied by a well-known base point to
|
79
77
|
obtain X25519 public keys (`X25519::MontgomeryU`).
|
80
78
|
|
81
|
-
|
79
|
+
### `X25519::Scalar.generate()`: make a random private key
|
82
80
|
|
83
81
|
Generate a random private scalar (using `SecureRandom`)
|
84
82
|
|
85
|
-
|
83
|
+
**Example:**
|
86
84
|
|
87
85
|
```ruby
|
88
86
|
secret_key = X25519::Scalar.generate
|
89
87
|
```
|
90
88
|
|
91
|
-
|
89
|
+
### `X25519::Scalar.new(bytes)`: load existing private key
|
92
90
|
|
93
91
|
* `bytes`: a 32-byte `String` value containing the private key
|
94
92
|
|
95
|
-
|
93
|
+
**Example:**
|
96
94
|
|
97
95
|
```ruby
|
98
96
|
secret_key = X25519::Scalar.new(File.read("alice.key"))
|
99
97
|
```
|
100
98
|
|
101
|
-
|
99
|
+
### `X25519::Scalar#public_key()`: obtain public key for this scalar
|
102
100
|
|
103
101
|
NOTE: The `#multiply_base` method is an alias of this one.
|
104
102
|
|
105
103
|
Performs fixed-base scalar multiplication (i.e. calculates public key)
|
106
104
|
|
107
|
-
|
105
|
+
**Return Value:**
|
108
106
|
|
109
107
|
Returns a `X25519::MontgomeryU` object which represents the public key for this private key/scalar.
|
110
108
|
|
111
|
-
|
109
|
+
**Example:**
|
112
110
|
|
113
111
|
```ruby
|
114
112
|
secret_key = X25519::Scalar.generate
|
115
113
|
public_key = secret_key.public_key
|
116
114
|
```
|
117
115
|
|
118
|
-
|
116
|
+
### `X25519::Scalar#diffie_hellman(other_public_key)`: obtain public key for this scalar
|
119
117
|
|
120
118
|
NOTE: The `#multiply` method is an alias of this one.
|
121
119
|
|
122
120
|
Performs variable-base scalar multiplication, computing a shared secret between
|
123
121
|
our private scalar and someone else's public key/point.
|
124
122
|
|
125
|
-
|
126
|
-
|
127
|
-
Returns a `X25519::MontgomeryU` object which represents the shared secret.
|
128
|
-
|
129
|
-
##### Arguments
|
123
|
+
**Arguments:**
|
130
124
|
|
131
125
|
* `other_public_key`: a `X25519::MontgomeryU` object containing the public key
|
132
126
|
with which we'd like to compute a shared secret.
|
133
127
|
|
134
|
-
|
128
|
+
**Return Value:**
|
129
|
+
|
130
|
+
Returns a `X25519::MontgomeryU` object which represents the shared secret.
|
131
|
+
|
132
|
+
**Example:**
|
135
133
|
|
136
134
|
```ruby
|
137
135
|
secret_key = X25519::Scalar.generate
|
@@ -144,63 +142,63 @@ shared_secret = secret_key.multiply(public_key)
|
|
144
142
|
shared_secret_bytes = shared_secret.to_bytes
|
145
143
|
```
|
146
144
|
|
147
|
-
|
145
|
+
### `X25519::Scalar#to_bytes`: serialize a scalar as a `String`
|
148
146
|
|
149
|
-
|
147
|
+
**Return Value:**
|
150
148
|
|
151
149
|
Returns a `String` containing a byte representation of this scalar:
|
152
150
|
|
153
|
-
|
151
|
+
**Example:**
|
154
152
|
|
155
153
|
```ruby
|
156
154
|
secret_key = X25519::Scalar.new(...)
|
157
155
|
File.write("alice.key", secret_key.to_bytes)
|
158
156
|
```
|
159
157
|
|
160
|
-
|
158
|
+
## X25519::MontgomeryU: public keys and shared secrets
|
161
159
|
|
162
160
|
The `X25519::MontgomeryU` class represents a coordinate (specifically a
|
163
161
|
Montgomery-u coordinate) on the elliptic curve. In the X25519 Diffie-Hellman
|
164
162
|
function, these serve both as public keys and as shared secrets.
|
165
163
|
|
166
|
-
|
164
|
+
### `X25519::MontgomeryU.new(bytes)`: load existing public key
|
167
165
|
|
168
|
-
|
166
|
+
**Arguments:**
|
169
167
|
|
170
168
|
* `bytes`: a 32-byte `String` value containing the public key
|
171
169
|
|
172
|
-
|
170
|
+
**Example:**
|
173
171
|
|
174
172
|
```ruby
|
175
173
|
public_key = X25519::MontgomeryU.new(File.read("bob.pub"))
|
176
174
|
```
|
177
175
|
|
178
|
-
|
176
|
+
### `X25519::MontgomeryU#to_bytes`: serialize a Montgomery-u coordinate as a `String`
|
179
177
|
|
180
|
-
|
178
|
+
**Return Value:**
|
181
179
|
|
182
180
|
Returns a `String` containing a byte representation of a compressed Montgomery-u coordinate:
|
183
181
|
|
184
|
-
|
182
|
+
**Example:**
|
185
183
|
|
186
184
|
```ruby
|
187
185
|
public_key = X25519::MontgomeryU..new(...)
|
188
186
|
File.write("bob.pub", public_key.to_bytes)
|
189
187
|
```
|
190
188
|
|
191
|
-
|
189
|
+
## X25519: module-level functionality
|
192
190
|
|
193
|
-
|
191
|
+
### `X25519.diffie_hellman(secret_key, public_key)`: shorthand `String`-oriented API
|
194
192
|
|
195
193
|
If you'd like to avoid the object-oriented API, you can use a simplified API which
|
196
194
|
acts entirely on bytestrings.
|
197
195
|
|
198
|
-
|
196
|
+
**Arguments:**
|
199
197
|
|
200
198
|
* `secret_key`: a 32-byte `String` containing a private scalar
|
201
199
|
* `public_key`: a 32-byte `String` containing a compressed Montgomery-u coordinate
|
202
200
|
|
203
|
-
|
201
|
+
**Return Value:**
|
204
202
|
|
205
203
|
Returns a `String` containing a 32-byte compressed Montgomery-u coordinate
|
206
204
|
|
data/lib/x25519.rb
CHANGED
data/lib/x25519/version.rb
CHANGED