-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgcrypt.cpp
More file actions
69 lines (59 loc) · 1.71 KB
/
Copy pathgcrypt.cpp
File metadata and controls
69 lines (59 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <gcrypt.h>
#include <assert.h>
#include "crypto_bench.h"
#include "gcrypt.h"
#define GCRY_CIPHER GCRY_CIPHER_CAST5
#define GCRY_C_MODE GCRY_CIPHER_MODE_CBC
void GCryptTest::encrypt_round() {
gcry_error_t gcryError;
gcry_cipher_hd_t gcryCipherHd;
gcryError = gcry_cipher_open(&gcryCipherHd, GCRY_CIPHER, GCRY_C_MODE, 0);
if (gcryError) {
printf("gcry_cipher_open failed: %s/%s\n",
gcry_strsource(gcryError),
gcry_strerror(gcryError));
return;
}
gcryError = gcry_cipher_setkey(gcryCipherHd, key, key_size());
if (gcryError) {
printf("gcry_cipher_setkey failed: %s/%s\n",
gcry_strsource(gcryError),
gcry_strerror(gcryError));
return;
}
gcryError = gcry_cipher_encrypt(gcryCipherHd, out, data_size(),
in, data_size());
if (gcryError) {
printf("gcry_cipher_encrypt failed: %s/%s\n",
gcry_strsource(gcryError),
gcry_strerror(gcryError));
return;
}
}
void GCryptTest::decrypt_round() {
gcry_error_t gcryError;
gcry_cipher_hd_t gcryCipherHd;
gcryError = gcry_cipher_open(&gcryCipherHd, GCRY_CIPHER, GCRY_C_MODE, 0);
if (gcryError) {
printf("gcry_cipher_open failed: %s/%s\n",
gcry_strsource(gcryError),
gcry_strerror(gcryError));
return;
}
gcryError = gcry_cipher_setkey(gcryCipherHd, key, key_size());
if (gcryError) {
printf("gcry_cipher_setkey failed: %s/%s\n",
gcry_strsource(gcryError),
gcry_strerror(gcryError));
return;
}
gcryError = gcry_cipher_decrypt(gcryCipherHd, out, data_size(),
in, data_size());
if (gcryError) {
printf("gcry_cipher_encrypt failed: %s/%s\n",
gcry_strsource(gcryError),
gcry_strerror(gcryError));
return;
}
}