Skip to content

Commit b6e5859

Browse files
committed
dependencies upgrade
1 parent 114eb1a commit b6e5859

File tree

10 files changed

+279
-235
lines changed

10 files changed

+279
-235
lines changed

Cargo.lock

Lines changed: 125 additions & 84 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ repository = "https://github.com/mathisbot/homomorph-rust"
1010

1111
[dependencies]
1212
bincode = { version = "2.0.0-rc.3", default-features = false, features = ["alloc"] }
13-
getrandom = { version = "0.2.15", default-features = false, features = ["rdrand"] }
13+
getrandom = "0.3.1"
1414

1515
[dev-dependencies]
1616
criterion = "0.5.1"
17-
rand = "0.8.5"
17+
rand = "0.9.0"
1818

1919
[features]
20-
default = []
21-
custom_rand = ["getrandom/custom"]
2220
derive = ["bincode/derive"]
2321

2422
[profile.release]

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ on the stack wouldn't be possible (at least on low end machines).
5858
This is why the heap is needed here.
5959

6060
You may also need a source of randomness.
61-
On bare x86, randomness can still be retrieved using `RDRAND`.
62-
On other architectures, such as `aarch64-unknown-none`,
63-
you will have to implement `getrandom::register_custom_getrandom`,
64-
which is re-exported by the crate behind the `custom_rand` feature.
61+
The crate uses `getrandom` in the backend, so please refer to their documentation for a list of supported targets
62+
as well as instructions on how to implement a custom source for other targets.
6563

6664
## Benchmarks
6765

src/cipher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl CipheredBit {
8585
let num_elements = (tau + 7) / 8;
8686
let mut part = vec![0; num_elements];
8787

88-
getrandom::getrandom(&mut part).expect("failed to generate random data");
88+
getrandom::fill(&mut part).expect("failed to generate random data");
8989

9090
part
9191
}

src/context.rs

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use alloc::vec::Vec;
1515
/// ## Examples
1616
///
1717
/// ```
18-
/// use homomorph::Parameters;
19-
///
18+
/// # use homomorph::Parameters;
19+
/// #
2020
/// let parameters = Parameters::new(6, 3, 2, 5);
2121
/// ```
2222
///
@@ -38,6 +38,7 @@ pub struct SecretKeyUnset;
3838

3939
impl Parameters {
4040
#[must_use]
41+
#[inline]
4142
/// Creates a new set of parameters.
4243
///
4344
/// ## Arguments
@@ -64,8 +65,8 @@ impl Parameters {
6465
/// ## Examples
6566
///
6667
/// ```
67-
/// use homomorph::Parameters;
68-
///
68+
/// # use homomorph::Parameters;
69+
/// #
6970
/// let parameters = Parameters::new(6, 3, 2, 5);
7071
/// ```
7172
pub const fn new(d: u16, dp: u16, delta: u16, tau: u16) -> Self {
@@ -78,21 +79,25 @@ impl Parameters {
7879
}
7980

8081
#[must_use]
82+
#[inline]
8183
pub const fn d(&self) -> u16 {
8284
self.d
8385
}
8486

8587
#[must_use]
88+
#[inline]
8689
pub const fn dp(&self) -> u16 {
8790
self.dp
8891
}
8992

9093
#[must_use]
94+
#[inline]
9195
pub const fn delta(&self) -> u16 {
9296
self.delta
9397
}
9498

9599
#[must_use]
100+
#[inline]
96101
pub const fn tau(&self) -> u16 {
97102
self.tau
98103
}
@@ -104,6 +109,7 @@ pub struct SecretKey(Polynomial);
104109

105110
impl SecretKey {
106111
#[must_use]
112+
#[inline]
107113
/// Creates a new secret key.
108114
///
109115
/// ## Arguments
@@ -122,8 +128,8 @@ impl SecretKey {
122128
/// ## Examples
123129
///
124130
/// ```
125-
/// use homomorph::SecretKey;
126-
///
131+
/// # use homomorph::SecretKey;
132+
/// #
127133
/// // INSECURE!!! Only for demonstration purposes
128134
/// let s = vec![5, 14, 8];
129135
///
@@ -134,16 +140,20 @@ impl SecretKey {
134140
}
135141

136142
#[must_use]
143+
#[inline]
137144
/// Generates a random secret key of the given degree
138145
fn random(d: u16) -> Self {
139146
Self(Polynomial::random(d as usize))
140147
}
141148

149+
#[must_use]
150+
#[inline]
142151
pub(crate) const fn get_polynomial(&self) -> &Polynomial {
143152
&self.0
144153
}
145154

146155
#[must_use]
156+
#[inline]
147157
/// Returns bytes representing the secret key.
148158
///
149159
/// ## Returns
@@ -157,8 +167,8 @@ impl SecretKey {
157167
/// ## Examples
158168
///
159169
/// ```
160-
/// use homomorph::{Context, Parameters};
161-
///
170+
/// # use homomorph::{Context, Parameters};
171+
/// #
162172
/// let mut context = Context::new(Parameters::new(6, 3, 2, 5));
163173
/// context.generate_secret_key();
164174
///
@@ -204,8 +214,8 @@ impl PublicKey {
204214
/// ## Examples
205215
///
206216
/// ```
207-
/// use homomorph::PublicKey;
208-
///
217+
/// # use homomorph::PublicKey;
218+
/// #
209219
/// // INSECURE!!! Only for demonstration purposes
210220
/// let p = vec![vec![4, 7, 5], vec![1, 2, 3], vec![5, 4, 6]];
211221
///
@@ -235,6 +245,8 @@ impl PublicKey {
235245
Self(list.into_boxed_slice())
236246
}
237247

248+
#[must_use]
249+
#[inline]
238250
pub(crate) const fn get_polynomials(&self) -> &[Polynomial] {
239251
&self.0
240252
}
@@ -253,8 +265,8 @@ impl PublicKey {
253265
/// ## Examples
254266
///
255267
/// ```
256-
/// use homomorph::{Context, Parameters};
257-
///
268+
/// # use homomorph::{Context, Parameters};
269+
/// #
258270
/// let mut context = Context::new(Parameters::new(6, 3, 2, 5));
259271
/// context.generate_secret_key();
260272
/// context.generate_public_key().unwrap();
@@ -280,6 +292,7 @@ pub struct Context {
280292

281293
impl Context {
282294
#[must_use]
295+
#[inline]
283296
/// Creates a new context.
284297
///
285298
/// ## Arguments
@@ -293,8 +306,8 @@ impl Context {
293306
/// ## Examples
294307
///
295308
/// ```
296-
/// use homomorph::{Context, Parameters};
297-
///
309+
/// # use homomorph::{Context, Parameters};
310+
/// #
298311
/// let params = Parameters::new(6, 3, 2, 5);
299312
/// let mut context = Context::new(params);
300313
/// ```
@@ -307,11 +320,13 @@ impl Context {
307320
}
308321

309322
#[must_use]
323+
#[inline]
310324
pub const fn parameters(&self) -> &Parameters {
311325
&self.parameters
312326
}
313327

314328
#[must_use]
329+
#[inline]
315330
/// Returns a reference to the secret key.
316331
///
317332
/// ## Returns
@@ -321,8 +336,8 @@ impl Context {
321336
/// ## Examples
322337
///
323338
/// ```
324-
/// use homomorph::{Context, Parameters};
325-
///
339+
/// # use homomorph::{Context, Parameters};
340+
/// #
326341
/// let params = Parameters::new(6, 3, 2, 5);
327342
/// let mut context = Context::new(params);
328343
/// context.generate_secret_key();
@@ -333,6 +348,7 @@ impl Context {
333348
}
334349

335350
#[must_use]
351+
#[inline]
336352
/// Returns a reference to the public key.
337353
///
338354
/// ## Returns
@@ -342,8 +358,8 @@ impl Context {
342358
/// ## Examples
343359
///
344360
/// ```
345-
/// use homomorph::{Context, Parameters};
346-
///
361+
/// # use homomorph::{Context, Parameters};
362+
/// #
347363
/// let params = Parameters::new(6, 3, 2, 5);
348364
/// let mut context = Context::new(params);
349365
/// context.generate_secret_key();
@@ -354,6 +370,7 @@ impl Context {
354370
self.public_key.as_ref()
355371
}
356372

373+
#[inline]
357374
/// Generates a secret key.
358375
///
359376
/// ## Note
@@ -363,8 +380,8 @@ impl Context {
363380
/// ## Examples
364381
///
365382
/// ```
366-
/// use homomorph::{Context, Parameters};
367-
///
383+
/// # use homomorph::{Context, Parameters};
384+
/// #
368385
/// let params = Parameters::new(6, 3, 2, 5);
369386
/// let mut context = Context::new(params);
370387
///
@@ -375,6 +392,7 @@ impl Context {
375392
self.public_key = None;
376393
}
377394

395+
#[inline]
378396
/// Generates a public key out of the private key.
379397
///
380398
/// ## Errors
@@ -384,8 +402,8 @@ impl Context {
384402
/// ## Examples
385403
///
386404
/// ```
387-
/// use homomorph::{Context, Parameters};
388-
///
405+
/// # use homomorph::{Context, Parameters};
406+
/// #
389407
/// let params = Parameters::new(6, 3, 2, 5);
390408
/// let mut context = Context::new(params);
391409
/// context.generate_secret_key();
@@ -403,6 +421,7 @@ impl Context {
403421
Ok(())
404422
}
405423

424+
#[inline]
406425
/// Explicitly sets the secret key.
407426
///
408427
/// ## Arguments
@@ -412,8 +431,8 @@ impl Context {
412431
/// ## Examples
413432
///
414433
/// ```
415-
/// use homomorph::{Context, Parameters, SecretKey};
416-
///
434+
/// # use homomorph::{Context, Parameters, SecretKey};
435+
/// #
417436
/// let mut context = Context::new(Parameters::new(6, 3, 2, 5));
418437
///
419438
/// // INSECURE!!! Only for demonstration purposes
@@ -426,6 +445,7 @@ impl Context {
426445
self.secret_key = Some(secret_key);
427446
}
428447

448+
#[inline]
429449
/// Explicitly sets the public key.
430450
///
431451
/// ## Arguments
@@ -435,8 +455,8 @@ impl Context {
435455
/// ## Examples
436456
///
437457
/// ```
438-
/// use homomorph::{Context, Parameters, PublicKey};
439-
///
458+
/// # use homomorph::{Context, Parameters, PublicKey};
459+
/// #
440460
/// let mut context = Context::new(Parameters::new(6, 3, 2, 5));
441461
///
442462
/// // INSECURE!!! Only for demonstration purposes

0 commit comments

Comments
 (0)