Tadashi Okoshi
slash****@users*****
2005年 10月 25日 (火) 04:20:49 JST
Index: affelio_farm/admin/skelton/affelio/extlib/Crypt/DH.pm
diff -u affelio_farm/admin/skelton/affelio/extlib/Crypt/DH.pm:1.1.1.1 affelio_farm/admin/skelton/affelio/extlib/Crypt/DH.pm:removed
--- affelio_farm/admin/skelton/affelio/extlib/Crypt/DH.pm:1.1.1.1 Tue Oct 25 04:14:40 2005
+++ affelio_farm/admin/skelton/affelio/extlib/Crypt/DH.pm Tue Oct 25 04:20:49 2005
@@ -1,243 +0,0 @@
-# $Id: DH.pm,v 1.1.1.1 2005/10/24 19:14:40 slash5234 Exp $
-
-package Crypt::DH;
-use strict;
-
-use Math::BigInt lib => "GMP,Pari";
-our $VERSION = '0.05';
-
-sub new {
- my $class = shift;
- my $dh = bless {}, $class;
-
- my %param = @_;
- for my $w (qw( p g priv_key )) {
- next unless exists $param{$w};
- $dh->$w(delete $param{$w});
- }
- die "Unknown parameters to constructor: " . join(", ", keys %param) if %param;
-
- $dh;
-}
-
-BEGIN {
- no strict 'refs';
- for my $meth (qw( p g pub_key priv_key )) {
- *$meth = sub {
- my($key, $value) = @_;
- if (ref $value eq 'Math::BigInt') {
- $key->{$meth} = $value;
- }
- elsif (ref $value eq 'Math::Pari') {
- $key->{$meth} = Math::BigInt->new(Math::Pari::pari2pv($value));
- }
- elsif (defined $value && !(ref $value)) {
- $key->{$meth} = Math::BigInt->new($value);
- }
- elsif (defined $value) {
- die "Unknown parameter type to $meth: $value\n";
- }
- my $ret = $key->{$meth} || "";
- $ret;
- };
- }
-}
-
-sub generate_keys {
- my $dh = shift;
-
- unless (defined $dh->{priv_key}) {
- my $i = _bitsize($dh->{p}) - 1;
- $dh->{priv_key} =
- $Crypt::Random::VERSION ?
- Crypt::Random::makerandom_itv(Strength => 0, Uniform => 1,
- Lower => 1, Upper => $dh->{p} - 1) :
- _makerandom_itv($i, 1, $dh->{p} - 1);
- }
-
- $dh->{pub_key} = $dh->{g}->copy->bmodpow($dh->{priv_key}, $dh->{p});
-}
-
-sub compute_key {
- my $dh = shift;
- my $pub_key = shift;
- $pub_key->copy->bmodpow($dh->{priv_key}, $dh->{p});
-}
-*compute_secret = \&compute_key;
-
-sub _bitsize {
- return length($_[0]->as_bin) - 2;
-}
-
-sub _makerandom_itv {
- my ($size, $min_inc, $max_exc) = @_;
-
- while (1) {
- my $r = _makerandom($size);
- return $r if $r >= $min_inc && $r < $max_exc;
- }
-}
-
-sub _makerandom {
- my $size = shift;
-
- my $bytes = int($size / 8) + ($size % 8 ? 1 : 0);
-
- my $rand;
- if (-e "/dev/urandom") {
- my $fh;
- open($fh, '/dev/urandom')
- or die "Couldn't open /dev/urandom";
- my $got = sysread $fh, $rand, $bytes;
- die "Didn't read all bytes from urandom" unless $got == $bytes;
- close $fh;
- } else {
- for (1..$bytes) {
- $rand .= chr(int(rand(256)));
- }
- }
-
- my $bits = unpack("b*", $rand);
- die unless length($bits) >= $size;
-
- Math::BigInt->new('0b' . substr($bits, 0, $size));
-}
-
-1;
-__END__
-
-=head1 NAME
-
-Crypt::DH - Diffie-Hellman key exchange system
-
-=head1 SYNOPSIS
-
- use Crypt::DH;
- my $dh = Crypt::DH->new;
- $dh->g($g);
- $dh->p($p);
-
- ## Generate public and private keys.
- $dh->generate_keys;
-
- $my_pub_key = $dh->pub_key;
-
- ## Send $my_pub_key to "other" party, and receive "other"
- ## public key in return.
-
- ## Now compute shared secret from "other" public key.
- my $shared_secret = $dh->compute_secret( $other_pub_key );
-
-=head1 DESCRIPTION
-
-I<Crypt::DH> is a Perl implementation of the Diffie-Hellman key
-exchange system. Diffie-Hellman is an algorithm by which two
-parties can agree on a shared secret key, known only to them.
-The secret is negotiated over an insecure network without the
-two parties ever passing the actual shared secret, or their
-private keys, between them.
-
-=head1 THE ALGORITHM
-
-The algorithm generally works as follows: Party A and Party B
-choose a property I<p> and a property I<g>; these properties are
-shared by both parties. Each party then computes a random private
-key integer I<priv_key>, where the length of I<priv_key> is at
-most (number of bits in I<p>) - 1. Each party then computes a
-public key based on I<g>, I<priv_key>, and I<p>; the exact value
-is
-
- g ^ priv_key mod p
-
-The parties exchange these public keys.
-
-The shared secret key is generated based on the exchanged public
-key, the private key, and I<p>. If the public key of Party B is
-denoted I<pub_key_B>, then the shared secret is equal to
-
- pub_key_B ^ priv_key mod p
-
-The mathematical principles involved insure that both parties will
-generate the same shared secret key.
-
-More information can be found in PKCS #3 (Diffie-Hellman Key
-Agreement Standard):
-
- http://www.rsasecurity.com/rsalabs/pkcs/pkcs-3/
-
-=head1 USAGE
-
-I<Crypt::DH> implements the core routines needed to use
-Diffie-Hellman key exchange. To actually use the algorithm,
-you'll need to start with values for I<p> and I<g>; I<p> is a
-large prime, and I<g> is a base which must be larger than 0
-and less than I<p>.
-
-I<Crypt::DH> uses I<Math::BigInt> internally for big-integer
-calculations. All accessor methods (I<p>, I<g>, I<priv_key>, and
-I<pub_key>) thus return I<Math::BigInt> objects, as does the
-I<compute_secret> method. The accessors, however, allow setting with a
-scalar decimal string, hex string (^0x), Math::BigInt object, or
-Math::Pari object (for backwards compatibility).
-
-=head2 $dh = Crypt::DH->new([ %param ]).
-
-Constructs a new I<Crypt::DH> object and returns the object.
-I<%param> may include none, some, or all of the keys I<p>, I<g>, and
-I<priv_key>.
-
-=head2 $dh->p([ $p ])
-
-Given an argument I<$p>, sets the I<p> parameter (large prime) for
-this I<Crypt::DH> object.
-
-Returns the current value of I<p>. (as a Math::BigInt object)
-
-=head2 $dh->g([ $g ])
-
-Given an argument I<$g>, sets the I<g> parameter (base) for
-this I<Crypt::DH> object.
-
-Returns the current value of I<g>.
-
-=head2 $dh->generate_keys
-
-Generates the public and private key portions of the I<Crypt::DH>
-object, assuming that you've already filled I<p> and I<g> with
-appropriate values.
-
-If you've provided a priv_key, it's used, otherwise a random priv_key
-is created using either Crypt::Random (if already loaded), or
-/dev/urandom, or Perl's rand, in that order.
-
-=head2 $dh->compute_secret( $public_key )
-
-Given the public key I<$public_key> of Party B (the party with which
-you're performing key negotiation and exchange), computes the shared
-secret key, based on that public key, your own private key, and your
-own large prime value (I<p>).
-
-The historical method name "compute_key" is aliased to this for
-compatibility.
-
-=head2 $dh->priv_key([ $priv_key ])
-
-Returns the private key. Given an argument I<$priv_key>, sets the
-I<priv_key> parameter for this I<Crypt::DH> object.
-
-=head2 $dh->pub_key
-
-Returns the public key.
-
-=head1 AUTHOR & COPYRIGHT
-
-Benjamin Trott, ben****@rhumb*****
-
-Brad Fitzpatrick, brad****@danga*****
-
-Except where otherwise noted, Crypt::DH is Copyright 2001
-Benjamin Trott. All rights reserved. Crypt::DH is free
-software; you may redistribute it and/or modify it under
-the same terms as Perl itself.
-
-=cut
Index: affelio_farm/admin/skelton/affelio/extlib/Crypt/RC5.pm
diff -u affelio_farm/admin/skelton/affelio/extlib/Crypt/RC5.pm:1.1.1.1 affelio_farm/admin/skelton/affelio/extlib/Crypt/RC5.pm:removed
--- affelio_farm/admin/skelton/affelio/extlib/Crypt/RC5.pm:1.1.1.1 Tue Oct 25 04:14:40 2005
+++ affelio_farm/admin/skelton/affelio/extlib/Crypt/RC5.pm Tue Oct 25 04:20:49 2005
@@ -1,152 +0,0 @@
-#---------------------------------------------------------------------------#
-# Crypt::RC5
-# Date Written: 23-Nov-2001 10:47:02 AM
-# Last Modified: 05-Nov-2002 09:52:18 AM
-# Author: Kurt Kincaid
-# Copyright (c) 2002, Kurt Kincaid
-# All Rights Reserved
-#
-# NOTICE: RC5 is a fast block cipher designed by Ronald Rivest
-# for RSA Data Security (now RSA Security) in 1994. It is a
-# parameterized algorithm with a variable block size, a variable
-# key size, and a variable number of rounds. This particular
-# implementation is 32 bit. As such, it is suggested that a minimum
-# of 12 rounds be performed.
-#---------------------------------------------------------------------------#
-
-package Crypt::RC5;
-
-use Exporter;
-use integer;
-use strict;
-no strict 'refs';
-use vars qw/ $VERSION @EXPORT_OK @ISA @S /;
-
- @ ISA = qw(Exporter);
- @ EXPORT_OK = qw($VERSION RC5);
-$VERSION = '2.00';
-
-sub new ($$$) {
- my ( $class, $key, $rounds ) = @_;
- my $self = bless {}, $class;
- my @temp = unpack( "C*", $key );
- my $newKey;
- foreach my $temp ( @temp ) {
- $temp = sprintf( "%lx", $temp );
- if ( length( $temp ) < 2 ) {
- $temp = "0" . $temp;
- }
- $newKey .= $temp;
- }
- my @L = unpack "V*", pack "H*x3", $newKey;
- my $T = 0xb7e15163;
- @S = ( M( $T ), map { $T = M( $T + 0x9e3779b9 ) } 0 .. 2 * $rounds );
- my ( $A, $B ) = ( 0, 0 );
- for ( 0 .. 3 * ( @S > @L ? @S : @L ) - 1 ) {
- $A = $S[ $_ % @S ] = ROTL( 3, M( $S[ $_ % @S ] ) + M( $A + $B ) );
- $B = $L[ $_ % @L ] = ROTL( M( $A + $B ), M( $L[ $_ % @L ] ) + M( $A + $B ) );
- }
- return $self;
-}
-
-sub encrypt ($$) {
- my ( $self, $text ) = @_;
- return $self->RC5( $text );
-}
-
-sub decrypt ($$) {
- my ( $self, $text ) = @_;
- return $self->RC5( $text, 1 );
-}
-
-sub decrypt_iv ($$$) {
- my ( $self, $text, $iv ) = @_;
- die "iv must be 8 bytes long" if length( $iv ) != 8;
-
- my @ivnum = unpack( 'C*', $iv . $text );
- my @plain = unpack( 'C*', $self->RC5( $text, 1 ) );
- for ( 0 .. @plain ) { $plain[ $_ ] ^= $ivnum[ $_ ]; }
- return pack( 'C*', @plain );
-}
-
-sub RC5 ($$) {
- my ( $self, $text, $decrypt ) = @_;
- my $last;
- my $processed = '';
- while ( $text =~ /(.{8})/gs ) {
- $last = $';
- $processed .= Process( $1, $decrypt );
- }
- if ( length( $text ) % 8 ) {
- $processed .= Process( $last, $decrypt );
- }
- return $processed;
-}
-
-sub M ($) {
- return unpack( 'V', pack( 'V', pop ) );
-}
-
-sub ROTL ($$) {
- my ( $x, $n );
- ( $x = pop ) << ( $n = 31 & pop ) | 2**$n - 1 & $x >> 32 - $n;
-}
-
-sub ROTR ($$) {
- ROTL( 32 - ( 31 & shift ), shift );
-}
-
-sub Process ($$) {
- my ( $block, $decrypt ) = @_;
- my ( $A, $B ) = unpack "V2", $block . "\0" x 3;
- $_ = '$A = M( $A+$S[0] );$B = M( $B+$S[1] )';
- $decrypt || eval;
- for ( 1 .. @S - 2 ) {
- if ( $decrypt ) {
- $B = $A ^ ROTR( $A, M( $B - $S[ @S - $_ ] ) );
- } else {
- $A = M( $S[ $_ + 1 ] + ROTL( $B, $A ^ $B ) );
- }
- $A ^= $B ^= $A ^= $B;
- }
- $decrypt && ( y/+/-/, eval );
- return pack "V2", $A, $B;
-}
-
-1;
-__END__
-
-
-=head1 NAME
-
-Crypt::RC5 - Perl implementation of the RC5 encryption algorithm.
-
-=head1 SYNOPSIS
-
- use Crypt::RC5;
-
- $ref = Crypt::RC5->new( $key, $rounds );
- $ciphertext = $ref->encrypt( $plaintext );
-
- $ref2 = Crypt::RC5->new( $key, $rounds );
- $plaintext2 = $ref2->decrypt( $ciphertext );
-
-=head1 DESCRIPTION
-
-RC5 is a fast block cipher designed by Ronald Rivest for RSA Data Security (now RSA Security) in 1994. It is a parameterized algorithm with a variable block size, a variable key size, and a variable number of rounds. This particular implementation is 32 bit. As such, it is suggested that a minimum of 12 rounds be performed.
-
-Core logic based on "RC5 in 6 lines of perl" at http://www.cypherspace.org
-
-=head1 AUTHOR
-
-Kurt Kincaid (sifuk****@yahoo*****)
-
-Ronald Rivest for RSA Security, Inc.
-
-=head1 SEE ALSO
-
-L<perl>, L<http://www.cypherspace.org>, L<http://www.rsasecurity.com>
-
-=cut
-
-