I have encountered a strange source code part in a soon-to-be-decommissioned legacy app, which uses an RSA-like scheme for "one-way hashing" data.
It works like this:
base^input mod N = hash
The input is numeric, actually a numeric form of a 128-bit UUID, usually around 120 bits.
Base and N are hardcoded values, sized around 1020 bits.
Base is a composite; it has a few smaller prime factors (under ~30 bits), but I could not factor it completely.
N is a composite number of two large primes. The factors for N (p, q) are not provided, but I was able to factor them. They are two large primes (around 510 bits each), but their difference was below 10000. (I used Fermat's factoring technique.)
There is no guarantee that the input is coprime with φ = (p-1)*(q-1).
It's obviously not suitable for hashing, but I got curious: How could I construct a valid input for a given hash?
Like an RSA, where I know nearly anything, and looking for a valid e/d pair for a given plaintext/ciphertext pair.
If I understand correctly, it's a DLP (Discrete Logarithm Problem) to find that value. I may make it somewhat easier if I try to solve the DLP for p and q respectively, but for ~500 bits, it's still a hard problem.
Is there any more suitable method to solve it? Does it matter if the input is coprime with φ at all?
Is there any situation where this usage of an "RSA like" algo as a "one-way hashing" is good for anything?
Extra info about p-1 and q-1:
(p-1) has a few small factors: 2, 3, 10709, but above that it has too large ones (may need more time to factor)
$base^{(p-1)/r} \ne 1 \bmod p$ for all factors (and for the remaining composite).
(q-1) has about 12 small factors (2, 7, 103,...), but I can't fully factor it (may need more time)
$base^{(q-1)/r} = 1 \bmod q$ for all known factors. So it's a safe prime.
Thanks, Bill