_detached versions of crypto_box
This commit is contained in:
parent
44f7a9f3cb
commit
c8dfd0d211
@ -4,9 +4,10 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
crypto_box_easy(unsigned char *c, const unsigned char *m,
|
crypto_box_easy_detached(unsigned char *c, unsigned char *mac,
|
||||||
unsigned long long mlen, const unsigned char *n,
|
const unsigned char *m, unsigned long long mlen,
|
||||||
const unsigned char *pk, const unsigned char *sk)
|
const unsigned char *n, const unsigned char *pk,
|
||||||
|
const unsigned char *sk)
|
||||||
{
|
{
|
||||||
unsigned char k[crypto_box_BEFORENMBYTES];
|
unsigned char k[crypto_box_BEFORENMBYTES];
|
||||||
int ret;
|
int ret;
|
||||||
@ -14,7 +15,32 @@ crypto_box_easy(unsigned char *c, const unsigned char *m,
|
|||||||
(void) sizeof(int[crypto_box_BEFORENMBYTES >=
|
(void) sizeof(int[crypto_box_BEFORENMBYTES >=
|
||||||
crypto_secretbox_KEYBYTES ? 1 : -1]);
|
crypto_secretbox_KEYBYTES ? 1 : -1]);
|
||||||
crypto_box_beforenm(k, pk, sk);
|
crypto_box_beforenm(k, pk, sk);
|
||||||
ret = crypto_secretbox_easy(c, m, mlen, n, k);
|
ret = crypto_secretbox_easy_detached(c, mac, m, mlen, n, k);
|
||||||
|
sodium_memzero(k, sizeof k);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
crypto_box_easy(unsigned char *c, const unsigned char *m,
|
||||||
|
unsigned long long mlen, const unsigned char *n,
|
||||||
|
const unsigned char *pk, const unsigned char *sk)
|
||||||
|
{
|
||||||
|
return crypto_box_easy_detached(c + crypto_box_MACBYTES, c, m, mlen, n,
|
||||||
|
pk, sk);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
crypto_box_open_easy_detached(unsigned char *m, const unsigned char *c,
|
||||||
|
const unsigned char *mac,
|
||||||
|
unsigned long long clen, const unsigned char *n,
|
||||||
|
const unsigned char *pk, const unsigned char *sk)
|
||||||
|
{
|
||||||
|
unsigned char k[crypto_box_BEFORENMBYTES];
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
crypto_box_beforenm(k, pk, sk);
|
||||||
|
ret = crypto_secretbox_open_easy_detached(m, c, mac, clen, n, k);
|
||||||
sodium_memzero(k, sizeof k);
|
sodium_memzero(k, sizeof k);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -25,12 +51,10 @@ crypto_box_open_easy(unsigned char *m, const unsigned char *c,
|
|||||||
unsigned long long clen, const unsigned char *n,
|
unsigned long long clen, const unsigned char *n,
|
||||||
const unsigned char *pk, const unsigned char *sk)
|
const unsigned char *pk, const unsigned char *sk)
|
||||||
{
|
{
|
||||||
unsigned char k[crypto_box_BEFORENMBYTES];
|
if (clen < crypto_box_MACBYTES) {
|
||||||
int ret;
|
return -1;
|
||||||
|
}
|
||||||
crypto_box_beforenm(k, pk, sk);
|
return crypto_box_open_easy_detached(m, c + crypto_box_MACBYTES, c,
|
||||||
ret = crypto_secretbox_open_easy(m, c, clen, n, k);
|
clen - crypto_box_MACBYTES,
|
||||||
sodium_memzero(k, sizeof k);
|
n, pk, sk);
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
@ -97,6 +97,19 @@ int crypto_box_open_easy(unsigned char *m, const unsigned char *c,
|
|||||||
unsigned long long clen, const unsigned char *n,
|
unsigned long long clen, const unsigned char *n,
|
||||||
const unsigned char *pk, const unsigned char *sk);
|
const unsigned char *pk, const unsigned char *sk);
|
||||||
|
|
||||||
|
SODIUM_EXPORT
|
||||||
|
int crypto_box_easy_detached(unsigned char *c, unsigned char *mac,
|
||||||
|
const unsigned char *m, unsigned long long mlen,
|
||||||
|
const unsigned char *n, const unsigned char *pk,
|
||||||
|
const unsigned char *sk);
|
||||||
|
|
||||||
|
SODIUM_EXPORT
|
||||||
|
int crypto_box_open_easy_detached(unsigned char *m, const unsigned char *c,
|
||||||
|
const unsigned char *mac,
|
||||||
|
unsigned long long clen,
|
||||||
|
const unsigned char *n,
|
||||||
|
const unsigned char *pk,
|
||||||
|
const unsigned char *sk);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user