| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
/* |
|
2
|
|
|
|
|
|
|
* Copyright (C) 1995, 1996 Systemics Ltd (http://www.systemics.com/) |
|
3
|
|
|
|
|
|
|
* All rights reserved. |
|
4
|
|
|
|
|
|
|
*/ |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
#include "EXTERN.h" |
|
7
|
|
|
|
|
|
|
#include "perl.h" |
|
8
|
|
|
|
|
|
|
#include "XSUB.h" |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#include "idea.h" |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#ifndef sv_undef |
|
13
|
|
|
|
|
|
|
#define sv_undef PL_sv_undef |
|
14
|
|
|
|
|
|
|
#endif |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
MODULE = Crypt::IDEA PACKAGE = Crypt::IDEA PREFIX = idea_ |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
char * |
|
19
|
|
|
|
|
|
|
idea_expand_key(key) |
|
20
|
|
|
|
|
|
|
char * key = NO_INIT |
|
21
|
|
|
|
|
|
|
STRLEN key_len = NO_INIT |
|
22
|
|
|
|
|
|
|
CODE: |
|
23
|
|
|
|
|
|
|
{ |
|
24
|
|
|
|
|
|
|
idea_ks ks; |
|
25
|
|
|
|
|
|
|
|
|
26
|
11
|
|
|
|
|
|
key = (char *) SvPV(ST(0), key_len); |
|
27
|
11
|
|
|
|
|
|
if (key_len != sizeof(idea_user_key)) |
|
28
|
0
|
|
|
|
|
|
croak("Invalid key"); |
|
29
|
|
|
|
|
|
|
|
|
30
|
11
|
|
|
|
|
|
idea_expand_key((u_int16_t *)key, ks); |
|
31
|
|
|
|
|
|
|
|
|
32
|
11
|
|
|
|
|
|
ST(0) = sv_2mortal(newSVpv((char *)ks, sizeof(ks))); |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
char * |
|
36
|
|
|
|
|
|
|
idea_invert_key(ks) |
|
37
|
|
|
|
|
|
|
char * ks = NO_INIT |
|
38
|
|
|
|
|
|
|
STRLEN ks_len = NO_INIT |
|
39
|
|
|
|
|
|
|
CODE: |
|
40
|
|
|
|
|
|
|
{ |
|
41
|
|
|
|
|
|
|
u_int16_t iks[52]; |
|
42
|
|
|
|
|
|
|
|
|
43
|
11
|
|
|
|
|
|
ks = (char *) SvPV(ST(0), ks_len); |
|
44
|
11
|
|
|
|
|
|
if (ks_len != sizeof(idea_ks)) |
|
45
|
0
|
|
|
|
|
|
croak("Invalid key schedule"); |
|
46
|
|
|
|
|
|
|
|
|
47
|
11
|
|
|
|
|
|
idea_invert_key((u_int16_t *)ks, iks); |
|
48
|
|
|
|
|
|
|
|
|
49
|
11
|
|
|
|
|
|
ST(0) = sv_2mortal(newSVpv((char *)iks, sizeof(iks))); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
void |
|
53
|
|
|
|
|
|
|
idea_crypt(input, output, ks) |
|
54
|
|
|
|
|
|
|
char * input = NO_INIT |
|
55
|
|
|
|
|
|
|
SV * output |
|
56
|
|
|
|
|
|
|
char * ks = NO_INIT |
|
57
|
|
|
|
|
|
|
STRLEN input_len = NO_INIT |
|
58
|
|
|
|
|
|
|
STRLEN output_len = NO_INIT |
|
59
|
|
|
|
|
|
|
STRLEN ks_len = NO_INIT |
|
60
|
|
|
|
|
|
|
CODE: |
|
61
|
|
|
|
|
|
|
{ |
|
62
|
22
|
|
|
|
|
|
input = (char *) SvPV(ST(0), input_len); |
|
63
|
22
|
|
|
|
|
|
if (input_len != 8) |
|
64
|
0
|
|
|
|
|
|
croak("input must be 8 bytes long"); |
|
65
|
|
|
|
|
|
|
|
|
66
|
22
|
|
|
|
|
|
ks = (char *) SvPV(ST(2), ks_len); |
|
67
|
22
|
|
|
|
|
|
if (ks_len != sizeof(idea_ks)) |
|
68
|
0
|
|
|
|
|
|
croak("Invalid key schedule"); |
|
69
|
|
|
|
|
|
|
|
|
70
|
22
|
|
|
|
|
|
if (output == &sv_undef) |
|
71
|
0
|
|
|
|
|
|
output = sv_newmortal(); |
|
72
|
|
|
|
|
|
|
output_len = 8; |
|
73
|
|
|
|
|
|
|
|
|
74
|
22
|
|
|
|
|
|
if (!SvUPGRADE(output, SVt_PV)) |
|
75
|
0
|
|
|
|
|
|
croak("cannot use output argument as lvalue"); |
|
76
|
|
|
|
|
|
|
|
|
77
|
22
|
|
|
|
|
|
idea_crypt((u_int16_t *)input, (u_int16_t *)SvGROW(output, output_len), (u_int16_t *)ks); |
|
78
|
|
|
|
|
|
|
|
|
79
|
22
|
|
|
|
|
|
SvCUR_set(output, output_len); |
|
80
|
22
|
|
|
|
|
|
*SvEND(output) = '\0'; |
|
81
|
22
|
|
|
|
|
|
(void) SvPOK_only(output); |
|
82
|
22
|
|
|
|
|
|
SvTAINT(output); |
|
83
|
|
|
|
|
|
|
|
|
84
|
22
|
|
|
|
|
|
ST(0) = output; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|