Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds RSA key encryption and signature scheme #38

Merged
merged 30 commits into from
Nov 13, 2024
Merged

Adds RSA key encryption and signature scheme #38

merged 30 commits into from
Nov 13, 2024

Conversation

HLRichardson-Git
Copy link
Owner

Description of the Change

Adds the Rivest–Shamir–Adleman (RSA) key encryption and signing schemes from FIPS 186-5 and padding schemes from RFC 8017

These can all be uses by a user by including #include <gestalt/rsa.h>, here is an example of using RSA to sign a message with the PSS padding scheme:

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

int main() {
    RSA rsa({RSASecurityStrength::RSA_2048, RandomPrimeMethod::probable});
    PSSParams parameters = {HashAlgorithm::SHA1, RSA_MGFFunctions::MGF1};

    std::string messageToSign = "Hello, Gestalt!";
    std::string computedSignature = rsa.signMessage(messageToSign, parameters);

    std::cout << "Signature: " << computedSignature << std::endl;

    RSAPublicKey peerPublicKey = publicKey; // For the sake of example
    bool isValidSignature= rsa.verifySignature(messageToSign,  computedSignature, peerPublicKey, parameters);

    if (isValidSignature) std::cout << "Signature is valid!" << std::endl;

    return 0;
}

Updates the following documentation:

  • README
  • CHANGES

Future Additions

  • Certificates are not considered for this PR, it would be best if we add functionality for users to import/ export RSA keys to and from Gestalt.
  • PKCS#1v1.5 padding scheme for encryption and signing is not currently provided despite being the simplest of the three main padding schemes. It has a tricky leading zero which is proving challenging to use with out multi-precision library (GMP) which strips leading zeros.
  • Optimizations. Generally the implementation of RSA is slow compared to ECDSA (which I know should be the case) but I want to lessen the difference in performance.

Verification Process

There are a lot new unit tests to test all current features of the RSA in Gestalt which can be found in tests/rsa/.

Release Notes

  • Adds RSA Key Generation with provable or probable primes with key sizes of 1024 to 15360.
  • Adds RSA key encryption with Raw or OAEP padding schemes.
  • Adds RSA message Signing Scheme with Raw or PSS padding schemes.
  • Refactors the BigInt class outside of ECC to its own file in tools/bigint/bigint.h to be used anywhere.
  • Refactors the hash utilities in ECC to its own file in tools/hash_utils/hash_utils.h to be used anywhere.

@HLRichardson-Git HLRichardson-Git linked an issue Nov 13, 2024 that may be closed by this pull request
6 tasks
@HLRichardson-Git HLRichardson-Git merged commit 031c6ca into main Nov 13, 2024
1 check passed
@HLRichardson-Git HLRichardson-Git added this to the Gestalt 0.7 milestone Nov 13, 2024
@HLRichardson-Git HLRichardson-Git added the enhancement New feature or request label Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add RSA encryption and signing algorithms
1 participant