summaryrefslogtreecommitdiff
path: root/include/sha.h
blob: 255c769f6216f37abe875c31c65519917b68937c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// This file is part of a crypto library, exam for the Algorithms class.
// All of these files are under MIT license.
//
// SHA declaration document:
// https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf

#ifndef HMACSHA256_SHA_H_
#define HMACSHA256_SHA_H_

#include<cstdint>
#include<array>

namespace hmacsha256 {
class SHA {
public:
    SHA() {
        digest_ = new uint8_t[32];
    }

    ~SHA() {
        delete digest_;
    }

    // get digest as array of bytes
    virtual uint8_t* digest() = 0;

    virtual std::string hexdigest() = 0;
protected:
    uint8_t* digest_;

    // work variables: a, b, c, d, e, f, g, h
    uint32_t vars_[8];

    // data message, in bytes
    // M,  "message to be hashed"
    uint8_t message_[64];

    // length L of the original message
    uint32_t message_l_;

    // lenght of bits
    uint64_t bit_len_;

    // the constructor
    virtual void init(const uint8_t* data, uint32_t length) = 0;

    // padding
    virtual void pad() = 0;

    // main function
    virtual void transform() = 0;
};


} // namespace hmacsha256

#endif // HMACSHA256_SHA_H_