Giter VIP home page Giter VIP logo

Comments (6)

tarcieri avatar tarcieri commented on August 22, 2024 1

If you'd still like to support the rscrypt format with the latest versions of the scrypt crate, the code to parse an rscrypt hash and upgrade it to a PHC PasswordHash can be found here:

https://github.com/RustCrypto/password-hashes/pull/219/files#diff-4bb467a45e82efda8dac9b3295416e0af3ce143c8b0f69e223a134235f89160dL61-L108

    fn upgrade_mcf_hash<'a>(&self, hash: &'a str) -> Result<PasswordHash<'a>> {
        let mut parts = hash.split('$');

        let buf = [
            parts.next(),
            parts.next(),
            parts.next(),
            parts.next(),
            parts.next(),
            parts.next(),
            parts.next(),
            parts.next(),
        ];

        let (log_n, r, p, salt, hash) = match buf {
            [Some(""), Some("rscrypt"), Some("0"), Some(p), Some(s), Some(h), Some(""), None] => {
                let pvec = Base64::decode_vec(p)?;
                if pvec.len() != 3 {
                    return Err(InvalidValue::Malformed.param_error());
                }
                (pvec[0], pvec[1] as u32, pvec[2] as u32, s, h)
            }
            [Some(""), Some("rscrypt"), Some("1"), Some(p), Some(s), Some(h), Some(""), None] => {
                let pvec = Base64::decode_vec(p)?;
                if pvec.len() != 9 {
                    return Err(InvalidValue::Malformed.param_error());
                }
                let log_n = pvec[0];
                let r = u32::from_le_bytes(pvec[1..5].try_into().unwrap());
                let p = u32::from_le_bytes(pvec[5..9].try_into().unwrap());
                (log_n, r, p, s, h)
            }
            _ => return Err(InvalidValue::Malformed.param_error()),
        };

        let params = Params::new(log_n, r, p).map_err(|_| InvalidValue::Malformed.param_error())?;

        let salt = Salt::new(b64_strip(salt))?;
        let hash = Output::b64_decode(b64_strip(hash))?;

        Ok(PasswordHash {
            algorithm: ALG_ID,
            version: None,
            params: params.try_into()?,
            salt: Some(salt),
            hash: Some(hash),
        })
    }

from password-hashes.

tarcieri avatar tarcieri commented on August 22, 2024

You'll need to use the McfHasher::upgrade_mcf_hash impl on Scrypt to upgrade them to PHC hashes:

https://docs.rs/scrypt/0.7.0/scrypt/struct.Scrypt.html#method.upgrade_mcf_hash

Note that "rscrypt" is a nonstandard format which was supported only by the scrypt crate.

from password-hashes.

ashaduri avatar ashaduri commented on August 22, 2024

Would it make sense to check if the hash starts with $rscrypt$, and upgrade it using upgrade_mcf_hash() only if it does?

from password-hashes.

tarcieri avatar tarcieri commented on August 22, 2024

Edit: sorry, I think I misunderstood your question.

Would it make sense to check if the hash starts with $rscrypt$, and upgrade it using upgrade_mcf_hash() only if it does?

Yes, that's a perfectly valid way to do an upgrade. You can even do that eagerly across all of your password hashes, as it's a lossless transformation which doesn't require a password.

from password-hashes.

ashaduri avatar ashaduri commented on August 22, 2024

Thanks, this makes sense. I will close the issue.
Unfortunately, I have customers with their own databases containing rscrypt hashes, and forcing them to upgrade may be problematic. So, supporting rscrypt hashes for quite some time is very important to me.

from password-hashes.

ashaduri avatar ashaduri commented on August 22, 2024

Thanks, much appreciated!

from password-hashes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.