Properly close file descriptor
Use system sha1 library instead of local implementation.