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   EC
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 47... Line 49...
47
use phpseclib3\Math\BigInteger;
49
use phpseclib3\Math\BigInteger;
48
 
50
 
49
/**
51
/**
50
 * Pure-PHP implementation of EC.
52
 * Pure-PHP implementation of EC.
51
 *
53
 *
-
 
54
 * @package EC
52
 * @author  Jim Wigginton <terrafrost@php.net>
55
 * @author  Jim Wigginton <terrafrost@php.net>
-
 
56
 * @access  public
53
 */
57
 */
54
abstract class EC extends AsymmetricKey
58
abstract class EC extends AsymmetricKey
55
{
59
{
56
    /**
60
    /**
57
     * Algorithm Name
61
     * Algorithm Name
58
     *
62
     *
59
     * @var string
63
     * @var string
-
 
64
     * @access private
60
     */
65
     */
61
    const ALGORITHM = 'EC';
66
    const ALGORITHM = 'EC';
62
 
67
 
63
    /**
68
    /**
64
     * Public Key QA
69
     * Public Key QA
Line 76... Line 81...
76
 
81
 
77
    /**
82
    /**
78
     * Signature Format
83
     * Signature Format
79
     *
84
     *
80
     * @var string
85
     * @var string
-
 
86
     * @access private
81
     */
87
     */
82
    protected $format;
88
    protected $format;
83
 
89
 
84
    /**
90
    /**
85
     * Signature Format (Short)
91
     * Signature Format (Short)
86
     *
92
     *
87
     * @var string
93
     * @var string
-
 
94
     * @access private
88
     */
95
     */
89
    protected $shortFormat;
96
    protected $shortFormat;
90
 
97
 
91
    /**
98
    /**
92
     * Curve Name
99
     * Curve Name
Line 124... Line 131...
124
    protected $context;
131
    protected $context;
125
 
132
 
126
    /**
133
    /**
127
     * Create public / private key pair.
134
     * Create public / private key pair.
128
     *
135
     *
-
 
136
     * @access public
129
     * @param string $curve
137
     * @param string $curve
130
     * @return \phpseclib3\Crypt\EC\PrivateKey
138
     * @return \phpseclib3\Crypt\EC\PrivateKey
131
     */
139
     */
132
    public static function createKey($curve)
140
    public static function createKey($curve)
133
    {
141
    {
Line 197... Line 205...
197
 
205
 
198
    /**
206
    /**
199
     * OnLoad Handler
207
     * OnLoad Handler
200
     *
208
     *
201
     * @return bool
209
     * @return bool
-
 
210
     * @access protected
202
     * @param array $components
211
     * @param array $components
203
     */
212
     */
204
    protected static function onLoad($components)
213
    protected static function onLoad($components)
205
    {
214
    {
206
        if (!isset(self::$engines['PHP'])) {
215
        if (!isset(self::$engines['PHP'])) {
Line 246... Line 255...
246
    /**
255
    /**
247
     * Returns the curve
256
     * Returns the curve
248
     *
257
     *
249
     * Returns a string if it's a named curve, an array if not
258
     * Returns a string if it's a named curve, an array if not
250
     *
259
     *
-
 
260
     * @access public
251
     * @return string|array
261
     * @return string|array
252
     */
262
     */
253
    public function getCurve()
263
    public function getCurve()
254
    {
264
    {
255
        if ($this->curveName) {
265
        if ($this->curveName) {
Line 293... Line 303...
293
     *  characteristic-2 curve is defined as the number of bits in the binary
303
     *  characteristic-2 curve is defined as the number of bits in the binary
294
     *  representation of the field, commonly denoted by m.  A set of
304
     *  representation of the field, commonly denoted by m.  A set of
295
     *  elliptic curve domain parameters defines a group of order n generated
305
     *  elliptic curve domain parameters defines a group of order n generated
296
     *  by a base point P"
306
     *  by a base point P"
297
     *
307
     *
-
 
308
     * @access public
298
     * @return int
309
     * @return int
299
     */
310
     */
300
    public function getLength()
311
    public function getLength()
301
    {
312
    {
302
        return $this->curve->getLength();
313
        return $this->curve->getLength();
Line 305... Line 316...
305
    /**
316
    /**
306
     * Returns the current engine being used
317
     * Returns the current engine being used
307
     *
318
     *
308
     * @see self::useInternalEngine()
319
     * @see self::useInternalEngine()
309
     * @see self::useBestEngine()
320
     * @see self::useBestEngine()
-
 
321
     * @access public
310
     * @return string
322
     * @return string
311
     */
323
     */
312
    public function getEngine()
324
    public function getEngine()
313
    {
325
    {
314
        if (!isset(self::$engines['PHP'])) {
326
        if (!isset(self::$engines['PHP'])) {
Line 343... Line 355...
343
 
355
 
344
    /**
356
    /**
345
     * Returns the parameters
357
     * Returns the parameters
346
     *
358
     *
347
     * @see self::getPublicKey()
359
     * @see self::getPublicKey()
-
 
360
     * @access public
348
     * @param string $type optional
361
     * @param string $type optional
349
     * @return mixed
362
     * @return mixed
350
     */
363
     */
351
    public function getParameters($type = 'PKCS1')
364
    public function getParameters($type = 'PKCS1')
352
    {
365
    {
Line 362... Line 375...
362
    /**
375
    /**
363
     * Determines the signature padding mode
376
     * Determines the signature padding mode
364
     *
377
     *
365
     * Valid values are: ASN1, SSH2, Raw
378
     * Valid values are: ASN1, SSH2, Raw
366
     *
379
     *
-
 
380
     * @access public
367
     * @param string $format
381
     * @param string $format
368
     */
382
     */
369
    public function withSignatureFormat($format)
383
    public function withSignatureFormat($format)
370
    {
384
    {
371
        if ($this->curve instanceof MontgomeryCurve) {
385
        if ($this->curve instanceof MontgomeryCurve) {
Line 379... Line 393...
379
    }
393
    }
380
 
394
 
381
    /**
395
    /**
382
     * Returns the signature format currently being used
396
     * Returns the signature format currently being used
383
     *
397
     *
-
 
398
     * @access public
384
     */
399
     */
385
    public function getSignatureFormat()
400
    public function getSignatureFormat()
386
    {
401
    {
387
        return $this->shortFormat;
402
        return $this->shortFormat;
388
    }
403
    }
Line 392... Line 407...
392
     *
407
     *
393
     * Used by Ed25519 / Ed448.
408
     * Used by Ed25519 / Ed448.
394
     *
409
     *
395
     * @see self::sign()
410
     * @see self::sign()
396
     * @see self::verify()
411
     * @see self::verify()
-
 
412
     * @access public
397
     * @param string $context optional
413
     * @param string $context optional
398
     */
414
     */
399
    public function withContext($context = null)
415
    public function withContext($context = null)
400
    {
416
    {
401
        if (!$this->curve instanceof TwistedEdwardsCurve) {
417
        if (!$this->curve instanceof TwistedEdwardsCurve) {
Line 418... Line 434...
418
    }
434
    }
419
 
435
 
420
    /**
436
    /**
421
     * Returns the signature format currently being used
437
     * Returns the signature format currently being used
422
     *
438
     *
-
 
439
     * @access public
423
     */
440
     */
424
    public function getContext()
441
    public function getContext()
425
    {
442
    {
426
        return $this->context;
443
        return $this->context;
427
    }
444
    }
428
 
445
 
429
    /**
446
    /**
430
     * Determines which hashing function should be used
447
     * Determines which hashing function should be used
431
     *
448
     *
-
 
449
     * @access public
432
     * @param string $hash
450
     * @param string $hash
433
     */
451
     */
434
    public function withHash($hash)
452
    public function withHash($hash)
435
    {
453
    {
436
        if ($this->curve instanceof MontgomeryCurve) {
454
        if ($this->curve instanceof MontgomeryCurve) {