diff --git a/src/main.c b/src/main.c index e4aadbd..086c355 100644 --- a/src/main.c +++ b/src/main.c @@ -35,7 +35,13 @@ int main(int argc, char **argv) { unsigned char *oh = crypt_hello(&own); unsigned char *rh = crypt_hello(&remote); + unsigned char *oc = NULL; + char *rmsg = NULL; + unsigned long long ocl = 0, rml = 0; + int rt = 0; + crypt_session_t os, rs; + unsigned char *nonce_own = NULL, *nonce_rem = NULL; if (crypt_hello_verify(oh, &own) < 0) { fprintf(stderr, "oh v fail"); @@ -49,8 +55,8 @@ int main(int argc, char **argv) { goto cleanup; } - const unsigned char *nonce_own = crypt_hello_get_nonce(oh, rh, false); - const unsigned char *nonce_rem = crypt_hello_get_nonce(rh, oh, true); + nonce_own = crypt_hello_get_nonce(oh, rh, false); + nonce_rem = crypt_hello_get_nonce(rh, oh, true); for (unsigned int i = 0; i < CRYPT_NONCE_LEN; ++i) if (nonce_own[i] != nonce_rem[i]) { @@ -59,7 +65,6 @@ int main(int argc, char **argv) { goto cleanup; } - crypt_session_t os, rs; if (crypt_session_init(&os, &own, &remote, nonce_own, true) < 0) { rt = -1; @@ -74,8 +79,7 @@ int main(int argc, char **argv) { char msg[] = "Hello!"; unsigned long long msglen = 6; - unsigned long long ocl = 0; - unsigned char *oc = crypt_session_encrypt(&os, (unsigned char *)msg, msglen, &ocl); + oc = crypt_session_encrypt(&os, (unsigned char *)msg, msglen, &ocl); if (oc == NULL) { fprintf(stderr, "oc is null"); @@ -83,8 +87,7 @@ int main(int argc, char **argv) { goto cleanup; } - unsigned long long rml = 0; - char *rmsg = (char *)crypt_session_decrypt(&rs, oc, ocl, &rml); + rmsg = (char *)crypt_session_decrypt(&rs, oc, ocl, &rml); if (rmsg == NULL) { rt = -1; @@ -98,6 +101,12 @@ cleanup: free(oh); free(rh); + free(oc); + free(rmsg); + + free(nonce_own); + free(nonce_rem); + crypt_key_destroy(&own); crypt_key_destroy(&remote);