RustCrypto / password-hashes

Password hashing functions / KDFs
652 stars 80 forks source link

Will Base64ShaCrypt ever be supported ? #466

Closed SteelAlloy closed 1 year ago

SteelAlloy commented 1 year ago

Hi there,

After debugging my code for a few hours, I discovered that SHA and bcrypt encoding are quite close but not similar. https://github.com/RustCrypto/traits/issues/507 confirmed what I thought.

Currently the only supported encoding are :

pub enum Encoding {
    /// "B64" encoding: standard Base64 without padding.
    ///
    /// ```text
    /// [A-Z]      [a-z]      [0-9]      +     /
    /// 0x41-0x5a, 0x61-0x7a, 0x30-0x39, 0x2b, 0x2f
    /// ```
    /// <https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md#b64>
    B64,

    /// bcrypt encoding.
    ///
    /// ```text
    /// ./         [A-Z]      [a-z]     [0-9]
    /// 0x2e-0x2f, 0x41-0x5a, 0x61-0x7a, 0x30-0x39
    /// ```
    Bcrypt,

    /// `crypt(3)` encoding.
    ///
    /// ```text
    /// [.-9]      [A-Z]      [a-z]
    /// 0x2e-0x39, 0x41-0x5a, 0x61-0x7a
    /// ```
    Crypt,
}

But from what I saw in the source code it wouldn't be hard to add the Base64ShaCrypt variant :

    pub fn decode(self, src: impl AsRef<[u8]>, dst: &mut [u8]) -> Result<&[u8], B64Error> {
        match self {
            Self::B64 => B64::decode(src, dst),
            Self::Bcrypt => Base64Bcrypt::decode(src, dst),
            Self::Crypt => Base64Crypt::decode(src, dst),
            // <-- here
        }
    }

Is there a reason why Base64ShaCrypt isn't there, or is it just a matter of someone doing a PR?

SteelAlloy commented 1 year ago

I've just noticed that base64ct is in version 1.1.1 on this repository (the latest being 1.6.0).

Will work on a PR (https://github.com/RustCrypto/traits/pull/1352)