This commit is contained in:
Sudo-Ivan
2024-12-30 04:00:52 -06:00
parent decbd8f29a
commit 139926be05
4 changed files with 196 additions and 60 deletions

View File

@@ -183,7 +183,8 @@ func (i *Identity) Encrypt(plaintext []byte, ratchet []byte) ([]byte, error) {
func (i *Identity) Hash() []byte {
h := sha256.New()
h.Write(i.GetPublicKey())
return h.Sum(nil)
fullHash := h.Sum(nil)
return fullHash[:TruncatedHashLen/8]
}
func TruncatedHash(data []byte) []byte {
@@ -200,6 +201,10 @@ func GetRandomHash() []byte {
}
func Remember(packetHash, destHash []byte, publicKey []byte, appData []byte) {
if len(destHash) > TruncatedHashLen/8 {
destHash = destHash[:TruncatedHashLen/8]
}
knownDestinations[string(destHash)] = []interface{}{
time.Now().Unix(),
packetHash,
@@ -213,6 +218,10 @@ func ValidateAnnounce(packet []byte, destHash []byte, publicKey []byte, signatur
return false
}
if len(destHash) > TruncatedHashLen/8 {
destHash = destHash[:TruncatedHashLen/8]
}
announced := &Identity{}
announced.publicKey = publicKey[:KeySize/16]
announced.verificationKey = publicKey[KeySize/16:]