line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
MODULE = CryptX PACKAGE = Crypt::Digest |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
PROTOTYPES: DISABLE |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Crypt::Digest |
6
|
|
|
|
|
|
|
new(char * cname, char * pname = NULL) |
7
|
|
|
|
|
|
|
CODE: |
8
|
|
|
|
|
|
|
{ |
9
|
|
|
|
|
|
|
int rv; |
10
|
|
|
|
|
|
|
int id; |
11
|
3158
|
100
|
|
|
|
|
char *digest_name = strcmp(cname, "Crypt::Digest") == 0 ? pname : cname; |
12
|
|
|
|
|
|
|
|
13
|
3158
|
|
|
|
|
|
id = cryptx_internal_find_hash(digest_name); |
14
|
3158
|
50
|
|
|
|
|
if (id == -1) croak("FATAL: find_hash failed for '%s'", digest_name); |
15
|
|
|
|
|
|
|
|
16
|
3158
|
|
|
|
|
|
Newz(0, RETVAL, 1, struct digest_struct); |
17
|
3158
|
50
|
|
|
|
|
if (!RETVAL) croak("FATAL: Newz failed"); |
18
|
|
|
|
|
|
|
|
19
|
3158
|
|
|
|
|
|
RETVAL->desc = &hash_descriptor[id]; |
20
|
3158
|
|
|
|
|
|
rv = RETVAL->desc->init(&RETVAL->state); |
21
|
3158
|
50
|
|
|
|
|
if (rv != CRYPT_OK) { |
22
|
0
|
|
|
|
|
|
Safefree(RETVAL); |
23
|
0
|
|
|
|
|
|
croak("FATAL: digest setup failed: %s", error_to_string(rv)); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
OUTPUT: |
27
|
|
|
|
|
|
|
RETVAL |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
void |
30
|
|
|
|
|
|
|
DESTROY(Crypt::Digest self) |
31
|
|
|
|
|
|
|
CODE: |
32
|
3158
|
|
|
|
|
|
Safefree(self); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
void |
35
|
|
|
|
|
|
|
reset(Crypt::Digest self) |
36
|
|
|
|
|
|
|
PPCODE: |
37
|
|
|
|
|
|
|
{ |
38
|
|
|
|
|
|
|
int rv; |
39
|
0
|
|
|
|
|
|
rv = self->desc->init(&self->state); |
40
|
0
|
0
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: digest init failed: %s", error_to_string(rv)); |
41
|
0
|
0
|
|
|
|
|
XPUSHs(ST(0)); /* return self */ |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Crypt::Digest |
45
|
|
|
|
|
|
|
clone(Crypt::Digest self) |
46
|
|
|
|
|
|
|
CODE: |
47
|
0
|
|
|
|
|
|
Newz(0, RETVAL, 1, struct digest_struct); |
48
|
0
|
0
|
|
|
|
|
if (!RETVAL) croak("FATAL: Newz failed"); |
49
|
0
|
|
|
|
|
|
Copy(&self->state, &RETVAL->state, 1, struct digest_struct); |
50
|
|
|
|
|
|
|
OUTPUT: |
51
|
|
|
|
|
|
|
RETVAL |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
void |
54
|
|
|
|
|
|
|
add(Crypt::Digest self, ...) |
55
|
|
|
|
|
|
|
PPCODE: |
56
|
|
|
|
|
|
|
{ |
57
|
|
|
|
|
|
|
STRLEN inlen; |
58
|
|
|
|
|
|
|
int rv, i; |
59
|
|
|
|
|
|
|
unsigned char *in; |
60
|
|
|
|
|
|
|
|
61
|
6382
|
100
|
|
|
|
|
for(i = 1; i < items; i++) { |
62
|
3224
|
50
|
|
|
|
|
in = (unsigned char *)SvPVbyte(ST(i), inlen); |
63
|
3224
|
100
|
|
|
|
|
if (inlen > 0) { |
64
|
3178
|
|
|
|
|
|
rv = self->desc->process(&self->state, in, (unsigned long)inlen); |
65
|
3178
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: digest process failed: %s", error_to_string(rv)); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
3158
|
50
|
|
|
|
|
XPUSHs(ST(0)); /* return self */ |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
SV * |
72
|
|
|
|
|
|
|
digest(Crypt::Digest self) |
73
|
|
|
|
|
|
|
ALIAS: |
74
|
|
|
|
|
|
|
hexdigest = 1 |
75
|
|
|
|
|
|
|
b64digest = 2 |
76
|
|
|
|
|
|
|
b64udigest = 3 |
77
|
|
|
|
|
|
|
CODE: |
78
|
|
|
|
|
|
|
{ |
79
|
|
|
|
|
|
|
int rv; |
80
|
|
|
|
|
|
|
unsigned long outlen; |
81
|
|
|
|
|
|
|
unsigned char hash[MAXBLOCKSIZE]; |
82
|
|
|
|
|
|
|
char out[MAXBLOCKSIZE*2+1]; |
83
|
|
|
|
|
|
|
|
84
|
3092
|
|
|
|
|
|
rv = self->desc->done(&self->state, hash); |
85
|
3092
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: digest done failed: %s", error_to_string(rv)); |
86
|
|
|
|
|
|
|
|
87
|
3092
|
|
|
|
|
|
outlen = sizeof(out); |
88
|
3092
|
100
|
|
|
|
|
if (ix == 3) { |
89
|
132
|
|
|
|
|
|
rv = base64url_encode(hash, self->desc->hashsize, out, &outlen); |
90
|
132
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv)); |
91
|
132
|
|
|
|
|
|
RETVAL = newSVpvn(out, outlen); |
92
|
|
|
|
|
|
|
} |
93
|
2960
|
100
|
|
|
|
|
else if (ix == 2) { |
94
|
264
|
|
|
|
|
|
rv = base64_encode(hash, self->desc->hashsize, out, &outlen); |
95
|
264
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv)); |
96
|
264
|
|
|
|
|
|
RETVAL = newSVpvn(out, outlen); |
97
|
|
|
|
|
|
|
} |
98
|
2696
|
100
|
|
|
|
|
else if (ix == 1) { |
99
|
2432
|
|
|
|
|
|
rv = base16_encode(hash, self->desc->hashsize, out, &outlen, 0); |
100
|
2432
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
101
|
2432
|
|
|
|
|
|
RETVAL = newSVpvn(out, outlen); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
else { |
104
|
264
|
|
|
|
|
|
RETVAL = newSVpvn((char *) hash, self->desc->hashsize); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
OUTPUT: |
108
|
|
|
|
|
|
|
RETVAL |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
SV * |
111
|
|
|
|
|
|
|
digest_data(char * digest_name, ...) |
112
|
|
|
|
|
|
|
ALIAS: |
113
|
|
|
|
|
|
|
digest_data_hex = 1 |
114
|
|
|
|
|
|
|
digest_data_b64 = 2 |
115
|
|
|
|
|
|
|
digest_data_b64u = 3 |
116
|
|
|
|
|
|
|
CODE: |
117
|
|
|
|
|
|
|
{ |
118
|
|
|
|
|
|
|
STRLEN inlen; |
119
|
|
|
|
|
|
|
int rv, id, i; |
120
|
|
|
|
|
|
|
unsigned char *in, hash[MAXBLOCKSIZE]; |
121
|
1005
|
|
|
|
|
|
unsigned long len = sizeof(hash), outlen; |
122
|
|
|
|
|
|
|
char out[MAXBLOCKSIZE*2+1]; |
123
|
|
|
|
|
|
|
hash_state md; |
124
|
|
|
|
|
|
|
|
125
|
1005
|
|
|
|
|
|
id = cryptx_internal_find_hash(digest_name); |
126
|
1005
|
50
|
|
|
|
|
if (id == -1) croak("FATAL: find_digest failed for '%s'", digest_name); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
/* digest_data("SHA1", $data1, $data2, $data3); */ |
129
|
1005
|
|
|
|
|
|
len = hash_descriptor[id].hashsize; |
130
|
1005
|
|
|
|
|
|
rv = hash_descriptor[id].init(&md); |
131
|
1005
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: digest init failed: %s", error_to_string(rv)); |
132
|
2538
|
100
|
|
|
|
|
for (i = 1; i < items; i++) { |
133
|
1533
|
50
|
|
|
|
|
in = (unsigned char *)SvPVbyte(ST(i), inlen); |
134
|
1533
|
100
|
|
|
|
|
if (inlen > 0) { |
135
|
1302
|
|
|
|
|
|
rv = hash_descriptor[id].process(&md, in, (unsigned long)inlen); |
136
|
1302
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: digest process failed: %s", error_to_string(rv)); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
1005
|
|
|
|
|
|
rv = hash_descriptor[id].done(&md, hash); |
140
|
1005
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: digest done failed: %s", error_to_string(rv)); |
141
|
|
|
|
|
|
|
|
142
|
1005
|
|
|
|
|
|
outlen = sizeof(out); |
143
|
1005
|
100
|
|
|
|
|
if (ix == 3) { |
144
|
165
|
|
|
|
|
|
rv = base64url_encode(hash, len, out, &outlen); |
145
|
165
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv)); |
146
|
165
|
|
|
|
|
|
RETVAL = newSVpvn(out, outlen); |
147
|
|
|
|
|
|
|
} |
148
|
840
|
100
|
|
|
|
|
else if (ix == 2) { |
149
|
264
|
|
|
|
|
|
rv = base64_encode(hash, len, out, &outlen); |
150
|
264
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv)); |
151
|
264
|
|
|
|
|
|
RETVAL = newSVpvn(out, outlen); |
152
|
|
|
|
|
|
|
} |
153
|
576
|
100
|
|
|
|
|
else if (ix == 1) { |
154
|
264
|
|
|
|
|
|
rv = base16_encode(hash, len, out, &outlen, 0); |
155
|
264
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
156
|
264
|
|
|
|
|
|
RETVAL = newSVpvn(out, outlen); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
else { |
159
|
312
|
|
|
|
|
|
RETVAL = newSVpvn((char *) hash, len); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
OUTPUT: |
163
|
|
|
|
|
|
|
RETVAL |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
int |
166
|
|
|
|
|
|
|
hashsize(SV * param, char * extra = NULL) |
167
|
|
|
|
|
|
|
CODE: |
168
|
|
|
|
|
|
|
{ |
169
|
2016
|
100
|
|
|
|
|
if (sv_isobject(param) && sv_derived_from(param, "Crypt::Digest")) { |
|
|
50
|
|
|
|
|
|
170
|
66
|
50
|
|
|
|
|
IV tmp = SvIV((SV*)SvRV(param)); |
171
|
66
|
|
|
|
|
|
Crypt__Digest obj = INT2PTR(Crypt__Digest, tmp); |
172
|
66
|
|
|
|
|
|
RETVAL = obj->desc->hashsize; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
else { |
175
|
|
|
|
|
|
|
char *digest_name; |
176
|
|
|
|
|
|
|
int rv, id; |
177
|
1884
|
50
|
|
|
|
|
digest_name = SvPOK(param) && strcmp(SvPVX(param), "Crypt::Digest") ? SvPVX(param) : extra; |
|
|
100
|
|
|
|
|
|
178
|
1884
|
|
|
|
|
|
id = cryptx_internal_find_hash(digest_name); |
179
|
1884
|
50
|
|
|
|
|
if (id == -1) croak("FATAL: find_hash failed for '%s'", digest_name); |
180
|
1884
|
|
|
|
|
|
rv = hash_descriptor[id].hashsize; |
181
|
1884
|
50
|
|
|
|
|
if (!rv) croak("FATAL: invalid hashsize for '%s'", digest_name);; |
182
|
1884
|
|
|
|
|
|
RETVAL = rv; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
OUTPUT: |
186
|
|
|
|
|
|
|
RETVAL |