inc/CryptX_Stream_Rabbit.xs.inc

filter: Statementstmt 82.3% 42 / 51 Branchbran 47.5% 19 / 40 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 67.0% 61 / 91 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« inc/CryptX_Stream_ChaCha.xs.inc ↑ Summary inc/CryptX_Mode_XTS.xs.inc »
1 MODULE = CryptX PACKAGE = Crypt::Stream::Rabbit
2  
3 PROTOTYPES: DISABLE
4  
5 Crypt::Stream::Rabbit
6 new(Class, SV * key, SV * nonce=&PL_sv_undef)
7 CODE:
8 {
9 int rv;
10 20 STRLEN iv_len=0, k_len=0;
11 20 unsigned char *iv=NULL, *k=NULL;
12  
13 20 ▶ if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar");
Branch: 5 branches
BranchTrueFalseTotal
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 20 0 20
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 0 20 20
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 0 0 0
14 20 k = (unsigned char *)SvPVbyte(key, k_len);
15  
16 20 Newz(0, RETVAL, 1, rabbit_state);
17 20 ▶ if (!RETVAL) croak("FATAL: Newz failed");
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) croak("FATAL: Newz failed"); 0 20 20
18  
19 20 rv = rabbit_setup(RETVAL, k, (unsigned long)k_len);
20 20 ▶ if (rv != CRYPT_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) { 0 20 20
21 0 Safefree(RETVAL);
22 0 croak("FATAL: rabbit_setup failed: %s", error_to_string(rv));
23 }
24  
25 20 ▶ if (SvOK(nonce)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(nonce)) { 15 5 20
26 15 ▶ if (!SvPOK_spec(nonce)) {
Branch: 5 branches
BranchTrueFalseTotal
if (!SvPOK_spec(nonce)) { 15 0 15
if (!SvPOK_spec(nonce)) { 0 15 15
if (!SvPOK_spec(nonce)) { 0 0 0
if (!SvPOK_spec(nonce)) { 0 0 0
if (!SvPOK_spec(nonce)) { 0 0 0
27 0 rabbit_done(RETVAL);
28 0 Safefree(RETVAL);
29 0 croak("FATAL: nonce must be string/buffer scalar");
30 }
31 15 iv = (unsigned char *)SvPVbyte(nonce, iv_len);
32 15 rv = rabbit_setiv(RETVAL, iv, (unsigned long)iv_len);
33 15 ▶ if (rv != CRYPT_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) { 1 14 15
34 1 rabbit_done(RETVAL);
35 1 Safefree(RETVAL);
36 1 croak("FATAL: rabbit_setiv failed: %s", error_to_string(rv));
37 }
38 }
39  
40 }
41 OUTPUT:
42 RETVAL
43  
44 void
45 DESTROY(Crypt::Stream::Rabbit self)
46 CODE:
47 21 rabbit_done(self);
48 21 zeromem(self, sizeof(*self));
49 21 Safefree(self);
50  
51 Crypt::Stream::Rabbit
52 clone(Crypt::Stream::Rabbit self)
53 CODE:
54 2 Newz(0, RETVAL, 1, rabbit_state);
55 2 ▶ if (!RETVAL) croak("FATAL: Newz failed");
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) croak("FATAL: Newz failed"); 0 2 2
56 2 Copy(self, RETVAL, 1, rabbit_state);
57 OUTPUT:
58 RETVAL
59  
60 SV *
61 keystream(Crypt::Stream::Rabbit self, unsigned long out_len)
62 CODE:
63 {
64 int rv;
65 unsigned char *out_data;
66  
67 5 ▶ if (out_len == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (out_len == 0) { 1 4 5
68 1 RETVAL = newSVpvn("", 0);
69 }
70 else {
71 4 ▶ if (out_len == ULONG_MAX) croak("FATAL: output length too large");
Branch: 1 branch
BranchTrueFalseTotal
if (out_len == ULONG_MAX) croak("FATAL: output length too large"); 2 2 4
72 2 RETVAL = NEWSV(0, out_len); /* avoid zero! */
73 2 SvPOK_only(RETVAL);
74 2 SvCUR_set(RETVAL, out_len);
75 2 *SvEND(RETVAL) = '\0';
76 2 out_data = (unsigned char *)SvPVX(RETVAL);
77 2 rv = rabbit_keystream(self, out_data, out_len);
78 2 ▶ if (rv != CRYPT_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) { 0 2 2
79 0 SvREFCNT_dec(RETVAL);
80 0 croak("FATAL: rabbit_keystream failed: %s", error_to_string(rv));
81 }
82 }
83 }
84 OUTPUT:
85 RETVAL
86  
87 SV *
88 crypt(Crypt::Stream::Rabbit self, SV * data)
89 CODE:
90 {
91 int rv;
92 STRLEN in_data_len;
93 unsigned char *in_data, *out_data;
94  
95 18 in_data = (unsigned char *)SvPVbyte(data, in_data_len);
96 18 ▶ if (in_data_len == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (in_data_len == 0) { 1 17 18
97 1 RETVAL = newSVpvn("", 0);
98 }
99 else {
100 17 RETVAL = NEWSV(0, in_data_len); /* avoid zero! */
101 17 SvPOK_only(RETVAL);
102 17 SvCUR_set(RETVAL, in_data_len);
103 17 *SvEND(RETVAL) = '\0';
104 17 out_data = (unsigned char *)SvPVX(RETVAL);
105 17 rv = rabbit_crypt(self, in_data, (unsigned long)in_data_len, out_data);
106 17 ▶ if (rv != CRYPT_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) { 0 17 17
107 0 SvREFCNT_dec(RETVAL);
108 0 croak("FATAL: rabbit_crypt failed: %s", error_to_string(rv));
109 }
110 }
111 }
112 OUTPUT:
113 RETVAL
« inc/CryptX_Stream_ChaCha.xs.inc ↑ Summary inc/CryptX_Mode_XTS.xs.inc »