RUSTSEC-2023-0068

See a problem?
Source
https://rustsec.org/advisories/RUSTSEC-2023-0068
Import Source
https://github.com/rustsec/advisory-db/blob/osv/crates/RUSTSEC-2023-0068.json
JSON Data
https://api.osv.dev/v1/vulns/RUSTSEC-2023-0068
Aliases
Published
2023-10-15T12:00:00Z
Modified
2024-10-08T04:11:51.783273Z
Severity
  • 4.5 (Medium) CVSS_V3 - CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:C/C:L/I:L/A:N CVSS Calculator
Summary
Sequential calls of encryption API (`encrypt`, `wrap`, and `dump`) result in nonce reuse
Details

Problem: Trying to create a new encrypted message with the same cocoon object generates the same ciphertext. It mostly affects MiniCocoon and Cocoon objects with custom seeds and RNGs (where StdRng is used under the hood).

Note: The issue does NOT affect objects created with Cocoon::new which utilizes ThreadRng.

Cause: StdRng produces the same nonce because StdRng::clone resets its state.

Measure: Make encryption API mutable (encrypt, wrap, and dump).

Workaround: Create a new cocoon object with a new seed per each encryption.

How to Reproduce

let cocoon = MiniCocoon::from_password(b"password", &[1; 32]);
let mut data1 = "my secret data".to_owned().into_bytes();
let _ = cocoon.encrypt(&mut data1)?;

let mut data2 = "my secret data".to_owned().into_bytes();
let _ = cocoon.encrypt(&mut data2)?;

// data1: [23, 217, 251, 151, 179, 62, 85, 15, 253, 92, 192, 112, 200, 52]
// data2: [23, 217, 251, 151, 179, 62, 85, 15, 253, 92, 192, 112, 200, 52]

Workaround

For cocoon <= 0.3.3, create a new cocoon with a different seed per each encrypt/wrap/dump call.

let cocoon = MiniCocoon::from_password(b"password", &[1; 32]);
let mut data1 = "my secret data".to_owned().into_bytes();
let _ = cocoon.encrypt(&mut data1)?;

// Another seed: &[2; 32].
let cocoon = MiniCocoon::from_password(b"password", &[2; 32]);
let mut data2 = "my secret data".to_owned().into_bytes();
let _ = cocoon.encrypt(&mut data2)?;

// data1: [23, 217, 251, 151, 179, 62, 85, 15, 253, 92, 192, 112, 200, 52]
// data2: [53, 223, 209, 96, 130, 99, 209, 108, 83, 189, 123, 81, 19, 1]
References

Affected packages

crates.io / cocoon

Package

Affected ranges

Type
SEMVER
Events
Introduced
0.0.0-0
Fixed
0.4.0

Ecosystem specific

{
    "affected_functions": null,
    "affects": {
        "os": [],
        "functions": [
            "cocoon::Cocoon::dump",
            "cocoon::Cocoon::encrypt",
            "cocoon::Cocoon::wrap",
            "cocoon::MiniCocoon::dump",
            "cocoon::MiniCocoon::encrypt",
            "cocoon::MiniCocoon::wrap"
        ],
        "arch": []
    }
}

Database specific

{
    "cvss": "CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:C/C:L/I:L/A:N",
    "informational": null,
    "categories": [
        "crypto-failure"
    ]
}