line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
MODULE = CryptX PACKAGE = Crypt::Mode::CTR |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
PROTOTYPES: DISABLE |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY! |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Crypt::Mode::CTR |
8
|
|
|
|
|
|
|
new(Class, char * cipher_name, int ctr_mode=0, int ctr_width=0, int rounds=0) |
9
|
|
|
|
|
|
|
CODE: |
10
|
|
|
|
|
|
|
{ |
11
|
42
|
|
|
|
|
|
Newz(0, RETVAL, 1, struct ctr_struct); |
12
|
42
|
50
|
|
|
|
|
if (!RETVAL) croak("FATAL: Newz failed"); |
13
|
42
|
|
|
|
|
|
RETVAL->direction = 0; |
14
|
42
|
|
|
|
|
|
RETVAL->cipher_rounds = rounds; |
15
|
42
|
|
|
|
|
|
RETVAL->cipher_id = cryptx_internal_find_cipher(cipher_name); |
16
|
42
|
50
|
|
|
|
|
if (RETVAL->cipher_id == -1) { |
17
|
0
|
|
|
|
|
|
Safefree(RETVAL); |
18
|
0
|
|
|
|
|
|
croak("FATAL: find_cipfer failed for '%s'", cipher_name); |
19
|
|
|
|
|
|
|
} |
20
|
42
|
100
|
|
|
|
|
if (ctr_mode == 0) RETVAL->ctr_mode_param = CTR_COUNTER_LITTLE_ENDIAN; |
21
|
42
|
100
|
|
|
|
|
if (ctr_mode == 1) RETVAL->ctr_mode_param = CTR_COUNTER_BIG_ENDIAN; |
22
|
42
|
100
|
|
|
|
|
if (ctr_mode == 2) RETVAL->ctr_mode_param = CTR_COUNTER_LITTLE_ENDIAN|LTC_CTR_RFC3686; |
23
|
42
|
100
|
|
|
|
|
if (ctr_mode == 3) RETVAL->ctr_mode_param = CTR_COUNTER_BIG_ENDIAN|LTC_CTR_RFC3686; |
24
|
42
|
50
|
|
|
|
|
if (ctr_width > 0 && ctr_width <= cipher_descriptor[RETVAL->cipher_id].block_length) RETVAL->ctr_mode_param |= ctr_width; |
|
|
0
|
|
|
|
|
|
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
OUTPUT: |
27
|
|
|
|
|
|
|
RETVAL |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
void |
30
|
|
|
|
|
|
|
DESTROY(Crypt::Mode::CTR self) |
31
|
|
|
|
|
|
|
CODE: |
32
|
42
|
|
|
|
|
|
Safefree(self); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
void |
35
|
|
|
|
|
|
|
start_decrypt(Crypt::Mode::CTR self, SV * key, SV * iv) |
36
|
|
|
|
|
|
|
ALIAS: |
37
|
|
|
|
|
|
|
start_encrypt = 1 |
38
|
|
|
|
|
|
|
PPCODE: |
39
|
|
|
|
|
|
|
{ |
40
|
42
|
|
|
|
|
|
STRLEN k_len=0; |
41
|
42
|
|
|
|
|
|
unsigned char *k=NULL; |
42
|
42
|
|
|
|
|
|
STRLEN i_len=0; |
43
|
42
|
|
|
|
|
|
unsigned char *i=NULL; |
44
|
|
|
|
|
|
|
int rv; |
45
|
|
|
|
|
|
|
|
46
|
42
|
50
|
|
|
|
|
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar"); |
47
|
42
|
50
|
|
|
|
|
k = (unsigned char *) SvPVbyte(key, k_len); |
48
|
|
|
|
|
|
|
|
49
|
42
|
50
|
|
|
|
|
if (!SvPOK(iv)) croak("FATAL: iv must be string/buffer scalar"); |
50
|
42
|
50
|
|
|
|
|
i = (unsigned char *) SvPVbyte(iv, i_len); |
51
|
42
|
50
|
|
|
|
|
if (i_len != (STRLEN)cipher_descriptor[self->cipher_id].block_length) { |
52
|
0
|
|
|
|
|
|
croak ("FATAL: sizeof(iv) should be equal to blocksize (%d)", cipher_descriptor[self->cipher_id].block_length); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
42
|
|
|
|
|
|
rv = ctr_start(self->cipher_id, i, k, (int)k_len, self->cipher_rounds, self->ctr_mode_param, &self->state); |
56
|
42
|
50
|
|
|
|
|
if (rv != CRYPT_OK) { |
57
|
0
|
|
|
|
|
|
croak("FATAL: ctr_start failed: %s", error_to_string(rv)); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
42
|
100
|
|
|
|
|
self->direction = ix == 1 ? 1 : -1; |
61
|
42
|
50
|
|
|
|
|
XPUSHs(ST(0)); /* return self */ |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
SV * |
65
|
|
|
|
|
|
|
add(Crypt::Mode::CTR self, ...) |
66
|
|
|
|
|
|
|
CODE: |
67
|
|
|
|
|
|
|
{ |
68
|
|
|
|
|
|
|
int rv, j; |
69
|
546
|
|
|
|
|
|
STRLEN in_data_len, out_len = 0; |
70
|
|
|
|
|
|
|
unsigned char *in_data, *out_data; |
71
|
|
|
|
|
|
|
|
72
|
546
|
|
|
|
|
|
RETVAL = newSVpvn("", 0); |
73
|
1596
|
100
|
|
|
|
|
for (j = 1; j < items; j++) { |
74
|
1050
|
50
|
|
|
|
|
in_data = (unsigned char *)SvPVbyte(ST(j), in_data_len); |
75
|
1050
|
50
|
|
|
|
|
if (in_data_len > 0) { |
76
|
1050
|
50
|
|
|
|
|
out_data = (unsigned char*)SvGROW(RETVAL, out_len + in_data_len + 1) + out_len; |
|
|
100
|
|
|
|
|
|
77
|
1050
|
|
|
|
|
|
out_len += in_data_len; |
78
|
1050
|
100
|
|
|
|
|
if (self->direction == 1) { |
79
|
525
|
|
|
|
|
|
rv = ctr_encrypt(in_data, out_data, (unsigned long)in_data_len, &self->state); |
80
|
525
|
50
|
|
|
|
|
if (rv != CRYPT_OK) { |
81
|
0
|
|
|
|
|
|
SvREFCNT_dec(RETVAL); |
82
|
0
|
|
|
|
|
|
croak("FATAL: ctr_encrypt failed: %s", error_to_string(rv)); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
525
|
50
|
|
|
|
|
else if (self->direction == -1) { |
86
|
525
|
|
|
|
|
|
rv = ctr_decrypt(in_data, out_data, (unsigned long)in_data_len, &self->state); |
87
|
525
|
50
|
|
|
|
|
if (rv != CRYPT_OK) { |
88
|
0
|
|
|
|
|
|
SvREFCNT_dec(RETVAL); |
89
|
0
|
|
|
|
|
|
croak("FATAL: ctr_decrypt failed: %s", error_to_string(rv)); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
else { |
93
|
0
|
|
|
|
|
|
SvREFCNT_dec(RETVAL); |
94
|
0
|
|
|
|
|
|
croak("FATAL: ctr_crypt failed: call start_encrypt or start_decrypt first"); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
546
|
50
|
|
|
|
|
if (out_len > 0) SvCUR_set(RETVAL, out_len); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
OUTPUT: |
101
|
|
|
|
|
|
|
RETVAL |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
SV * |
104
|
|
|
|
|
|
|
finish(Crypt::Mode::CTR self) |
105
|
|
|
|
|
|
|
CODE: |
106
|
16
|
|
|
|
|
|
self->direction = 0; |
107
|
16
|
|
|
|
|
|
RETVAL = newSVpvn("", 0); |
108
|
|
|
|
|
|
|
OUTPUT: |
109
|
|
|
|
|
|
|
RETVAL |