2014-08-01 12:01:10 -05:00
|
|
|
/*
|
|
|
|
sha1.h - header of
|
2014-11-19 19:58:57 -06:00
|
|
|
|
2014-08-01 12:01:10 -05:00
|
|
|
============
|
|
|
|
SHA-1 in C++
|
|
|
|
============
|
2014-11-19 19:58:57 -06:00
|
|
|
|
2014-08-01 12:01:10 -05:00
|
|
|
100% Public Domain.
|
2014-11-19 19:58:57 -06:00
|
|
|
|
2014-08-01 12:01:10 -05:00
|
|
|
Original C Code
|
|
|
|
-- Steve Reid <steve@edmweb.com>
|
|
|
|
Small changes to fit into bglibs
|
|
|
|
-- Bruce Guenter <bruce@untroubled.org>
|
|
|
|
Translation to simpler C++ Code
|
|
|
|
-- Volker Grabsch <vog@notjusthosting.com>
|
2014-11-19 19:58:57 -06:00
|
|
|
Fixing bugs and improving style
|
|
|
|
-- Eugene Hopkinson <slowriot at voxelstorm dot com>
|
2014-08-01 12:01:10 -05:00
|
|
|
*/
|
2014-11-19 19:58:57 -06:00
|
|
|
|
2014-08-01 12:01:10 -05:00
|
|
|
#ifndef SHA1_HPP
|
|
|
|
#define SHA1_HPP
|
2014-11-19 19:58:57 -06:00
|
|
|
|
|
|
|
|
2014-08-01 12:01:10 -05:00
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
2014-12-11 08:27:38 -06:00
|
|
|
#include <stdint.h>
|
2014-11-19 19:58:57 -06:00
|
|
|
|
2014-08-01 12:01:10 -05:00
|
|
|
class SHA1
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SHA1();
|
|
|
|
void update(const std::string &s);
|
|
|
|
void update(std::istream &is);
|
|
|
|
std::string final();
|
|
|
|
static std::string from_file(const std::string &filename);
|
2014-11-19 19:58:57 -06:00
|
|
|
|
2014-08-01 12:01:10 -05:00
|
|
|
private:
|
2020-04-14 16:19:38 -05:00
|
|
|
static constexpr unsigned int DIGEST_INTS = 5; /* number of 32bit integers per SHA1 digest */
|
|
|
|
static constexpr unsigned int BLOCK_INTS = 16; /* number of 32bit integers per SHA1 block */
|
|
|
|
static constexpr unsigned int BLOCK_BYTES = BLOCK_INTS * 4;
|
2014-11-19 19:58:57 -06:00
|
|
|
|
2014-11-19 20:03:08 -06:00
|
|
|
uint32_t digest[DIGEST_INTS];
|
2014-08-01 12:01:10 -05:00
|
|
|
std::string buffer;
|
2014-11-19 20:03:08 -06:00
|
|
|
uint64_t transforms;
|
2014-11-19 19:58:57 -06:00
|
|
|
|
2014-08-01 12:01:10 -05:00
|
|
|
void reset();
|
2014-11-19 20:03:08 -06:00
|
|
|
void transform(uint32_t block[BLOCK_BYTES]);
|
2014-11-19 19:58:57 -06:00
|
|
|
|
|
|
|
static void read(std::istream &is, std::string &s, size_t max);
|
2014-11-19 20:03:08 -06:00
|
|
|
static void buffer_to_block(const std::string &buffer, uint32_t block[BLOCK_INTS]);
|
2014-08-01 12:01:10 -05:00
|
|
|
};
|
2014-11-19 19:58:57 -06:00
|
|
|
|
2014-08-01 12:01:10 -05:00
|
|
|
std::string sha1(const std::string &string);
|
2014-11-19 19:58:57 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-01 12:01:10 -05:00
|
|
|
#endif /* SHA1_HPP */
|