rsa.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef __RSA_H__
  2. #define __RSA_H__
  3. #include <stdint.h>
  4. //C++ guard
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. // This is the header file for the library librsaencrypt.a
  9. // Change this line to the file you'd like to use as a source of primes.
  10. // The format of the file should be one prime per line.
  11. char *PRIME_SOURCE_FILE = "primes.txt";
  12. struct public_key_class{
  13. long long modulus;
  14. long long exponent;
  15. };
  16. struct private_key_class{
  17. long long modulus;
  18. long long exponent;
  19. };
  20. // This function generates public and private keys, then stores them in the structures you
  21. // provide pointers to. The 3rd argument should be the text PRIME_SOURCE_FILE to have it use
  22. // the location specified above in this header.
  23. void rsa_gen_keys(struct public_key_class *pub, struct private_key_class *priv);
  24. // This function will encrypt the data pointed to by message. It returns a pointer to a heap
  25. // array containing the encrypted data, or NULL upon failure. This pointer should be freed when
  26. // you are finished. The encrypted data will be 8 times as large as the original data.
  27. unsigned char *rsa_encrypt(const unsigned char *message, const unsigned long message_size, const struct public_key_class *pub);
  28. // This function will decrypt the data pointed to by message. It returns a pointer to a heap
  29. // array containing the decrypted data, or NULL upon failure. This pointer should be freed when
  30. // you are finished. The variable message_size is the size in bytes of the encrypted message.
  31. // The decrypted data will be 1/8th the size of the encrypted data.
  32. unsigned char *rsa_decrypt(const long long *message, const unsigned long message_size, const struct private_key_class *pub);
  33. //C++ guard
  34. #ifdef __cplusplus
  35. }
  36. #endif
  37. #endif