Skip to content

Conversation

@robert-scheck
Copy link

Switch from Digest::SHA1 to Digest::SHA, because: Digest::SHA is a bit faster than Digest::SHA1, Digest::SHA1 has been removed from some Linux distributions, Digest::SHA is a core library (as of Perl >= 5.10.0) and Digest::SHA1 is not (and never will be). See also:

Original author: Warren Togami ([email protected])

@mss
Copy link
Contributor

mss commented Jun 19, 2022

A slightly simpler patch is used in Debian as well: https://salsa.debian.org/debian/razor/-/blob/debian/1%252.85-7/debian/patches/use-Digest-SHA.patch

@robert-scheck
Copy link
Author

A slightly simpler patch is used in Debian as well: https://salsa.debian.org/debian/razor/-/blob/debian/1%252.85-7/debian/patches/use-Digest-SHA.patch

Yes, however the Debian patch does not provide any backwards compatibility, which may or may not be desired by upstream.

@mss
Copy link
Contributor

mss commented Jun 19, 2022

A slightly simpler patch is used in Debian as well: https://salsa.debian.org/debian/razor/-/blob/debian/1%252.85-7/debian/patches/use-Digest-SHA.patch

Yes, however the Debian patch does not provide any backwards compatibility, which may or may not be desired by upstream.

Indeed, I just ran into this while hacking on #13 and wanted to add this data point that most people probably use this change in some way already.

@michal-josef-spacek
Copy link

@robert-scheck Updated commit, rebased: michal-josef-spacek@d84debb

Switch from Digest::SHA1 to Digest::SHA, because: Digest::SHA is a bit
faster than Digest::SHA1, Digest::SHA1 has been removed from some Linux
distributions, Digest::SHA is a core library (as of Perl >= 5.10.0) and
Digest::SHA1 is not (and never will be). See also:

 - https://src.fedoraproject.org/rpms/perl-Razor-Agent/c/75fa8a6c1f1fdf779312dac68f331a288bd2920f?branch=rawhide
 - https://stackoverflow.com/questions/3420720/what-are-the-advantages-of-digestsha-over-digestsha1

Original author: Warren Togami <[email protected]>

Co-authored-by: Warren Togami <[email protected]>
@michal-josef-spacek
Copy link

@toddr Could we merge this?

@robert-scheck
Copy link
Author

@toddr, what's missing to get this merged? Happy to perform changes, if you let me know what needs to be changed…

@toddr
Copy link
Owner

toddr commented Nov 30, 2024

I took a brief look at it this weekend. My major concern is that if you are trying to get it to load and then fall back to the older module, I don't think it is going to do that right now.

Is that your goal? Or are you just trying to use the new module?

@robert-scheck
Copy link
Author

Is that your goal? Or are you just trying to use the new module?

Goal is to use the new module and fall back to the older one if it fails. But I don't know if that's what you would like to see anyway.

$sha1->add($corrected_length);
$sig .= substr $sha1->hexdigest, 0, 4;
$sig = substr sha1_hex($host), 0, 12;
$sig .= substr sha1_hex($corrected_length), 0, 4;
Copy link
Contributor

@mss mss Dec 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be missing something about the inner workings of SHA1 but to me it looks like this code behaves differently to the old one:

The old code created a SHA1 object, added the $host, took the first 12 characters of the digest as generated up to that point, added $corrected_length and then took the first four characters of the digest calculated at this new point in time.

The new code calculates two different digests, one over $host and one over $corrected_length, the latter does not include state from the previous digest.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally forgot to update this: In the meantime I verified that both code paths calculate the same hash.

$ctx->add($digest);
$digest = $ctx->hexdigest;
my $digest = sha1_hex($iv2, $text);
$digest = sha1_hex($iv1, $digest);
Copy link
Contributor

@mss mss Dec 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this is a bit confusing due to the reuse of $digest. I'd either use $digest1 and $digest2 or just make that a sha1_hex($iv1, sha1_hex($iv2, $text))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants