• Main Page
  • Classes
  • Files
  • File List

Swiften/StringCodecs/SHA256.h

00001 /*
00002  * Copyright (c) 2010 Remko Tronçon
00003  * Licensed under the GNU General Public License v3.
00004  * See Documentation/Licenses/GPLv3.txt for more information.
00005  */
00006 
00007 #pragma once
00008 
00009 #include <vector>
00010 #include <boost/cstdint.hpp>
00011 
00012 #include <Swiften/Base/API.h>
00013 #include <Swiften/Base/ByteArray.h>
00014 #include <Swiften/Base/SafeByteArray.h>
00015 
00016 namespace Swift {
00017   class SWIFTEN_API SHA256 {
00018     public:
00019       SHA256();
00020 
00021       SHA256& update(const std::vector<unsigned char>& data);
00022       std::vector<unsigned char> getHash() const;
00023 
00029       static ByteArray getHash(const ByteArray& data);
00030       static ByteArray getHash(const SafeByteArray& data);
00031 
00032       ByteArray operator()(const SafeByteArray& data) {
00033         return getHash(data);
00034       }
00035 
00036       ByteArray operator()(const ByteArray& data) {
00037         return getHash(data);
00038       }
00039 
00040     private:
00041       struct State {
00042           boost::uint64_t length;
00043           boost::uint32_t state[8], curlen;
00044           unsigned char buf[64];
00045       };
00046 
00047       static int init(State *md);
00048       static int process(State * md, const unsigned char *in, unsigned int inlen);
00049       static int compress(State *md, unsigned char *buf);
00050       static int done(State * md, unsigned char *out);
00051 
00052       template<typename Container> static ByteArray getHashInternal(const Container& input);
00053 
00054     private:
00055       State state;
00056   };
00057 }

Generated on Fri Oct 12 2012 21:00:19 for Swiften by  doxygen 1.7.1