home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / CFB.pm < prev    next >
Encoding:
Perl POD Document  |  2001-04-24  |  1.7 KB  |  81 lines

  1. # $Id: CFB.pm,v 1.5 2001/04/03 19:44:47 btrott Exp $
  2.  
  3. # This code based in part on the Systemics Crypt::CFB.
  4. # Parts Copyright (C) 1995, 1996 Systemics Ltd (http://www.systemics.com/)
  5. # All rights reserved.
  6.  
  7. package Net::SSH::Perl::Cipher::CFB;
  8. use strict;
  9.  
  10. sub new {
  11.     my($class, $ciph, $iv) = @_;
  12.     bless {
  13.         cipher    => $ciph,
  14.         iv        => $iv || ("\0" x $ciph->blocksize),
  15.     }, $class;
  16. }
  17.  
  18. sub encrypt {
  19.     my $cfb = shift;
  20.     my $data = shift;
  21.  
  22.     my $retval = "";
  23.     my $iv = $cfb->{iv};
  24.     my $size = $cfb->{cipher}->blocksize;
  25.  
  26.     while (length $data) {
  27.         my $out = $cfb->{cipher}->encrypt($iv);
  28.         $iv = substr($data, 0, $size, '') ^ substr($out, 0, $size, '');
  29.         $retval .= $iv;
  30.     }
  31.  
  32.     $cfb->{iv} = $iv;
  33.     $retval;
  34. }
  35.  
  36. sub decrypt {
  37.     my $cfb = shift;
  38.     my $data = shift;
  39.  
  40.     my $retval = "";
  41.     my $iv = $cfb->{iv};
  42.     my $size = $cfb->{cipher}->blocksize;
  43.  
  44.     while (length $data) {
  45.         my $out = $cfb->{cipher}->encrypt($iv);
  46.         $iv = substr($data, 0, $size, '');
  47.         $retval .= $iv ^ substr($out, 0, $size);
  48.     }
  49.  
  50.     $cfb->{iv} = $iv;
  51.     $retval;
  52. }
  53.  
  54. 1;
  55. __END__
  56.  
  57. =head1 NAME
  58.  
  59. Net::SSH::Perl::Cipher::CFB - CFB Implementation
  60.  
  61. =head1 SYNOPSIS
  62.  
  63.     use Net::SSH::Cipher::CFB;
  64.     my $cbc = Net::SSH::Cipher::CFB->new($cipher_obj);
  65.     print $cbc->encrypt($plaintext);
  66.  
  67. =head1 DESCRIPTION
  68.  
  69. I<Net::SSH::Perl::Cipher::CFB> provides a CFB (cipher
  70. feedback) implementation for SSH encryption ciphers.
  71.  
  72. =head1 AUTHOR & COPYRIGHTS
  73.  
  74. This code is based in part on the I<Crypt::CFB> code
  75. originally developed by Systemics Ltd.
  76.  
  77. Please see the Net::SSH::Perl manpage for author, copyright,
  78. and license information.
  79.  
  80. =cut
  81.