Use memcmp() instead of deprecated bcmp()

This commit is contained in:
Andrew Bettison 2012-04-17 10:33:01 +09:30
parent 866ddea189
commit 0d6e77e221
2 changed files with 8 additions and 8 deletions

View File

@ -684,7 +684,7 @@ int keyring_decrypt_pkr(keyring_file *k,keyring_context *c,
goto kdp_safeexit; goto kdp_safeexit;
} }
/* compare hash to record */ /* compare hash to record */
if (bcmp(hash,&slot[32],crypto_hash_sha512_BYTES)) if (memcmp(hash,&slot[32],crypto_hash_sha512_BYTES))
{ {
WHY("Slot is not valid (MAC mismatch)"); WHY("Slot is not valid (MAC mismatch)");
dump("computed",hash,crypto_hash_sha512_BYTES); dump("computed",hash,crypto_hash_sha512_BYTES);
@ -1169,14 +1169,14 @@ int keyring_mapping_request(keyring_file *k,overlay_mdp_frame *req)
check anyway. */ check anyway. */
if (plain_len!=SID_SIZE) if (plain_len!=SID_SIZE)
return WHY("key mapping signed block is wrong length"); return WHY("key mapping signed block is wrong length");
if (bcmp(plain,req->out.src.sid,SID_SIZE)) if (memcmp(plain,req->out.src.sid,SID_SIZE))
return WHY("key mapping signed block is for wrong SID"); return WHY("key mapping signed block is for wrong SID");
WHY("Key mapping looks valid"); WHY("Key mapping looks valid");
/* work out where to put it */ /* work out where to put it */
int i; int i;
for(i=0;i<sid_sas_mapping_count;i++) for(i=0;i<sid_sas_mapping_count;i++)
if (!bcmp(req->out.src.sid,sid_sas_mappings[i].sid,SID_SIZE)) break; if (!memcmp(req->out.src.sid,sid_sas_mappings[i].sid,SID_SIZE)) break;
if (i>=MAX_SID_SAS_MAPPINGS) i=random()%MAX_SID_SAS_MAPPINGS; if (i>=MAX_SID_SAS_MAPPINGS) i=random()%MAX_SID_SAS_MAPPINGS;
if (i>=sid_sas_mapping_count) sid_sas_mapping_count=i+1; if (i>=sid_sas_mapping_count) sid_sas_mapping_count=i+1;
@ -1220,7 +1220,7 @@ unsigned char *keyring_find_sas_public(keyring_file *k,unsigned char *sid)
long long now=overlay_gettime_ms(); long long now=overlay_gettime_ms();
for(i=0;i<sid_sas_mapping_count;i++) for(i=0;i<sid_sas_mapping_count;i++)
{ {
if (bcmp(sid,sid_sas_mappings[i].sid,SID_SIZE)) continue; if (memcmp(sid,sid_sas_mappings[i].sid,SID_SIZE)) continue;
if (sid_sas_mappings[i].validP) return sid_sas_mappings[i].sas_public; if (sid_sas_mappings[i].validP) return sid_sas_mappings[i].sas_public;
/* Don't flood the network with mapping requests */ /* Don't flood the network with mapping requests */
if ((now-sid_sas_mappings[i].last_request_time_in_ms)<1000) return NULL; if ((now-sid_sas_mappings[i].last_request_time_in_ms)<1000) return NULL;
@ -1274,7 +1274,7 @@ int keyring_find_sid(keyring_file *k,int *cn,int *in,int *kp,unsigned char *sid)
if (k->contexts[*cn]->identities[*in]->keypairs[*kp]->type==KEYTYPE_CRYPTOBOX) if (k->contexts[*cn]->identities[*in]->keypairs[*kp]->type==KEYTYPE_CRYPTOBOX)
{ {
/* Compare SIDs */ /* Compare SIDs */
if (!bcmp(sid,(char *)k->contexts[*cn]->identities[*in] if (!memcmp(sid,(char *)k->contexts[*cn]->identities[*in]
->keypairs[*kp]->public_key,SID_SIZE)) ->keypairs[*kp]->public_key,SID_SIZE))
{ {
/* match */ /* match */
@ -1385,9 +1385,9 @@ unsigned char *keyring_get_nm_bytes(sockaddr_mdp *known,sockaddr_mdp *unknown)
/* See if we have it cached already */ /* See if we have it cached already */
for(i=0;i<nm_slots_used;i++) for(i=0;i<nm_slots_used;i++)
{ {
if (bcmp(nm_cache[i].known_key,known->sid, if (memcmp(nm_cache[i].known_key,known->sid,
crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES)) continue; crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES)) continue;
if (bcmp(nm_cache[i].unknown_key,unknown->sid, if (memcmp(nm_cache[i].unknown_key,unknown->sid,
crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES)) continue; crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES)) continue;
return nm_cache[i].nm_bytes; return nm_cache[i].nm_bytes;
} }

View File

@ -482,7 +482,7 @@ int overlay_abbreviate_cache_lookup(unsigned char *in,unsigned char *out,int *of
if (keyring->contexts[cn]->identities[id]->keypairs[kp]->type if (keyring->contexts[cn]->identities[id]->keypairs[kp]->type
==KEYTYPE_CRYPTOBOX) ==KEYTYPE_CRYPTOBOX)
{ {
if (!bcmp(in,keyring->contexts[cn]->identities[id] if (!memcmp(in,keyring->contexts[cn]->identities[id]
->keypairs[kp]->public_key,prefix_bytes)) ->keypairs[kp]->public_key,prefix_bytes))
{ {
if (debug&DEBUG_OVERLAYABBREVIATIONS) if (debug&DEBUG_OVERLAYABBREVIATIONS)