4 * IEEE P1363 Signature Handler
8 * Handles signatures in the format described in
9 * https://standards.ieee.org/ieee/1363/2049/ and
10 * https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/sign#ecdsa
12 * @author Jim Wigginton <terrafrost@php.net>
13 * @copyright 2016 Jim Wigginton
14 * @license http://www.opensource.org/licenses/mit-license.html MIT License
15 * @link http://phpseclib.sourceforge.net
18 namespace phpseclib3\Crypt\EC\Formats\Signature;
20 use phpseclib3\Math\BigInteger;
23 * ASN1 Signature Handler
25 * @author Jim Wigginton <terrafrost@php.net>
35 public static function load($sig)
37 if (!is_string($sig)) {
46 $r = new BigInteger(substr($sig, 0, $len >> 1), 256);
47 $s = new BigInteger(substr($sig, $len >> 1), 256);
49 return compact('r', 's');
53 * Returns a signature in the appropriate format
55 * @param \phpseclib3\Math\BigInteger $r
56 * @param \phpseclib3\Math\BigInteger $s
59 public static function save(BigInteger $r, BigInteger $s)
63 $len = max(strlen($r), strlen($s));
64 return str_pad($r, $len, "\0", STR_PAD_LEFT) . str_pad($s, $len, "\0", STR_PAD_LEFT);