Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ uniffi = "0.28"
chacha20poly1305 = { version = "0.10", features = ["std"] }
argon2 = "0.5"
ed25519-dalek = "3"
rand = "0.8"
getrandom = "0.4"
zeroize = { version = "1", features = ["derive"] }
2 changes: 1 addition & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ serde_json.workspace = true
base64.workspace = true
hex.workspace = true
ed25519-dalek.workspace = true
rand.workspace = true
getrandom.workspace = true
fs2 = "0.4"
notify = "6"

Expand Down
4 changes: 1 addition & 3 deletions client/src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ use note_protocol::{
CreateGroupResponse, CreateInviteRequest, CreateInviteResponse, DeviceListResponse,
EnrollRequest, EnrollResponse,
};
use rand::RngCore;
use rand::rngs::OsRng;

use crate::config::{PairingBlob, Settings, decode_blob, encode_blob, encode_key};
use crate::store::{LocalStore, resolve_id};

fn new_signing_key() -> ([u8; 32], SigningKey) {
let mut seed = [0u8; 32];
OsRng.fill_bytes(&mut seed);
getrandom::fill(&mut seed).expect("OS RNG unavailable");
let sk = SigningKey::from_bytes(&seed);
(seed, sk)
}
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ chacha20poly1305.workspace = true
sha2 = "0.10"
argon2.workspace = true
ed25519-dalek.workspace = true
rand.workspace = true
getrandom.workspace = true
zeroize.workspace = true
tokio.workspace = true
tokio-tungstenite.workspace = true
Expand Down
6 changes: 2 additions & 4 deletions core/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

use chacha20poly1305::aead::{Aead, Payload};
use chacha20poly1305::{KeyInit, XChaCha20Poly1305, XNonce};
use rand::RngCore;
use rand::rngs::OsRng;
use sha2::{Digest, Sha256};
use zeroize::{Zeroize, ZeroizeOnDrop};

Expand Down Expand Up @@ -82,7 +80,7 @@ impl GroupKey {
/// Generate a fresh random group key from the OS CSPRNG.
pub fn generate() -> Self {
let mut bytes = [0u8; KEY_LEN];
OsRng.fill_bytes(&mut bytes);
getrandom::fill(&mut bytes).expect("OS RNG unavailable");
Self(bytes)
}

Expand All @@ -104,7 +102,7 @@ impl GroupKey {
/// Seal `plaintext` into an envelope: `version || nonce || ciphertext`.
pub fn seal(key: &GroupKey, aad: Aad, plaintext: &[u8]) -> Vec<u8> {
let mut nonce = [0u8; NONCE_LEN];
OsRng.fill_bytes(&mut nonce);
getrandom::fill(&mut nonce).expect("OS RNG unavailable");

let aad_bytes = aad.to_bytes();
let ciphertext = key
Expand Down
6 changes: 2 additions & 4 deletions core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ use automerge::transaction::{CommitOptions, Transactable};
use automerge::{
AutoCommit, AutomergeError, Change, ChangeHash, ObjId, ObjType, ROOT, ReadDoc, Value,
};
use rand::RngCore;
use rand::rngs::OsRng;
use std::collections::{HashMap, HashSet};

/// Unix milliseconds. Supplied by the caller; the model never reads a clock.
Expand Down Expand Up @@ -88,7 +86,7 @@ pub struct NoteId(String);
impl NoteId {
pub fn generate() -> Self {
let mut bytes = [0u8; 16];
OsRng.fill_bytes(&mut bytes);
getrandom::fill(&mut bytes).expect("OS RNG unavailable");
let mut s = String::with_capacity(32);
for b in bytes {
s.push_str(&format!("{b:02x}"));
Expand All @@ -115,7 +113,7 @@ pub struct FolderId(String);
impl FolderId {
pub fn generate() -> Self {
let mut bytes = [0u8; 16];
OsRng.fill_bytes(&mut bytes);
getrandom::fill(&mut bytes).expect("OS RNG unavailable");
let mut s = String::with_capacity(32);
for b in bytes {
s.push_str(&format!("{b:02x}"));
Expand Down
4 changes: 1 addition & 3 deletions core/tests/e2e_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ use ed25519_dalek::SigningKey;
use note_core::{GroupKey, NoteStore, SyncConfig, sync_once};
use note_relay::state::AppState;
use note_relay::storage::{InMemoryStorage, Storage};
use rand::RngCore;
use rand::rngs::OsRng;

fn signing_key() -> SigningKey {
let mut seed = [0u8; 32];
OsRng.fill_bytes(&mut seed);
getrandom::fill(&mut seed).expect("OS RNG unavailable");
SigningKey::from_bytes(&seed)
}

Expand Down
2 changes: 1 addition & 1 deletion relay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ tracing-subscriber.workspace = true
ed25519-dalek.workspace = true
base64.workspace = true
hex.workspace = true
rand.workspace = true
getrandom.workspace = true
sha2 = "0.10"
rusqlite = { version = "0.32", features = ["bundled"] }

Expand Down
4 changes: 1 addition & 3 deletions relay/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
use std::collections::{HashMap, HashSet};
use std::sync::Mutex;

use rand::RngCore;
use rand::rngs::OsRng;
use rusqlite::{Connection, OptionalExtension, params};
use sha2::{Digest, Sha256};

Expand Down Expand Up @@ -84,7 +82,7 @@ pub trait Storage: Send + Sync {

fn random_hex(bytes: usize) -> String {
let mut buf = vec![0u8; bytes];
OsRng.fill_bytes(&mut buf);
getrandom::fill(&mut buf).expect("OS RNG unavailable");
hex::encode(buf)
}

Expand Down
4 changes: 1 addition & 3 deletions relay/src/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ use base64::engine::general_purpose::STANDARD as B64;
use ed25519_dalek::{Signature, Verifier, VerifyingKey};
use futures_util::{SinkExt, StreamExt};
use note_protocol::{ClientMsg, PROTOCOL_VERSION, ServerMsg};
use rand::RngCore;
use rand::rngs::OsRng;
use tokio::sync::broadcast::error::RecvError;

use crate::state::{AppState, Broadcast};
Expand Down Expand Up @@ -47,7 +45,7 @@ async fn run_session(mut socket: WebSocket, state: Arc<AppState>) -> anyhow::Res

// 2. Challenge
let mut challenge = [0u8; 32];
OsRng.fill_bytes(&mut challenge);
getrandom::fill(&mut challenge).expect("OS RNG unavailable");
send(
&mut socket,
ServerMsg::Challenge {
Expand Down
4 changes: 1 addition & 3 deletions relay/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ use note_protocol::{
use note_relay::build_app;
use note_relay::state::AppState;
use note_relay::storage::{InMemoryStorage, SqliteStorage, Storage};
use rand::RngCore;
use rand::rngs::OsRng;
use tokio::net::TcpStream;
use tokio_tungstenite::tungstenite::Message;
use tokio_tungstenite::{MaybeTlsStream, WebSocketStream, connect_async};
Expand All @@ -28,7 +26,7 @@ type Ws = WebSocketStream<MaybeTlsStream<TcpStream>>;

fn signing_key() -> SigningKey {
let mut seed = [0u8; 32];
OsRng.fill_bytes(&mut seed);
getrandom::fill(&mut seed).expect("OS RNG unavailable");
SigningKey::from_bytes(&seed)
}

Expand Down
Loading