Skip to content

Commit eb2947e

Browse files
committed
Fix Rng
1 parent a1249d5 commit eb2947e

File tree

18 files changed

+84
-91
lines changed

18 files changed

+84
-91
lines changed

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ required-features = ["build-binary"]
4242

4343
[dependencies]
4444
curve25519-dalek = { version = "=5.0.0-pre.6", features = ["rand_core", "lizard"] }
45-
rand_core = "=0.10.0"
46-
rand = { version = "=0.10.0", optional = true }
47-
sha2 = "^0.11.0-rc.3"
48-
hmac = "^0.13.0-rc.3"
45+
rand_core = "^0.10"
46+
rand = { version = "^0.10", optional = true }
47+
sha2 = "^0.11.0-rc.5"
48+
hmac = "^0.13.0-rc.5"
4949
derive_more = { version = "^2.0", features = ["deref", "from", "into"] }
5050
hex = "^0.4"
5151
base64 = "^0.22"

src/lib/arithmetic/group_elements.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use curve25519_dalek::ristretto::CompressedRistretto;
22
use curve25519_dalek::ristretto::RistrettoPoint;
33
use curve25519_dalek::traits::Identity;
4-
use rand_core::{CryptoRng, RngCore};
4+
use rand_core::{CryptoRng, Rng};
55
#[cfg(feature = "serde")]
66
use serde::de::{Error, Visitor};
77
#[cfg(feature = "serde")]
@@ -26,7 +26,7 @@ pub struct GroupElement(pub(crate) RistrettoPoint);
2626
impl GroupElement {
2727
/// Generate a random `GroupElement`. This is the preferred way of generating pseudonyms.
2828
#[must_use]
29-
pub fn random<R: RngCore + CryptoRng>(rng: &mut R) -> Self {
29+
pub fn random<R: Rng + CryptoRng>(rng: &mut R) -> Self {
3030
Self(RistrettoPoint::random(rng))
3131
}
3232

@@ -306,7 +306,6 @@ impl std::ops::Mul<GroupElement> for ScalarCanBeZero {
306306
mod tests {
307307
use super::*;
308308
use crate::arithmetic::scalars::ScalarNonZero;
309-
use rand_core::RngCore;
310309

311310
#[test]
312311
fn encode_decode() {

src/lib/arithmetic/scalars.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use curve25519_dalek::scalar::Scalar;
2-
use rand_core::{CryptoRng, RngCore};
2+
use rand_core::{CryptoRng, Rng};
33
#[cfg(feature = "serde")]
44
use serde::de::{Error, Visitor};
55
#[cfg(feature = "serde")]
@@ -22,7 +22,7 @@ pub struct ScalarNonZero(pub(crate) Scalar);
2222
impl ScalarNonZero {
2323
/// Always return a random non-zero scalar.
2424
#[must_use]
25-
pub fn random<R: RngCore + CryptoRng>(rng: &mut R) -> Self {
25+
pub fn random<R: Rng + CryptoRng>(rng: &mut R) -> Self {
2626
loop {
2727
let r = ScalarCanBeZero::random(rng);
2828
if let Ok(s) = r.try_into() {
@@ -83,7 +83,7 @@ pub struct ScalarCanBeZero(pub(crate) Scalar);
8383
impl ScalarCanBeZero {
8484
/// Generate a random scalar.
8585
#[must_use]
86-
pub fn random<R: RngCore + CryptoRng>(rng: &mut R) -> Self {
86+
pub fn random<R: Rng + CryptoRng>(rng: &mut R) -> Self {
8787
Self(Scalar::random(rng))
8888
}
8989

src/lib/client/batch.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::data::traits::{Encryptable, Encrypted};
44
use crate::transcryptor::batch::BatchError;
5-
use rand_core::{CryptoRng, RngCore};
5+
use rand_core::{CryptoRng, Rng};
66

77
/// Polymorphic batch encryption.
88
///
@@ -19,7 +19,7 @@ pub fn encrypt_batch<M, R>(
1919
) -> Result<Vec<M::EncryptedType>, BatchError>
2020
where
2121
M: Encryptable,
22-
R: RngCore + CryptoRng,
22+
R: Rng + CryptoRng,
2323
{
2424
Ok(messages
2525
.iter()
@@ -43,7 +43,7 @@ pub fn encrypt_global_batch<M, R>(
4343
) -> Result<Vec<M::EncryptedType>, BatchError>
4444
where
4545
M: Encryptable,
46-
R: RngCore + CryptoRng,
46+
R: Rng + CryptoRng,
4747
{
4848
Ok(messages
4949
.iter()

src/lib/client/functions.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Polymorphic encryption and decryption helper functions for client operations.
22
33
use crate::data::traits::{Encryptable, Encrypted};
4-
use rand_core::{CryptoRng, RngCore};
4+
use rand_core::{CryptoRng, Rng};
55

66
/// Polymorphic encrypt function that works for any encryptable type.
77
///
@@ -14,7 +14,7 @@ use rand_core::{CryptoRng, RngCore};
1414
pub fn encrypt<M, R>(message: &M, public_key: &M::PublicKeyType, rng: &mut R) -> M::EncryptedType
1515
where
1616
M: Encryptable,
17-
R: RngCore + CryptoRng,
17+
R: Rng + CryptoRng,
1818
{
1919
message.encrypt(public_key, rng)
2020
}
@@ -64,7 +64,7 @@ pub fn encrypt_global<M, R>(
6464
) -> M::EncryptedType
6565
where
6666
M: Encryptable,
67-
R: RngCore + CryptoRng,
67+
R: Rng + CryptoRng,
6868
{
6969
message.encrypt_global(public_key, rng)
7070
}

src/lib/client/types.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::data::traits::{Encryptable, Encrypted};
44
use crate::keys::{GlobalPublicKeys, KeyProvider, SessionKeys};
5-
use rand_core::{CryptoRng, RngCore};
5+
use rand_core::{CryptoRng, Rng};
66

77
/// A PEP client that can encrypt and decrypt data, based on session key pairs for pseudonyms and attributes.
88
#[derive(Clone)]
@@ -32,7 +32,7 @@ impl Client {
3232
where
3333
M: Encryptable,
3434
SessionKeys: KeyProvider<M::PublicKeyType>,
35-
R: RngCore + CryptoRng,
35+
R: Rng + CryptoRng,
3636
{
3737
message.encrypt(self.keys.get_key(), rng)
3838
}
@@ -71,7 +71,7 @@ impl Client {
7171
where
7272
M: Encryptable,
7373
SessionKeys: KeyProvider<M::PublicKeyType>,
74-
R: RngCore + CryptoRng,
74+
R: Rng + CryptoRng,
7575
{
7676
super::batch::encrypt_batch(messages, self.keys.get_key(), rng)
7777
}
@@ -129,7 +129,7 @@ impl OfflineClient {
129129
where
130130
M: Encryptable,
131131
GlobalPublicKeys: KeyProvider<M::GlobalPublicKeyType>,
132-
R: RngCore + CryptoRng,
132+
R: Rng + CryptoRng,
133133
{
134134
message.encrypt_global(self.global_public_keys.get_key(), rng)
135135
}
@@ -145,7 +145,7 @@ impl OfflineClient {
145145
where
146146
M: Encryptable,
147147
GlobalPublicKeys: KeyProvider<M::GlobalPublicKeyType>,
148-
R: RngCore + CryptoRng,
148+
R: Rng + CryptoRng,
149149
{
150150
super::batch::encrypt_global_batch(messages, self.global_public_keys.get_key(), rng)
151151
}

src/lib/core/elgamal.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::arithmetic::group_elements::{GroupElement, G};
44
use crate::arithmetic::scalars::ScalarNonZero;
55
use base64::engine::general_purpose;
66
use base64::Engine;
7-
use rand_core::{CryptoRng, RngCore};
7+
use rand_core::{CryptoRng, Rng};
88
#[cfg(feature = "serde")]
99
use serde::de::{Error, Visitor};
1010
#[cfg(feature = "serde")]
@@ -121,11 +121,7 @@ impl<'de> Deserialize<'de> for ElGamal {
121121
/// The randomness is generated using the provided random number generator `rng`.
122122
///
123123
/// Encryption may **not** be done with public key [`GroupElement::identity`], which is checked with an assertion.
124-
pub fn encrypt<R: RngCore + CryptoRng>(
125-
gm: &GroupElement,
126-
gy: &GroupElement,
127-
rng: &mut R,
128-
) -> ElGamal {
124+
pub fn encrypt<R: Rng + CryptoRng>(gm: &GroupElement, gy: &GroupElement, rng: &mut R) -> ElGamal {
129125
assert_ne!(gy, &GroupElement::identity()); // we should not encrypt anything with an empty public key, as this will result in plain text sent over the line
130126
let r = ScalarNonZero::random(rng); // random() should never return a zero scalar
131127
ElGamal {

src/lib/data/json/data.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::keys::GlobalPublicKeys;
1616
#[cfg(all(feature = "offline", feature = "insecure"))]
1717
use crate::keys::GlobalSecretKeys;
1818
use crate::keys::SessionKeys;
19-
use rand_core::{CryptoRng, RngCore};
19+
use rand_core::{CryptoRng, Rng};
2020
#[cfg(feature = "serde")]
2121
use serde::{Deserialize, Serialize};
2222
use serde_json::Value;
@@ -230,7 +230,7 @@ impl Encryptable for PEPJSONValue {
230230
#[cfg(feature = "offline")]
231231
type GlobalPublicKeyType = GlobalPublicKeys;
232232

233-
fn encrypt<R: RngCore + CryptoRng>(
233+
fn encrypt<R: Rng + CryptoRng>(
234234
&self,
235235
keys: &Self::PublicKeyType,
236236
rng: &mut R,
@@ -266,7 +266,7 @@ impl Encryptable for PEPJSONValue {
266266
}
267267
}
268268
#[cfg(feature = "offline")]
269-
fn encrypt_global<R: RngCore + CryptoRng>(
269+
fn encrypt_global<R: Rng + CryptoRng>(
270270
&self,
271271
public_key: &Self::GlobalPublicKeyType,
272272
rng: &mut R,
@@ -463,7 +463,7 @@ impl Encrypted for EncryptedPEPJSONValue {
463463
#[cfg(feature = "elgamal3")]
464464
fn rerandomize<R>(&self, rng: &mut R) -> Self
465465
where
466-
R: RngCore + CryptoRng,
466+
R: Rng + CryptoRng,
467467
{
468468
let r = ScalarNonZero::random(rng);
469469
self.rerandomize_known(&RerandomizeFactor(r))
@@ -476,7 +476,7 @@ impl Encrypted for EncryptedPEPJSONValue {
476476
rng: &mut R,
477477
) -> Self
478478
where
479-
R: RngCore + CryptoRng,
479+
R: Rng + CryptoRng,
480480
{
481481
let r = ScalarNonZero::random(rng);
482482
self.rerandomize_known(public_key, &RerandomizeFactor(r))

src/lib/data/long.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::keys::{
1818
PseudonymGlobalPublicKey, PseudonymSessionPublicKey, PseudonymSessionSecretKey,
1919
};
2020
use derive_more::{Deref, From};
21-
use rand_core::{CryptoRng, RngCore};
21+
use rand_core::{CryptoRng, Rng};
2222
#[cfg(feature = "serde")]
2323
use serde::{Deserialize, Deserializer, Serialize, Serializer};
2424
use std::io::{Error, ErrorKind};
@@ -444,7 +444,7 @@ impl Encryptable for LongPseudonym {
444444

445445
fn encrypt<R>(&self, public_key: &Self::PublicKeyType, rng: &mut R) -> Self::EncryptedType
446446
where
447-
R: RngCore + CryptoRng,
447+
R: Rng + CryptoRng,
448448
{
449449
let encrypted_blocks = self
450450
.blocks()
@@ -461,7 +461,7 @@ impl Encryptable for LongPseudonym {
461461
rng: &mut R,
462462
) -> Self::EncryptedType
463463
where
464-
R: RngCore + CryptoRng,
464+
R: Rng + CryptoRng,
465465
{
466466
let encrypted_blocks = self
467467
.blocks()
@@ -497,7 +497,7 @@ impl Encryptable for LongAttribute {
497497

498498
fn encrypt<R>(&self, public_key: &Self::PublicKeyType, rng: &mut R) -> Self::EncryptedType
499499
where
500-
R: RngCore + CryptoRng,
500+
R: Rng + CryptoRng,
501501
{
502502
let encrypted_blocks = self
503503
.blocks()
@@ -514,7 +514,7 @@ impl Encryptable for LongAttribute {
514514
rng: &mut R,
515515
) -> Self::EncryptedType
516516
where
517-
R: RngCore + CryptoRng,
517+
R: Rng + CryptoRng,
518518
{
519519
let encrypted_blocks = self
520520
.blocks()
@@ -636,7 +636,7 @@ impl Encrypted for LongEncryptedPseudonym {
636636
#[cfg(feature = "elgamal3")]
637637
fn rerandomize<R>(&self, rng: &mut R) -> Self
638638
where
639-
R: RngCore + CryptoRng,
639+
R: Rng + CryptoRng,
640640
{
641641
let r = ScalarNonZero::random(rng);
642642
self.rerandomize_known(&RerandomizeFactor(r))
@@ -649,7 +649,7 @@ impl Encrypted for LongEncryptedPseudonym {
649649
rng: &mut R,
650650
) -> Self
651651
where
652-
R: RngCore + CryptoRng,
652+
R: Rng + CryptoRng,
653653
{
654654
let r = ScalarNonZero::random(rng);
655655
self.rerandomize_known(public_key, &RerandomizeFactor(r))
@@ -733,7 +733,7 @@ impl Encrypted for LongEncryptedAttribute {
733733
#[cfg(feature = "elgamal3")]
734734
fn rerandomize<R>(&self, rng: &mut R) -> Self
735735
where
736-
R: RngCore + CryptoRng,
736+
R: Rng + CryptoRng,
737737
{
738738
let r = ScalarNonZero::random(rng);
739739
self.rerandomize_known(&RerandomizeFactor(r))
@@ -746,7 +746,7 @@ impl Encrypted for LongEncryptedAttribute {
746746
rng: &mut R,
747747
) -> Self
748748
where
749-
R: RngCore + CryptoRng,
749+
R: Rng + CryptoRng,
750750
{
751751
let r = ScalarNonZero::random(rng);
752752
self.rerandomize_known(public_key, &RerandomizeFactor(r))

src/lib/data/records.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::data::simple::{
99
use crate::data::traits::{Encryptable, Encrypted, Transcryptable};
1010
use crate::factors::TranscryptionInfo;
1111
use crate::keys::{GlobalPublicKeys, SessionKeys};
12-
use rand_core::{CryptoRng, RngCore};
12+
use rand_core::{CryptoRng, Rng};
1313
#[cfg(feature = "serde")]
1414
use serde::{Deserialize, Deserializer, Serialize, Serializer};
1515
use std::io::{Error, ErrorKind};
@@ -271,7 +271,7 @@ impl Encryptable for Record {
271271

272272
fn encrypt<R>(&self, keys: &Self::PublicKeyType, rng: &mut R) -> Self::EncryptedType
273273
where
274-
R: RngCore + CryptoRng,
274+
R: Rng + CryptoRng,
275275
{
276276
EncryptedRecord {
277277
pseudonyms: self
@@ -294,7 +294,7 @@ impl Encryptable for Record {
294294
rng: &mut R,
295295
) -> Self::EncryptedType
296296
where
297-
R: RngCore + CryptoRng,
297+
R: Rng + CryptoRng,
298298
{
299299
EncryptedRecord {
300300
pseudonyms: self
@@ -389,7 +389,7 @@ impl Encrypted for EncryptedRecord {
389389
#[cfg(feature = "elgamal3")]
390390
fn rerandomize<R>(&self, rng: &mut R) -> Self
391391
where
392-
R: RngCore + CryptoRng,
392+
R: Rng + CryptoRng,
393393
{
394394
EncryptedRecord {
395395
pseudonyms: self.pseudonyms.iter().map(|p| p.rerandomize(rng)).collect(),
@@ -400,7 +400,7 @@ impl Encrypted for EncryptedRecord {
400400
#[cfg(not(feature = "elgamal3"))]
401401
fn rerandomize<R>(&self, keys: &SessionKeys, rng: &mut R) -> Self
402402
where
403-
R: RngCore + CryptoRng,
403+
R: Rng + CryptoRng,
404404
{
405405
EncryptedRecord {
406406
pseudonyms: self
@@ -493,7 +493,7 @@ impl Encryptable for LongRecord {
493493

494494
fn encrypt<R>(&self, keys: &Self::PublicKeyType, rng: &mut R) -> Self::EncryptedType
495495
where
496-
R: RngCore + CryptoRng,
496+
R: Rng + CryptoRng,
497497
{
498498
LongEncryptedRecord {
499499
pseudonyms: self
@@ -516,7 +516,7 @@ impl Encryptable for LongRecord {
516516
rng: &mut R,
517517
) -> Self::EncryptedType
518518
where
519-
R: RngCore + CryptoRng,
519+
R: Rng + CryptoRng,
520520
{
521521
LongEncryptedRecord {
522522
pseudonyms: self
@@ -613,7 +613,7 @@ impl Encrypted for LongEncryptedRecord {
613613
#[cfg(feature = "elgamal3")]
614614
fn rerandomize<R>(&self, rng: &mut R) -> Self
615615
where
616-
R: RngCore + CryptoRng,
616+
R: Rng + CryptoRng,
617617
{
618618
LongEncryptedRecord {
619619
pseudonyms: self.pseudonyms.iter().map(|p| p.rerandomize(rng)).collect(),
@@ -624,7 +624,7 @@ impl Encrypted for LongEncryptedRecord {
624624
#[cfg(not(feature = "elgamal3"))]
625625
fn rerandomize<R>(&self, keys: &SessionKeys, rng: &mut R) -> Self
626626
where
627-
R: RngCore + CryptoRng,
627+
R: Rng + CryptoRng,
628628
{
629629
LongEncryptedRecord {
630630
pseudonyms: self

0 commit comments

Comments
 (0)