blob: 366e2e30f445e2b7b6824393c746142909d39a2e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#include <string>
using std::string;
#include <stdio.h>
#include "crypto_box.h"
#include "randombytes.h"
main()
{
int mlen;
for (mlen = 0;mlen < 1000;++mlen) {
string alicesk;
string alicepk = crypto_box_keypair(&alicesk);
string bobsk;
string bobpk = crypto_box_keypair(&bobsk);
unsigned char nbytes[crypto_box_NONCEBYTES];
randombytes(nbytes,crypto_box_NONCEBYTES);
string n((char *) nbytes,crypto_box_NONCEBYTES);
unsigned char mbytes[mlen];
randombytes(mbytes,mlen);
string m((char *) mbytes,mlen);
string c = crypto_box(m,n,bobpk,alicesk);
try {
string m2 = crypto_box_open(c,n,alicepk,bobsk);
if (m != m2) printf("bad decryption\n");
} catch(const char *s) {
printf("%s\n",s);
}
}
return 0;
}
|