3 #include "crypto_box.h"
5 string
crypto_box(const string
&m
,const string
&n
,const string
&pk
,const string
&sk
)
7 if (pk
.size() != crypto_box_PUBLICKEYBYTES
) throw "incorrect public-key length";
8 if (sk
.size() != crypto_box_SECRETKEYBYTES
) throw "incorrect secret-key length";
9 if (n
.size() != crypto_box_NONCEBYTES
) throw "incorrect nonce length";
10 size_t mlen
= m
.size() + crypto_box_ZEROBYTES
;
11 unsigned char mpad
[mlen
];
12 for (int i
= 0;i
< crypto_box_ZEROBYTES
;++i
) mpad
[i
] = 0;
13 for (int i
= crypto_box_ZEROBYTES
;i
< mlen
;++i
) mpad
[i
] = m
[i
- crypto_box_ZEROBYTES
];
14 unsigned char cpad
[mlen
];
15 crypto_box(cpad
,mpad
,mlen
,
16 (const unsigned char *) n
.c_str(),
17 (const unsigned char *) pk
.c_str(),
18 (const unsigned char *) sk
.c_str()
21 (char *) cpad
+ crypto_box_BOXZEROBYTES
,
22 mlen
- crypto_box_BOXZEROBYTES