mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-14 08:59:50 -05:00
removed a few asserts
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-OpenPGP@5234 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
b603ef9d9f
commit
d825508836
@ -311,7 +311,7 @@ static ops_boolean_t rsa_verify(ops_hash_algorithm_t type,
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr,"Warning: unhandled hash type in signature verification code: %d\n",type) ;
|
fprintf(stderr,"Warning: unhandled hash type in signature verification code: %d\n",type) ;
|
||||||
assert(0); break;
|
return ops_false ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(keysize-plen-hash_length < 10)
|
if(keysize-plen-hash_length < 10)
|
||||||
@ -415,35 +415,37 @@ static void hash_add_trailer(ops_hash_t *hash, const ops_signature_t *sig,
|
|||||||
ops_boolean_t ops_check_signature(const unsigned char *hash, unsigned length,
|
ops_boolean_t ops_check_signature(const unsigned char *hash, unsigned length,
|
||||||
const ops_signature_t *sig,
|
const ops_signature_t *sig,
|
||||||
const ops_public_key_t *signer)
|
const ops_public_key_t *signer)
|
||||||
{
|
{
|
||||||
ops_boolean_t ret;
|
ops_boolean_t ret;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
printf(" hash=");
|
printf(" hash=");
|
||||||
// hashout[0]=0;
|
// hashout[0]=0;
|
||||||
hexdump(hash,length);
|
hexdump(hash,length);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
switch(sig->info.key_algorithm)
|
switch(sig->info.key_algorithm)
|
||||||
{
|
{
|
||||||
case OPS_PKA_DSA:
|
case OPS_PKA_DSA:
|
||||||
ret=ops_dsa_verify(hash, length, &sig->info.signature.dsa,
|
ret=ops_dsa_verify(hash, length, &sig->info.signature.dsa,
|
||||||
&signer->key.dsa);
|
&signer->key.dsa);
|
||||||
/* fprintf(stderr,"Cannot verify DSA signature. skipping.\n") ;
|
/* fprintf(stderr,"Cannot verify DSA signature. skipping.\n") ;
|
||||||
ret = ops_false ; */
|
ret = ops_false ; */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OPS_PKA_RSA:
|
case OPS_PKA_RSA:
|
||||||
ret=rsa_verify(sig->info.hash_algorithm, hash, length,
|
ret=rsa_verify(sig->info.hash_algorithm, hash, length,
|
||||||
&sig->info.signature.rsa, &signer->key.rsa);
|
&sig->info.signature.rsa, &signer->key.rsa);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
fprintf(stderr,"Cannot verify signature. Unknown key signing algorithm %d. skipping.\n",sig->info.key_algorithm) ;
|
||||||
|
ret = ops_false ;
|
||||||
|
|
||||||
default:
|
|
||||||
assert(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ops_boolean_t hash_and_check_signature(ops_hash_t *hash,
|
static ops_boolean_t hash_and_check_signature(ops_hash_t *hash,
|
||||||
const ops_signature_t *sig,
|
const ops_signature_t *sig,
|
||||||
@ -770,87 +772,87 @@ ops_boolean_t ops_write_signature(ops_create_signature_t *sig,
|
|||||||
const ops_public_key_t *key,
|
const ops_public_key_t *key,
|
||||||
const ops_secret_key_t *skey,
|
const ops_secret_key_t *skey,
|
||||||
ops_create_info_t *info)
|
ops_create_info_t *info)
|
||||||
{
|
{
|
||||||
ops_boolean_t rtn=ops_false;
|
ops_boolean_t rtn=ops_false;
|
||||||
size_t l=ops_memory_get_length(sig->mem);
|
size_t l=ops_memory_get_length(sig->mem);
|
||||||
|
|
||||||
// check key not decrypted
|
// check key not decrypted
|
||||||
switch (skey->public_key.algorithm)
|
switch (skey->public_key.algorithm)
|
||||||
{
|
{
|
||||||
case OPS_PKA_RSA:
|
case OPS_PKA_RSA:
|
||||||
case OPS_PKA_RSA_ENCRYPT_ONLY:
|
case OPS_PKA_RSA_ENCRYPT_ONLY:
|
||||||
case OPS_PKA_RSA_SIGN_ONLY:
|
case OPS_PKA_RSA_SIGN_ONLY:
|
||||||
assert(skey->key.rsa.d);
|
assert(skey->key.rsa.d);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OPS_PKA_DSA:
|
case OPS_PKA_DSA:
|
||||||
assert(skey->key.dsa.x);
|
assert(skey->key.dsa.x);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Unsupported algorithm %d\n",
|
fprintf(stderr, "Unsupported algorithm %d\n",
|
||||||
skey->public_key.algorithm);
|
skey->public_key.algorithm);
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(sig->hashed_data_length != (unsigned)-1);
|
assert(sig->hashed_data_length != (unsigned)-1);
|
||||||
|
|
||||||
ops_memory_place_int(sig->mem, sig->unhashed_count_offset,
|
ops_memory_place_int(sig->mem, sig->unhashed_count_offset,
|
||||||
l-sig->unhashed_count_offset-2, 2);
|
l-sig->unhashed_count_offset-2, 2);
|
||||||
|
|
||||||
// add the packet from version number to end of hashed subpackets
|
// add the packet from version number to end of hashed subpackets
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
{ fprintf(stderr, "--- Adding packet to hash from version number to"
|
{ fprintf(stderr, "--- Adding packet to hash from version number to"
|
||||||
" hashed subpkts\n"); }
|
" hashed subpkts\n"); }
|
||||||
|
|
||||||
sig->hash.add(&sig->hash, ops_memory_get_data(sig->mem),
|
sig->hash.add(&sig->hash, ops_memory_get_data(sig->mem),
|
||||||
sig->unhashed_count_offset);
|
sig->unhashed_count_offset);
|
||||||
|
|
||||||
// add final trailer
|
// add final trailer
|
||||||
ops_hash_add_int(&sig->hash, sig->sig.info.version, 1);
|
ops_hash_add_int(&sig->hash, sig->sig.info.version, 1);
|
||||||
ops_hash_add_int(&sig->hash, 0xff, 1);
|
ops_hash_add_int(&sig->hash, 0xff, 1);
|
||||||
// +6 for version, type, pk alg, hash alg, hashed subpacket length
|
// +6 for version, type, pk alg, hash alg, hashed subpacket length
|
||||||
ops_hash_add_int(&sig->hash, sig->hashed_data_length+6, 4);
|
ops_hash_add_int(&sig->hash, sig->hashed_data_length+6, 4);
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
{ fprintf(stderr, "--- Finished adding packet to hash from version"
|
{ fprintf(stderr, "--- Finished adding packet to hash from version"
|
||||||
" number to hashed subpkts\n"); }
|
" number to hashed subpkts\n"); }
|
||||||
|
|
||||||
// XXX: technically, we could figure out how big the signature is
|
// XXX: technically, we could figure out how big the signature is
|
||||||
// and write it directly to the output instead of via memory.
|
// and write it directly to the output instead of via memory.
|
||||||
switch(skey->public_key.algorithm)
|
switch(skey->public_key.algorithm)
|
||||||
{
|
{
|
||||||
case OPS_PKA_RSA:
|
case OPS_PKA_RSA:
|
||||||
case OPS_PKA_RSA_ENCRYPT_ONLY:
|
case OPS_PKA_RSA_ENCRYPT_ONLY:
|
||||||
case OPS_PKA_RSA_SIGN_ONLY:
|
case OPS_PKA_RSA_SIGN_ONLY:
|
||||||
rsa_sign(&sig->hash, &key->key.rsa, &skey->key.rsa, sig->info);
|
rsa_sign(&sig->hash, &key->key.rsa, &skey->key.rsa, sig->info);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OPS_PKA_DSA:
|
case OPS_PKA_DSA:
|
||||||
dsa_sign(&sig->hash, &key->key.dsa, &skey->key.dsa, sig->info);
|
dsa_sign(&sig->hash, &key->key.dsa, &skey->key.dsa, sig->info);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Unsupported algorithm %d\n",
|
fprintf(stderr, "Unsupported algorithm %d\n",
|
||||||
skey->public_key.algorithm);
|
skey->public_key.algorithm);
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
rtn=ops_write_ptag(OPS_PTAG_CT_SIGNATURE, info);
|
rtn=ops_write_ptag(OPS_PTAG_CT_SIGNATURE, info);
|
||||||
if (rtn)
|
if (rtn)
|
||||||
{
|
{
|
||||||
l=ops_memory_get_length(sig->mem);
|
l=ops_memory_get_length(sig->mem);
|
||||||
rtn = ops_write_length(l, info)
|
rtn = ops_write_length(l, info)
|
||||||
&& ops_write(ops_memory_get_data(sig->mem), l, info);
|
&& ops_write(ops_memory_get_data(sig->mem), l, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
ops_memory_free(sig->mem);
|
ops_memory_free(sig->mem);
|
||||||
|
|
||||||
if (!rtn)
|
if (!rtn)
|
||||||
OPS_ERROR(&info->errors, OPS_E_W, "Cannot write signature");
|
OPS_ERROR(&info->errors, OPS_E_W, "Cannot write signature");
|
||||||
return rtn;
|
return rtn;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \ingroup Core_Signature
|
* \ingroup Core_Signature
|
||||||
|
Loading…
Reference in New Issue
Block a user