Beispiel #1
0
/* Measure the performance of a hashing primitive */
static void perf_hash(int id)
{
    NoiseHashState *hash;
    uint8_t data[BLOCK_SIZE];
    timestamp_t start, end;
    int count;
    double elapsed;

    if (noise_hashstate_new_by_id(&hash, id) != NOISE_ERROR_NONE)
        return;

    memset(data, 0xAA, sizeof(data));
    noise_hashstate_reset(hash);
    start = current_timestamp();
    for (count = 0; count < (MB_COUNT * BLOCKS_PER_MB); ++count)
        noise_hashstate_update(hash, data, sizeof(data));
    end = current_timestamp();

    elapsed = elapsed_to_seconds(start, end) / (double)MB_COUNT;
    printf("%-20s%8.2f          %8.2f\n",
           noise_id_to_name(NOISE_HASH_CATEGORY, id),
           1.0 / elapsed, units / elapsed);

    noise_hashstate_free(hash);
}
Beispiel #2
0
/**
 * \brief Frees a SymmetricState object after destroying all sensitive material.
 *
 * \param state The SymmetricState object to free.
 *
 * \return NOISE_ERROR_NONE on success.
 * \return NOISE_ERROR_INVALID_PARAM if \a state is NULL.
 *
 * \sa noise_symmetricstate_new_by_id(), noise_symmetricstate_new_by_name()
 */
int noise_symmetricstate_free(NoiseSymmetricState *state)
{
    /* Bail out if no symmetric state */
    if (!state)
        return NOISE_ERROR_INVALID_PARAM;

    /* Free the sub objects that are hanging off the symmetricstate */
    if (state->cipher)
        noise_cipherstate_free(state->cipher);
    if (state->hash)
        noise_hashstate_free(state->hash);

    /* Clean and free the memory for "state" */
    noise_free(state, state->size);
    return NOISE_ERROR_NONE;
}