| 1 | # This code based in part on the Systemics Crypt::CFB. | ||||||||||||||||||||
| 2 | # Parts Copyright (C) 1995, 1996 Systemics Ltd (http://www.systemics.com/) | ||||||||||||||||||||
| 3 | # All rights reserved. | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | package Net::SSH::Perl::Cipher::CFB; | ||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | sub new { | ||||||||||||||||||||
| 10 | 6 | ▶ | my($class, $ciph, $iv) = @_; | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=8.1
Pod
undocumented
| |||||||||||||||||||||
| 11 | 6 | ▶ | bless { | ||||||||||||||||||
|
Condition33%1/3
$iv || "\000" x $ciph->blocksize
MC/DC0%0/2
$iv || "\000" x $ciph->blocksize
$iv
"\000" x $ciph->blocksize
Truth table33%1/3
A || B
A= $ivB= "\000" x $ciph->blocksize
| |||||||||||||||||||||
| 12 | cipher => $ciph, | ||||||||||||||||||||
| 13 | iv => $iv || ("\0" x $ciph->blocksize), | ||||||||||||||||||||
| 14 | }, $class; | ||||||||||||||||||||
| 15 | } | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | sub encrypt { | ||||||||||||||||||||
| 18 | 3 | ▶ | my $cfb = shift; | ||||||||||||||||||
|
Subroutine
encrypt: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 19 | 3 | my $data = shift; | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 3 | my $retval = ""; | |||||||||||||||||||
| 22 | 3 | my $iv = $cfb->{iv}; | |||||||||||||||||||
| 23 | 3 | my $size = $cfb->{cipher}->blocksize; | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 3 | ▶ | while (length $data) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 26 | 3 | my $out = $cfb->{cipher}->encrypt($iv); | |||||||||||||||||||
| 27 | 3 | $iv = substr($data, 0, $size, '') ^ substr($out, 0, $size, ''); | |||||||||||||||||||
| 28 | 3 | $retval .= $iv; | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 3 | $cfb->{iv} = $iv; | |||||||||||||||||||
| 32 | 3 | $retval; | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | sub decrypt { | ||||||||||||||||||||
| 36 | 3 | ▶ | my $cfb = shift; | ||||||||||||||||||
|
Subroutine
decrypt: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 37 | 3 | my $data = shift; | |||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 3 | my $retval = ""; | |||||||||||||||||||
| 40 | 3 | my $iv = $cfb->{iv}; | |||||||||||||||||||
| 41 | 3 | my $size = $cfb->{cipher}->blocksize; | |||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 3 | ▶ | while (length $data) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 3 | my $out = $cfb->{cipher}->encrypt($iv); | |||||||||||||||||||
| 45 | 3 | $iv = substr($data, 0, $size, ''); | |||||||||||||||||||
| 46 | 3 | $retval .= $iv ^ substr($out, 0, $size); | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 3 | $cfb->{iv} = $iv; | |||||||||||||||||||
| 50 | 3 | $retval; | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 1 | 1; | |||||||||||||||||||
| 54 | __END__ | ||||||||||||||||||||