line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*-cperl-*- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Crypt::RSA::Blind - Blind RSA signatures |
4
|
|
|
|
|
|
|
# Copyright (c) 2016-2017 Ashish Gulhati |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# $Id: lib/Crypt/RSA/Blind.pm v1.009 Sat Jun 10 00:16:58 PDT 2017 $ |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Crypt::RSA::Blind; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
39302
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
62
|
|
11
|
1
|
|
|
1
|
|
10
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
48
|
|
12
|
1
|
|
|
1
|
|
386
|
use Crypt::FDH; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Crypt::RSA; |
14
|
|
|
|
|
|
|
use Crypt::RSA::Primitives; |
15
|
|
|
|
|
|
|
use Crypt::Random qw(makerandom_itv makerandom); |
16
|
|
|
|
|
|
|
use Math::Pari qw (Mod component); |
17
|
|
|
|
|
|
|
use vars qw( $VERSION $AUTOLOAD ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our ( $VERSION ) = '$Revision: 1.009 $' =~ /\s+([\d\.]+)/; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
|
|
|
|
|
|
bless { HASHSIZE => 768, |
23
|
|
|
|
|
|
|
INITSIZE => 128, |
24
|
|
|
|
|
|
|
BLINDSIZE => 512, |
25
|
|
|
|
|
|
|
_RSA => new Crypt::RSA, |
26
|
|
|
|
|
|
|
_RSAP => new Crypt::RSA::Primitives}, shift; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub keygen { |
30
|
|
|
|
|
|
|
my $self = shift; |
31
|
|
|
|
|
|
|
$self->_rsa->keygen(@_); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub init { |
35
|
|
|
|
|
|
|
my $self = shift; |
36
|
|
|
|
|
|
|
makerandom( Size => $self->initsize, Strength => 0 ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub request { |
40
|
|
|
|
|
|
|
my $self = shift; |
41
|
|
|
|
|
|
|
my %arg = @_; |
42
|
|
|
|
|
|
|
my ($invertible, $blinding); |
43
|
|
|
|
|
|
|
while (!$invertible) { |
44
|
|
|
|
|
|
|
$blinding = makerandom_itv( Size => $self->blindsize, Upper => $arg{Key}->n-1, Strength => 0 ); |
45
|
|
|
|
|
|
|
# Check that blinding is invertible mod n |
46
|
|
|
|
|
|
|
$invertible = Math::Pari::gcd($blinding, $arg{Key}->n); |
47
|
|
|
|
|
|
|
$invertible = 0 unless $invertible == 1; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
$self->_request($arg{Init} => $blinding); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $be = $self->_rsap->core_encrypt(Key => $arg{Key}, Plaintext => $blinding); |
52
|
|
|
|
|
|
|
my $fdh = Math::Pari::_hex_cvt ('0x'.Crypt::FDH::hash(Size => $self->hashsize, Message => $arg{Message})); |
53
|
|
|
|
|
|
|
component((Mod($fdh,$arg{Key}->n)) * (Mod($be,$arg{Key}->n)), 2); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub sign { |
57
|
|
|
|
|
|
|
my $self = shift; |
58
|
|
|
|
|
|
|
$self->_rsap->core_sign(@_); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub unblind { |
62
|
|
|
|
|
|
|
my $self = shift; |
63
|
|
|
|
|
|
|
my %arg = @_; |
64
|
|
|
|
|
|
|
my $blinding = $self->_request($arg{Init}); |
65
|
|
|
|
|
|
|
component((Mod($arg{Signature},$arg{Key}->n)) / (Mod($blinding,$arg{Key}->n)), 2); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub verify { |
69
|
|
|
|
|
|
|
my $self = shift; |
70
|
|
|
|
|
|
|
my %arg = @_; |
71
|
|
|
|
|
|
|
my $pt = $self->_rsap->core_verify(Key => $arg{Key}, Signature => $arg{Signature}); |
72
|
|
|
|
|
|
|
$pt == Math::Pari::_hex_cvt ('0x'.Crypt::FDH::hash(Size => $self->hashsize, Message => $arg{Message})); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub errstr { |
76
|
|
|
|
|
|
|
my $self = shift; |
77
|
|
|
|
|
|
|
$self->_rsa->errstr(@_); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _request { |
81
|
|
|
|
|
|
|
my $self = shift; |
82
|
|
|
|
|
|
|
my $init = $_[0]; my $ret; |
83
|
|
|
|
|
|
|
if ($_[1]) { |
84
|
|
|
|
|
|
|
$self->{Requests}->{$init} = $_[1]; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
else { |
87
|
|
|
|
|
|
|
$ret = $self->{Requests}->{$init}; |
88
|
|
|
|
|
|
|
delete $self->{Requests}->{$init}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
return $ret; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub AUTOLOAD { |
94
|
|
|
|
|
|
|
my $self = shift; (my $auto = $AUTOLOAD) =~ s/.*:://; |
95
|
|
|
|
|
|
|
return if $auto eq 'DESTROY'; |
96
|
|
|
|
|
|
|
if ($auto =~ /^(_rsa|_rsap|hashsize|blindsize|initsize)$/x) { |
97
|
|
|
|
|
|
|
$self->{"\U$auto"} = shift if (defined $_[0]); |
98
|
|
|
|
|
|
|
return $self->{"\U$auto"}; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
else { |
101
|
|
|
|
|
|
|
die "Could not AUTOLOAD method $auto."; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; # End of Crypt::RSA::Blind |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
package Crypt::RSA::Blind::PubKey; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
use Compress::Zlib; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub from_hex { |
112
|
|
|
|
|
|
|
Crypt::RSA::Key::Public->new->deserialize(String => [ uncompress(pack('H*',shift)) ]); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; # End of Crypt::RSA::Blind::PubKey |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
package Crypt::RSA::Blind::SecKey; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
use Compress::Zlib; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub from_hex { |
122
|
|
|
|
|
|
|
Crypt::RSA::Key::Private->new->deserialize(String => [ uncompress(pack('H*',shift)) ]); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; # End of Crypt::RSA::Blind::SecKey |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
__END__ |