File tree 7 files changed +193
-0
lines changed 7 files changed +193
-0
lines changed Original file line number Diff line number Diff line change
1
+ package Crypt::OpenSSL::Blowfish ;
2
+
3
+ use strict;
4
+ use Carp;
5
+
6
+ use vars qw/ $VERSION @ISA/ ;
7
+
8
+ require DynaLoader;
9
+ @ISA = qw/ DynaLoader/ ;
10
+
11
+ $VERSION = ' 0.01' ;
12
+
13
+ bootstrap Crypt::OpenSSL::Blowfish $VERSION ;
14
+
15
+ sub blocksize { 8; }
16
+ sub keysize { 0; }
17
+ sub min_keysize { 8; }
18
+ sub max_keysize { 56; }
19
+
20
+ sub new {
21
+ my $self = {};
22
+ bless $self , shift ;
23
+ $self -> {ks } = Crypt::OpenSSL::Blowfish::init(shift );
24
+
25
+ $self ;
26
+ }
27
+
28
+ sub encrypt {
29
+ my ($self , $data ) = @_ ;
30
+
31
+ Crypt::OpenSSL::Blowfish::crypt ($data , $self -> {ks }, 0);
32
+
33
+ $data ;
34
+ }
35
+
36
+ sub decrypt {
37
+ my ($self , $data ) = @_ ;
38
+
39
+ Crypt::OpenSSL::Blowfish::crypt ($data , $self -> {ks }, 1);
40
+
41
+ $data ;
42
+ }
43
+
44
+ 1;
45
+
46
+ __END__
47
+
48
+ =head1 NAME
49
+
50
+ Crypt::OpenSSL::Blowfish - Blowfish Algorithm using OpenSSL
51
+
52
+ =head1 SYNOPSIS
53
+
54
+ use Crypt::OpenSSL::Blowfish;
55
+ my $cipher = new Crypt::Blowfish $key;
56
+ my $ciphertext = $cipher->encrypt($plaintext);
57
+ $plaintext = $cipher->decrypt($ciphertext);
58
+
59
+ =head1 DESCRIPTION
60
+
61
+ Crypt::OpenSSL::Blowfish implements the Blowfish Algorithm using functions contained in the OpenSSL crypto library.
62
+ It produces different result than Crypt::Blowfish.
63
+
64
+ =head1 SEE ALSO
65
+
66
+ L<Crypt::Blowfish>
67
+ http://www.openssl.org/
68
+
69
+ =head1 AUTHOR
70
+
71
+ Vitaly Kramskikh, E<lt> vkramskih@cpan.orgE<gt>
72
+
73
+ =cut
Original file line number Diff line number Diff line change
1
+ #include "EXTERN.h"
2
+ #include "perl.h"
3
+ #include "XSUB.h"
4
+
5
+ #include <openssl/blowfish.h>
6
+
7
+ MODULE = Crypt ::OpenSSL ::Blowfish PACKAGE = Crypt ::OpenSSL ::Blowfish PREFIX = blowfish_
8
+ PROTOTYPES : DISABLE
9
+
10
+ char * blowfish_init (key )
11
+ unsigned char * key = NO_INIT
12
+ STRLEN key_len = NO_INIT
13
+ CODE :
14
+ {
15
+ char ks [8192 ];
16
+ key = (unsigned char * ) SvPV (ST (0 ), key_len );
17
+ if (key_len < 8 || key_len > 56 ) {
18
+ croak ("Invalid length key" );
19
+ }
20
+
21
+ BF_set_key ((BF_KEY * )ks , key_len , key );
22
+ ST (0 ) = sv_2mortal (newSVpv (ks , sizeof (ks )));
23
+ }
24
+
25
+ void blowfish_crypt (data , ks , dir )
26
+ char * data = NO_INIT
27
+ STRLEN data_len = NO_INIT
28
+ char * ks
29
+ int dir
30
+ CODE :
31
+ {
32
+ data = (char * ) SvPV (ST (0 ), data_len );
33
+ if (data_len != 8 ) {
34
+ croak ("data must be 8 bytes long" );
35
+ }
36
+
37
+ if (dir ) {
38
+ BF_decrypt ((BF_LONG * )data , (BF_KEY * )ks );
39
+ } else {
40
+ BF_encrypt ((BF_LONG * )data , (BF_KEY * )ks );
41
+ }
42
+ }
Original file line number Diff line number Diff line change
1
+ Revision history for Perl extension Crypt::OpenSSL::Blowfish.
2
+
3
+ 0.01 Wed Jul 1 20:50:04 2009
4
+ - original version
Original file line number Diff line number Diff line change
1
+ Changes
2
+ Makefile.PL
3
+ MANIFEST
4
+ README
5
+ t/blowfish.t
6
+ Blowfish.pm
7
+ Blowfish.xs
Original file line number Diff line number Diff line change
1
+ use ExtUtils::MakeMaker;
2
+ # See lib/ExtUtils/MakeMaker.pm for details of how to influence
3
+ # the contents of the Makefile that is written.
4
+ WriteMakefile(
5
+ NAME => ' Crypt::OpenSSL::Blowfish' ,
6
+ VERSION_FROM => ' Blowfish.pm' ,
7
+ ABSTRACT_FROM => ' Blowfish.pm' , # retrieve abstract from module
8
+ AUTHOR => ' Vitaly Kramskikh <vkramskih@cpan.org>' ,
9
+ LIBS => [' -lcrypto' ], # e.g., '-lm'
10
+ DEFINE => ' -DPERL5 -DOPENSSL_NO_KRB5' ,
11
+ );
Original file line number Diff line number Diff line change
1
+ Crypt-OpenSSL-Blowfish version 0.01
2
+ ===================================
3
+
4
+ The README is used to introduce the module and provide instructions on
5
+ how to install the module, any machine dependencies it may have (for
6
+ example C compilers and installed libraries) and any other information
7
+ that should be provided before the module is installed.
8
+
9
+ A README file is required for CPAN modules since CPAN extracts the
10
+ README file from a module distribution so that people browsing the
11
+ archive can use it get an idea of the modules uses. It is usually a
12
+ good idea to provide version information here so that people can
13
+ decide whether fixes for the module are worth downloading.
14
+
15
+ INSTALLATION
16
+
17
+ To install this module type the following:
18
+
19
+ perl Makefile.PL
20
+ make
21
+ make test
22
+ make install
23
+
24
+ SYNOPSIS
25
+
26
+ use Crypt::OpenSSL::Blowfish;
27
+ my $cipher = new Crypt::Blowfish $key;
28
+ my $ciphertext = $cipher->encrypt($plaintext);
29
+ $plaintext = $cipher->decrypt($ciphertext);
30
+
31
+ COPYRIGHT AND LICENCE
32
+
33
+ Copyright (C) Vitaly Kramskikh
34
+
35
+ This library is free software; you can redistribute it and/or modify
36
+ it under the same terms as Perl itself, either Perl version 5.10.0 or,
37
+ at your option, any later version of Perl 5 you may have available.
38
+
39
+
Original file line number Diff line number Diff line change
1
+ print " 1..3\n " ;
2
+
3
+ use Crypt::OpenSSL::Blowfish;
4
+
5
+ my $cipher = new Crypt::OpenSSL::Blowfish(pack (" H*" , " 0123456789ABCDEF" ));
6
+ print " not " unless defined $cipher ;
7
+ print " ok 1\n " ;
8
+
9
+ my $data = pack (" H*" , " 0000000000000000" );
10
+
11
+ my $out = $cipher -> encrypt($data );
12
+ print " not " if (uc (unpack (" H16" , $out )) ne " 884659249A365457" );
13
+ print " ok 2\n " ;
14
+
15
+ $data = $cipher -> decrypt($out );
16
+ print " not " if (uc (unpack (" H*" , $data )) ne " 0000000000000000" );
17
+ print " ok 3\n " ;
You can’t perform that action at this time.
0 commit comments