static void mac_bench(int algo, int size) { void *_key; int blocksize = gnutls_hmac_get_len(algo); int step = size * 1024; struct benchmark_st st; _key = malloc(blocksize); if (_key == NULL) return; memset(_key, 0xf0, blocksize); printf("%16s ", gnutls_mac_get_name(algo)); fflush(stdout); start_benchmark(&st); do { gnutls_hmac_fast(algo, _key, blocksize, data, step, _key); st.size += step; } while (benchmark_must_finish == 0); stop_benchmark(&st, NULL, 1); free(_key); }
static void dcrypt_gnutls_ctx_hmac_set_key(struct dcrypt_context_hmac *ctx, const unsigned char *key, size_t key_len) { if(ctx->key.data != NULL) p_free(ctx->pool, ctx->key.data); ctx->key.size = I_MIN(key_len,(size_t)gnutls_hmac_get_len(ctx->md)); ctx->key.data = p_malloc(ctx->pool, ctx->key.size); memcpy(ctx->key.data, key, ctx->key.size); }
_public_ size_t dnssec_tsig_size(dnssec_tsig_ctx_t *ctx) { if (!ctx) { return 0; } return gnutls_hmac_get_len(ctx->algorithm); }
static int dcrypt_gnutls_ctx_hmac_final(struct dcrypt_context_hmac *ctx, buffer_t *result, const char **error_r) { size_t hlen = gnutls_hmac_get_len(ctx->md); unsigned char buf[hlen]; gnutls_hmac_output(ctx->ctx, buf); buffer_append(result, buf, hlen); return 0; }
static void mac_bench (int algo, int size) { void *_key; struct timespec start, stop; double secs; double data_size = 0; double ddata, dspeed; int blocksize = gnutls_hmac_get_len (algo); char metric[16]; _key = malloc (blocksize); if (_key == NULL) return; memset (_key, 0xf0, blocksize); printf ("Checking %s (%dkb payload)... ", gnutls_mac_get_name (algo), size); fflush (stdout); must_finish = 0; alarm (5); gettime (&start); do { gnutls_hmac_fast (algo, _key, blocksize, data, size * 1024, _key); data_size += size * 1024; } while (must_finish == 0); gettime (&stop); secs = (stop.tv_sec * 1000 + stop.tv_nsec / (1000 * 1000) - (start.tv_sec * 1000 + start.tv_nsec / (1000 * 1000))); secs /= 1000; value2human (data_size, secs, &ddata, &dspeed, metric); printf ("Hashed %.2f %s in %.2f secs: ", ddata, metric, secs); printf ("%.2f %s/sec\n", dspeed, metric); free (_key); }
static void mac_bench(int algo, int size) { void *_key; int blocksize = gnutls_hmac_get_len(algo); int step = size * 1024; struct benchmark_st st; void *input; unsigned char c, *i; ALLOCM(input, MAX_MEM); i = input; _key = malloc(blocksize); if (_key == NULL) return; memset(_key, 0xf0, blocksize); printf("%16s ", gnutls_mac_get_name(algo)); fflush(stdout); assert(gnutls_rnd(GNUTLS_RND_NONCE, &c, 1) >= 0); start_benchmark(&st); do { gnutls_hmac_fast(algo, _key, blocksize, i, step, _key); st.size += step; INC(input, i, step); } while (benchmark_must_finish == 0); stop_benchmark(&st, NULL, 1); FREE(input); free(_key); }
_public_ size_t dnssec_tsig_algorithm_size(dnssec_tsig_algorithm_t algorithm) { int gnutls_algorithm = algorithm_to_gnutls(algorithm); return gnutls_hmac_get_len(gnutls_algorithm); }