From bdf77f6dbd9205c70639fb682059e4ba0761c767 Mon Sep 17 00:00:00 2001 From: mdw Date: Sun, 21 Nov 2004 03:32:32 +0000 Subject: [PATCH] Add fill for encryption schemes. --- Catacomb/Crypto.pm | 26 ++++++++++++++++++++++++++ algorithms.xs | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/Catacomb/Crypto.pm b/Catacomb/Crypto.pm index c4e886d..85c7a3c 100644 --- a/Catacomb/Crypto.pm +++ b/Catacomb/Crypto.pm @@ -78,6 +78,19 @@ sub encrypt { return $c->encrypt($p); } +sub fill { + croak("Usage: Catacomb::CipherClass::fill(cc, k, [iv], len)") + if @_ < 3 || @_ > 4; + my ($cc, $k, $iv, $len) = @_; + if (@_ == 3) { + $len = $iv; + $iv = undef; + } + my $c = $cc->init($k); + $c->setiv($iv) if defined($iv); + return $c->fill($len); +} + sub decrypt { croak("Usage: Catacomb::CipherClass::decrypt(cc, k, [iv], cipher)") if @_ < 3 || @_ > 4; @@ -91,6 +104,19 @@ sub decrypt { return $c->decrypt($p); } +sub filldecrypt { + croak("Usage: Catacomb::CipherClass::filldecrypt(cc, k, [iv], len)") + if @_ < 3 || @_ > 4; + my ($cc, $k, $iv, $len) = @_; + if (@_ == 3) { + $len = $iv; + $iv = undef; + } + my $c = $cc->init($k); + $c->setiv($iv) if defined($iv); + return $c->filldecrypt($len); +} + package Catacomb::HashClass; use Carp; diff --git a/algorithms.xs b/algorithms.xs index 6a01f15..1c9f5f1 100644 --- a/algorithms.xs +++ b/algorithms.xs @@ -227,6 +227,19 @@ encrypt(c, plain) RETVAL SV * +fill(c, len) + gcipher *c + size_t len; + CODE: + RETVAL = NEWSV(0, len ? len : 1); + memset(SvPVX(RETVAL), 0, len); + c->ops->encrypt(c, SvPVX(RETVAL), SvPVX(RETVAL), len); + SvCUR_set(RETVAL, len); + SvPOK_on(RETVAL); + OUTPUT: + RETVAL + +SV * decrypt(c, cipher) gcipher *c SV *cipher @@ -243,6 +256,19 @@ decrypt(c, cipher) RETVAL SV * +filldecrypt(c, len) + gcipher *c + size_t len; + CODE: + RETVAL = NEWSV(0, len ? len : 1); + memset(SvPVX(RETVAL), 0, len); + c->ops->decrypt(c, SvPVX(RETVAL), SvPVX(RETVAL), len); + SvCUR_set(RETVAL, len); + SvPOK_on(RETVAL); + OUTPUT: + RETVAL + +SV * setiv(c, iv) gcipher *c SV *iv -- 2.11.0