diff options
author | dartraiden <wowemuh@gmail.com> | 2023-09-14 22:53:45 +0300 |
---|---|---|
committer | dartraiden <wowemuh@gmail.com> | 2023-09-14 22:53:45 +0300 |
commit | c400f5c17af4996eb2ecf0597e17eb25c17857d8 (patch) | |
tree | c895207a210e5538c491ba9fc15ee0f28780a7f6 /libs/libsodium/src/crypto_box | |
parent | cd3146d46f9b9e24065b9ec31d963d52da3cdcbe (diff) |
libsodium: update to 1.0.19
Diffstat (limited to 'libs/libsodium/src/crypto_box')
6 files changed, 736 insertions, 736 deletions
diff --git a/libs/libsodium/src/crypto_box/crypto_box.c b/libs/libsodium/src/crypto_box/crypto_box.c index 7e4f00bd15..18a5c63ccc 100644 --- a/libs/libsodium/src/crypto_box/crypto_box.c +++ b/libs/libsodium/src/crypto_box/crypto_box.c @@ -1,114 +1,114 @@ - -#include "crypto_box.h" - -size_t -crypto_box_seedbytes(void) -{ - return crypto_box_SEEDBYTES; -} - -size_t -crypto_box_publickeybytes(void) -{ - return crypto_box_PUBLICKEYBYTES; -} - -size_t -crypto_box_secretkeybytes(void) -{ - return crypto_box_SECRETKEYBYTES; -} - -size_t -crypto_box_beforenmbytes(void) -{ - return crypto_box_BEFORENMBYTES; -} - -size_t -crypto_box_noncebytes(void) -{ - return crypto_box_NONCEBYTES; -} - -size_t -crypto_box_zerobytes(void) -{ - return crypto_box_ZEROBYTES; -} - -size_t -crypto_box_boxzerobytes(void) -{ - return crypto_box_BOXZEROBYTES; -} - -size_t -crypto_box_macbytes(void) -{ - return crypto_box_MACBYTES; -} - -size_t -crypto_box_messagebytes_max(void) -{ - return crypto_box_MESSAGEBYTES_MAX; -} - -const char * -crypto_box_primitive(void) -{ - return crypto_box_PRIMITIVE; -} - -int -crypto_box_seed_keypair(unsigned char *pk, unsigned char *sk, - const unsigned char *seed) -{ - return crypto_box_curve25519xsalsa20poly1305_seed_keypair(pk, sk, seed); -} - -int -crypto_box_keypair(unsigned char *pk, unsigned char *sk) -{ - return crypto_box_curve25519xsalsa20poly1305_keypair(pk, sk); -} - -int -crypto_box_beforenm(unsigned char *k, const unsigned char *pk, - const unsigned char *sk) -{ - return crypto_box_curve25519xsalsa20poly1305_beforenm(k, pk, sk); -} - -int -crypto_box_afternm(unsigned char *c, const unsigned char *m, - unsigned long long mlen, const unsigned char *n, - const unsigned char *k) -{ - return crypto_box_curve25519xsalsa20poly1305_afternm(c, m, mlen, n, k); -} - -int -crypto_box_open_afternm(unsigned char *m, const unsigned char *c, - unsigned long long clen, const unsigned char *n, - const unsigned char *k) -{ - return crypto_box_curve25519xsalsa20poly1305_open_afternm(m, c, clen, n, k); -} - -int -crypto_box(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_curve25519xsalsa20poly1305(c, m, mlen, n, pk, sk); -} - -int -crypto_box_open(unsigned char *m, const unsigned char *c, - unsigned long long clen, const unsigned char *n, - const unsigned char *pk, const unsigned char *sk) -{ - return crypto_box_curve25519xsalsa20poly1305_open(m, c, clen, n, pk, sk); -} +
+#include "crypto_box.h"
+
+size_t
+crypto_box_seedbytes(void)
+{
+ return crypto_box_SEEDBYTES;
+}
+
+size_t
+crypto_box_publickeybytes(void)
+{
+ return crypto_box_PUBLICKEYBYTES;
+}
+
+size_t
+crypto_box_secretkeybytes(void)
+{
+ return crypto_box_SECRETKEYBYTES;
+}
+
+size_t
+crypto_box_beforenmbytes(void)
+{
+ return crypto_box_BEFORENMBYTES;
+}
+
+size_t
+crypto_box_noncebytes(void)
+{
+ return crypto_box_NONCEBYTES;
+}
+
+size_t
+crypto_box_zerobytes(void)
+{
+ return crypto_box_ZEROBYTES;
+}
+
+size_t
+crypto_box_boxzerobytes(void)
+{
+ return crypto_box_BOXZEROBYTES;
+}
+
+size_t
+crypto_box_macbytes(void)
+{
+ return crypto_box_MACBYTES;
+}
+
+size_t
+crypto_box_messagebytes_max(void)
+{
+ return crypto_box_MESSAGEBYTES_MAX;
+}
+
+const char *
+crypto_box_primitive(void)
+{
+ return crypto_box_PRIMITIVE;
+}
+
+int
+crypto_box_seed_keypair(unsigned char *pk, unsigned char *sk,
+ const unsigned char *seed)
+{
+ return crypto_box_curve25519xsalsa20poly1305_seed_keypair(pk, sk, seed);
+}
+
+int
+crypto_box_keypair(unsigned char *pk, unsigned char *sk)
+{
+ return crypto_box_curve25519xsalsa20poly1305_keypair(pk, sk);
+}
+
+int
+crypto_box_beforenm(unsigned char *k, const unsigned char *pk,
+ const unsigned char *sk)
+{
+ return crypto_box_curve25519xsalsa20poly1305_beforenm(k, pk, sk);
+}
+
+int
+crypto_box_afternm(unsigned char *c, const unsigned char *m,
+ unsigned long long mlen, const unsigned char *n,
+ const unsigned char *k)
+{
+ return crypto_box_curve25519xsalsa20poly1305_afternm(c, m, mlen, n, k);
+}
+
+int
+crypto_box_open_afternm(unsigned char *m, const unsigned char *c,
+ unsigned long long clen, const unsigned char *n,
+ const unsigned char *k)
+{
+ return crypto_box_curve25519xsalsa20poly1305_open_afternm(m, c, clen, n, k);
+}
+
+int
+crypto_box(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_curve25519xsalsa20poly1305(c, m, mlen, n, pk, sk);
+}
+
+int
+crypto_box_open(unsigned char *m, const unsigned char *c,
+ unsigned long long clen, const unsigned char *n,
+ const unsigned char *pk, const unsigned char *sk)
+{
+ return crypto_box_curve25519xsalsa20poly1305_open(m, c, clen, n, pk, sk);
+}
diff --git a/libs/libsodium/src/crypto_box/crypto_box_easy.c b/libs/libsodium/src/crypto_box/crypto_box_easy.c index deb40b4083..74a3c6cebe 100644 --- a/libs/libsodium/src/crypto_box/crypto_box_easy.c +++ b/libs/libsodium/src/crypto_box/crypto_box_easy.c @@ -1,115 +1,115 @@ - -#include <limits.h> -#include <stdint.h> -#include <stdlib.h> - -#include "core.h" -#include "crypto_box.h" -#include "crypto_secretbox.h" -#include "private/common.h" -#include "utils.h" - -int -crypto_box_detached_afternm(unsigned char *c, unsigned char *mac, - const unsigned char *m, unsigned long long mlen, - const unsigned char *n, const unsigned char *k) -{ - return crypto_secretbox_detached(c, mac, m, mlen, n, k); -} - -int -crypto_box_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) -{ - unsigned char k[crypto_box_BEFORENMBYTES]; - int ret; - - COMPILER_ASSERT(crypto_box_BEFORENMBYTES >= crypto_secretbox_KEYBYTES); - if (crypto_box_beforenm(k, pk, sk) != 0) { - return -1; - } - ret = crypto_box_detached_afternm(c, mac, m, mlen, n, k); - sodium_memzero(k, sizeof k); - - return ret; -} - -int -crypto_box_easy_afternm(unsigned char *c, const unsigned char *m, - unsigned long long mlen, const unsigned char *n, - const unsigned char *k) -{ - if (mlen > crypto_box_MESSAGEBYTES_MAX) { - sodium_misuse(); - } - return crypto_box_detached_afternm(c + crypto_box_MACBYTES, c, m, mlen, n, - k); -} - -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) -{ - if (mlen > crypto_box_MESSAGEBYTES_MAX) { - sodium_misuse(); - } - return crypto_box_detached(c + crypto_box_MACBYTES, c, m, mlen, n, - pk, sk); -} - -int -crypto_box_open_detached_afternm(unsigned char *m, const unsigned char *c, - const unsigned char *mac, - unsigned long long clen, - const unsigned char *n, - const unsigned char *k) -{ - return crypto_secretbox_open_detached(m, c, mac, clen, n, k); -} - -int -crypto_box_open_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; - - if (crypto_box_beforenm(k, pk, sk) != 0) { - return -1; - } - ret = crypto_box_open_detached_afternm(m, c, mac, clen, n, k); - sodium_memzero(k, sizeof k); - - return ret; -} - -int -crypto_box_open_easy_afternm(unsigned char *m, const unsigned char *c, - unsigned long long clen, const unsigned char *n, - const unsigned char *k) -{ - if (clen < crypto_box_MACBYTES) { - return -1; - } - return crypto_box_open_detached_afternm(m, c + crypto_box_MACBYTES, c, - clen - crypto_box_MACBYTES, - n, k); -} - -int -crypto_box_open_easy(unsigned char *m, const unsigned char *c, - unsigned long long clen, const unsigned char *n, - const unsigned char *pk, const unsigned char *sk) -{ - if (clen < crypto_box_MACBYTES) { - return -1; - } - return crypto_box_open_detached(m, c + crypto_box_MACBYTES, c, - clen - crypto_box_MACBYTES, - n, pk, sk); -} +
+#include <limits.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include "core.h"
+#include "crypto_box.h"
+#include "crypto_secretbox.h"
+#include "private/common.h"
+#include "utils.h"
+
+int
+crypto_box_detached_afternm(unsigned char *c, unsigned char *mac,
+ const unsigned char *m, unsigned long long mlen,
+ const unsigned char *n, const unsigned char *k)
+{
+ return crypto_secretbox_detached(c, mac, m, mlen, n, k);
+}
+
+int
+crypto_box_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)
+{
+ unsigned char k[crypto_box_BEFORENMBYTES];
+ int ret;
+
+ COMPILER_ASSERT(crypto_box_BEFORENMBYTES >= crypto_secretbox_KEYBYTES);
+ if (crypto_box_beforenm(k, pk, sk) != 0) {
+ return -1;
+ }
+ ret = crypto_box_detached_afternm(c, mac, m, mlen, n, k);
+ sodium_memzero(k, sizeof k);
+
+ return ret;
+}
+
+int
+crypto_box_easy_afternm(unsigned char *c, const unsigned char *m,
+ unsigned long long mlen, const unsigned char *n,
+ const unsigned char *k)
+{
+ if (mlen > crypto_box_MESSAGEBYTES_MAX) {
+ sodium_misuse();
+ }
+ return crypto_box_detached_afternm(c + crypto_box_MACBYTES, c, m, mlen, n,
+ k);
+}
+
+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)
+{
+ if (mlen > crypto_box_MESSAGEBYTES_MAX) {
+ sodium_misuse();
+ }
+ return crypto_box_detached(c + crypto_box_MACBYTES, c, m, mlen, n,
+ pk, sk);
+}
+
+int
+crypto_box_open_detached_afternm(unsigned char *m, const unsigned char *c,
+ const unsigned char *mac,
+ unsigned long long clen,
+ const unsigned char *n,
+ const unsigned char *k)
+{
+ return crypto_secretbox_open_detached(m, c, mac, clen, n, k);
+}
+
+int
+crypto_box_open_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;
+
+ if (crypto_box_beforenm(k, pk, sk) != 0) {
+ return -1;
+ }
+ ret = crypto_box_open_detached_afternm(m, c, mac, clen, n, k);
+ sodium_memzero(k, sizeof k);
+
+ return ret;
+}
+
+int
+crypto_box_open_easy_afternm(unsigned char *m, const unsigned char *c,
+ unsigned long long clen, const unsigned char *n,
+ const unsigned char *k)
+{
+ if (clen < crypto_box_MACBYTES) {
+ return -1;
+ }
+ return crypto_box_open_detached_afternm(m, c + crypto_box_MACBYTES, c,
+ clen - crypto_box_MACBYTES,
+ n, k);
+}
+
+int
+crypto_box_open_easy(unsigned char *m, const unsigned char *c,
+ unsigned long long clen, const unsigned char *n,
+ const unsigned char *pk, const unsigned char *sk)
+{
+ if (clen < crypto_box_MACBYTES) {
+ return -1;
+ }
+ return crypto_box_open_detached(m, c + crypto_box_MACBYTES, c,
+ clen - crypto_box_MACBYTES,
+ n, pk, sk);
+}
diff --git a/libs/libsodium/src/crypto_box/crypto_box_seal.c b/libs/libsodium/src/crypto_box/crypto_box_seal.c index 7181334578..59c686c4cc 100644 --- a/libs/libsodium/src/crypto_box/crypto_box_seal.c +++ b/libs/libsodium/src/crypto_box/crypto_box_seal.c @@ -1,68 +1,68 @@ - -#include <string.h> - -#include "crypto_box.h" -#include "crypto_generichash.h" -#include "private/common.h" -#include "utils.h" - -static int -_crypto_box_seal_nonce(unsigned char *nonce, - const unsigned char *pk1, const unsigned char *pk2) -{ - crypto_generichash_state st; - - crypto_generichash_init(&st, NULL, 0U, crypto_box_NONCEBYTES); - crypto_generichash_update(&st, pk1, crypto_box_PUBLICKEYBYTES); - crypto_generichash_update(&st, pk2, crypto_box_PUBLICKEYBYTES); - crypto_generichash_final(&st, nonce, crypto_box_NONCEBYTES); - - return 0; -} - -int -crypto_box_seal(unsigned char *c, const unsigned char *m, - unsigned long long mlen, const unsigned char *pk) -{ - unsigned char nonce[crypto_box_NONCEBYTES]; - unsigned char epk[crypto_box_PUBLICKEYBYTES]; - unsigned char esk[crypto_box_SECRETKEYBYTES]; - int ret; - - if (crypto_box_keypair(epk, esk) != 0) { - return -1; /* LCOV_EXCL_LINE */ - } - memcpy(c, epk, crypto_box_PUBLICKEYBYTES); - _crypto_box_seal_nonce(nonce, epk, pk); - ret = crypto_box_easy(c + crypto_box_PUBLICKEYBYTES, m, mlen, - nonce, pk, esk); - sodium_memzero(esk, sizeof esk); - sodium_memzero(epk, sizeof epk); - sodium_memzero(nonce, sizeof nonce); - - return ret; -} - -int -crypto_box_seal_open(unsigned char *m, const unsigned char *c, - unsigned long long clen, - const unsigned char *pk, const unsigned char *sk) -{ - unsigned char nonce[crypto_box_NONCEBYTES]; - - if (clen < crypto_box_SEALBYTES) { - return -1; - } - _crypto_box_seal_nonce(nonce, c, pk); - - COMPILER_ASSERT(crypto_box_PUBLICKEYBYTES < crypto_box_SEALBYTES); - return crypto_box_open_easy(m, c + crypto_box_PUBLICKEYBYTES, - clen - crypto_box_PUBLICKEYBYTES, - nonce, c, sk); -} - -size_t -crypto_box_sealbytes(void) -{ - return crypto_box_SEALBYTES; -} +
+#include <string.h>
+
+#include "crypto_box.h"
+#include "crypto_generichash.h"
+#include "private/common.h"
+#include "utils.h"
+
+static int
+_crypto_box_seal_nonce(unsigned char *nonce,
+ const unsigned char *pk1, const unsigned char *pk2)
+{
+ crypto_generichash_state st;
+
+ crypto_generichash_init(&st, NULL, 0U, crypto_box_NONCEBYTES);
+ crypto_generichash_update(&st, pk1, crypto_box_PUBLICKEYBYTES);
+ crypto_generichash_update(&st, pk2, crypto_box_PUBLICKEYBYTES);
+ crypto_generichash_final(&st, nonce, crypto_box_NONCEBYTES);
+
+ return 0;
+}
+
+int
+crypto_box_seal(unsigned char *c, const unsigned char *m,
+ unsigned long long mlen, const unsigned char *pk)
+{
+ unsigned char nonce[crypto_box_NONCEBYTES];
+ unsigned char epk[crypto_box_PUBLICKEYBYTES];
+ unsigned char esk[crypto_box_SECRETKEYBYTES];
+ int ret;
+
+ if (crypto_box_keypair(epk, esk) != 0) {
+ return -1; /* LCOV_EXCL_LINE */
+ }
+ memcpy(c, epk, crypto_box_PUBLICKEYBYTES);
+ _crypto_box_seal_nonce(nonce, epk, pk);
+ ret = crypto_box_easy(c + crypto_box_PUBLICKEYBYTES, m, mlen,
+ nonce, pk, esk);
+ sodium_memzero(esk, sizeof esk);
+ sodium_memzero(epk, sizeof epk);
+ sodium_memzero(nonce, sizeof nonce);
+
+ return ret;
+}
+
+int
+crypto_box_seal_open(unsigned char *m, const unsigned char *c,
+ unsigned long long clen,
+ const unsigned char *pk, const unsigned char *sk)
+{
+ unsigned char nonce[crypto_box_NONCEBYTES];
+
+ if (clen < crypto_box_SEALBYTES) {
+ return -1;
+ }
+ _crypto_box_seal_nonce(nonce, c, pk);
+
+ COMPILER_ASSERT(crypto_box_PUBLICKEYBYTES < crypto_box_SEALBYTES);
+ return crypto_box_open_easy(m, c + crypto_box_PUBLICKEYBYTES,
+ clen - crypto_box_PUBLICKEYBYTES,
+ nonce, c, sk);
+}
+
+size_t
+crypto_box_sealbytes(void)
+{
+ return crypto_box_SEALBYTES;
+}
diff --git a/libs/libsodium/src/crypto_box/curve25519xchacha20poly1305/box_curve25519xchacha20poly1305.c b/libs/libsodium/src/crypto_box/curve25519xchacha20poly1305/box_curve25519xchacha20poly1305.c index 5e2532eab7..3fd7968405 100644 --- a/libs/libsodium/src/crypto_box/curve25519xchacha20poly1305/box_curve25519xchacha20poly1305.c +++ b/libs/libsodium/src/crypto_box/curve25519xchacha20poly1305/box_curve25519xchacha20poly1305.c @@ -1,204 +1,204 @@ - -#include <limits.h> -#include <stdint.h> -#include <stdlib.h> -#include <string.h> - -#include "core.h" -#include "crypto_box_curve25519xchacha20poly1305.h" -#include "crypto_core_hchacha20.h" -#include "crypto_hash_sha512.h" -#include "crypto_scalarmult_curve25519.h" -#include "crypto_secretbox_xchacha20poly1305.h" -#include "private/common.h" -#include "randombytes.h" -#include "utils.h" - -int -crypto_box_curve25519xchacha20poly1305_seed_keypair(unsigned char *pk, - unsigned char *sk, - const unsigned char *seed) -{ - unsigned char hash[64]; - - crypto_hash_sha512(hash, seed, 32); - memcpy(sk, hash, 32); - sodium_memzero(hash, sizeof hash); - - return crypto_scalarmult_curve25519_base(pk, sk); -} - -int -crypto_box_curve25519xchacha20poly1305_keypair(unsigned char *pk, - unsigned char *sk) -{ - randombytes_buf(sk, 32); - - return crypto_scalarmult_curve25519_base(pk, sk); -} - -int -crypto_box_curve25519xchacha20poly1305_beforenm(unsigned char *k, - const unsigned char *pk, - const unsigned char *sk) -{ - static const unsigned char zero[16] = { 0 }; - unsigned char s[32]; - - if (crypto_scalarmult_curve25519(s, sk, pk) != 0) { - return -1; - } - return crypto_core_hchacha20(k, zero, s, NULL); -} - -int -crypto_box_curve25519xchacha20poly1305_detached_afternm( - unsigned char *c, unsigned char *mac, const unsigned char *m, - unsigned long long mlen, const unsigned char *n, const unsigned char *k) -{ - return crypto_secretbox_xchacha20poly1305_detached(c, mac, m, mlen, n, k); -} - -int -crypto_box_curve25519xchacha20poly1305_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) -{ - unsigned char k[crypto_box_curve25519xchacha20poly1305_BEFORENMBYTES]; - int ret; - - COMPILER_ASSERT(crypto_box_curve25519xchacha20poly1305_BEFORENMBYTES >= - crypto_secretbox_xchacha20poly1305_KEYBYTES); - if (crypto_box_curve25519xchacha20poly1305_beforenm(k, pk, sk) != 0) { - return -1; - } - ret = crypto_box_curve25519xchacha20poly1305_detached_afternm(c, mac, m, - mlen, n, k); - sodium_memzero(k, sizeof k); - - return ret; -} - -int -crypto_box_curve25519xchacha20poly1305_easy_afternm(unsigned char *c, - const unsigned char *m, - unsigned long long mlen, - const unsigned char *n, - const unsigned char *k) -{ - if (mlen > crypto_box_curve25519xchacha20poly1305_MESSAGEBYTES_MAX) { - sodium_misuse(); - } - return crypto_box_curve25519xchacha20poly1305_detached_afternm( - c + crypto_box_curve25519xchacha20poly1305_MACBYTES, c, m, mlen, n, k); -} - -int -crypto_box_curve25519xchacha20poly1305_easy( - unsigned char *c, const unsigned char *m, unsigned long long mlen, - const unsigned char *n, const unsigned char *pk, const unsigned char *sk) -{ - if (mlen > crypto_box_curve25519xchacha20poly1305_MESSAGEBYTES_MAX) { - sodium_misuse(); - } - return crypto_box_curve25519xchacha20poly1305_detached( - c + crypto_box_curve25519xchacha20poly1305_MACBYTES, c, m, mlen, n, pk, - sk); -} - -int -crypto_box_curve25519xchacha20poly1305_open_detached_afternm( - unsigned char *m, const unsigned char *c, const unsigned char *mac, - unsigned long long clen, const unsigned char *n, const unsigned char *k) -{ - return crypto_secretbox_xchacha20poly1305_open_detached(m, c, mac, clen, n, - k); -} - -int -crypto_box_curve25519xchacha20poly1305_open_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_curve25519xchacha20poly1305_BEFORENMBYTES]; - int ret; - - if (crypto_box_curve25519xchacha20poly1305_beforenm(k, pk, sk) != 0) { - return -1; - } - ret = crypto_box_curve25519xchacha20poly1305_open_detached_afternm( - m, c, mac, clen, n, k); - sodium_memzero(k, sizeof k); - - return ret; -} - -int -crypto_box_curve25519xchacha20poly1305_open_easy_afternm( - unsigned char *m, const unsigned char *c, unsigned long long clen, - const unsigned char *n, const unsigned char *k) -{ - if (clen < crypto_box_curve25519xchacha20poly1305_MACBYTES) { - return -1; - } - return crypto_box_curve25519xchacha20poly1305_open_detached_afternm( - m, c + crypto_box_curve25519xchacha20poly1305_MACBYTES, c, - clen - crypto_box_curve25519xchacha20poly1305_MACBYTES, n, k); -} - -int -crypto_box_curve25519xchacha20poly1305_open_easy( - unsigned char *m, const unsigned char *c, unsigned long long clen, - const unsigned char *n, const unsigned char *pk, const unsigned char *sk) -{ - if (clen < crypto_box_curve25519xchacha20poly1305_MACBYTES) { - return -1; - } - return crypto_box_curve25519xchacha20poly1305_open_detached( - m, c + crypto_box_curve25519xchacha20poly1305_MACBYTES, c, - clen - crypto_box_curve25519xchacha20poly1305_MACBYTES, n, pk, sk); -} - -size_t -crypto_box_curve25519xchacha20poly1305_seedbytes(void) -{ - return crypto_box_curve25519xchacha20poly1305_SEEDBYTES; -} - -size_t -crypto_box_curve25519xchacha20poly1305_publickeybytes(void) -{ - return crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES; -} - -size_t -crypto_box_curve25519xchacha20poly1305_secretkeybytes(void) -{ - return crypto_box_curve25519xchacha20poly1305_SECRETKEYBYTES; -} - -size_t -crypto_box_curve25519xchacha20poly1305_beforenmbytes(void) -{ - return crypto_box_curve25519xchacha20poly1305_BEFORENMBYTES; -} - -size_t -crypto_box_curve25519xchacha20poly1305_noncebytes(void) -{ - return crypto_box_curve25519xchacha20poly1305_NONCEBYTES; -} - -size_t -crypto_box_curve25519xchacha20poly1305_macbytes(void) -{ - return crypto_box_curve25519xchacha20poly1305_MACBYTES; -} - -size_t -crypto_box_curve25519xchacha20poly1305_messagebytes_max(void) -{ - return crypto_box_curve25519xchacha20poly1305_MESSAGEBYTES_MAX; -} +
+#include <limits.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "core.h"
+#include "crypto_box_curve25519xchacha20poly1305.h"
+#include "crypto_core_hchacha20.h"
+#include "crypto_hash_sha512.h"
+#include "crypto_scalarmult_curve25519.h"
+#include "crypto_secretbox_xchacha20poly1305.h"
+#include "private/common.h"
+#include "randombytes.h"
+#include "utils.h"
+
+int
+crypto_box_curve25519xchacha20poly1305_seed_keypair(unsigned char *pk,
+ unsigned char *sk,
+ const unsigned char *seed)
+{
+ unsigned char hash[64];
+
+ crypto_hash_sha512(hash, seed, 32);
+ memcpy(sk, hash, 32);
+ sodium_memzero(hash, sizeof hash);
+
+ return crypto_scalarmult_curve25519_base(pk, sk);
+}
+
+int
+crypto_box_curve25519xchacha20poly1305_keypair(unsigned char *pk,
+ unsigned char *sk)
+{
+ randombytes_buf(sk, 32);
+
+ return crypto_scalarmult_curve25519_base(pk, sk);
+}
+
+int
+crypto_box_curve25519xchacha20poly1305_beforenm(unsigned char *k,
+ const unsigned char *pk,
+ const unsigned char *sk)
+{
+ static const unsigned char zero[16] = { 0 };
+ unsigned char s[32];
+
+ if (crypto_scalarmult_curve25519(s, sk, pk) != 0) {
+ return -1;
+ }
+ return crypto_core_hchacha20(k, zero, s, NULL);
+}
+
+int
+crypto_box_curve25519xchacha20poly1305_detached_afternm(
+ unsigned char *c, unsigned char *mac, const unsigned char *m,
+ unsigned long long mlen, const unsigned char *n, const unsigned char *k)
+{
+ return crypto_secretbox_xchacha20poly1305_detached(c, mac, m, mlen, n, k);
+}
+
+int
+crypto_box_curve25519xchacha20poly1305_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)
+{
+ unsigned char k[crypto_box_curve25519xchacha20poly1305_BEFORENMBYTES];
+ int ret;
+
+ COMPILER_ASSERT(crypto_box_curve25519xchacha20poly1305_BEFORENMBYTES >=
+ crypto_secretbox_xchacha20poly1305_KEYBYTES);
+ if (crypto_box_curve25519xchacha20poly1305_beforenm(k, pk, sk) != 0) {
+ return -1;
+ }
+ ret = crypto_box_curve25519xchacha20poly1305_detached_afternm(c, mac, m,
+ mlen, n, k);
+ sodium_memzero(k, sizeof k);
+
+ return ret;
+}
+
+int
+crypto_box_curve25519xchacha20poly1305_easy_afternm(unsigned char *c,
+ const unsigned char *m,
+ unsigned long long mlen,
+ const unsigned char *n,
+ const unsigned char *k)
+{
+ if (mlen > crypto_box_curve25519xchacha20poly1305_MESSAGEBYTES_MAX) {
+ sodium_misuse();
+ }
+ return crypto_box_curve25519xchacha20poly1305_detached_afternm(
+ c + crypto_box_curve25519xchacha20poly1305_MACBYTES, c, m, mlen, n, k);
+}
+
+int
+crypto_box_curve25519xchacha20poly1305_easy(
+ unsigned char *c, const unsigned char *m, unsigned long long mlen,
+ const unsigned char *n, const unsigned char *pk, const unsigned char *sk)
+{
+ if (mlen > crypto_box_curve25519xchacha20poly1305_MESSAGEBYTES_MAX) {
+ sodium_misuse();
+ }
+ return crypto_box_curve25519xchacha20poly1305_detached(
+ c + crypto_box_curve25519xchacha20poly1305_MACBYTES, c, m, mlen, n, pk,
+ sk);
+}
+
+int
+crypto_box_curve25519xchacha20poly1305_open_detached_afternm(
+ unsigned char *m, const unsigned char *c, const unsigned char *mac,
+ unsigned long long clen, const unsigned char *n, const unsigned char *k)
+{
+ return crypto_secretbox_xchacha20poly1305_open_detached(m, c, mac, clen, n,
+ k);
+}
+
+int
+crypto_box_curve25519xchacha20poly1305_open_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_curve25519xchacha20poly1305_BEFORENMBYTES];
+ int ret;
+
+ if (crypto_box_curve25519xchacha20poly1305_beforenm(k, pk, sk) != 0) {
+ return -1;
+ }
+ ret = crypto_box_curve25519xchacha20poly1305_open_detached_afternm(
+ m, c, mac, clen, n, k);
+ sodium_memzero(k, sizeof k);
+
+ return ret;
+}
+
+int
+crypto_box_curve25519xchacha20poly1305_open_easy_afternm(
+ unsigned char *m, const unsigned char *c, unsigned long long clen,
+ const unsigned char *n, const unsigned char *k)
+{
+ if (clen < crypto_box_curve25519xchacha20poly1305_MACBYTES) {
+ return -1;
+ }
+ return crypto_box_curve25519xchacha20poly1305_open_detached_afternm(
+ m, c + crypto_box_curve25519xchacha20poly1305_MACBYTES, c,
+ clen - crypto_box_curve25519xchacha20poly1305_MACBYTES, n, k);
+}
+
+int
+crypto_box_curve25519xchacha20poly1305_open_easy(
+ unsigned char *m, const unsigned char *c, unsigned long long clen,
+ const unsigned char *n, const unsigned char *pk, const unsigned char *sk)
+{
+ if (clen < crypto_box_curve25519xchacha20poly1305_MACBYTES) {
+ return -1;
+ }
+ return crypto_box_curve25519xchacha20poly1305_open_detached(
+ m, c + crypto_box_curve25519xchacha20poly1305_MACBYTES, c,
+ clen - crypto_box_curve25519xchacha20poly1305_MACBYTES, n, pk, sk);
+}
+
+size_t
+crypto_box_curve25519xchacha20poly1305_seedbytes(void)
+{
+ return crypto_box_curve25519xchacha20poly1305_SEEDBYTES;
+}
+
+size_t
+crypto_box_curve25519xchacha20poly1305_publickeybytes(void)
+{
+ return crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES;
+}
+
+size_t
+crypto_box_curve25519xchacha20poly1305_secretkeybytes(void)
+{
+ return crypto_box_curve25519xchacha20poly1305_SECRETKEYBYTES;
+}
+
+size_t
+crypto_box_curve25519xchacha20poly1305_beforenmbytes(void)
+{
+ return crypto_box_curve25519xchacha20poly1305_BEFORENMBYTES;
+}
+
+size_t
+crypto_box_curve25519xchacha20poly1305_noncebytes(void)
+{
+ return crypto_box_curve25519xchacha20poly1305_NONCEBYTES;
+}
+
+size_t
+crypto_box_curve25519xchacha20poly1305_macbytes(void)
+{
+ return crypto_box_curve25519xchacha20poly1305_MACBYTES;
+}
+
+size_t
+crypto_box_curve25519xchacha20poly1305_messagebytes_max(void)
+{
+ return crypto_box_curve25519xchacha20poly1305_MESSAGEBYTES_MAX;
+}
diff --git a/libs/libsodium/src/crypto_box/curve25519xchacha20poly1305/box_seal_curve25519xchacha20poly1305.c b/libs/libsodium/src/crypto_box/curve25519xchacha20poly1305/box_seal_curve25519xchacha20poly1305.c index 9e73a265aa..9ed3e809aa 100644 --- a/libs/libsodium/src/crypto_box/curve25519xchacha20poly1305/box_seal_curve25519xchacha20poly1305.c +++ b/libs/libsodium/src/crypto_box/curve25519xchacha20poly1305/box_seal_curve25519xchacha20poly1305.c @@ -1,79 +1,79 @@ - -#include <string.h> - -#include "crypto_box_curve25519xchacha20poly1305.h" -#include "crypto_generichash.h" -#include "private/common.h" -#include "utils.h" - -static int -_crypto_box_curve25519xchacha20poly1305_seal_nonce(unsigned char *nonce, - const unsigned char *pk1, - const unsigned char *pk2) -{ - crypto_generichash_state st; - - crypto_generichash_init(&st, NULL, 0U, - crypto_box_curve25519xchacha20poly1305_NONCEBYTES); - crypto_generichash_update(&st, pk1, - crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES); - crypto_generichash_update(&st, pk2, - crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES); - crypto_generichash_final(&st, nonce, - crypto_box_curve25519xchacha20poly1305_NONCEBYTES); - - return 0; -} - -int -crypto_box_curve25519xchacha20poly1305_seal(unsigned char *c, const unsigned char *m, - unsigned long long mlen, - const unsigned char *pk) -{ - unsigned char nonce[crypto_box_curve25519xchacha20poly1305_NONCEBYTES]; - unsigned char epk[crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES]; - unsigned char esk[crypto_box_curve25519xchacha20poly1305_SECRETKEYBYTES]; - int ret; - - if (crypto_box_curve25519xchacha20poly1305_keypair(epk, esk) != 0) { - return -1; /* LCOV_EXCL_LINE */ - } - memcpy(c, epk, crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES); - _crypto_box_curve25519xchacha20poly1305_seal_nonce(nonce, epk, pk); - ret = crypto_box_curve25519xchacha20poly1305_easy( - c + crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES, m, mlen, - nonce, pk, esk); - sodium_memzero(esk, sizeof esk); - sodium_memzero(epk, sizeof epk); - sodium_memzero(nonce, sizeof nonce); - - return ret; -} - -int -crypto_box_curve25519xchacha20poly1305_seal_open(unsigned char *m, const unsigned char *c, - unsigned long long clen, - const unsigned char *pk, - const unsigned char *sk) -{ - unsigned char nonce[crypto_box_curve25519xchacha20poly1305_NONCEBYTES]; - - if (clen < crypto_box_curve25519xchacha20poly1305_SEALBYTES) { - return -1; - } - _crypto_box_curve25519xchacha20poly1305_seal_nonce(nonce, c, pk); - - COMPILER_ASSERT(crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES < - crypto_box_curve25519xchacha20poly1305_SEALBYTES); - - return crypto_box_curve25519xchacha20poly1305_open_easy( - m, c + crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES, - clen - crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES, - nonce, c, sk); -} - -size_t -crypto_box_curve25519xchacha20poly1305_sealbytes(void) -{ - return crypto_box_curve25519xchacha20poly1305_SEALBYTES; -} +
+#include <string.h>
+
+#include "crypto_box_curve25519xchacha20poly1305.h"
+#include "crypto_generichash.h"
+#include "private/common.h"
+#include "utils.h"
+
+static int
+_crypto_box_curve25519xchacha20poly1305_seal_nonce(unsigned char *nonce,
+ const unsigned char *pk1,
+ const unsigned char *pk2)
+{
+ crypto_generichash_state st;
+
+ crypto_generichash_init(&st, NULL, 0U,
+ crypto_box_curve25519xchacha20poly1305_NONCEBYTES);
+ crypto_generichash_update(&st, pk1,
+ crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES);
+ crypto_generichash_update(&st, pk2,
+ crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES);
+ crypto_generichash_final(&st, nonce,
+ crypto_box_curve25519xchacha20poly1305_NONCEBYTES);
+
+ return 0;
+}
+
+int
+crypto_box_curve25519xchacha20poly1305_seal(unsigned char *c, const unsigned char *m,
+ unsigned long long mlen,
+ const unsigned char *pk)
+{
+ unsigned char nonce[crypto_box_curve25519xchacha20poly1305_NONCEBYTES];
+ unsigned char epk[crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES];
+ unsigned char esk[crypto_box_curve25519xchacha20poly1305_SECRETKEYBYTES];
+ int ret;
+
+ if (crypto_box_curve25519xchacha20poly1305_keypair(epk, esk) != 0) {
+ return -1; /* LCOV_EXCL_LINE */
+ }
+ memcpy(c, epk, crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES);
+ _crypto_box_curve25519xchacha20poly1305_seal_nonce(nonce, epk, pk);
+ ret = crypto_box_curve25519xchacha20poly1305_easy(
+ c + crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES, m, mlen,
+ nonce, pk, esk);
+ sodium_memzero(esk, sizeof esk);
+ sodium_memzero(epk, sizeof epk);
+ sodium_memzero(nonce, sizeof nonce);
+
+ return ret;
+}
+
+int
+crypto_box_curve25519xchacha20poly1305_seal_open(unsigned char *m, const unsigned char *c,
+ unsigned long long clen,
+ const unsigned char *pk,
+ const unsigned char *sk)
+{
+ unsigned char nonce[crypto_box_curve25519xchacha20poly1305_NONCEBYTES];
+
+ if (clen < crypto_box_curve25519xchacha20poly1305_SEALBYTES) {
+ return -1;
+ }
+ _crypto_box_curve25519xchacha20poly1305_seal_nonce(nonce, c, pk);
+
+ COMPILER_ASSERT(crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES <
+ crypto_box_curve25519xchacha20poly1305_SEALBYTES);
+
+ return crypto_box_curve25519xchacha20poly1305_open_easy(
+ m, c + crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES,
+ clen - crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES,
+ nonce, c, sk);
+}
+
+size_t
+crypto_box_curve25519xchacha20poly1305_sealbytes(void)
+{
+ return crypto_box_curve25519xchacha20poly1305_SEALBYTES;
+}
diff --git a/libs/libsodium/src/crypto_box/curve25519xsalsa20poly1305/box_curve25519xsalsa20poly1305.c b/libs/libsodium/src/crypto_box/curve25519xsalsa20poly1305/box_curve25519xsalsa20poly1305.c index 4c1d62ed43..d25d0a1c05 100644 --- a/libs/libsodium/src/crypto_box/curve25519xsalsa20poly1305/box_curve25519xsalsa20poly1305.c +++ b/libs/libsodium/src/crypto_box/curve25519xsalsa20poly1305/box_curve25519xsalsa20poly1305.c @@ -1,156 +1,156 @@ -#include <string.h> - -#include "crypto_box_curve25519xsalsa20poly1305.h" -#include "crypto_core_hsalsa20.h" -#include "crypto_hash_sha512.h" -#include "crypto_scalarmult_curve25519.h" -#include "crypto_secretbox_xsalsa20poly1305.h" -#include "randombytes.h" -#include "utils.h" - -int -crypto_box_curve25519xsalsa20poly1305_seed_keypair(unsigned char *pk, - unsigned char *sk, - const unsigned char *seed) -{ - unsigned char hash[64]; - - crypto_hash_sha512(hash, seed, 32); - memcpy(sk, hash, 32); - sodium_memzero(hash, sizeof hash); - - return crypto_scalarmult_curve25519_base(pk, sk); -} - -int -crypto_box_curve25519xsalsa20poly1305_keypair(unsigned char *pk, - unsigned char *sk) -{ - randombytes_buf(sk, 32); - - return crypto_scalarmult_curve25519_base(pk, sk); -} - -int -crypto_box_curve25519xsalsa20poly1305_beforenm(unsigned char *k, - const unsigned char *pk, - const unsigned char *sk) -{ - static const unsigned char zero[16] = { 0 }; - unsigned char s[32]; - - if (crypto_scalarmult_curve25519(s, sk, pk) != 0) { - return -1; - } - return crypto_core_hsalsa20(k, zero, s, NULL); -} - -int -crypto_box_curve25519xsalsa20poly1305_afternm(unsigned char *c, - const unsigned char *m, - unsigned long long mlen, - const unsigned char *n, - const unsigned char *k) -{ - return crypto_secretbox_xsalsa20poly1305(c, m, mlen, n, k); -} - -int -crypto_box_curve25519xsalsa20poly1305_open_afternm(unsigned char *m, - const unsigned char *c, - unsigned long long clen, - const unsigned char *n, - const unsigned char *k) -{ - return crypto_secretbox_xsalsa20poly1305_open(m, c, clen, n, k); -} - -int -crypto_box_curve25519xsalsa20poly1305(unsigned char *c, const unsigned char *m, - unsigned long long mlen, - const unsigned char *n, - const unsigned char *pk, - const unsigned char *sk) -{ - unsigned char k[crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES]; - int ret; - - if (crypto_box_curve25519xsalsa20poly1305_beforenm(k, pk, sk) != 0) { - return -1; - } - ret = crypto_box_curve25519xsalsa20poly1305_afternm(c, m, mlen, n, k); - sodium_memzero(k, sizeof k); - - return ret; -} - -int -crypto_box_curve25519xsalsa20poly1305_open( - unsigned char *m, const unsigned char *c, unsigned long long clen, - const unsigned char *n, const unsigned char *pk, const unsigned char *sk) -{ - unsigned char k[crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES]; - int ret; - - if (crypto_box_curve25519xsalsa20poly1305_beforenm(k, pk, sk) != 0) { - return -1; - } - ret = crypto_box_curve25519xsalsa20poly1305_open_afternm(m, c, clen, n, k); - sodium_memzero(k, sizeof k); - - return ret; -} - -size_t -crypto_box_curve25519xsalsa20poly1305_seedbytes(void) -{ - return crypto_box_curve25519xsalsa20poly1305_SEEDBYTES; -} - -size_t -crypto_box_curve25519xsalsa20poly1305_publickeybytes(void) -{ - return crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES; -} - -size_t -crypto_box_curve25519xsalsa20poly1305_secretkeybytes(void) -{ - return crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES; -} - -size_t -crypto_box_curve25519xsalsa20poly1305_beforenmbytes(void) -{ - return crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES; -} - -size_t -crypto_box_curve25519xsalsa20poly1305_noncebytes(void) -{ - return crypto_box_curve25519xsalsa20poly1305_NONCEBYTES; -} - -size_t -crypto_box_curve25519xsalsa20poly1305_zerobytes(void) -{ - return crypto_box_curve25519xsalsa20poly1305_ZEROBYTES; -} - -size_t -crypto_box_curve25519xsalsa20poly1305_boxzerobytes(void) -{ - return crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES; -} - -size_t -crypto_box_curve25519xsalsa20poly1305_macbytes(void) -{ - return crypto_box_curve25519xsalsa20poly1305_MACBYTES; -} - -size_t -crypto_box_curve25519xsalsa20poly1305_messagebytes_max(void) -{ - return crypto_box_curve25519xsalsa20poly1305_MESSAGEBYTES_MAX; -} +#include <string.h>
+
+#include "crypto_box_curve25519xsalsa20poly1305.h"
+#include "crypto_core_hsalsa20.h"
+#include "crypto_hash_sha512.h"
+#include "crypto_scalarmult_curve25519.h"
+#include "crypto_secretbox_xsalsa20poly1305.h"
+#include "randombytes.h"
+#include "utils.h"
+
+int
+crypto_box_curve25519xsalsa20poly1305_seed_keypair(unsigned char *pk,
+ unsigned char *sk,
+ const unsigned char *seed)
+{
+ unsigned char hash[64];
+
+ crypto_hash_sha512(hash, seed, 32);
+ memcpy(sk, hash, 32);
+ sodium_memzero(hash, sizeof hash);
+
+ return crypto_scalarmult_curve25519_base(pk, sk);
+}
+
+int
+crypto_box_curve25519xsalsa20poly1305_keypair(unsigned char *pk,
+ unsigned char *sk)
+{
+ randombytes_buf(sk, 32);
+
+ return crypto_scalarmult_curve25519_base(pk, sk);
+}
+
+int
+crypto_box_curve25519xsalsa20poly1305_beforenm(unsigned char *k,
+ const unsigned char *pk,
+ const unsigned char *sk)
+{
+ static const unsigned char zero[16] = { 0 };
+ unsigned char s[32];
+
+ if (crypto_scalarmult_curve25519(s, sk, pk) != 0) {
+ return -1;
+ }
+ return crypto_core_hsalsa20(k, zero, s, NULL);
+}
+
+int
+crypto_box_curve25519xsalsa20poly1305_afternm(unsigned char *c,
+ const unsigned char *m,
+ unsigned long long mlen,
+ const unsigned char *n,
+ const unsigned char *k)
+{
+ return crypto_secretbox_xsalsa20poly1305(c, m, mlen, n, k);
+}
+
+int
+crypto_box_curve25519xsalsa20poly1305_open_afternm(unsigned char *m,
+ const unsigned char *c,
+ unsigned long long clen,
+ const unsigned char *n,
+ const unsigned char *k)
+{
+ return crypto_secretbox_xsalsa20poly1305_open(m, c, clen, n, k);
+}
+
+int
+crypto_box_curve25519xsalsa20poly1305(unsigned char *c, const unsigned char *m,
+ unsigned long long mlen,
+ const unsigned char *n,
+ const unsigned char *pk,
+ const unsigned char *sk)
+{
+ unsigned char k[crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES];
+ int ret;
+
+ if (crypto_box_curve25519xsalsa20poly1305_beforenm(k, pk, sk) != 0) {
+ return -1;
+ }
+ ret = crypto_box_curve25519xsalsa20poly1305_afternm(c, m, mlen, n, k);
+ sodium_memzero(k, sizeof k);
+
+ return ret;
+}
+
+int
+crypto_box_curve25519xsalsa20poly1305_open(
+ unsigned char *m, const unsigned char *c, unsigned long long clen,
+ const unsigned char *n, const unsigned char *pk, const unsigned char *sk)
+{
+ unsigned char k[crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES];
+ int ret;
+
+ if (crypto_box_curve25519xsalsa20poly1305_beforenm(k, pk, sk) != 0) {
+ return -1;
+ }
+ ret = crypto_box_curve25519xsalsa20poly1305_open_afternm(m, c, clen, n, k);
+ sodium_memzero(k, sizeof k);
+
+ return ret;
+}
+
+size_t
+crypto_box_curve25519xsalsa20poly1305_seedbytes(void)
+{
+ return crypto_box_curve25519xsalsa20poly1305_SEEDBYTES;
+}
+
+size_t
+crypto_box_curve25519xsalsa20poly1305_publickeybytes(void)
+{
+ return crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES;
+}
+
+size_t
+crypto_box_curve25519xsalsa20poly1305_secretkeybytes(void)
+{
+ return crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES;
+}
+
+size_t
+crypto_box_curve25519xsalsa20poly1305_beforenmbytes(void)
+{
+ return crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES;
+}
+
+size_t
+crypto_box_curve25519xsalsa20poly1305_noncebytes(void)
+{
+ return crypto_box_curve25519xsalsa20poly1305_NONCEBYTES;
+}
+
+size_t
+crypto_box_curve25519xsalsa20poly1305_zerobytes(void)
+{
+ return crypto_box_curve25519xsalsa20poly1305_ZEROBYTES;
+}
+
+size_t
+crypto_box_curve25519xsalsa20poly1305_boxzerobytes(void)
+{
+ return crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES;
+}
+
+size_t
+crypto_box_curve25519xsalsa20poly1305_macbytes(void)
+{
+ return crypto_box_curve25519xsalsa20poly1305_MACBYTES;
+}
+
+size_t
+crypto_box_curve25519xsalsa20poly1305_messagebytes_max(void)
+{
+ return crypto_box_curve25519xsalsa20poly1305_MESSAGEBYTES_MAX;
+}
|