Skip to content

Commit

Permalink
chore: replace const-random dependency by obfstr
Browse files Browse the repository at this point in the history
`obfstr` is both more featureful and faster to compile.
  • Loading branch information
AlexTMjugador committed Nov 24, 2024
1 parent 89b13e0 commit 33d7261
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:
env:
DEBIAN_FRONTEND: noninteractive

CONST_RANDOM_SEED: ${{ secrets.CONST_RANDOM_SEED }}
OBFSTR_SEED: ${{ secrets.CONST_RANDOM_SEED }}

# Disable quickinstall telemetry reporting to cut down on external HTTP requests
# a little. See: https://github.com/cargo-bins/cargo-binstall/issues/1884
Expand Down
28 changes: 7 additions & 21 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 packages/packsquash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ zopfli = { version = "0.8.1", default-features = false, features = [
"nightly",
] }

const-random = "0.1.18"
obfstr = "0.4.4"
aes = "0.8.4"
fpe = "0.6.1"
uuid = "1.11.0"
Expand Down
5 changes: 2 additions & 3 deletions packages/packsquash/src/squash_zip/obfuscation_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use std::{
io,
iter::{self, Once}
};

use const_random::const_random;
use obfstr::random;
use rand_xoshiro::{
rand_core::{RngCore, SeedableRng},
Xoshiro128Plus
Expand All @@ -37,7 +36,7 @@ use super::{
mod pseudodir_concealment;

const CRC32_KEY: u32 = {
let k = const_random!(u32);
let k = random!(u32);

if k == 0 {
0xDEADBEEF
Expand Down
7 changes: 4 additions & 3 deletions packages/packsquash/src/squash_zip/system_time_sanitizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use aes::{
cipher::{BlockCipher, BlockEncrypt, KeyInit},
Aes128, Block
};
use const_random::const_random;

use fpe::ff1::{BinaryNumeralString, FF1};
use obfstr::random;
use thiserror::Error;

use super::system_id::get_or_compute_system_id;
Expand Down Expand Up @@ -48,14 +48,15 @@ pub(super) struct SystemTimeSanitizer<C: BlockCipher + BlockEncrypt + Clone> {

/// An application-wide salt that is used for time sanitization.
///
/// This salt may be deterministically generated via the `CONST_RANDOM_SEED`
/// This salt may be deterministically generated via the `OBFSTR_SEED`
/// environment variable on build time. A good way to generate a 512-bit
/// seed on a Linux system with GNU Coreutils is:
///
/// ```bash
/// $ dd if=/dev/urandom bs=1 count=64 2>/dev/null | base64 -w 0
/// ```
const TIME_SANITIZATION_SALT: [u8; 16] = const_random!(u128).to_le_bytes();
const TIME_SANITIZATION_SALT: [u8; 16] =
((random!(u64) as u128) << 64 | random!(u64) as u128).to_le_bytes();

/// A 32-bit unsigned integer with the MSB set.
const STICK_PARITY_BIT_MASK: u32 = 1 << 31;
Expand Down

0 comments on commit 33d7261

Please sign in to comment.