Skip to content

Commit

Permalink
atcab_verify_stored and atcab_verify_extern return boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
Damiano Mazzella authored and Damiano Mazzella committed Jan 17, 2019
1 parent 1db329d commit 91c6936
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
14 changes: 4 additions & 10 deletions cryptoauthlib/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,17 +638,14 @@ def atcab_verify_extern(self, message, signature, public_key):
nonce_target = ATCA_CONSTANTS.NONCE_MODE_TARGET_MSGDIGBUF
verify_source = ATCA_CONSTANTS.VERIFY_MODE_SOURCE_MSGDIGBUF

packets = []
packet = self.atcab_nonce_load(nonce_target, message)
packets.append(packet)
self.atcab_nonce_load(nonce_target, message)
packet = self.atcab_verify(
ATCA_CONSTANTS.VERIFY_MODE_EXTERNAL | verify_source,
ATCA_CONSTANTS.VERIFY_KEY_P256,
signature,
public_key
)
packets.append(packet)
return packets
return packet.response_data[1] == ATCA_STATUS.ATCA_SUCCESS

def atcab_verify_extern_mac(self, message, signature, public_key, num_in, io_key, is_verified):
raise NotImplementedError("atcab_verify_extern_mac")
Expand All @@ -669,16 +666,13 @@ def atcab_verify_stored(self, message, signature, key_id):
nonce_target = ATCA_CONSTANTS.NONCE_MODE_TARGET_MSGDIGBUF
verify_source = ATCA_CONSTANTS.VERIFY_MODE_SOURCE_MSGDIGBUF

packets = []
packet = self.atcab_nonce_load(nonce_target, message)
packets.append(packet)
self.atcab_nonce_load(nonce_target, message)
packet = self.atcab_verify(
ATCA_CONSTANTS.VERIFY_MODE_STORED | verify_source,
key_id,
signature
)
packets.append(packet)
return packets
return packet.response_data[1] == ATCA_STATUS.ATCA_SUCCESS

def atcab_verify_stored_mac(self, message, signature, key_id, num_in, io_key, is_verified):
raise NotImplementedError("atcab_verify_stored_mac")
Expand Down
13 changes: 8 additions & 5 deletions tests/ateccX08a/tests_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def run(device=None):
config = _TEST_CONFIG[device.device]

log.debug("test_config for %s : %s", device.device, hexlify(config))
ATEC_UTIL.dump_configuration(config)
# ATEC_UTIL.dump_configuration(config)

if not device.atcab_is_locked(ATCA_CONSTANTS.LOCK_ZONE_CONFIG):
device.atcab_write_config_zone(config)
Expand All @@ -87,11 +87,14 @@ def run(device=None):
message_digest = packet.response_data[1:-2]
signature = _TEST_KEYS["SIGNATURE"]["R"] + _TEST_KEYS["SIGNATURE"]["S"]
# # write public_key to slot
# device.atcab_write_pubkey(slot, public_key)
device.atcab_write_pubkey(slot, public_key)
# # verify wrote public_key
# assert public_key == device.atcab_read_pubkey(slot)
assert public_key == device.atcab_read_pubkey(slot)
# # verify the signature
packets = device.atcab_verify_extern(message_digest, signature, public_key)
log.info("atcab_verify_stored %s", list(map(str, packets)))
verified = device.atcab_verify_extern(message_digest, signature, public_key)
log.info("atcab_verify_extern %r", verified)

verified = device.atcab_verify_stored(message, signature, slot)
log.info("atcab_verify_stored %r", verified)
else:
log.info("slot %d locked", slot)

0 comments on commit 91c6936

Please sign in to comment.