Skip to content
Snippets Groups Projects
Select Git revision
  • 461a58e6a4e0622b852efd209c7e137946b5dd92
  • 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

encryptDecrypt.go

Blame
  • encryptDecrypt.go 1.49 KiB
    ////////////////////////////////////////////////////////////////////////////////
    // Copyright © 2022 xx foundation                                             //
    //                                                                            //
    // Use of this source code is governed by a license that can be found in the  //
    // LICENSE file.                                                              //
    ////////////////////////////////////////////////////////////////////////////////
    
    package auth
    
    import (
    	"gitlab.com/elixxir/crypto/cyclic"
    )
    
    // Encrypts the payload for use in authenticated channels and provides a MAC
    // on this encrypted payload
    func Encrypt(myPrivKey, partnerPubKey *cyclic.Int, payload []byte,
    	grp *cyclic.Group) (ecrPayload, mac []byte) {
    
    	// Generate the base key
    	authKey, vec := MakeAuthKey(myPrivKey, partnerPubKey, grp)
    
    	// Encrypt the payload
    	ecrPayload = Crypt(authKey, vec, payload)
    
    	// Generate the MAC
    	mac = MakeMac(authKey, ecrPayload)
    	return ecrPayload, mac
    }
    
    // Decrypts the payload for use in authenticated channels and provides a MAC
    // on this encrypted payload
    func Decrypt(myPrivKey, partnerPubKey *cyclic.Int, ecrPayload, MAC []byte,
    	grp *cyclic.Group) (success bool, payload []byte) {
    
    	// Generate the base key
    	authKey, vec := MakeAuthKey(myPrivKey, partnerPubKey, grp)
    
    	// Check if the mac if valid
    	if !VerifyMac(authKey, ecrPayload, MAC) {
    		return false, nil
    	}
    
    	// Decrypt the payload
    	payload = Crypt(authKey, vec, ecrPayload)
    
    	return true, payload
    }