wrapper-sign-open.cpp 605 B

123456789101112131415161718192021222324
  1. #include <string>
  2. using std::string;
  3. #include "crypto_sign.h"
  4. string crypto_sign_open(const string &sm_string, const string &pk_string)
  5. {
  6. if (pk_string.size() != crypto_sign_PUBLICKEYBYTES) throw "incorrect public-key length";
  7. size_t smlen = sm_string.size();
  8. unsigned char m[smlen];
  9. unsigned long long mlen;
  10. for (int i = 0;i < smlen;++i) m[i] = sm_string[i];
  11. if (crypto_sign_open(
  12. m,
  13. &mlen,
  14. m,
  15. smlen,
  16. (const unsigned char *) pk_string.c_str()
  17. ) != 0)
  18. throw "ciphertext fails verification";
  19. return string(
  20. (char *) m,
  21. mlen
  22. );
  23. }