1 /*
2 * cross-platform and mod_ssl-safe code modifications are Copyright (C)
3 * 2000 W3Works, LLC. All rights reserved.
4 */
5
6 /*
7 * Copyright (C) 1995, 1996 Systemics Ltd (http://www.systemics.com/)
8 * All rights reserved.
9 */
10
11 #include "EXTERN.h"
12 #include "perl.h"
13 #include "XSUB.h"
14
15 typedef unsigned char i8;
16 typedef unsigned long i32;
17
18 #include "_des.h"
19
20 #ifndef sv_undef
21 #define sv_undef PL_sv_undef
22 #endif
23
24 MODULE = Crypt::DES PACKAGE = Crypt::DES PREFIX = _des_
25 PROTOTYPES: DISABLE
26
27 char *
_des_expand_key(key)28 _des_expand_key(key)
29 char * key = NO_INIT
30 STRLEN key_len = NO_INIT
31 CODE:
32 {
33 des_ks ks;
34
35 key = (char *) SvPV(ST(0), key_len);
36 if (key_len != sizeof(des_user_key))
37 croak("Invalid key");
38
39 perl_des_expand_key((i8 *)key, ks);
40
41 ST(0) = sv_2mortal(newSVpv((char *)ks, sizeof(ks)));
42 }
43
44 void
_des_crypt(input,output,ks,enc_flag)45 _des_crypt(input, output, ks, enc_flag)
46 char * input = NO_INIT
47 SV * output
48 char * ks = NO_INIT
49 int enc_flag
50 STRLEN input_len = NO_INIT
51 STRLEN output_len = NO_INIT
52 STRLEN ks_len = NO_INIT
53 CODE:
54 {
55 input = (char *) SvPV(ST(0), input_len);
56 if (input_len != 8)
57 croak("input must be 8 bytes long");
58
59 ks = (char *) SvPV(ST(2), ks_len);
60 if (ks_len != sizeof(des_ks))
61 croak("Invalid key schedule");
62
63 if (output == &sv_undef)
64 output = sv_newmortal();
65 output_len = 8;
66
67 (SvUPGRADE(output, SVt_PV));
68
69 perl_des_crypt(input, SvGROW(output, output_len), (i32 *)ks, enc_flag);
70
71 SvCUR_set(output, output_len);
72 *SvEND(output) = '\0';
73 (void) SvPOK_only(output);
74 SvTAINT(output);
75
76 ST(0) = output;
77 }
78
79
80
81
82
83
84
85
86
87
88
89
90