@@ -3302,10 +3302,7 @@ public static IntPtr HpkeInit(HpkeKem kem, HpkeKdf kdf, HpkeAead aead)
33023302 }
33033303
33043304 /* Zero the memory */
3305- for ( int i = 0 ; i < HPKE_STRUCT_SZ ; i ++ )
3306- {
3307- Marshal . WriteByte ( hpke , i , 0 ) ;
3308- }
3305+ Marshal . Copy ( new byte [ HPKE_STRUCT_SZ ] , 0 , hpke , HPKE_STRUCT_SZ ) ;
33093306
33103307 int ret = wc_HpkeInit ( hpke , ( int ) kem , ( int ) kdf , ( int ) aead , IntPtr . Zero ) ;
33113308 if ( ret != 0 )
@@ -3537,6 +3534,48 @@ public static byte[] HpkeSealBase(IntPtr hpke, IntPtr ephemeralKey, IntPtr recei
35373534 }
35383535 }
35393536
3537+ /// <summary>
3538+ /// Convenience SingleShot seal (encrypt) using HPKE Base mode.
3539+ /// Generates an ephemeral keypair internally so the caller does not
3540+ /// need to manage one.
3541+ /// Returns enc||ciphertext as a single byte array.
3542+ /// </summary>
3543+ /// <param name="hpke">HPKE context from HpkeInit()</param>
3544+ /// <param name="receiverKey">Receiver public key</param>
3545+ /// <param name="info">Info context bytes (can be null)</param>
3546+ /// <param name="aad">Additional authenticated data (can be null)</param>
3547+ /// <param name="plaintext">Plaintext to encrypt</param>
3548+ /// <param name="kem">KEM used (needed to free the ephemeral key)</param>
3549+ /// <returns>enc||ciphertext byte array or null on failure</returns>
3550+ public static byte [ ] HpkeSealBase ( IntPtr hpke , IntPtr receiverKey ,
3551+ byte [ ] info , byte [ ] aad , byte [ ] plaintext , HpkeKem kem )
3552+ {
3553+ IntPtr ephemeralKey = IntPtr . Zero ;
3554+
3555+ try
3556+ {
3557+ ephemeralKey = HpkeGenerateKeyPair ( hpke ) ;
3558+ if ( ephemeralKey == IntPtr . Zero )
3559+ {
3560+ log ( ERROR_LOG , "HPKE seal base: ephemeral keygen failed" ) ;
3561+ return null ;
3562+ }
3563+
3564+ return HpkeSealBase ( hpke , ephemeralKey , receiverKey ,
3565+ info , aad , plaintext ) ;
3566+ }
3567+ catch ( Exception e )
3568+ {
3569+ log ( ERROR_LOG , "HPKE seal base exception " + e . ToString ( ) ) ;
3570+ return null ;
3571+ }
3572+ finally
3573+ {
3574+ if ( ephemeralKey != IntPtr . Zero )
3575+ HpkeFreeKey ( hpke , ephemeralKey , kem ) ;
3576+ }
3577+ }
3578+
35403579 /// <summary>
35413580 /// SingleShot open (decrypt) using HPKE Base mode.
35423581 /// Takes the full enc||ciphertext blob returned by HpkeSealBase.
0 commit comments