I recently made a similar implementation for SHA256. Unfortunately it suffers from gradient vanishing. Source code: <a href="https://github.com/calebh/differentiablesha256" rel="nofollow">https://github.com/calebh/differentiablesha256</a>