| 1 |
|
| /* |
| 2 |
|
| * Copyright (C) 1995, 1996 Systemics Ltd (http://www.systemics.com/) |
| 3 |
|
| * |
| 4 |
|
| * Code Modfifications Copyright (C) 2000 W3Works, LLC (http://www.w3works.co/) |
| 5 |
|
| * All rights reserved. |
| 6 |
|
| */ |
| 7 |
|
| |
| 8 |
|
| #include "EXTERN.h" |
| 9 |
|
| #include "perl.h" |
| 10 |
|
| #include "XSUB.h" |
| 11 |
|
| |
| 12 |
|
| #include "blowfish.h" |
| 13 |
|
| |
| 14 |
|
| /* thanks to LDS */ |
| 15 |
|
| #ifndef sv_undef |
| 16 |
|
| #define sv_undef PL_sv_undef |
| 17 |
|
| #endif |
| 18 |
|
| |
| 19 |
|
| MODULE = Crypt::Blowfish PACKAGE = Crypt::Blowfish PREFIX = blowfish_ |
| 20 |
|
| |
| 21 |
|
| PROTOTYPES: DISABLE |
| 22 |
|
| |
| 23 |
|
| |
| 24 |
|
| char * |
| 25 |
|
| blowfish_init(key) |
| 26 |
|
| unsigned char * key = NO_INIT |
| 27 |
|
| STRLEN key_len = NO_INIT |
| 28 |
|
| CODE: |
| 29 |
|
| { |
| 30 |
|
| /* |
| 31 |
|
| * What should this length be??? |
| 32 |
|
| */ |
| 33 |
|
| char ks[8192]; |
| 34 |
|
| |
| 35 |
10011 |
| key = (unsigned char *) SvPV(ST(0), key_len); |
| 36 |
10011 |
▶ | if (key_len < 8 || key_len > 56) |
Branch: 2 branches
| Branch | True | False | Total |
| if (key_len < 8 || key_len > 56) |
10011 |
0 |
10011 |
| if (key_len < 8 || key_len > 56) |
0 |
10011 |
10011 |
|
| 37 |
0 |
| croak("Invalid length key"); |
| 38 |
|
| |
| 39 |
10011 |
▶ | if (blowfish_make_bfkey(key, key_len, ks)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (blowfish_make_bfkey(key, key_len, ks)) |
0 |
10011 |
10011 |
|
| 40 |
0 |
| croak("Error creating key schedule"); |
| 41 |
|
| |
| 42 |
10011 |
| ST(0) = sv_2mortal(newSVpv(ks, sizeof(ks))); |
| 43 |
|
| } |
| 44 |
|
| |
| 45 |
|
| void |
| 46 |
|
| blowfish_crypt(input, output, ks, dir) |
| 47 |
|
| char * input = NO_INIT |
| 48 |
|
| SV * output |
| 49 |
|
| char * ks = NO_INIT |
| 50 |
|
| STRLEN input_len = NO_INIT |
| 51 |
|
| STRLEN output_len = NO_INIT |
| 52 |
|
| STRLEN ks_len = NO_INIT |
| 53 |
|
| int dir |
| 54 |
|
| CODE: |
| 55 |
|
| { |
| 56 |
30010 |
| input = (char *) SvPV(ST(0), input_len); |
| 57 |
30010 |
▶ | if (input_len != 8) |
Branch: 1 branch
| Branch | True | False | Total |
| if (input_len != 8) |
0 |
30010 |
30010 |
|
| 58 |
0 |
| croak("input must be 8 bytes long"); |
| 59 |
|
| |
| 60 |
30010 |
| ks = (char *) SvPV(ST(2), ks_len); |
| 61 |
|
| |
| 62 |
30010 |
▶ | if (output == &sv_undef) |
Branch: 1 branch
| Branch | True | False | Total |
| if (output == &sv_undef) |
0 |
30010 |
30010 |
|
| 63 |
0 |
| output = sv_newmortal(); |
| 64 |
30010 |
| output_len = 8; |
| 65 |
|
| |
| 66 |
30010 |
▶ | (SvUPGRADE(output, SVt_PV)); |
Branch: 1 branch
| Branch | True | False | Total |
| (SvUPGRADE(output, SVt_PV)); |
0 |
30010 |
30010 |
|
| 67 |
|
| |
| 68 |
|
| /* blowfish_crypt_8bytes(input, SvGROW(output, 8), ks, dir); */ |
| 69 |
|
| /* HP-UX (HP cc) fix below, thanks Addi! */ |
| 70 |
30010 |
▶ | blowfish_crypt_8bytes( (unsigned char*)input, (unsigned char*)SvGROW(output, 8), ks, (short)dir); |
Branch: 2 branches
| Branch | True | False | Total |
| blowfish_crypt_8bytes( (unsigned char*)input, (unsigned char*)SvGROW(output, 8), ks, (short)dir); |
30008 |
2 |
30010 |
| blowfish_crypt_8bytes( (unsigned char*)input, (unsigned char*)SvGROW(output, 8), ks, (short)dir); |
0 |
30008 |
30008 |
|
| 71 |
|
| |
| 72 |
30010 |
| SvCUR_set(output, output_len); |
| 73 |
30010 |
| *SvEND(output) = '\0'; |
| 74 |
30010 |
| (void) SvPOK_only(output); |
| 75 |
30010 |
▶ | SvTAINT(output); |
Branch: 2 branches
| Branch | True | False | Total |
| SvTAINT(output); |
0 |
30010 |
30010 |
| SvTAINT(output); |
0 |
0 |
0 |
|
| 76 |
|
| |
| 77 |
30010 |
| ST(0) = output; |
| 78 |
|
| } |