void load_rsa_key_blob(rsa_ctx_t* ctx){
	if(ctx->modulus.wordv){
		free(ctx->modulus.wordv);
	}
	ctx->modulus.wordv = malloc(ALL_LEN_B);
	if(ctx->modulus.wordv==NULL){
		cli_putstr_P(PSTR("\r\nERROR: OUT OF MEMORY!!!"));
		return;
	}
	ctx->modulus.info = ctx->privexp.info = ctx->pubexp.info = 0;
	memcpy_P(ctx->modulus.wordv, rsa_key_blob, ALL_LEN_B);
	ctx->modulus.length_B=N_LEN_B;
	ctx->pubexp.wordv = ctx->modulus.wordv+N_LEN_B;
	ctx->pubexp.length_B = E_LEN_B;
	ctx->privexp.wordv = ctx->pubexp.wordv+E_LEN_B;
	ctx->privexp.length_B = D_LEN_B;

	bigint_changeendianess(&(ctx->modulus));
	bigint_changeendianess(&(ctx->pubexp));
	bigint_changeendianess(&(ctx->privexp));

	bigint_adjust(&(ctx->modulus));
	bigint_adjust(&(ctx->pubexp));
	bigint_adjust(&(ctx->privexp));
}
uint8_t read_bigint(bigint_t *a, char *prompt){
	uint16_t read_length, actual_length;
	uint8_t off;
	uint8_t *buffer;
	char read_int_str[18];
	cli_putstr(prompt);
	cli_putstr_P(PSTR("\r\n  length: "));
	cli_getsn(read_int_str, 16);
	read_length = own_atou(read_int_str);
	off = (sizeof(bigint_word_t) - (read_length % sizeof(bigint_word_t))) % sizeof(bigint_word_t);
	buffer = malloc(((read_length + sizeof(bigint_word_t) - 1) / sizeof(bigint_word_t)) * sizeof(bigint_word_t));
	if(!buffer){
		cli_putstr_P(PSTR("\r\nERROR: OOM!"));
		return 2;
	}
	cli_putstr_P(PSTR("\r\n  data: "));
	memset(buffer, 0, sizeof(bigint_word_t));
	actual_length = read_os(buffer + off, read_length, NULL);
	if(actual_length != read_length){
		cli_putstr_P(PSTR("\r\nERROR: unexpected end of data!"));
		free(buffer);
		return 1;
	}
	a->wordv = (bigint_word_t*)buffer;
	a->length_W = (read_length + sizeof(bigint_word_t) - 1) / sizeof(bigint_word_t);
	a->info = 0;
	bigint_changeendianess(a);
	bigint_adjust(a);
	return 0;
}
Example #3
0
uint8_t dsa_verify_message(const dsa_signature_t* s, const void* m, uint16_t m_len_b,
                           const hfdesc_t* hash_desc, const dsa_ctx_t* ctx) {
    bigint_t z;
    uint8_t n_B = ctx->domain.q.length_B;
    uint8_t hash_value[(hfal_hash_getHashsize(hash_desc)+7)/8];
    hfal_hash_mem(hash_desc, hash_value, m, m_len_b);
    z.wordv=hash_value;
    z.length_B=n_B;
    bigint_changeendianess(&z);
    bigint_adjust(&z);
    return dsa_verify_bigint(s, &z, ctx);
}
uint8_t load_bigint_from_os(bigint_t *a, PGM_VOID_P os, uint16_t length_B){
	a->length_W = BIGINT_CEIL(length_B) / sizeof(bigint_word_t);
	a->wordv = malloc(BIGINT_CEIL(length_B));
	if(!a->wordv){
		cli_putstr_P(PSTR("\r\nOOM!\r\n"));
		return 1;
	}
	memset(a->wordv, 0, sizeof(bigint_word_t));
	memcpy_P((uint8_t*)a->wordv + BIGINT_OFF(length_B), os, length_B);
	a->info = 0;
	bigint_changeendianess(a);
	bigint_adjust(a);
	return 0;
}