@@ -221,8 +221,6 @@ void Point_Ge_from_Gej(secp256k1_ge* pGe, const gej_t* p)
221221 AffinePoint ap ;
222222 Gej_Get_Affine (p , & ap );
223223
224- Suffer (1000 ); // Very heavy
225-
226224 Point_Ge_from_Affine (pGe , & ap );
227225 }
228226}
@@ -1564,7 +1562,8 @@ static void RangeProof_Calculate_S(RangeProof* const p, RangeProof_Worker* const
15641562 NonceGenerator_NextScalar (& pWrk -> m_NonceGen , & s );
15651563 MulG (pWrk -> m_pGej + 1 , & s ); // can mul fast!
15661564
1567- gej_t gej2 ;
1565+ gej_t gej1 , gej2 ;
1566+ Gej_Init (& gej1 );
15681567 Gej_Init (& gej2 );
15691568
15701569 UintBig pK [2 ];
@@ -1615,6 +1614,7 @@ static void RangeProof_Calculate_S(RangeProof* const p, RangeProof_Worker* const
16151614 }
16161615
16171616 secp256k1_scalar * const pTrg = pS + mmCtx .m_Fast .m_Count ;
1617+ mmCtx .m_Fast .m_Count ++ ;
16181618
16191619#endif // BeamCrypto_ExternalGej
16201620
@@ -1634,27 +1634,30 @@ static void RangeProof_Calculate_S(RangeProof* const p, RangeProof_Worker* const
16341634
16351635 if (1 & iBit )
16361636 {
1637- Gej_Set_Affine (pWrk -> m_pGej , Context_get ()-> m_pGenRangeproof [iBit - 1 ]);
1637+ Gej_Set_Affine (& gej1 , Context_get ()-> m_pGenRangeproof [iBit - 1 ]);
16381638 Gej_Set_Affine (& gej2 , Context_get ()-> m_pGenRangeproof [iBit ]);
16391639
1640- Gej_Mul2_Fast (pWrk -> m_pGej , pWrk -> m_pGej , pK , & gej2 , pK + 1 );
1640+ Gej_Mul2_Fast (pWrk -> m_pGej , & gej1 , pK , & gej2 , pK + 1 );
16411641
16421642 Gej_Add (pWrk -> m_pGej + 1 , pWrk -> m_pGej + 1 , pWrk -> m_pGej );
16431643 }
16441644
1645- #else // BeamCrypto_ExternalGej
1646- mmCtx .m_Fast .m_Count ++ ;
16471645#endif // BeamCrypto_ExternalGej
16481646 }
16491647
16501648#ifdef BeamCrypto_ExternalGej
1649+
16511650 Gej_Destroy (& gej2 );
1651+ Gej_Destroy (& gej1 );
1652+
16521653#else // BeamCrypto_ExternalGej
1654+
16531655 mmCtx .m_pRes = pWrk -> m_pGej + 1 ;
16541656 MultiMac_Calculate (& mmCtx );
16551657
16561658 if (Calc_S_Naggle < Calc_S_Naggle_Max )
16571659 wrap_gej_add_var (pWrk -> m_pGej + 1 , pWrk -> m_pGej + 1 , pWrk -> m_pGej );
1660+
16581661#endif // BeamCrypto_ExternalGej
16591662}
16601663
@@ -2688,6 +2691,13 @@ static int TxAggr_AddAmount_Raw(int64_t* pRcv, Amount newVal, int isOut)
26882691
26892692 return 1 ;
26902693}
2694+
2695+ static int TxAggr_AddAmount_Uns (Amount * pRes , Amount newVal )
2696+ {
2697+ * pRes += newVal ;
2698+ return (* pRes ) >= newVal ;
2699+ }
2700+
26912701static int TxAggr_AddAmount (KeyKeeper * p , Amount newVal , AssetID aid , int isOut )
26922702{
26932703 int64_t * pRcv = & p -> u .m_TxBalance .m_RcvBeam ;
@@ -2707,11 +2717,6 @@ static int TxAggr_AddAmount(KeyKeeper* p, Amount newVal, AssetID aid, int isOut)
27072717
27082718 return TxAggr_AddAmount_Raw (pRcv , newVal , isOut );
27092719}
2710- static int TxAggr_AddFee (KeyKeeper * p , Amount newVal )
2711- {
2712- p -> u .m_TxBalance .m_TotalFee += newVal ;
2713- return (p -> u .m_TxBalance .m_TotalFee >= newVal );
2714- }
27152720
27162721__stack_hungry__
27172722static uint16_t TxAggr_AddCoins (KeyKeeper * p , CoinID * pCid_unaligned , uint32_t nCount , int isOut )
@@ -2754,8 +2759,8 @@ static uint16_t TxAggr_AddShieldedInputs(KeyKeeper* p, uint8_t* pIns_unaligned,
27542759
27552760 if (fmt .m_Fee )
27562761 {
2757- // Starding from HF3 shielded input fees are optional. And basically should not be used. But currently we support them
2758- if (!TxAggr_AddFee ( p , fmt .m_Fee ))
2762+ // Starting from HF3 shielded input fees are optional. And basically should not be used. But currently we support them
2763+ if (!TxAggr_AddAmount_Uns ( & p -> u . m_TxBalance . m_ImplicitFee , fmt .m_Fee ))
27592764 return MakeStatus (c_KeyKeeper_Status_Unspecified , 1 ); // overflow
27602765 }
27612766
@@ -2770,7 +2775,7 @@ static uint16_t TxAggr_AddShieldedInputs(KeyKeeper* p, uint8_t* pIns_unaligned,
27702775 return c_KeyKeeper_Status_Ok ;
27712776}
27722777
2773- static uint16_t TxAggr_Get (KeyKeeper * p , TxSummary * pRes , const TxCommonIn * pTx , uint8_t isSender )
2778+ static uint16_t TxAggr_Get (const KeyKeeper * p , TxSummary * pRes , const TxCommonIn * pTx , uint8_t isSender )
27742779{
27752780 if (c_KeyKeeper_State_TxBalance != p -> m_State )
27762781 return MakeStatus (c_KeyKeeper_Status_Unspecified , 10 );
@@ -2784,16 +2789,17 @@ static uint16_t TxAggr_Get(KeyKeeper* p, TxSummary* pRes, const TxCommonIn* pTx,
27842789 int64_t rcvVal = p -> u .m_TxBalance .m_RcvBeam ;
27852790 if (isSender )
27862791 {
2787- if (!TxAggr_AddFee (p , pRes -> m_Krn .m_Fee ))
2792+ Amount totalFee = p -> u .m_TxBalance .m_ImplicitFee ;
2793+ if (!TxAggr_AddAmount_Uns (& totalFee , pRes -> m_Krn .m_Fee ))
27882794 return MakeStatus (c_KeyKeeper_Status_Unspecified , 15 );
27892795
27902796 // we're paying the fee. Subtract it from the net value we're sending
2791- if (!TxAggr_AddAmount_Raw (& rcvVal , p -> u . m_TxBalance . m_TotalFee , 1 ))
2797+ if (!TxAggr_AddAmount_Raw (& rcvVal , totalFee , 1 ))
27922798 return MakeStatus (c_KeyKeeper_Status_Unspecified , 17 );
27932799 }
27942800 else
27952801 {
2796- if (p -> u .m_TxBalance .m_TotalFee )
2802+ if (p -> u .m_TxBalance .m_ImplicitFee )
27972803 // Implicit fees are not allowed for rcv tx (since we don't ask user permission)
27982804 return MakeStatus (c_KeyKeeper_Status_Unspecified , 16 );
27992805 }
@@ -3439,7 +3445,7 @@ typedef struct
34393445
34403446 union
34413447 {
3442- const ShieldedOfflineContext * m_pOffline ;
3448+ ShieldedOfflineContext * m_pOffline ;
34433449 const ShieldedViewer * m_pViewer ;
34443450 } u ;
34453451
@@ -3593,6 +3599,7 @@ static void CreateVoucherInternal(const ShieldedVoucherContext* pCtx, ShieldedVo
35933599#ifdef BeamCrypto_ExternalGej
35943600
35953601 Gej_MulFast (& gej , pCtx -> u .m_pOffline -> m_pPubGJG + 2 , & sk ); // ser.G
3602+ Gej_Destroy (pCtx -> u .m_pOffline -> m_pPubGJG + 2 );
35963603
35973604#else // BeamCrypto_ExternalGej
35983605
@@ -3638,11 +3645,14 @@ static void CreateVoucherInternal(const ShieldedVoucherContext* pCtx, ShieldedVo
36383645#ifdef BeamCrypto_ExternalGej
36393646
36403647 Gej_MulFast (& gej , pCtx -> u .m_pOffline -> m_pPubGJG , pN );
3648+ Gej_Destroy (pCtx -> u .m_pOffline -> m_pPubGJG );
36413649
36423650 gej_t gej2 ;
36433651 Gej_Init (& gej2 );
36443652
36453653 Gej_MulFast (& gej2 , pCtx -> u .m_pOffline -> m_pPubGJG + 1 , pN + 1 );
3654+ Gej_Destroy (pCtx -> u .m_pOffline -> m_pPubGJG + 1 );
3655+
36463656 Gej_Add (& gej , & gej , & gej2 );
36473657
36483658 Gej_Destroy (& gej2 );
0 commit comments