Minor cleanup
Rewrite SHA-1 implementation

There wasn't any license on the old code, and although it was
well-documented it wasn't very efficient either. The new code is also
almost twice as fast.
Use memsize type to access index in string