Is calculating HMAC from hashed input a good idea? The original HMAC algorithm is as follows:


  H(K XOR opad || H(K XOR ipad || text))


What if text would replaced with H(text)? Will it weaken the HMAC algorithm?
What if text would replaced with H(text)? Will it weaken the HMAC algorithm?


Yes. It makes collision attacks on the hash function apply to the MAC, which isn't normally the case with HMAC. You can find a pair $(m, m')$ that hash to the same value, get the MAC for one of them and move it to the other.

That means that your modified HMAC construction would be insecure with a hash function $H$ that isn't collision resistant, such as MD5. Even though normal HMAC-MD5 is still believed to be secure. In fact, any hash function with a small enough output size to lack collision resistance would be insecure to use in this modified HMAC.

If you use a collision resistant hash function, such as one of the SHA-2 hash functions (notably SHA-256 and SHA-512) or SHA-3 then the modified HMAC should still be secure.