| 1 | # This code based slightly on the Systemics Crypt::CFB. | ||||||||||||||||||||
| 2 | # Parts Copyright (C) 1995, 1996 Systemics Ltd (http://www.systemics.com/) | ||||||||||||||||||||
| 3 | # All rights reserved. | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | package Crypt::OpenPGP::CFB; | ||||||||||||||||||||
| 6 | 9 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 9 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 9 | our $VERSION = '1.21'; # VERSION | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 23 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 12 | 23 | my $class = shift; | |||||||||||||||||||
| 13 | 23 | my $c = bless { }, $class; | |||||||||||||||||||
| 14 | 23 | $c->init(@_); | |||||||||||||||||||
| 15 | } | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 23 | ▶ | sub init { | ||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 18 | 23 | my $c = shift; | |||||||||||||||||||
| 19 | 23 | my($cipher, $iv) = @_; | |||||||||||||||||||
| 20 | 23 | $c->{cipher} = $cipher; | |||||||||||||||||||
| 21 | 23 | $c->{blocksize} = $cipher->blocksize; | |||||||||||||||||||
| 22 | 23 | ▶ | $c->{iv} = $iv || "\0" x $c->{blocksize}; | ||||||||||||||||||
|
Condition66%2/3
$iv || "\000" x $c->{'blocksize'}
MC/DC0%0/2
$iv || "\000" x $c->{'blocksize'}
$iv
"\000" x $c->{'blocksize'}
Truth table66%2/3
A || B
A= $ivB= "\000" x $c->{'blocksize'}
| |||||||||||||||||||||
| 23 | 23 | $c; | |||||||||||||||||||
| 24 | } | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 4 | ▶ | sub sync { $_[0]->{unused} = '' } | ||||||||||||||||||
|
Subroutine
sync: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 24 | ▶ | sub encrypt { | ||||||||||||||||||
|
Subroutine
encrypt: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||
| 29 | 24 | my $c = shift; | |||||||||||||||||||
| 30 | 24 | my($data) = @_; | |||||||||||||||||||
| 31 | 24 | my $ret = ''; | |||||||||||||||||||
| 32 | 24 | my $iv = $c->{iv}; | |||||||||||||||||||
| 33 | 24 | ▶ | my $out = $c->{unused} || ''; | ||||||||||||||||||
|
Condition100%2/2
$c->{'unused'} || ''
MC/DC100%1/1
$c->{'unused'} || ''
$c->{'unused'}
Truth table100%2/2
A
A= $c->{'unused'}
| |||||||||||||||||||||
| 34 | 24 | my $size = length $out; | |||||||||||||||||||
| 35 | 24 | ▶ | while ( $data ne '' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | 260 | ▶ | unless ($size) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | 256 | $out = $c->{cipher}->encrypt($iv); | |||||||||||||||||||
| 38 | 256 | $size = $c->{blocksize}; | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | 260 | my $in = substr $data, 0, $size, ''; | |||||||||||||||||||
| 41 | 260 | $size -= (my $got = length $in); | |||||||||||||||||||
| 42 | 260 | $iv .= ($in ^= substr $out, 0, $got, ''); | |||||||||||||||||||
| 43 | 260 | substr $iv, 0, $got, ''; | |||||||||||||||||||
| 44 | 260 | $ret .= $in; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | 24 | $c->{unused} = $out; | |||||||||||||||||||
| 47 | 24 | $c->{iv} = $iv; | |||||||||||||||||||
| 48 | 24 | $ret; | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 20 | ▶ | sub decrypt { | ||||||||||||||||||
|
Subroutine
decrypt: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||
| 52 | 20 | my $c = shift; | |||||||||||||||||||
| 53 | 20 | my($data) = @_; | |||||||||||||||||||
| 54 | 20 | my $ret = ''; | |||||||||||||||||||
| 55 | 20 | my $iv = $c->{iv}; | |||||||||||||||||||
| 56 | 20 | ▶ | my $out = $c->{unused} || ''; | ||||||||||||||||||
|
Condition100%2/2
$c->{'unused'} || ''
MC/DC100%1/1
$c->{'unused'} || ''
$c->{'unused'}
Truth table100%2/2
A
A= $c->{'unused'}
| |||||||||||||||||||||
| 57 | 20 | my $size = length $out; | |||||||||||||||||||
| 58 | 20 | ▶ | while ( $data ne '' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | 240 | ▶ | unless ($size) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 236 | $out = $c->{cipher}->encrypt($iv); | |||||||||||||||||||
| 61 | 236 | $size = $c->{blocksize}; | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | 240 | my $in = substr $data, 0, $size, ''; | |||||||||||||||||||
| 64 | 240 | $size -= (my $got = length $in); | |||||||||||||||||||
| 65 | 240 | substr $iv .= $in, 0, $got, ''; | |||||||||||||||||||
| 66 | 240 | $ret .= ($in ^= substr $out, 0, $got, ''); | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | 20 | $c->{unused} = $out; | |||||||||||||||||||
| 69 | 20 | $c->{iv} = $iv; | |||||||||||||||||||
| 70 | 20 | $ret; | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 9 | 1; | |||||||||||||||||||
| 74 | __END__ | ||||||||||||||||||||