コード例 #1
0
ファイル: test_randlib.c プロジェクト: AlessandroA/mbed
bool test_randLIB_get_n_bytes_random()
{
    int8_t ret = randLIB_get_n_bytes_random(NULL, 0);
    if( ret != -1){
        return false;
    }

    uint8_t dat[5];
    ret = randLIB_get_n_bytes_random(&dat, 5);
    if( ret != 0){
        return false;
    }
    return true;
}
コード例 #2
0
ファイル: sec_prot_lib.c プロジェクト: donatieng/mbed
/*
 * From IEEE 802.11 how to init nonce calculation by using non-secure random
 *
 * PRF-256(Random number, “Init Counter”, Local MAC Address || Time)
 */
void sec_prot_lib_nonce_init(uint8_t *nonce, uint8_t *eui64, uint64_t time)
{
    // For now, use randlib
    uint8_t random[EAPOL_KEY_NONCE_LEN];
    randLIB_get_n_bytes_random(random, EAPOL_KEY_NONCE_LEN);

    const uint8_t a_string_val[] = {"Init Counter"};
    const uint8_t a_string_val_len = sizeof(a_string_val) - 1;

    ieee_802_11_prf_t prf;

    uint16_t string_len = ieee_802_11_prf_setup(&prf, EAPOL_KEY_NONCE_LEN * 8, a_string_val_len, EUI64_LEN + EUI64_LEN);
    uint8_t string[string_len];

    uint8_t *a_string = ieee_802_11_prf_get_a_string(&prf, string);
    memcpy(a_string, a_string_val, a_string_val_len);

    uint8_t *b_string = ieee_802_11_prf_get_b_string(&prf, string);
    memcpy(b_string, eui64, EUI64_LEN);
    b_string += EUI64_LEN;
    memcpy(b_string, &time, sizeof(uint64_t));

    uint16_t result_len = ieee_802_11_prf_starts(&prf, random, EAPOL_KEY_NONCE_LEN);

    ieee_802_11_prf_update(&prf, string);

    uint8_t result[result_len];

    ieee_802_11_prf_finish(&prf, result);

    memcpy(nonce, result, EAPOL_KEY_NONCE_LEN);
}
コード例 #3
0
ファイル: pana.c プロジェクト: MarceloSalazar/mbed-os
pana_heap_t *pana_heap_structure_allocate(void)
{
    pana_heap_t *heap = ns_dyn_mem_temporary_alloc(sizeof(pana_heap_t));
    if (heap) {
        heap->handshake_len = 0;
        heap->handshake_req_offset = 0;
        randLIB_get_n_bytes_random(heap->client_nonce, 16);
    }
    return heap;
}
コード例 #4
0
ファイル: sec_prot_lib.c プロジェクト: donatieng/mbed
/*
 * IEEE 802.11 advises using sequential nonces, but should this be
 * randlib?
 */
void sec_prot_lib_nonce_generate(uint8_t *nonce)
{
    // For now, use randlib
    randLIB_get_n_bytes_random(nonce, EAPOL_KEY_NONCE_LEN);

#if 0
    for (int i = 31; i >= 0; i--) {
        if (++nonce[i] != 0) {
            break;
        }
    }
#endif
}
コード例 #5
0
ファイル: thread_discovery.c プロジェクト: betzw/mbed
static thread_discovery_request_info_t * thread_discovery_request_allocate(thread_discover_reques_t *scan_request, thread_discovery_ready_cb *response_cb)
{
    thread_discovery_request_info_t * discover_request = ns_dyn_mem_temporary_alloc(sizeof(thread_discovery_request_info_t) + scan_request->filter_tlv_length);
    if (discover_request) {
        discover_request->waiting_response = false;
        discover_request->active_timer = 0;
        discover_request->channel_mask = scan_request->channel_mask;
        discover_request->joiner_flag = scan_request->joiner_flag;
        discover_request->native_commisioner_scan = scan_request->native_commisioner;
        discover_request->filter_tlv_length = scan_request->filter_tlv_length;
        discover_request->random_panid = randLIB_get_random_in_range(1, 0xfffd); //Generate random pan-id
        randLIB_get_n_bytes_random(discover_request->temporary_mac64, 8); //Generate random temporary mac64

        discover_request->response_cb = response_cb;
        if (discover_request->filter_tlv_length) {
            memcpy(discover_optional_start_pointer(discover_request), scan_request->filter_tlv_data, discover_request->filter_tlv_length);
        }
    }
    return discover_request;
}