Exemple #1
0
/*
 * storage_reset_uuid() - Reset configuration uuid in RAM with random numbers
 *
 * INPUT
 *     none
 * OUTPUT
 *     none
 *
 */
void storage_reset_uuid(void)
{
    // set random uuid
    random_buffer(shadow_config.meta.uuid, sizeof(shadow_config.meta.uuid));
    data2hex(shadow_config.meta.uuid, sizeof(shadow_config.meta.uuid),
             shadow_config.meta.uuid_str);
}
Exemple #2
0
const char *mnemonic_generate(int strength)
{
	if (strength % 32 || strength < 128 || strength > 256) {
		return 0;
	}
	static uint8_t data[32];
	random_buffer(data, 32);
	return mnemonic_from_data(data, strength / 8);
}
Exemple #3
0
const uint16_t *mnemonic_generate_indexes(int strength)
{
	if (strength % 32 || strength < 128 || strength > 256) {
		return 0;
	}
	uint8_t data[32];
	random_buffer(data, 32);
	return mnemonic_from_data_indexes(data, strength / 8);
}
Exemple #4
0
void reset_init(bool display_random, uint32_t _strength, bool passphrase_protection,
                bool pin_protection, const char *language, const char *label)
{
    if(_strength != 128 && _strength != 192 && _strength != 256)
    {
        fsm_sendFailure(FailureType_Failure_SyntaxError,
                        "Invalid strength (has to be 128, 192 or 256 bits)");
        go_home();
        return;
    }

    strength = _strength;

    random_buffer(int_entropy, 32);

    char ent_str[4][17];
    data2hex(int_entropy     , 8, ent_str[0]);
    data2hex(int_entropy +  8, 8, ent_str[1]);
    data2hex(int_entropy + 16, 8, ent_str[2]);
    data2hex(int_entropy + 24, 8, ent_str[3]);

    if(display_random)
    {
        if(!confirm(ButtonRequestType_ButtonRequest_ResetDevice,
                    "Internal Entropy", "%s %s %s %s", ent_str[0], ent_str[1], ent_str[2], ent_str[3]))
        {
            fsm_sendFailure(FailureType_Failure_ActionCancelled, "Reset cancelled");
            go_home();
            return;
        }
    }

    if(pin_protection && !change_pin())
    {
        go_home();
        return;
    }

    storage_set_passphrase_protected(passphrase_protection);
    storage_set_language(language);
    storage_set_label(label);

    EntropyRequest resp;
    memset(&resp, 0, sizeof(EntropyRequest));
    msg_write(MessageType_MessageType_EntropyRequest, &resp);
    awaiting_entropy = true;
}
Exemple #5
0
void random_buffer_(char* buffer, int size)
  /*@ requires [?f]world(?pub, ?key_clsfy) &*&
               proof_obligations(pub) &*&
               chars(buffer, size, _) &*&
               principal(?principal, ?count) &*&
               true == bad(principal); @*/
  /*@ ensures  [f]world(pub, key_clsfy) &*&
               proof_obligations(pub) &*&
               chars(buffer, size, _) &*&
               principal(principal, count + 1); @*/
{
  //@ open proof_obligations(pub);
  //@ assert is_public_nonce(?proof, _);
  //@ proof(nonce_item(principal, count + 1, 0));
  random_buffer(buffer, size);
  //@ close proof_obligations(pub);
}
Exemple #6
0
void fsm_msgGetEntropy(GetEntropy *msg)
{
	layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", "send entropy?", NULL, NULL, NULL, NULL);
	if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) {
		fsm_sendFailure(FailureType_Failure_ActionCancelled, "Entropy cancelled");
		layoutHome();
		return;
	}
	RESP_INIT(Entropy);
	uint32_t len = msg->size;
	if (len > 1024) {
		len = 1024;
	}
	resp->entropy.size = len;
	random_buffer(resp->entropy.bytes, len);
	msg_write(MessageType_MessageType_Entropy, resp);
	layoutHome();
}
void stress_check(struct proto *proto)
{
    struct timeval now;
    timeval_set_now(&now);
    log_set_level(LOG_ERR, NULL);
    srand(time(NULL));

    struct parser *parser = proto->ops->parser_new(proto);
    assert(parser);

    for (unsigned nb_tests = 0; nb_tests < 10000 ; nb_tests ++) {
        size_t size;
        uint8_t *buf = random_buffer(&size, 20, 60);
        parser->proto->ops->parse(parser, NULL, rand()%1, buf, size, size, &now, size, buf);
        free(buf);
    }

    parser_unref(&parser);
}
Exemple #8
0
void reset_init(bool display_random, uint32_t _strength, bool passphrase_protection, bool pin_protection, const char *language, const char *label)
{
    if (_strength != 128 && _strength != 192 && _strength != 256) {
        fsm_sendFailure(FailureType_Failure_SyntaxError, "Invalid strength (has to be 128, 192 or 256 bits)");
        layoutHome();
        return;
    }

    strength = _strength;

    random_buffer(int_entropy, 32);

    char ent_str[4][17];
    data2hex(int_entropy     , 8, ent_str[0]);
    data2hex(int_entropy +  8, 8, ent_str[1]);
    data2hex(int_entropy + 16, 8, ent_str[2]);
    data2hex(int_entropy + 24, 8, ent_str[3]);

    if (display_random) {
        layoutDialogSwipe(DIALOG_ICON_INFO, "Cancel", "Continue", NULL, "Internal entropy:", ent_str[0], ent_str[1], ent_str[2], ent_str[3], NULL);
        if (!protectButton(ButtonRequestType_ButtonRequest_ResetDevice, false)) {
            fsm_sendFailure(FailureType_Failure_ActionCancelled, "Reset cancelled");
            layoutHome();
            return;
        }
    }

    if (pin_protection && !protectChangePin()) {
        fsm_sendFailure(FailureType_Failure_ActionCancelled, "PIN change failed");
        layoutHome();
        return;
    }

    storage.has_passphrase_protection = true;
    storage.passphrase_protection = passphrase_protection;
    storage_setLanguage(language);
    storage_setLabel(label);

    EntropyRequest resp;
    memset(&resp, 0, sizeof(EntropyRequest));
    msg_write(MessageType_MessageType_EntropyRequest, &resp);
    awaiting_entropy = true;
}
Exemple #9
0
void fsm_msgGetEntropy(GetEntropy *msg)
{
    if(!confirm(ButtonRequestType_ButtonRequest_GetEntropy,
                "Generate Entropy",
                "Do you want to generate and return entropy using the hardware RNG?"))
    {
        fsm_sendFailure(FailureType_Failure_ActionCancelled, "Entropy cancelled");
        go_home();
        return;
    }

    RESP_INIT(Entropy);
    uint32_t len = msg->size;

    if(len > ENTROPY_BUF)
    {
        len = ENTROPY_BUF;
    }

    resp->entropy.size = len;
    random_buffer(resp->entropy.bytes, len);
    msg_write(MessageType_MessageType_Entropy, resp);
    go_home();
}
Exemple #10
0
void storage_reset_uuid(void)
{
	// set random uuid
	random_buffer(storage_uuid, sizeof(storage_uuid));
	data2hex(storage_uuid, sizeof(storage_uuid), storage_uuid_str);
}