Package list libcryptx-perl / b0e1718
adopt to updated ltc Karel Miko 3 years ago
20 changed file(s) with 149 addition(s) and 142 deletion(s). Raw diff Collapse all Expand all
240240 void _ecc_oid_lookup(ecc_key *key)
241241 {
242242 int err;
243 unsigned i;
243 unsigned i, j;
244244 void *tmp;
245245 const ltc_ecc_curve *cu;
246246
263263 break; /* found */
264264 }
265265 ltc_mp.deinit(tmp);
266 if (cu->prime != NULL) {
267 key->dp.oidlen = cu->oidlen;
268 for(i = 0; i < cu->oidlen; i++) key->dp.oid[i] = cu->oid[i];
266 if (cu->prime && cu->OID) {
267 for (i = 0; i < 16; i++) key->dp.oid[i] = 0;
268 for (i = 0, j = 0; i < strlen(cu->OID); i++) {
269 if (cu->OID[i] == '.') {
270 if (++j >= 16) return;
271 }
272 else if(cu->OID[i] >= '0' && cu->OID[i] <= '9') {
273 key->dp.oid[j] = key->dp.oid[j] * 10 + (cu->OID[i] - '0');
274 }
275 else {
276 return;
277 }
278 }
279 key->dp.oidlen = j + 1;
269280 }
270281 }
271282
275286 HV *hc, *hl, *h;
276287 SV *sv_crv, **pref;
277288 SV **sv_cofactor, **sv_prime, **sv_A, **sv_B, **sv_order, **sv_Gx, **sv_Gy, **sv_oid;
278 char *ch_name;
279 STRLEN l_name, i, j;
289 char *ptr_crv;
290 STRLEN len_crv;
280291 int err;
281292
282293 if (!SvOK(curve)) croak("FATAL: undefined curve");
283294
284295 if (SvPOK(curve)) {
285296 /* string */
286 ch_name = SvPV(curve, l_name);
297 ptr_crv = SvPV(curve, len_crv);
287298 if ((hl = get_hv("Crypt::PK::ECC::curve2ltc", 0)) == NULL) croak("FATAL: no curve2ltc register");
288 pref = hv_fetch(hl, ch_name, (U32)l_name, 0);
299 pref = hv_fetch(hl, ptr_crv, (U32)len_crv, 0);
289300 if (pref && SvOK(*pref)) {
290301 sv_crv = *pref; /* found in %cutve2ltc */
291302 }
292303 else {
293304 if ((hc = get_hv("Crypt::PK::ECC::curve", 0)) == NULL) croak("FATAL: no curve register");
294 pref = hv_fetch(hc, ch_name, (U32)l_name, 0);
305 pref = hv_fetch(hc, ptr_crv, (U32)len_crv, 0);
295306 if (pref && SvOK(*pref)) {
296307 sv_crv = *pref; /* found in %curve */
297308 }
311322 if (SvPOK(sv_crv)) {
312323 /* string - curve name */
313324 const ltc_ecc_curve *cu;
314 ch_name = SvPV(sv_crv, l_name);
315 if (ecc_get_curve_by_name(ch_name, &cu) != CRYPT_OK) croak("FATAL: ecparams: unknown curve '%s'", ch_name);
325 ptr_crv = SvPV(sv_crv, len_crv);
326 if (ecc_get_curve(ptr_crv, &cu) != CRYPT_OK) croak("FATAL: ecparams: unknown curve '%s'", ptr_crv);
316327 return ecc_set_dp(cu, key);
317328 }
318329 else {
337348 if (!SvOK(*sv_Gy )) croak("FATAL: ecparams: undefined param Gy");
338349 if (!SvOK(*sv_cofactor)) croak("FATAL: ecparams: undefined param cofactor");
339350
351 sv_oid = hv_fetchs(h, "oid", 0); /* 'oid' is optional */
352 cu.OID = (sv_oid && SvOK(*sv_oid)) ? SvPV_nolen(*sv_oid) : NULL;
353
340354 cu.prime = SvPV_nolen(*sv_prime);
341355 cu.A = SvPV_nolen(*sv_A);
342356 cu.B = SvPV_nolen(*sv_B);
343357 cu.order = SvPV_nolen(*sv_order);
344358 cu.Gx = SvPV_nolen(*sv_Gx);
345359 cu.Gy = SvPV_nolen(*sv_Gy);
346 cu.cofactor = (unsigned long)SvUV(*sv_cofactor),
347 cu.oidlen = 0;
348
349 sv_oid = hv_fetchs(h, "oid", 0);
350 if (sv_oid && SvPOK(*sv_oid)) {
351 ch_name = SvPV(*sv_oid, l_name);
352 for (i = 0, j = 0; i < l_name; i++) {
353 if (ch_name[i] == '.') {
354 if (++j >= 16) return CRYPT_ERROR;
355 }
356 else if(ch_name[i] >= '0' && ch_name[i] <= '9') {
357 cu.oid[j] = cu.oid[j] * 10 + (ch_name[i] - '0');
358 }
359 else {
360 return CRYPT_ERROR;
361 }
362 }
363 if (j == 0) return CRYPT_ERROR;
364 cu.oidlen = j + 1;
365 }
360 cu.cofactor = (unsigned long)SvUV(*sv_cofactor);
366361
367362 if ((err = ecc_set_dp(&cu, key)) != CRYPT_OK) return err;
368363 if (key->dp.oidlen == 0) _ecc_oid_lookup(key);
492487 int rv;
493488 STRLEN in_len;
494489 unsigned long out_len;
495 unsigned char *out_data, *in_data;
490 unsigned char *in_data;
491 char *out_data;
496492
497493 if (!SvPOK(in)) XSRETURN_UNDEF;
498494 in_data = (unsigned char *) SvPVbyte(in, in_len);
503499 out_len = (unsigned long)(4 * ((in_len + 2) / 3) + 1);
504500 RETVAL = NEWSV(0, out_len); /* avoid zero! */
505501 SvPOK_only(RETVAL);
506 out_data = (unsigned char *)SvPVX(RETVAL);
502 out_data = SvPVX(RETVAL);
507503 if (ix == 1)
508504 rv = base64url_encode(in_data, (unsigned long)in_len, out_data, &out_len);
509505 else
527523 int rv;
528524 STRLEN in_len;
529525 unsigned long out_len;
530 unsigned char *out_data, *in_data;
526 unsigned char *out_data;
527 char *in_data;
531528
532529 if (!SvPOK(in)) XSRETURN_UNDEF;
533 in_data = (unsigned char *)SvPVbyte(in, in_len);
530 in_data = SvPVbyte(in, in_len);
534531 if (in_len == 0) {
535532 RETVAL = newSVpvn("", 0);
536533 }
4949 my ($maj, $min) = $arver =~ /^GNU ar [^\d]*(\d)\.(\d+)\.\d+/s;
5050 $myarflags = 'rcD' if ($maj && $min && $maj >= 2 && $min >= 20) || $arver=~ /^BSD ar /;
5151 }
52
53 # turn on extra warnings in AUTHOR_MODE (it is gcc only!!)
54 $mycflags = "$mycflags -Wall -Werror -Wextra" if $ENV{AUTHOR_MODE};
55
5256 @EUMM_INC_LIB = (
53 INC => '-DLTM_DESC -Isrc/ltc/headers -Isrc/ltm',
57 INC => $ENV{AUTHOR_MODE} ? '-DLTM_DESC -Isrc/ltc/headers -Isrc/ltm -Wall -Werror -Wextra' #gcc only!!
58 : '-DLTM_DESC -Isrc/ltc/headers -Isrc/ltm',
5459 MYEXTLIB => "src/liballinone$Config{lib_ext}",
5560 clean => { 'FILES' => join(' ', @myobjs, "src/liballinone$Config{lib_ext}") },
5661 );
127127 [%-END%]
128128 outlen = sizeof(out);
129129 if (ix == 3) {
130 rv = base64url_encode(mac, maclen, (unsigned char*)out, &outlen);
130 rv = base64url_encode(mac, maclen, out, &outlen);
131131 if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
132132 RETVAL = newSVpvn(out, outlen);
133133 }
134134 if (ix == 2) {
135 rv = base64_encode(mac, maclen, (unsigned char*)out, &outlen);
135 rv = base64_encode(mac, maclen, out, &outlen);
136136 if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
137137 RETVAL = newSVpvn(out, outlen);
138138 }
139139 if (ix == 1) {
140 rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0);
140 rv = base16_encode(mac, maclen, out, &outlen, 0);
141141 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
142142 RETVAL = newSVpvn(out, outlen);
143143 }
247247
248248 outlen = sizeof(out);
249249 if (ix == 3) {
250 rv = base64url_encode(mac, len, (unsigned char *)out, &outlen);
250 rv = base64url_encode(mac, len, out, &outlen);
251251 if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
252252 RETVAL = newSVpvn((char *) out, outlen);
253253 }
254254 else if (ix == 2) {
255 rv = base64_encode(mac, len, (unsigned char *)out, &outlen);
255 rv = base64_encode(mac, len, out, &outlen);
256256 if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
257 RETVAL = newSVpvn((char *) out, outlen);
257 RETVAL = newSVpvn(out, outlen);
258258 }
259259 else if (ix == 1) {
260 rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0);
260 rv = base16_encode(mac, len, out, &outlen, 0);
261261 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
262 RETVAL = newSVpvn((char *) out, outlen);
262 RETVAL = newSVpvn(out, outlen);
263263 }
264264 else {
265265 RETVAL = newSVpvn((char *) mac, len);
5858 CODE:
5959 {
6060 int rv;
61 unsigned char hash[4], out[9];
61 unsigned char hash[4];
62 char out[9];
6263 unsigned long outlen = 9;
6364 unsigned int ui32;
6465
6667 if (ix == 1) {
6768 rv = base16_encode(hash, 4, out, &outlen, 0);
6869 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
69 RETVAL = newSVpvn((char *)out, outlen);
70 RETVAL = newSVpvn(out, outlen);
7071 }
7172 else if (ix == 2) {
7273 LOAD32H(ui32, hash);
8889 {
8990 adler32_state st;
9091 int rv, j;
91 unsigned char hash[4], out[9], *in;
92 unsigned char hash[4], *in;
93 char out[9];
9294 unsigned long outlen = 9;
9395 unsigned int ui32;
9496 STRLEN inlen;
104106 if (ix == 1) {
105107 rv = base16_encode(hash, 4, out, &outlen, 0);
106108 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
107 RETVAL = newSVpvn((char *)out, outlen);
109 RETVAL = newSVpvn(out, outlen);
108110 }
109111 else if (ix == 2) {
110112 LOAD32H(ui32, hash);
5858 CODE:
5959 {
6060 int rv;
61 unsigned char hash[4], out[9];
61 unsigned char hash[4];
62 char out[9];
6263 unsigned long outlen = 9;
6364 unsigned int ui32;
6465
6667 if (ix == 1) {
6768 rv = base16_encode(hash, 4, out, &outlen, 0);
6869 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
69 RETVAL = newSVpvn((char *)out, outlen);
70 RETVAL = newSVpvn(out, outlen);
7071 }
7172 else if (ix == 2) {
7273 LOAD32H(ui32, hash);
8889 {
8990 crc32_state st;
9091 int rv, j;
91 unsigned char hash[4], out[9], *in;
92 unsigned char hash[4], *in;
93 char out[9];
9294 unsigned long outlen = 9;
9395 unsigned int ui32;
9496 STRLEN inlen;
104106 if (ix == 1) {
105107 rv = base16_encode(hash, 4, out, &outlen, 0);
106108 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
107 RETVAL = newSVpvn((char *)out, outlen);
109 RETVAL = newSVpvn(out, outlen);
108110 }
109111 else if (ix == 2) {
110112 LOAD32H(ui32, hash);
8585
8686 outlen = sizeof(out);
8787 if (ix == 3) {
88 rv = base64url_encode(hash, self->desc->hashsize, (unsigned char *)out, &outlen);
88 rv = base64url_encode(hash, self->desc->hashsize, out, &outlen);
8989 if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
9090 RETVAL = newSVpvn(out, outlen);
9191 }
9292 else if (ix == 2) {
93 rv = base64_encode(hash, self->desc->hashsize, (unsigned char *)out, &outlen);
93 rv = base64_encode(hash, self->desc->hashsize, out, &outlen);
9494 if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
9595 RETVAL = newSVpvn(out, outlen);
9696 }
9797 else if (ix == 1) {
98 rv = base16_encode(hash, self->desc->hashsize, (unsigned char *)out, &outlen, 0);
98 rv = base16_encode(hash, self->desc->hashsize, out, &outlen, 0);
9999 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
100100 RETVAL = newSVpvn(out, outlen);
101101 }
140140
141141 outlen = sizeof(out);
142142 if (ix == 3) {
143 rv = base64url_encode(hash, len, (unsigned char *)out, &outlen);
143 rv = base64url_encode(hash, len, out, &outlen);
144144 if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
145 RETVAL = newSVpvn((char *) out, outlen);
145 RETVAL = newSVpvn(out, outlen);
146146 }
147147 else if (ix == 2) {
148 rv = base64_encode(hash, len, (unsigned char *)out, &outlen);
148 rv = base64_encode(hash, len, out, &outlen);
149149 if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
150 RETVAL = newSVpvn((char *) out, outlen);
150 RETVAL = newSVpvn(out, outlen);
151151 }
152152 else if (ix == 1) {
153 rv = base16_encode(hash, len, (unsigned char *)out, &outlen, 0);
153 rv = base16_encode(hash, len, out, &outlen, 0);
154154 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
155 RETVAL = newSVpvn((char *) out, outlen);
155 RETVAL = newSVpvn(out, outlen);
156156 }
157157 else {
158158 RETVAL = newSVpvn((char *) hash, len);
7676 if (rv != CRYPT_OK) croak("FATAL: blake2bmac_done failed: %s", error_to_string(rv));
7777 outlen = sizeof(out);
7878 if (ix == 3) {
79 rv = base64url_encode(mac, maclen, (unsigned char*)out, &outlen);
79 rv = base64url_encode(mac, maclen, out, &outlen);
8080 if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
8181 RETVAL = newSVpvn(out, outlen);
8282 }
8383 if (ix == 2) {
84 rv = base64_encode(mac, maclen, (unsigned char*)out, &outlen);
84 rv = base64_encode(mac, maclen, out, &outlen);
8585 if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
8686 RETVAL = newSVpvn(out, outlen);
8787 }
8888 if (ix == 1) {
89 rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0);
89 rv = base16_encode(mac, maclen, out, &outlen, 0);
9090 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
9191 RETVAL = newSVpvn(out, outlen);
9292 }
129129
130130 outlen = sizeof(out);
131131 if (ix == 3) {
132 rv = base64url_encode(mac, len, (unsigned char *)out, &outlen);
132 rv = base64url_encode(mac, len, out, &outlen);
133133 if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
134134 RETVAL = newSVpvn((char *) out, outlen);
135135 }
136136 else if (ix == 2) {
137 rv = base64_encode(mac, len, (unsigned char *)out, &outlen);
137 rv = base64_encode(mac, len, out, &outlen);
138138 if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
139 RETVAL = newSVpvn((char *) out, outlen);
139 RETVAL = newSVpvn(out, outlen);
140140 }
141141 else if (ix == 1) {
142 rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0);
142 rv = base16_encode(mac, len, out, &outlen, 0);
143143 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
144 RETVAL = newSVpvn((char *) out, outlen);
144 RETVAL = newSVpvn(out, outlen);
145145 }
146146 else {
147147 RETVAL = newSVpvn((char *) mac, len);
7676 if (rv != CRYPT_OK) croak("FATAL: blake2smac_done failed: %s", error_to_string(rv));
7777 outlen = sizeof(out);
7878 if (ix == 3) {
79 rv = base64url_encode(mac, maclen, (unsigned char*)out, &outlen);
79 rv = base64url_encode(mac, maclen, out, &outlen);
8080 if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
8181 RETVAL = newSVpvn(out, outlen);
8282 }
8383 if (ix == 2) {
84 rv = base64_encode(mac, maclen, (unsigned char*)out, &outlen);
84 rv = base64_encode(mac, maclen, out, &outlen);
8585 if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
8686 RETVAL = newSVpvn(out, outlen);
8787 }
8888 if (ix == 1) {
89 rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0);
89 rv = base16_encode(mac, maclen, out, &outlen, 0);
9090 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
9191 RETVAL = newSVpvn(out, outlen);
9292 }
129129
130130 outlen = sizeof(out);
131131 if (ix == 3) {
132 rv = base64url_encode(mac, len, (unsigned char *)out, &outlen);
132 rv = base64url_encode(mac, len, out, &outlen);
133133 if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
134134 RETVAL = newSVpvn((char *) out, outlen);
135135 }
136136 else if (ix == 2) {
137 rv = base64_encode(mac, len, (unsigned char *)out, &outlen);
137 rv = base64_encode(mac, len, out, &outlen);
138138 if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
139 RETVAL = newSVpvn((char *) out, outlen);
139 RETVAL = newSVpvn(out, outlen);
140140 }
141141 else if (ix == 1) {
142 rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0);
142 rv = base16_encode(mac, len, out, &outlen, 0);
143143 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
144 RETVAL = newSVpvn((char *) out, outlen);
144 RETVAL = newSVpvn(out, outlen);
145145 }
146146 else {
147147 RETVAL = newSVpvn((char *) mac, len);
8080 if (rv != CRYPT_OK) croak("FATAL: f9_done failed: %s", error_to_string(rv));
8181 outlen = sizeof(out);
8282 if (ix == 3) {
83 rv = base64url_encode(mac, maclen, (unsigned char*)out, &outlen);
83 rv = base64url_encode(mac, maclen, out, &outlen);
8484 if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
8585 RETVAL = newSVpvn(out, outlen);
8686 }
8787 if (ix == 2) {
88 rv = base64_encode(mac, maclen, (unsigned char*)out, &outlen);
88 rv = base64_encode(mac, maclen, out, &outlen);
8989 if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
9090 RETVAL = newSVpvn(out, outlen);
9191 }
9292 if (ix == 1) {
93 rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0);
93 rv = base16_encode(mac, maclen, out, &outlen, 0);
9494 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
9595 RETVAL = newSVpvn(out, outlen);
9696 }
134134
135135 outlen = sizeof(out);
136136 if (ix == 3) {
137 rv = base64url_encode(mac, len, (unsigned char *)out, &outlen);
137 rv = base64url_encode(mac, len, out, &outlen);
138138 if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
139139 RETVAL = newSVpvn((char *) out, outlen);
140140 }
141141 else if (ix == 2) {
142 rv = base64_encode(mac, len, (unsigned char *)out, &outlen);
142 rv = base64_encode(mac, len, out, &outlen);
143143 if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
144 RETVAL = newSVpvn((char *) out, outlen);
144 RETVAL = newSVpvn(out, outlen);
145145 }
146146 else if (ix == 1) {
147 rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0);
147 rv = base16_encode(mac, len, out, &outlen, 0);
148148 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
149 RETVAL = newSVpvn((char *) out, outlen);
149 RETVAL = newSVpvn(out, outlen);
150150 }
151151 else {
152152 RETVAL = newSVpvn((char *) mac, len);
8080 if (rv != CRYPT_OK) croak("FATAL: hmac_done failed: %s", error_to_string(rv));
8181 outlen = sizeof(out);
8282 if (ix == 3) {
83 rv = base64url_encode(mac, maclen, (unsigned char*)out, &outlen);
83 rv = base64url_encode(mac, maclen, out, &outlen);
8484 if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
8585 RETVAL = newSVpvn(out, outlen);
8686 }
8787 if (ix == 2) {
88 rv = base64_encode(mac, maclen, (unsigned char*)out, &outlen);
88 rv = base64_encode(mac, maclen, out, &outlen);
8989 if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
9090 RETVAL = newSVpvn(out, outlen);
9191 }
9292 if (ix == 1) {
93 rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0);
93 rv = base16_encode(mac, maclen, out, &outlen, 0);
9494 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
9595 RETVAL = newSVpvn(out, outlen);
9696 }
134134
135135 outlen = sizeof(out);
136136 if (ix == 3) {
137 rv = base64url_encode(mac, len, (unsigned char *)out, &outlen);
137 rv = base64url_encode(mac, len, out, &outlen);
138138 if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
139139 RETVAL = newSVpvn((char *) out, outlen);
140140 }
141141 else if (ix == 2) {
142 rv = base64_encode(mac, len, (unsigned char *)out, &outlen);
142 rv = base64_encode(mac, len, out, &outlen);
143143 if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
144 RETVAL = newSVpvn((char *) out, outlen);
144 RETVAL = newSVpvn(out, outlen);
145145 }
146146 else if (ix == 1) {
147 rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0);
147 rv = base16_encode(mac, len, out, &outlen, 0);
148148 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
149 RETVAL = newSVpvn((char *) out, outlen);
149 RETVAL = newSVpvn(out, outlen);
150150 }
151151 else {
152152 RETVAL = newSVpvn((char *) mac, len);
8080 if (rv != CRYPT_OK) croak("FATAL: omac_done failed: %s", error_to_string(rv));
8181 outlen = sizeof(out);
8282 if (ix == 3) {
83 rv = base64url_encode(mac, maclen, (unsigned char*)out, &outlen);
83 rv = base64url_encode(mac, maclen, out, &outlen);
8484 if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
8585 RETVAL = newSVpvn(out, outlen);
8686 }
8787 if (ix == 2) {
88 rv = base64_encode(mac, maclen, (unsigned char*)out, &outlen);
88 rv = base64_encode(mac, maclen, out, &outlen);
8989 if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
9090 RETVAL = newSVpvn(out, outlen);
9191 }
9292 if (ix == 1) {
93 rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0);
93 rv = base16_encode(mac, maclen, out, &outlen, 0);
9494 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
9595 RETVAL = newSVpvn(out, outlen);
9696 }
134134
135135 outlen = sizeof(out);
136136 if (ix == 3) {
137 rv = base64url_encode(mac, len, (unsigned char *)out, &outlen);
137 rv = base64url_encode(mac, len, out, &outlen);
138138 if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
139139 RETVAL = newSVpvn((char *) out, outlen);
140140 }
141141 else if (ix == 2) {
142 rv = base64_encode(mac, len, (unsigned char *)out, &outlen);
142 rv = base64_encode(mac, len, out, &outlen);
143143 if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
144 RETVAL = newSVpvn((char *) out, outlen);
144 RETVAL = newSVpvn(out, outlen);
145145 }
146146 else if (ix == 1) {
147 rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0);
147 rv = base16_encode(mac, len, out, &outlen, 0);
148148 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
149 RETVAL = newSVpvn((char *) out, outlen);
149 RETVAL = newSVpvn(out, outlen);
150150 }
151151 else {
152152 RETVAL = newSVpvn((char *) mac, len);
8080 if (rv != CRYPT_OK) croak("FATAL: pmac_done failed: %s", error_to_string(rv));
8181 outlen = sizeof(out);
8282 if (ix == 3) {
83 rv = base64url_encode(mac, maclen, (unsigned char*)out, &outlen);
83 rv = base64url_encode(mac, maclen, out, &outlen);
8484 if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
8585 RETVAL = newSVpvn(out, outlen);
8686 }
8787 if (ix == 2) {
88 rv = base64_encode(mac, maclen, (unsigned char*)out, &outlen);
88 rv = base64_encode(mac, maclen, out, &outlen);
8989 if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
9090 RETVAL = newSVpvn(out, outlen);
9191 }
9292 if (ix == 1) {
93 rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0);
93 rv = base16_encode(mac, maclen, out, &outlen, 0);
9494 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
9595 RETVAL = newSVpvn(out, outlen);
9696 }
134134
135135 outlen = sizeof(out);
136136 if (ix == 3) {
137 rv = base64url_encode(mac, len, (unsigned char *)out, &outlen);
137 rv = base64url_encode(mac, len, out, &outlen);
138138 if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
139139 RETVAL = newSVpvn((char *) out, outlen);
140140 }
141141 else if (ix == 2) {
142 rv = base64_encode(mac, len, (unsigned char *)out, &outlen);
142 rv = base64_encode(mac, len, out, &outlen);
143143 if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
144 RETVAL = newSVpvn((char *) out, outlen);
144 RETVAL = newSVpvn(out, outlen);
145145 }
146146 else if (ix == 1) {
147 rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0);
147 rv = base16_encode(mac, len, out, &outlen, 0);
148148 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
149 RETVAL = newSVpvn((char *) out, outlen);
149 RETVAL = newSVpvn(out, outlen);
150150 }
151151 else {
152152 RETVAL = newSVpvn((char *) mac, len);
7676 if (rv != CRYPT_OK) croak("FATAL: pelican_done failed: %s", error_to_string(rv));
7777 outlen = sizeof(out);
7878 if (ix == 3) {
79 rv = base64url_encode(mac, maclen, (unsigned char*)out, &outlen);
79 rv = base64url_encode(mac, maclen, out, &outlen);
8080 if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
8181 RETVAL = newSVpvn(out, outlen);
8282 }
8383 if (ix == 2) {
84 rv = base64_encode(mac, maclen, (unsigned char*)out, &outlen);
84 rv = base64_encode(mac, maclen, out, &outlen);
8585 if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
8686 RETVAL = newSVpvn(out, outlen);
8787 }
8888 if (ix == 1) {
89 rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0);
89 rv = base16_encode(mac, maclen, out, &outlen, 0);
9090 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
9191 RETVAL = newSVpvn(out, outlen);
9292 }
129129
130130 outlen = sizeof(out);
131131 if (ix == 3) {
132 rv = base64url_encode(mac, len, (unsigned char *)out, &outlen);
132 rv = base64url_encode(mac, len, out, &outlen);
133133 if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
134134 RETVAL = newSVpvn((char *) out, outlen);
135135 }
136136 else if (ix == 2) {
137 rv = base64_encode(mac, len, (unsigned char *)out, &outlen);
137 rv = base64_encode(mac, len, out, &outlen);
138138 if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
139 RETVAL = newSVpvn((char *) out, outlen);
139 RETVAL = newSVpvn(out, outlen);
140140 }
141141 else if (ix == 1) {
142 rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0);
142 rv = base16_encode(mac, len, out, &outlen, 0);
143143 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
144 RETVAL = newSVpvn((char *) out, outlen);
144 RETVAL = newSVpvn(out, outlen);
145145 }
146146 else {
147147 RETVAL = newSVpvn((char *) mac, len);
7676 if (rv != CRYPT_OK) croak("FATAL: poly1305_done failed: %s", error_to_string(rv));
7777 outlen = sizeof(out);
7878 if (ix == 3) {
79 rv = base64url_encode(mac, maclen, (unsigned char*)out, &outlen);
79 rv = base64url_encode(mac, maclen, out, &outlen);
8080 if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
8181 RETVAL = newSVpvn(out, outlen);
8282 }
8383 if (ix == 2) {
84 rv = base64_encode(mac, maclen, (unsigned char*)out, &outlen);
84 rv = base64_encode(mac, maclen, out, &outlen);
8585 if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
8686 RETVAL = newSVpvn(out, outlen);
8787 }
8888 if (ix == 1) {
89 rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0);
89 rv = base16_encode(mac, maclen, out, &outlen, 0);
9090 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
9191 RETVAL = newSVpvn(out, outlen);
9292 }
128128
129129 outlen = sizeof(out);
130130 if (ix == 3) {
131 rv = base64url_encode(mac, len, (unsigned char *)out, &outlen);
131 rv = base64url_encode(mac, len, out, &outlen);
132132 if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
133133 RETVAL = newSVpvn((char *) out, outlen);
134134 }
135135 else if (ix == 2) {
136 rv = base64_encode(mac, len, (unsigned char *)out, &outlen);
136 rv = base64_encode(mac, len, out, &outlen);
137137 if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
138 RETVAL = newSVpvn((char *) out, outlen);
138 RETVAL = newSVpvn(out, outlen);
139139 }
140140 else if (ix == 1) {
141 rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0);
141 rv = base16_encode(mac, len, out, &outlen, 0);
142142 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
143 RETVAL = newSVpvn((char *) out, outlen);
143 RETVAL = newSVpvn(out, outlen);
144144 }
145145 else {
146146 RETVAL = newSVpvn((char *) mac, len);
8080 if (rv != CRYPT_OK) croak("FATAL: xcbc_done failed: %s", error_to_string(rv));
8181 outlen = sizeof(out);
8282 if (ix == 3) {
83 rv = base64url_encode(mac, maclen, (unsigned char*)out, &outlen);
83 rv = base64url_encode(mac, maclen, out, &outlen);
8484 if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
8585 RETVAL = newSVpvn(out, outlen);
8686 }
8787 if (ix == 2) {
88 rv = base64_encode(mac, maclen, (unsigned char*)out, &outlen);
88 rv = base64_encode(mac, maclen, out, &outlen);
8989 if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
9090 RETVAL = newSVpvn(out, outlen);
9191 }
9292 if (ix == 1) {
93 rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0);
93 rv = base16_encode(mac, maclen, out, &outlen, 0);
9494 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
9595 RETVAL = newSVpvn(out, outlen);
9696 }
134134
135135 outlen = sizeof(out);
136136 if (ix == 3) {
137 rv = base64url_encode(mac, len, (unsigned char *)out, &outlen);
137 rv = base64url_encode(mac, len, out, &outlen);
138138 if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
139139 RETVAL = newSVpvn((char *) out, outlen);
140140 }
141141 else if (ix == 2) {
142 rv = base64_encode(mac, len, (unsigned char *)out, &outlen);
142 rv = base64_encode(mac, len, out, &outlen);
143143 if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
144 RETVAL = newSVpvn((char *) out, outlen);
144 RETVAL = newSVpvn(out, outlen);
145145 }
146146 else if (ix == 1) {
147 rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0);
147 rv = base16_encode(mac, len, out, &outlen, 0);
148148 if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
149 RETVAL = newSVpvn((char *) out, outlen);
149 RETVAL = newSVpvn(out, outlen);
150150 }
151151 else {
152152 RETVAL = newSVpvn((char *) mac, len);
104104 IV curpid = (IV)PerlProc_getpid();
105105 int rv_len, rv;
106106 unsigned long len;
107 unsigned char *rdata, *tmp;
107 unsigned char *tmp;
108 char *rdata;
108109 unsigned char entropy_buf[40];
109110
110111 if (output_len == 0) {
126127 RETVAL = NEWSV(0, output_len * 2 + 1); /* avoid zero! */
127128 SvPOK_only(RETVAL);
128129 SvCUR_set(RETVAL, output_len * 2 + 1);
129 rdata = (unsigned char *)SvPVX(RETVAL);
130 rdata = SvPVX(RETVAL);
130131 len = output_len * 2 + 1;
131132 rv = base16_encode(tmp, output_len, rdata, &len, 0);
132133 SvCUR_set(RETVAL, len);
145146 RETVAL = NEWSV(0, output_len * 2); /* avoid zero! */
146147 SvPOK_only(RETVAL);
147148 SvCUR_set(RETVAL, output_len * 2);
148 rdata = (unsigned char *)SvPVX(RETVAL);
149 rdata = SvPVX(RETVAL);
149150 len = output_len * 2;
150151 rv = ix == 3 ? base64url_encode(tmp, output_len, rdata, &len) :
151152 base64_encode(tmp, output_len, rdata, &len);
161162 RETVAL = NEWSV(0, output_len); /* avoid zero! */
162163 SvPOK_only(RETVAL);
163164 SvCUR_set(RETVAL, output_len);
164 rdata = (unsigned char *)SvPVX(RETVAL);
165 rv_len = (self->desc->read)(rdata, (unsigned long)output_len, &self->state);
165 rdata = SvPVX(RETVAL);
166 rv_len = (self->desc->read)((unsigned char*)rdata, (unsigned long)output_len, &self->state);
166167 if ((UV)rv_len != output_len) {
167168 SvREFCNT_dec(RETVAL);
168169 croak("FATAL: PRNG_read failed");
22
33 use Test::More;
44
5 plan skip_all => "set TEST_POD to enable this test (developer only!)" unless $ENV{TEST_POD};
5 plan skip_all => "set AUTHOR_MODE to enable this test (developer only!)" unless $ENV{AUTHOR_MODE};
66 plan skip_all => "File::Find not installed" unless eval { require File::Find };
77 plan tests => 1;
88
22
33 use Test::More;
44
5 plan skip_all => "set TEST_POD to enable this test (developer only!)" unless $ENV{TEST_POD};
5 plan skip_all => "set AUTHOR_MODE to enable this test (developer only!)" unless $ENV{AUTHOR_MODE};
66 plan skip_all => "File::Find not installed" unless eval { require File::Find };
77 plan skip_all => "Test::Pod not installed" unless eval { require Test::Pod };
88 plan tests => 107;
22
33 use Test::More;
44
5 plan skip_all => "set TEST_POD to enable this test (developer only!)" unless $ENV{TEST_POD};
5 plan skip_all => "set AUTHOR_MODE to enable this test (developer only!)" unless $ENV{AUTHOR_MODE};
66 plan skip_all => "File::Find not installed" unless eval { require File::Find };
77 plan skip_all => "Test::Pod::Spelling or Text::Aspell not installed" unless eval { require Test::Pod::Spelling; require Text::Aspell; };
88
22
33 use Test::More;
44
5 plan skip_all => "set TEST_POD to enable this test (developer only!)" unless $ENV{TEST_POD};
5 plan skip_all => "set AUTHOR_MODE to enable this test (developer only!)" unless $ENV{AUTHOR_MODE};
66 plan skip_all => "Pod::Coverage not installed" unless eval { require Pod::Coverage };
77 plan skip_all => "File::Find not installed" unless eval { require File::Find };
88 plan tests => 107;