From: Loup Vaillant Date: Wed, 8 Jan 2020 22:03:55 +0000 (+0100) Subject: Fixed C++ compilation X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=e1520e87d;p=Monocypher.git Fixed C++ compilation Fixes #148 C++ is less lenient than C with its casts. It requires the pointers to be cast to the correct type, `void*` alone does not work. TODO: we should probably fix the documentation as well. --- diff --git a/src/monocypher.c b/src/monocypher.c index 7e55f24..6eeffb2 100644 --- a/src/monocypher.c +++ b/src/monocypher.c @@ -2061,11 +2061,12 @@ void crypto_sign(u8 signature[64], const u8 *message, size_t message_size) { crypto_sign_ctx ctx; - crypto_sign_init_first_pass ((void*)&ctx, secret_key, public_key); - crypto_sign_update ((void*)&ctx, message, message_size); - crypto_sign_init_second_pass((void*)&ctx); - crypto_sign_update ((void*)&ctx, message, message_size); - crypto_sign_final ((void*)&ctx, signature); + crypto_sign_ctx_abstract *actx = (crypto_sign_ctx_abstract*)&ctx; + crypto_sign_init_first_pass (actx, secret_key, public_key); + crypto_sign_update (actx, message, message_size); + crypto_sign_init_second_pass(actx); + crypto_sign_update (actx, message, message_size); + crypto_sign_final (actx, signature); } void crypto_check_init_custom_hash(crypto_check_ctx_abstract *ctx, @@ -2125,10 +2126,11 @@ int crypto_check(const u8 signature[64], const u8 public_key[32], const u8 *message, size_t message_size) { - crypto_check_ctx ctx; - crypto_check_init((void*)&ctx, signature, public_key); - crypto_check_update((void*)&ctx, message, message_size); - return crypto_check_final((void*)&ctx); + crypto_check_ctx ctx; + crypto_check_ctx_abstract *actx = (crypto_check_ctx_abstract*)&ctx; + crypto_check_init (actx, signature, public_key); + crypto_check_update(actx, message, message_size); + return crypto_check_final(actx); } //////////////////// diff --git a/src/optional/monocypher-ed25519.c b/src/optional/monocypher-ed25519.c index ee366e4..aa524b5 100644 --- a/src/optional/monocypher-ed25519.c +++ b/src/optional/monocypher-ed25519.c @@ -376,11 +376,12 @@ void crypto_ed25519_sign(u8 signature [64], const u8 *message, size_t message_size) { crypto_sign_ed25519_ctx ctx; - crypto_ed25519_sign_init_first_pass ((void*)&ctx, secret_key, public_key); - crypto_ed25519_sign_update ((void*)&ctx, message, message_size); - crypto_ed25519_sign_init_second_pass((void*)&ctx); - crypto_ed25519_sign_update ((void*)&ctx, message, message_size); - crypto_ed25519_sign_final ((void*)&ctx, signature); + crypto_sign_ctx_abstract *actx = (crypto_sign_ctx_abstract*)&ctx; + crypto_ed25519_sign_init_first_pass (actx, secret_key, public_key); + crypto_ed25519_sign_update (actx, message, message_size); + crypto_ed25519_sign_init_second_pass(actx); + crypto_ed25519_sign_update (actx, message, message_size); + crypto_ed25519_sign_final (actx, signature); } @@ -389,8 +390,8 @@ int crypto_ed25519_check(const u8 signature [64], const u8 *message, size_t message_size) { crypto_check_ed25519_ctx ctx; - crypto_ed25519_check_init((void*)&ctx, signature, public_key); - crypto_ed25519_check_update((void*)&ctx, message, message_size); - return crypto_ed25519_check_final((void*)&ctx); + crypto_check_ctx_abstract *actx = (crypto_check_ctx_abstract*)&ctx; + crypto_ed25519_check_init (actx, signature, public_key); + crypto_ed25519_check_update(actx, message, message_size); + return crypto_ed25519_check_final(actx); } - diff --git a/tests/test.c b/tests/test.c index 71acf0b..969e657 100644 --- a/tests/test.c +++ b/tests/test.c @@ -739,22 +739,24 @@ static int p_eddsa_incremental() u8 sig_incr[64]; { crypto_sign_ctx ctx; - crypto_sign_init_first_pass ((void*)&ctx, sk, pk); - crypto_sign_update ((void*)&ctx, msg , i); - crypto_sign_update ((void*)&ctx, msg+i, MESSAGE_SIZE-i); - crypto_sign_init_second_pass((void*)&ctx); - crypto_sign_update ((void*)&ctx, msg , i); - crypto_sign_update ((void*)&ctx, msg+i, MESSAGE_SIZE-i); - crypto_sign_final ((void*)&ctx, sig_incr); + crypto_sign_ctx_abstract *actx = (crypto_sign_ctx_abstract*)&ctx; + crypto_sign_init_first_pass (actx, sk, pk); + crypto_sign_update (actx, msg , i); + crypto_sign_update (actx, msg+i, MESSAGE_SIZE-i); + crypto_sign_init_second_pass(actx); + crypto_sign_update (actx, msg , i); + crypto_sign_update (actx, msg+i, MESSAGE_SIZE-i); + crypto_sign_final (actx, sig_incr); } status |= memcmp(sig_mono, sig_incr, 64); status |= crypto_check(sig_mono, pk, msg, MESSAGE_SIZE); { crypto_check_ctx ctx; - crypto_check_init ((void*)&ctx, sig_incr, pk); - crypto_check_update((void*)&ctx, msg , i); - crypto_check_update((void*)&ctx, msg+i, MESSAGE_SIZE-i); - status |= crypto_check_final((void*)&ctx); + crypto_check_ctx_abstract *actx = (crypto_check_ctx_abstract*)&ctx; + crypto_check_init (actx, sig_incr, pk); + crypto_check_update(actx, msg , i); + crypto_check_update(actx, msg+i, MESSAGE_SIZE-i); + status |= crypto_check_final(actx); } } printf("%s: EdDSA (incremental)\n", status != 0 ? "FAILED" : "OK");