Initial Commit
This commit is contained in:
39
database/perl/vendor/lib/Crypt/OpenPGP/Key/Secret/DSA.pm
vendored
Normal file
39
database/perl/vendor/lib/Crypt/OpenPGP/Key/Secret/DSA.pm
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
package Crypt::OpenPGP::Key::Secret::DSA;
|
||||
use strict;
|
||||
|
||||
use Crypt::DSA::Key;
|
||||
use Crypt::OpenPGP::Key::Public::DSA;
|
||||
use Crypt::OpenPGP::Key::Secret;
|
||||
use Crypt::OpenPGP::ErrorHandler;
|
||||
use base qw( Crypt::OpenPGP::Key::Secret Crypt::OpenPGP::ErrorHandler );
|
||||
|
||||
sub secret_props { qw( x ) }
|
||||
*sig_props = \&Crypt::OpenPGP::Key::Public::DSA::sig_props;
|
||||
*public_props = \&Crypt::OpenPGP::Key::Public::DSA::public_props;
|
||||
*size = \&Crypt::OpenPGP::Key::Public::DSA::size;
|
||||
*keygen = \&Crypt::OpenPGP::Key::Public::DSA::keygen;
|
||||
*can_sign = \&Crypt::OpenPGP::Key::Public::DSA::can_sign;
|
||||
|
||||
sub init {
|
||||
my $key = shift;
|
||||
$key->{key_data} = shift || Crypt::DSA::Key->new;
|
||||
$key;
|
||||
}
|
||||
|
||||
sub y { $_[0]->{key_data}->pub_key(@_[1..$#_]) }
|
||||
sub x { $_[0]->{key_data}->priv_key(@_[1..$#_]) }
|
||||
|
||||
sub sign {
|
||||
my $key = shift;
|
||||
my($dgst) = @_;
|
||||
require Crypt::DSA;
|
||||
my $dsa = Crypt::DSA->new;
|
||||
my $sig = $dsa->sign(
|
||||
Key => $key->{key_data},
|
||||
Digest => $dgst,
|
||||
);
|
||||
}
|
||||
|
||||
*verify = \&Crypt::OpenPGP::Key::Public::DSA::verify;
|
||||
|
||||
1;
|
||||
57
database/perl/vendor/lib/Crypt/OpenPGP/Key/Secret/ElGamal.pm
vendored
Normal file
57
database/perl/vendor/lib/Crypt/OpenPGP/Key/Secret/ElGamal.pm
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
package Crypt::OpenPGP::Key::Secret::ElGamal;
|
||||
use strict;
|
||||
|
||||
use Crypt::OpenPGP::Key::Public::ElGamal;
|
||||
use Crypt::OpenPGP::Key::Secret;
|
||||
use Crypt::OpenPGP::ErrorHandler;
|
||||
use base qw( Crypt::OpenPGP::Key::Secret Crypt::OpenPGP::ErrorHandler );
|
||||
|
||||
sub secret_props { qw( x ) }
|
||||
*public_props = \&Crypt::OpenPGP::Key::Public::ElGamal::public_props;
|
||||
*crypt_props = \&Crypt::OpenPGP::Key::Public::ElGamal::crypt_props;
|
||||
*size = \&Crypt::OpenPGP::Key::Public::ElGamal::size;
|
||||
*keygen = \&Crypt::OpenPGP::Key::Public::ElGamal::keygen;
|
||||
*can_encrypt = \&Crypt::OpenPGP::Key::Public::ElGamal::can_encrypt;
|
||||
|
||||
sub init {
|
||||
my $key = shift;
|
||||
$key->{key_data} = shift || Crypt::OpenPGP::ElGamal::Private->new;
|
||||
$key;
|
||||
}
|
||||
|
||||
sub decrypt { $_[0]->{key_data}->decrypt(@_[1..$#_]) }
|
||||
|
||||
package Crypt::OpenPGP::ElGamal::Private;
|
||||
use strict;
|
||||
|
||||
use Crypt::OpenPGP::Util qw( mod_exp mod_inverse );
|
||||
use Math::BigInt;
|
||||
|
||||
sub new { bless {}, $_[0] }
|
||||
|
||||
sub decrypt {
|
||||
my $key = shift;
|
||||
my($C) = @_;
|
||||
my $p = $key->p;
|
||||
my $t1 = mod_exp($C->{a}, $key->x, $p);
|
||||
$t1 = mod_inverse($t1, $p);
|
||||
my $n = Math::BigInt->new($C->{b} * $t1);
|
||||
$n->bmod($p);
|
||||
return $n;
|
||||
}
|
||||
|
||||
sub _getset {
|
||||
my $e = shift;
|
||||
sub {
|
||||
my $key = shift;
|
||||
$key->{$e} = shift if @_;
|
||||
$key->{$e};
|
||||
}
|
||||
}
|
||||
|
||||
*p = _getset('p');
|
||||
*g = _getset('g');
|
||||
*y = _getset('y');
|
||||
*x = _getset('x');
|
||||
|
||||
1;
|
||||
49
database/perl/vendor/lib/Crypt/OpenPGP/Key/Secret/RSA.pm
vendored
Normal file
49
database/perl/vendor/lib/Crypt/OpenPGP/Key/Secret/RSA.pm
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
package Crypt::OpenPGP::Key::Secret::RSA;
|
||||
use strict;
|
||||
|
||||
use Crypt::RSA::Key::Private;
|
||||
use Crypt::OpenPGP::Key::Public::RSA;
|
||||
use Crypt::OpenPGP::Key::Secret;
|
||||
use Crypt::OpenPGP::Util qw( bin2mp );
|
||||
use Crypt::OpenPGP::ErrorHandler;
|
||||
use base qw( Crypt::OpenPGP::Key::Secret Crypt::OpenPGP::ErrorHandler );
|
||||
|
||||
sub secret_props { qw( d p q u ) }
|
||||
*sig_props = \&Crypt::OpenPGP::Key::Public::RSA::sig_props;
|
||||
*public_props = \&Crypt::OpenPGP::Key::Public::RSA::public_props;
|
||||
*crypt_props = \&Crypt::OpenPGP::Key::Public::RSA::crypt_props;
|
||||
*size = \&Crypt::OpenPGP::Key::Public::RSA::size;
|
||||
*encode = \&Crypt::OpenPGP::Key::Public::RSA::encode;
|
||||
*keygen = \&Crypt::OpenPGP::Key::Public::RSA::keygen;
|
||||
*can_encrypt = \&Crypt::OpenPGP::Key::Public::RSA::can_encrypt;
|
||||
*can_sign = \&Crypt::OpenPGP::Key::Public::RSA::can_sign;
|
||||
|
||||
sub init {
|
||||
my $key = shift;
|
||||
$key->{key_data} = shift ||
|
||||
Crypt::RSA::Key::Private->new( Password => 'pgp' );
|
||||
$key;
|
||||
}
|
||||
|
||||
*encrypt = \&Crypt::OpenPGP::Key::Public::RSA::encrypt;
|
||||
|
||||
sub decrypt {
|
||||
my $key = shift;
|
||||
my($C) = @_;
|
||||
require Crypt::RSA::Primitives;
|
||||
my $prim = Crypt::RSA::Primitives->new;
|
||||
$prim->core_decrypt( Key => $key->{key_data}, Cyphertext => $C->{c} );
|
||||
}
|
||||
|
||||
sub sign {
|
||||
my $key = shift;
|
||||
my($dgst, $hash_alg) = @_;
|
||||
my $m = encode($dgst, $hash_alg, $key->bytesize - 1);
|
||||
require Crypt::RSA::Primitives;
|
||||
my $prim = Crypt::RSA::Primitives->new;
|
||||
$m = bin2mp($m);
|
||||
my $c = $prim->core_sign( Key => $key->{key_data}, Message => $m );
|
||||
{ c => $c }
|
||||
}
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user