@@ -97,10 +97,11 @@ void Secp256k1PP::encryptECIES(Public const& _k, bytesConstRef _sharedMacData, b
9797	auto  key = ecies::kdf (z, bytes (), 32 );
9898	bytesConstRef eKey = bytesConstRef (&key).cropped (0 , 16 );
9999	bytesRef mKeyMaterial  = bytesRef (&key).cropped (16 , 16 );
100- 	CryptoPP::SHA256 ctx;
101- 	ctx.Update (mKeyMaterial .data (), mKeyMaterial .size ());
100+ 	secp256k1_sha256_t  ctx;
101+ 	secp256k1_sha256_initialize (&ctx);
102+ 	secp256k1_sha256_write (&ctx, mKeyMaterial .data (), mKeyMaterial .size ());
102103	bytes mKey (32 );
103- 	ctx. Final ( mKey .data ());
104+ 	secp256k1_sha256_finalize (&ctx,  mKey .data ());
104105
105106	auto  iv = h128::random ();
106107	bytes cipherText = encryptSymNoAuth (SecureFixedHash<16 >(eKey), iv, bytesConstRef (&io_cipher));
@@ -113,14 +114,15 @@ void Secp256k1PP::encryptECIES(Public const& _k, bytesConstRef _sharedMacData, b
113114	iv.ref ().copyTo (bytesRef (&msg).cropped (1  + Public::size, h128::size));
114115	bytesRef msgCipherRef = bytesRef (&msg).cropped (1  + Public::size + h128::size, cipherText.size ());
115116	bytesConstRef (&cipherText).copyTo (msgCipherRef);
116- 	 
117+ 
117118	//  tag message
118- 	CryptoPP::HMAC<SHA256> hmacctx (mKey .data (), mKey .size ());
119+ 	secp256k1_hmac_sha256_t  hmacCtx;
120+ 	secp256k1_hmac_sha256_initialize (&hmacCtx, mKey .data (), mKey .size ());
119121	bytesConstRef cipherWithIV = bytesRef (&msg).cropped (1  + Public::size, h128::size + cipherText.size ());
120- 	hmacctx. Update ( cipherWithIV.data (), cipherWithIV.size ());
121- 	hmacctx. Update ( _sharedMacData.data (), _sharedMacData.size ());
122- 	hmacctx. Final ( msg.data () + 1  + Public::size + cipherWithIV.size ());
123- 	 
122+ 	secp256k1_hmac_sha256_write (&hmacCtx,  cipherWithIV.data (), cipherWithIV.size ());
123+ 	secp256k1_hmac_sha256_write (&hmacCtx,  _sharedMacData.data (), _sharedMacData.size ());
124+ 	secp256k1_hmac_sha256_finalize (&hmacCtx,  msg.data () + 1  + Public::size + cipherWithIV.size ());
125+ 
124126	io_cipher.resize (msg.size ());
125127	io_cipher.swap (msg);
126128}
0 commit comments