ltc update
Karel Miko
6 years ago
174 | 174 | } |
175 | 175 | |
176 | 176 | return MP_OKAY; |
177 | } | |
178 | ||
179 | int _base16_encode(const unsigned char *in, unsigned long inlen, unsigned char *out, unsigned long *outlen) | |
180 | { | |
181 | unsigned long i; | |
182 | const char alphabet[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; | |
183 | ||
184 | if (*outlen < inlen * 2) { | |
185 | *outlen = inlen * 2; | |
186 | return CRYPT_BUFFER_OVERFLOW; | |
187 | } | |
188 | ||
189 | for (i = 0; i < inlen; i++) { | |
190 | out[i*2] = (unsigned char)alphabet[in[i] >> 4]; | |
191 | out[i*2+1] = (unsigned char)alphabet[in[i] & 0xF]; | |
192 | } | |
193 | ||
194 | *outlen = inlen * 2; | |
195 | return CRYPT_OK; | |
196 | 177 | } |
197 | 178 | |
198 | 179 | size_t _find_start(const char *name, char *ltcname, size_t ltclen) |
267 | 248 | if ((err = ltc_mp.init(&tmp)) != CRYPT_OK) return; |
268 | 249 | for (cu = ltc_ecc_curves; cu->prime != NULL; cu++) { |
269 | 250 | if ((err = mp_read_radix(tmp, cu->prime, 16)) != CRYPT_OK) continue; |
270 | if ((mp_cmp(tmp, key->dp.prime) != LTC_MP_EQ)) continue; | |
251 | if ((mp_cmp(tmp, key->dp.prime) != LTC_MP_EQ)) continue; | |
271 | 252 | if ((err = mp_read_radix(tmp, cu->order, 16)) != CRYPT_OK) continue; |
272 | if ((mp_cmp(tmp, key->dp.order) != LTC_MP_EQ)) continue; | |
253 | if ((mp_cmp(tmp, key->dp.order) != LTC_MP_EQ)) continue; | |
273 | 254 | if ((err = mp_read_radix(tmp, cu->A, 16)) != CRYPT_OK) continue; |
274 | if ((mp_cmp(tmp, key->dp.A) != LTC_MP_EQ)) continue; | |
255 | if ((mp_cmp(tmp, key->dp.A) != LTC_MP_EQ)) continue; | |
275 | 256 | if ((err = mp_read_radix(tmp, cu->B, 16)) != CRYPT_OK) continue; |
276 | if ((mp_cmp(tmp, key->dp.B) != LTC_MP_EQ)) continue; | |
257 | if ((mp_cmp(tmp, key->dp.B) != LTC_MP_EQ)) continue; | |
277 | 258 | if ((err = mp_read_radix(tmp, cu->Gx, 16)) != CRYPT_OK) continue; |
278 | if ((mp_cmp(tmp, key->dp.base.x) != LTC_MP_EQ)) continue; | |
259 | if ((mp_cmp(tmp, key->dp.base.x) != LTC_MP_EQ)) continue; | |
279 | 260 | if ((err = mp_read_radix(tmp, cu->Gy, 16)) != CRYPT_OK) continue; |
280 | if ((mp_cmp(tmp, key->dp.base.y) != LTC_MP_EQ)) continue; | |
261 | if ((mp_cmp(tmp, key->dp.base.y) != LTC_MP_EQ)) continue; | |
281 | 262 | if (key->dp.cofactor != cu->cofactor) continue; |
282 | 263 | break; /* found */ |
283 | 264 | } |
531 | 512 | SvREFCNT_dec(RETVAL); |
532 | 513 | XSRETURN_UNDEF; |
533 | 514 | } |
534 | SvCUR_set(RETVAL, strlen(out_data)); | |
515 | SvCUR_set(RETVAL, out_len); | |
535 | 516 | } |
536 | 517 | } |
537 | 518 | OUTPUT: |
606 | 587 | SvREFCNT_dec(RETVAL); |
607 | 588 | XSRETURN_UNDEF; |
608 | 589 | } |
609 | SvCUR_set(RETVAL, strlen(out_data)); | |
590 | SvCUR_set(RETVAL, out_len); | |
610 | 591 | } |
611 | 592 | } |
612 | 593 | OUTPUT: |
110 | 110 | unsigned char mac[MAXBLOCKSIZE]; |
111 | 111 | unsigned long maclen, outlen; |
112 | 112 | int rv; |
113 | char out[MAXBLOCKSIZE*2]; | |
113 | char out[MAXBLOCKSIZE*2+1]; | |
114 | 114 | |
115 | 115 | [%-IF lc_name == 'pelican' %] |
116 | 116 | maclen = 16; |
137 | 137 | RETVAL = newSVpvn(out, outlen); |
138 | 138 | } |
139 | 139 | if (ix == 1) { |
140 | rv = _base16_encode(mac, maclen, (unsigned char *)out, &outlen); | |
140 | rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0); | |
141 | 141 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
142 | 142 | RETVAL = newSVpvn(out, outlen); |
143 | 143 | } |
257 | 257 | RETVAL = newSVpvn((char *) out, outlen); |
258 | 258 | } |
259 | 259 | else if (ix == 1) { |
260 | rv = _base16_encode(mac, len, (unsigned char *)out, &outlen); | |
260 | rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0); | |
261 | 261 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
262 | 262 | RETVAL = newSVpvn((char *) out, outlen); |
263 | 263 | } |
58 | 58 | CODE: |
59 | 59 | { |
60 | 60 | int rv; |
61 | unsigned char hash[4], out[8]; | |
62 | unsigned long outlen = 8; | |
61 | unsigned char hash[4], out[9]; | |
62 | unsigned long outlen = 9; | |
63 | 63 | unsigned int ui32; |
64 | 64 | |
65 | 65 | adler32_finish(self, hash, 4); /* returns void */ |
66 | 66 | if (ix == 1) { |
67 | rv = _base16_encode(hash, 4, out, &outlen); | |
67 | rv = base16_encode(hash, 4, out, &outlen, 0); | |
68 | 68 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
69 | 69 | RETVAL = newSVpvn((char *)out, outlen); |
70 | 70 | } |
88 | 88 | { |
89 | 89 | adler32_state st; |
90 | 90 | int rv, j; |
91 | unsigned char hash[4], out[8], *in; | |
92 | unsigned long outlen = 8; | |
91 | unsigned char hash[4], out[9], *in; | |
92 | unsigned long outlen = 9; | |
93 | 93 | unsigned int ui32; |
94 | 94 | STRLEN inlen; |
95 | 95 | |
102 | 102 | } |
103 | 103 | adler32_finish(&st, hash, 4); /* returns void */ |
104 | 104 | if (ix == 1) { |
105 | rv = _base16_encode(hash, 4, out, &outlen); | |
105 | rv = base16_encode(hash, 4, out, &outlen, 0); | |
106 | 106 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
107 | 107 | RETVAL = newSVpvn((char *)out, outlen); |
108 | 108 | } |
58 | 58 | CODE: |
59 | 59 | { |
60 | 60 | int rv; |
61 | unsigned char hash[4], out[8]; | |
62 | unsigned long outlen = 8; | |
61 | unsigned char hash[4], out[9]; | |
62 | unsigned long outlen = 9; | |
63 | 63 | unsigned int ui32; |
64 | 64 | |
65 | 65 | crc32_finish(self, hash, 4); /* returns void */ |
66 | 66 | if (ix == 1) { |
67 | rv = _base16_encode(hash, 4, out, &outlen); | |
67 | rv = base16_encode(hash, 4, out, &outlen, 0); | |
68 | 68 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
69 | 69 | RETVAL = newSVpvn((char *)out, outlen); |
70 | 70 | } |
88 | 88 | { |
89 | 89 | crc32_state st; |
90 | 90 | int rv, j; |
91 | unsigned char hash[4], out[8], *in; | |
92 | unsigned long outlen = 8; | |
91 | unsigned char hash[4], out[9], *in; | |
92 | unsigned long outlen = 9; | |
93 | 93 | unsigned int ui32; |
94 | 94 | STRLEN inlen; |
95 | 95 | |
102 | 102 | } |
103 | 103 | crc32_finish(&st, hash, 4); /* returns void */ |
104 | 104 | if (ix == 1) { |
105 | rv = _base16_encode(hash, 4, out, &outlen); | |
105 | rv = base16_encode(hash, 4, out, &outlen, 0); | |
106 | 106 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
107 | 107 | RETVAL = newSVpvn((char *)out, outlen); |
108 | 108 | } |
78 | 78 | int rv; |
79 | 79 | unsigned long outlen; |
80 | 80 | unsigned char hash[MAXBLOCKSIZE]; |
81 | char out[MAXBLOCKSIZE*2]; | |
81 | char out[MAXBLOCKSIZE*2+1]; | |
82 | 82 | |
83 | 83 | rv = self->desc->done(&self->state, hash); |
84 | 84 | if (rv != CRYPT_OK) croak("FATAL: digest done failed: %s", error_to_string(rv)); |
95 | 95 | RETVAL = newSVpvn(out, outlen); |
96 | 96 | } |
97 | 97 | else if (ix == 1) { |
98 | rv = _base16_encode(hash, self->desc->hashsize, (unsigned char *)out, &outlen); | |
98 | rv = base16_encode(hash, self->desc->hashsize, (unsigned char *)out, &outlen, 0); | |
99 | 99 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
100 | 100 | RETVAL = newSVpvn(out, outlen); |
101 | 101 | } |
118 | 118 | int rv, id, i; |
119 | 119 | unsigned char *in, hash[MAXBLOCKSIZE]; |
120 | 120 | unsigned long len = sizeof(hash), outlen; |
121 | char out[MAXBLOCKSIZE*2]; | |
121 | char out[MAXBLOCKSIZE*2+1]; | |
122 | 122 | hash_state md; |
123 | 123 | |
124 | 124 | id = _find_hash(digest_name); |
150 | 150 | RETVAL = newSVpvn((char *) out, outlen); |
151 | 151 | } |
152 | 152 | else if (ix == 1) { |
153 | rv = _base16_encode(hash, len, (unsigned char *)out, &outlen); | |
153 | rv = base16_encode(hash, len, (unsigned char *)out, &outlen, 0); | |
154 | 154 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
155 | 155 | RETVAL = newSVpvn((char *) out, outlen); |
156 | 156 | } |
69 | 69 | unsigned char mac[MAXBLOCKSIZE]; |
70 | 70 | unsigned long maclen, outlen; |
71 | 71 | int rv; |
72 | char out[MAXBLOCKSIZE*2]; | |
72 | char out[MAXBLOCKSIZE*2+1]; | |
73 | 73 | |
74 | 74 | maclen = sizeof(mac); |
75 | 75 | rv = blake2bmac_done(self, mac, &maclen); |
86 | 86 | RETVAL = newSVpvn(out, outlen); |
87 | 87 | } |
88 | 88 | if (ix == 1) { |
89 | rv = _base16_encode(mac, maclen, (unsigned char *)out, &outlen); | |
89 | rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0); | |
90 | 90 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
91 | 91 | RETVAL = newSVpvn(out, outlen); |
92 | 92 | } |
139 | 139 | RETVAL = newSVpvn((char *) out, outlen); |
140 | 140 | } |
141 | 141 | else if (ix == 1) { |
142 | rv = _base16_encode(mac, len, (unsigned char *)out, &outlen); | |
142 | rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0); | |
143 | 143 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
144 | 144 | RETVAL = newSVpvn((char *) out, outlen); |
145 | 145 | } |
69 | 69 | unsigned char mac[MAXBLOCKSIZE]; |
70 | 70 | unsigned long maclen, outlen; |
71 | 71 | int rv; |
72 | char out[MAXBLOCKSIZE*2]; | |
72 | char out[MAXBLOCKSIZE*2+1]; | |
73 | 73 | |
74 | 74 | maclen = sizeof(mac); |
75 | 75 | rv = blake2smac_done(self, mac, &maclen); |
86 | 86 | RETVAL = newSVpvn(out, outlen); |
87 | 87 | } |
88 | 88 | if (ix == 1) { |
89 | rv = _base16_encode(mac, maclen, (unsigned char *)out, &outlen); | |
89 | rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0); | |
90 | 90 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
91 | 91 | RETVAL = newSVpvn(out, outlen); |
92 | 92 | } |
139 | 139 | RETVAL = newSVpvn((char *) out, outlen); |
140 | 140 | } |
141 | 141 | else if (ix == 1) { |
142 | rv = _base16_encode(mac, len, (unsigned char *)out, &outlen); | |
142 | rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0); | |
143 | 143 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
144 | 144 | RETVAL = newSVpvn((char *) out, outlen); |
145 | 145 | } |
73 | 73 | unsigned char mac[MAXBLOCKSIZE]; |
74 | 74 | unsigned long maclen, outlen; |
75 | 75 | int rv; |
76 | char out[MAXBLOCKSIZE*2]; | |
76 | char out[MAXBLOCKSIZE*2+1]; | |
77 | 77 | |
78 | 78 | maclen = sizeof(mac); |
79 | 79 | rv = f9_done(self, mac, &maclen); |
90 | 90 | RETVAL = newSVpvn(out, outlen); |
91 | 91 | } |
92 | 92 | if (ix == 1) { |
93 | rv = _base16_encode(mac, maclen, (unsigned char *)out, &outlen); | |
93 | rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0); | |
94 | 94 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
95 | 95 | RETVAL = newSVpvn(out, outlen); |
96 | 96 | } |
144 | 144 | RETVAL = newSVpvn((char *) out, outlen); |
145 | 145 | } |
146 | 146 | else if (ix == 1) { |
147 | rv = _base16_encode(mac, len, (unsigned char *)out, &outlen); | |
147 | rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0); | |
148 | 148 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
149 | 149 | RETVAL = newSVpvn((char *) out, outlen); |
150 | 150 | } |
73 | 73 | unsigned char mac[MAXBLOCKSIZE]; |
74 | 74 | unsigned long maclen, outlen; |
75 | 75 | int rv; |
76 | char out[MAXBLOCKSIZE*2]; | |
76 | char out[MAXBLOCKSIZE*2+1]; | |
77 | 77 | |
78 | 78 | maclen = sizeof(mac); |
79 | 79 | rv = hmac_done(self, mac, &maclen); |
90 | 90 | RETVAL = newSVpvn(out, outlen); |
91 | 91 | } |
92 | 92 | if (ix == 1) { |
93 | rv = _base16_encode(mac, maclen, (unsigned char *)out, &outlen); | |
93 | rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0); | |
94 | 94 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
95 | 95 | RETVAL = newSVpvn(out, outlen); |
96 | 96 | } |
144 | 144 | RETVAL = newSVpvn((char *) out, outlen); |
145 | 145 | } |
146 | 146 | else if (ix == 1) { |
147 | rv = _base16_encode(mac, len, (unsigned char *)out, &outlen); | |
147 | rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0); | |
148 | 148 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
149 | 149 | RETVAL = newSVpvn((char *) out, outlen); |
150 | 150 | } |
73 | 73 | unsigned char mac[MAXBLOCKSIZE]; |
74 | 74 | unsigned long maclen, outlen; |
75 | 75 | int rv; |
76 | char out[MAXBLOCKSIZE*2]; | |
76 | char out[MAXBLOCKSIZE*2+1]; | |
77 | 77 | |
78 | 78 | maclen = sizeof(mac); |
79 | 79 | rv = omac_done(self, mac, &maclen); |
90 | 90 | RETVAL = newSVpvn(out, outlen); |
91 | 91 | } |
92 | 92 | if (ix == 1) { |
93 | rv = _base16_encode(mac, maclen, (unsigned char *)out, &outlen); | |
93 | rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0); | |
94 | 94 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
95 | 95 | RETVAL = newSVpvn(out, outlen); |
96 | 96 | } |
144 | 144 | RETVAL = newSVpvn((char *) out, outlen); |
145 | 145 | } |
146 | 146 | else if (ix == 1) { |
147 | rv = _base16_encode(mac, len, (unsigned char *)out, &outlen); | |
147 | rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0); | |
148 | 148 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
149 | 149 | RETVAL = newSVpvn((char *) out, outlen); |
150 | 150 | } |
73 | 73 | unsigned char mac[MAXBLOCKSIZE]; |
74 | 74 | unsigned long maclen, outlen; |
75 | 75 | int rv; |
76 | char out[MAXBLOCKSIZE*2]; | |
76 | char out[MAXBLOCKSIZE*2+1]; | |
77 | 77 | |
78 | 78 | maclen = sizeof(mac); |
79 | 79 | rv = pmac_done(self, mac, &maclen); |
90 | 90 | RETVAL = newSVpvn(out, outlen); |
91 | 91 | } |
92 | 92 | if (ix == 1) { |
93 | rv = _base16_encode(mac, maclen, (unsigned char *)out, &outlen); | |
93 | rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0); | |
94 | 94 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
95 | 95 | RETVAL = newSVpvn(out, outlen); |
96 | 96 | } |
144 | 144 | RETVAL = newSVpvn((char *) out, outlen); |
145 | 145 | } |
146 | 146 | else if (ix == 1) { |
147 | rv = _base16_encode(mac, len, (unsigned char *)out, &outlen); | |
147 | rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0); | |
148 | 148 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
149 | 149 | RETVAL = newSVpvn((char *) out, outlen); |
150 | 150 | } |
69 | 69 | unsigned char mac[MAXBLOCKSIZE]; |
70 | 70 | unsigned long maclen, outlen; |
71 | 71 | int rv; |
72 | char out[MAXBLOCKSIZE*2]; | |
72 | char out[MAXBLOCKSIZE*2+1]; | |
73 | 73 | |
74 | 74 | maclen = 16; |
75 | 75 | rv = pelican_done(self, mac); |
86 | 86 | RETVAL = newSVpvn(out, outlen); |
87 | 87 | } |
88 | 88 | if (ix == 1) { |
89 | rv = _base16_encode(mac, maclen, (unsigned char *)out, &outlen); | |
89 | rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0); | |
90 | 90 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
91 | 91 | RETVAL = newSVpvn(out, outlen); |
92 | 92 | } |
139 | 139 | RETVAL = newSVpvn((char *) out, outlen); |
140 | 140 | } |
141 | 141 | else if (ix == 1) { |
142 | rv = _base16_encode(mac, len, (unsigned char *)out, &outlen); | |
142 | rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0); | |
143 | 143 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
144 | 144 | RETVAL = newSVpvn((char *) out, outlen); |
145 | 145 | } |
69 | 69 | unsigned char mac[MAXBLOCKSIZE]; |
70 | 70 | unsigned long maclen, outlen; |
71 | 71 | int rv; |
72 | char out[MAXBLOCKSIZE*2]; | |
72 | char out[MAXBLOCKSIZE*2+1]; | |
73 | 73 | |
74 | 74 | maclen = sizeof(mac); |
75 | 75 | rv = poly1305_done(self, mac, &maclen); |
86 | 86 | RETVAL = newSVpvn(out, outlen); |
87 | 87 | } |
88 | 88 | if (ix == 1) { |
89 | rv = _base16_encode(mac, maclen, (unsigned char *)out, &outlen); | |
89 | rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0); | |
90 | 90 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
91 | 91 | RETVAL = newSVpvn(out, outlen); |
92 | 92 | } |
138 | 138 | RETVAL = newSVpvn((char *) out, outlen); |
139 | 139 | } |
140 | 140 | else if (ix == 1) { |
141 | rv = _base16_encode(mac, len, (unsigned char *)out, &outlen); | |
141 | rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0); | |
142 | 142 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
143 | 143 | RETVAL = newSVpvn((char *) out, outlen); |
144 | 144 | } |
73 | 73 | unsigned char mac[MAXBLOCKSIZE]; |
74 | 74 | unsigned long maclen, outlen; |
75 | 75 | int rv; |
76 | char out[MAXBLOCKSIZE*2]; | |
76 | char out[MAXBLOCKSIZE*2+1]; | |
77 | 77 | |
78 | 78 | maclen = sizeof(mac); |
79 | 79 | rv = xcbc_done(self, mac, &maclen); |
90 | 90 | RETVAL = newSVpvn(out, outlen); |
91 | 91 | } |
92 | 92 | if (ix == 1) { |
93 | rv = _base16_encode(mac, maclen, (unsigned char *)out, &outlen); | |
93 | rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0); | |
94 | 94 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
95 | 95 | RETVAL = newSVpvn(out, outlen); |
96 | 96 | } |
144 | 144 | RETVAL = newSVpvn((char *) out, outlen); |
145 | 145 | } |
146 | 146 | else if (ix == 1) { |
147 | rv = _base16_encode(mac, len, (unsigned char *)out, &outlen); | |
147 | rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0); | |
148 | 148 | if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
149 | 149 | RETVAL = newSVpvn((char *) out, outlen); |
150 | 150 | } |
123 | 123 | if (tmp == NULL) croak("FATAL: Newz failed"); |
124 | 124 | rv_len = (self->desc->read)(tmp, (unsigned long)output_len, &self->state); |
125 | 125 | if ((UV)rv_len != output_len) croak("FATAL: PRNG_read failed"); |
126 | RETVAL = NEWSV(0, output_len * 2); /* avoid zero! */ | |
126 | RETVAL = NEWSV(0, output_len * 2 + 1); /* avoid zero! */ | |
127 | 127 | SvPOK_only(RETVAL); |
128 | SvCUR_set(RETVAL, output_len * 2); | |
128 | SvCUR_set(RETVAL, output_len * 2 + 1); | |
129 | 129 | rdata = (unsigned char *)SvPVX(RETVAL); |
130 | len = output_len * 2; | |
131 | rv = _base16_encode(tmp, output_len, rdata, &len); | |
130 | len = output_len * 2 + 1; | |
131 | rv = base16_encode(tmp, output_len, rdata, &len, 0); | |
132 | SvCUR_set(RETVAL, len); | |
132 | 133 | Safefree(tmp); |
133 | 134 | if (rv != CRYPT_OK) { |
134 | 135 | SvREFCNT_dec(RETVAL); |
48 | 48 | *outlen = x; |
49 | 49 | return CRYPT_BUFFER_OVERFLOW; |
50 | 50 | } |
51 | *outlen = x; | |
51 | x--; | |
52 | *outlen = x; /* returning the length without terminating NUL */ | |
52 | 53 | |
53 | 54 | if (caps == 0) alphabet = alphabets[0]; |
54 | 55 | else alphabet = alphabets[1]; |
55 | 56 | |
56 | x -= 1; | |
57 | 57 | for (i = 0; i < x; i += 2) { |
58 | 58 | out[i] = alphabet[(in[i/2] >> 4) & 0x0f]; |
59 | 59 | out[i+1] = alphabet[in[i/2] & 0x0f]; |