line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
MODULE = CryptX PACKAGE = Crypt::Mac::HMAC |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
PROTOTYPES: DISABLE |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY! |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Crypt::Mac::HMAC |
8
|
|
|
|
|
|
|
new(Class, char * hash_name, SV * key) |
9
|
|
|
|
|
|
|
CODE: |
10
|
|
|
|
|
|
|
{ |
11
|
1769
|
|
|
|
|
|
STRLEN k_len=0; |
12
|
1769
|
|
|
|
|
|
unsigned char *k=NULL; |
13
|
|
|
|
|
|
|
int rv; |
14
|
|
|
|
|
|
|
int id; |
15
|
|
|
|
|
|
|
|
16
|
1769
|
|
|
|
|
|
id = cryptx_internal_find_hash(hash_name); |
17
|
1769
|
50
|
|
|
|
|
if (id == -1) croak("FATAL: find_hash failed for '%s'", hash_name); |
18
|
|
|
|
|
|
|
|
19
|
1769
|
50
|
|
|
|
|
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar"); |
20
|
1769
|
50
|
|
|
|
|
k = (unsigned char *) SvPVbyte(key, k_len); |
21
|
|
|
|
|
|
|
|
22
|
1769
|
|
|
|
|
|
Newz(0, RETVAL, 1, hmac_state); |
23
|
1769
|
50
|
|
|
|
|
if (!RETVAL) croak("FATAL: Newz failed"); |
24
|
|
|
|
|
|
|
|
25
|
1769
|
|
|
|
|
|
rv = hmac_init(RETVAL, id, k, (unsigned long)k_len); |
26
|
1769
|
50
|
|
|
|
|
if (rv != CRYPT_OK) { |
27
|
0
|
|
|
|
|
|
Safefree(RETVAL); |
28
|
0
|
|
|
|
|
|
croak("FATAL: hmac_init failed: %s", error_to_string(rv)); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
OUTPUT: |
32
|
|
|
|
|
|
|
RETVAL |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
void |
35
|
|
|
|
|
|
|
DESTROY(Crypt::Mac::HMAC self) |
36
|
|
|
|
|
|
|
CODE: |
37
|
1769
|
|
|
|
|
|
Safefree(self); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Crypt::Mac::HMAC |
40
|
|
|
|
|
|
|
clone(Crypt::Mac::HMAC self) |
41
|
|
|
|
|
|
|
CODE: |
42
|
0
|
|
|
|
|
|
Newz(0, RETVAL, 1, hmac_state); |
43
|
0
|
0
|
|
|
|
|
if (!RETVAL) croak("FATAL: Newz failed"); |
44
|
0
|
|
|
|
|
|
Copy(self, RETVAL, 1, hmac_state); |
45
|
|
|
|
|
|
|
OUTPUT: |
46
|
|
|
|
|
|
|
RETVAL |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
void |
49
|
|
|
|
|
|
|
add(Crypt::Mac::HMAC self, ...) |
50
|
|
|
|
|
|
|
PPCODE: |
51
|
|
|
|
|
|
|
{ |
52
|
|
|
|
|
|
|
int rv, i; |
53
|
|
|
|
|
|
|
STRLEN in_data_len; |
54
|
|
|
|
|
|
|
unsigned char *in_data; |
55
|
|
|
|
|
|
|
|
56
|
3554
|
100
|
|
|
|
|
for(i = 1; i < items; i++) { |
57
|
1781
|
100
|
|
|
|
|
in_data = (unsigned char *)SvPVbyte(ST(i), in_data_len); |
58
|
1781
|
100
|
|
|
|
|
if (in_data_len > 0) { |
59
|
1760
|
|
|
|
|
|
rv = hmac_process(self, in_data, (unsigned long)in_data_len); |
60
|
1760
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: hmac_process failed: %s", error_to_string(rv)); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
1773
|
50
|
|
|
|
|
XPUSHs(ST(0)); /* return self */ |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
SV * |
67
|
|
|
|
|
|
|
mac(Crypt::Mac::HMAC self) |
68
|
|
|
|
|
|
|
ALIAS: |
69
|
|
|
|
|
|
|
hexmac = 1 |
70
|
|
|
|
|
|
|
b64mac = 2 |
71
|
|
|
|
|
|
|
b64umac = 3 |
72
|
|
|
|
|
|
|
CODE: |
73
|
|
|
|
|
|
|
{ |
74
|
|
|
|
|
|
|
unsigned char mac[MAXBLOCKSIZE]; |
75
|
|
|
|
|
|
|
unsigned long maclen, outlen; |
76
|
|
|
|
|
|
|
int rv; |
77
|
|
|
|
|
|
|
char out[MAXBLOCKSIZE*2+1]; |
78
|
|
|
|
|
|
|
|
79
|
1769
|
|
|
|
|
|
maclen = sizeof(mac); |
80
|
1769
|
|
|
|
|
|
rv = hmac_done(self, mac, &maclen); |
81
|
1769
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: hmac_done failed: %s", error_to_string(rv)); |
82
|
1769
|
|
|
|
|
|
outlen = sizeof(out); |
83
|
1769
|
100
|
|
|
|
|
if (ix == 3) { |
84
|
1
|
|
|
|
|
|
rv = base64url_encode(mac, maclen, out, &outlen); |
85
|
1
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv)); |
86
|
1
|
|
|
|
|
|
RETVAL = newSVpvn(out, outlen); |
87
|
|
|
|
|
|
|
} |
88
|
1768
|
100
|
|
|
|
|
else if (ix == 2) { |
89
|
1
|
|
|
|
|
|
rv = base64_encode(mac, maclen, out, &outlen); |
90
|
1
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv)); |
91
|
1
|
|
|
|
|
|
RETVAL = newSVpvn(out, outlen); |
92
|
|
|
|
|
|
|
} |
93
|
1767
|
100
|
|
|
|
|
else if (ix == 1) { |
94
|
14
|
|
|
|
|
|
rv = base16_encode(mac, maclen, out, &outlen, 0); |
95
|
14
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
96
|
14
|
|
|
|
|
|
RETVAL = newSVpvn(out, outlen); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
else { |
99
|
1753
|
|
|
|
|
|
RETVAL = newSVpvn((char * )mac, maclen); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
OUTPUT: |
103
|
|
|
|
|
|
|
RETVAL |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
SV * |
106
|
|
|
|
|
|
|
hmac(char * hash_name, SV * key, ...) |
107
|
|
|
|
|
|
|
ALIAS: |
108
|
|
|
|
|
|
|
hmac_hex = 1 |
109
|
|
|
|
|
|
|
hmac_b64 = 2 |
110
|
|
|
|
|
|
|
hmac_b64u = 3 |
111
|
|
|
|
|
|
|
CODE: |
112
|
|
|
|
|
|
|
{ |
113
|
|
|
|
|
|
|
STRLEN inlen, klen; |
114
|
|
|
|
|
|
|
unsigned char *in; |
115
|
88
|
50
|
|
|
|
|
unsigned char *k = (unsigned char *)SvPVbyte(key, klen); |
116
|
|
|
|
|
|
|
int rv, i; |
117
|
|
|
|
|
|
|
unsigned char mac[MAXBLOCKSIZE]; |
118
|
88
|
|
|
|
|
|
unsigned long len = sizeof(mac), outlen; |
119
|
|
|
|
|
|
|
char out[MAXBLOCKSIZE*2]; |
120
|
|
|
|
|
|
|
hmac_state st; |
121
|
|
|
|
|
|
|
|
122
|
88
|
|
|
|
|
|
int id = cryptx_internal_find_hash(hash_name); |
123
|
88
|
50
|
|
|
|
|
if (id == -1) croak("FATAL: find_digest failed for '%s'", hash_name); |
124
|
88
|
|
|
|
|
|
rv = hmac_init(&st, id, k, (unsigned long)klen); |
125
|
88
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: hmac_init failed: %s", error_to_string(rv)); |
126
|
184
|
100
|
|
|
|
|
for (i = 2; i < items; i++) { |
127
|
96
|
100
|
|
|
|
|
in = (unsigned char *)SvPVbyte(ST(i), inlen); |
128
|
96
|
100
|
|
|
|
|
if (inlen > 0) { |
129
|
80
|
|
|
|
|
|
rv = hmac_process(&st, in, (unsigned long)inlen); |
130
|
80
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: hmac_process failed: %s", error_to_string(rv)); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
} |
133
|
88
|
|
|
|
|
|
rv = hmac_done(&st, mac, &len); |
134
|
88
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: hmac_done failed: %s", error_to_string(rv)); |
135
|
|
|
|
|
|
|
|
136
|
88
|
|
|
|
|
|
outlen = sizeof(out); |
137
|
88
|
100
|
|
|
|
|
if (ix == 3) { |
138
|
13
|
|
|
|
|
|
rv = base64url_encode(mac, len, out, &outlen); |
139
|
13
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv)); |
140
|
13
|
|
|
|
|
|
RETVAL = newSVpvn((char *) out, outlen); |
141
|
|
|
|
|
|
|
} |
142
|
75
|
100
|
|
|
|
|
else if (ix == 2) { |
143
|
13
|
|
|
|
|
|
rv = base64_encode(mac, len, out, &outlen); |
144
|
13
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv)); |
145
|
13
|
|
|
|
|
|
RETVAL = newSVpvn(out, outlen); |
146
|
|
|
|
|
|
|
} |
147
|
62
|
100
|
|
|
|
|
else if (ix == 1) { |
148
|
49
|
|
|
|
|
|
rv = base16_encode(mac, len, out, &outlen, 0); |
149
|
49
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
150
|
49
|
|
|
|
|
|
RETVAL = newSVpvn(out, outlen); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
else { |
153
|
13
|
|
|
|
|
|
RETVAL = newSVpvn((char *) mac, len); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
OUTPUT: |
157
|
|
|
|
|
|
|
RETVAL |