Skip to content
Snippets Groups Projects
kms.go 1.75 KiB
Newer Older
  • Learn to ignore specific revisions
  • // This package kms implements a simplistic key managment system (kms) for
    // Quantum Key Distribution Networks (QKDN) which is a simple emulated KMS. x
    // It relies on the emulated quantum link out of the quantumlayer package
    
    package kms
    
    import (
    	"code.fbi.h-da.de/m.stiemerling/proto-kms/quantumlayer"
    	"github.com/google/uuid"
    )
    
    type Qkdnkms interface {
    	AddQuantumElement() *QuantumElement
    }
    
    type qlElementId uuid.UUID
    type qlElementLinkID int
    
    // The general emulated KMS
    type eKMS struct {
    	QuantumElements map[qlElementId]*QuantumElement
    	KeyStorages     map[qlElementId]map[qlElementLinkID]uint64
    }
    
    // Will keep information about the quantum elements that this eKMS is talking to
    type QuantumElement struct {
    	qlElementName       string                                         // the name of this Quantum Element
    	qlElementUUID       uuid.UUID                                      // the uuid for this device
    	QlElement           *quantumlayer.QuantumlayerEmuPRNG              // the actual quantum element
    	QuantumElementLinks map[qlElementLinkID]*quantumlayer.QuantumLayer // contains information about the quantum links
    }
    
    func NeweKMS() (newekms *eKMS) {
    
    	return &eKMS{
    		QuantumElements: make(map[qlElementId]*QuantumElement),
    		KeyStorages:     make(map[qlElementId]map[qlElementLinkID]uint64),
    	}
    }
    
    func (kms *eKMS) AddQuantumElement(kmsName string, kmsUUID uuid.UUID, kmsUDPAddrr string) *QuantumElement {
    
    	//Get an emulated Quantumlayer
    	ql := quantumlayer.NewQuantumlayerEmuPRNG()
    	ql.PowerOn(kmsUDPAddrr)
    
    	qle := QuantumElement{
    		qlElementName:       kmsName,
    		qlElementUUID:       kmsUUID,
    		QlElement:           ql,
    		QuantumElementLinks: make(map[qlElementLinkID]*quantumlayer.QuantumLayer),
    	}
    
    	kms.QuantumElements[qlElementId(kmsUUID)] = &qle
    
    	return &qle
    }