1
0

Oh, because of goto used some var can never be presented, so lets move them right before the first use of a goto.

This commit is contained in:
Alexander Andreev 2024-03-24 04:56:02 +04:00
parent 98581204e9
commit 3b68835c9c
Signed by: Arav
GPG Key ID: 25969B23DCB5CA34

View File

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