void test_mac_throughput(void) { struct crypt *c; int id = TC_HMAC_SHA1_128; int len = get_test_param(0, 8); int num = get_test_param(1, 1); struct iovec *iov; int i; unsigned char out[1024]; int outlen = sizeof(out); c = setup_cipher(TYPE_SYM, id, 1); iov = alloca(sizeof(*iov) * num); for (i = 0; i < num; i++) { iov[i].iov_len = len; iov[i].iov_base = alloca(iov[i].iov_len); memset(iov[i].iov_base, 0, iov[i].iov_len); } printf("MACing %d iovecs of %d bytes each\n", num, len); speed_start(cipher_throughput); while (1) { crypt_mac(c, iov, num, out, &outlen); speed_add(1); } crypt_destroy(c); }
static int modcrypt_decrypt2( INSTANCE * my, int * params ) { int r; crypt_handle * ch = crypt_create( params[0], ( char * ) params[1] ); r = __crypt( ch, ( char * ) params[2], ( char * ) params[3], params[4], 0 ); crypt_destroy( ch ); return r; }
int main(void) { unsigned char plain[19] = "testing encryption"; unsigned char *encrypted = NULL; unsigned char *decrypted = NULL; unsigned char key[CRYPT_KEY_SIZE_AES256] = "weak"; size_t encrypted_out_len = 0, decrypted_out_len = 0; encrypted = crypt_encrypt_aes256ecb(NULL, &encrypted_out_len, plain, sizeof(plain), NULL, key); decrypted = crypt_decrypt_aes256ecb(NULL, &decrypted_out_len, encrypted, encrypted_out_len, NULL, key); puts((char *) decrypted); crypt_destroy(encrypted); crypt_destroy(decrypted); return 0; }
static void hkdf_destroy(struct crypt *c) { struct hkdf_priv *hk = crypt_priv(c); if (!hk) return; crypt_destroy(hk->hk_hmac); free(hk); free(c); }
void test_sym_throughput(void) { struct crypt *c; int id = TC_AES128_HMAC_SHA2; uint64_t iv = 0; int dlen = 1420; void *data; c = setup_cipher(TYPE_SYM, id, 0); data = alloca(dlen); _state.s_dlen = dlen; memset(data, 0, dlen); printf("Encrypting %d bytes of data\n", dlen); speed_start(cipher_throughput); while (1) { crypt_encrypt(c, &iv, data, dlen); speed_add(1); } crypt_destroy(c); }
static int modcrypt_del( INSTANCE * my, int * params ) { crypt_destroy( ( crypt_handle * ) params[0] ); return 1; }