/* sha1.cc - Functions to compute SHA1 message digest of data streams
* according to the NIST specification FIPS-180-1.
- * part of Cumulus: Smart Filesystem Backup to Dumb Servers
+ * part of Cumulus: Efficient Filesystem Backup to the Cloud
*
* Copyright (C) 2000, 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
* Copyright (C) 2006-2007 The Regents of the University of California
+ * Copyright (C) 2012 The Cumulus Developers
+ * See the AUTHORS file for a list of Cumulus contributors.
+ *
* Written by Scott G. Miller
* Additional Credits:
* Robert Klep <robert@ilse.nl> -- Expansion function fix
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "../hash.h"
#include "sha1.h"
#include <stddef.h>
return result;
}
+
+class SHA1Hash : public Hash {
+public:
+ SHA1Hash();
+ static Hash *New() { return new SHA1Hash; }
+ virtual void update(const void *data, size_t len);
+ virtual size_t digest_size() const { return 20; }
+ virtual std::string name() const { return "sha1"; }
+
+protected:
+ const uint8_t *finalize();
+
+private:
+ struct sha1_ctx ctx;
+ char resbuf[20] __attribute__ ((__aligned__ (__alignof__ (md5_uint32))));
+};
+
+SHA1Hash::SHA1Hash()
+{
+ sha1_init_ctx(&ctx);
+}
+
+void SHA1Hash::update(const void *data, size_t len)
+{
+ sha1_process_bytes(data, len, &ctx);
+}
+
+const uint8_t *SHA1Hash::finalize()
+{
+ sha1_finish_ctx(&ctx, resbuf);
+ return (const uint8_t *)resbuf;
+}
+
+void sha1_register()
+{
+ Hash::Register("sha1", SHA1Hash::New);
+}