X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=third_party%2Fsha1.cc;h=9e9e74bff6c4a25ca724b32f6b3efc9bd5501ca3;hb=86852c7d1d491d73ae9ecc64ee5a8c3dcece4ca0;hp=7111f94ab40ad67fcb7745f90def6861728f0efe;hpb=35dd99aa3d47805b661fe3126a951710fa7dee11;p=cumulus.git diff --git a/third_party/sha1.cc b/third_party/sha1.cc index 7111f94..9e9e74b 100644 --- a/third_party/sha1.cc +++ b/third_party/sha1.cc @@ -1,9 +1,12 @@ /* 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 -- Expansion function fix @@ -27,6 +30,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "../hash.h" #include "sha1.h" #include @@ -392,3 +396,40 @@ string SHA1Checksum::checksum_str() 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); +}