@@ -38,6 +38,47 @@ public function __construct(
3838 ) {}
3939
4040 /**
41+ * This is called Npk in the HPKE spec..
42+ *
43+ * @return int
44+ */
45+ public function getPublicKeyLength (): int
46+ {
47+ return match ($ this ->curve ) {
48+ Curve::Secp256k1, Curve::NistP256 => 65 ,
49+ Curve::NistP384 => 97 ,
50+ Curve::NistP521 => 133 ,
51+ Curve::X25519 => 32
52+ };
53+ }
54+
55+ /**
56+ * Thisi s called Nsec in the HPKE spec.
57+ */
58+ public function getSecretLength (): int
59+ {
60+ return match ($ this ->curve ) {
61+ Curve::Secp256k1, Curve::NistP256, Curve::X25519 => 32 ,
62+ Curve::NistP384 => 48 ,
63+ Curve::NistP521 => 64
64+ };
65+ }
66+
67+ /**
68+ * Thisi s called Nsk in the HPKE spec.
69+ */
70+ public function getSecretKeyLength (): int
71+ {
72+ return match ($ this ->curve ) {
73+ Curve::Secp256k1, Curve::NistP256, Curve::X25519 => 32 ,
74+ Curve::NistP384 => 48 ,
75+ Curve::NistP521 => 66
76+ };
77+ }
78+
79+ /**
80+ * This is called Nenc in the HPKE spec.
81+ *
4182 * @return int
4283 */
4384 public function getHeaderLength (): int
@@ -137,7 +178,7 @@ public function encapsulate(EncapsKeyInterface $encapsKey): array
137178 $ dh = $ this ->scalarMult ($ ephSecret , $ encapsKey );
138179 $ enc = $ ephPublic ->serializeForHeader ();
139180 $ kem_context = $ enc . $ encapsKey ->serializeForHeader ();
140- $ secret_length = $ this ->curve -> secretLength ();
181+ $ secret_length = $ this ->getSecretLength ();
141182 $ shared_secret = new SymmetricKey (
142183 $ this ->kdf ->extractAndExpand (
143184 suiteId: $ this ->getSuiteId (),
@@ -171,7 +212,7 @@ public function decapsulate(
171212 $ ephPublic = new EncapsKey ($ decapsKey ->curve , $ enc );
172213 $ dh = $ this ->scalarMult ($ decapsKey , $ ephPublic );
173214 $ kem_context = $ enc . $ decapsKey ->getEncapsKey ()->bytes ;
174- $ secret_length = $ this ->curve -> secretLength ();
215+ $ secret_length = $ this ->getSecretLength ();
175216 return new SymmetricKey (
176217 $ this ->kdf ->extractAndExpand ($ this ->getSuiteId (), $ dh , $ kem_context , $ secret_length )
177218 );
0 commit comments