FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cryptoauthlib/python/tests/test_device.py at main · op/cryptoauthlib · GitHub
op
/
cryptoauthlib
Public
forked from
MicrochipTech/cryptoauthlib
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cryptoauthlib
/
python
/
tests
/
test_device.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
149 lines (139 loc) · 6.25 KB
Breadcrumbs
cryptoauthlib
/
python
/
tests
/
test_device.py
Copy path
File metadata and controls
149 lines (139 loc) · 6.25 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"""
Device.py tests. Covers the configuration structures
"""
import
pytest
import
ctypes
from
cryptoauthlib
.
device
import
*
from
cryptoauthlib
.
library
import
load_cryptoauthlib
,
get_size_by_name
,
ctypes_to_bytes
# ATSHA204A Test Data
ATSHA204A_SER_NUM_VECTOR
=
bytearray
.
fromhex
(
'01 23 6E AA CE FE 0B 8D EE'
)
ATSHA204A_DEVICE_CONFIG_VECTOR
=
bytearray
.
fromhex
(
'01 23 6E AA 00 09 04 00 CE FE 0B 8D EE 00 01 00'
'C8 00 55 00 8F 80 80 A1 82 E0 C4 F4 84 00 A0 85'
'86 40 87 07 0F 00 C4 64 8A 7A 0B 8B 0C 4C DD 4D'
'C2 42 AF 8F FF 00 FF 00 FF 00 FF 00 FF 00 FF 00'
'FF 00 FF 00 FF FF FF FF FF FF FF FF FF FF FF FF'
'FF FF FF FF 00 00 55 55'
)
ATSHA204A_DEVICE_CONFIG
=
{
'SN03'
: [
0x01
,
0x23
,
0x6E
,
0xAA
],
'RevNum'
: [
0x00
,
0x09
,
0x04
,
0x00
],
'SN48'
: [
0xCE
,
0xFE
,
0x0B
,
0x8D
,
0xEE
],
'I2C_Enable'
:
0x01
,
'I2C_Address'
:
0xC8
,
'OTPmode'
:
0x55
,
'SlotConfig'
: [
0x808F
,
0xA180
,
0xE082
,
0xF4C4
,
0x0084
,
0x85A0
,
0x4086
,
0x0787
,
0x000F
,
0x64C4
,
0x7A8A
,
0x8B0B
,
0x4C0C
,
0x4DDD
,
0x42C2
,
0x8FAF
],
'Counter'
: [
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
],
'LastKeyUse'
: [
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
],
'LockValue'
:
0x55
,
'LockConfig'
:
0x55
}
# ATECC508A Test Data
ATECC508A_SER_NUM_VECTOR
=
bytearray
.
fromhex
(
'01 23 72 E8 B9 63 B2 D3 EE'
)
ATECC508A_DEVICE_CONFIG_VECTOR
=
bytearray
.
fromhex
(
'01 23 72 E8 00 00 60 02 B9 63 B2 D3 EE 00 2D 00'
'B0 00 55 00 8F 20 C4 44 87 20 87 20 8F 0F C4 36'
'9F 0F 82 20 0F 0F C4 44 0F 0F 0F 0F 0F 0F 0F 0F'
'0F 0F 0F 0F FF FF FF FF 00 00 00 00 FF FF FF FF'
'00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF'
'FF FF FF FF 00 00 55 55 FF FF 00 00 00 00 00 00'
'33 00 1C 00 13 00 13 00 7C 00 1C 00 3C 00 33 00'
'3C 00 3C 00 3C 00 30 00 3C 00 3C 00 3C 00 30 00'
)
ATECC508A_DEVICE_CONFIG
=
{
'SN03'
: [
0x01
,
0x23
,
0x72
,
0xE8
],
'RevNum'
: [
0x00
,
0x00
,
0x60
,
0x02
],
'SN48'
: [
0xB9
,
0x63
,
0xB2
,
0xD3
,
0xEE
],
'I2C_Enable'
:
0x2D
,
'I2C_Address'
:
0xB0
,
'OTPmode'
:
0x55
,
'SlotConfig'
: [
0x208F
,
0x44C4
,
0x2087
,
0x2087
,
0x0F8F
,
0x36C4
,
0x0F9F
,
0x2082
,
0x0F0F
,
0x44C4
,
0x0F0F
,
0x0F0F
,
0x0F0F
,
0x0F0F
,
0x0F0F
,
0x0F0F
],
'Counter0'
: [
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0x00
,
0x00
,
0x00
,
0x00
],
'Counter1'
: [
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0x00
,
0x00
,
0x00
,
0x00
],
'LastKeyUse'
: [
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
],
'LockValue'
:
0x55
,
'LockConfig'
:
0x55
,
'SlotLocked'
:
0xFFFF
,
'KeyConfig'
: [
0x0033
,
0x001C
,
0x0013
,
0x0013
,
0x007C
,
0x001C
,
0x003C
,
0x0033
,
0x003C
,
0x003C
,
0x003C
,
0x0030
,
0x003C
,
0x003C
,
0x003C
,
0x0030
]
}
# ATECC608 Test Data
ATECC608_SER_NUM_VECTOR
=
bytearray
.
fromhex
(
'01 23 72 E8 B9 63 B2 D3 EE'
)
ATECC608_DEVICE_CONFIG_VECTOR
=
bytearray
.
fromhex
(
'01 23 72 E8 00 00 60 02 B9 63 B2 D3 EE 01 2D 00'
'B0 00 55 01 8F 20 C4 44 87 20 87 20 8F 0F C4 36'
'9F 0F 82 20 0F 0F C4 44 0F 0F 0F 0F 0F 0F 0F 0F'
'0F 0F 0F 0F FF FF FF FF 00 00 00 00 FF FF FF FF'
'00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00'
'00 00 00 00 00 00 00 00 FF FF 06 40 00 00 00 00'
'33 00 1C 00 13 00 13 00 7C 00 1C 00 3C 00 33 00'
'3C 00 3C 00 3C 00 30 00 3C 00 3C 00 3C 00 30 00'
)
ATECC608_DEVICE_CONFIG
=
{
'SN03'
: [
0x01
,
0x23
,
0x72
,
0xE8
],
'RevNum'
: [
0x00
,
0x00
,
0x60
,
0x02
],
'SN48'
: [
0xB9
,
0x63
,
0xB2
,
0xD3
,
0xEE
],
'AES_Enable'
: {
'Enable'
:
1
},
'I2C_Enable'
:
0x2D
,
'I2C_Address'
:
0xB0
,
'ChipMode'
:
1
,
'CountMatch'
:
0x55
,
'SlotConfig'
: [
0x208F
,
0x44C4
,
0x2087
,
0x2087
,
0x0F8F
,
0x36C4
,
0x0F9F
,
0x2082
,
0x0F0F
,
0x44C4
,
0x0F0F
,
0x0F0F
,
0x0F0F
,
0x0F0F
,
0x0F0F
,
0x0F0F
],
'Counter0'
: [
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0x00
,
0x00
,
0x00
,
0x00
],
'Counter1'
: [
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0x00
,
0x00
,
0x00
,
0x00
],
'SlotLocked'
:
0xFFFF
,
'ChipOptions'
: {
'IoProtectionKeyEnable'
:
1
,
'KdfAesEnable'
:
1
,
'IoProtectionKey'
:
4
},
'KeyConfig'
: [
0x0033
,
0x001C
,
0x0013
,
0x0013
,
0x007C
,
0x001C
,
0x003C
,
0x0033
,
0x003C
,
0x003C
,
0x003C
,
0x0030
,
0x003C
,
0x003C
,
0x003C
,
0x0030
]
}
@
pytest
.
mark
.
parametrize
(
"config,size"
, [
pytest
.
param
(
Atsha204aConfig
,
len
(
ATSHA204A_DEVICE_CONFIG_VECTOR
),
id
=
'ATSHA204A'
),
pytest
.
param
(
Atecc508aConfig
,
len
(
ATECC508A_DEVICE_CONFIG_VECTOR
),
id
=
'ATECC508A'
),
pytest
.
param
(
Atecc608Config
,
len
(
ATECC608_DEVICE_CONFIG_VECTOR
),
id
=
'ATECC608'
)
])
def
test_device_config_size
(
config
,
size
):
assert
ctypes
.
sizeof
(
config
)
==
size
@
pytest
.
mark
.
parametrize
(
"config,definition,vector"
, [
pytest
.
param
(
Atsha204aConfig
,
ATSHA204A_DEVICE_CONFIG
,
ATSHA204A_DEVICE_CONFIG_VECTOR
,
id
=
'ATSHA204A'
),
pytest
.
param
(
Atecc508aConfig
,
ATECC508A_DEVICE_CONFIG
,
ATECC508A_DEVICE_CONFIG_VECTOR
,
id
=
'ATECC508A'
),
pytest
.
param
(
Atecc608Config
,
ATECC608_DEVICE_CONFIG
,
ATECC608_DEVICE_CONFIG_VECTOR
,
id
=
'ATECC608'
)
])
def
test_device_config_from_def
(
config
,
definition
,
vector
):
assert
ctypes_to_bytes
(
config
(
**
definition
))
==
bytes
(
vector
)
@
pytest
.
mark
.
parametrize
(
"config,vector"
, [
pytest
.
param
(
Atsha204aConfig
,
ATSHA204A_DEVICE_CONFIG_VECTOR
,
id
=
'ATSHA204A'
),
pytest
.
param
(
Atecc508aConfig
,
ATECC508A_DEVICE_CONFIG_VECTOR
,
id
=
'ATECC508A'
),
pytest
.
param
(
Atecc608Config
,
ATECC608_DEVICE_CONFIG_VECTOR
,
id
=
'ATECC608'
)
])
def
test_device_config_from_vector
(
config
,
vector
):
assert
ctypes_to_bytes
(
config
.
from_buffer
(
vector
))
==
bytes
(
vector
)
@
pytest
.
mark
.
parametrize
(
"config,definition,vector"
, [
pytest
.
param
(
Atsha204aConfig
,
ATSHA204A_DEVICE_CONFIG
,
ATSHA204A_SER_NUM_VECTOR
,
id
=
'ATSHA204A'
),
pytest
.
param
(
Atecc508aConfig
,
ATECC508A_DEVICE_CONFIG
,
ATECC508A_SER_NUM_VECTOR
,
id
=
'ATECC508A'
),
pytest
.
param
(
Atecc608Config
,
ATECC608_DEVICE_CONFIG
,
ATECC608_SER_NUM_VECTOR
,
id
=
'ATECC608'
)
])
def
test_device_serial_number_from_def
(
config
,
definition
,
vector
):
config
=
config
(
**
definition
)
sernum
=
ctypes_to_bytes
(
config
.
SN03
)
+
ctypes_to_bytes
(
config
.
SN48
)
assert
sernum
==
bytes
(
vector
)
Back
|
FazBrowse Home
|
New Git URL