LudovicRousseau / pyscard

pyscard smartcard library for python
http://pyscard.sourceforge.net/
GNU Lesser General Public License v2.1
400 stars 113 forks source link

ATR clock rates and bit rates #214

Closed kurtmckee closed 1 week ago

kurtmckee commented 1 week ago

I'm beginning to review the ATR code to test it, and it looks like some of the constants are sourced from ISO 7816-3. However, I'm not sure if I'm reading this right and want to confirm.

I think I'm looking at the 2006 edition of 7816-3, which may affect correctness.

Clock rate conversion integers

Screenshot of clock conversion rate integers, from section 8.3:

image

Current Python code, formatted into groups of 8:

clockrateconversion = [
    372,   372, 558, 744,  1116, 1488, 1860,  "RFU",
    "RFU", 512, 768, 1024, 1536, 2048, "RFU", "RFU",

    "RFU",  # <-- This looks like it's not part of the spec
]

Analysis: It looks like there's an extra "RFU" trailing at the end of the Python code, and that it could be removed.

Baud rate adjustment integers

Screenshot of baud rate adjustment integers, from section 8.3:

image

Current Python code, formatted into groups of 8:

bitratefactor = [
    "RFU", 1,  2,     4,     8,     16,    32,    "RFU",
#                                                 ^^^^^ looks like this should be 64
    12,    20, "RFU", "RFU", "RFU", "RFU", "RFU", "RFU",
]

Analysis: It looks like one of the "RFU" values should be 64.


I'm working to understand what ATRs represent, and wanted to confirm that I'm reading the correct specification (ISO 7816-3 2006) in the correct section (8.3) and comparing that with the correct code (ATR.py).

Thanks for any insight you can offer!

LudovicRousseau commented 1 week ago

You are right. The tables have been updated in a later ISO 7816-3 document. The Python code should be updated.

See https://blog.apdu.fr/posts/2016/04/atr-statistics-ta1-global-encodes-fi/