Exemplo n.º 1
0
bool check_prog(struct prog* prog, struct symtable *syms)
{
  bool correct = true;
  fill_std_types(syms);
  fill_std_fun(syms);
  constdecllist_t consts = prog->entry_point->const_decls;

  for(unsigned i =0; i < consts.size; ++i)
    correct = correct && check_const(list_nth(consts,i), syms, true);
  correct = correct && add_types(syms, prog->entry_point->type_decls);
  correct = correct && add_variables(syms, prog->entry_point->var_decl, true, false, false);
  for(unsigned i = 0; i < prog->algos.size; ++i)
  {
    struct algo* al = list_nth(prog->algos, i);
    struct function* f = malloc(sizeof(struct function));
    f->ident = al->ident;
    f->ret = find_type(syms->types, al->return_type);
    f->arg = get_args(al->declarations->param_decl, syms);
    add_function(syms->functions, f);
  }
  for (unsigned i = 0; i < prog->entry_point->instructions.size; ++i)
    if (!check_inst(
          prog->entry_point->instructions.data[i],
          find_type(syms->types, TYPE_INT), syms))
      correct = false;
  for(unsigned i = 0; i < prog->algos.size; ++i)
  {
    struct algo* al = list_nth(prog->algos, i);
    if (!check_algo(al, syms))
      correct = false;
  }
  return correct;
}
Exemplo n.º 2
0
static void
try_add_algo(const char *algo_name, algo_type *algos, 
		const char *algo_desc, algo_type * new_algos, int *num_ret)
{
	algo_type *match_algo = check_algo(algo_name, algos);
	if (!match_algo)
	{
		dropbear_log(LOG_WARNING, "This Dropbear program does not support '%s' %s algorithm", algo_name, algo_desc);
		return;
	}

	new_algos[*num_ret] = *match_algo;
	(*num_ret)++;
}
Exemplo n.º 3
0
const sensor_cal_algo_t* CalibrationManager::getCalAlgo(const sensor_t *s/* = NULL*/)
{
	uint32_t i = 0;
	int j = 0;
	const sensor_cal_algo_t **list = algo_list;
	const sensor_cal_algo_t *tmp = NULL;

	if (s == NULL) {
		ALOGW("No available algo found!");
		return NULL;
	}

	for (i = 0; i < algo_count; i++) {
		if ((list[i]->type != s->type) || check_algo(list[i]))
			continue;
		j = 0;
		while (list[i]->compatible[j] != NULL) {
			if (strcmp(list[i]->compatible[j], s->name) == 0)
				break;
			if (strcmp(list[i]->compatible[j], type_to_name(s->type)) == 0)
				tmp = list[i];
			j++;
		}

		/* Exactly compatible */
		if (list[i]->compatible[j] != NULL)
			break;
	}

	if (i != algo_count) {
		ALOGI("found exactly compatible algo for type %d", s->type);
		return list[i];
	}

	if (tmp != NULL)
		ALOGI("found compatible algo for type %d", s->type);

	return tmp;
}
Exemplo n.º 4
0
/**
 * cdk_pklist_select_algo:
 * @pkl: the keylist
 * @preftype: preference type
 *
 * Select a symmetric cipher algorithm from a list of public keys.
 * This algorithm is present in all key preferences.
 **/
int
cdk_pklist_select_algo( cdk_keylist_t pkl, int preftype )
{
    const struct cdk_prefitem_s * prefs;
    cdk_keylist_t pkr;
    u32 bits[8];
    int compr_hack = 0, any = 0;
    int i = 0, j = 0;

    if (!pkl)
        return -1;

    memset (bits, ~0, 8 * sizeof *bits);
    for (pkr = pkl; pkr; pkr = pkr->next) {
        u32 mask[8];
        if (preftype == CDK_PREFTYPE_SYM) {
            memset (mask, 0, 8 * sizeof *mask);
            mask[0] |= (1 << 2); /*3DES is implicitly there for everyone else*/
	}
        if (pkr->key.pk->uid)
            prefs = pkr->key.pk->uid->prefs;
        else
            prefs = pkr->key.pk->prefs;      
        any = 0;
        for (i = 0; prefs && prefs[i].type; i++) {
            if (prefs[i].type == preftype) {
                mask[prefs[i].value / 32] |= 1 << (prefs[i].value % 32);
                any = 1;
	    }
	}
        if ((!prefs || !any) && preftype == CDK_PREFTYPE_ZIP) {
            mask[0] |= 3; /* asume no_compression and old pgp */
            compr_hack = 1;
	}
        for (i = 0; i < 8; i++)
            bits[i] &= mask[i];
        /* Usable algorithms are now in bits:
           We now use the last key from pkl to select the algorithm we want
           to use. There are no preferences for the last key, we select the one
           corresponding to first set bit. */
        i = -1;
        any = 0;
        for (j = 0; prefs && prefs[j].type; j++) {
            if (prefs[j].type == preftype) {
                if ((bits[prefs[j].value / 32] & (1 << (prefs[j].value % 32))))
		{
                    if (check_algo (preftype, prefs[j].value)) {
                        any = 1;
                        i = prefs[j].value;
                        break;
		    }
		}
	    }
	}
        if (!prefs || !any) {
            for (j = 0; j < 256; j++)
                if ((bits[j / 32] & (1 << (j % 32)))) {
                    if (check_algo (preftype, j)) {
                        i = j;
                        break;
                    }
                }
	}
        if (compr_hack && !i) {
            /* selected no compression, but we should check whether
               algorithm 1 is also available (the ordering is not relevant
               in this case). */
            if (bits[0] & (1 << 1))
                i = 1; /* yep; we can use compression algo 1 */
	}
    }
    _cdk_log_debug ("selected algo %d from prefs\n", i);
    return i;
}