Skip to content

Commit

Permalink
Merge pull request #70 from wolfendale/performance-tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbarrow authored Jul 7, 2024
2 parents d633dca + feee2dd commit a035545
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
10 changes: 6 additions & 4 deletions kerberos.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,15 @@ func NewKerberosTicketInternalData(server *PRUDPServer) *KerberosTicketInternalD

// DeriveKerberosKey derives a users kerberos encryption key based on their PID and password
func DeriveKerberosKey(pid *types.PID, password []byte) []byte {
iterationCount := 65000 + pid.Value()%1024
iterationCount := int(65000 + pid.Value()%1024)
key := make([]byte, md5.Size)
copy(key, password)

var i uint64 = 0
for ; i < iterationCount; i++ {
hash := md5.Sum(key)
hash := md5.Sum(password)
copy(key, hash[:])

for i := 1; i < iterationCount; i++ {
hash = md5.Sum(key)
copy(key, hash[:])
}

Expand Down
16 changes: 16 additions & 0 deletions kerberos_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package nex

import (
"encoding/hex"
"testing"

"github.com/PretendoNetwork/nex-go/v2/types"
"github.com/stretchr/testify/assert"
)

func TestDeriveGuestKey(t *testing.T) {
pid := types.NewPID(100)
password := []byte("MMQea3n!fsik")
result := DeriveKerberosKey(pid, password)
assert.Equal(t, "9ef318f0a170fb46aab595bf9644f9e1", hex.EncodeToString(result))
}
3 changes: 2 additions & 1 deletion prudp_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ func (ps *PRUDPServer) listenDatagram(quit chan struct{}) {

read, addr, err = ps.udpSocket.ReadFromUDP(buffer)
if err == nil {
packetData := buffer[:read]
packetData := make([]byte, read)
copy(packetData, buffer[:read])

err = ps.handleSocketMessage(packetData, addr, nil)
}
Expand Down

0 comments on commit a035545

Please sign in to comment.