HLRichardson-Git / Gestalt

A user-friendly cryptography library
https://gestaltcrypto.github.io
MIT License
2 stars 1 forks source link

Adds SHA2, HMAC-SHA1 and HMAC-SHA2. Adds more documentation. #23

Closed HLRichardson-Git closed 2 months ago

HLRichardson-Git commented 2 months ago

Description of the Change

Adds the secure hashing algorithms from FIPS 180-4"

These can all be uses by a user by including #include <gestalt/sha2.h>, here is an example of using SHA2-256:

#include <gestalt/sha2.h>
#include <iostream>

int main() {
    std::string message = "Hello, Gestalt!";
    std::string hash = hashSHA256(message);

    std::cout << "SHA2-256: " << hash << std::endl;

    return 0;
}

Adds the keyed secure hashing algorithms from FIPS 198-1"

These can all be uses by a user by including #include <gestalt/hmac_sha1.h> or #include <gestalt/hmac_sha2.h>, here is an example of using HMAC-SHA2-256:

#include <gestalt/hmac_sha2.h>
#include <iostream>

int main() {
    std::string key= "key";
    std::string message = "Hello, Gestalt!";
    std::string hash = hmacSHA256(key, message);

    std::cout << "HMAC-SHA2-256: " << hash << std::endl;

    return 0;
}

Updates the following documentation:

Adds the following documentation:

Alternate Designs

Many other SHA implementations use a init update and final structure to provide SHA algorithms to users. I did not so this, as my main goal was first to provide a user-friendly interface to SHA for the users. So that naturally led me to just making one function call, not making it necessary to implement SHA as it is in many other libraries. This can be implemented later to provide more flexibility to users and still maintain the separate simple function.

Verification Process

I wrote a new suite of test vectors in tests/sha2Tests.cpp and tests/hmacTests.cpp that test many cases of null inputs, inputs larger than the SHA block size, and inputs larger than the SHA block size. This provides confidence that the algorithms are correct, and if a code change is made in the future then the tests are already present.

Release Notes