5 #include "crypto_secretbox.h"
6 #include "randombytes.h"
11 for (mlen
= 0;mlen
< 1000;++mlen
) {
12 unsigned char kbytes
[crypto_secretbox_KEYBYTES
];
13 randombytes(kbytes
,crypto_secretbox_KEYBYTES
);
14 string
k((char *) kbytes
,crypto_secretbox_KEYBYTES
);
15 unsigned char nbytes
[crypto_secretbox_NONCEBYTES
];
16 randombytes(nbytes
,crypto_secretbox_NONCEBYTES
);
17 string
n((char *) nbytes
,crypto_secretbox_NONCEBYTES
);
18 unsigned char mbytes
[mlen
];
19 randombytes(mbytes
,mlen
);
20 string
m((char *) mbytes
,mlen
);
21 string c
= crypto_secretbox(m
,n
,k
);
24 c
.replace(random() % c
.size(),1,1,random());
26 string m2
= crypto_secretbox_open(c
,n
,k
);
31 } catch(const char *s
) {
32 if (string(s
) == string("ciphertext fails verification"))