From 3cf1d9b9e42ae24ca67b438d56e779ab195c4707 Mon Sep 17 00:00:00 2001
From: Paragon Initiatve Enterprises <security@paragonie.com>
Date: Tue, 11 Oct 2022 03:30:41 -0400
Subject: [PATCH] Backport k3.seal fix from v2 branch

See #12, #13
---
 src/Operations/PKE/PKEv3.php    | 4 ++--
 tests/test-vectors/k3.seal.json | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/Operations/PKE/PKEv3.php b/src/Operations/PKE/PKEv3.php
index 3e4e617..8e07d06 100644
--- a/src/Operations/PKE/PKEv3.php
+++ b/src/Operations/PKE/PKEv3.php
@@ -81,7 +81,7 @@ public function seal(SymmetricKey $ptk, SealingPublicKey $pk): string
         $eph_pk = $eph_sk->getPublicKey();
         $seal_pk = PublicKey::importPem($pk->raw());
 
-        $pk_compressed = $seal_pk->toString();
+        $pk_compressed = Hex::decode($seal_pk->toString());
         $eph_pk_compressed = Hex::decode($eph_pk->toString());
 
         // Step 2:
@@ -168,7 +168,7 @@ public function unseal(string $header, string $encoded, SealingSecretKey $sk): S
         if (!($pk_obj instanceof PublicKey)) {
             throw new TypeError("An unexpected type violation occurred");
         }
-        $pk_compressed = $pk_obj->toString();
+        $pk_compressed = Hex::decode($pk_obj->toString());
 
         // Step 2:
         $Ak = hash(
diff --git a/tests/test-vectors/k3.seal.json b/tests/test-vectors/k3.seal.json
index b491ce1..40b4f0f 100644
--- a/tests/test-vectors/k3.seal.json
+++ b/tests/test-vectors/k3.seal.json
@@ -7,7 +7,7 @@
       "sealing-secret-key": "-----BEGIN EC PRIVATE KEY-----\nMIGkAgEBBDAhUb6WGhABE1MTj0x7E/5acgyap23kh7hUAVoAavKyfhYcmI3n1Q7L\nJpHxNb792H6gBwYFK4EEACKhZANiAAT5H7mTSOyjfILDtSuavZfalI3doM8pRUlb\nTzNyYLqM9iVmajpc0JRXvKuBtGtYi7Yft+eqFr6BuzGrdb4Z1vkvRcI504m0qKiE\nzjhi6u4sNgzW23rrVkRYkb2oE3SJPko=\n-----END EC PRIVATE KEY-----",
       "sealing-public-key": "-----BEGIN PUBLIC KEY-----\nMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE+R+5k0jso3yCw7Urmr2X2pSN3aDPKUVJ\nW08zcmC6jPYlZmo6XNCUV7yrgbRrWIu2H7fnqha+gbsxq3W+Gdb5L0XCOdOJtKio\nhM44YuruLDYM1tt661ZEWJG9qBN0iT5K\n-----END PUBLIC KEY-----",
       "unsealed": "0000000000000000000000000000000000000000000000000000000000000000",
-      "paserk": "k3.seal.Re1_8c1NeFaVVuzysZyNUUlv6oZE2zhpv_Bqs25hexJ1cKr4dDtKKtp9oWNJZ6v-Ah1dx3k4zPqRdua4fzjq8bYP6FYDc4mCqH4KZhwgsEOM955uO6HT_Vfg_Od0qoXhgQ3lHi1H10vBfFa0PaeDXK2B_H3_YQZH8Z_1lOGnRwb2"
+      "paserk": "k3.seal.NsI9NFzAouTSs7V5mejAeyBLYcoeNlbb9eY8C2KnkPTsARsPLen9KfMFfgqeI50FAnuRCdcb4HmXPaY3i-ZdBXwfdqSiB_65lmIHosVOJ7chmqqscnBkA7vc3mEAXxM05hSytjBYFxwlUnfFE3Sq3YHUZrOELF7PM87K6FFOMqc6"
     },
     {
       "name": "k3.seal-2",
@@ -15,7 +15,7 @@
       "sealing-secret-key": "-----BEGIN EC PRIVATE KEY-----\nMIGkAgEBBDAhUb6WGhABE1MTj0x7E/5acgyap23kh7hUAVoAavKyfhYcmI3n1Q7L\nJpHxNb792H6gBwYFK4EEACKhZANiAAT5H7mTSOyjfILDtSuavZfalI3doM8pRUlb\nTzNyYLqM9iVmajpc0JRXvKuBtGtYi7Yft+eqFr6BuzGrdb4Z1vkvRcI504m0qKiE\nzjhi6u4sNgzW23rrVkRYkb2oE3SJPko=\n-----END EC PRIVATE KEY-----",
       "sealing-public-key": "-----BEGIN PUBLIC KEY-----\nMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE+R+5k0jso3yCw7Urmr2X2pSN3aDPKUVJ\nW08zcmC6jPYlZmo6XNCUV7yrgbRrWIu2H7fnqha+gbsxq3W+Gdb5L0XCOdOJtKio\nhM44YuruLDYM1tt661ZEWJG9qBN0iT5K\n-----END PUBLIC KEY-----",
       "unsealed": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
-      "paserk": "k3.seal.LpevSc3v4VYqlUjEr3OD4LSMaYspcU-VlqI8rpywnFwVKqT1sMJQB_K3GwyszVueA8QJ3KmBUr4ravEb8DsazPuXcWbrnQF4CJmUQSgaTI4YyCb35n-xkx8CDA7ig-m-lhhYKkp_r3Ybcm-s9BKPlPW2VRr791ukbrCSRXFkQ8sR"
+      "paserk": "k3.seal.qCFR9x-TwGcUQgprulNtvJqy7ZOipwmHQMOXXaJKetgYFsDm1aP3P9ljbCcDFlj0AqWxxuxaIFi59cCHDAysYdL5gzsVUTz-boo5G4V49FGiJu4kGj5pov1RKijsvaN4XQVhui57jUKWMy1fnjC5E6DrYlII2WWBKVMSbsnXuPGI"
     },
     {
       "name": "k3.seal-fail-1",