diff options
Diffstat (limited to 'nacl/crypto_sign/wrapper-sign-open.cpp')
-rw-r--r-- | nacl/crypto_sign/wrapper-sign-open.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/nacl/crypto_sign/wrapper-sign-open.cpp b/nacl/crypto_sign/wrapper-sign-open.cpp new file mode 100644 index 00000000..346e9400 --- /dev/null +++ b/nacl/crypto_sign/wrapper-sign-open.cpp | |||
@@ -0,0 +1,24 @@ | |||
1 | #include <string> | ||
2 | using std::string; | ||
3 | #include "crypto_sign.h" | ||
4 | |||
5 | string crypto_sign_open(const string &sm_string, const string &pk_string) | ||
6 | { | ||
7 | if (pk_string.size() != crypto_sign_PUBLICKEYBYTES) throw "incorrect public-key length"; | ||
8 | size_t smlen = sm_string.size(); | ||
9 | unsigned char m[smlen]; | ||
10 | unsigned long long mlen; | ||
11 | for (int i = 0;i < smlen;++i) m[i] = sm_string[i]; | ||
12 | if (crypto_sign_open( | ||
13 | m, | ||
14 | &mlen, | ||
15 | m, | ||
16 | smlen, | ||
17 | (const unsigned char *) pk_string.c_str() | ||
18 | ) != 0) | ||
19 | throw "ciphertext fails verification"; | ||
20 | return string( | ||
21 | (char *) m, | ||
22 | mlen | ||
23 | ); | ||
24 | } | ||