Subversion Repositories oidplus

Rev

Rev 874 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 874 Rev 1042
Line 3... Line 3...
3
/**
3
/**
4
 * Ed25519
4
 * Ed25519
5
 *
5
 *
6
 * PHP version 5 and 7
6
 * PHP version 5 and 7
7
 *
7
 *
8
 * @category  Crypt
-
 
9
 * @package   EC
-
 
10
 * @author    Jim Wigginton <terrafrost@php.net>
8
 * @author    Jim Wigginton <terrafrost@php.net>
11
 * @copyright 2017 Jim Wigginton
9
 * @copyright 2017 Jim Wigginton
12
 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
10
 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
13
 */
11
 */
14
 
12
 
Line 156... Line 154...
156
     * Implements steps 1-3 at https://tools.ietf.org/html/rfc8032#section-5.1.5
154
     * Implements steps 1-3 at https://tools.ietf.org/html/rfc8032#section-5.1.5
157
     *
155
     *
158
     * Used by the various key handlers
156
     * Used by the various key handlers
159
     *
157
     *
160
     * @param string $str
158
     * @param string $str
161
     * @return \phpseclib3\Math\PrimeField\Integer
159
     * @return array
162
     */
160
     */
163
    public function extractSecret($str)
161
    public function extractSecret($str)
164
    {
162
    {
165
        if (strlen($str) != 32) {
163
        if (strlen($str) != 32) {
166
            throw new \LengthException('Private Key should be 32-bytes long');
164
            throw new \LengthException('Private Key should be 32-bytes long');
Line 179... Line 177...
179
        $h[0] = ($h[0] & chr(0x3F)) | chr(0x40);
177
        $h[0] = ($h[0] & chr(0x3F)) | chr(0x40);
180
        // 3.  Interpret the buffer as the little-endian integer, forming a
178
        // 3.  Interpret the buffer as the little-endian integer, forming a
181
        //     secret scalar s.
179
        //     secret scalar s.
182
        $dA = new BigInteger($h, 256);
180
        $dA = new BigInteger($h, 256);
183
 
181
 
-
 
182
        return [
-
 
183
            'dA' => $dA,
184
        $dA->secret = $str;
184
            'secret' => $str
185
        return $dA;
185
        ];
186
    }
186
    }
187
 
187
 
188
    /**
188
    /**
189
     * Encode a point as a string
189
     * Encode a point as a string
190
     *
190
     *
Line 209... Line 209...
209
     *
209
     *
210
     * @return \phpseclib3\Math\PrimeField\Integer
210
     * @return \phpseclib3\Math\PrimeField\Integer
211
     */
211
     */
212
    public function createRandomMultiplier()
212
    public function createRandomMultiplier()
213
    {
213
    {
214
        return $this->extractSecret(Random::string(32));
214
        return $this->extractSecret(Random::string(32))['dA'];
215
    }
215
    }
216
 
216
 
217
    /**
217
    /**
218
     * Converts an affine point to an extended homogeneous coordinate
218
     * Converts an affine point to an extended homogeneous coordinate
219
     *
219
     *