]> git.codecow.com Git - Monocypher.git/commitdiff
Fixed C++ compilation
authorLoup Vaillant <loup@loup-vaillant.fr>
Wed, 8 Jan 2020 22:03:55 +0000 (23:03 +0100)
committerLoup Vaillant <loup@loup-vaillant.fr>
Wed, 8 Jan 2020 22:03:55 +0000 (23:03 +0100)
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.

src/monocypher.c
src/optional/monocypher-ed25519.c
tests/test.c

index 7e55f24622fd8b5faa9dedfea81e02698387a5c4..6eeffb222fc8b0568747f62287d04629d513559a 100644 (file)
@@ -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);
 }
 
 ////////////////////
index ee366e4a0cca7788b668e488ba3d84a875cec820..aa524b55f834307830c095182b66e867ede59756 100644 (file)
@@ -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);
 }
-
index 71acf0ba0a381ba4fbfb5a49e6019c35b0ce9f25..969e657cf810acd3638dd7166a671bfa0719a46e 100644 (file)
@@ -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");