line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#include "EXTERN.h" |
2
|
|
|
|
|
|
|
#include "perl.h" |
3
|
|
|
|
|
|
|
#include "XSUB.h" |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
15
|
|
|
|
|
|
static int do_compare(unsigned char *a, unsigned char *b, size_t n) { |
8
|
|
|
|
|
|
|
size_t i; |
9
|
15
|
|
|
|
|
|
unsigned char r = 0; |
10
|
|
|
|
|
|
|
|
11
|
5695
|
100
|
|
|
|
|
for (i = 0; i < n; i++) { |
12
|
5680
|
|
|
|
|
|
r |= *a++ ^ *b++; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
15
|
|
|
|
|
|
return r; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
MODULE = String::Compare::ConstantTime PACKAGE = String::Compare::ConstantTime |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
PROTOTYPES: ENABLE |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
int |
27
|
|
|
|
|
|
|
equals(a, b) |
28
|
|
|
|
|
|
|
SV *a |
29
|
|
|
|
|
|
|
SV *b |
30
|
|
|
|
|
|
|
CODE: |
31
|
|
|
|
|
|
|
size_t alen; |
32
|
|
|
|
|
|
|
unsigned char *ap; |
33
|
|
|
|
|
|
|
size_t blen; |
34
|
|
|
|
|
|
|
unsigned char *bp; |
35
|
|
|
|
|
|
|
int r; |
36
|
|
|
|
|
|
|
|
37
|
21
|
100
|
|
|
|
|
SvGETMAGIC(a); |
|
|
50
|
|
|
|
|
|
38
|
21
|
100
|
|
|
|
|
SvGETMAGIC(b); |
|
|
50
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
21
|
100
|
|
|
|
|
if (SvOK(a) && SvOK(b)) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
41
|
18
|
|
|
|
|
|
alen = sv_len_utf8(a); |
42
|
18
|
100
|
|
|
|
|
ap = SvPV(a, alen); |
43
|
|
|
|
|
|
|
|
44
|
18
|
|
|
|
|
|
blen = sv_len_utf8(b); |
45
|
18
|
100
|
|
|
|
|
bp = SvPV(b, blen); |
46
|
|
|
|
|
|
|
|
47
|
36
|
100
|
|
|
|
|
if (alen == blen) { |
48
|
15
|
|
|
|
|
|
r = !do_compare(ap, bp, alen); |
49
|
|
|
|
|
|
|
} else { |
50
|
3
|
|
|
|
|
|
r = 0; |
51
|
|
|
|
|
|
|
} |
52
|
3
|
100
|
|
|
|
|
} else if (SvOK(a) || SvOK(b)) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
53
|
2
|
|
|
|
|
|
r = 0; |
54
|
|
|
|
|
|
|
} else { |
55
|
1
|
|
|
|
|
|
r = 1; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
21
|
|
|
|
|
|
RETVAL = r; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
OUTPUT: |
61
|
|
|
|
|
|
|
RETVAL |