@@ -725,23 +725,24 @@ namespace garlic
725
725
726
726
bool ECIESX25519AEADRatchetSession::NewExistingSessionMessage (const uint8_t * payload, size_t len, uint8_t * out, size_t outLen)
727
727
{
728
+ auto owner = GetOwner ();
729
+ if (!owner) return false ;
728
730
uint8_t nonce[12 ];
729
731
auto index = m_SendTagset->GetNextIndex ();
730
732
CreateNonce (index, nonce); // tag's index
731
733
uint64_t tag = m_SendTagset->GetNextSessionTag ();
732
734
if (!tag)
733
735
{
734
736
LogPrint (eLogError, " Garlic: Can't create new ECIES-X25519-AEAD-Ratchet tag for send tagset" );
735
- if (GetOwner ())
736
- GetOwner ()->RemoveECIESx25519Session (m_RemoteStaticKey);
737
+ owner->RemoveECIESx25519Session (m_RemoteStaticKey);
737
738
return false ;
738
739
}
739
740
memcpy (out, &tag, 8 );
740
741
// ad = The session tag, 8 bytes
741
742
// ciphertext = ENCRYPT(k, n, payload, ad)
742
743
uint8_t key[32 ];
743
744
m_SendTagset->GetSymmKey (index, key);
744
- if (!i2p::crypto::AEADChaCha20Poly1305 (payload, len, out, 8 , key, nonce, out + 8 , outLen - 8 , true )) // encrypt
745
+ if (!owner-> AEADChaCha20Poly1305Encrypt (payload, len, out, 8 , key, nonce, out + 8 , outLen - 8 ))
745
746
{
746
747
LogPrint (eLogWarning, " Garlic: Payload section AEAD encryption failed" );
747
748
return false ;
@@ -760,34 +761,35 @@ namespace garlic
760
761
uint8_t * payload = buf + 8 ;
761
762
uint8_t key[32 ];
762
763
receiveTagset->GetSymmKey (index, key);
763
- if (!i2p::crypto::AEADChaCha20Poly1305 (payload, len - 16 , buf, 8 , key, nonce, payload, len - 16 , false )) // decrypt
764
+ auto owner = GetOwner ();
765
+ if (!owner) return true ; // drop message
766
+
767
+ if (!owner->AEADChaCha20Poly1305Decrypt (payload, len - 16 , buf, 8 , key, nonce, payload, len - 16 ))
764
768
{
765
769
LogPrint (eLogWarning, " Garlic: Payload section AEAD decryption failed" );
766
770
return false ;
767
771
}
768
772
HandlePayload (payload, len - 16 , receiveTagset, index);
769
- if (GetOwner ())
773
+
774
+ int moreTags = 0 ;
775
+ if (owner->GetNumRatchetInboundTags () > 0 ) // override in settings?
770
776
{
771
- int moreTags = 0 ;
772
- if (GetOwner ()->GetNumRatchetInboundTags () > 0 ) // override in settings?
773
- {
774
- if (receiveTagset->GetNextIndex () - index < GetOwner ()->GetNumRatchetInboundTags ()/2 )
775
- moreTags = GetOwner ()->GetNumRatchetInboundTags ();
776
- index -= GetOwner ()->GetNumRatchetInboundTags (); // trim behind
777
- }
778
- else
779
- {
780
- moreTags = (receiveTagset->GetTagSetID () > 0 ) ? ECIESX25519_MAX_NUM_GENERATED_TAGS : // for non first tagset
781
- (ECIESX25519_MIN_NUM_GENERATED_TAGS + (index >> 1 )); // N/2
782
- if (moreTags > ECIESX25519_MAX_NUM_GENERATED_TAGS) moreTags = ECIESX25519_MAX_NUM_GENERATED_TAGS;
783
- moreTags -= (receiveTagset->GetNextIndex () - index);
784
- index -= ECIESX25519_MAX_NUM_GENERATED_TAGS; // trim behind
785
- }
786
- if (moreTags > 0 )
787
- GenerateMoreReceiveTags (receiveTagset, moreTags);
788
- if (index > 0 )
789
- receiveTagset->SetTrimBehind (index);
777
+ if (receiveTagset->GetNextIndex () - index < owner->GetNumRatchetInboundTags ()/2 )
778
+ moreTags = owner->GetNumRatchetInboundTags ();
779
+ index -= owner->GetNumRatchetInboundTags (); // trim behind
780
+ }
781
+ else
782
+ {
783
+ moreTags = (receiveTagset->GetTagSetID () > 0 ) ? ECIESX25519_MAX_NUM_GENERATED_TAGS : // for non first tagset
784
+ (ECIESX25519_MIN_NUM_GENERATED_TAGS + (index >> 1 )); // N/2
785
+ if (moreTags > ECIESX25519_MAX_NUM_GENERATED_TAGS) moreTags = ECIESX25519_MAX_NUM_GENERATED_TAGS;
786
+ moreTags -= (receiveTagset->GetNextIndex () - index);
787
+ index -= ECIESX25519_MAX_NUM_GENERATED_TAGS; // trim behind
790
788
}
789
+ if (moreTags > 0 )
790
+ GenerateMoreReceiveTags (receiveTagset, moreTags);
791
+ if (index > 0 )
792
+ receiveTagset->SetTrimBehind (index);
791
793
return true ;
792
794
}
793
795
0 commit comments