MCPcopy Index your code
hub / github.com/crocs-muni/ECTester

github.com/crocs-muni/ECTester @0.3.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.3.3 ↗ · + Follow
1,471 symbols 3,786 edges 122 files 197 documented · 13%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

ECTester

Build status Build status GitHub release license docs

Tests support and behavior of elliptic curve cryptography implementations on JavaCards (TYPE_EC_FP and TYPE_EC_F2M) and on selected software libraries. For more information on ECC support on JavaCards see the github page, with results, tables and docs.

Setup

ECTester uses ant. There are three parts of ECTester, the JavaCard applet used for testing, the reader app which controls it and the standalone app which tests software libraries.

git submodule update --init --recursive       # To initialize submodules.
ant -f build-reader.xml package               # To build the reader tool (jar) -> "dist/ECTesterReader.jar"
ant -f build-standalone.xml package           # To build the standalone tool (jar) -> "dist/ECTesterStandalone.jar"
ant -f build-applet.xml build                 # To build the applet (cap) -> "applet/ectester.cap".

Build produces both a lightweight version of the JARs and a full version of the JARs with dependencies included, the latter has the *-dist.jar suffix. The standalone build tries building test binaries for all the supported libraries, and silently fails if the library is not properly supported.

The applet comes in two flavors, targeting JavaCard 2.2.1 and 2.2.2. The 2.2.2 version supports extended length APDUs which are necessary for some commands to work properly. Use the cap ant property to specify which CAP file to build, either ectester221.cap or ectester222.cap.

To build the 221 version do:

ant -f build-applet.xml build -Dcap=ectester221.cap

JavaCard testing

  1. Upload applet/ectester.cap using your favorite tool (e.g., GlobalPlatformPro tool) or the build-applet.xml ant file.
  2. Run java -jar dist/ECTesterReader.jar -t.
  3. Inspect output log with annotated results.

Following operations are tested in the default test suite: - Allocation of new KeyPair class for specified parameters - Generation of KeyPair with default curve - Setting of custom curve and KeyPair generation - Generation of shared secret via ECDH - Signature via ECDSA

See java -jar ECTesterReader.jar -h, java -jar ECTesterReader.jar -ls and DOCS for more.

Options

 -V,--version                         Print version info.
 -h,--help                            Print help.
 -ln,--list-named <what>              Print the list of supported named
                                      curves and keys.
 -ls,--list-suites                    List supported test suites.
 -e,--export                          Export the defaut curve parameters
                                      of the card(if any).
 -g,--generate <amount>               Generate <amount> of EC keys.
 -t,--test <test_suite[:from[:to]]>   Test ECC support. Optionally specify
                                      a test number to run only a part of
                                      a test suite. <test_suite>:
                                      - default
                                      - compression
                                      - invalid
                                      - twist
                                      - degenerate
                                      - cofactor
                                      - wrong
                                      - signature
                                      - composite
                                      - test-vectors
                                      - edge-cases
                                      - miscellaneous
 -dh,--ecdh <count>                   Do EC KeyAgreement (ECDH...),
                                      [count] times.
 -dsa,--ecdsa <count>                 Sign data with ECDSA, [count] times.
 -nf,--info                           Get applet info.
 -b,--bit-size <bits>                 Set curve size.
 -fp,--prime-field                    Use a prime field.
 -f2m,--binary-field                  Use a binary field.
 -nc,--named-curve <cat/id>           Use a named curve, from CurveDB:
                                      <cat/id>
 -c,--curve <curve_file>              Use curve from file <curve_file>
                                      (field,a,b,gx,gy,r,k).
 -u,--custom                          Use a custom curve (applet-side
                                      embedded, SECG curves).
 -npub,--named-public <cat/id>        Use public key from KeyDB: <cat/id>
 -pub,--public <pubkey_file>          Use public key from file
                                      <pubkey_file> (wx,wy).
 -npriv,--named-private <cat/id>      Use private key from KeyDB: <cat/id>
 -priv,--private <privkey_file>       Use private key from file
                                      <privkey_file> (s).
 -nk,--named-key <cat/id>             Use keyPair from KeyDB: <cat/id>
 -k,--key <key_file>                  Use keyPair from file <key_file>
                                      (wx,wy,s).
 -i,--input <input_file>              Input from file <input_file>, for
                                      ECDSA signing.
 -o,--output <output_file>            Output into file <output_file>. The
                                      file can be prefixed by the format
                                      (one of text,yml,xml), such as:
                                      xml:<output_file>.
 -l,--log <log_file>                  Log output into file [log_file].
 -v,--verbose                         Turn on verbose logging.
    --format <format>                 Output format to use. One of:
                                      text,yml,xml.
    --fixed                           Generate key(s) only once, keep them
                                      for later operations.
    --fixed-private                   Generate private key only once, keep
                                      it for later ECDH.
    --fixed-public                    Generate public key only once, keep
                                      it for later ECDH.
 -f,--fresh                           Generate fresh keys (set domain
                                      parameters before every generation).
    --time                            Output better timing values, by
                                      running command in dry run mode and
                                      normal mode, and subtracting the
                                      two.
    --time-unit <unit>                Use given time unit in measurement,
                                      one of: milli, micro, nano.
    --cleanup                         Send the cleanup command trigerring
                                      JCSystem.requestObjectDeletion()
                                      after some operations.
 -s,--simulate                        Simulate a card with jcardsim
                                      instead of using a terminal.
 -y,--yes                             Accept all warnings and prompts.
 -to,--test-options <options>         Test options to use:
                                      - preset: Use preset semi-random
                                      private keys (derived from curve)
                                      instead of generating keypairs on
                                      the cards when the test needs one.
                                      - random: Use fully random private
                                      keys instead of generating keypairs.
 -ka,--ka-type <type>                 Set KeyAgreement object [type],
                                      corresponds to JC.KeyAgreement
                                      constants.
 -sig,--sig-type <type>               Set Signature object [type],
                                      corresponds to JC.Signature
                                      constants.
 -C,--color                           Print stuff with color, requires
                                      ANSI terminal.

Actions

Export

-e / --export

Exports the default curves (if any) that are preset on the card. Use with -o / --output [out_file] to output the curve parameters to a file. For format of this file see FORMAT.

Test

-t / --test [test_suite]

Perform support, performance and vulnerability tests of ECC.

To select which tests will be performed, it is possible to enter the test suite name with a suffix which specifies the number of the first test to be run, and optionally the number of the last test to be run as -t <test_suite>[:start_index[:stop_index]].

Use with -o / --output [out_type:]<out_file> to output the test results to a file. For possible formats of this file see FORMAT. For more info about the test suites see TESTS.

Generate

-g / --generate [amount]

Generates batch of EC keypairs and exports them.

Use with -o / --output [out_file] to output the generated keys to a file. Use with --time to measure time as a difference of real duration of the operation and the dry-run duration of the operation. For format of this file see FORMAT.

ECDH

-dh / --ecdh [count]

Performs ECDH.

Use with -o / --output [out_file] to output into a file. Use with --time to measure time as a difference of real duration of the operation and the dry-run duration of the operation. For format of this file see FORMAT. Respects the KeyAgreement type specified in -ka / --ka-type [type].

ECDSA

-dsa / --ecdsa [count]

Performs ECDSA. Useful with -i / --input [in_file] to sign the contents of a file. Use with -o / --output [out_file] to output into a file. Use with --time to measure time as a difference of real duration of the operation and the dry-run duration of the operation. For format of these files see FORMAT. Respects the Signature type specified in -sig / --sig-type [type].

List named curves

-ln / --list-named []

Lists categories of curves, keys and keypairs embedded in ECTester's jar, along with some information about them. These can be used as arguments to the -n[c|k|pub|priv] / --named-[curve|key|public|private] parameters, using the format: category/name.

For example: secg/secp192r1 identifies the SECG 192 bit prime field curve known as secp192r1.

For more info about the curves and curve categories see CURVES.

List test suites

-ls / --list-suites

Lists the implemented test suites and gives their short description.

Get applet info

-nf / --info

Get and print ECTester applet info from an applet installed on a card.

Outputs: - Card ATR - Negotiated protocol (T=0/T=1) - ECTester applet version - ECTester APDU support (basic/extended APDU) - JavaCard API version - JavaCard cleanup support - ECTester internal array sizes and APDU buffer size

Example

Snippet below shows running the default test suite while simulating(-s), so using JCardSim. This shows that JCardsim simulates 112b Fp support with default curve present and supports ECDH, ECDHC and ECDSA.

```

java -jar ECTesterReader.jar -t -s ═══ Running test suite: default ═══ ═══ The default test suite tests basic support of ECDH and ECDSA. ═══ Date: 2018.05.02 20:29:38 ═══ ECTester version: v0.3.0 ═══ Card ATR: 3bfa1800008131fe454a434f5033315632333298 ■━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━┓ OK ╋ (0) Get applet info: v0.3.0; 3.0; basic ┃ SUCCESS ┃ All sub-tests had the expected result. ┗ OK ━ Get applet info ┃ SUCCESS ┃ 0 ms ┃ OK (0x9000) ■━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━┓ OK ╋ (1) Tests of 112b ALG_EC_FP support. ┃ SUCCESS ┃ All sub-tests matched the expected mask. ┣ OK ━ Allocate both keypairs 112b ALG_EC_FP ┃ SUCCESS ┃ 166 ms ┃ OK (0x9000) OK (0x9000) ┣ OK ━ Generate both keypairs ┃ SUCCESS ┃ 19 ms ┃ OK (0x9000) OK (0x9000) ┣ OK ━ Allocate both keypairs 112b ALG_EC_FP ┃ SUCCESS ┃ 0 ms ┃ OK (0x9000) OK (0x9000) ┣ OK ━ Set custom curve parameters on both keypairs ┃ SUCCESS ┃ 0 ms ┃ OK (0x9000) OK (0x9000) ┣ OK ━ Generate both keypairs ┃ SUCCESS ┃ 5 ms ┃ OK (0x9000) OK (0x9000) ┣ OK ┳ KeyAgreement tests. ┃ SUCCESS ┃ Some sub-tests did have the expected result. ┃ ┣ OK ┳ Test of the ALG_EC_SVDP_DH KeyAgreement. ┃ SUCCESS ┃ Some ECDH is supported. ┃ ┃ ┣ OK ━ Allocate KeyAgreement(ALG_EC_SVDP_DH) object ┃ SUCCESS ┃ 1 ms ┃ OK (0x9000) ┃ ┃

Extension points exported contracts — how you extend this code

TestWriter (Interface)
@author Jan Jancar johny@neuromancer.sk [8 implementers]
src/cz/crcs/ectester/common/output/TestWriter.java
Testable (Interface)
@author Jan Jancar johny@neuromancer.sk [4 implementers]
src/cz/crcs/ectester/common/test/Testable.java
ECLibrary (Interface)
@author Jan Jancar johny@neuromancer.sk [1 implementers]
src/cz/crcs/ectester/standalone/libs/ECLibrary.java
ANSIParam (Interface)
(no doc) [3 implementers]
src/cz/crcs/ectester/common/cli/Colors.java

Core symbols most depended-on inside this repo

throw_new
called by 67
src/cz/crcs/ectester/standalone/libs/jni/c_utils.c
throw_new_var
called by 29
src/cz/crcs/ectester/standalone/libs/jni/c_utils.c
native_timing_start
called by 25
src/cz/crcs/ectester/standalone/libs/jni/c_timing.c
native_timing_stop
called by 25
src/cz/crcs/ectester/standalone/libs/jni/c_timing.c
end
called by 24
src/cz/crcs/ectester/common/output/TestWriter.java
ok
called by 24
src/cz/crcs/ectester/common/test/Testable.java
add_sig
called by 23
src/cz/crcs/ectester/standalone/libs/jni/cpp_utils.cpp
begin
called by 20
src/cz/crcs/ectester/common/output/TestWriter.java

Shape

Method 1,015
Class 249
Function 194
Enum 9
Interface 4

Languages

Java87%
C9%
C++4%
Python1%

Modules by API surface

src/cz/crcs/ectester/standalone/libs/jni/NativeSignatureSpi.java123 symbols
src/cz/crcs/ectester/reader/command/Command.java75 symbols
src/cz/crcs/ectester/reader/response/Response.java63 symbols
src/cz/crcs/ectester/standalone/libs/jni/NativeKeyAgreementSpi.java62 symbols
src/cz/crcs/ectester/standalone/libs/jni/NativeKeyPairGeneratorSpi.java57 symbols
src/cz/crcs/ectester/applet/AppletBase.java37 symbols
src/cz/crcs/ectester/standalone/libs/jni/gcrypt.c30 symbols
src/cz/crcs/ectester/standalone/libs/jni/NativeECPublicKey.java30 symbols
src/cz/crcs/ectester/standalone/libs/jni/NativeECPrivateKey.java30 symbols
src/cz/crcs/ectester/standalone/libs/jni/mscng.c29 symbols
src/cz/crcs/ectester/standalone/libs/jni/cryptopp.cpp29 symbols
src/cz/crcs/ectester/common/util/ECUtil.java25 symbols

For agents

$ claude mcp add ECTester \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact