Esempio n. 1
0
/**
 * Expand the AES key into a Python (byte) string object.
 */ 
EXPORT_SYM int ghash_expand(const uint8_t h[16], t_exp_key **ghash_tables)
{
    t_exp_key *exp_key;

    if (NULL==h || NULL==ghash_tables)
        return ERR_NULL;

    *ghash_tables = exp_key = calloc(1, sizeof(t_exp_key));
    if (NULL == exp_key)
        return ERR_MEMORY;
    
    exp_key->offset = ALIGNMENT - ((uintptr_t)exp_key->buffer & (ALIGNMENT-1));
    make_v_tables(h, (t_v_tables*)(exp_key->buffer + exp_key->offset));
    
    return 0;
}
Esempio n. 2
0
/**
 * Expand a hash key into a set of tables that will speed
 * up GHASH.
 *
 * \param tables    Pointer to allocated memory that will hold
 *                  the tables.
 * \param h         The hash key.
 */
static int ghash_expand(t_key_tables *key_tables, const uint8_t h[16])
{
    int i;
    const t_v_tables *v_tables;

    v_tables = make_v_tables(h);
    if (v_tables==NULL) {
        return -1;
    }

    for (i=0; i<16; i++) {
        int j;

        for (j=0; j<256; j++) {
            /** Z = H*j*P^{8i} **/
            gcm_mult3(&((*key_tables)[i][j][0]), j, i, v_tables);
        }
    }

    free(v_tables);
    return 0;
}