Skip to content

Commit d2b89d7

Browse files
committed
- fixed public key registration on osnma
1 parent ff845cf commit d2b89d7

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

src/cssrlib/osnma.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def pubkey_decompress(self, pkt, pnt):
215215

216216
if curve is None:
217217
return False
218-
pk = ec.EllipticCurvePublicKey.from_encoded_point(curve, pnt)
218+
pk = ec.EllipticCurvePublicKey.from_encoded_point(curve, bytes(pnt))
219219
return pk
220220

221221
def load_mt(self, file):
@@ -339,9 +339,9 @@ def verify_pdk(self, p_dk, did):
339339
l_pdk = len(p_dk)
340340
return h[0:l_pdk] == p_dk
341341

342-
def verify_pdp(self, m0, p_dp):
342+
def verify_pdp(self, mi, p_dp):
343343
""" verify P_DP """
344-
msg = self.root_mt + m0
344+
msg = self.root_mt + mi
345345
h = self.process_hash(msg)
346346
l_pdp = len(p_dp)
347347
return h[0:l_pdp] == p_dp
@@ -432,29 +432,29 @@ def decode_dsm_pkr(self, did):
432432
l_npk = self.npk_len_t[npkt]
433433
i0 = 130+l_npk//8
434434
npk = self.dsm[did][130:i0]
435-
l_pdp = l_dp - 1040 - l_npk
435+
l_pdp = l_dp - 1040 - l_npk # Eq.3
436436
if l_pdp < 0:
437437
return False
438438
p_dp = self.dsm[did][i0:i0+l_pdp//8]
439439

440-
m0 = bytearray([self.dsm[did][129]])+npk # NPKT||NPKID||NPK
440+
mi = bytearray([self.dsm[did][129]])+npk # mi=(NPKT||NPKID||NPK) Eq.11
441441

442-
# A7.3 Verification of the PDP
443-
if not self.verify_pdp(m0, p_dp):
442+
# 3.2.2.7 Verification of the PDP with Eq.4
443+
if not self.verify_pdp(mi, p_dp):
444444
return False
445445

446-
# A7.2 DSM-PKR Verification
447-
h = self.process_hash(m0)
446+
# 6.2 DSM-PKR Verification
447+
x = self.process_hash(mi) # Eq.12
448448
for k in range(4):
449449
itn_b = itn[k*32:(k+1)*32]
450450
if mid % 2 == 0:
451-
msg = h+itn_b
451+
msg = x+itn_b
452452
else:
453-
msg = itn_b+h
454-
h = self.process_hash(msg)
453+
msg = itn_b+x
454+
x = self.process_hash(msg) # Eq.13
455455
mid >>= 1
456456

457-
result = (h == self.root_mt)
457+
result = (x == self.root_mt)
458458
if not result:
459459
return False
460460

@@ -468,11 +468,22 @@ def decode_dsm_pkr(self, did):
468468
def decode_hk(self, hk, prn):
469469
""" decode HKROOT message """
470470
self.nma_header = hk[0]
471+
472+
# NMA Status (nmas): 1: Test, 2: Operational, 3: Don'use
473+
# Chain ID (cid)
474+
# Chain and Public Key Status (CPKS):
475+
# 1: Nominal
476+
# 2: End of Chain (EOC)
477+
# 3: Chain Revoked (CREV)
478+
# 4: New Public Key (NPK)
479+
# 5: Public Key Revoked (PKREV)
480+
# 6: New Markle Tree (NMT)
481+
# 7: Alert Message (AM)
471482
nmas, cid, cpks, _ = bs.unpack_from('u2u2u3u1', hk, 0)
472483
did, bid = bs.unpack_from('u4u4', hk, 8)
473484
if nmas != 1 and nmas != 2:
474485
return False
475-
if cpks != 1: # nominal only
486+
if cpks == 0: # skip reserved
476487
return False
477488

478489
if did not in self.flg_dsm.keys():
@@ -495,10 +506,14 @@ def decode_hk(self, hk, prn):
495506
self.nb[did] = nb_ + 6 # number of blocks
496507

497508
result = False
509+
510+
# if did > 11 and bid == 6: # (debug) missing bid=6 of DSM-PKR
511+
# self.fh.write(f"### DSM[{did}] bid={bid}\n")
512+
498513
if self.monlevel > 1:
499514
print(f"flg_dsm[did={did}]={self.flg_dsm[did]:2x} "
500515
f"nb={self.nb[did]:2d} bid={bid} prn={prn}")
501-
if did in self.nb.keys() and \
516+
if did in self.nb.keys() and self.nb[did] > 0 and \
502517
self.flg_dsm[did] == (1 << self.nb[did])-1:
503518
if did <= 11: # DSM-KROOT
504519
result = self.decode_dsm_kroot(did)

0 commit comments

Comments
 (0)