Exemple #1
0
int OTPCalculator_Init (OTPCalculator *calc, int num_otps, int cipher)
{
    ASSERT(num_otps >= 0)
    ASSERT(BEncryption_cipher_valid(cipher))
    
    // init arguments
    calc->num_otps = num_otps;
    calc->cipher = cipher;
    
    // remember block size
    calc->block_size = BEncryption_cipher_block_size(calc->cipher);
    
    // calculate number of blocks
    if (calc->num_otps > SIZE_MAX / sizeof(otp_t)) {
        goto fail0;
    }
    calc->num_blocks = bdivide_up(calc->num_otps * sizeof(otp_t), calc->block_size);
    
    // allocate buffer
    if (!(calc->data = (otp_t *)BAllocArray(calc->num_blocks, calc->block_size))) {
        goto fail0;
    }
    
    // init debug object
    DebugObject_Init(&calc->d_obj);
    
    return 1;
    
fail0:
    return 0;
}
Exemple #2
0
void OTPGenerator_SetSeed (OTPGenerator *g, uint8_t *key, uint8_t *iv)
{
    DebugObject_Access(&g->d_obj);

    // free existing work
    if (g->tw_have) {
        BThreadWork_Free(&g->tw);
    }

    // copy key and IV
    memcpy(g->tw_key, key, BEncryption_cipher_key_size(g->cipher));
    memcpy(g->tw_iv, iv, BEncryption_cipher_block_size(g->cipher));

    // start work
    BThreadWork_Init(&g->tw, g->twd, (BThreadWork_handler_done)work_done_handler, g, (BThreadWork_work_func)work_func, g);

    // set have work
    g->tw_have = 1;
}
Exemple #3
0
void OTPChecker_AddSeed (OTPChecker *mc, uint16_t seed_id, uint8_t *key, uint8_t *iv)
{
    ASSERT(mc->next_table >= 0)
    ASSERT(mc->next_table < mc->num_tables)
    DebugObject_Access(&mc->d_obj);
    
    // free existing work
    if (mc->tw_have) {
        BThreadWork_Free(&mc->tw);
    }
    
    // set table's seed ID
    mc->tables[mc->next_table].id = seed_id;
    
    // copy key and IV
    memcpy(mc->tw_key, key, BEncryption_cipher_key_size(mc->cipher));
    memcpy(mc->tw_iv, iv, BEncryption_cipher_block_size(mc->cipher));
    
    // start work
    BThreadWork_Init(&mc->tw, mc->twd, (BThreadWork_handler_done)work_done_handler, mc, (BThreadWork_work_func)work_func, mc);
    
    // set have work
    mc->tw_have = 1;
}