Browse Source

add in support for doing the shared key...

irr_shared
John-Mark Gurney 3 years ago
parent
commit
0f83ec169d
4 changed files with 19 additions and 8 deletions
  1. +4
    -2
      comms.c
  2. +1
    -1
      comms.h
  3. +13
    -4
      lora.py
  4. +1
    -1
      lora_comms.py

+ 4
- 2
comms.c View File

@@ -13,7 +13,7 @@ _strobe_state_size()
}

void
comms_init(struct comms_state *cs, process_msgfunc_t pmf)
comms_init(struct comms_state *cs, process_msgfunc_t pmf, struct pktbuf *shared)
{

*cs = (struct comms_state){
@@ -23,9 +23,11 @@ comms_init(struct comms_state *cs, process_msgfunc_t pmf)

strobe_init(&cs->cs_start, domain, sizeof domain - 1);

if (shared != NULL)
strobe_key(&cs->cs_start, SYM_KEY, shared->pkt, shared->pktlen);

/* copy starting state over to initial state */
cs->cs_state = cs->cs_start;

}

#define CONFIRMED_STR_BASE "confirmed"


+ 1
- 1
comms.h View File

@@ -27,5 +27,5 @@ struct comms_state {

size_t _strobe_state_size();

void comms_init(struct comms_state *, process_msgfunc_t);
void comms_init(struct comms_state *, process_msgfunc_t, struct pktbuf *);
void comms_process(struct comms_state *, struct pktbuf, struct pktbuf *);

+ 13
- 4
lora.py View File

@@ -22,9 +22,11 @@ CMD_RUNFOR = 3 # arg: (chan, length): turns on chan for length seconds
class LORANode(object):
'''Implement a LORANode initiator.'''

def __init__(self, syncdatagram):
def __init__(self, syncdatagram, shared=None):
self.sd = syncdatagram
self.st = Strobe(domain, F=KeccakF(800))
if shared is not None:
self.st.key(shared)

async def start(self):
msg = self.st.send_enc(os.urandom(16) + b'reqreset') + \
@@ -177,10 +179,14 @@ def timeout(timeout):
class TestLORANode(unittest.IsolatedAsyncioTestCase):
@timeout(2)
async def test_lora(self):
shared_key = os.urandom(32)

class TestSD(MockSyncDatagram):
async def runner(self):
l = Strobe(domain, F=KeccakF(800))

l.key(shared_key)

# start handshake
r = await self.get()

@@ -234,7 +240,7 @@ class TestLORANode(unittest.IsolatedAsyncioTestCase):
l.send_mac(8))

tsd = TestSD()
l = LORANode(tsd)
l = LORANode(tsd, shared=shared_key)

await l.start()

@@ -308,12 +314,15 @@ class TestLORANode(unittest.IsolatedAsyncioTestCase):
# pass the reply back
await self.put(outbytes[:outbuf.pktlen])

# Generate shared key
shared_key = os.urandom(32)

# Initialize everything
lora_comms.comms_init(commstate, cb)
lora_comms.comms_init(commstate, cb, make_pktbuf(shared_key))

# Create test fixture
tsd = CCodeSD()
l = LORANode(tsd)
l = LORANode(tsd, shared=shared_key)

# Send various messages
await l.start()


+ 1
- 1
lora_comms.py View File

@@ -49,7 +49,7 @@ class CommsState(Structure):
]

for func, ret, args in [
('comms_init', None, (POINTER(CommsState), process_msgfunc_t)),
('comms_init', None, (POINTER(CommsState), process_msgfunc_t, POINTER(PktBuf))),
('comms_process', None, (POINTER(CommsState), PktBuf, POINTER(PktBuf))),
('strobe_seed_prng', None, (POINTER(c_uint8), c_ssize_t)),
]:


Loading…
Cancel
Save