Skip to content
Snippets Groups Projects
Select Git revision
  • 6d2304df43d7d73c0ec1d5e69b8aa808c3666d6c
  • release default protected
  • XX-4719/announcementChannels
  • jonah/channelCodenames
  • master protected
  • XX-4601/HavenInvites
  • sihSize
  • project/HavenNotifications
  • hotfix/base8KeySizes
  • Anne/Project/DM
  • XX-4004_ownership_vector_test
  • XX-3566_constant_time_comparison
  • XX-4132-upgrade-channel-keying
  • XX-4133-rsa-to-private
  • XX-3958/ConnectionCLI
  • xx-3893/asymmetric
  • xx-3891/symmetric-integration
  • hotfix/groupChat
  • XX-3770/UpdateExternalDeps
  • dev
  • waitingRoundsRewrite
  • v0.0.9
  • v0.0.8
  • v0.0.7
  • v0.0.6
  • v0.0.5
  • v0.0.4
  • v0.0.3
  • v0.0.2
  • v0.0.1
30 results

recipientID.go

  • recipientID.go 1.39 KiB
    ///////////////////////////////////////////////////////////////////////////////
    // Copyright © 2020 xx network SEZC                                          //
    //                                                                           //
    // Use of this source code is governed by a license that can be found in the //
    // LICENSE file                                                              //
    ///////////////////////////////////////////////////////////////////////////////
    
    package singleUse
    
    import (
    	jww "github.com/spf13/jwalterweatherman"
    	"gitlab.com/elixxir/crypto/cyclic"
    	"gitlab.com/elixxir/crypto/hash"
    	"gitlab.com/xx_network/primitives/id"
    )
    
    // NewRecipientID generates the recipient ID for a single-use sender. The ID is
    // generated from the hash of the unencrypted transmission payload. The
    // unencryptedPayload must contain a nonce to prevent collision on the same
    // message being sent multiple times.
    func NewRecipientID(pubKey *cyclic.Int, unencryptedPayload []byte) *id.ID {
    	// Create new hash
    	h, err := hash.NewCMixHash()
    	if err != nil {
    		jww.FATAL.Panicf("[SU] Failed to create new hash for single-use "+
    			"communication recipient ID: %+v", err)
    	}
    
    	// Hash the public key and unencrypted payload
    	h.Write(pubKey.Bytes())
    	h.Write(unencryptedPayload)
    
    	// Get hash bytes
    	rid := &id.ID{}
    	copy(rid[:], h.Sum(nil))
    
    	// Set the ID type to user
    	rid.SetType(id.User)
    
    	return rid
    }