SilcUInt32 dest_data_size,
SilcUInt32 *dest_len)
{
- int i = 0;
+ SilcUInt32 i = 0;
SILC_LOG_DEBUG(("PKCS#1 decoding, bt %d", bt));
}
/* Sanity checks */
+ if (i >= data_len) {
+ SILC_LOG_DEBUG(("Malformed block, too short message"));
+ return FALSE;
+ }
+ if (i < SILC_PKCS1_MIN_PADDING) {
+ SILC_LOG_DEBUG(("Malformed block, too short padding"));
+ return FALSE;
+ }
if (data[i++] != 0x00) {
SILC_LOG_DEBUG(("Malformed block"));
return FALSE;
}
- if (i - 1 < SILC_PKCS1_MIN_PADDING) {
- SILC_LOG_DEBUG(("Malformed block"));
+ if (i >= data_len) {
+ SILC_LOG_DEBUG(("Malformed block, too short message"));
return FALSE;
}
if (dest_data_size < data_len - i) {
silc_mp_uninit(&key->n);
silc_mp_uninit(&key->e);
+ silc_hash_free(key->hash);
silc_free(key);
}
silc_mp_uninit(&key->qP);
silc_mp_uninit(&key->p);
silc_mp_uninit(&key->q);
+ silc_hash_free(key->hash);
silc_free(key);
}
/* Compute hash */
if (compute_hash) {
+ if (!hash)
+ hash = key->hash;
silc_hash_make(hash, src, src_len, hashr);
src = hashr;
src_len = silc_hash_len(hash);
silc_buffer_set(&di, unpadded, len);
/* If hash isn't given, allocate the one given in digest info */
- if (!hash) {
- has_null = FALSE;
+ if (compute_hash) {
+ if (!hash) {
+ has_null = FALSE;
- /* Decode digest info */
- if (!silc_asn1_decode(asn1, &di,
- SILC_ASN1_OPTS(SILC_ASN1_ACCUMUL),
- SILC_ASN1_SEQUENCE,
+ /* Decode digest info */
+ if (!silc_asn1_decode(asn1, &di,
+ SILC_ASN1_OPTS(SILC_ASN1_ACCUMUL),
SILC_ASN1_SEQUENCE,
- SILC_ASN1_OID(&oid),
- SILC_ASN1_NULL_T(SILC_ASN1_OPTIONAL,
- SILC_ASN1_TAG_NULL, &has_null),
- SILC_ASN1_END,
- SILC_ASN1_END, SILC_ASN1_END))
- goto err;
-
- if (!silc_hash_alloc_by_oid(oid, &ihash)) {
- SILC_LOG_DEBUG(("Unknown OID %s", oid));
- goto err;
+ SILC_ASN1_SEQUENCE,
+ SILC_ASN1_OID(&oid),
+ SILC_ASN1_NULL_T(SILC_ASN1_OPTIONAL,
+ SILC_ASN1_TAG_NULL, &has_null),
+ SILC_ASN1_END,
+ SILC_ASN1_END, SILC_ASN1_END))
+ goto err;
+
+ if (!silc_hash_alloc_by_oid(oid, &ihash)) {
+ SILC_LOG_DEBUG(("Unknown OID %s", oid));
+ goto err;
+ }
+ hash = ihash;
}
- hash = ihash;
- }
- /* Hash the data */
- silc_hash_make(hash, data, data_len, hashr);
- data = hashr;
- data_len = silc_hash_len(hash);
- oid = (char *)silc_hash_get_oid(hash);
+ /* Hash the data */
+ silc_hash_make(hash, data, data_len, hashr);
+ data = hashr;
+ data_len = silc_hash_len(hash);
+ oid = (char *)silc_hash_get_oid(hash);
+ }
/* Encode digest info for comparison */
memset(&ldi, 0, sizeof(ldi));
silc_free(verify);
silc_mp_uninit(&mp_tmp2);
silc_mp_uninit(&mp_dst);
- if (hash)
+ if (compute_hash)
memset(hashr, 0, sizeof(hashr));
if (ihash)
silc_hash_free(ihash);
/* Compute hash if requested */
if (compute_hash) {
+ if (!hash)
+ hash = key->hash;
silc_hash_make(hash, src, src_len, hashr);
src = hashr;
src_len = silc_hash_len(hash);
}
/* Hash data if requested */
- if (hash) {
+ if (compute_hash) {
+ if (!hash)
+ hash = key->hash;
silc_hash_make(hash, data, data_len, hashr);
data = hashr;
data_len = silc_hash_len(hash);
memset(verify, 0, verify_len);
memset(unpadded, 0, sizeof(unpadded));
- if (hash)
+ if (compute_hash)
memset(hashr, 0, sizeof(hashr));
silc_free(verify);
silc_mp_uninit(&mp_tmp2);