SHA256Ident.c 944 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*====================================================================*
  2. *
  3. * void SHA256Ident (signed fd, uint8_t digest []);
  4. *
  5. * SHA256.h
  6. *
  7. * compute the SHA256 digest of file content; the digest becomes
  8. * the fingerprint that can be used to identify the file despite
  9. * filename changes;
  10. *
  11. * Motley Tools by Charles Maier;
  12. * Copyright (c) 2001-2006 by Charles Maier Associates;
  13. * Licensed under the Internet Software Consortium License;
  14. *
  15. *--------------------------------------------------------------------*/
  16. #ifndef SHA256IDENT_SOURCE
  17. #define SHA256IDENT_SOURCE
  18. #include <unistd.h>
  19. #include "../key/SHA256.h"
  20. void SHA256Ident (signed fd, uint8_t digest [])
  21. {
  22. struct sha256 sha256;
  23. uint8_t buffer [1024];
  24. signed length;
  25. SHA256Reset (&sha256);
  26. while ((length = read (fd, buffer, sizeof (buffer))) > 0)
  27. {
  28. SHA256Write (&sha256, buffer, length);
  29. }
  30. SHA256Fetch (&sha256, digest);
  31. return;
  32. }
  33. #endif