pyecsca.sca.target.ectester module¶
Provides an ECTester target class.
- class KeypairEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
ShiftableFlag
ECTester’s KeyPair type.
- class InstructionEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
IntEnum
ECTester’s instruction (INS).
- class KeyBuildEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
IntEnum
ECTester’s key builder type.
- class ExportEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
IntEnum
ECTester’s export boolean.
- class RunModeEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
IntEnum
ECTester’s run mode.
- class KeyEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
ShiftableFlag
ECTester’s key enum.
- class AppletBaseEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
IntEnum
ECTester’s JavaCard applet base version.
- class KeyClassEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
IntEnum
JavaCard EC-based key class.
- class KeyAgreementEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
IntEnum
JavaCard KeyAgreement type values.
- class SignatureEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
IntEnum
JavaCard Signature type values.
- class TransformationEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
ShiftableFlag
ECTester’s point/value transformation types.
- class FormatEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
IntEnum
ECTester’s point format types.
- class CurveEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
IntEnum
ECTester’s curve constants.
- class ParameterEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
ShiftableFlag
ECTester’s parameter ids.
- exception ChunkingException[source]¶
Bases:
Exception
An exception that is raised if an error happened during the chunking process of a large APDU.
- class AllocateKaResponse(resp)[source]¶
Bases:
Response
A response to the KeyAgreement allocation command.
-
resp:
ResponseAPDU
[source]¶
-
resp:
- class AllocateSigResponse(resp)[source]¶
Bases:
Response
A response to the Signature allocation command.
-
resp:
ResponseAPDU
[source]¶
-
resp:
- class AllocateResponse(resp, keypair)[source]¶
Bases:
Response
A response to the KeyPair allocation command.
-
resp:
ResponseAPDU
[source]¶
-
resp:
- class ClearResponse(resp, keypair)[source]¶
Bases:
Response
A response to the Clear key command.
-
resp:
ResponseAPDU
[source]¶
-
resp:
- class SetResponse(resp, keypair)[source]¶
Bases:
Response
A response to the Set command.
-
resp:
ResponseAPDU
[source]¶
-
resp:
- class TransformResponse(resp, keypair)[source]¶
Bases:
Response
A response to the Transform command.
-
resp:
ResponseAPDU
[source]¶
-
resp:
- class GenerateResponse(resp, keypair)[source]¶
Bases:
Response
A response to the Generate command.
-
resp:
ResponseAPDU
[source]¶
-
resp:
- class ExportResponse(resp, keypair, key, params)[source]¶
Bases:
Response
A response to the Export command, contains the exported parameters/values.
-
keypair:
KeypairEnum
[source]¶
-
parameters:
ParameterEnum
[source]¶
-
resp:
ResponseAPDU
[source]¶
-
keypair:
- class ECDHResponse(resp, export)[source]¶
Bases:
Response
A response to the ECDH and ECDH_direct KeyAgreement commands.
-
resp:
ResponseAPDU
[source]¶
-
resp:
- class ECDSAResponse(resp, export)[source]¶
Bases:
Response
A response to the ECDSA and ECDSA sign and ECDSA verify commands.
-
resp:
ResponseAPDU
[source]¶
-
resp:
- class CleanupResponse(resp)[source]¶
Bases:
Response
A response to the Cleanup command.
-
resp:
ResponseAPDU
[source]¶
-
resp:
- class RunModeResponse(resp)[source]¶
Bases:
Response
A response to the Set run mode command.
-
resp:
ResponseAPDU
[source]¶
-
resp:
- class ECTesterTarget[source]¶
Bases:
ISO7816Target
,ABC
Smartcard target which communicates with the ECTester sapplet on smartcards of the JavaCard platform using PCSC.
- connect(protocol=None)[source]¶
Connect to the card.
- Parameters:
protocol¶ (
Optional
[CardProtocol
]) – CardProtocol to use.
- abstract select(aid)[source]¶
Select an applet with
aid
.- Parameters:
aid¶ (
bytes
) – The AID of the applet to select.- Return type:
bool
- Returns:
Whether the selection was successful.
- abstract send_apdu(apdu)[source]¶
Send an APDU to the selected applet.
- Parameters:
apdu¶ (
CommandAPDU
) – The APDU to send.- Return type:
- Returns:
The response.
- select_applet(latest_version=b'033', count_back=10)[source]¶
Select the ECTester applet, with a specified version or older.
- static encode_parameters(params, obj)[source]¶
Encode values from obj into the byte parameters that the ECTester applet expects.
- Return type:
Mapping
[ParameterEnum
,bytes
]
- allocate_ka(ka_type)[source]¶
Send the Allocate KeyAgreement command.
- Parameters:
ka_type¶ (
KeyAgreementEnum
) – Which KeyAgreement type to allocate.- Return type:
- Returns:
The response.
- allocate_sig(sig_type)[source]¶
Send the Allocate Signature command.
- Parameters:
sig_type¶ (
SignatureEnum
) – Which Signature type to allocate.- Return type:
- Returns:
The response.
- allocate(keypair, builder, key_length, key_class)[source]¶
Send the Allocate KeyPair command.
- Parameters:
keypair¶ (
KeypairEnum
) – Which keypair to allocate.builder¶ (
KeyBuildEnum
) – Which builder to use to allocate the keypair.key_length¶ (
int
) – Bit-size of the allocated keypair.key_class¶ (
KeyClassEnum
) – Type of the allocated keypair.
- Return type:
- Returns:
The response.
- clear(keypair)[source]¶
Send the Clear key command.
- Parameters:
keypair¶ (
KeypairEnum
) – Which keypair to clear.- Return type:
- Returns:
The response.
- set(keypair, curve, params, values=None)[source]¶
Send the Set command.
- Parameters:
keypair¶ (
KeypairEnum
) – Which keypair to set values on.curve¶ (
CurveEnum
) – Which pre-set curve to use to set values, or default or external.params¶ (
ParameterEnum
) – Which parameters to set on the keypair.values¶ (
Optional
[Mapping
[ParameterEnum
,bytes
]]) – External values to set on the keypair.
- Return type:
- Returns:
The response.
- transform(keypair, key, params, transformation)[source]¶
Send the Transform command.
- Parameters:
keypair¶ (
KeypairEnum
) – Which keypair to transform.params¶ (
ParameterEnum
) – Which parameters to transform.transformation¶ (
TransformationEnum
) – What transformation to apply.
- Return type:
- Returns:
The response.
- generate(keypair)[source]¶
Send the Generate command.
- Parameters:
keypair¶ (
KeypairEnum
) – Which keypair to generate.- Return type:
- Returns:
The response.
- export(keypair, key, params)[source]¶
Send the Export command.
- Parameters:
keypair¶ (
KeypairEnum
) – Which keypair to export from.params¶ (
ParameterEnum
) – Which parameters to export.
- Return type:
- Returns:
The response, containing the exported parameters.
- ecdh(pubkey, privkey, export, transformation, ka_type)[source]¶
Send the ECDH command.
- Parameters:
pubkey¶ (
KeypairEnum
) – Which keypair to use the pubkey from, in the key-agreement.privkey¶ (
KeypairEnum
) – Which keypair to use the privkey from, in the key-agreement.export¶ (
bool
) – Whether to export the shared secret.transformation¶ (
TransformationEnum
) – The transformation to apply to the pubkey before key-agreement.ka_type¶ (
KeyAgreementEnum
) – The key-agreement type to use.
- Return type:
- Returns:
The response.
- ecdh_direct(privkey, export, transformation, ka_type, pubkey)[source]¶
Send the ECDH direct command.
- Parameters:
privkey¶ (
KeypairEnum
) – Which keypair to use the privkey from, in the key-agreement.export¶ (
bool
) – Whether to export the shared secret.transformation¶ (
TransformationEnum
) – The transformation to apply to the pubkey before key-agreement.ka_type¶ (
KeyAgreementEnum
) – The key-agreement type to use.pubkey¶ (
bytes
) – The raw bytes that will be used as a pubkey in the key-agreement.
- Return type:
- Returns:
The response.
- ecdsa(keypair, export, sig_type, data)[source]¶
Send the ECDSA command.
- Parameters:
keypair¶ (
KeypairEnum
) – The keypair to use.export¶ (
bool
) – Whether to export the signature.sig_type¶ (
SignatureEnum
) – The Signature type to use.data¶ (
bytes
) – The data to sign and verify.
- Return type:
- Returns:
The response.
- ecdsa_sign(keypair, export, sig_type, data)[source]¶
Send the ECDSA sign command.
- Parameters:
keypair¶ (
KeypairEnum
) – The keypair to use to sign.export¶ (
bool
) – Whether to export the signature.sig_type¶ (
SignatureEnum
) – The Signature type to use.data¶ (
bytes
) – The data to sign.
- Return type:
- Returns:
The response.
- ecdsa_verify(keypair, sig_type, sig, data)[source]¶
Send the ECDSA verify command.
- Parameters:
keypair¶ (
KeypairEnum
) – The keypair to use to verify.sig_type¶ (
SignatureEnum
) – The Signature type to use.sig¶ (
bytes
) – The signature to verify.data¶ (
bytes
) – The data.
- Return type:
- Returns:
The response.
- class ECTesterTargetPCSC(reader)[source]¶
Bases:
ECTesterTarget
,PCSCTarget
An ECTester-applet-based target that is connected via a PCSC-compatible reader.
- allocate(keypair, builder, key_length, key_class)[source]¶
Send the Allocate KeyPair command.
- Parameters:
keypair¶ (
KeypairEnum
) – Which keypair to allocate.builder¶ (
KeyBuildEnum
) – Which builder to use to allocate the keypair.key_length¶ (
int
) – Bit-size of the allocated keypair.key_class¶ (
KeyClassEnum
) – Type of the allocated keypair.
- Return type:
- Returns:
The response.
- allocate_ka(ka_type)[source]¶
Send the Allocate KeyAgreement command.
- Parameters:
ka_type¶ (
KeyAgreementEnum
) – Which KeyAgreement type to allocate.- Return type:
- Returns:
The response.
- allocate_sig(sig_type)[source]¶
Send the Allocate Signature command.
- Parameters:
sig_type¶ (
SignatureEnum
) – Which Signature type to allocate.- Return type:
- Returns:
The response.
- clear(keypair)[source]¶
Send the Clear key command.
- Parameters:
keypair¶ (
KeypairEnum
) – Which keypair to clear.- Return type:
- Returns:
The response.
- connect(protocol=None)[source]¶
Connect to the card.
- Parameters:
protocol¶ (
Optional
[CardProtocol
]) – CardProtocol to use.
- ecdh(pubkey, privkey, export, transformation, ka_type)[source]¶
Send the ECDH command.
- Parameters:
pubkey¶ (
KeypairEnum
) – Which keypair to use the pubkey from, in the key-agreement.privkey¶ (
KeypairEnum
) – Which keypair to use the privkey from, in the key-agreement.export¶ (
bool
) – Whether to export the shared secret.transformation¶ (
TransformationEnum
) – The transformation to apply to the pubkey before key-agreement.ka_type¶ (
KeyAgreementEnum
) – The key-agreement type to use.
- Return type:
- Returns:
The response.
- ecdh_direct(privkey, export, transformation, ka_type, pubkey)[source]¶
Send the ECDH direct command.
- Parameters:
privkey¶ (
KeypairEnum
) – Which keypair to use the privkey from, in the key-agreement.export¶ (
bool
) – Whether to export the shared secret.transformation¶ (
TransformationEnum
) – The transformation to apply to the pubkey before key-agreement.ka_type¶ (
KeyAgreementEnum
) – The key-agreement type to use.pubkey¶ (
bytes
) – The raw bytes that will be used as a pubkey in the key-agreement.
- Return type:
- Returns:
The response.
- ecdsa(keypair, export, sig_type, data)[source]¶
Send the ECDSA command.
- Parameters:
keypair¶ (
KeypairEnum
) – The keypair to use.export¶ (
bool
) – Whether to export the signature.sig_type¶ (
SignatureEnum
) – The Signature type to use.data¶ (
bytes
) – The data to sign and verify.
- Return type:
- Returns:
The response.
- ecdsa_sign(keypair, export, sig_type, data)[source]¶
Send the ECDSA sign command.
- Parameters:
keypair¶ (
KeypairEnum
) – The keypair to use to sign.export¶ (
bool
) – Whether to export the signature.sig_type¶ (
SignatureEnum
) – The Signature type to use.data¶ (
bytes
) – The data to sign.
- Return type:
- Returns:
The response.
- ecdsa_verify(keypair, sig_type, sig, data)[source]¶
Send the ECDSA verify command.
- Parameters:
keypair¶ (
KeypairEnum
) – The keypair to use to verify.sig_type¶ (
SignatureEnum
) – The Signature type to use.sig¶ (
bytes
) – The signature to verify.data¶ (
bytes
) – The data.
- Return type:
- Returns:
The response.
- static encode_parameters(params, obj)[source]¶
Encode values from obj into the byte parameters that the ECTester applet expects.
- Return type:
Mapping
[ParameterEnum
,bytes
]
- export(keypair, key, params)[source]¶
Send the Export command.
- Parameters:
keypair¶ (
KeypairEnum
) – Which keypair to export from.params¶ (
ParameterEnum
) – Which parameters to export.
- Return type:
- Returns:
The response, containing the exported parameters.
- generate(keypair)[source]¶
Send the Generate command.
- Parameters:
keypair¶ (
KeypairEnum
) – Which keypair to generate.- Return type:
- Returns:
The response.
- select(aid)[source]¶
Select an applet with
aid
.- Parameters:
aid¶ (
bytes
) – The AID of the applet to select.- Return type:
bool
- Returns:
Whether the selection was successful.
- select_applet(latest_version=b'033', count_back=10)[source]¶
Select the ECTester applet, with a specified version or older.
- send_apdu(apdu)[source]¶
Send an APDU to the selected applet.
- Parameters:
apdu¶ (
CommandAPDU
) – The APDU to send.- Return type:
- Returns:
The response.
- set(keypair, curve, params, values=None)[source]¶
Send the Set command.
- Parameters:
keypair¶ (
KeypairEnum
) – Which keypair to set values on.curve¶ (
CurveEnum
) – Which pre-set curve to use to set values, or default or external.params¶ (
ParameterEnum
) – Which parameters to set on the keypair.values¶ (
Optional
[Mapping
[ParameterEnum
,bytes
]]) – External values to set on the keypair.
- Return type:
- Returns:
The response.
- transform(keypair, key, params, transformation)[source]¶
Send the Transform command.
- Parameters:
keypair¶ (
KeypairEnum
) – Which keypair to transform.params¶ (
ParameterEnum
) – Which parameters to transform.transformation¶ (
TransformationEnum
) – What transformation to apply.
- Return type:
- Returns:
The response.
- class ECTesterTargetLEIA(leia)[source]¶
Bases:
ECTesterTarget
,LEIATarget
An ECTester-applet-based target that is connected via the LEIA board.
- allocate(keypair, builder, key_length, key_class)[source]¶
Send the Allocate KeyPair command.
- Parameters:
keypair¶ (
KeypairEnum
) – Which keypair to allocate.builder¶ (
KeyBuildEnum
) – Which builder to use to allocate the keypair.key_length¶ (
int
) – Bit-size of the allocated keypair.key_class¶ (
KeyClassEnum
) – Type of the allocated keypair.
- Return type:
- Returns:
The response.
- allocate_ka(ka_type)[source]¶
Send the Allocate KeyAgreement command.
- Parameters:
ka_type¶ (
KeyAgreementEnum
) – Which KeyAgreement type to allocate.- Return type:
- Returns:
The response.
- allocate_sig(sig_type)[source]¶
Send the Allocate Signature command.
- Parameters:
sig_type¶ (
SignatureEnum
) – Which Signature type to allocate.- Return type:
- Returns:
The response.
- clear(keypair)[source]¶
Send the Clear key command.
- Parameters:
keypair¶ (
KeypairEnum
) – Which keypair to clear.- Return type:
- Returns:
The response.
- connect(protocol=None)[source]¶
Connect to the card.
- Parameters:
protocol¶ (
Optional
[CardProtocol
]) – CardProtocol to use.
- ecdh(pubkey, privkey, export, transformation, ka_type)[source]¶
Send the ECDH command.
- Parameters:
pubkey¶ (
KeypairEnum
) – Which keypair to use the pubkey from, in the key-agreement.privkey¶ (
KeypairEnum
) – Which keypair to use the privkey from, in the key-agreement.export¶ (
bool
) – Whether to export the shared secret.transformation¶ (
TransformationEnum
) – The transformation to apply to the pubkey before key-agreement.ka_type¶ (
KeyAgreementEnum
) – The key-agreement type to use.
- Return type:
- Returns:
The response.
- ecdh_direct(privkey, export, transformation, ka_type, pubkey)[source]¶
Send the ECDH direct command.
- Parameters:
privkey¶ (
KeypairEnum
) – Which keypair to use the privkey from, in the key-agreement.export¶ (
bool
) – Whether to export the shared secret.transformation¶ (
TransformationEnum
) – The transformation to apply to the pubkey before key-agreement.ka_type¶ (
KeyAgreementEnum
) – The key-agreement type to use.pubkey¶ (
bytes
) – The raw bytes that will be used as a pubkey in the key-agreement.
- Return type:
- Returns:
The response.
- ecdsa(keypair, export, sig_type, data)[source]¶
Send the ECDSA command.
- Parameters:
keypair¶ (
KeypairEnum
) – The keypair to use.export¶ (
bool
) – Whether to export the signature.sig_type¶ (
SignatureEnum
) – The Signature type to use.data¶ (
bytes
) – The data to sign and verify.
- Return type:
- Returns:
The response.
- ecdsa_sign(keypair, export, sig_type, data)[source]¶
Send the ECDSA sign command.
- Parameters:
keypair¶ (
KeypairEnum
) – The keypair to use to sign.export¶ (
bool
) – Whether to export the signature.sig_type¶ (
SignatureEnum
) – The Signature type to use.data¶ (
bytes
) – The data to sign.
- Return type:
- Returns:
The response.
- ecdsa_verify(keypair, sig_type, sig, data)[source]¶
Send the ECDSA verify command.
- Parameters:
keypair¶ (
KeypairEnum
) – The keypair to use to verify.sig_type¶ (
SignatureEnum
) – The Signature type to use.sig¶ (
bytes
) – The signature to verify.data¶ (
bytes
) – The data.
- Return type:
- Returns:
The response.
- static encode_parameters(params, obj)[source]¶
Encode values from obj into the byte parameters that the ECTester applet expects.
- Return type:
Mapping
[ParameterEnum
,bytes
]
- export(keypair, key, params)[source]¶
Send the Export command.
- Parameters:
keypair¶ (
KeypairEnum
) – Which keypair to export from.params¶ (
ParameterEnum
) – Which parameters to export.
- Return type:
- Returns:
The response, containing the exported parameters.
- generate(keypair)[source]¶
Send the Generate command.
- Parameters:
keypair¶ (
KeypairEnum
) – Which keypair to generate.- Return type:
- Returns:
The response.
- select(aid)[source]¶
Select an applet with
aid
.- Parameters:
aid¶ (
bytes
) – The AID of the applet to select.- Return type:
bool
- Returns:
Whether the selection was successful.
- select_applet(latest_version=b'033', count_back=10)[source]¶
Select the ECTester applet, with a specified version or older.
- send_apdu(apdu)[source]¶
Send an APDU to the selected applet.
- Parameters:
apdu¶ (
CommandAPDU
) – The APDU to send.- Return type:
- Returns:
The response.
- set(keypair, curve, params, values=None)[source]¶
Send the Set command.
- Parameters:
keypair¶ (
KeypairEnum
) – Which keypair to set values on.curve¶ (
CurveEnum
) – Which pre-set curve to use to set values, or default or external.params¶ (
ParameterEnum
) – Which parameters to set on the keypair.values¶ (
Optional
[Mapping
[ParameterEnum
,bytes
]]) – External values to set on the keypair.
- Return type:
- Returns:
The response.
- transform(keypair, key, params, transformation)[source]¶
Send the Transform command.
- Parameters:
keypair¶ (
KeypairEnum
) – Which keypair to transform.params¶ (
ParameterEnum
) – Which parameters to transform.transformation¶ (
TransformationEnum
) – What transformation to apply.
- Return type:
- Returns:
The response.