1 #include "crypto_onetimeauth_poly1305.h"
2 #include "crypto_stream_xsalsa20.h"
3 #include "crypto_secretbox.h"
7 const unsigned char *m
,unsigned long long mlen
,
8 const unsigned char *n
,
13 if (mlen
< 32) return -1;
14 crypto_stream_xsalsa20_xor(c
,m
,mlen
,n
,k
);
15 crypto_onetimeauth_poly1305(c
+ 16,c
+ 32,mlen
- 32,c
);
16 for (i
= 0;i
< 16;++i
) c
[i
] = 0;
20 int crypto_secretbox_open(
22 const unsigned char *c
,unsigned long long clen
,
23 const unsigned char *n
,
24 const unsigned char *k
28 unsigned char subkey
[32];
29 if (clen
< 32) return -1;
30 crypto_stream_xsalsa20(subkey
,32,n
,k
);
31 if (crypto_onetimeauth_poly1305_verify(c
+ 16,c
+ 32,clen
- 32,subkey
) != 0) return -1;
32 crypto_stream_xsalsa20_xor(m
,c
,clen
,n
,k
);
33 for (i
= 0;i
< 32;++i
) m
[i
] = 0;