[Pkg-privacy-commits] [libotr] 39/225: * src/sm.c: * src/message.c: ISO C cleanups (no mixing declarations with code)

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 12:44:50 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository libotr.

commit 298d6aa70b78f43b36c2adebc30fe1ca7c7d18bb
Author: cypherpunk <cypherpunk>
Date:   Thu Jul 26 16:38:40 2007 +0000

    	* src/sm.c:
    	* src/message.c: ISO C cleanups (no mixing declarations with
    	code)
    
    	* src/sm.c: Fixed a 64-bit pointer error
---
 ChangeLog     |  8 ++++++++
 src/message.c | 16 ++++++++++------
 src/proto.c   |  6 ++++--
 src/sm.c      | 48 ++++++++++++++++++++++++++++++------------------
 4 files changed, 52 insertions(+), 26 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c989147..16c2432 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-07-26:
+
+	* src/sm.c:
+	* src/message.c: ISO C cleanups (no mixing declarations with
+	code)
+
+	* src/sm.c: Fixed a 64-bit pointer error
+
 2007-07-25:
 
 	* src/message.c: Behave sanely if we receive a totally malformed
diff --git a/src/message.c b/src/message.c
index 1439439..ff1da30 100644
--- a/src/message.c
+++ b/src/message.c
@@ -519,6 +519,8 @@ static void init_respond_smp(OtrlUserState us, const OtrlMessageAppOps *ops,
     unsigned char our_fp[20];
     unsigned char *combined_buf;
     size_t combined_buf_len;
+    OtrlTLV *sendtlv;
+    char *sendsmp = NULL;
 
     if (!context || context->msgstate != OTRL_MSGSTATE_ENCRYPTED) return;
 
@@ -559,9 +561,8 @@ static void init_respond_smp(OtrlUserState us, const OtrlMessageAppOps *ops,
     }
 
     /* Send msg with next smp msg content */
-    OtrlTLV *sendtlv = otrl_tlv_new(initiating ? OTRL_TLV_SMP1 : OTRL_TLV_SMP2,
+    sendtlv = otrl_tlv_new(initiating ? OTRL_TLV_SMP1 : OTRL_TLV_SMP2,
 	    smpmsglen, smpmsg);
-    char *sendsmp = NULL;
     err = otrl_proto_create_data(&sendsmp, context, "", sendtlv,
             OTRL_MSGFLAGS_IGNORE_UNREADABLE);
     if (!err) {
@@ -598,12 +599,13 @@ void otrl_message_respond_smp(OtrlUserState us, const OtrlMessageAppOps *ops,
 void otrl_message_abort_smp(OtrlUserState us, const OtrlMessageAppOps *ops,
 	void *opdata, ConnContext *context)
 {
-    context->smstate->nextExpected = OTRL_SMP_EXPECT1;
-
     OtrlTLV *sendtlv = otrl_tlv_new(OTRL_TLV_SMP_ABORT, 0,
 	    (const unsigned char *)"");
     char *sendsmp = NULL;
     gcry_error_t err;
+    
+    context->smstate->nextExpected = OTRL_SMP_EXPECT1;
+
     err = otrl_proto_create_data(&sendsmp,
 	    context, "", sendtlv,
 	    OTRL_MSGFLAGS_IGNORE_UNREADABLE);
@@ -1295,18 +1297,21 @@ gcry_error_t otrl_message_fragment_and_send(const OtrlMessageAppOps *ops,
 {
     int mms = 0;
     if (message && ops->inject_message) {
+    	int msglen;
+
         if (otrl_api_version >= 0x030100 && ops->max_message_size) {
 	    mms = ops->max_message_size(opdata, context);
         }
-    	int msglen;
     	msglen = strlen(message);
 
 	/* Don't incur overhead of fragmentation unless necessary */
     	if(mms != 0 && msglen > mms) {
 	    char **fragments;
 	    gcry_error_t err;
+	    int i;
 	    int fragment_count = ((msglen - 1) / (mms -19)) + 1;
 		/* like ceil(msglen/(mms - 19)) */
+
 	    err = otrl_proto_fragment_create(mms, fragment_count, &fragments,
 		    message);
 	    if (err) {
@@ -1322,7 +1327,6 @@ gcry_error_t otrl_message_fragment_and_send(const OtrlMessageAppOps *ops,
 		ops->inject_message(opdata, context->accountname,
 			context->protocol, context->username, fragments[0]);
 	    }
-	    int i;
 	    for (i=1; i<fragment_count-1; i++) {
 		ops->inject_message(opdata, context->accountname,
 			context->protocol, context->username, fragments[i]);
diff --git a/src/proto.c b/src/proto.c
index e0e738f..844af2e 100644
--- a/src/proto.c
+++ b/src/proto.c
@@ -846,12 +846,14 @@ gcry_error_t otrl_proto_fragment_create(int mms, int fragment_count,
      * Find the next message fragment and store it in the array.
      */
     for(curfrag = 1; curfrag <= fragment_count; curfrag++) {
+	int i;
+    	char *fragmentmsg;
+
 	if (msglen - index < mms - headerlen) {
     	    fragdatalen = msglen - index;
 	} else {
 	    fragdatalen = mms - headerlen;
 	}
-	int i;
 	fragdata = malloc(fragdatalen + 1);
     	if(!fragdata) {
 		for (i=0; i<curfrag-1; free(fragmentarray[i++])) {}
@@ -861,7 +863,7 @@ gcry_error_t otrl_proto_fragment_create(int mms, int fragment_count,
     	strncpy(fragdata, message, fragdatalen);
     	fragdata[fragdatalen] = 0;
     	
-    	char *fragmentmsg = malloc(fragdatalen+headerlen+1);
+    	fragmentmsg = malloc(fragdatalen+headerlen+1);
     	if(!fragmentmsg) {
 	    for (i=0; i<curfrag-1; free(fragmentarray[i++])) {}
     	    free(fragmentarray);
diff --git a/src/sm.c b/src/sm.c
index 82df905..84b9bab 100644
--- a/src/sm.c
+++ b/src/sm.c
@@ -246,8 +246,8 @@ static gcry_error_t otrl_sm_hash(gcry_mpi_t* hash, int version,
 {
     unsigned char* input;
     unsigned char output[SM_DIGEST_SIZE];
-    unsigned int sizea;
-    unsigned int sizeb;
+    size_t sizea;
+    size_t sizeb;
     unsigned int totalsize;
     unsigned char* dataa;
     unsigned char* datab;
@@ -415,6 +415,8 @@ static gcry_error_t otrl_sm_proof_know_log(gcry_mpi_t *c, gcry_mpi_t *d, const g
  */
 static int otrl_sm_check_know_log(const gcry_mpi_t c, const gcry_mpi_t d, const gcry_mpi_t g, const gcry_mpi_t x, int version)
 {
+    int comp;
+
     gcry_mpi_t gd = gcry_mpi_new(SM_MOD_LEN_BITS);  /* g^d */
     gcry_mpi_t xc = gcry_mpi_new(SM_MOD_LEN_BITS);  /* x^c */
     gcry_mpi_t gdxc = gcry_mpi_new(SM_MOD_LEN_BITS);   /* (g^d x^c) */
@@ -425,7 +427,7 @@ static int otrl_sm_check_know_log(const gcry_mpi_t c, const gcry_mpi_t d, const
     gcry_mpi_mulm(gdxc, gd, xc, SM_MODULUS);
     otrl_sm_hash(&hgdxc, version, gdxc, NULL);
     
-    int comp = gcry_mpi_cmp(hgdxc, c);
+    comp = gcry_mpi_cmp(hgdxc, c);
     gcry_mpi_release(gd);
     gcry_mpi_release(xc);
     gcry_mpi_release(gdxc);
@@ -471,6 +473,8 @@ static gcry_error_t otrl_sm_proof_equal_coords(gcry_mpi_t *c, gcry_mpi_t *d1, gc
  */
 static gcry_error_t otrl_sm_check_equal_coords(const gcry_mpi_t c, const gcry_mpi_t d1, const gcry_mpi_t d2, const gcry_mpi_t p, const gcry_mpi_t q, const OtrlSMState *state, int version)
 {
+    int comp;
+
     gcry_mpi_t temp1 = gcry_mpi_new(SM_MOD_LEN_BITS);
     gcry_mpi_t temp2 = gcry_mpi_new(SM_MOD_LEN_BITS);
     gcry_mpi_t temp3 = gcry_mpi_new(SM_MOD_LEN_BITS);
@@ -498,7 +502,7 @@ static gcry_error_t otrl_sm_check_equal_coords(const gcry_mpi_t c, const gcry_mp
 
     otrl_sm_hash(&cprime, version, temp1, temp2);
 
-    int comp = gcry_mpi_cmp(c, cprime);
+    comp = gcry_mpi_cmp(c, cprime);
     gcry_mpi_release(temp1);
     gcry_mpi_release(temp2);
     gcry_mpi_release(temp3);
@@ -537,6 +541,8 @@ static gcry_error_t otrl_sm_proof_equal_logs(gcry_mpi_t *c, gcry_mpi_t *d, OtrlS
  */
 static gcry_error_t otrl_sm_check_equal_logs(const gcry_mpi_t c, const gcry_mpi_t d, const gcry_mpi_t r, const OtrlSMState *state, int version)
 {
+    int comp;
+
     gcry_mpi_t temp1 = gcry_mpi_new(SM_MOD_LEN_BITS);
     gcry_mpi_t temp2 = gcry_mpi_new(SM_MOD_LEN_BITS);
     gcry_mpi_t temp3 = gcry_mpi_new(SM_MOD_LEN_BITS);
@@ -565,7 +571,7 @@ static gcry_error_t otrl_sm_check_equal_logs(const gcry_mpi_t c, const gcry_mpi_
 
     otrl_sm_hash(&cprime, version, temp1, temp2);
 
-    int comp = gcry_mpi_cmp(c, cprime);
+    comp = gcry_mpi_cmp(c, cprime);
     gcry_mpi_release(temp1);
     gcry_mpi_release(temp2);
     gcry_mpi_release(temp3);
@@ -587,6 +593,7 @@ gcry_error_t otrl_sm_step1(OtrlSMAliceState *astate,
 {
     /* Initialize the sm state or update the secret */
     gcry_mpi_t secret_mpi = NULL;
+    gcry_mpi_t *msg1;
 
     *output = NULL;
     *outputlen = 0;
@@ -599,7 +606,6 @@ gcry_error_t otrl_sm_step1(OtrlSMAliceState *astate,
     gcry_mpi_set(astate->secret, secret_mpi);
     gcry_mpi_release(secret_mpi);
 
-    gcry_mpi_t *msg1;
     otrl_sm_msg1_init(&msg1);
 
     astate->x2 = randomExponent();
@@ -672,6 +678,7 @@ gcry_error_t otrl_sm_step2a(OtrlSMBobState *bstate, const unsigned char* input,
 gcry_error_t otrl_sm_step2b(OtrlSMBobState *bstate, const unsigned char* secret, int secretlen, unsigned char **output, int* outputlen)
 {
     /* Convert the given secret to the proper form and store it */
+    gcry_mpi_t r, qb1, qb2;
     gcry_mpi_t *msg2;
     gcry_mpi_t secret_mpi = NULL;
 
@@ -691,9 +698,9 @@ gcry_error_t otrl_sm_step2b(OtrlSMBobState *bstate, const unsigned char* secret,
     otrl_sm_proof_know_log(&(msg2[4]), &(msg2[5]), bstate->g1, bstate->x3, 4);
 
     /* Calculate P and Q values for Bob */
-    gcry_mpi_t r = randomExponent();
-    gcry_mpi_t qb1 = gcry_mpi_new(SM_MOD_LEN_BITS);
-    gcry_mpi_t qb2 = gcry_mpi_new(SM_MOD_LEN_BITS);
+    r = randomExponent();
+    qb1 = gcry_mpi_new(SM_MOD_LEN_BITS);
+    qb2 = gcry_mpi_new(SM_MOD_LEN_BITS);
     gcry_mpi_powm(bstate->p, bstate->g3, r, SM_MODULUS);
     gcry_mpi_set(msg2[6], bstate->p);
     gcry_mpi_powm(qb1, bstate->g1, r, SM_MODULUS);
@@ -725,6 +732,7 @@ gcry_error_t otrl_sm_step2b(OtrlSMBobState *bstate, const unsigned char* secret,
 gcry_error_t otrl_sm_step3(OtrlSMAliceState *astate, const unsigned char* input, const int inputlen, unsigned char **output, int* outputlen)
 {
     /* Read from input to find the mpis */
+    gcry_mpi_t r, qa1, qa2, inv;
     gcry_mpi_t *msg2;
     gcry_mpi_t *msg3;
     gcry_error_t err;
@@ -762,9 +770,9 @@ gcry_error_t otrl_sm_step3(OtrlSMAliceState *astate, const unsigned char* input,
         return gcry_error(GPG_ERR_INV_VALUE);
 
     /* Calculate P and Q values for Alice */
-    gcry_mpi_t r = randomExponent();
-    gcry_mpi_t qa1 = gcry_mpi_new(SM_MOD_LEN_BITS);
-    gcry_mpi_t qa2 = gcry_mpi_new(SM_MOD_LEN_BITS);
+    r = randomExponent();
+    qa1 = gcry_mpi_new(SM_MOD_LEN_BITS);
+    qa2 = gcry_mpi_new(SM_MOD_LEN_BITS);
     gcry_mpi_powm(astate->p, astate->g3, r, SM_MODULUS);
     gcry_mpi_set(msg3[0], astate->p);
     gcry_mpi_powm(qa1, astate->g1, r, SM_MODULUS);
@@ -775,7 +783,7 @@ gcry_error_t otrl_sm_step3(OtrlSMAliceState *astate, const unsigned char* input,
     otrl_sm_proof_equal_coords(&(msg3[2]), &(msg3[3]), &(msg3[4]), astate, r, 6);
 
     /* Calculate Ra and proof */
-    gcry_mpi_t inv = gcry_mpi_new(SM_MOD_LEN_BITS);
+    inv = gcry_mpi_new(SM_MOD_LEN_BITS);
     gcry_mpi_invm(inv, msg2[6], SM_MODULUS);
     gcry_mpi_mulm(astate->pab, astate->p, inv, SM_MODULUS);
     gcry_mpi_invm(inv, msg2[7], SM_MODULUS);
@@ -806,6 +814,8 @@ gcry_error_t otrl_sm_step3(OtrlSMAliceState *astate, const unsigned char* input,
 gcry_error_t otrl_sm_step4(OtrlSMBobState *bstate, const unsigned char* input, const int inputlen, unsigned char **output, int* outputlen)
 {
     /* Read from input to find the mpis */
+    int comp;
+    gcry_mpi_t inv, rab;
     gcry_mpi_t *msg3;
     gcry_mpi_t *msg4;
     gcry_error_t err;
@@ -829,7 +839,7 @@ gcry_error_t otrl_sm_step4(OtrlSMBobState *bstate, const unsigned char* input, c
         return gcry_error(GPG_ERR_INV_VALUE);
 
     /* Find Pa/Pb and Qa/Qb */
-    gcry_mpi_t inv = gcry_mpi_new(SM_MOD_LEN_BITS);
+    inv = gcry_mpi_new(SM_MOD_LEN_BITS);
     gcry_mpi_invm(inv, bstate->p, SM_MODULUS);
     gcry_mpi_mulm(bstate->pab, msg3[0], inv, SM_MODULUS);
     gcry_mpi_invm(inv, bstate->q, SM_MODULUS);
@@ -846,9 +856,9 @@ gcry_error_t otrl_sm_step4(OtrlSMBobState *bstate, const unsigned char* input, c
     serialize_mpi_array(output, outputlen, SM_MSG4_LEN, msg4);
 
     /* Calculate Rab and verify that secrets match */
-    gcry_mpi_t rab = gcry_mpi_new(SM_MOD_LEN_BITS);
+    rab = gcry_mpi_new(SM_MOD_LEN_BITS);
     gcry_mpi_powm(rab, msg3[5], bstate->x3, SM_MODULUS);
-    int comp = gcry_mpi_cmp(rab, bstate->pab);
+    comp = gcry_mpi_cmp(rab, bstate->pab);
 
     /* Clean up everything allocated in this step */
     otrl_sm_msg_free(&msg3, SM_MSG3_LEN);
@@ -869,6 +879,8 @@ gcry_error_t otrl_sm_step4(OtrlSMBobState *bstate, const unsigned char* input, c
 gcry_error_t otrl_sm_step5(OtrlSMAliceState *astate, const unsigned char* input, const int inputlen)
 {
     /* Read from input to find the mpis */
+    int comp;
+    gcry_mpi_t rab;
     gcry_mpi_t *msg4;
     gcry_error_t err;
     err = unserialize_mpi_array(&msg4, SM_MSG4_LEN, input, inputlen);
@@ -884,10 +896,10 @@ gcry_error_t otrl_sm_step5(OtrlSMAliceState *astate, const unsigned char* input,
         return gcry_error(GPG_ERR_INV_VALUE);
 
     /* Calculate Rab and verify that secrets match */
-    gcry_mpi_t rab = gcry_mpi_new(SM_MOD_LEN_BITS);
+    rab = gcry_mpi_new(SM_MOD_LEN_BITS);
     gcry_mpi_powm(rab, msg4[0], astate->x3, SM_MODULUS);
 
-    int comp = gcry_mpi_cmp(rab, astate->pab);
+    comp = gcry_mpi_cmp(rab, astate->pab);
     gcry_mpi_release(rab);
     otrl_sm_msg_free(&msg4, SM_MSG4_LEN);
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/libotr.git



More information about the Pkg-privacy-commits mailing list