Subversion Repositories oidplus

Rev

Rev 846 | Rev 1042 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 846 Rev 874
Line 19... Line 19...
19
 *
19
 *
20
 * echo $public->verify($plaintext, $signature) ? 'verified' : 'unverified';
20
 * echo $public->verify($plaintext, $signature) ? 'verified' : 'unverified';
21
 * ?>
21
 * ?>
22
 * </code>
22
 * </code>
23
 *
23
 *
-
 
24
 * @category  Crypt
-
 
25
 * @package   DSA
24
 * @author    Jim Wigginton <terrafrost@php.net>
26
 * @author    Jim Wigginton <terrafrost@php.net>
25
 * @copyright 2016 Jim Wigginton
27
 * @copyright 2016 Jim Wigginton
26
 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
28
 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
27
 * @link      http://phpseclib.sourceforge.net
29
 * @link      http://phpseclib.sourceforge.net
28
 */
30
 */
Line 37... Line 39...
37
use phpseclib3\Math\BigInteger;
39
use phpseclib3\Math\BigInteger;
38
 
40
 
39
/**
41
/**
40
 * Pure-PHP FIPS 186-4 compliant implementation of DSA.
42
 * Pure-PHP FIPS 186-4 compliant implementation of DSA.
41
 *
43
 *
-
 
44
 * @package DSA
42
 * @author  Jim Wigginton <terrafrost@php.net>
45
 * @author  Jim Wigginton <terrafrost@php.net>
-
 
46
 * @access  public
43
 */
47
 */
44
abstract class DSA extends AsymmetricKey
48
abstract class DSA extends AsymmetricKey
45
{
49
{
46
    /**
50
    /**
47
     * Algorithm Name
51
     * Algorithm Name
48
     *
52
     *
49
     * @var string
53
     * @var string
-
 
54
     * @access private
50
     */
55
     */
51
    const ALGORITHM = 'DSA';
56
    const ALGORITHM = 'DSA';
52
 
57
 
53
    /**
58
    /**
54
     * DSA Prime P
59
     * DSA Prime P
55
     *
60
     *
56
     * @var \phpseclib3\Math\BigInteger
61
     * @var \phpseclib3\Math\BigInteger
-
 
62
     * @access private
57
     */
63
     */
58
    protected $p;
64
    protected $p;
59
 
65
 
60
    /**
66
    /**
61
     * DSA Group Order q
67
     * DSA Group Order q
62
     *
68
     *
63
     * Prime divisor of p-1
69
     * Prime divisor of p-1
64
     *
70
     *
65
     * @var \phpseclib3\Math\BigInteger
71
     * @var \phpseclib3\Math\BigInteger
-
 
72
     * @access private
66
     */
73
     */
67
    protected $q;
74
    protected $q;
68
 
75
 
69
    /**
76
    /**
70
     * DSA Group Generator G
77
     * DSA Group Generator G
71
     *
78
     *
72
     * @var \phpseclib3\Math\BigInteger
79
     * @var \phpseclib3\Math\BigInteger
-
 
80
     * @access private
73
     */
81
     */
74
    protected $g;
82
    protected $g;
75
 
83
 
76
    /**
84
    /**
77
     * DSA public key value y
85
     * DSA public key value y
78
     *
86
     *
79
     * @var \phpseclib3\Math\BigInteger
87
     * @var \phpseclib3\Math\BigInteger
-
 
88
     * @access private
80
     */
89
     */
81
    protected $y;
90
    protected $y;
82
 
91
 
83
    /**
92
    /**
84
     * Signature Format
93
     * Signature Format
85
     *
94
     *
86
     * @var string
95
     * @var string
-
 
96
     * @access private
87
     */
97
     */
88
    protected $sigFormat;
98
    protected $sigFormat;
89
 
99
 
90
    /**
100
    /**
91
     * Signature Format (Short)
101
     * Signature Format (Short)
92
     *
102
     *
93
     * @var string
103
     * @var string
-
 
104
     * @access private
94
     */
105
     */
95
    protected $shortFormat;
106
    protected $shortFormat;
96
 
107
 
97
    /**
108
    /**
98
     * Create DSA parameters
109
     * Create DSA parameters
99
     *
110
     *
-
 
111
     * @access public
100
     * @param int $L
112
     * @param int $L
101
     * @param int $N
113
     * @param int $N
102
     * @return \phpseclib3\Crypt\DSA|bool
114
     * @return \phpseclib3\Crypt\DSA|bool
103
     */
115
     */
104
    public static function createParameters($L = 2048, $N = 224)
116
    public static function createParameters($L = 2048, $N = 224)
Line 172... Line 184...
172
     * no parameters (at which point L and N will be generated with this method)
184
     * no parameters (at which point L and N will be generated with this method)
173
     *
185
     *
174
     * Returns the private key, from which the publickey can be extracted
186
     * Returns the private key, from which the publickey can be extracted
175
     *
187
     *
176
     * @param int[] ...$args
188
     * @param int[] ...$args
-
 
189
     * @access public
177
     * @return DSA\PrivateKey
190
     * @return DSA\PrivateKey
178
     */
191
     */
179
    public static function createKey(...$args)
192
    public static function createKey(...$args)
180
    {
193
    {
181
        self::initialize_static_variables();
194
        self::initialize_static_variables();
Line 212... Line 225...
212
 
225
 
213
    /**
226
    /**
214
     * OnLoad Handler
227
     * OnLoad Handler
215
     *
228
     *
216
     * @return bool
229
     * @return bool
-
 
230
     * @access protected
217
     * @param array $components
231
     * @param array $components
218
     */
232
     */
219
    protected static function onLoad($components)
233
    protected static function onLoad($components)
220
    {
234
    {
221
        if (!isset(self::$engines['PHP'])) {
235
        if (!isset(self::$engines['PHP'])) {
Line 258... Line 272...
258
    /**
272
    /**
259
     * Returns the key size
273
     * Returns the key size
260
     *
274
     *
261
     * More specifically, this L (the length of DSA Prime P) and N (the length of DSA Group Order q)
275
     * More specifically, this L (the length of DSA Prime P) and N (the length of DSA Group Order q)
262
     *
276
     *
-
 
277
     * @access public
263
     * @return array
278
     * @return array
264
     */
279
     */
265
    public function getLength()
280
    public function getLength()
266
    {
281
    {
267
        return ['L' => $this->p->getLength(), 'N' => $this->q->getLength()];
282
        return ['L' => $this->p->getLength(), 'N' => $this->q->getLength()];
Line 270... Line 285...
270
    /**
285
    /**
271
     * Returns the current engine being used
286
     * Returns the current engine being used
272
     *
287
     *
273
     * @see self::useInternalEngine()
288
     * @see self::useInternalEngine()
274
     * @see self::useBestEngine()
289
     * @see self::useBestEngine()
-
 
290
     * @access public
275
     * @return string
291
     * @return string
276
     */
292
     */
277
    public function getEngine()
293
    public function getEngine()
278
    {
294
    {
279
        if (!isset(self::$engines['PHP'])) {
295
        if (!isset(self::$engines['PHP'])) {
Line 288... Line 304...
288
     *
304
     *
289
     * A public / private key is only returned if the currently loaded "key" contains an x or y
305
     * A public / private key is only returned if the currently loaded "key" contains an x or y
290
     * value.
306
     * value.
291
     *
307
     *
292
     * @see self::getPublicKey()
308
     * @see self::getPublicKey()
-
 
309
     * @access public
293
     * @return mixed
310
     * @return mixed
294
     */
311
     */
295
    public function getParameters()
312
    public function getParameters()
296
    {
313
    {
297
        $type = self::validatePlugin('Keys', 'PKCS1', 'saveParameters');
314
        $type = self::validatePlugin('Keys', 'PKCS1', 'saveParameters');
Line 305... Line 322...
305
    /**
322
    /**
306
     * Determines the signature padding mode
323
     * Determines the signature padding mode
307
     *
324
     *
308
     * Valid values are: ASN1, SSH2, Raw
325
     * Valid values are: ASN1, SSH2, Raw
309
     *
326
     *
-
 
327
     * @access public
310
     * @param string $format
328
     * @param string $format
311
     */
329
     */
312
    public function withSignatureFormat($format)
330
    public function withSignatureFormat($format)
313
    {
331
    {
314
        $new = clone $this;
332
        $new = clone $this;
Line 318... Line 336...
318
    }
336
    }
319
 
337
 
320
    /**
338
    /**
321
     * Returns the signature format currently being used
339
     * Returns the signature format currently being used
322
     *
340
     *
-
 
341
     * @access public
323
     */
342
     */
324
    public function getSignatureFormat()
343
    public function getSignatureFormat()
325
    {
344
    {
326
        return $this->shortFormat;
345
        return $this->shortFormat;
327
    }
346
    }