@@ -145,7 +145,7 @@ ECDSA
145145 # Generate an EC keypair in this session from a named curve
146146 ecparams = session.create_domain_parameters(
147147 pkcs11.KeyType.EC, {
148- pkcs11.Attribute: pkcs11.util.ec.encode_named_curve_parameters('prime256v1'),
148+ pkcs11.Attribute.EC_PARAMS : pkcs11.util.ec.encode_named_curve_parameters('prime256v1'),
149149 }, local=True)
150150 pub, priv = ecparams.generate_keypair()
151151
@@ -164,9 +164,9 @@ Diffie-Hellman
164164
165165 with token.open() as session:
166166 # Given shared Diffie-Hellman parameters
167- parameters = session.create_domain_parameters(KeyType.DH, {
168- Attribute.PRIME: prime, # Diffie-Hellman parameters
169- Attribute.BASE: base,
167+ parameters = session.create_domain_parameters(pkcs11. KeyType.DH, {
168+ pkcs11. Attribute.PRIME: prime, # Diffie-Hellman parameters
169+ pkcs11. Attribute.BASE: base,
170170 })
171171
172172 # Generate a DH key pair from the public parameters
@@ -179,7 +179,7 @@ Diffie-Hellman
179179
180180 # Derive a shared session key with perfect forward secrecy
181181 session_key = private.derive_key(
182- KeyType.AES, 128,
182+ pkcs11. KeyType.AES, 128,
183183 mechanism_param=other_value)
184184
185185
@@ -196,22 +196,22 @@ Elliptic-Curve Diffie-Hellman
196196 with token.open() as session:
197197 # Given DER encocded EC parameters, e.g. from
198198 # openssl ecparam -outform der -name <named curve>
199- parameters = session.create_domain_parameters(KeyType.EC, {
200- Attribute.EC_PARAMS: ecparams,
199+ parameters = session.create_domain_parameters(pkcs11. KeyType.EC, {
200+ pkcs11. Attribute.EC_PARAMS: ecparams,
201201 })
202202
203203 # Generate a DH key pair from the public parameters
204204 public, private = parameters.generate_keypair()
205205
206206 # Share the public half of it with our other party.
207- _network_.write(public[Attribute.EC_POINT])
207+ _network_.write(public[pkcs11. Attribute.EC_POINT])
208208 # And get their shared value
209209 other_value = _network_.read()
210210
211211 # Derive a shared session key
212212 session_key = private.derive_key(
213- KeyType.AES, 128,
214- mechanism_param=(KDF.NULL, None, other_value))
213+ pkcs11. KeyType.AES, 128,
214+ mechanism_param=(pkcs11. KDF.NULL, None, other_value))
215215
216216Tested Compatibility
217217--------------------
0 commit comments