Adds partially support to t:sha1 transformation

This commit is contained in:
Felipe Zimmerle
2015-10-23 10:53:54 -03:00
parent 91d29d2849
commit 743fb651da
3 changed files with 29 additions and 10 deletions

View File

@@ -65,7 +65,7 @@ void SHA1::update(std::istream *is) {
}
std::string SHA1::final() {
std::string SHA1::final_bin(bool toReset = true) {
/* Total number of hashed bits */
uint64_t total_bits = (transforms*BLOCK_BYTES + buffer.size()) * 8;
@@ -91,6 +91,22 @@ std::string SHA1::final() {
block[BLOCK_INTS - 2] = (total_bits >> 32);
transform(block);
if (toReset) {
/* Reset for next run */
reset();
}
std::string bin;
bin.append((const char*) digest, BLOCK_INTS);
return bin;
}
std::string SHA1::final() {
final_bin(false);
/* Hex std::string */
std::ostringstream result;
for (unsigned int i = 0; i < DIGEST_INTS; i++) {

View File

@@ -47,6 +47,10 @@ class SHA1 {
void update(std::string *s);
void update(std::istream *is);
std::string final();
std::string final_bin() {
return final_bin(true);
}
std::string final_bin(bool reset);
private:
/* number of 32bit integers per SHA1 digest */