File Coverage

inc/CryptX_Mode_OFB.xs.inc
Criterion Covered Total %
statement 34 46 73.9
branch 23 40 57.5
condition n/a
subroutine n/a
pod n/a
total 57 86 66.2


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