| 1 |
|
| #define PERL_NO_GET_CONTEXT /* we want efficiency */ |
| 2 |
|
| #include "EXTERN.h" |
| 3 |
|
| #include "perl.h" |
| 4 |
|
| #include "XSUB.h" |
| 5 |
|
| |
| 6 |
|
| #define NEED_sv_2pvbyte_GLOBAL |
| 7 |
|
| #define NEED_sv_2pv_flags_GLOBAL |
| 8 |
|
| #define NEED_newRV_noinc_GLOBAL |
| 9 |
|
| #include "ppport.h" |
| 10 |
|
| |
| 11 |
|
| /* assert_not_ROK is broken in 5.8.1 */ |
| 12 |
|
| #if PERL_VERSION == 8 && PERL_SUBVERSION == 1 |
| 13 |
|
| # undef assert_not_ROK |
| 14 |
|
| # if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) |
| 15 |
|
| # define assert_not_ROK(sv) ({assert(!SvROK(sv) || !SvRV(sv));}), |
| 16 |
|
| # else |
| 17 |
|
| # define assert_not_ROK(sv) |
| 18 |
|
| # endif |
| 19 |
|
| #endif |
| 20 |
|
| |
| 21 |
|
| /* HACK: https://github.com/DCIT/perl-CryptX/issues/105 (replacement for SvPOK(sv) suggestet by Leont) */ |
| 22 |
|
| #define SvPOK_spec(sv) (SvOK(sv) && (!SvROK(sv) || SvAMAGIC(sv))) |
| 23 |
|
| |
| 24 |
|
| #undef LTC_SOURCE |
| 25 |
|
| #include "tomcrypt.h" |
| 26 |
|
| #include "tommath.h" |
| 27 |
|
| |
| 28 |
666 |
| STATIC int cryptx_internal_input_has_no_payload(const char *in, STRLEN len) { |
| 29 |
|
| STRLEN i; |
| 30 |
666 |
| int saw_formatting = 0; |
| 31 |
|
| |
| 32 |
666 |
▶ | if (in == NULL || len == 0) return 0; |
Branch: 2 branches
| Branch | True | False | Total |
| if (in == NULL || len == 0) return 0; |
666 |
0 |
666 |
| if (in == NULL || len == 0) return 0; |
0 |
666 |
666 |
|
| 33 |
|
| |
| 34 |
695 |
▶ | for (i = 0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < len; i++) { |
686 |
9 |
695 |
|
| 35 |
686 |
▶ | if (in[i] == '=') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (in[i] == '=') { |
10 |
676 |
686 |
|
| 36 |
10 |
| saw_formatting = 1; |
| 37 |
10 |
| continue; |
| 38 |
|
| } |
| 39 |
676 |
▶ | if (in[i] == ' ' || in[i] == '\t' || in[i] == '\n' || in[i] == '\r') { |
Branch: 4 branches
| Branch | True | False | Total |
| if (in[i] == ' ' || in[i] == '\t' || in[i] == '\n' || in[i] == '\r') { |
673 |
3 |
676 |
| if (in[i] == ' ' || in[i] == '\t' || in[i] == '\n' || in[i] == '\r') { |
670 |
3 |
673 |
| if (in[i] == ' ' || in[i] == '\t' || in[i] == '\n' || in[i] == '\r') { |
657 |
13 |
670 |
| if (in[i] == ' ' || in[i] == '\t' || in[i] == '\n' || in[i] == '\r') { |
0 |
657 |
657 |
|
| 40 |
19 |
| saw_formatting = 1; |
| 41 |
19 |
| continue; |
| 42 |
|
| } |
| 43 |
657 |
| return 0; |
| 44 |
|
| } |
| 45 |
9 |
| return saw_formatting; |
| 46 |
|
| } |
| 47 |
|
| |
| 48 |
|
| typedef adler32_state *Crypt__Checksum__Adler32; |
| 49 |
|
| typedef crc32_state *Crypt__Checksum__CRC32; |
| 50 |
|
| |
| 51 |
|
| typedef struct cryptx_authenc_ccm_struct { |
| 52 |
|
| ccm_state state; |
| 53 |
|
| int finalized; |
| 54 |
|
| } *Crypt__AuthEnc__CCM; |
| 55 |
|
| typedef struct cryptx_authenc_eax_struct { |
| 56 |
|
| eax_state state; |
| 57 |
|
| int finalized; |
| 58 |
|
| } *Crypt__AuthEnc__EAX; |
| 59 |
|
| typedef struct cryptx_authenc_gcm_struct { |
| 60 |
|
| gcm_state state; |
| 61 |
|
| int finalized; |
| 62 |
|
| } *Crypt__AuthEnc__GCM; |
| 63 |
|
| typedef struct cryptx_authenc_chacha20poly1305_struct { |
| 64 |
|
| chacha20poly1305_state state; |
| 65 |
|
| int finalized; |
| 66 |
|
| } *Crypt__AuthEnc__ChaCha20Poly1305; |
| 67 |
|
| typedef struct cryptx_authenc_ocb_struct { |
| 68 |
|
| ocb3_state state; |
| 69 |
|
| int finalized; |
| 70 |
|
| } *Crypt__AuthEnc__OCB; |
| 71 |
|
| |
| 72 |
|
| typedef chacha_state *Crypt__Stream__ChaCha; |
| 73 |
|
| typedef chacha_state *Crypt__Stream__XChaCha; |
| 74 |
|
| typedef salsa20_state *Crypt__Stream__Salsa20; |
| 75 |
|
| typedef salsa20_state *Crypt__Stream__XSalsa20; |
| 76 |
|
| typedef sosemanuk_state *Crypt__Stream__Sosemanuk; |
| 77 |
|
| typedef rabbit_state *Crypt__Stream__Rabbit; |
| 78 |
|
| typedef rc4_state *Crypt__Stream__RC4; |
| 79 |
|
| typedef sober128_state *Crypt__Stream__Sober128; |
| 80 |
|
| |
| 81 |
|
| typedef struct cryptx_mac_f9_struct { |
| 82 |
|
| f9_state state; |
| 83 |
|
| int finalized; |
| 84 |
|
| } *Crypt__Mac__F9; |
| 85 |
|
| typedef struct cryptx_mac_hmac_struct { |
| 86 |
|
| hmac_state state; |
| 87 |
|
| int finalized; |
| 88 |
|
| } *Crypt__Mac__HMAC; |
| 89 |
|
| typedef struct cryptx_mac_omac_struct { |
| 90 |
|
| omac_state state; |
| 91 |
|
| int finalized; |
| 92 |
|
| } *Crypt__Mac__OMAC; |
| 93 |
|
| typedef struct cryptx_mac_pelican_struct { |
| 94 |
|
| pelican_state state; |
| 95 |
|
| int finalized; |
| 96 |
|
| } *Crypt__Mac__Pelican; |
| 97 |
|
| typedef struct cryptx_mac_pmac_struct { |
| 98 |
|
| pmac_state state; |
| 99 |
|
| int finalized; |
| 100 |
|
| } *Crypt__Mac__PMAC; |
| 101 |
|
| typedef struct cryptx_mac_xcbc_struct { |
| 102 |
|
| xcbc_state state; |
| 103 |
|
| int finalized; |
| 104 |
|
| } *Crypt__Mac__XCBC; |
| 105 |
|
| typedef struct cryptx_mac_poly1305_struct { |
| 106 |
|
| poly1305_state state; |
| 107 |
|
| int finalized; |
| 108 |
|
| } *Crypt__Mac__Poly1305; |
| 109 |
|
| typedef struct cryptx_mac_blake2s_struct { |
| 110 |
|
| blake2smac_state state; |
| 111 |
|
| int finalized; |
| 112 |
|
| } *Crypt__Mac__BLAKE2s; |
| 113 |
|
| typedef struct cryptx_mac_blake2b_struct { |
| 114 |
|
| blake2bmac_state state; |
| 115 |
|
| int finalized; |
| 116 |
|
| } *Crypt__Mac__BLAKE2b; |
| 117 |
|
| typedef struct cryptx_mac_kmac_struct { |
| 118 |
|
| kmac_state state; |
| 119 |
|
| int finalized; |
| 120 |
|
| int variant; |
| 121 |
|
| } *Crypt__Mac__KMAC; |
| 122 |
|
| |
| 123 |
|
| typedef struct cipher_struct { /* used by Crypt::Cipher */ |
| 124 |
|
| symmetric_key skey; |
| 125 |
|
| struct ltc_cipher_descriptor *desc; |
| 126 |
|
| } *Crypt__Cipher; |
| 127 |
|
| |
| 128 |
|
| typedef struct digest_struct { /* used by Crypt::Digest */ |
| 129 |
|
| hash_state state; |
| 130 |
|
| struct ltc_hash_descriptor *desc; |
| 131 |
|
| int finalized; |
| 132 |
|
| } *Crypt__Digest; |
| 133 |
|
| |
| 134 |
|
| typedef struct digest_shake_struct { /* used by Crypt::Digest::SHAKE, TurboSHAKE, KangarooTwelve */ |
| 135 |
|
| hash_state state; |
| 136 |
|
| int num; |
| 137 |
|
| int squeezing; |
| 138 |
|
| } *Crypt__Digest__SHAKE; |
| 139 |
|
| typedef struct digest_shake_struct *Crypt__Digest__TurboSHAKE; |
| 140 |
|
| typedef struct digest_shake_struct *Crypt__Digest__KangarooTwelve; |
| 141 |
|
| |
| 142 |
|
| /* --- Crypt::ASN1 helper -------------------------------------------------- */ |
| 143 |
|
| static const char * const s_asn1_class_names[] = { |
| 144 |
|
| "UNIVERSAL", "APPLICATION", "CONTEXT_SPECIFIC", "PRIVATE" |
| 145 |
|
| }; |
| 146 |
|
| |
| 147 |
|
| typedef struct { int int_fmt; int bin_fmt; int dt_fmt; HV *oidmap; } asn1_opts_t; |
| 148 |
|
| /* int_fmt: 0=decimal(default) 1=hex 2=bytes */ |
| 149 |
|
| /* bin_fmt: 0=raw(default) 1=hex 2=base64 */ |
| 150 |
|
| /* dt_fmt: 0=rfc3339(default) 1=epoch */ |
| 151 |
|
| |
| 152 |
56 |
| static SV * s_asn1_oid_name_sv(pTHX_ HV *oidmap, SV *oid_sv) |
| 153 |
|
| { |
| 154 |
56 |
| STRLEN len = 0; |
| 155 |
56 |
| const char *oid = NULL; |
| 156 |
56 |
| SV **name_sv = NULL; |
| 157 |
|
| |
| 158 |
56 |
▶ | if (!oidmap || !oid_sv || !SvOK(oid_sv)) return NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!oidmap || !oid_sv || !SvOK(oid_sv)) return NULL; |
1 |
55 |
56 |
| if (!oidmap || !oid_sv || !SvOK(oid_sv)) return NULL; |
1 |
0 |
1 |
| if (!oidmap || !oid_sv || !SvOK(oid_sv)) return NULL; |
0 |
1 |
1 |
|
| 159 |
|
| |
| 160 |
1 |
| oid = SvPV(oid_sv, len); |
| 161 |
1 |
| name_sv = hv_fetch(oidmap, oid, (I32)len, 0); |
| 162 |
1 |
▶ | if (!name_sv || !SvOK(*name_sv)) return NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!name_sv || !SvOK(*name_sv)) return NULL; |
1 |
0 |
1 |
| if (!name_sv || !SvOK(*name_sv)) return NULL; |
0 |
1 |
1 |
|
| 163 |
|
| |
| 164 |
1 |
| return newSVsv(*name_sv); |
| 165 |
|
| } |
| 166 |
|
| |
| 167 |
|
| /* Encode binary data according to bin_fmt */ |
| 168 |
56 |
| static SV * s_asn1_bin_sv(pTHX_ const void *data, unsigned long size, int bin_fmt) |
| 169 |
|
| { |
| 170 |
56 |
▶ | if (!data || size == 0) return newSVpvn("", 0); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!data || size == 0) return newSVpvn("", 0); |
56 |
0 |
56 |
| if (!data || size == 0) return newSVpvn("", 0); |
0 |
56 |
56 |
|
| 171 |
56 |
▶ | if (bin_fmt == 1) { /* hex */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (bin_fmt == 1) { /* hex */ |
6 |
50 |
56 |
|
| 172 |
|
| SV *s; |
| 173 |
6 |
| unsigned long outlen = size * 2 + 1; |
| 174 |
6 |
| char *buf; Newz(0, buf, outlen, char); |
| 175 |
6 |
| { unsigned long ol = outlen; base16_encode((const unsigned char*)data, size, buf, &ol, 0); } |
| 176 |
6 |
| s = newSVpvn(buf, size * 2); Safefree(buf); |
| 177 |
6 |
| return s; |
| 178 |
50 |
▶ | } else if (bin_fmt == 2) { /* base64 */ |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (bin_fmt == 2) { /* base64 */ |
11 |
39 |
50 |
|
| 179 |
|
| SV *s; |
| 180 |
11 |
| unsigned long outlen = ((size + 2) / 3) * 4 + 4; |
| 181 |
11 |
| char *buf; Newz(0, buf, outlen, char); |
| 182 |
11 |
| base64_encode((const unsigned char*)data, size, buf, &outlen); |
| 183 |
11 |
| s = newSVpvn(buf, outlen); Safefree(buf); |
| 184 |
11 |
| return s; |
| 185 |
|
| } |
| 186 |
39 |
| return newSVpvn((const char *)data, size); /* raw */ |
| 187 |
|
| } |
| 188 |
|
| |
| 189 |
|
| /* Convert Gregorian date+time to Unix epoch (portable, no timegm needed) */ |
| 190 |
7 |
| static IV s_asn1_to_epoch(unsigned YYYY, unsigned MM, unsigned DD, |
| 191 |
|
| unsigned hh, unsigned mm, unsigned ss, |
| 192 |
|
| unsigned off_dir, unsigned off_hh, unsigned off_mm) |
| 193 |
|
| { |
| 194 |
7 |
| long y = YYYY, m = MM, d = DD; |
| 195 |
|
| long days; |
| 196 |
|
| IV epoch, offset; |
| 197 |
7 |
▶ | if (m <= 2) { y--; m += 12; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (m <= 2) { y--; m += 12; } |
1 |
6 |
7 |
|
| 198 |
7 |
| days = 365*y + y/4 - y/100 + y/400 + (153*m - 457)/5 + d - 719469; |
| 199 |
7 |
| epoch = (IV)days * 86400 + (IV)hh * 3600 + (IV)mm * 60 + (IV)ss; |
| 200 |
7 |
| offset = (IV)(off_hh * 3600 + off_mm * 60); |
| 201 |
|
| /* off_dir: 0 = '+' (local ahead of UTC, subtract to get UTC) |
| 202 |
|
| * 1 = '-' (local behind UTC, add to get UTC) */ |
| 203 |
7 |
▶ | epoch += (off_dir ? offset : -offset); |
Branch: 1 branch
| Branch | True | False | Total |
| epoch += (off_dir ? offset : -offset); |
7 |
0 |
7 |
|
| 204 |
7 |
| return epoch; |
| 205 |
|
| } |
| 206 |
|
| |
| 207 |
190 |
| static SV * s_ltc_asn1_to_perl(pTHX_ ltc_asn1_list *node, asn1_opts_t opts) |
| 208 |
|
| { |
| 209 |
190 |
| AV *av = newAV(); |
| 210 |
556 |
▶ | while (node != NULL && node->type != LTC_ASN1_EOL) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (node != NULL && node->type != LTC_ASN1_EOL) { |
370 |
186 |
556 |
| while (node != NULL && node->type != LTC_ASN1_EOL) { |
367 |
3 |
370 |
|
| 211 |
367 |
| HV *hv = newHV(); |
| 212 |
367 |
| SV *value_sv = NULL; |
| 213 |
367 |
| const char *type_str = "UNKNOWN"; |
| 214 |
367 |
| const char *format_str = "unknown"; |
| 215 |
367 |
| switch (node->type) { |
| 216 |
3 |
| case LTC_ASN1_BOOLEAN: |
| 217 |
3 |
| type_str = "BOOLEAN"; format_str = "bool"; |
| 218 |
3 |
▶ | if (node->data) value_sv = newSViv(*(int *)node->data ? 1 : 0); |
Branch: 1 branch
| Branch | True | False | Total |
| if (node->data) value_sv = newSViv(*(int *)node->data ? 1 : 0); |
3 |
0 |
3 |
|
| 219 |
3 |
| break; |
| 220 |
44 |
| case LTC_ASN1_INTEGER: { |
| 221 |
44 |
| mp_int *mpi = (mp_int *)node->data; |
| 222 |
44 |
| type_str = "INTEGER"; |
| 223 |
44 |
▶ | if (mpi) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (mpi) { |
44 |
0 |
44 |
|
| 224 |
44 |
▶ | if (opts.int_fmt == 2) { /* bytes */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (opts.int_fmt == 2) { /* bytes */ |
5 |
39 |
44 |
|
| 225 |
5 |
▶ | if (mp_isneg(mpi)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (mp_isneg(mpi)) { |
1 |
4 |
5 |
|
| 226 |
1 |
| SvREFCNT_dec(hv); |
| 227 |
1 |
| croak("FATAL: asn1_decode_der: negative INTEGER cannot be represented with int=>'bytes'"); |
| 228 |
|
| } |
| 229 |
4 |
| format_str = "bytes"; |
| 230 |
4 |
▶ | if (mp_iszero(mpi)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (mp_iszero(mpi)) { |
1 |
3 |
4 |
|
| 231 |
1 |
| value_sv = newSVpvn("\0", 1); |
| 232 |
|
| } else { |
| 233 |
3 |
| unsigned long usize = mp_ubin_size(mpi); |
| 234 |
3 |
| unsigned char *ubuf; Newz(0, ubuf, usize, unsigned char); |
| 235 |
3 |
| { mp_err me = mp_to_ubin(mpi, ubuf, usize, NULL); PERL_UNUSED_VAR(me); } |
| 236 |
3 |
| value_sv = newSVpvn((char *)ubuf, usize); Safefree(ubuf); |
| 237 |
|
| } |
| 238 |
|
| } else { |
| 239 |
39 |
▶ | int radix = (opts.int_fmt == 1) ? 16 : 10; |
Branch: 1 branch
| Branch | True | False | Total |
| int radix = (opts.int_fmt == 1) ? 16 : 10; |
5 |
34 |
39 |
|
| 240 |
|
| int len; |
| 241 |
|
| char *buf; |
| 242 |
39 |
▶ | format_str = (opts.int_fmt == 1) ? "hex" : "decimal"; |
Branch: 1 branch
| Branch | True | False | Total |
| format_str = (opts.int_fmt == 1) ? "hex" : "decimal"; |
5 |
34 |
39 |
|
| 243 |
39 |
▶ | len = mp_count_bits(mpi) / (opts.int_fmt == 1 ? 4 : 3) + 4; |
Branch: 1 branch
| Branch | True | False | Total |
| len = mp_count_bits(mpi) / (opts.int_fmt == 1 ? 4 : 3) + 4; |
5 |
34 |
39 |
|
| 244 |
39 |
| Newz(0, buf, len, char); |
| 245 |
39 |
| { mp_err me = mp_to_radix(mpi, buf, len, NULL, radix); PERL_UNUSED_VAR(me); } |
| 246 |
39 |
▶ | if (opts.int_fmt == 1) { /* lowercase hex */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (opts.int_fmt == 1) { /* lowercase hex */ |
5 |
34 |
39 |
|
| 247 |
41 |
▶ | char *p; for (p = buf; *p; p++) if (*p >= 'A' && *p <= 'F') *p += 32; |
Branch: 3 branches
| Branch | True | False | Total |
| char *p; for (p = buf; *p; p++) if (*p >= 'A' && *p <= 'F') *p += 32; |
18 |
18 |
36 |
| char *p; for (p = buf; *p; p++) if (*p >= 'A' && *p <= 'F') *p += 32; |
18 |
0 |
18 |
| char *p; for (p = buf; *p; p++) if (*p >= 'A' && *p <= 'F') *p += 32; |
36 |
5 |
41 |
|
| 248 |
|
| } |
| 249 |
39 |
| value_sv = newSVpv(buf, 0); Safefree(buf); |
| 250 |
|
| } |
| 251 |
|
| } |
| 252 |
43 |
| break; |
| 253 |
|
| } |
| 254 |
0 |
| case LTC_ASN1_SHORT_INTEGER: { |
| 255 |
0 |
| type_str = "INTEGER"; |
| 256 |
0 |
▶ | if (node->data) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (node->data) { |
0 |
0 |
0 |
|
| 257 |
0 |
| unsigned long v = *(unsigned long *)node->data; |
| 258 |
0 |
▶ | if (opts.int_fmt == 1) { /* hex */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (opts.int_fmt == 1) { /* hex */ |
0 |
0 |
0 |
|
| 259 |
|
| char buf[32]; |
| 260 |
0 |
| format_str = "hex"; |
| 261 |
0 |
| snprintf(buf, sizeof(buf), "%lx", v); |
| 262 |
0 |
| value_sv = newSVpv(buf, 0); |
| 263 |
0 |
▶ | } else if (opts.int_fmt == 2) { /* bytes */ |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (opts.int_fmt == 2) { /* bytes */ |
0 |
0 |
0 |
|
| 264 |
|
| unsigned char b[8], be[8]; |
| 265 |
0 |
| int n = 0, k; |
| 266 |
0 |
| unsigned long tmp = v; |
| 267 |
0 |
| format_str = "bytes"; |
| 268 |
0 |
▶ | while (tmp) { b[n++] = (unsigned char)(tmp & 0xff); tmp >>= 8; } |
Branch: 1 branch
| Branch | True | False | Total |
| while (tmp) { b[n++] = (unsigned char)(tmp & 0xff); tmp >>= 8; } |
0 |
0 |
0 |
|
| 269 |
0 |
▶ | if (!n) { b[0] = 0; n = 1; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (!n) { b[0] = 0; n = 1; } |
0 |
0 |
0 |
|
| 270 |
0 |
▶ | for (k = 0; k < n; k++) be[k] = b[n - 1 - k]; |
Branch: 1 branch
| Branch | True | False | Total |
| for (k = 0; k < n; k++) be[k] = b[n - 1 - k]; |
0 |
0 |
0 |
|
| 271 |
0 |
| value_sv = newSVpvn((char *)be, n); |
| 272 |
|
| } else { |
| 273 |
0 |
| format_str = "decimal"; |
| 274 |
0 |
| value_sv = newSVuv((UV)v); |
| 275 |
|
| } |
| 276 |
|
| } |
| 277 |
0 |
| break; |
| 278 |
|
| } |
| 279 |
18 |
| case LTC_ASN1_BIT_STRING: { |
| 280 |
18 |
| unsigned char *bits = (unsigned char *)node->data; |
| 281 |
18 |
| unsigned long nbits = node->size, nbytes = (nbits + 7) / 8; |
| 282 |
18 |
| type_str = "BIT_STRING"; |
| 283 |
18 |
▶ | format_str = (opts.bin_fmt == 1) ? "hex" : (opts.bin_fmt == 2) ? "base64" : "bytes"; |
Branch: 2 branches
| Branch | True | False | Total |
| format_str = (opts.bin_fmt == 1) ? "hex" : (opts.bin_fmt == 2) ? "base64" : "bytes"; |
16 |
2 |
18 |
| format_str = (opts.bin_fmt == 1) ? "hex" : (opts.bin_fmt == 2) ? "base64" : "bytes"; |
4 |
12 |
16 |
|
| 284 |
18 |
▶ | if (bits && nbytes > 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (bits && nbytes > 0) { |
18 |
0 |
18 |
| if (bits && nbytes > 0) { |
18 |
0 |
18 |
|
| 285 |
|
| unsigned long i; |
| 286 |
|
| unsigned char *packed; |
| 287 |
18 |
| Newz(0, packed, nbytes, unsigned char); |
| 288 |
28074 |
▶ | for (i = 0; i < nbits; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < nbits; i++) |
28056 |
18 |
28074 |
|
| 289 |
28056 |
▶ | if (bits[i]) packed[i/8] |= (unsigned char)(0x80u >> (i%8)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (bits[i]) packed[i/8] |= (unsigned char)(0x80u >> (i%8)); |
13734 |
14322 |
28056 |
|
| 290 |
18 |
| value_sv = s_asn1_bin_sv(aTHX_ packed, nbytes, opts.bin_fmt); |
| 291 |
18 |
| Safefree(packed); |
| 292 |
|
| } |
| 293 |
18 |
| hv_stores(hv, "bits", newSVuv((UV)nbits)); |
| 294 |
18 |
| break; |
| 295 |
|
| } |
| 296 |
0 |
| case LTC_ASN1_RAW_BIT_STRING: { |
| 297 |
0 |
| unsigned long nbits_raw = node->size; |
| 298 |
0 |
| unsigned long nbytes_raw = (nbits_raw + 7) / 8; |
| 299 |
0 |
| type_str = "BIT_STRING"; |
| 300 |
0 |
▶ | format_str = (opts.bin_fmt == 1) ? "hex" : (opts.bin_fmt == 2) ? "base64" : "bytes"; |
Branch: 2 branches
| Branch | True | False | Total |
| format_str = (opts.bin_fmt == 1) ? "hex" : (opts.bin_fmt == 2) ? "base64" : "bytes"; |
0 |
0 |
0 |
| format_str = (opts.bin_fmt == 1) ? "hex" : (opts.bin_fmt == 2) ? "base64" : "bytes"; |
0 |
0 |
0 |
|
| 301 |
0 |
| value_sv = s_asn1_bin_sv(aTHX_ node->data, nbytes_raw, opts.bin_fmt); |
| 302 |
0 |
| hv_stores(hv, "bits", newSVuv((UV)nbits_raw)); |
| 303 |
0 |
| break; |
| 304 |
|
| } |
| 305 |
37 |
| case LTC_ASN1_OCTET_STRING: |
| 306 |
37 |
| type_str = "OCTET_STRING"; |
| 307 |
37 |
▶ | format_str = (opts.bin_fmt == 1) ? "hex" : (opts.bin_fmt == 2) ? "base64" : "bytes"; |
Branch: 2 branches
| Branch | True | False | Total |
| format_str = (opts.bin_fmt == 1) ? "hex" : (opts.bin_fmt == 2) ? "base64" : "bytes"; |
33 |
4 |
37 |
| format_str = (opts.bin_fmt == 1) ? "hex" : (opts.bin_fmt == 2) ? "base64" : "bytes"; |
7 |
26 |
33 |
|
| 308 |
37 |
| value_sv = s_asn1_bin_sv(aTHX_ node->data, node->size, opts.bin_fmt); |
| 309 |
37 |
| break; |
| 310 |
20 |
| case LTC_ASN1_NULL: |
| 311 |
20 |
| type_str = "NULL"; format_str = "null"; |
| 312 |
20 |
| break; |
| 313 |
56 |
| case LTC_ASN1_OBJECT_IDENTIFIER: { |
| 314 |
56 |
| unsigned long *oid = (unsigned long *)node->data; |
| 315 |
56 |
| type_str = "OID"; format_str = "oid"; |
| 316 |
56 |
▶ | if (oid && node->size > 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (oid && node->size > 0) { |
56 |
0 |
56 |
| if (oid && node->size > 0) { |
56 |
0 |
56 |
|
| 317 |
56 |
| unsigned long i; SV *s = newSVpvn("", 0); |
| 318 |
337 |
▶ | for (i = 0; i < node->size; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < node->size; i++) { |
281 |
56 |
337 |
|
| 319 |
281 |
▶ | if (i > 0) sv_catpv(s, "."); sv_catpvf(s, "%lu", oid[i]); |
Branch: 1 branch
| Branch | True | False | Total |
| if (i > 0) sv_catpv(s, "."); sv_catpvf(s, "%lu", oid[i]); |
225 |
56 |
281 |
|
| 320 |
|
| } |
| 321 |
56 |
| value_sv = s; |
| 322 |
|
| { |
| 323 |
56 |
| SV *name_sv = s_asn1_oid_name_sv(aTHX_ opts.oidmap, value_sv); |
| 324 |
56 |
▶ | if (name_sv) hv_stores(hv, "name", name_sv); |
Branch: 1 branch
| Branch | True | False | Total |
| if (name_sv) hv_stores(hv, "name", name_sv); |
1 |
55 |
56 |
|
| 325 |
|
| } |
| 326 |
|
| } |
| 327 |
56 |
| break; |
| 328 |
|
| } |
| 329 |
2 |
| case LTC_ASN1_IA5_STRING: |
| 330 |
2 |
| type_str = "IA5_STRING"; format_str = "string"; |
| 331 |
2 |
▶ | if (node->data && node->size > 0) value_sv = newSVpvn((char *)node->data, node->size); |
Branch: 2 branches
| Branch | True | False | Total |
| if (node->data && node->size > 0) value_sv = newSVpvn((char *)node->data, node->size); |
2 |
0 |
2 |
| if (node->data && node->size > 0) value_sv = newSVpvn((char *)node->data, node->size); |
2 |
0 |
2 |
|
| 332 |
2 |
| break; |
| 333 |
2 |
| case LTC_ASN1_PRINTABLE_STRING: |
| 334 |
2 |
| type_str = "PRINTABLE_STRING"; format_str = "string"; |
| 335 |
2 |
▶ | if (node->data && node->size > 0) value_sv = newSVpvn((char *)node->data, node->size); |
Branch: 2 branches
| Branch | True | False | Total |
| if (node->data && node->size > 0) value_sv = newSVpvn((char *)node->data, node->size); |
2 |
0 |
2 |
| if (node->data && node->size > 0) value_sv = newSVpvn((char *)node->data, node->size); |
2 |
0 |
2 |
|
| 336 |
2 |
| break; |
| 337 |
0 |
| case LTC_ASN1_TELETEX_STRING: |
| 338 |
0 |
| type_str = "TELETEX_STRING"; format_str = "string"; |
| 339 |
0 |
▶ | if (node->data && node->size > 0) value_sv = newSVpvn((char *)node->data, node->size); |
Branch: 2 branches
| Branch | True | False | Total |
| if (node->data && node->size > 0) value_sv = newSVpvn((char *)node->data, node->size); |
0 |
0 |
0 |
| if (node->data && node->size > 0) value_sv = newSVpvn((char *)node->data, node->size); |
0 |
0 |
0 |
|
| 340 |
0 |
| break; |
| 341 |
14 |
| case LTC_ASN1_UTF8_STRING: { |
| 342 |
14 |
| wchar_t *wstr = (wchar_t *)node->data; |
| 343 |
14 |
| type_str = "UTF8_STRING"; format_str = "utf8"; |
| 344 |
14 |
▶ | if (wstr && node->size > 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (wstr && node->size > 0) { |
14 |
0 |
14 |
| if (wstr && node->size > 0) { |
14 |
0 |
14 |
|
| 345 |
|
| unsigned long i; |
| 346 |
14 |
| SV *s = newSVpvn("", 0); SvUTF8_on(s); |
| 347 |
78 |
▶ | for (i = 0; i < node->size; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < node->size; i++) { |
64 |
14 |
78 |
|
| 348 |
|
| U8 ubuf[UTF8_MAXBYTES + 1]; |
| 349 |
64 |
| U8 *end = uvchr_to_utf8(ubuf, (UV)wstr[i]); |
| 350 |
64 |
| sv_catpvn(s, (char *)ubuf, end - ubuf); |
| 351 |
|
| } |
| 352 |
14 |
| value_sv = s; |
| 353 |
|
| } |
| 354 |
14 |
| break; |
| 355 |
|
| } |
| 356 |
16 |
| case LTC_ASN1_UTCTIME: { |
| 357 |
16 |
| ltc_utctime *t = (ltc_utctime *)node->data; |
| 358 |
16 |
| type_str = "UTCTIME"; |
| 359 |
16 |
▶ | if (t) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (t) { |
16 |
0 |
16 |
|
| 360 |
16 |
▶ | unsigned YYYY = (t->YY >= 50) ? 1900 + t->YY : 2000 + t->YY; |
Branch: 1 branch
| Branch | True | False | Total |
| unsigned YYYY = (t->YY >= 50) ? 1900 + t->YY : 2000 + t->YY; |
0 |
16 |
16 |
|
| 361 |
16 |
▶ | if (opts.dt_fmt == 1) { /* epoch */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (opts.dt_fmt == 1) { /* epoch */ |
6 |
10 |
16 |
|
| 362 |
6 |
| format_str = "epoch"; |
| 363 |
6 |
| value_sv = newSViv(s_asn1_to_epoch(YYYY, t->MM, t->DD, t->hh, t->mm, t->ss, |
| 364 |
|
| t->off_dir, t->off_hh, t->off_mm)); |
| 365 |
|
| } else { /* rfc3339 */ |
| 366 |
|
| char buf[32]; |
| 367 |
10 |
| format_str = "rfc3339"; |
| 368 |
10 |
▶ | if (t->off_dir == 0 && t->off_hh == 0 && t->off_mm == 0) |
Branch: 3 branches
| Branch | True | False | Total |
| if (t->off_dir == 0 && t->off_hh == 0 && t->off_mm == 0) |
10 |
0 |
10 |
| if (t->off_dir == 0 && t->off_hh == 0 && t->off_mm == 0) |
10 |
0 |
10 |
| if (t->off_dir == 0 && t->off_hh == 0 && t->off_mm == 0) |
10 |
0 |
10 |
|
| 369 |
10 |
| snprintf(buf, sizeof(buf), "%04u-%02u-%02uT%02u:%02u:%02uZ", |
| 370 |
|
| YYYY, t->MM, t->DD, t->hh, t->mm, t->ss); |
| 371 |
|
| else |
| 372 |
0 |
| snprintf(buf, sizeof(buf), "%04u-%02u-%02uT%02u:%02u:%02u%c%02u:%02u", |
| 373 |
|
| YYYY, t->MM, t->DD, t->hh, t->mm, t->ss, |
| 374 |
0 |
▶ | t->off_dir ? '-' : '+', t->off_hh, t->off_mm); |
Branch: 1 branch
| Branch | True | False | Total |
| t->off_dir ? '-' : '+', t->off_hh, t->off_mm); |
0 |
0 |
0 |
|
| 375 |
10 |
| value_sv = newSVpv(buf, 0); |
| 376 |
|
| } |
| 377 |
|
| } |
| 378 |
16 |
| break; |
| 379 |
|
| } |
| 380 |
5 |
| case LTC_ASN1_GENERALIZEDTIME: { |
| 381 |
5 |
| ltc_generalizedtime *t = (ltc_generalizedtime *)node->data; |
| 382 |
5 |
| type_str = "GENERALIZEDTIME"; |
| 383 |
5 |
▶ | if (t) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (t) { |
5 |
0 |
5 |
|
| 384 |
5 |
▶ | if (opts.dt_fmt == 1) { /* epoch */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (opts.dt_fmt == 1) { /* epoch */ |
1 |
4 |
5 |
|
| 385 |
1 |
| format_str = "epoch"; |
| 386 |
1 |
| value_sv = newSViv(s_asn1_to_epoch(t->YYYY, t->MM, t->DD, t->hh, t->mm, t->ss, |
| 387 |
|
| t->off_dir, t->off_hh, t->off_mm)); |
| 388 |
|
| } else { /* rfc3339 */ |
| 389 |
|
| char buf[48]; |
| 390 |
|
| int pos; |
| 391 |
4 |
| format_str = "rfc3339"; |
| 392 |
4 |
| pos = snprintf(buf, sizeof(buf), "%04u-%02u-%02uT%02u:%02u:%02u", |
| 393 |
|
| t->YYYY, t->MM, t->DD, t->hh, t->mm, t->ss); |
| 394 |
4 |
▶ | if (t->fs > 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (t->fs > 0) |
3 |
1 |
4 |
|
| 395 |
3 |
| pos += snprintf(buf + pos, sizeof(buf) - pos, ".%u", t->fs); |
| 396 |
4 |
▶ | if (t->off_dir == 0 && t->off_hh == 0 && t->off_mm == 0) |
Branch: 3 branches
| Branch | True | False | Total |
| if (t->off_dir == 0 && t->off_hh == 0 && t->off_mm == 0) |
4 |
0 |
4 |
| if (t->off_dir == 0 && t->off_hh == 0 && t->off_mm == 0) |
3 |
1 |
4 |
| if (t->off_dir == 0 && t->off_hh == 0 && t->off_mm == 0) |
3 |
0 |
3 |
|
| 397 |
3 |
| snprintf(buf + pos, sizeof(buf) - pos, "Z"); |
| 398 |
|
| else |
| 399 |
1 |
| snprintf(buf + pos, sizeof(buf) - pos, "%c%02u:%02u", |
| 400 |
1 |
▶ | t->off_dir ? '-' : '+', t->off_hh, t->off_mm); |
Branch: 1 branch
| Branch | True | False | Total |
| t->off_dir ? '-' : '+', t->off_hh, t->off_mm); |
0 |
1 |
1 |
|
| 401 |
4 |
| value_sv = newSVpv(buf, 0); |
| 402 |
|
| } |
| 403 |
|
| } |
| 404 |
5 |
| break; |
| 405 |
|
| } |
| 406 |
115 |
| case LTC_ASN1_SEQUENCE: |
| 407 |
115 |
| type_str = "SEQUENCE"; format_str = "array"; |
| 408 |
115 |
▶ | value_sv = node->child ? newRV_noinc(s_ltc_asn1_to_perl(aTHX_ node->child, opts)) : newRV_noinc((SV *)newAV()); |
Branch: 1 branch
| Branch | True | False | Total |
| value_sv = node->child ? newRV_noinc(s_ltc_asn1_to_perl(aTHX_ node->child, opts)) : newRV_noinc((SV *)newAV()); |
115 |
0 |
115 |
|
| 409 |
115 |
| break; |
| 410 |
14 |
| case LTC_ASN1_SET: |
| 411 |
|
| case LTC_ASN1_SETOF: |
| 412 |
14 |
| type_str = "SET"; format_str = "array"; |
| 413 |
14 |
▶ | value_sv = node->child ? newRV_noinc(s_ltc_asn1_to_perl(aTHX_ node->child, opts)) : newRV_noinc((SV *)newAV()); |
Branch: 1 branch
| Branch | True | False | Total |
| value_sv = node->child ? newRV_noinc(s_ltc_asn1_to_perl(aTHX_ node->child, opts)) : newRV_noinc((SV *)newAV()); |
14 |
0 |
14 |
|
| 414 |
14 |
| break; |
| 415 |
21 |
| case LTC_ASN1_CUSTOM_TYPE: { |
| 416 |
21 |
| unsigned int cls = (unsigned int)node->klass; |
| 417 |
21 |
| type_str = "CUSTOM"; |
| 418 |
21 |
▶ | hv_stores(hv, "class", newSVpv((cls < 4) ? s_asn1_class_names[cls] : "UNKNOWN", 0)); |
Branch: 1 branch
| Branch | True | False | Total |
| hv_stores(hv, "class", newSVpv((cls < 4) ? s_asn1_class_names[cls] : "UNKNOWN", 0)); |
21 |
0 |
21 |
|
| 419 |
21 |
| hv_stores(hv, "constructed", newSViv(node->pc == LTC_ASN1_PC_CONSTRUCTED ? 1 : 0)); |
| 420 |
21 |
| hv_stores(hv, "tag", newSVuv((UV)node->tag)); |
| 421 |
21 |
▶ | if (node->pc == LTC_ASN1_PC_CONSTRUCTED && node->child) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (node->pc == LTC_ASN1_PC_CONSTRUCTED && node->child) { |
20 |
1 |
21 |
| if (node->pc == LTC_ASN1_PC_CONSTRUCTED && node->child) { |
20 |
0 |
20 |
|
| 422 |
20 |
| format_str = "array"; |
| 423 |
20 |
| value_sv = newRV_noinc(s_ltc_asn1_to_perl(aTHX_ node->child, opts)); |
| 424 |
1 |
▶ | } else if (node->data && node->size > 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| } else if (node->data && node->size > 0) { |
1 |
0 |
1 |
| } else if (node->data && node->size > 0) { |
1 |
0 |
1 |
|
| 425 |
1 |
▶ | format_str = (opts.bin_fmt == 1) ? "hex" : (opts.bin_fmt == 2) ? "base64" : "bytes"; |
Branch: 2 branches
| Branch | True | False | Total |
| format_str = (opts.bin_fmt == 1) ? "hex" : (opts.bin_fmt == 2) ? "base64" : "bytes"; |
1 |
0 |
1 |
| format_str = (opts.bin_fmt == 1) ? "hex" : (opts.bin_fmt == 2) ? "base64" : "bytes"; |
0 |
1 |
1 |
|
| 426 |
1 |
| value_sv = s_asn1_bin_sv(aTHX_ node->data, node->size, opts.bin_fmt); |
| 427 |
|
| } |
| 428 |
21 |
| break; |
| 429 |
|
| } |
| 430 |
0 |
| default: |
| 431 |
|
| /* Unknown ltc_asn1_type — skip rather than emit unroundtrippable node */ |
| 432 |
0 |
| SvREFCNT_dec(hv); |
| 433 |
0 |
| node = node->next; |
| 434 |
0 |
| continue; |
| 435 |
|
| } |
| 436 |
366 |
| hv_stores(hv, "type", newSVpv(type_str, 0)); |
| 437 |
366 |
| hv_stores(hv, "format", newSVpv(format_str, 0)); |
| 438 |
366 |
▶ | hv_stores(hv, "value", value_sv ? value_sv : newSV(0)); |
Branch: 1 branch
| Branch | True | False | Total |
| hv_stores(hv, "value", value_sv ? value_sv : newSV(0)); |
20 |
346 |
366 |
|
| 439 |
366 |
| av_push(av, newRV_noinc((SV *)hv)); |
| 440 |
366 |
| node = node->next; |
| 441 |
|
| } |
| 442 |
189 |
| return (SV *)av; |
| 443 |
|
| } |
| 444 |
|
| /* --- end Crypt::ASN1 decoder helper -------------------------------------- */ |
| 445 |
|
| |
| 446 |
|
| /* --- Crypt::ASN1 encoder helpers ----------------------------------------- */ |
| 447 |
|
| |
| 448 |
|
| /* Write DER length to buf, return bytes written (buf must be >= 5 bytes) */ |
| 449 |
141 |
| static unsigned long s_asn1_put_der_length(pTHX_ unsigned char *buf, unsigned long len) |
| 450 |
|
| { |
| 451 |
141 |
▶ | if (len > 0xffffffffUL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > 0xffffffffUL) { |
0 |
141 |
141 |
|
| 452 |
0 |
| croak("FATAL: asn1_encode: DER length exceeds 0xffffffff bytes"); |
| 453 |
|
| } |
| 454 |
141 |
▶ | if (len < 128) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len < 128) { |
123 |
18 |
141 |
|
| 455 |
123 |
| buf[0] = (unsigned char)len; |
| 456 |
123 |
| return 1; |
| 457 |
18 |
▶ | } else if (len <= 0xffUL) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (len <= 0xffUL) { |
0 |
18 |
18 |
|
| 458 |
0 |
| buf[0] = 0x81; buf[1] = (unsigned char)len; |
| 459 |
0 |
| return 2; |
| 460 |
18 |
▶ | } else if (len <= 0xffffUL) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (len <= 0xffffUL) { |
18 |
0 |
18 |
|
| 461 |
18 |
| buf[0] = 0x82; |
| 462 |
18 |
| buf[1] = (unsigned char)(len >> 8); |
| 463 |
18 |
| buf[2] = (unsigned char)(len & 0xff); |
| 464 |
18 |
| return 3; |
| 465 |
0 |
▶ | } else if (len <= 0xffffffUL) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (len <= 0xffffffUL) { |
0 |
0 |
0 |
|
| 466 |
0 |
| buf[0] = 0x83; |
| 467 |
0 |
| buf[1] = (unsigned char)(len >> 16); |
| 468 |
0 |
| buf[2] = (unsigned char)((len >> 8) & 0xff); |
| 469 |
0 |
| buf[3] = (unsigned char)(len & 0xff); |
| 470 |
0 |
| return 4; |
| 471 |
|
| } |
| 472 |
0 |
| buf[0] = 0x84; |
| 473 |
0 |
| buf[1] = (unsigned char)(len >> 24); |
| 474 |
0 |
| buf[2] = (unsigned char)((len >> 16) & 0xff); |
| 475 |
0 |
| buf[3] = (unsigned char)((len >> 8) & 0xff); |
| 476 |
0 |
| buf[4] = (unsigned char)(len & 0xff); |
| 477 |
0 |
| return 5; |
| 478 |
|
| } |
| 479 |
|
| |
| 480 |
|
| /* Append single-byte tag + DER length + content to SV */ |
| 481 |
130 |
| static void s_asn1_append_tlv(pTHX_ SV *out, unsigned char tag, |
| 482 |
|
| const void *content, unsigned long clen) |
| 483 |
|
| { |
| 484 |
|
| unsigned char lbuf[5]; |
| 485 |
130 |
| unsigned long llen = s_asn1_put_der_length(aTHX_ lbuf, clen); |
| 486 |
130 |
| sv_catpvn(out, (char *)&tag, 1); |
| 487 |
130 |
| sv_catpvn(out, (char *)lbuf, llen); |
| 488 |
130 |
▶ | if (clen > 0 && content) sv_catpvn(out, (const char *)content, clen); |
Branch: 2 branches
| Branch | True | False | Total |
| if (clen > 0 && content) sv_catpvn(out, (const char *)content, clen); |
117 |
13 |
130 |
| if (clen > 0 && content) sv_catpvn(out, (const char *)content, clen); |
117 |
0 |
117 |
|
| 489 |
130 |
| } |
| 490 |
|
| |
| 491 |
|
| /* Append multi-byte tag (for CUSTOM) + DER length + content to SV */ |
| 492 |
11 |
| static void s_asn1_append_custom_tlv(pTHX_ SV *out, |
| 493 |
|
| unsigned int klass, unsigned int pc, |
| 494 |
|
| unsigned long tag, |
| 495 |
|
| const void *content, unsigned long clen) |
| 496 |
|
| { |
| 497 |
|
| unsigned char tbuf[12], lbuf[5]; |
| 498 |
|
| unsigned long tlen, llen; |
| 499 |
11 |
| unsigned char first = (unsigned char)(((klass & 0x3) << 6) | ((pc & 0x1) << 5)); |
| 500 |
|
| |
| 501 |
11 |
▶ | if (tag < 31) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tag < 31) { |
11 |
0 |
11 |
|
| 502 |
11 |
| tbuf[0] = first | (unsigned char)tag; |
| 503 |
11 |
| tlen = 1; |
| 504 |
|
| } else { |
| 505 |
|
| unsigned char tmp[10]; |
| 506 |
0 |
| int n = 0, i; |
| 507 |
0 |
| unsigned long t = tag; |
| 508 |
0 |
| tbuf[0] = first | 0x1f; |
| 509 |
|
| /* base-128 big-endian */ |
| 510 |
0 |
▶ | do { tmp[n++] = (unsigned char)(t & 0x7f); t >>= 7; } while (t > 0); |
Branch: 1 branch
| Branch | True | False | Total |
| do { tmp[n++] = (unsigned char)(t & 0x7f); t >>= 7; } while (t > 0); |
0 |
0 |
0 |
|
| 511 |
0 |
| tlen = 1; |
| 512 |
0 |
▶ | for (i = n - 1; i >= 0; i--) tbuf[tlen++] = tmp[i] | (i > 0 ? 0x80 : 0x00); |
Branch: 2 branches
| Branch | True | False | Total |
| for (i = n - 1; i >= 0; i--) tbuf[tlen++] = tmp[i] | (i > 0 ? 0x80 : 0x00); |
0 |
0 |
0 |
| for (i = n - 1; i >= 0; i--) tbuf[tlen++] = tmp[i] | (i > 0 ? 0x80 : 0x00); |
0 |
0 |
0 |
|
| 513 |
|
| } |
| 514 |
11 |
| llen = s_asn1_put_der_length(aTHX_ lbuf, clen); |
| 515 |
11 |
| sv_catpvn(out, (char *)tbuf, tlen); |
| 516 |
11 |
| sv_catpvn(out, (char *)lbuf, llen); |
| 517 |
11 |
▶ | if (clen > 0 && content) sv_catpvn(out, (const char *)content, clen); |
Branch: 2 branches
| Branch | True | False | Total |
| if (clen > 0 && content) sv_catpvn(out, (const char *)content, clen); |
10 |
1 |
11 |
| if (clen > 0 && content) sv_catpvn(out, (const char *)content, clen); |
10 |
0 |
10 |
|
| 518 |
11 |
| } |
| 519 |
|
| |
| 520 |
|
| /* Forward declarations */ |
| 521 |
|
| static void s_asn1_encode_node(pTHX_ SV *out, HV *node); |
| 522 |
|
| |
| 523 |
115 |
| static void s_asn1_encode_nodes(pTHX_ SV *out, AV *nodes) |
| 524 |
|
| { |
| 525 |
115 |
| I32 i, len = av_top_index(nodes); |
| 526 |
309 |
▶ | for (i = 0; i <= len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= len; i++) { |
194 |
115 |
309 |
|
| 527 |
194 |
| SV **elem = av_fetch(nodes, i, 0); |
| 528 |
194 |
▶ | if (!elem || !SvROK(*elem) || SvTYPE(SvRV(*elem)) != SVt_PVHV) continue; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!elem || !SvROK(*elem) || SvTYPE(SvRV(*elem)) != SVt_PVHV) continue; |
194 |
0 |
194 |
| if (!elem || !SvROK(*elem) || SvTYPE(SvRV(*elem)) != SVt_PVHV) continue; |
194 |
0 |
194 |
| if (!elem || !SvROK(*elem) || SvTYPE(SvRV(*elem)) != SVt_PVHV) continue; |
0 |
194 |
194 |
|
| 529 |
194 |
| s_asn1_encode_node(aTHX_ out, (HV *)SvRV(*elem)); |
| 530 |
|
| } |
| 531 |
115 |
| } |
| 532 |
|
| |
| 533 |
194 |
| static void s_asn1_encode_node(pTHX_ SV *out, HV *node) |
| 534 |
|
| { |
| 535 |
194 |
| SV **sv_type = hv_fetchs(node, "type", 0); |
| 536 |
194 |
| SV **sv_value = hv_fetchs(node, "value", 0); |
| 537 |
|
| const char *type; |
| 538 |
|
| |
| 539 |
194 |
▶ | if (!sv_type || !SvOK(*sv_type)) croak("FATAL: asn1_encode: node missing 'type'"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!sv_type || !SvOK(*sv_type)) croak("FATAL: asn1_encode: node missing 'type'"); |
194 |
0 |
194 |
| if (!sv_type || !SvOK(*sv_type)) croak("FATAL: asn1_encode: node missing 'type'"); |
0 |
194 |
194 |
|
| 540 |
194 |
| type = SvPV_nolen(*sv_type); |
| 541 |
|
| |
| 542 |
194 |
▶ | if (strEQ(type, "BOOLEAN")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(type, "BOOLEAN")) { |
4 |
190 |
194 |
|
| 543 |
4 |
▶ | int val = (sv_value && SvOK(*sv_value)) ? SvIV(*sv_value) : 0; |
Branch: 2 branches
| Branch | True | False | Total |
| int val = (sv_value && SvOK(*sv_value)) ? SvIV(*sv_value) : 0; |
4 |
0 |
4 |
| int val = (sv_value && SvOK(*sv_value)) ? SvIV(*sv_value) : 0; |
4 |
0 |
4 |
|
| 544 |
4 |
▶ | unsigned char c = val ? 0xFF : 0x00; |
Branch: 1 branch
| Branch | True | False | Total |
| unsigned char c = val ? 0xFF : 0x00; |
2 |
2 |
4 |
|
| 545 |
4 |
| s_asn1_append_tlv(aTHX_ out, 0x01, &c, 1); |
| 546 |
|
| } |
| 547 |
190 |
▶ | else if (strEQ(type, "NULL")) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(type, "NULL")) { |
11 |
179 |
190 |
|
| 548 |
11 |
| s_asn1_append_tlv(aTHX_ out, 0x05, NULL, 0); |
| 549 |
|
| } |
| 550 |
179 |
▶ | else if (strEQ(type, "INTEGER")) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(type, "INTEGER")) { |
25 |
154 |
179 |
|
| 551 |
|
| STRLEN slen; const char *str; |
| 552 |
|
| mp_int mpi; int rv; |
| 553 |
|
| unsigned long outlen; unsigned char *buf; |
| 554 |
|
| |
| 555 |
25 |
▶ | if (!sv_value || !SvOK(*sv_value)) croak("FATAL: asn1_encode: INTEGER missing value"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!sv_value || !SvOK(*sv_value)) croak("FATAL: asn1_encode: INTEGER missing value"); |
25 |
0 |
25 |
| if (!sv_value || !SvOK(*sv_value)) croak("FATAL: asn1_encode: INTEGER missing value"); |
0 |
25 |
25 |
|
| 556 |
25 |
| str = SvPV(*sv_value, slen); |
| 557 |
|
| |
| 558 |
25 |
▶ | if (mp_init(&mpi) != MP_OKAY) croak("FATAL: asn1_encode: mp_init failed"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (mp_init(&mpi) != MP_OKAY) croak("FATAL: asn1_encode: mp_init failed"); |
0 |
25 |
25 |
|
| 559 |
25 |
▶ | if (mp_read_radix(&mpi, str, 10) != MP_OKAY) { mp_clear(&mpi); croak("FATAL: asn1_encode: invalid INTEGER value '%s'", str); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (mp_read_radix(&mpi, str, 10) != MP_OKAY) { mp_clear(&mpi); croak("FATAL: asn1_encode: invalid INTEGER value '%s'", str); } |
0 |
25 |
25 |
|
| 560 |
|
| |
| 561 |
25 |
| rv = der_length_integer(&mpi, &outlen); |
| 562 |
25 |
▶ | if (rv != CRYPT_OK) { mp_clear(&mpi); croak("FATAL: asn1_encode: der_length_integer failed"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != CRYPT_OK) { mp_clear(&mpi); croak("FATAL: asn1_encode: der_length_integer failed"); } |
0 |
25 |
25 |
|
| 563 |
|
| |
| 564 |
25 |
| Newx(buf, outlen, unsigned char); |
| 565 |
25 |
| rv = der_encode_integer(&mpi, buf, &outlen); |
| 566 |
25 |
| mp_clear(&mpi); |
| 567 |
25 |
▶ | if (rv != CRYPT_OK) { Safefree(buf); croak("FATAL: asn1_encode: der_encode_integer failed"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != CRYPT_OK) { Safefree(buf); croak("FATAL: asn1_encode: der_encode_integer failed"); } |
0 |
25 |
25 |
|
| 568 |
|
| |
| 569 |
25 |
| sv_catpvn(out, (char *)buf, outlen); |
| 570 |
25 |
| Safefree(buf); |
| 571 |
|
| } |
| 572 |
154 |
▶ | else if (strEQ(type, "OID")) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(type, "OID")) { |
28 |
126 |
154 |
|
| 573 |
|
| STRLEN slen; const char *str; const char *p; |
| 574 |
28 |
| unsigned long words[64], nwords = 0, outlen; |
| 575 |
|
| unsigned char *buf; int rv; |
| 576 |
|
| |
| 577 |
28 |
▶ | if (!sv_value || !SvOK(*sv_value)) croak("FATAL: asn1_encode: OID missing value"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!sv_value || !SvOK(*sv_value)) croak("FATAL: asn1_encode: OID missing value"); |
28 |
0 |
28 |
| if (!sv_value || !SvOK(*sv_value)) croak("FATAL: asn1_encode: OID missing value"); |
0 |
28 |
28 |
|
| 578 |
28 |
| str = SvPV(*sv_value, slen); |
| 579 |
|
| |
| 580 |
28 |
| p = str; |
| 581 |
166 |
▶ | while (*p && nwords < 64) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (*p && nwords < 64) { |
138 |
28 |
166 |
| while (*p && nwords < 64) { |
138 |
0 |
138 |
|
| 582 |
138 |
| words[nwords++] = strtoul(p, (char **)&p, 10); |
| 583 |
138 |
▶ | if (*p == '.') p++; |
Branch: 1 branch
| Branch | True | False | Total |
| if (*p == '.') p++; |
110 |
28 |
138 |
|
| 584 |
|
| } |
| 585 |
28 |
▶ | if (nwords < 2) croak("FATAL: asn1_encode: OID must have at least 2 arcs"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (nwords < 2) croak("FATAL: asn1_encode: OID must have at least 2 arcs"); |
0 |
28 |
28 |
|
| 586 |
|
| |
| 587 |
28 |
| rv = der_length_object_identifier(words, nwords, &outlen); |
| 588 |
28 |
▶ | if (rv != CRYPT_OK) croak("FATAL: asn1_encode: der_length_object_identifier failed"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != CRYPT_OK) croak("FATAL: asn1_encode: der_length_object_identifier failed"); |
0 |
28 |
28 |
|
| 589 |
|
| |
| 590 |
28 |
| Newx(buf, outlen, unsigned char); |
| 591 |
28 |
| rv = der_encode_object_identifier(words, nwords, buf, &outlen); |
| 592 |
28 |
▶ | if (rv != CRYPT_OK) { Safefree(buf); croak("FATAL: asn1_encode: der_encode_object_identifier failed"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != CRYPT_OK) { Safefree(buf); croak("FATAL: asn1_encode: der_encode_object_identifier failed"); } |
0 |
28 |
28 |
|
| 593 |
|
| |
| 594 |
28 |
| sv_catpvn(out, (char *)buf, outlen); |
| 595 |
28 |
| Safefree(buf); |
| 596 |
|
| } |
| 597 |
126 |
▶ | else if (strEQ(type, "OCTET_STRING")) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(type, "OCTET_STRING")) { |
17 |
109 |
126 |
|
| 598 |
17 |
| STRLEN vlen = 0; |
| 599 |
34 |
▶ | const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : ""; |
Branch: 2 branches
| Branch | True | False | Total |
| const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : ""; |
17 |
0 |
17 |
| const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : ""; |
17 |
0 |
17 |
|
| 600 |
17 |
| s_asn1_append_tlv(aTHX_ out, 0x04, data, (unsigned long)vlen); |
| 601 |
|
| } |
| 602 |
109 |
▶ | else if (strEQ(type, "BIT_STRING")) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(type, "BIT_STRING")) { |
11 |
98 |
109 |
|
| 603 |
11 |
| STRLEN vlen = 0; |
| 604 |
22 |
▶ | const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : ""; |
Branch: 2 branches
| Branch | True | False | Total |
| const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : ""; |
11 |
0 |
11 |
| const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : ""; |
11 |
0 |
11 |
|
| 605 |
11 |
| SV **sv_bits = hv_fetchs(node, "bits", 0); |
| 606 |
11 |
▶ | unsigned long nbits = (sv_bits && SvOK(*sv_bits)) ? (unsigned long)SvUV(*sv_bits) : (unsigned long)(vlen * 8); |
Branch: 2 branches
| Branch | True | False | Total |
| unsigned long nbits = (sv_bits && SvOK(*sv_bits)) ? (unsigned long)SvUV(*sv_bits) : (unsigned long)(vlen * 8); |
11 |
0 |
11 |
| unsigned long nbits = (sv_bits && SvOK(*sv_bits)) ? (unsigned long)SvUV(*sv_bits) : (unsigned long)(vlen * 8); |
11 |
0 |
11 |
|
| 607 |
11 |
| unsigned long nbytes = (nbits + 7) / 8; |
| 608 |
11 |
▶ | unsigned char unused = (nbytes > 0) ? (unsigned char)(8 * nbytes - nbits) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| unsigned char unused = (nbytes > 0) ? (unsigned char)(8 * nbytes - nbits) : 0; |
11 |
0 |
11 |
|
| 609 |
11 |
| unsigned long content_len = 1 + nbytes; |
| 610 |
|
| unsigned char *content; |
| 611 |
|
| |
| 612 |
11 |
| Newxz(content, content_len, unsigned char); |
| 613 |
11 |
| content[0] = unused; |
| 614 |
11 |
▶ | if (nbytes > 0 && vlen > 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (nbytes > 0 && vlen > 0) { |
11 |
0 |
11 |
| if (nbytes > 0 && vlen > 0) { |
11 |
0 |
11 |
|
| 615 |
11 |
| Copy(data, content + 1, nbytes < (unsigned long)vlen ? nbytes : (unsigned long)vlen, unsigned char); |
| 616 |
11 |
▶ | if (unused > 0) content[nbytes] &= (unsigned char)(0xFF << unused); |
Branch: 1 branch
| Branch | True | False | Total |
| if (unused > 0) content[nbytes] &= (unsigned char)(0xFF << unused); |
1 |
10 |
11 |
|
| 617 |
|
| } |
| 618 |
11 |
| s_asn1_append_tlv(aTHX_ out, 0x03, content, content_len); |
| 619 |
11 |
| Safefree(content); |
| 620 |
|
| } |
| 621 |
98 |
▶ | else if (strEQ(type, "UTF8_STRING")) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(type, "UTF8_STRING")) { |
8 |
90 |
98 |
|
| 622 |
8 |
| STRLEN vlen = 0; |
| 623 |
16 |
▶ | const char *data = (sv_value && SvOK(*sv_value)) ? SvPVutf8(*sv_value, vlen) : ""; |
Branch: 2 branches
| Branch | True | False | Total |
| const char *data = (sv_value && SvOK(*sv_value)) ? SvPVutf8(*sv_value, vlen) : ""; |
8 |
0 |
8 |
| const char *data = (sv_value && SvOK(*sv_value)) ? SvPVutf8(*sv_value, vlen) : ""; |
8 |
0 |
8 |
|
| 624 |
8 |
| s_asn1_append_tlv(aTHX_ out, 0x0C, data, (unsigned long)vlen); |
| 625 |
|
| } |
| 626 |
90 |
▶ | else if (strEQ(type, "IA5_STRING")) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(type, "IA5_STRING")) { |
2 |
88 |
90 |
|
| 627 |
2 |
| STRLEN vlen = 0; |
| 628 |
4 |
▶ | const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : ""; |
Branch: 2 branches
| Branch | True | False | Total |
| const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : ""; |
2 |
0 |
2 |
| const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : ""; |
2 |
0 |
2 |
|
| 629 |
2 |
| s_asn1_append_tlv(aTHX_ out, 0x16, data, (unsigned long)vlen); |
| 630 |
|
| } |
| 631 |
88 |
▶ | else if (strEQ(type, "PRINTABLE_STRING")) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(type, "PRINTABLE_STRING")) { |
2 |
86 |
88 |
|
| 632 |
2 |
| STRLEN vlen = 0; |
| 633 |
4 |
▶ | const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : ""; |
Branch: 2 branches
| Branch | True | False | Total |
| const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : ""; |
2 |
0 |
2 |
| const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : ""; |
2 |
0 |
2 |
|
| 634 |
2 |
| s_asn1_append_tlv(aTHX_ out, 0x13, data, (unsigned long)vlen); |
| 635 |
|
| } |
| 636 |
86 |
▶ | else if (strEQ(type, "TELETEX_STRING")) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(type, "TELETEX_STRING")) { |
1 |
85 |
86 |
|
| 637 |
1 |
| STRLEN vlen = 0; |
| 638 |
2 |
▶ | const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : ""; |
Branch: 2 branches
| Branch | True | False | Total |
| const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : ""; |
1 |
0 |
1 |
| const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : ""; |
1 |
0 |
1 |
|
| 639 |
1 |
| s_asn1_append_tlv(aTHX_ out, 0x14, data, (unsigned long)vlen); |
| 640 |
|
| } |
| 641 |
85 |
▶ | else if (strEQ(type, "UTCTIME")) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(type, "UTCTIME")) { |
10 |
75 |
85 |
|
| 642 |
10 |
| STRLEN vlen = 0; |
| 643 |
20 |
▶ | const char *data = (sv_value && SvOK(*sv_value)) ? SvPV(*sv_value, vlen) : ""; |
Branch: 2 branches
| Branch | True | False | Total |
| const char *data = (sv_value && SvOK(*sv_value)) ? SvPV(*sv_value, vlen) : ""; |
10 |
0 |
10 |
| const char *data = (sv_value && SvOK(*sv_value)) ? SvPV(*sv_value, vlen) : ""; |
10 |
0 |
10 |
|
| 644 |
10 |
| s_asn1_append_tlv(aTHX_ out, 0x17, data, (unsigned long)vlen); |
| 645 |
|
| } |
| 646 |
75 |
▶ | else if (strEQ(type, "GENERALIZEDTIME")) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(type, "GENERALIZEDTIME")) { |
1 |
74 |
75 |
|
| 647 |
1 |
| STRLEN vlen = 0; |
| 648 |
2 |
▶ | const char *data = (sv_value && SvOK(*sv_value)) ? SvPV(*sv_value, vlen) : ""; |
Branch: 2 branches
| Branch | True | False | Total |
| const char *data = (sv_value && SvOK(*sv_value)) ? SvPV(*sv_value, vlen) : ""; |
1 |
0 |
1 |
| const char *data = (sv_value && SvOK(*sv_value)) ? SvPV(*sv_value, vlen) : ""; |
1 |
0 |
1 |
|
| 649 |
1 |
| s_asn1_append_tlv(aTHX_ out, 0x18, data, (unsigned long)vlen); |
| 650 |
|
| } |
| 651 |
137 |
▶ | else if (strEQ(type, "SEQUENCE") || strEQ(type, "SET")) { |
Branch: 2 branches
| Branch | True | False | Total |
| else if (strEQ(type, "SEQUENCE") || strEQ(type, "SET")) { |
19 |
55 |
74 |
| else if (strEQ(type, "SEQUENCE") || strEQ(type, "SET")) { |
8 |
11 |
19 |
|
| 652 |
63 |
▶ | unsigned char tag = strEQ(type, "SEQUENCE") ? 0x30 : 0x31; |
Branch: 1 branch
| Branch | True | False | Total |
| unsigned char tag = strEQ(type, "SEQUENCE") ? 0x30 : 0x31; |
55 |
8 |
63 |
|
| 653 |
126 |
▶ | if (sv_value && SvROK(*sv_value) && SvTYPE(SvRV(*sv_value)) == SVt_PVAV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (sv_value && SvROK(*sv_value) && SvTYPE(SvRV(*sv_value)) == SVt_PVAV) { |
63 |
0 |
63 |
| if (sv_value && SvROK(*sv_value) && SvTYPE(SvRV(*sv_value)) == SVt_PVAV) { |
63 |
0 |
63 |
| if (sv_value && SvROK(*sv_value) && SvTYPE(SvRV(*sv_value)) == SVt_PVAV) { |
63 |
0 |
63 |
|
| 654 |
63 |
| SV *content = newSVpvn("", 0); |
| 655 |
63 |
| s_asn1_encode_nodes(aTHX_ content, (AV *)SvRV(*sv_value)); |
| 656 |
63 |
| { STRLEN clen; const char *cdata = SvPV(content, clen); |
| 657 |
63 |
| s_asn1_append_tlv(aTHX_ out, tag, cdata, (unsigned long)clen); } |
| 658 |
63 |
| SvREFCNT_dec(content); |
| 659 |
|
| } else { |
| 660 |
0 |
| s_asn1_append_tlv(aTHX_ out, tag, NULL, 0); |
| 661 |
|
| } |
| 662 |
|
| } |
| 663 |
11 |
▶ | else if (strEQ(type, "CUSTOM")) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(type, "CUSTOM")) { |
11 |
0 |
11 |
|
| 664 |
11 |
| SV **sv_class = hv_fetchs(node, "class", 0); |
| 665 |
11 |
| SV **sv_constr = hv_fetchs(node, "constructed", 0); |
| 666 |
11 |
| SV **sv_tag = hv_fetchs(node, "tag", 0); |
| 667 |
11 |
▶ | unsigned int klass = (sv_class && SvOK(*sv_class)) ? (unsigned int)SvIV(*sv_class) : 2; |
Branch: 2 branches
| Branch | True | False | Total |
| unsigned int klass = (sv_class && SvOK(*sv_class)) ? (unsigned int)SvIV(*sv_class) : 2; |
11 |
0 |
11 |
| unsigned int klass = (sv_class && SvOK(*sv_class)) ? (unsigned int)SvIV(*sv_class) : 2; |
11 |
0 |
11 |
|
| 668 |
11 |
▶ | unsigned int pc = (sv_constr && SvOK(*sv_constr) && SvIV(*sv_constr)) ? 1 : 0; |
Branch: 3 branches
| Branch | True | False | Total |
| unsigned int pc = (sv_constr && SvOK(*sv_constr) && SvIV(*sv_constr)) ? 1 : 0; |
11 |
0 |
11 |
| unsigned int pc = (sv_constr && SvOK(*sv_constr) && SvIV(*sv_constr)) ? 1 : 0; |
11 |
0 |
11 |
| unsigned int pc = (sv_constr && SvOK(*sv_constr) && SvIV(*sv_constr)) ? 1 : 0; |
10 |
1 |
11 |
|
| 669 |
11 |
▶ | unsigned long tag = (sv_tag && SvOK(*sv_tag)) ? (unsigned long)SvUV(*sv_tag) : 0; |
Branch: 2 branches
| Branch | True | False | Total |
| unsigned long tag = (sv_tag && SvOK(*sv_tag)) ? (unsigned long)SvUV(*sv_tag) : 0; |
11 |
0 |
11 |
| unsigned long tag = (sv_tag && SvOK(*sv_tag)) ? (unsigned long)SvUV(*sv_tag) : 0; |
11 |
0 |
11 |
|
| 670 |
|
| |
| 671 |
21 |
▶ | if (pc && sv_value && SvROK(*sv_value) && SvTYPE(SvRV(*sv_value)) == SVt_PVAV) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (pc && sv_value && SvROK(*sv_value) && SvTYPE(SvRV(*sv_value)) == SVt_PVAV) { |
10 |
1 |
11 |
| if (pc && sv_value && SvROK(*sv_value) && SvTYPE(SvRV(*sv_value)) == SVt_PVAV) { |
10 |
0 |
10 |
| if (pc && sv_value && SvROK(*sv_value) && SvTYPE(SvRV(*sv_value)) == SVt_PVAV) { |
10 |
0 |
10 |
| if (pc && sv_value && SvROK(*sv_value) && SvTYPE(SvRV(*sv_value)) == SVt_PVAV) { |
10 |
0 |
10 |
|
| 672 |
10 |
| SV *content = newSVpvn("", 0); |
| 673 |
10 |
| s_asn1_encode_nodes(aTHX_ content, (AV *)SvRV(*sv_value)); |
| 674 |
10 |
| { STRLEN clen; const char *cdata = SvPV(content, clen); |
| 675 |
10 |
| s_asn1_append_custom_tlv(aTHX_ out, klass, pc, tag, cdata, (unsigned long)clen); } |
| 676 |
10 |
| SvREFCNT_dec(content); |
| 677 |
|
| } else { |
| 678 |
1 |
| STRLEN vlen = 0; |
| 679 |
2 |
▶ | const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : ""; |
Branch: 2 branches
| Branch | True | False | Total |
| const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : ""; |
1 |
0 |
1 |
| const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : ""; |
1 |
0 |
1 |
|
| 680 |
1 |
| s_asn1_append_custom_tlv(aTHX_ out, klass, pc, tag, data, (unsigned long)vlen); |
| 681 |
|
| } |
| 682 |
|
| } |
| 683 |
|
| else { |
| 684 |
0 |
| croak("FATAL: asn1_encode: unsupported type '%s'", type); |
| 685 |
|
| } |
| 686 |
194 |
| } |
| 687 |
|
| /* --- end Crypt::ASN1 encoder helpers ------------------------------------- */ |
| 688 |
|
| |
| 689 |
|
| typedef struct cbc_struct { /* used by Crypt::Mode::CBC */ |
| 690 |
|
| int cipher_id, cipher_rounds; |
| 691 |
|
| symmetric_CBC state; |
| 692 |
|
| unsigned char pad[MAXBLOCKSIZE]; |
| 693 |
|
| int padlen; |
| 694 |
|
| int padding_mode; |
| 695 |
|
| int direction; |
| 696 |
|
| } *Crypt__Mode__CBC; |
| 697 |
|
| |
| 698 |
|
| typedef struct ecb_struct { /* used by Crypt::Mode::ECB */ |
| 699 |
|
| int cipher_id, cipher_rounds; |
| 700 |
|
| symmetric_ECB state; |
| 701 |
|
| unsigned char pad[MAXBLOCKSIZE]; |
| 702 |
|
| int padlen; |
| 703 |
|
| int padding_mode; |
| 704 |
|
| int direction; |
| 705 |
|
| } *Crypt__Mode__ECB; |
| 706 |
|
| |
| 707 |
|
| typedef struct cfb_struct { /* used by Crypt::Mode::CFB */ |
| 708 |
|
| int cipher_id, cipher_rounds; |
| 709 |
|
| symmetric_CFB state; |
| 710 |
|
| int direction; |
| 711 |
|
| } *Crypt__Mode__CFB; |
| 712 |
|
| |
| 713 |
|
| typedef struct ctr_struct { /* used by Crypt::Mode::CTR */ |
| 714 |
|
| int cipher_id, cipher_rounds; |
| 715 |
|
| int ctr_mode_param; |
| 716 |
|
| symmetric_CTR state; |
| 717 |
|
| int direction; |
| 718 |
|
| } *Crypt__Mode__CTR; |
| 719 |
|
| |
| 720 |
|
| typedef struct f8_struct { /* used by Crypt::Mode::F8 */ |
| 721 |
|
| int cipher_id, cipher_rounds; |
| 722 |
|
| symmetric_F8 state; |
| 723 |
|
| int direction; |
| 724 |
|
| } *Crypt__Mode__F8; |
| 725 |
|
| |
| 726 |
|
| typedef struct lrw_struct { /* used by Crypt::Mode::LRW */ |
| 727 |
|
| int cipher_id, cipher_rounds; |
| 728 |
|
| symmetric_LRW state; |
| 729 |
|
| int direction; |
| 730 |
|
| } *Crypt__Mode__LRW; |
| 731 |
|
| |
| 732 |
|
| typedef struct ofb_struct { /* used by Crypt::Mode::OFB */ |
| 733 |
|
| int cipher_id, cipher_rounds; |
| 734 |
|
| symmetric_OFB state; |
| 735 |
|
| int direction; |
| 736 |
|
| } *Crypt__Mode__OFB; |
| 737 |
|
| |
| 738 |
|
| typedef struct xts_struct { /* used by Crypt::Mode::XTS */ |
| 739 |
|
| symmetric_xts state; /* the two key schedules; raw key is never kept */ |
| 740 |
|
| } *Crypt__Mode__XTS; |
| 741 |
|
| |
| 742 |
|
| typedef struct prng_struct { /* used by Crypt::PRNG */ |
| 743 |
|
| prng_state state; |
| 744 |
|
| struct ltc_prng_descriptor *desc; |
| 745 |
|
| IV last_pid; |
| 746 |
|
| } *Crypt__PRNG; |
| 747 |
|
| |
| 748 |
|
| typedef struct rsa_struct { /* used by Crypt::PK::RSA */ |
| 749 |
|
| prng_state pstate; |
| 750 |
|
| int pindex; |
| 751 |
|
| IV last_pid; |
| 752 |
|
| rsa_key key; |
| 753 |
|
| } *Crypt__PK__RSA; |
| 754 |
|
| |
| 755 |
|
| typedef struct dsa_struct { /* used by Crypt::PK::DSA */ |
| 756 |
|
| prng_state pstate; |
| 757 |
|
| int pindex; |
| 758 |
|
| IV last_pid; |
| 759 |
|
| dsa_key key; |
| 760 |
|
| } *Crypt__PK__DSA; |
| 761 |
|
| |
| 762 |
|
| typedef struct dh_struct { /* used by Crypt::PK::DH */ |
| 763 |
|
| prng_state pstate; |
| 764 |
|
| int pindex; |
| 765 |
|
| IV last_pid; |
| 766 |
|
| dh_key key; |
| 767 |
|
| } *Crypt__PK__DH; |
| 768 |
|
| |
| 769 |
|
| typedef struct ecc_struct { /* used by Crypt::PK::ECC */ |
| 770 |
|
| prng_state pstate; |
| 771 |
|
| int pindex; |
| 772 |
|
| IV last_pid; |
| 773 |
|
| ecc_key key; |
| 774 |
|
| } *Crypt__PK__ECC; |
| 775 |
|
| |
| 776 |
|
| typedef struct ed25519_struct { /* used by Crypt::PK::Ed25519 */ |
| 777 |
|
| prng_state pstate; |
| 778 |
|
| int pindex; |
| 779 |
|
| IV last_pid; |
| 780 |
|
| curve25519_key key; |
| 781 |
|
| int initialized; |
| 782 |
|
| } *Crypt__PK__Ed25519; |
| 783 |
|
| |
| 784 |
|
| typedef struct x25519_struct { /* used by Crypt::PK::X25519 */ |
| 785 |
|
| prng_state pstate; |
| 786 |
|
| int pindex; |
| 787 |
|
| IV last_pid; |
| 788 |
|
| curve25519_key key; |
| 789 |
|
| int initialized; |
| 790 |
|
| } *Crypt__PK__X25519; |
| 791 |
|
| |
| 792 |
|
| typedef struct ed448_struct { /* used by Crypt::PK::Ed448 */ |
| 793 |
|
| prng_state pstate; |
| 794 |
|
| int pindex; |
| 795 |
|
| IV last_pid; |
| 796 |
|
| curve448_key key; |
| 797 |
|
| int initialized; |
| 798 |
|
| } *Crypt__PK__Ed448; |
| 799 |
|
| |
| 800 |
|
| typedef struct x448_struct { /* used by Crypt::PK::X448 */ |
| 801 |
|
| prng_state pstate; |
| 802 |
|
| int pindex; |
| 803 |
|
| IV last_pid; |
| 804 |
|
| curve448_key key; |
| 805 |
|
| int initialized; |
| 806 |
|
| } *Crypt__PK__X448; |
| 807 |
|
| |
| 808 |
64 |
| STATIC int cryptx_internal_password_cb_getpw(void **p, unsigned long *l, void *u) { |
| 809 |
|
| dTHX; /* fetch context */ |
| 810 |
64 |
| SV *passwd = u; |
| 811 |
64 |
| void *pwd = NULL; |
| 812 |
64 |
| STRLEN pwd_len = 0; |
| 813 |
|
| |
| 814 |
64 |
▶ | if (p == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p == NULL) { |
0 |
64 |
64 |
|
| 815 |
0 |
| *l = 0; |
| 816 |
0 |
| return 1; |
| 817 |
|
| } |
| 818 |
64 |
▶ | if (passwd == NULL || !SvOK(passwd)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (passwd == NULL || !SvOK(passwd)) { |
64 |
0 |
64 |
| if (passwd == NULL || !SvOK(passwd)) { |
0 |
64 |
64 |
|
| 819 |
0 |
| *p = NULL; |
| 820 |
0 |
| *l = 0; |
| 821 |
0 |
| return 1; |
| 822 |
|
| } |
| 823 |
64 |
| pwd = SvPVbyte(passwd, pwd_len); |
| 824 |
64 |
▶ | if (pwd == NULL || pwd_len == 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (pwd == NULL || pwd_len == 0) { |
64 |
0 |
64 |
| if (pwd == NULL || pwd_len == 0) { |
0 |
64 |
64 |
|
| 825 |
0 |
| *p = NULL; |
| 826 |
0 |
| *l = 0; |
| 827 |
0 |
| return 1; |
| 828 |
|
| } |
| 829 |
64 |
| Newz(0, *p, pwd_len, unsigned char); |
| 830 |
64 |
▶ | if (*p == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*p == NULL) { |
0 |
64 |
64 |
|
| 831 |
0 |
| *l = 0; |
| 832 |
0 |
| return 1; |
| 833 |
|
| } |
| 834 |
64 |
| Copy(pwd, *p, pwd_len, unsigned char); |
| 835 |
64 |
| *l = (unsigned long)pwd_len; |
| 836 |
|
| |
| 837 |
64 |
| return 0; |
| 838 |
|
| } |
| 839 |
|
| |
| 840 |
401 |
| STATIC void cryptx_internal_pk_prng_reseed(prng_state *state, int pindex, IV *last_pid) { |
| 841 |
|
| dTHX; /* fetch context */ |
| 842 |
401 |
| IV curpid = (IV)PerlProc_getpid(); |
| 843 |
|
| unsigned char entropy_buf[40]; |
| 844 |
|
| int rv; |
| 845 |
|
| |
| 846 |
401 |
▶ | if (*last_pid == curpid) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (*last_pid == curpid) return; |
401 |
0 |
401 |
|
| 847 |
|
| |
| 848 |
0 |
▶ | if (rng_get_bytes(entropy_buf, sizeof(entropy_buf), NULL) != sizeof(entropy_buf)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (rng_get_bytes(entropy_buf, sizeof(entropy_buf), NULL) != sizeof(entropy_buf)) { |
0 |
0 |
0 |
|
| 849 |
0 |
| croak("FATAL: rng_get_bytes failed"); |
| 850 |
|
| } |
| 851 |
0 |
| rv = prng_descriptor[pindex].add_entropy(entropy_buf, sizeof(entropy_buf), state); |
| 852 |
0 |
▶ | if (rv != CRYPT_OK) croak("FATAL: PRNG_add_entropy failed: %s", error_to_string(rv)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != CRYPT_OK) croak("FATAL: PRNG_add_entropy failed: %s", error_to_string(rv)); |
0 |
0 |
0 |
|
| 853 |
0 |
| rv = prng_descriptor[pindex].ready(state); |
| 854 |
0 |
▶ | if (rv != CRYPT_OK) croak("FATAL: PRNG_ready failed: %s", error_to_string(rv)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != CRYPT_OK) croak("FATAL: PRNG_ready failed: %s", error_to_string(rv)); |
0 |
0 |
0 |
|
| 855 |
0 |
| zeromem(entropy_buf, sizeof(entropy_buf)); |
| 856 |
0 |
| *last_pid = curpid; |
| 857 |
|
| } |
| 858 |
|
| |
| 859 |
54 |
| STATIC void cryptx_internal_prng_done(struct prng_struct *prng) { |
| 860 |
54 |
▶ | if (prng != NULL && prng->desc != NULL && prng->desc->done != NULL) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (prng != NULL && prng->desc != NULL && prng->desc->done != NULL) { |
54 |
0 |
54 |
| if (prng != NULL && prng->desc != NULL && prng->desc->done != NULL) { |
54 |
0 |
54 |
| if (prng != NULL && prng->desc != NULL && prng->desc->done != NULL) { |
54 |
0 |
54 |
|
| 861 |
54 |
| (void)prng->desc->done(&prng->state); |
| 862 |
|
| } |
| 863 |
54 |
| } |
| 864 |
|
| |
| 865 |
36144 |
| STATIC void cryptx_internal_prng_reseed(struct prng_struct *prng) { |
| 866 |
|
| dTHX; /* fetch context */ |
| 867 |
36144 |
| IV curpid = (IV)PerlProc_getpid(); |
| 868 |
|
| unsigned char entropy_buf[40]; |
| 869 |
|
| int rv; |
| 870 |
|
| |
| 871 |
36144 |
▶ | if (prng == NULL || prng->desc == NULL || prng->last_pid == curpid) return; |
Branch: 3 branches
| Branch | True | False | Total |
| if (prng == NULL || prng->desc == NULL || prng->last_pid == curpid) return; |
36144 |
0 |
36144 |
| if (prng == NULL || prng->desc == NULL || prng->last_pid == curpid) return; |
36144 |
0 |
36144 |
| if (prng == NULL || prng->desc == NULL || prng->last_pid == curpid) return; |
36144 |
0 |
36144 |
|
| 872 |
|
| |
| 873 |
0 |
▶ | if (rng_get_bytes(entropy_buf, sizeof(entropy_buf), NULL) != sizeof(entropy_buf)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (rng_get_bytes(entropy_buf, sizeof(entropy_buf), NULL) != sizeof(entropy_buf)) { |
0 |
0 |
0 |
|
| 874 |
0 |
| croak("FATAL: rng_get_bytes failed"); |
| 875 |
|
| } |
| 876 |
0 |
| rv = prng->desc->add_entropy(entropy_buf, sizeof(entropy_buf), &prng->state); |
| 877 |
0 |
| zeromem(entropy_buf, sizeof(entropy_buf)); |
| 878 |
0 |
▶ | if (rv != CRYPT_OK) croak("FATAL: PRNG_add_entropy failed: %s", error_to_string(rv)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != CRYPT_OK) croak("FATAL: PRNG_add_entropy failed: %s", error_to_string(rv)); |
0 |
0 |
0 |
|
| 879 |
0 |
| rv = prng->desc->ready(&prng->state); |
| 880 |
0 |
▶ | if (rv != CRYPT_OK) croak("FATAL: PRNG_ready failed: %s", error_to_string(rv)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != CRYPT_OK) croak("FATAL: PRNG_ready failed: %s", error_to_string(rv)); |
0 |
0 |
0 |
|
| 881 |
0 |
| prng->last_pid = curpid; |
| 882 |
|
| } |
| 883 |
|
| |
| 884 |
64 |
| STATIC void cryptx_internal_password_cb_free(void *p) { |
| 885 |
|
| dTHX; /* fetch context */ |
| 886 |
64 |
| Safefree(p); |
| 887 |
64 |
| return; |
| 888 |
|
| } |
| 889 |
|
| |
| 890 |
1404 |
| STATIC int cryptx_internal_mp2hex_with_leading_zero(mp_int * a, char *str, int maxlen, int minlen) { |
| 891 |
|
| int len, rv; |
| 892 |
|
| |
| 893 |
1404 |
▶ | if (mp_isneg(a) == MP_YES) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (mp_isneg(a) == MP_YES) { |
0 |
1404 |
1404 |
|
| 894 |
0 |
| *str = '\0'; |
| 895 |
0 |
| return MP_VAL; |
| 896 |
|
| } |
| 897 |
|
| |
| 898 |
1404 |
| rv = mp_to_radix(a, str, maxlen, NULL, 16); |
| 899 |
1404 |
▶ | if (rv != MP_OKAY) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != MP_OKAY) { |
0 |
1404 |
1404 |
|
| 900 |
0 |
| *str = '\0'; |
| 901 |
0 |
| return rv; |
| 902 |
|
| } |
| 903 |
|
| |
| 904 |
1404 |
| len = (int)strlen(str); |
| 905 |
1404 |
▶ | if (len > 0 && len % 2 && len < maxlen-2) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (len > 0 && len % 2 && len < maxlen-2) { |
1404 |
0 |
1404 |
| if (len > 0 && len % 2 && len < maxlen-2) { |
275 |
1129 |
1404 |
| if (len > 0 && len % 2 && len < maxlen-2) { |
275 |
0 |
275 |
|
| 906 |
275 |
| memmove(str+1, str, len+1); /* incl. NUL byte */ |
| 907 |
275 |
| *str = '0'; /* add leading zero */ |
| 908 |
|
| } |
| 909 |
|
| |
| 910 |
1404 |
| len = (int)strlen(str); |
| 911 |
1404 |
▶ | if (len < minlen && minlen < maxlen-1) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (len < minlen && minlen < maxlen-1) { |
6 |
1398 |
1404 |
| if (len < minlen && minlen < maxlen-1) { |
6 |
0 |
6 |
|
| 912 |
6 |
| memmove(str+(minlen-len), str, len+1); /* incl. NUL byte */ |
| 913 |
6 |
| memset(str, '0', minlen-len); /* add leading zero */ |
| 914 |
|
| } |
| 915 |
|
| |
| 916 |
1404 |
| return MP_OKAY; |
| 917 |
|
| } |
| 918 |
|
| |
| 919 |
15736 |
| STATIC size_t cryptx_internal_find_start(const char *name, char *ltcname, size_t ltclen) |
| 920 |
|
| { |
| 921 |
15736 |
| size_t i, start = 0; |
| 922 |
15736 |
▶ | if (name == NULL || strlen(name) + 1 > ltclen) croak("FATAL: invalid name") ; |
Branch: 2 branches
| Branch | True | False | Total |
| if (name == NULL || strlen(name) + 1 > ltclen) croak("FATAL: invalid name") ; |
15736 |
0 |
15736 |
| if (name == NULL || strlen(name) + 1 > ltclen) croak("FATAL: invalid name") ; |
0 |
15736 |
15736 |
|
| 923 |
|
| /* normalize */ |
| 924 |
113259 |
▶ | for (i = 0; i < ltclen && name[i] > 0; i++) { |
Branch: 2 branches
| Branch | True | False | Total |
| for (i = 0; i < ltclen && name[i] > 0; i++) { |
113259 |
0 |
113259 |
| for (i = 0; i < ltclen && name[i] > 0; i++) { |
97523 |
15736 |
113259 |
|
| 925 |
97523 |
▶ | if (name[i] >= 'A' && name[i] <= 'Z') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (name[i] >= 'A' && name[i] <= 'Z') { |
71912 |
25611 |
97523 |
| if (name[i] >= 'A' && name[i] <= 'Z') { |
51366 |
20546 |
71912 |
|
| 926 |
51366 |
| ltcname[i] = name[i] + 32; /* lowecase */ |
| 927 |
|
| } |
| 928 |
46157 |
▶ | else if (name[i] == '_') { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (name[i] == '_') { |
1859 |
44298 |
46157 |
|
| 929 |
1859 |
| ltcname[i] = '-'; |
| 930 |
|
| } |
| 931 |
|
| else { |
| 932 |
44298 |
| ltcname[i] = name[i]; |
| 933 |
|
| } |
| 934 |
97523 |
▶ | if (name[i] == ':') start = i + 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (name[i] == ':') start = i + 1; |
0 |
97523 |
97523 |
|
| 935 |
|
| } |
| 936 |
15736 |
| return start; |
| 937 |
|
| } |
| 938 |
|
| |
| 939 |
8889 |
| STATIC int cryptx_internal_find_hash(const char *name) |
| 940 |
|
| { |
| 941 |
8889 |
| char ltcname[100] = { 0 }; |
| 942 |
8889 |
| size_t start = cryptx_internal_find_start(name, ltcname, sizeof(ltcname) - 1); |
| 943 |
|
| /* special cases */ |
| 944 |
8889 |
▶ | if (strcmp(ltcname + start, "ripemd128") == 0) return find_hash("rmd128"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (strcmp(ltcname + start, "ripemd128") == 0) return find_hash("rmd128"); |
472 |
8417 |
8889 |
|
| 945 |
8417 |
▶ | if (strcmp(ltcname + start, "ripemd160") == 0) return find_hash("rmd160"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (strcmp(ltcname + start, "ripemd160") == 0) return find_hash("rmd160"); |
472 |
7945 |
8417 |
|
| 946 |
7945 |
▶ | if (strcmp(ltcname + start, "ripemd256") == 0) return find_hash("rmd256"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (strcmp(ltcname + start, "ripemd256") == 0) return find_hash("rmd256"); |
84 |
7861 |
7945 |
|
| 947 |
7861 |
▶ | if (strcmp(ltcname + start, "ripemd320") == 0) return find_hash("rmd320"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (strcmp(ltcname + start, "ripemd320") == 0) return find_hash("rmd320"); |
84 |
7777 |
7861 |
|
| 948 |
7777 |
▶ | if (strcmp(ltcname + start, "tiger192") == 0) return find_hash("tiger"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (strcmp(ltcname + start, "tiger192") == 0) return find_hash("tiger"); |
490 |
7287 |
7777 |
|
| 949 |
7287 |
▶ | if (strcmp(ltcname + start, "chaes") == 0) return find_hash("chc_hash"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (strcmp(ltcname + start, "chaes") == 0) return find_hash("chc_hash"); |
184 |
7103 |
7287 |
|
| 950 |
7103 |
▶ | if (strcmp(ltcname + start, "chc-hash") == 0) return find_hash("chc_hash"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (strcmp(ltcname + start, "chc-hash") == 0) return find_hash("chc_hash"); |
0 |
7103 |
7103 |
|
| 951 |
7103 |
| return find_hash(ltcname + start); |
| 952 |
|
| } |
| 953 |
|
| |
| 954 |
6792 |
| STATIC int cryptx_internal_find_cipher(const char *name) |
| 955 |
|
| { |
| 956 |
6792 |
| char ltcname[100] = { 0 }; |
| 957 |
6792 |
| size_t start = cryptx_internal_find_start(name, ltcname, sizeof(ltcname) - 1); |
| 958 |
|
| /* special cases */ |
| 959 |
6792 |
▶ | if (strcmp(ltcname + start, "des-ede") == 0) return find_cipher("3des"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (strcmp(ltcname + start, "des-ede") == 0) return find_cipher("3des"); |
135 |
6657 |
6792 |
|
| 960 |
6657 |
▶ | if (strcmp(ltcname + start, "saferp") == 0) return find_cipher("safer+"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (strcmp(ltcname + start, "saferp") == 0) return find_cipher("safer+"); |
263 |
6394 |
6657 |
|
| 961 |
6394 |
| return find_cipher(ltcname + start); |
| 962 |
|
| } |
| 963 |
|
| |
| 964 |
55 |
| STATIC int cryptx_internal_find_prng(const char *name) |
| 965 |
|
| { |
| 966 |
55 |
| char ltcname[100] = { 0 }; |
| 967 |
55 |
| size_t start = cryptx_internal_find_start(name, ltcname, sizeof(ltcname) - 1); |
| 968 |
55 |
| return find_prng(ltcname + start); |
| 969 |
|
| } |
| 970 |
|
| |
| 971 |
|
| /* Math::BigInt::LTM related */ |
| 972 |
|
| typedef mp_int * Math__BigInt__LTM; |
| 973 |
181 |
| STATIC SV * sv_from_mpi(mp_int *mpi) { |
| 974 |
|
| dTHX; /* fetch context */ |
| 975 |
181 |
| SV *obj = newSV(0); |
| 976 |
181 |
| sv_setref_pv(obj, "Math::BigInt::LTM", (void*)mpi); |
| 977 |
181 |
| return obj; |
| 978 |
|
| } |
| 979 |
|
| |
| 980 |
2 |
| STATIC void cryptx_internal_ecc_oid_lookup(ecc_key *key) |
| 981 |
|
| { |
| 982 |
|
| int err; |
| 983 |
|
| unsigned i, j; |
| 984 |
|
| void *tmp; |
| 985 |
|
| const ltc_ecc_curve *cu; |
| 986 |
|
| |
| 987 |
2 |
| key->dp.oidlen = 0; |
| 988 |
2 |
▶ | if ((err = ltc_mp.init(&tmp)) != CRYPT_OK) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if ((err = ltc_mp.init(&tmp)) != CRYPT_OK) return; |
0 |
2 |
2 |
|
| 989 |
52 |
▶ | for (cu = ltc_ecc_curves; cu->prime != NULL; cu++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (cu = ltc_ecc_curves; cu->prime != NULL; cu++) { |
51 |
1 |
52 |
|
| 990 |
51 |
▶ | if ((err = mp_read_radix(tmp, cu->prime, 16)) != CRYPT_OK) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if ((err = mp_read_radix(tmp, cu->prime, 16)) != CRYPT_OK) continue; |
0 |
51 |
51 |
|
| 991 |
51 |
▶ | if ((mp_cmp(tmp, key->dp.prime) != LTC_MP_EQ)) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if ((mp_cmp(tmp, key->dp.prime) != LTC_MP_EQ)) continue; |
49 |
2 |
51 |
|
| 992 |
2 |
▶ | if ((err = mp_read_radix(tmp, cu->order, 16)) != CRYPT_OK) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if ((err = mp_read_radix(tmp, cu->order, 16)) != CRYPT_OK) continue; |
0 |
2 |
2 |
|
| 993 |
2 |
▶ | if ((mp_cmp(tmp, key->dp.order) != LTC_MP_EQ)) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if ((mp_cmp(tmp, key->dp.order) != LTC_MP_EQ)) continue; |
0 |
2 |
2 |
|
| 994 |
2 |
▶ | if ((err = mp_read_radix(tmp, cu->A, 16)) != CRYPT_OK) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if ((err = mp_read_radix(tmp, cu->A, 16)) != CRYPT_OK) continue; |
0 |
2 |
2 |
|
| 995 |
2 |
▶ | if ((mp_cmp(tmp, key->dp.A) != LTC_MP_EQ)) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if ((mp_cmp(tmp, key->dp.A) != LTC_MP_EQ)) continue; |
0 |
2 |
2 |
|
| 996 |
2 |
▶ | if ((err = mp_read_radix(tmp, cu->B, 16)) != CRYPT_OK) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if ((err = mp_read_radix(tmp, cu->B, 16)) != CRYPT_OK) continue; |
0 |
2 |
2 |
|
| 997 |
2 |
▶ | if ((mp_cmp(tmp, key->dp.B) != LTC_MP_EQ)) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if ((mp_cmp(tmp, key->dp.B) != LTC_MP_EQ)) continue; |
0 |
2 |
2 |
|
| 998 |
2 |
▶ | if ((err = mp_read_radix(tmp, cu->Gx, 16)) != CRYPT_OK) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if ((err = mp_read_radix(tmp, cu->Gx, 16)) != CRYPT_OK) continue; |
0 |
2 |
2 |
|
| 999 |
2 |
▶ | if ((mp_cmp(tmp, key->dp.base.x) != LTC_MP_EQ)) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if ((mp_cmp(tmp, key->dp.base.x) != LTC_MP_EQ)) continue; |
0 |
2 |
2 |
|
| 1000 |
2 |
▶ | if ((err = mp_read_radix(tmp, cu->Gy, 16)) != CRYPT_OK) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if ((err = mp_read_radix(tmp, cu->Gy, 16)) != CRYPT_OK) continue; |
0 |
2 |
2 |
|
| 1001 |
2 |
▶ | if ((mp_cmp(tmp, key->dp.base.y) != LTC_MP_EQ)) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if ((mp_cmp(tmp, key->dp.base.y) != LTC_MP_EQ)) continue; |
0 |
2 |
2 |
|
| 1002 |
2 |
▶ | if (key->dp.cofactor != cu->cofactor) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (key->dp.cofactor != cu->cofactor) continue; |
1 |
1 |
2 |
|
| 1003 |
1 |
| break; /* found */ |
| 1004 |
|
| } |
| 1005 |
2 |
| ltc_mp.deinit(tmp); |
| 1006 |
2 |
▶ | if (cu->prime && cu->OID) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (cu->prime && cu->OID) { |
1 |
1 |
2 |
| if (cu->prime && cu->OID) { |
1 |
0 |
1 |
|
| 1007 |
17 |
▶ | for (i = 0; i < 16; i++) key->dp.oid[i] = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < 16; i++) key->dp.oid[i] = 0; |
16 |
1 |
17 |
|
| 1008 |
13 |
▶ | for (i = 0, j = 0; i < strlen(cu->OID); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0, j = 0; i < strlen(cu->OID); i++) { |
12 |
1 |
13 |
|
| 1009 |
12 |
▶ | if (cu->OID[i] == '.') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cu->OID[i] == '.') { |
4 |
8 |
12 |
|
| 1010 |
4 |
▶ | if (++j >= 16) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (++j >= 16) return; |
0 |
4 |
4 |
|
| 1011 |
|
| } |
| 1012 |
8 |
▶ | else if(cu->OID[i] >= '0' && cu->OID[i] <= '9') { |
Branch: 2 branches
| Branch | True | False | Total |
| else if(cu->OID[i] >= '0' && cu->OID[i] <= '9') { |
8 |
0 |
8 |
| else if(cu->OID[i] >= '0' && cu->OID[i] <= '9') { |
8 |
0 |
8 |
|
| 1013 |
8 |
| key->dp.oid[j] = key->dp.oid[j] * 10 + (cu->OID[i] - '0'); |
| 1014 |
|
| } |
| 1015 |
|
| else { |
| 1016 |
0 |
| return; |
| 1017 |
|
| } |
| 1018 |
|
| } |
| 1019 |
1 |
| key->dp.oidlen = j + 1; |
| 1020 |
|
| } |
| 1021 |
|
| } |
| 1022 |
|
| |
| 1023 |
199 |
| STATIC int cryptx_internal_ecc_set_curve_from_SV(ecc_key *key, SV *curve) |
| 1024 |
|
| { |
| 1025 |
|
| dTHX; /* fetch context */ |
| 1026 |
|
| HV *hc, *h; |
| 1027 |
|
| SV *sv_crv, **pref; |
| 1028 |
|
| SV **sv_cofactor, **sv_prime, **sv_A, **sv_B, **sv_order, **sv_Gx, **sv_Gy, **sv_oid; |
| 1029 |
|
| char *ptr_crv; |
| 1030 |
|
| STRLEN len_crv; |
| 1031 |
|
| int err; |
| 1032 |
|
| |
| 1033 |
199 |
▶ | if (!SvOK(curve)) croak("FATAL: undefined curve"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(curve)) croak("FATAL: undefined curve"); |
0 |
199 |
199 |
|
| 1034 |
|
| |
| 1035 |
199 |
▶ | if (SvPOK_spec(curve)) { |
Branch: 5 branches
| Branch | True | False | Total |
| if (SvPOK_spec(curve)) { |
199 |
0 |
199 |
| if (SvPOK_spec(curve)) { |
2 |
197 |
199 |
| if (SvPOK_spec(curve)) { |
2 |
0 |
2 |
| if (SvPOK_spec(curve)) { |
0 |
2 |
2 |
| if (SvPOK_spec(curve)) { |
0 |
0 |
0 |
|
| 1036 |
|
| /* string */ |
| 1037 |
197 |
| ptr_crv = SvPV(curve, len_crv); |
| 1038 |
197 |
▶ | if ((hc = get_hv("Crypt::PK::ECC::curve", 0)) == NULL) croak("FATAL: no curve register"); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((hc = get_hv("Crypt::PK::ECC::curve", 0)) == NULL) croak("FATAL: no curve register"); |
0 |
197 |
197 |
|
| 1039 |
197 |
| pref = hv_fetch(hc, ptr_crv, (U32)len_crv, 0); |
| 1040 |
197 |
▶ | if (pref && SvOK(*pref)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (pref && SvOK(*pref)) { |
0 |
197 |
197 |
| if (pref && SvOK(*pref)) { |
0 |
0 |
0 |
|
| 1041 |
0 |
| sv_crv = *pref; /* found in %curve */ |
| 1042 |
|
| } |
| 1043 |
|
| else { |
| 1044 |
197 |
| sv_crv = curve; |
| 1045 |
|
| } |
| 1046 |
|
| } |
| 1047 |
2 |
▶ | else if (SvROK(curve) && SvTYPE(SvRV(curve)) == SVt_PVHV) { |
Branch: 2 branches
| Branch | True | False | Total |
| else if (SvROK(curve) && SvTYPE(SvRV(curve)) == SVt_PVHV) { |
2 |
0 |
2 |
| else if (SvROK(curve) && SvTYPE(SvRV(curve)) == SVt_PVHV) { |
2 |
0 |
2 |
|
| 1048 |
|
| /* hashref */ |
| 1049 |
2 |
| sv_crv = curve; |
| 1050 |
|
| } |
| 1051 |
|
| else { |
| 1052 |
0 |
| croak("FATAL: curve has to be a string or a hashref"); |
| 1053 |
|
| } |
| 1054 |
|
| |
| 1055 |
199 |
▶ | if (SvPOK_spec(sv_crv)) { |
Branch: 5 branches
| Branch | True | False | Total |
| if (SvPOK_spec(sv_crv)) { |
199 |
0 |
199 |
| if (SvPOK_spec(sv_crv)) { |
2 |
197 |
199 |
| if (SvPOK_spec(sv_crv)) { |
2 |
0 |
2 |
| if (SvPOK_spec(sv_crv)) { |
0 |
2 |
2 |
| if (SvPOK_spec(sv_crv)) { |
0 |
0 |
0 |
|
| 1056 |
|
| /* string - curve name */ |
| 1057 |
|
| const ltc_ecc_curve *cu; |
| 1058 |
197 |
| ptr_crv = SvPV(sv_crv, len_crv); |
| 1059 |
197 |
▶ | if (ecc_find_curve(ptr_crv, &cu) != CRYPT_OK) croak("FATAL: ecparams: unknown curve '%s'", ptr_crv); |
Branch: 1 branch
| Branch | True | False | Total |
| if (ecc_find_curve(ptr_crv, &cu) != CRYPT_OK) croak("FATAL: ecparams: unknown curve '%s'", ptr_crv); |
0 |
197 |
197 |
|
| 1060 |
197 |
| return ecc_set_curve(cu, key); |
| 1061 |
|
| } |
| 1062 |
|
| else { |
| 1063 |
|
| /* hashref */ |
| 1064 |
2 |
| ltc_ecc_curve cu = { 0 }; |
| 1065 |
|
| |
| 1066 |
2 |
▶ | if ((h = (HV*)(SvRV(sv_crv))) == NULL) croak("FATAL: ecparams: param is not valid hashref"); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((h = (HV*)(SvRV(sv_crv))) == NULL) croak("FATAL: ecparams: param is not valid hashref"); |
0 |
2 |
2 |
|
| 1067 |
|
| |
| 1068 |
2 |
▶ | if ((sv_prime = hv_fetchs(h, "prime", 0)) == NULL) croak("FATAL: ecparams: missing param prime"); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((sv_prime = hv_fetchs(h, "prime", 0)) == NULL) croak("FATAL: ecparams: missing param prime"); |
0 |
2 |
2 |
|
| 1069 |
2 |
▶ | if ((sv_A = hv_fetchs(h, "A", 0)) == NULL) croak("FATAL: ecparams: missing param A"); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((sv_A = hv_fetchs(h, "A", 0)) == NULL) croak("FATAL: ecparams: missing param A"); |
0 |
2 |
2 |
|
| 1070 |
2 |
▶ | if ((sv_B = hv_fetchs(h, "B", 0)) == NULL) croak("FATAL: ecparams: missing param B"); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((sv_B = hv_fetchs(h, "B", 0)) == NULL) croak("FATAL: ecparams: missing param B"); |
0 |
2 |
2 |
|
| 1071 |
2 |
▶ | if ((sv_order = hv_fetchs(h, "order", 0)) == NULL) croak("FATAL: ecparams: missing param order"); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((sv_order = hv_fetchs(h, "order", 0)) == NULL) croak("FATAL: ecparams: missing param order"); |
0 |
2 |
2 |
|
| 1072 |
2 |
▶ | if ((sv_Gx = hv_fetchs(h, "Gx", 0)) == NULL) croak("FATAL: ecparams: missing param Gx"); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((sv_Gx = hv_fetchs(h, "Gx", 0)) == NULL) croak("FATAL: ecparams: missing param Gx"); |
0 |
2 |
2 |
|
| 1073 |
2 |
▶ | if ((sv_Gy = hv_fetchs(h, "Gy", 0)) == NULL) croak("FATAL: ecparams: missing param Gy"); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((sv_Gy = hv_fetchs(h, "Gy", 0)) == NULL) croak("FATAL: ecparams: missing param Gy"); |
0 |
2 |
2 |
|
| 1074 |
2 |
▶ | if ((sv_cofactor = hv_fetchs(h, "cofactor", 0)) == NULL) croak("FATAL: ecparams: missing param cofactor"); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((sv_cofactor = hv_fetchs(h, "cofactor", 0)) == NULL) croak("FATAL: ecparams: missing param cofactor"); |
0 |
2 |
2 |
|
| 1075 |
|
| |
| 1076 |
2 |
▶ | if (!SvOK(*sv_prime )) croak("FATAL: ecparams: undefined param prime"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(*sv_prime )) croak("FATAL: ecparams: undefined param prime"); |
0 |
2 |
2 |
|
| 1077 |
2 |
▶ | if (!SvOK(*sv_A )) croak("FATAL: ecparams: undefined param A"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(*sv_A )) croak("FATAL: ecparams: undefined param A"); |
0 |
2 |
2 |
|
| 1078 |
2 |
▶ | if (!SvOK(*sv_B )) croak("FATAL: ecparams: undefined param B"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(*sv_B )) croak("FATAL: ecparams: undefined param B"); |
0 |
2 |
2 |
|
| 1079 |
2 |
▶ | if (!SvOK(*sv_order )) croak("FATAL: ecparams: undefined param order"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(*sv_order )) croak("FATAL: ecparams: undefined param order"); |
0 |
2 |
2 |
|
| 1080 |
2 |
▶ | if (!SvOK(*sv_Gx )) croak("FATAL: ecparams: undefined param Gx"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(*sv_Gx )) croak("FATAL: ecparams: undefined param Gx"); |
0 |
2 |
2 |
|
| 1081 |
2 |
▶ | if (!SvOK(*sv_Gy )) croak("FATAL: ecparams: undefined param Gy"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(*sv_Gy )) croak("FATAL: ecparams: undefined param Gy"); |
0 |
2 |
2 |
|
| 1082 |
2 |
▶ | if (!SvOK(*sv_cofactor)) croak("FATAL: ecparams: undefined param cofactor"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(*sv_cofactor)) croak("FATAL: ecparams: undefined param cofactor"); |
0 |
2 |
2 |
|
| 1083 |
|
| |
| 1084 |
2 |
| sv_oid = hv_fetchs(h, "oid", 0); /* 'oid' is optional */ |
| 1085 |
2 |
▶ | cu.OID = (sv_oid && SvOK(*sv_oid)) ? SvPV_nolen(*sv_oid) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| cu.OID = (sv_oid && SvOK(*sv_oid)) ? SvPV_nolen(*sv_oid) : NULL; |
0 |
2 |
2 |
| cu.OID = (sv_oid && SvOK(*sv_oid)) ? SvPV_nolen(*sv_oid) : NULL; |
0 |
0 |
0 |
|
| 1086 |
|
| |
| 1087 |
2 |
| cu.prime = SvPV_nolen(*sv_prime); |
| 1088 |
2 |
▶ | cu.A = SvPV_nolen(*sv_A); |
Branch: 1 branch
| Branch | True | False | Total |
| cu.A = SvPV_nolen(*sv_A); |
2 |
0 |
2 |
|
| 1089 |
2 |
▶ | cu.B = SvPV_nolen(*sv_B); |
Branch: 1 branch
| Branch | True | False | Total |
| cu.B = SvPV_nolen(*sv_B); |
2 |
0 |
2 |
|
| 1090 |
2 |
▶ | cu.order = SvPV_nolen(*sv_order); |
Branch: 1 branch
| Branch | True | False | Total |
| cu.order = SvPV_nolen(*sv_order); |
2 |
0 |
2 |
|
| 1091 |
2 |
▶ | cu.Gx = SvPV_nolen(*sv_Gx); |
Branch: 1 branch
| Branch | True | False | Total |
| cu.Gx = SvPV_nolen(*sv_Gx); |
2 |
0 |
2 |
|
| 1092 |
2 |
▶ | cu.Gy = SvPV_nolen(*sv_Gy); |
Branch: 1 branch
| Branch | True | False | Total |
| cu.Gy = SvPV_nolen(*sv_Gy); |
2 |
0 |
2 |
|
| 1093 |
2 |
| cu.cofactor = (unsigned long)SvUV(*sv_cofactor); |
| 1094 |
|
| |
| 1095 |
2 |
▶ | if ((err = ecc_set_curve(&cu, key)) != CRYPT_OK) return err; |
Branch: 1 branch
| Branch | True | False | Total |
| if ((err = ecc_set_curve(&cu, key)) != CRYPT_OK) return err; |
0 |
2 |
2 |
|
| 1096 |
2 |
▶ | if (key->dp.oidlen == 0) cryptx_internal_ecc_oid_lookup(key); |
Branch: 1 branch
| Branch | True | False | Total |
| if (key->dp.oidlen == 0) cryptx_internal_ecc_oid_lookup(key); |
2 |
0 |
2 |
|
| 1097 |
2 |
| return CRYPT_OK; |
| 1098 |
|
| } |
| 1099 |
|
| } |
| 1100 |
|
| |
| 1101 |
|
| MODULE = CryptX PACKAGE = CryptX PREFIX = CryptX_ |
| 1102 |
|
| |
| 1103 |
|
| PROTOTYPES: DISABLE |
| 1104 |
|
| |
| 1105 |
|
| BOOT: |
| 1106 |
160 |
▶ | if(register_all_ciphers() != CRYPT_OK) { croak("FATAL: register_all_ciphers failed"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if(register_all_ciphers() != CRYPT_OK) { croak("FATAL: register_all_ciphers failed"); } |
0 |
160 |
160 |
|
| 1107 |
160 |
▶ | if(register_all_hashes() != CRYPT_OK) { croak("FATAL: register_all_hashes failed"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if(register_all_hashes() != CRYPT_OK) { croak("FATAL: register_all_hashes failed"); } |
0 |
160 |
160 |
|
| 1108 |
160 |
▶ | if(register_all_prngs() != CRYPT_OK) { croak("FATAL: register_all_prngs failed"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if(register_all_prngs() != CRYPT_OK) { croak("FATAL: register_all_prngs failed"); } |
0 |
160 |
160 |
|
| 1109 |
160 |
▶ | if(crypt_mp_init("ltm") != CRYPT_OK) { croak("FATAL: crypt_mp_init failed"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if(crypt_mp_init("ltm") != CRYPT_OK) { croak("FATAL: crypt_mp_init failed"); } |
0 |
160 |
160 |
|
| 1110 |
|
| |
| 1111 |
|
| SV * |
| 1112 |
|
| CryptX__ltc_build_settings() |
| 1113 |
|
| CODE: |
| 1114 |
1 |
| RETVAL = newSVpv(crypt_build_settings, 0); |
| 1115 |
|
| OUTPUT: |
| 1116 |
|
| RETVAL |
| 1117 |
|
| |
| 1118 |
|
| SV * |
| 1119 |
|
| CryptX__ltc_mp_name() |
| 1120 |
|
| CODE: |
| 1121 |
1 |
| RETVAL = newSVpv(ltc_mp.name, 0); |
| 1122 |
|
| OUTPUT: |
| 1123 |
|
| RETVAL |
| 1124 |
|
| |
| 1125 |
|
| int |
| 1126 |
|
| CryptX__ltc_mp_bits_per_digit() |
| 1127 |
|
| CODE: |
| 1128 |
1 |
▶ | RETVAL = ltc_mp.bits_per_digit; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = ltc_mp.bits_per_digit; |
0 |
1 |
1 |
|
| 1129 |
|
| OUTPUT: |
| 1130 |
|
| RETVAL |
| 1131 |
|
| |
| 1132 |
|
| MODULE = CryptX PACKAGE = Crypt::Misc |
| 1133 |
|
| |
| 1134 |
|
| PROTOTYPES: DISABLE |
| 1135 |
|
| |
| 1136 |
|
| SV * |
| 1137 |
|
| _radix_to_bin(SV *in, int radix) |
| 1138 |
|
| CODE: |
| 1139 |
|
| { |
| 1140 |
|
| STRLEN in_len, len; |
| 1141 |
|
| unsigned char *out_data; |
| 1142 |
|
| char *in_data; |
| 1143 |
|
| mp_int mpi; |
| 1144 |
|
| |
| 1145 |
265 |
▶ | if (!SvPOK_spec(in) || radix < 2 || radix > 64) XSRETURN_UNDEF; |
Branch: 7 branches
| Branch | True | False | Total |
| if (!SvPOK_spec(in) || radix < 2 || radix > 64) XSRETURN_UNDEF; |
265 |
0 |
265 |
| if (!SvPOK_spec(in) || radix < 2 || radix > 64) XSRETURN_UNDEF; |
0 |
265 |
265 |
| if (!SvPOK_spec(in) || radix < 2 || radix > 64) XSRETURN_UNDEF; |
0 |
0 |
0 |
| if (!SvPOK_spec(in) || radix < 2 || radix > 64) XSRETURN_UNDEF; |
0 |
0 |
0 |
| if (!SvPOK_spec(in) || radix < 2 || radix > 64) XSRETURN_UNDEF; |
0 |
0 |
0 |
| if (!SvPOK_spec(in) || radix < 2 || radix > 64) XSRETURN_UNDEF; |
265 |
0 |
265 |
| if (!SvPOK_spec(in) || radix < 2 || radix > 64) XSRETURN_UNDEF; |
0 |
265 |
265 |
|
| 1146 |
265 |
| in_data = SvPVbyte(in, in_len); |
| 1147 |
265 |
▶ | if (in_len > 0 && memchr(in_data, '\0', in_len) != NULL) XSRETURN_UNDEF; |
Branch: 2 branches
| Branch | True | False | Total |
| if (in_len > 0 && memchr(in_data, '\0', in_len) != NULL) XSRETURN_UNDEF; |
265 |
0 |
265 |
| if (in_len > 0 && memchr(in_data, '\0', in_len) != NULL) XSRETURN_UNDEF; |
0 |
265 |
265 |
|
| 1148 |
265 |
▶ | if (mp_init(&mpi) != MP_OKAY) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (mp_init(&mpi) != MP_OKAY) XSRETURN_UNDEF; |
0 |
265 |
265 |
|
| 1149 |
265 |
▶ | if (in_len == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (in_len == 0) { |
0 |
265 |
265 |
|
| 1150 |
0 |
| RETVAL = newSVpvn("", 0); |
| 1151 |
|
| } |
| 1152 |
265 |
▶ | else if (mp_read_radix(&mpi, in_data, radix) == MP_OKAY) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (mp_read_radix(&mpi, in_data, radix) == MP_OKAY) { |
265 |
0 |
265 |
|
| 1153 |
265 |
| len = mp_ubin_size(&mpi); |
| 1154 |
265 |
▶ | if (len == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len == 0) { |
0 |
265 |
265 |
|
| 1155 |
0 |
| RETVAL = newSVpvn("", 0); |
| 1156 |
|
| } |
| 1157 |
|
| else { |
| 1158 |
265 |
| RETVAL = NEWSV(0, len); /* avoid zero! */ |
| 1159 |
265 |
| SvPOK_only(RETVAL); |
| 1160 |
265 |
| SvCUR_set(RETVAL, len); |
| 1161 |
265 |
| *SvEND(RETVAL) = '\0'; |
| 1162 |
265 |
| out_data = (unsigned char *)SvPVX(RETVAL); |
| 1163 |
265 |
▶ | if (mp_to_ubin(&mpi, out_data, len, NULL) != MP_OKAY) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (mp_to_ubin(&mpi, out_data, len, NULL) != MP_OKAY) { |
0 |
265 |
265 |
|
| 1164 |
0 |
| SvREFCNT_dec(RETVAL); |
| 1165 |
0 |
| RETVAL = newSVpvn(NULL, 0); /* undef */ |
| 1166 |
|
| } |
| 1167 |
|
| } |
| 1168 |
|
| } |
| 1169 |
|
| else { |
| 1170 |
0 |
| RETVAL = newSVpvn(NULL, 0); /* undef */ |
| 1171 |
|
| } |
| 1172 |
265 |
| mp_clear(&mpi); |
| 1173 |
|
| } |
| 1174 |
|
| OUTPUT: |
| 1175 |
|
| RETVAL |
| 1176 |
|
| |
| 1177 |
|
| SV * |
| 1178 |
|
| _bin_to_radix(SV *in, int radix) |
| 1179 |
|
| CODE: |
| 1180 |
|
| { |
| 1181 |
|
| STRLEN len; |
| 1182 |
|
| unsigned char *in_data; |
| 1183 |
|
| char *out_data; |
| 1184 |
|
| mp_int mpi, tmp; |
| 1185 |
|
| mp_digit d; |
| 1186 |
|
| mp_err merr; |
| 1187 |
290 |
| int digits = 0; |
| 1188 |
|
| |
| 1189 |
290 |
▶ | if (!SvPOK_spec(in) || radix < 2 || radix > 64) XSRETURN_UNDEF; |
Branch: 7 branches
| Branch | True | False | Total |
| if (!SvPOK_spec(in) || radix < 2 || radix > 64) XSRETURN_UNDEF; |
290 |
0 |
290 |
| if (!SvPOK_spec(in) || radix < 2 || radix > 64) XSRETURN_UNDEF; |
0 |
290 |
290 |
| if (!SvPOK_spec(in) || radix < 2 || radix > 64) XSRETURN_UNDEF; |
0 |
0 |
0 |
| if (!SvPOK_spec(in) || radix < 2 || radix > 64) XSRETURN_UNDEF; |
0 |
0 |
0 |
| if (!SvPOK_spec(in) || radix < 2 || radix > 64) XSRETURN_UNDEF; |
0 |
0 |
0 |
| if (!SvPOK_spec(in) || radix < 2 || radix > 64) XSRETURN_UNDEF; |
290 |
0 |
290 |
| if (!SvPOK_spec(in) || radix < 2 || radix > 64) XSRETURN_UNDEF; |
0 |
290 |
290 |
|
| 1190 |
290 |
| in_data = (unsigned char *) SvPVbyte(in, len); |
| 1191 |
290 |
▶ | if (mp_init_multi(&mpi, &tmp, NULL) != MP_OKAY) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (mp_init_multi(&mpi, &tmp, NULL) != MP_OKAY) XSRETURN_UNDEF; |
0 |
290 |
290 |
|
| 1192 |
290 |
▶ | if (len == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len == 0) { |
0 |
290 |
290 |
|
| 1193 |
0 |
| RETVAL = newSVpvn("", 0); |
| 1194 |
|
| } |
| 1195 |
|
| else { |
| 1196 |
290 |
▶ | if (mp_from_ubin(&mpi, in_data, (size_t)len) == MP_OKAY) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (mp_from_ubin(&mpi, in_data, (size_t)len) == MP_OKAY) { |
290 |
0 |
290 |
|
| 1197 |
290 |
| merr = mp_copy(&mpi, &tmp); |
| 1198 |
5655 |
▶ | while (merr == MP_OKAY && mp_iszero(&tmp) == MP_NO) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (merr == MP_OKAY && mp_iszero(&tmp) == MP_NO) { |
5655 |
0 |
5655 |
| while (merr == MP_OKAY && mp_iszero(&tmp) == MP_NO) { |
5365 |
290 |
5655 |
|
| 1199 |
5365 |
| merr = mp_div_d(&tmp, (mp_digit)radix, &tmp, &d); |
| 1200 |
5365 |
| digits++; |
| 1201 |
|
| } |
| 1202 |
290 |
▶ | if (merr != MP_OKAY) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (merr != MP_OKAY) { |
0 |
290 |
290 |
|
| 1203 |
0 |
| RETVAL = newSVpvn(NULL, 0); /* undef */ |
| 1204 |
|
| } |
| 1205 |
290 |
▶ | else if (digits == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (digits == 0) { |
25 |
265 |
290 |
|
| 1206 |
25 |
| RETVAL = newSVpvn("", 0); |
| 1207 |
|
| } |
| 1208 |
|
| else { |
| 1209 |
265 |
| RETVAL = NEWSV(0, digits + 2); /* +2 for sign and NUL byte */ |
| 1210 |
265 |
| SvPOK_only(RETVAL); |
| 1211 |
265 |
| out_data = SvPVX(RETVAL); |
| 1212 |
265 |
▶ | if (mp_to_radix(&mpi, out_data, digits + 2, NULL, radix) == MP_OKAY) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (mp_to_radix(&mpi, out_data, digits + 2, NULL, radix) == MP_OKAY) { |
265 |
0 |
265 |
|
| 1213 |
265 |
| SvCUR_set(RETVAL, strlen(out_data)); |
| 1214 |
|
| } |
| 1215 |
|
| else { |
| 1216 |
0 |
| SvREFCNT_dec(RETVAL); |
| 1217 |
0 |
| RETVAL = newSVpvn(NULL, 0); /* undef */ |
| 1218 |
|
| } |
| 1219 |
|
| } |
| 1220 |
|
| } |
| 1221 |
|
| else { |
| 1222 |
0 |
| RETVAL = newSVpvn(NULL, 0); /* undef */ |
| 1223 |
|
| } |
| 1224 |
|
| } |
| 1225 |
290 |
| mp_clear_multi(&tmp, &mpi, NULL); |
| 1226 |
|
| } |
| 1227 |
|
| OUTPUT: |
| 1228 |
|
| RETVAL |
| 1229 |
|
| |
| 1230 |
|
| SV * |
| 1231 |
|
| encode_b64(SV * in) |
| 1232 |
|
| ALIAS: |
| 1233 |
|
| encode_b64u = 1 |
| 1234 |
|
| CODE: |
| 1235 |
|
| { |
| 1236 |
|
| int rv; |
| 1237 |
|
| STRLEN in_len; |
| 1238 |
|
| unsigned long out_len; |
| 1239 |
|
| unsigned char *in_data; |
| 1240 |
|
| char *out_data; |
| 1241 |
|
| |
| 1242 |
174 |
▶ | if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
Branch: 5 branches
| Branch | True | False | Total |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
173 |
1 |
174 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
1 |
172 |
173 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
1 |
0 |
1 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
1 |
0 |
1 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
0 |
1 |
1 |
|
| 1243 |
173 |
| in_data = (unsigned char *) SvPVbyte(in, in_len); |
| 1244 |
173 |
▶ | if (in_len == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (in_len == 0) { |
0 |
173 |
173 |
|
| 1245 |
0 |
| RETVAL = newSVpvn("", 0); |
| 1246 |
|
| } |
| 1247 |
|
| else { |
| 1248 |
173 |
| out_len = (unsigned long)(4 * ((in_len + 2) / 3) + 1); |
| 1249 |
173 |
| RETVAL = NEWSV(0, out_len); /* avoid zero! */ |
| 1250 |
173 |
| SvPOK_only(RETVAL); |
| 1251 |
173 |
| out_data = SvPVX(RETVAL); |
| 1252 |
173 |
▶ | if (ix == 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ix == 1) |
59 |
114 |
173 |
|
| 1253 |
59 |
| rv = base64url_encode(in_data, (unsigned long)in_len, out_data, &out_len); |
| 1254 |
|
| else |
| 1255 |
114 |
| rv = base64_encode(in_data, (unsigned long)in_len, out_data, &out_len); |
| 1256 |
173 |
▶ | if (rv != CRYPT_OK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != CRYPT_OK) { |
0 |
173 |
173 |
|
| 1257 |
0 |
| SvREFCNT_dec(RETVAL); |
| 1258 |
0 |
| XSRETURN_UNDEF; |
| 1259 |
|
| } |
| 1260 |
173 |
| SvCUR_set(RETVAL, out_len); |
| 1261 |
|
| } |
| 1262 |
|
| } |
| 1263 |
|
| OUTPUT: |
| 1264 |
|
| RETVAL |
| 1265 |
|
| |
| 1266 |
|
| SV * |
| 1267 |
|
| decode_b64(SV * in) |
| 1268 |
|
| ALIAS: |
| 1269 |
|
| decode_b64u = 1 |
| 1270 |
|
| CODE: |
| 1271 |
|
| { |
| 1272 |
|
| int rv; |
| 1273 |
|
| STRLEN in_len; |
| 1274 |
|
| unsigned long out_len; |
| 1275 |
|
| unsigned char *out_data; |
| 1276 |
|
| char *in_data; |
| 1277 |
|
| |
| 1278 |
436 |
▶ | if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
Branch: 5 branches
| Branch | True | False | Total |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
430 |
1 |
431 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
1 |
429 |
430 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
1 |
0 |
1 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
1 |
0 |
1 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
0 |
1 |
1 |
|
| 1279 |
430 |
| in_data = SvPVbyte(in, in_len); |
| 1280 |
430 |
▶ | if (in_len == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (in_len == 0) { |
0 |
430 |
430 |
|
| 1281 |
0 |
| RETVAL = newSVpvn("", 0); |
| 1282 |
|
| } |
| 1283 |
|
| else { |
| 1284 |
430 |
▶ | if (cryptx_internal_input_has_no_payload(in_data, in_len)) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (cryptx_internal_input_has_no_payload(in_data, in_len)) XSRETURN_UNDEF; |
5 |
425 |
430 |
|
| 1285 |
425 |
| out_len = (unsigned long)in_len; |
| 1286 |
425 |
| RETVAL = NEWSV(0, out_len); /* avoid zero! */ |
| 1287 |
425 |
| SvPOK_only(RETVAL); |
| 1288 |
425 |
| out_data = (unsigned char *)SvPVX(RETVAL); |
| 1289 |
425 |
▶ | if (ix == 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ix == 1) |
76 |
349 |
425 |
|
| 1290 |
76 |
| rv = base64url_sane_decode(in_data, (unsigned long)in_len, out_data, &out_len); |
| 1291 |
|
| else |
| 1292 |
349 |
| rv = base64_sane_decode(in_data, (unsigned long)in_len, out_data, &out_len); |
| 1293 |
425 |
▶ | if (rv != CRYPT_OK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != CRYPT_OK) { |
0 |
425 |
425 |
|
| 1294 |
0 |
| SvREFCNT_dec(RETVAL); |
| 1295 |
0 |
| XSRETURN_UNDEF; |
| 1296 |
|
| } |
| 1297 |
425 |
| SvCUR_set(RETVAL, out_len); |
| 1298 |
425 |
| *SvEND(RETVAL) = '\0'; |
| 1299 |
|
| } |
| 1300 |
|
| } |
| 1301 |
|
| OUTPUT: |
| 1302 |
|
| RETVAL |
| 1303 |
|
| |
| 1304 |
|
| SV * |
| 1305 |
|
| encode_b32r(SV *in) |
| 1306 |
|
| ALIAS: |
| 1307 |
|
| encode_b32b = 1 |
| 1308 |
|
| encode_b32z = 2 |
| 1309 |
|
| encode_b32c = 3 |
| 1310 |
|
| CODE: |
| 1311 |
|
| { |
| 1312 |
|
| STRLEN in_len; |
| 1313 |
|
| unsigned long out_len; |
| 1314 |
|
| unsigned char *in_data; |
| 1315 |
|
| char *out_data; |
| 1316 |
235 |
| int id = -1, err; |
| 1317 |
|
| |
| 1318 |
235 |
▶ | if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
Branch: 5 branches
| Branch | True | False | Total |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
234 |
1 |
235 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
1 |
233 |
234 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
1 |
0 |
1 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
1 |
0 |
1 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
0 |
1 |
1 |
|
| 1319 |
234 |
▶ | if (ix == 0) id = BASE32_RFC4648; |
Branch: 1 branch
| Branch | True | False | Total |
| if (ix == 0) id = BASE32_RFC4648; |
60 |
174 |
234 |
|
| 1320 |
234 |
▶ | if (ix == 1) id = BASE32_BASE32HEX; |
Branch: 1 branch
| Branch | True | False | Total |
| if (ix == 1) id = BASE32_BASE32HEX; |
58 |
176 |
234 |
|
| 1321 |
234 |
▶ | if (ix == 2) id = BASE32_ZBASE32; |
Branch: 1 branch
| Branch | True | False | Total |
| if (ix == 2) id = BASE32_ZBASE32; |
58 |
176 |
234 |
|
| 1322 |
234 |
▶ | if (ix == 3) id = BASE32_CROCKFORD; |
Branch: 1 branch
| Branch | True | False | Total |
| if (ix == 3) id = BASE32_CROCKFORD; |
58 |
176 |
234 |
|
| 1323 |
234 |
▶ | if (id == -1) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (id == -1) XSRETURN_UNDEF; |
0 |
234 |
234 |
|
| 1324 |
234 |
| in_data = (unsigned char *) SvPVbyte(in, in_len); |
| 1325 |
234 |
▶ | if (in_len == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (in_len == 0) { |
0 |
234 |
234 |
|
| 1326 |
0 |
| RETVAL = newSVpvn("", 0); |
| 1327 |
|
| } |
| 1328 |
|
| else { |
| 1329 |
234 |
| out_len = (unsigned long)((8 * in_len + 4) / 5 + 1); |
| 1330 |
234 |
| RETVAL = NEWSV(0, out_len); /* avoid zero! */ |
| 1331 |
234 |
| SvPOK_only(RETVAL); |
| 1332 |
234 |
| out_data = SvPVX(RETVAL); |
| 1333 |
234 |
| err = base32_encode(in_data, (unsigned long)in_len, out_data, &out_len, id); |
| 1334 |
234 |
▶ | if (err != CRYPT_OK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (err != CRYPT_OK) { |
0 |
234 |
234 |
|
| 1335 |
0 |
| SvREFCNT_dec(RETVAL); |
| 1336 |
0 |
| XSRETURN_UNDEF; |
| 1337 |
|
| } |
| 1338 |
234 |
| SvCUR_set(RETVAL, out_len); |
| 1339 |
|
| } |
| 1340 |
|
| } |
| 1341 |
|
| OUTPUT: |
| 1342 |
|
| RETVAL |
| 1343 |
|
| |
| 1344 |
|
| SV * |
| 1345 |
|
| decode_b32r(SV *in) |
| 1346 |
|
| ALIAS: |
| 1347 |
|
| decode_b32b = 1 |
| 1348 |
|
| decode_b32z = 2 |
| 1349 |
|
| decode_b32c = 3 |
| 1350 |
|
| CODE: |
| 1351 |
|
| { |
| 1352 |
|
| STRLEN in_len; |
| 1353 |
|
| unsigned long out_len; |
| 1354 |
|
| unsigned char *out_data; |
| 1355 |
|
| char *in_data; |
| 1356 |
237 |
| int id = -1, err; |
| 1357 |
|
| |
| 1358 |
241 |
▶ | if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
Branch: 5 branches
| Branch | True | False | Total |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
236 |
1 |
237 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
0 |
236 |
236 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
0 |
0 |
0 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
0 |
0 |
0 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
0 |
0 |
0 |
|
| 1359 |
236 |
▶ | if (ix == 0) id = BASE32_RFC4648; |
Branch: 1 branch
| Branch | True | False | Total |
| if (ix == 0) id = BASE32_RFC4648; |
60 |
176 |
236 |
|
| 1360 |
236 |
▶ | if (ix == 1) id = BASE32_BASE32HEX; |
Branch: 1 branch
| Branch | True | False | Total |
| if (ix == 1) id = BASE32_BASE32HEX; |
59 |
177 |
236 |
|
| 1361 |
236 |
▶ | if (ix == 2) id = BASE32_ZBASE32; |
Branch: 1 branch
| Branch | True | False | Total |
| if (ix == 2) id = BASE32_ZBASE32; |
58 |
178 |
236 |
|
| 1362 |
236 |
▶ | if (ix == 3) id = BASE32_CROCKFORD; |
Branch: 1 branch
| Branch | True | False | Total |
| if (ix == 3) id = BASE32_CROCKFORD; |
59 |
177 |
236 |
|
| 1363 |
236 |
▶ | if (id == -1) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (id == -1) XSRETURN_UNDEF; |
0 |
236 |
236 |
|
| 1364 |
236 |
| in_data = SvPVbyte(in, in_len); |
| 1365 |
236 |
▶ | if (in_len == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (in_len == 0) { |
0 |
236 |
236 |
|
| 1366 |
0 |
| RETVAL = newSVpvn("", 0); |
| 1367 |
|
| } |
| 1368 |
|
| else { |
| 1369 |
236 |
▶ | if (cryptx_internal_input_has_no_payload(in_data, in_len)) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (cryptx_internal_input_has_no_payload(in_data, in_len)) XSRETURN_UNDEF; |
4 |
232 |
236 |
|
| 1370 |
232 |
| out_len = (unsigned long)in_len; |
| 1371 |
232 |
| RETVAL = NEWSV(0, out_len); /* avoid zero! */ |
| 1372 |
232 |
| SvPOK_only(RETVAL); |
| 1373 |
232 |
| out_data = (unsigned char *)SvPVX(RETVAL); |
| 1374 |
232 |
| err = base32_decode(in_data, (unsigned long)in_len, out_data, &out_len, id); |
| 1375 |
232 |
▶ | if (err != CRYPT_OK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (err != CRYPT_OK) { |
0 |
232 |
232 |
|
| 1376 |
0 |
| SvREFCNT_dec(RETVAL); |
| 1377 |
0 |
| XSRETURN_UNDEF; |
| 1378 |
|
| } |
| 1379 |
232 |
| SvCUR_set(RETVAL, out_len); |
| 1380 |
232 |
| *SvEND(RETVAL) = '\0'; |
| 1381 |
|
| } |
| 1382 |
|
| } |
| 1383 |
|
| OUTPUT: |
| 1384 |
|
| RETVAL |
| 1385 |
|
| |
| 1386 |
|
| SV * |
| 1387 |
|
| increment_octets_le(SV * in) |
| 1388 |
|
| CODE: |
| 1389 |
|
| { |
| 1390 |
6 |
| STRLEN len, i = 0; |
| 1391 |
|
| unsigned char *out_data, *in_data; |
| 1392 |
|
| |
| 1393 |
6 |
▶ | if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
Branch: 5 branches
| Branch | True | False | Total |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
6 |
0 |
6 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
0 |
6 |
6 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
0 |
0 |
0 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
0 |
0 |
0 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
0 |
0 |
0 |
|
| 1394 |
6 |
| in_data = (unsigned char *)SvPVbyte(in, len); |
| 1395 |
6 |
▶ | if (len == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len == 0) { |
0 |
6 |
6 |
|
| 1396 |
0 |
| RETVAL = newSVpvn("", 0); |
| 1397 |
|
| } |
| 1398 |
|
| else { |
| 1399 |
6 |
| RETVAL = NEWSV(0, len); /* avoid zero! */ |
| 1400 |
6 |
| SvPOK_only(RETVAL); |
| 1401 |
6 |
| SvCUR_set(RETVAL, len); |
| 1402 |
6 |
| *SvEND(RETVAL) = '\0'; |
| 1403 |
6 |
| out_data = (unsigned char *)SvPVX(RETVAL); |
| 1404 |
6 |
| Copy(in_data, out_data, len, unsigned char); |
| 1405 |
13 |
▶ | while (i < len) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (i < len) { |
11 |
2 |
13 |
|
| 1406 |
11 |
| out_data[i]++; |
| 1407 |
11 |
▶ | if (0 != out_data[i]) break; |
Branch: 1 branch
| Branch | True | False | Total |
| if (0 != out_data[i]) break; |
4 |
7 |
11 |
|
| 1408 |
7 |
| i++; |
| 1409 |
|
| } |
| 1410 |
6 |
▶ | if (i == len) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (i == len) { |
2 |
4 |
6 |
|
| 1411 |
2 |
| SvREFCNT_dec(RETVAL); |
| 1412 |
2 |
| croak("FATAL: increment_octets_le overflow"); |
| 1413 |
|
| } |
| 1414 |
|
| } |
| 1415 |
|
| } |
| 1416 |
|
| OUTPUT: |
| 1417 |
|
| RETVAL |
| 1418 |
|
| |
| 1419 |
|
| SV * |
| 1420 |
|
| increment_octets_be(SV * in) |
| 1421 |
|
| CODE: |
| 1422 |
|
| { |
| 1423 |
18 |
| STRLEN len, i = 0; |
| 1424 |
|
| unsigned char *out_data, *in_data; |
| 1425 |
|
| |
| 1426 |
18 |
▶ | if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
Branch: 5 branches
| Branch | True | False | Total |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
18 |
0 |
18 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
1 |
17 |
18 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
1 |
0 |
1 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
1 |
0 |
1 |
| if (!SvPOK_spec(in)) XSRETURN_UNDEF; |
0 |
1 |
1 |
|
| 1427 |
18 |
| in_data = (unsigned char *)SvPVbyte(in, len); |
| 1428 |
18 |
▶ | if (len == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len == 0) { |
0 |
18 |
18 |
|
| 1429 |
0 |
| RETVAL = newSVpvn("", 0); |
| 1430 |
|
| } |
| 1431 |
|
| else { |
| 1432 |
18 |
| RETVAL = NEWSV(0, len); /* avoid zero! */ |
| 1433 |
18 |
| SvPOK_only(RETVAL); |
| 1434 |
18 |
| SvCUR_set(RETVAL, len); |
| 1435 |
18 |
| *SvEND(RETVAL) = '\0'; |
| 1436 |
18 |
| out_data = (unsigned char *)SvPVX(RETVAL); |
| 1437 |
18 |
| Copy(in_data, out_data, len, unsigned char); |
| 1438 |
25 |
▶ | while (i < len) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (i < len) { |
23 |
2 |
25 |
|
| 1439 |
23 |
| out_data[len - 1 - i]++; |
| 1440 |
23 |
▶ | if (0 != out_data[len - 1 - i]) break; |
Branch: 1 branch
| Branch | True | False | Total |
| if (0 != out_data[len - 1 - i]) break; |
16 |
7 |
23 |
|
| 1441 |
7 |
| i++; |
| 1442 |
|
| } |
| 1443 |
18 |
▶ | if (i == len) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (i == len) { |
2 |
16 |
18 |
|
| 1444 |
2 |
| SvREFCNT_dec(RETVAL); |
| 1445 |
2 |
| croak("FATAL: increment_octets_be overflow"); |
| 1446 |
|
| } |
| 1447 |
|
| } |
| 1448 |
|
| } |
| 1449 |
|
| OUTPUT: |
| 1450 |
|
| RETVAL |
| 1451 |
|
| |
| 1452 |
|
| SV * |
| 1453 |
|
| slow_eq(SV *a, SV *b) |
| 1454 |
|
| CODE: |
| 1455 |
|
| { |
| 1456 |
|
| STRLEN a_len, b_len; |
| 1457 |
|
| unsigned char *a_data, *b_data; |
| 1458 |
|
| const void *first; |
| 1459 |
9 |
| int result = 0; |
| 1460 |
|
| |
| 1461 |
9 |
▶ | if (!SvPOK_spec(a) || !SvPOK_spec(b)) XSRETURN_UNDEF; |
Branch: 10 branches
| Branch | True | False | Total |
| if (!SvPOK_spec(a) || !SvPOK_spec(b)) XSRETURN_UNDEF; |
8 |
1 |
9 |
| if (!SvPOK_spec(a) || !SvPOK_spec(b)) XSRETURN_UNDEF; |
0 |
8 |
8 |
| if (!SvPOK_spec(a) || !SvPOK_spec(b)) XSRETURN_UNDEF; |
0 |
0 |
0 |
| if (!SvPOK_spec(a) || !SvPOK_spec(b)) XSRETURN_UNDEF; |
0 |
0 |
0 |
| if (!SvPOK_spec(a) || !SvPOK_spec(b)) XSRETURN_UNDEF; |
0 |
0 |
0 |
| if (!SvPOK_spec(a) || !SvPOK_spec(b)) XSRETURN_UNDEF; |
8 |
0 |
8 |
| if (!SvPOK_spec(a) || !SvPOK_spec(b)) XSRETURN_UNDEF; |
0 |
8 |
8 |
| if (!SvPOK_spec(a) || !SvPOK_spec(b)) XSRETURN_UNDEF; |
0 |
0 |
0 |
| if (!SvPOK_spec(a) || !SvPOK_spec(b)) XSRETURN_UNDEF; |
0 |
0 |
0 |
| if (!SvPOK_spec(a) || !SvPOK_spec(b)) XSRETURN_UNDEF; |
0 |
0 |
0 |
|
| 1462 |
8 |
▶ | a_data = (unsigned char *)SvPVbyte(a, a_len); |
Branch: 1 branch
| Branch | True | False | Total |
| a_data = (unsigned char *)SvPVbyte(a, a_len); |
8 |
0 |
8 |
|
| 1463 |
8 |
| b_data = (unsigned char *)SvPVbyte(b, b_len); |
| 1464 |
8 |
| first = a_data; |
| 1465 |
8 |
▶ | if (a_len != b_len) { first = b_data; result = 1; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (a_len != b_len) { first = b_data; result = 1; } |
2 |
6 |
8 |
|
| 1466 |
8 |
| result |= mem_neq(first, b_data, b_len); |
| 1467 |
8 |
| RETVAL = newSViv(result == 0 ? 1 : 0); |
| 1468 |
|
| } |
| 1469 |
|
| OUTPUT: |
| 1470 |
|
| RETVAL |
| 1471 |
|
| |
| 1472 |
|
| ############################################################################### |
| 1473 |
|
| |
| 1474 |
|
| INCLUDE: inc/CryptX_ASN1.xs.inc |
| 1475 |
|
| INCLUDE: inc/CryptX_Digest.xs.inc |
| 1476 |
|
| INCLUDE: inc/CryptX_Digest_SHAKE.xs.inc |
| 1477 |
|
| INCLUDE: inc/CryptX_Digest_TurboSHAKE.xs.inc |
| 1478 |
|
| INCLUDE: inc/CryptX_Digest_KangarooTwelve.xs.inc |
| 1479 |
|
| INCLUDE: inc/CryptX_Cipher.xs.inc |
| 1480 |
|
| |
| 1481 |
|
| INCLUDE: inc/CryptX_Checksum_Adler32.xs.inc |
| 1482 |
|
| INCLUDE: inc/CryptX_Checksum_CRC32.xs.inc |
| 1483 |
|
| |
| 1484 |
|
| INCLUDE: inc/CryptX_AuthEnc_EAX.xs.inc |
| 1485 |
|
| INCLUDE: inc/CryptX_AuthEnc_GCM.xs.inc |
| 1486 |
|
| INCLUDE: inc/CryptX_AuthEnc_OCB.xs.inc |
| 1487 |
|
| INCLUDE: inc/CryptX_AuthEnc_CCM.xs.inc |
| 1488 |
|
| INCLUDE: inc/CryptX_AuthEnc_ChaCha20Poly1305.xs.inc |
| 1489 |
|
| INCLUDE: inc/CryptX_AuthEnc_SIV.xs.inc |
| 1490 |
|
| INCLUDE: inc/CryptX_AuthEnc_GCMSIV.xs.inc |
| 1491 |
|
| |
| 1492 |
|
| INCLUDE: inc/CryptX_Stream_ChaCha.xs.inc |
| 1493 |
|
| INCLUDE: inc/CryptX_Stream_XChaCha.xs.inc |
| 1494 |
|
| INCLUDE: inc/CryptX_Stream_Salsa20.xs.inc |
| 1495 |
|
| INCLUDE: inc/CryptX_Stream_XSalsa20.xs.inc |
| 1496 |
|
| INCLUDE: inc/CryptX_Stream_RC4.xs.inc |
| 1497 |
|
| INCLUDE: inc/CryptX_Stream_Sober128.xs.inc |
| 1498 |
|
| INCLUDE: inc/CryptX_Stream_Sosemanuk.xs.inc |
| 1499 |
|
| INCLUDE: inc/CryptX_Stream_Rabbit.xs.inc |
| 1500 |
|
| |
| 1501 |
|
| INCLUDE: inc/CryptX_Mac_F9.xs.inc |
| 1502 |
|
| INCLUDE: inc/CryptX_Mac_HMAC.xs.inc |
| 1503 |
|
| INCLUDE: inc/CryptX_Mac_OMAC.xs.inc |
| 1504 |
|
| INCLUDE: inc/CryptX_Mac_Pelican.xs.inc |
| 1505 |
|
| INCLUDE: inc/CryptX_Mac_PMAC.xs.inc |
| 1506 |
|
| INCLUDE: inc/CryptX_Mac_XCBC.xs.inc |
| 1507 |
|
| INCLUDE: inc/CryptX_Mac_Poly1305.xs.inc |
| 1508 |
|
| INCLUDE: inc/CryptX_Mac_BLAKE2s.xs.inc |
| 1509 |
|
| INCLUDE: inc/CryptX_Mac_BLAKE2b.xs.inc |
| 1510 |
|
| INCLUDE: inc/CryptX_Mac_KMAC.xs.inc |
| 1511 |
|
| |
| 1512 |
|
| INCLUDE: inc/CryptX_Mode_CBC.xs.inc |
| 1513 |
|
| INCLUDE: inc/CryptX_Mode_ECB.xs.inc |
| 1514 |
|
| INCLUDE: inc/CryptX_Mode_CFB.xs.inc |
| 1515 |
|
| INCLUDE: inc/CryptX_Mode_OFB.xs.inc |
| 1516 |
|
| INCLUDE: inc/CryptX_Mode_CTR.xs.inc |
| 1517 |
|
| #INCLUDE: inc/CryptX_Mode_F8.xs.inc |
| 1518 |
|
| #INCLUDE: inc/CryptX_Mode_LRW.xs.inc |
| 1519 |
|
| INCLUDE: inc/CryptX_Mode_XTS.xs.inc |
| 1520 |
|
| |
| 1521 |
|
| INCLUDE: inc/CryptX_PRNG.xs.inc |
| 1522 |
|
| |
| 1523 |
|
| INCLUDE: inc/CryptX_PK_RSA.xs.inc |
| 1524 |
|
| INCLUDE: inc/CryptX_PK_DSA.xs.inc |
| 1525 |
|
| INCLUDE: inc/CryptX_PK_DH.xs.inc |
| 1526 |
|
| INCLUDE: inc/CryptX_PK_ECC.xs.inc |
| 1527 |
|
| INCLUDE: inc/CryptX_PK_Ed25519.xs.inc |
| 1528 |
|
| INCLUDE: inc/CryptX_PK_X25519.xs.inc |
| 1529 |
|
| INCLUDE: inc/CryptX_PK_Ed448.xs.inc |
| 1530 |
|
| INCLUDE: inc/CryptX_PK_X448.xs.inc |
| 1531 |
|
| |
| 1532 |
|
| INCLUDE: inc/CryptX_KeyDerivation.xs.inc |
| 1533 |
|
| |
| 1534 |
|
| INCLUDE: inc/CryptX_BigInt_LTM.xs.inc |