Skip to content

Conversation

@robertboeser
Copy link

Target branch: 4.2.x

  • It is a Bug fix
  • It is a New feature
  • It is related to dependencies

Includes:

  • Breaks BC
  • Deprecations

I needed support for the brainpool curve, so I added support for it. Maybe it is useful for somebody else, too.

@Spomky Spomky self-assigned this Nov 20, 2025
@Spomky Spomky added this to the 4.2.0 milestone Nov 20, 2025
@Spomky
Copy link
Member

Spomky commented Nov 20, 2025

Thank you.
Please let me have some time to review it carefully.

Copy link
Member

@Spomky Spomky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @robertboeser,

Please fix the issues I spotted.
Also, would you mind adding some tests to confirm:

  • BP-256 key creation
  • PEM import/export to check the OID
  • OpenSSL compatibility

Many thanks.
Regards.

{
$der = match ($jwk->get('crv')) {
'P-256' => self::p256PublicKey(),
'BP-256' => self::p256PublicKey(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct as the OID is different for BP public keys

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be as follows:

  private static function bp256PublicKey(): string
  {
      return pack(
          'H*',
          '305a' // SEQUENCE, length 90
          . '3014' // SEQUENCE, length 20
          . '0607' // OID, length 7
          . '2a8648ce3d0201' // 1.2.840.10045.2.1 = EC Public Key
          . '0609' // OID, length 9
          . '2b2403030208010107' // 1.3.36.3.3.2.8.1.1.7 = brainpoolP256r1
          . '0342' // BIT STRING, length 66
          . '00' // prepend with NUL
      );
  }

{
$der = match ($jwk->get('crv')) {
'P-256' => self::p256PrivateKey($jwk),
'BP-256' => self::p256PrivateKey($jwk),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. The OID is different for BP private keys

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be as follows:

  private static function bp256PrivateKey(JWK $jwk): string
  {
      $d = $jwk->get('d');
      if (!is_string($d)) {
          throw new InvalidArgumentException('Unable to get the private key');
      }
      $d = unpack('H*', str_pad(Base64UrlSafe::decodeNoPadding($d), 32, "\0", STR_PAD_LEFT));
      if (!is_array($d) || !isset($d[1])) {
          throw new InvalidArgumentException('Unable to get the private key');
      }

      return pack(
          'H*',
          '3078' // SEQUENCE, length 120
          . '020101' // INTEGER, 1
          . '0420' // OCTET STRING, length 32
          . $d[1]
          . 'a00b' // TAGGED OBJECT #0, length 11
          . '0609' // OID, length 9
          . '2b2403030208010107' // 1.3.36.3.3.2.8.1.1.7
          . 'a144' // TAGGED OBJECT #1, length 68
          . '0342' // BIT STRING, length 66
          . '00'
      );
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants