mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-25 08:37:13 +09:00
Force functions whose result must be checked to be checked
This commit is contained in:
@@ -9,7 +9,8 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
SODIUM_EXPORT
|
||||
int sodium_init(void);
|
||||
int sodium_init(void)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -54,7 +54,8 @@ int crypto_aead_aes256gcm_decrypt(unsigned char *m,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k);
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aes256gcm_beforenm(crypto_aead_aes256gcm_state *ctx_,
|
||||
@@ -80,7 +81,9 @@ int crypto_aead_aes256gcm_decrypt_afternm(unsigned char *m,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *npub,
|
||||
const crypto_aead_aes256gcm_state *ctx_);
|
||||
const crypto_aead_aes256gcm_state *ctx_)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -47,7 +47,8 @@ int crypto_aead_chacha20poly1305_decrypt(unsigned char *m,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k);
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
#define crypto_aead_chacha20poly1305_IETF_NPUBBYTES 12U
|
||||
SODIUM_EXPORT
|
||||
@@ -73,7 +74,9 @@ int crypto_aead_chacha20poly1305_ietf_decrypt(unsigned char *m,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k);
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -23,7 +23,8 @@ size_t crypto_auth_keybytes(void);
|
||||
|
||||
#define crypto_auth_PRIMITIVE "hmacsha512256"
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_auth_primitive(void);
|
||||
const char *crypto_auth_primitive(void)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_auth(unsigned char *out, const unsigned char *in,
|
||||
@@ -31,7 +32,9 @@ int crypto_auth(unsigned char *out, const unsigned char *in,
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_auth_verify(const unsigned char *h, const unsigned char *in,
|
||||
unsigned long long inlen, const unsigned char *k);
|
||||
unsigned long long inlen, const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -30,7 +30,8 @@ SODIUM_EXPORT
|
||||
int crypto_auth_hmacsha256_verify(const unsigned char *h,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen,
|
||||
const unsigned char *k);
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
@@ -30,7 +30,8 @@ SODIUM_EXPORT
|
||||
int crypto_auth_hmacsha512_verify(const unsigned char *h,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen,
|
||||
const unsigned char *k);
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
@@ -28,7 +28,8 @@ SODIUM_EXPORT
|
||||
int crypto_auth_hmacsha512256_verify(const unsigned char *h,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen,
|
||||
const unsigned char *k);
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
@@ -59,7 +59,8 @@ int crypto_box_easy(unsigned char *c, const unsigned char *m,
|
||||
SODIUM_EXPORT
|
||||
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);
|
||||
const unsigned char *pk, const unsigned char *sk)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_detached(unsigned char *c, unsigned char *mac,
|
||||
@@ -73,7 +74,8 @@ int crypto_box_open_detached(unsigned char *m, const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *pk,
|
||||
const unsigned char *sk);
|
||||
const unsigned char *sk)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
/* -- Precomputation interface -- */
|
||||
|
||||
@@ -93,7 +95,8 @@ int crypto_box_easy_afternm(unsigned char *c, const unsigned char *m,
|
||||
SODIUM_EXPORT
|
||||
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);
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_detached_afternm(unsigned char *c, unsigned char *mac,
|
||||
@@ -104,7 +107,8 @@ SODIUM_EXPORT
|
||||
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);
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
/* -- Ephemeral SK interface -- */
|
||||
|
||||
@@ -119,7 +123,8 @@ int crypto_box_seal(unsigned char *c, const unsigned char *m,
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_seal_open(unsigned char *m, const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *pk, const unsigned char *sk);
|
||||
const unsigned char *pk, const unsigned char *sk)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
/* -- NaCl compatibility interface ; Requires padding -- */
|
||||
|
||||
@@ -139,7 +144,8 @@ int crypto_box(unsigned char *c, const unsigned char *m,
|
||||
SODIUM_EXPORT
|
||||
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);
|
||||
const unsigned char *pk, const unsigned char *sk)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_afternm(unsigned char *c, const unsigned char *m,
|
||||
@@ -149,7 +155,9 @@ int crypto_box_afternm(unsigned char *c, const unsigned char *m,
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_open_afternm(unsigned char *m, const unsigned char *c,
|
||||
unsigned long long clen, const unsigned char *n,
|
||||
const unsigned char *k);
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -59,7 +59,8 @@ int crypto_box_curve25519xsalsa20poly1305_open(unsigned char *m,
|
||||
unsigned long long clen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *pk,
|
||||
const unsigned char *sk);
|
||||
const unsigned char *sk)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_box_curve25519xsalsa20poly1305_seed_keypair(unsigned char *pk,
|
||||
@@ -87,7 +88,8 @@ 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);
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -39,7 +39,8 @@ size_t crypto_generichash_keybytes(void);
|
||||
|
||||
#define crypto_generichash_PRIMITIVE "blake2b"
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_generichash_primitive(void);
|
||||
const char *crypto_generichash_primitive(void)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
typedef crypto_generichash_blake2b_state crypto_generichash_state;
|
||||
SODIUM_EXPORT
|
||||
|
||||
@@ -30,7 +30,8 @@ int crypto_hash(unsigned char *out, const unsigned char *in,
|
||||
|
||||
#define crypto_hash_PRIMITIVE "sha512"
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_hash_primitive(void);
|
||||
const char *crypto_hash_primitive(void)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -35,7 +35,8 @@ int crypto_onetimeauth(unsigned char *out, const unsigned char *in,
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_onetimeauth_verify(const unsigned char *h, const unsigned char *in,
|
||||
unsigned long long inlen, const unsigned char *k);
|
||||
unsigned long long inlen, const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_onetimeauth_init(crypto_onetimeauth_state *state,
|
||||
|
||||
@@ -39,7 +39,8 @@ SODIUM_EXPORT
|
||||
int crypto_onetimeauth_poly1305_verify(const unsigned char *h,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen,
|
||||
const unsigned char *k);
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_onetimeauth_poly1305_init(crypto_onetimeauth_poly1305_state *state,
|
||||
|
||||
@@ -48,25 +48,29 @@ int crypto_pwhash_scryptsalsa208sha256(unsigned char * const out,
|
||||
unsigned long long passwdlen,
|
||||
const unsigned char * const salt,
|
||||
unsigned long long opslimit,
|
||||
size_t memlimit);
|
||||
size_t memlimit)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_scryptsalsa208sha256_str(char out[crypto_pwhash_scryptsalsa208sha256_STRBYTES],
|
||||
const char * const passwd,
|
||||
unsigned long long passwdlen,
|
||||
unsigned long long opslimit,
|
||||
size_t memlimit);
|
||||
size_t memlimit)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_scryptsalsa208sha256_str_verify(const char str[crypto_pwhash_scryptsalsa208sha256_STRBYTES],
|
||||
const char * const passwd,
|
||||
unsigned long long passwdlen);
|
||||
unsigned long long passwdlen)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_scryptsalsa208sha256_ll(const uint8_t * passwd, size_t passwdlen,
|
||||
const uint8_t * salt, size_t saltlen,
|
||||
uint64_t N, uint32_t r, uint32_t p,
|
||||
uint8_t * buf, size_t buflen);
|
||||
uint8_t * buf, size_t buflen)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -37,7 +37,8 @@ int crypto_secretbox_easy(unsigned char *c, const unsigned char *m,
|
||||
SODIUM_EXPORT
|
||||
int crypto_secretbox_open_easy(unsigned char *m, const unsigned char *c,
|
||||
unsigned long long clen, const unsigned char *n,
|
||||
const unsigned char *k);
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_secretbox_detached(unsigned char *c, unsigned char *mac,
|
||||
@@ -52,7 +53,8 @@ int crypto_secretbox_open_detached(unsigned char *m,
|
||||
const unsigned char *mac,
|
||||
unsigned long long clen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *k);
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
/* -- NaCl compatibility interface ; Requires padding -- */
|
||||
|
||||
@@ -72,7 +74,9 @@ int crypto_secretbox(unsigned char *c, const unsigned char *m,
|
||||
SODIUM_EXPORT
|
||||
int crypto_secretbox_open(unsigned char *m, const unsigned char *c,
|
||||
unsigned long long clen, const unsigned char *n,
|
||||
const unsigned char *k);
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -38,7 +38,8 @@ size_t crypto_sign_secretkeybytes(void);
|
||||
|
||||
#define crypto_sign_PRIMITIVE "ed25519"
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_sign_primitive(void);
|
||||
const char *crypto_sign_primitive(void)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_seed_keypair(unsigned char *pk, unsigned char *sk,
|
||||
@@ -55,7 +56,8 @@ int crypto_sign(unsigned char *sm, unsigned long long *smlen_p,
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_open(unsigned char *m, unsigned long long *mlen_p,
|
||||
const unsigned char *sm, unsigned long long smlen,
|
||||
const unsigned char *pk);
|
||||
const unsigned char *pk)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_detached(unsigned char *sig, unsigned long long *siglen_p,
|
||||
@@ -66,7 +68,9 @@ SODIUM_EXPORT
|
||||
int crypto_sign_verify_detached(const unsigned char *sig,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *pk);
|
||||
const unsigned char *pk)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -35,7 +35,8 @@ int crypto_sign_ed25519(unsigned char *sm, unsigned long long *smlen_p,
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_ed25519_open(unsigned char *m, unsigned long long *mlen_p,
|
||||
const unsigned char *sm, unsigned long long smlen,
|
||||
const unsigned char *pk);
|
||||
const unsigned char *pk)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_ed25519_detached(unsigned char *sig,
|
||||
@@ -48,7 +49,8 @@ SODIUM_EXPORT
|
||||
int crypto_sign_ed25519_verify_detached(const unsigned char *sig,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *pk);
|
||||
const unsigned char *pk)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_ed25519_keypair(unsigned char *pk, unsigned char *sk);
|
||||
@@ -59,7 +61,8 @@ int crypto_sign_ed25519_seed_keypair(unsigned char *pk, unsigned char *sk,
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_ed25519_pk_to_curve25519(unsigned char *curve25519_pk,
|
||||
const unsigned char *ed25519_pk);
|
||||
const unsigned char *ed25519_pk)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_sign_ed25519_sk_to_curve25519(unsigned char *curve25519_sk,
|
||||
|
||||
@@ -31,7 +31,8 @@ size_t crypto_stream_noncebytes(void);
|
||||
|
||||
#define crypto_stream_PRIMITIVE "xsalsa20"
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_stream_primitive(void);
|
||||
const char *crypto_stream_primitive(void)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_stream(unsigned char *c, unsigned long long clen,
|
||||
|
||||
@@ -13,7 +13,8 @@ SODIUM_EXPORT
|
||||
size_t crypto_verify_16_bytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_verify_16(const unsigned char *x, const unsigned char *y);
|
||||
int crypto_verify_16(const unsigned char *x, const unsigned char *y)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ SODIUM_EXPORT
|
||||
size_t crypto_verify_32_bytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_verify_32(const unsigned char *x, const unsigned char *y);
|
||||
int crypto_verify_32(const unsigned char *x, const unsigned char *y)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ SODIUM_EXPORT
|
||||
size_t crypto_verify_64_bytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_verify_64(const unsigned char *x, const unsigned char *y);
|
||||
int crypto_verify_64(const unsigned char *x, const unsigned char *y)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -44,7 +44,8 @@ SODIUM_EXPORT
|
||||
int randombytes_set_implementation(randombytes_implementation *impl);
|
||||
|
||||
SODIUM_EXPORT
|
||||
const char *randombytes_implementation_name(void);
|
||||
const char *randombytes_implementation_name(void)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
/* -- NaCl compatibility interface -- */
|
||||
|
||||
|
||||
@@ -17,7 +17,8 @@ SODIUM_EXPORT
|
||||
extern struct randombytes_implementation randombytes_nativeclient_implementation;
|
||||
|
||||
SODIUM_EXPORT
|
||||
const char *randombytes_nativeclient_implementation_name(void);
|
||||
const char *randombytes_nativeclient_implementation_name(void)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
uint32_t randombytes_nativeclient(void);
|
||||
|
||||
@@ -22,7 +22,8 @@ SODIUM_EXPORT
|
||||
extern struct randombytes_implementation randombytes_salsa20_implementation;
|
||||
|
||||
SODIUM_EXPORT
|
||||
const char *randombytes_salsa20_implementation_name(void);
|
||||
const char *randombytes_salsa20_implementation_name(void)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
uint32_t randombytes_salsa20_random(void);
|
||||
|
||||
@@ -21,7 +21,8 @@ SODIUM_EXPORT
|
||||
extern struct randombytes_implementation randombytes_sysrandom_implementation;
|
||||
|
||||
SODIUM_EXPORT
|
||||
const char *randombytes_sysrandom_implementation_name(void);
|
||||
const char *randombytes_sysrandom_implementation_name(void)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
uint32_t randombytes_sysrandom(void);
|
||||
|
||||
@@ -26,7 +26,8 @@ void sodium_memzero(void * const pnt, const size_t len);
|
||||
* This function is not designed for lexicographical comparisons.
|
||||
*/
|
||||
SODIUM_EXPORT
|
||||
int sodium_memcmp(const void * const b1_, const void * const b2_, size_t len);
|
||||
int sodium_memcmp(const void * const b1_, const void * const b2_, size_t len)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
/*
|
||||
* sodium_compare() returns -1 if b1_ < b2_, 1 if b1_ > b2_ and 0 if b1_ == b2_
|
||||
@@ -36,7 +37,8 @@ int sodium_memcmp(const void * const b1_, const void * const b2_, size_t len);
|
||||
*/
|
||||
SODIUM_EXPORT
|
||||
int sodium_compare(const unsigned char *b1_, const unsigned char *b2_,
|
||||
size_t len);
|
||||
size_t len)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void sodium_increment(unsigned char *n, const size_t nlen);
|
||||
@@ -92,10 +94,12 @@ int sodium_munlock(void * const addr, const size_t len);
|
||||
*/
|
||||
|
||||
SODIUM_EXPORT
|
||||
void *sodium_malloc(const size_t size);
|
||||
void *sodium_malloc(const size_t size)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void *sodium_allocarray(size_t count, size_t size);
|
||||
void *sodium_allocarray(size_t count, size_t size)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
void sodium_free(void *ptr);
|
||||
|
||||
@@ -68,9 +68,11 @@ int main(void)
|
||||
printf("crypto_box_easy_afternm() with a short ciphertext should have failed\n");
|
||||
}
|
||||
crypto_box_easy_afternm(c, m, (unsigned long long) mlen, nonce, k1);
|
||||
crypto_box_open_easy_afternm(m2, c,
|
||||
(unsigned long long) mlen + crypto_box_MACBYTES,
|
||||
nonce, k2);
|
||||
if (crypto_box_open_easy_afternm(m2, c,
|
||||
(unsigned long long) mlen + crypto_box_MACBYTES,
|
||||
nonce, k2) != 0) {
|
||||
printf("crypto_box_open_easy_afternm() failed\n");
|
||||
}
|
||||
printf("%d\n", memcmp(m, m2, mlen));
|
||||
if (crypto_box_open_easy_afternm(m2, c, crypto_box_MACBYTES - 1U,
|
||||
nonce, k2) == 0) {
|
||||
@@ -79,15 +81,19 @@ int main(void)
|
||||
memset(m2, 0, sizeof m2);
|
||||
crypto_box_detached(c, mac, m, (unsigned long long) mlen,
|
||||
nonce, alicepk, bobsk);
|
||||
crypto_box_open_detached(m2, c, mac, (unsigned long long) mlen,
|
||||
nonce, bobpk, alicesk);
|
||||
if (crypto_box_open_detached(m2, c, mac, (unsigned long long) mlen,
|
||||
nonce, bobpk, alicesk) != 0) {
|
||||
printf("crypto_box_open_detached() failed\n");
|
||||
}
|
||||
printf("%d\n", memcmp(m, m2, mlen));
|
||||
|
||||
memset(m2, 0, sizeof m2);
|
||||
crypto_box_detached_afternm(c, mac, m, (unsigned long long) mlen,
|
||||
nonce, k1);
|
||||
crypto_box_open_detached_afternm(m2, c, mac, (unsigned long long) mlen,
|
||||
nonce, k2);
|
||||
if (crypto_box_open_detached_afternm(m2, c, mac, (unsigned long long) mlen,
|
||||
nonce, k2) != 0) {
|
||||
printf("crypto_box_open_detached_afternm() failed\n");
|
||||
}
|
||||
printf("%d\n", memcmp(m, m2, mlen));
|
||||
|
||||
sodium_free(alicepk);
|
||||
|
||||
@@ -19,7 +19,9 @@ int main(void)
|
||||
unsigned int i;
|
||||
|
||||
crypto_sign_ed25519_seed_keypair(ed25519_pk, ed25519_skpk, keypair_seed);
|
||||
crypto_sign_ed25519_pk_to_curve25519(curve25519_pk, ed25519_pk);
|
||||
if (crypto_sign_ed25519_pk_to_curve25519(curve25519_pk, ed25519_pk) != 0) {
|
||||
printf("conversion failed\n");
|
||||
}
|
||||
crypto_sign_ed25519_sk_to_curve25519(curve25519_sk, ed25519_skpk);
|
||||
sodium_bin2hex(curve25519_pk_hex, sizeof curve25519_pk_hex, curve25519_pk,
|
||||
sizeof curve25519_pk);
|
||||
@@ -31,7 +33,9 @@ int main(void)
|
||||
|
||||
for (i = 0U; i < 500U; i++) {
|
||||
crypto_sign_ed25519_keypair(ed25519_pk, ed25519_skpk);
|
||||
crypto_sign_ed25519_pk_to_curve25519(curve25519_pk, ed25519_pk);
|
||||
if (crypto_sign_ed25519_pk_to_curve25519(curve25519_pk, ed25519_pk) != 0) {
|
||||
printf("conversion failed\n");
|
||||
}
|
||||
crypto_sign_ed25519_sk_to_curve25519(curve25519_sk, ed25519_skpk);
|
||||
crypto_scalarmult_curve25519_base(curve25519_pk2, curve25519_sk);
|
||||
if (memcmp(curve25519_pk, curve25519_pk2, sizeof curve25519_pk) != 0) {
|
||||
|
||||
Reference in New Issue
Block a user