/** * @param NamedCurveFp $curve * @return ObjectIdentifier */ public static function getCurveOid(NamedCurveFp $curve) { if (array_key_exists($curve->getName(), self::$oidMap)) { $oidString = self::$oidMap[$curve->getName()]; return new ObjectIdentifier($oidString); } throw new \RuntimeException('Unsupported curve type.'); }
/** * @param MathAdapterInterface $math * @param NamedCurveFp $curve * @param GeneratorPoint $generatorPoint * @param Hasher $hasher - must be a known hash algorithm */ public function __construct(MathAdapterInterface $math, NamedCurveFp $curve, GeneratorPoint $generatorPoint, Hasher $hasher) { if (!$curve->contains($generatorPoint->getX(), $generatorPoint->getY())) { throw new \RuntimeException('Provided generator point does not exist on curve'); } $this->hasher = $hasher; $this->curve = $curve; $this->generator = $generatorPoint; $this->math = $math; }
/** * @param NamedCurveFp $curve * @return string */ public function getCanonicalCurveName(NamedCurveFp $curve) { switch ($curve->getName()) { case 'nist-p256': return 'nistp256'; case 'nist-p384': return 'nistp384'; case 'nist-p521': return 'nistp521'; default: throw new \RuntimeException('Key not supported by git'); } }
/** * @param MathAdapterInterface $math * @param NamedCurveFp $c * @return Sequence */ private function getCurveAsn(MathAdapterInterface $math, NamedCurveFp $c) { $a = new OctetString($math->decHex($math->mod($c->getA(), $c->getPrime()))); $b = new OctetString($math->decHex($math->mod($c->getB(), $c->getPrime()))); try { $seed = CurveRandomSeed::getSeed($c); return new Sequence($a, $b, new BitString($seed)); } catch (\Exception $e) { return new Sequence($a, $b); } }