inc/CryptX_Mac_Poly1305.xs.inc

filter: Statementstmt 92.8% 65 / 70 Branchbran 56.7% 42 / 74 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 74.3% 107 / 144 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« inc/CryptX_Mac_PMAC.xs.inc ↑ Summary inc/CryptX_Mac_XCBC.xs.inc »
1 MODULE = CryptX PACKAGE = Crypt::Mac::Poly1305
2  
3 PROTOTYPES: DISABLE
4  
5 ### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
6  
7 Crypt::Mac::Poly1305
8 new(Class, SV * key)
9 CODE:
10 {
11 19 STRLEN k_len=0;
12 19 unsigned char *k=NULL;
13 int rv;
14  
15 19 ▶ 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"); 19 0 19
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 0 19 19
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
16 19 k = (unsigned char *) SvPVbyte(key, k_len);
17  
18 19 Newz(0, RETVAL, 1, struct cryptx_mac_poly1305_struct);
19 19 ▶ if (!RETVAL) croak("FATAL: Newz failed");
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) croak("FATAL: Newz failed"); 0 19 19
20  
21 19 rv = poly1305_init(&RETVAL->state, k, (unsigned long)k_len);
22 19 ▶ if (rv != CRYPT_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) { 0 19 19
23 0 Safefree(RETVAL);
24 0 croak("FATAL: poly1305_init failed: %s", error_to_string(rv));
25 }
26 19 RETVAL->finalized = 0;
27 }
28 OUTPUT:
29 RETVAL
30  
31 void
32 DESTROY(Crypt::Mac::Poly1305 self)
33 CODE:
34 {
35 19 zeromem(&self->state, sizeof(poly1305_state));
36 19 Safefree(self);
37 }
38  
39 Crypt::Mac::Poly1305
40 clone(Crypt::Mac::Poly1305 self)
41 CODE:
42 0 Newz(0, RETVAL, 1, struct cryptx_mac_poly1305_struct);
43 0 ▶ if (!RETVAL) croak("FATAL: Newz failed");
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) croak("FATAL: Newz failed"); 0 0 0
44 0 Copy(self, RETVAL, 1, struct cryptx_mac_poly1305_struct);
45 OUTPUT:
46 RETVAL
47  
48 void
49 add(Crypt::Mac::Poly1305 self, ...)
50 PPCODE:
51 {
52 int rv, i;
53 STRLEN in_data_len;
54 unsigned char *in_data;
55  
56 24 ▶ if (self->finalized) croak("FATAL: MAC object already finalized");
Branch: 1 branch
BranchTrueFalseTotal
if (self->finalized) croak("FATAL: MAC object already finalized"); 1 23 24
57 56 ▶ for(i = 1; i < items; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i = 1; i < items; i++) { 33 23 56
58 33 in_data = (unsigned char *)SvPVbyte(ST(i), in_data_len);
59 33 ▶ if (in_data_len > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (in_data_len > 0) { 29 4 33
60 29 rv = poly1305_process(&self->state, in_data, (unsigned long)in_data_len);
61 29 ▶ if (rv != CRYPT_OK) croak("FATAL: poly1305_process failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: poly1305_process failed: %s", error_to_string(rv)); 0 29 29
62 }
63 }
64 23 ▶ XPUSHs(ST(0)); /* return self */
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(ST(0)); /* return self */ 0 23 23
65 }
66  
67 SV *
68 mac(Crypt::Mac::Poly1305 self)
69 ALIAS:
70 hexmac = 1
71 b64mac = 2
72 b64umac = 3
73 CODE:
74 {
75 unsigned char mac[MAXBLOCKSIZE];
76 unsigned long maclen, outlen;
77 int rv;
78 char out[MAXBLOCKSIZE*2+1];
79  
80 20 ▶ if (self->finalized) croak("FATAL: MAC object already finalized");
Branch: 1 branch
BranchTrueFalseTotal
if (self->finalized) croak("FATAL: MAC object already finalized"); 1 19 20
81 19 maclen = sizeof(mac);
82 19 rv = poly1305_done(&self->state, mac, &maclen);
83 19 ▶ if (rv != CRYPT_OK) croak("FATAL: poly1305_done failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: poly1305_done failed: %s", error_to_string(rv)); 0 19 19
84 19 self->finalized = 1;
85 19 outlen = sizeof(out);
86 19 ▶ if (ix == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 3) { 1 18 19
87 1 rv = base64url_encode(mac, maclen, out, &outlen);
88 1 ▶ if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv)); 0 1 1
89 1 RETVAL = newSVpvn(out, outlen);
90 }
91 18 ▶ else if (ix == 2) {
Branch: 1 branch
BranchTrueFalseTotal
else if (ix == 2) { 1 17 18
92 1 rv = base64_encode(mac, maclen, out, &outlen);
93 1 ▶ if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv)); 0 1 1
94 1 RETVAL = newSVpvn(out, outlen);
95 }
96 17 ▶ else if (ix == 1) {
Branch: 1 branch
BranchTrueFalseTotal
else if (ix == 1) { 9 8 17
97 9 rv = base16_encode(mac, maclen, out, &outlen, 0);
98 9 ▶ if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); 0 9 9
99 9 RETVAL = newSVpvn(out, outlen);
100 }
101 else {
102 8 RETVAL = newSVpvn((char * )mac, maclen);
103 }
104 19 zeromem(mac, sizeof(mac));
105 }
106 OUTPUT:
107 RETVAL
108  
109 SV *
110 poly1305(SV * key, ...)
111 ALIAS:
112 poly1305_hex = 1
113 poly1305_b64 = 2
114 poly1305_b64u = 3
115 CODE:
116 {
117 STRLEN inlen, klen;
118 unsigned char *in;
119 28 ▶ 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"); 28 0 28
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 0 28 28
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
120 28 unsigned char *k = (unsigned char *)SvPVbyte(key, klen);
121 int rv, i;
122 unsigned char mac[MAXBLOCKSIZE];
123 28 unsigned long len = sizeof(mac), outlen;
124 char out[MAXBLOCKSIZE*2+1];
125 poly1305_state st;
126  
127 28 rv = poly1305_init(&st, k, (unsigned long)klen);
128 28 ▶ if (rv != CRYPT_OK) croak("FATAL: poly1305_init failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: poly1305_init failed: %s", error_to_string(rv)); 0 28 28
129 64 ▶ for (i = 1; i < items; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < items; i++) { 36 28 64
130 36 in = (unsigned char *)SvPVbyte(ST(i), inlen);
131 36 ▶ if (inlen > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (inlen > 0) { 28 8 36
132 28 rv = poly1305_process(&st, in, (unsigned long)inlen);
133 28 ▶ if (rv != CRYPT_OK) croak("FATAL: poly1305_process failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: poly1305_process failed: %s", error_to_string(rv)); 0 28 28
134 }
135 }
136 28 rv = poly1305_done(&st, mac, &len);
137 28 ▶ if (rv != CRYPT_OK) croak("FATAL: poly1305_done failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: poly1305_done failed: %s", error_to_string(rv)); 0 28 28
138  
139 28 outlen = sizeof(out);
140 28 ▶ if (ix == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 3) { 7 21 28
141 7 rv = base64url_encode(mac, len, out, &outlen);
142 7 ▶ if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv)); 0 7 7
143 7 RETVAL = newSVpvn((char *) out, outlen);
144 }
145 21 ▶ else if (ix == 2) {
Branch: 1 branch
BranchTrueFalseTotal
else if (ix == 2) { 7 14 21
146 7 rv = base64_encode(mac, len, out, &outlen);
147 7 ▶ if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv)); 0 7 7
148 7 RETVAL = newSVpvn(out, outlen);
149 }
150 14 ▶ else if (ix == 1) {
Branch: 1 branch
BranchTrueFalseTotal
else if (ix == 1) { 7 7 14
151 7 rv = base16_encode(mac, len, out, &outlen, 0);
152 7 ▶ if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); 0 7 7
153 7 RETVAL = newSVpvn(out, outlen);
154 }
155 else {
156 7 RETVAL = newSVpvn((char *) mac, len);
157 }
158 28 zeromem(mac, sizeof(mac));
159 }
160 OUTPUT:
161 RETVAL
« inc/CryptX_Mac_PMAC.xs.inc ↑ Summary inc/CryptX_Mac_XCBC.xs.inc »