united-states
Trademarks shouldn't be a problem, so long as they don't induce anyone to think you're affiliated with the trademark (which seems rather unlikely if you're merely embedding a hash of an encoded version of a name into source code; it would take significant effort for a user to even detect that.)
I don't think using the hash would itself violate copyright. A hash cannot really be called a work of authorship, and thus is not really a derivative work (just like the word count of a book is not a "derivative work" even though it's derived from the work.) The hash would presumably not be reversible, and thus it could not be used to generate an infringing copy.
But there's a problem with this step:
If I were to reproduce a large amount of text (e.g. from a book)
To generate the hash in the first place, you're making a copy of a large amount of the work! This itself is infringing unless you have an exception. I'm not sure whether you could claim fair use here. Your use won't affect the market for the original, which is in your favor, but another prong is whether the amount you copied was necessary... and it seems to me that the entire use is unnecessary.