MCPcopy Create free account
hub / github.com/encodeous/nylon / RoutineEncryption

Method RoutineEncryption

polyamide/device/send.go:403–439  ·  view source on GitHub ↗

* Encrypts the elements in the queue * and marks them for sequential consumption (by releasing the mutex) * * Obs. One instance per core */

(id int)

Source from the content-addressed store, hash-verified

401 * Obs. One instance per core
402 */
403func (device *Device) RoutineEncryption(id int) {
404 var paddingZeros [PaddingMultiple]byte
405 var nonce [chacha20poly1305.NonceSize]byte
406
407 defer device.Log.Verbosef("Routine: encryption worker %d - stopped", id)
408 device.Log.Verbosef("Routine: encryption worker %d - started", id)
409
410 for elemsContainer := range device.queue.encryption.c {
411 for _, elem := range elemsContainer.elems {
412 // populate header fields
413 header := elem.buffer[:MessageTransportHeaderSize]
414
415 fieldType := header[0:4]
416 fieldReceiver := header[4:8]
417 fieldNonce := header[8:16]
418
419 binary.LittleEndian.PutUint32(fieldType, MessageTransportType)
420 binary.LittleEndian.PutUint32(fieldReceiver, elem.keypair.remoteIndex)
421 binary.LittleEndian.PutUint64(fieldNonce, elem.nonce)
422
423 // pad content to multiple of 16
424 paddingSize := calculatePaddingSize(len(elem.packet), int(device.tun.mtu.Load()))
425 elem.packet = append(elem.packet, paddingZeros[:paddingSize]...)
426
427 // encrypt content and release to consumer
428
429 binary.LittleEndian.PutUint64(nonce[4:], elem.nonce)
430 elem.packet = elem.keypair.send.Seal(
431 header,
432 nonce[:],
433 elem.packet,
434 nil,
435 )
436 }
437 elemsContainer.Unlock()
438 }
439}
440
441/*
442This function arranges buffers and endpoints by endpoint, into contiguous

Callers 1

NewDeviceFunction · 0.80

Implementers 4

NativeTunpolyamide/tun/tun_linux.go
netTunpolyamide/tun/netstack/tun.go
chTunpolyamide/tun/tuntest/tuntest.go
fakeTUNDeviceSizedpolyamide/device/device_test.go

Calls 1

calculatePaddingSizeFunction · 0.85

Tested by

no test coverage detected