{ "cells": [ { "cell_type": "markdown", "id": "15ac247f", "metadata": {}, "source": [ "## Test results\n", "\n", "This notebook takes in the raw results created by the [measure.ipynb](measure.ipynb) notebook and evaluates them.\n", "\n", "[Test 3n](#Test-3n)\n", "\n", "[Test composite](#Test-composite-(inverse))\n", "\n", "[Test k=10](#Test-k=10)\n", "\n", "[Test n+epsilon GSR](#Test-n+epsilon-GSR)\n", "\n", "[Test n+epsilon Multiplicative](#Test-n+epsilon-Multiplicative)" ] }, { "cell_type": "code", "execution_count": null, "id": "e3313aa9-5cc6-47ff-8db0-b4419e1afb4d", "metadata": {}, "outputs": [], "source": [ "from test_eval import Test3n, Testinverse, Testk10, TestEpsilon_GSR, TestEpsilon_Multiplicative" ] }, { "cell_type": "code", "execution_count": null, "id": "aeb9bd2b", "metadata": {}, "outputs": [], "source": [ "cards = ['A1','F1','F2','G1','I1','I2','N1','N10','N2','N3','N4','N5','N6','N7','N8','N9','S1','S2']" ] }, { "cell_type": "markdown", "id": "6e544e0f-1249-41b8-87bd-69d8c3e90c0f", "metadata": {}, "source": [ "For each test evaluation call below you can choose one of the cards above.\n", "\n", "Note that several smartcards really are the same model and thus we merge them:\n", " - N4 = N5 = N10\n", " - N6 = N7\n", " - N3 = N8" ] }, { "cell_type": "markdown", "id": "7a53b79a", "metadata": {}, "source": [ "## Test 3n" ] }, { "cell_type": "code", "execution_count": null, "id": "75a7366e", "metadata": {}, "outputs": [], "source": [ "curve_path = \"tests/test3n/curve.csv\"\n", "point_path = \"tests/test3n/point_3n.csv\"\n", "test3n = Test3n(curve_path,point_path)\n", "test3n.existing_measurements(cards,\"ecdh\")\n", "test3n.existing_measurements(cards,\"ecdsa\")\n", "test3n.existing_measurements(cards,\"keygen\")" ] }, { "cell_type": "code", "execution_count": null, "id": "495f4854", "metadata": {}, "outputs": [], "source": [ "test3n.print_ecdh(\"N1\")" ] }, { "cell_type": "code", "execution_count": null, "id": "706ef56e", "metadata": {}, "outputs": [], "source": [ "test3n.print_keygen(\"N1\")" ] }, { "cell_type": "code", "execution_count": null, "id": "7e007ee6-cb16-40e4-9217-7e0d08047a7a", "metadata": {}, "outputs": [], "source": [ "test3n.print_ecdsa(\"N1\")" ] }, { "cell_type": "markdown", "id": "c0cad787", "metadata": {}, "source": [ "## Test composite (inverse)" ] }, { "cell_type": "code", "execution_count": null, "id": "c7c5f56e", "metadata": {}, "outputs": [], "source": [ "curve_path = \"tests/testinverse/cofactor256p11_full.csv\"\n", "point_path = \"tests/testinverse/point_11n.csv\"\n", "testinverse = Testinverse(curve_path, point_path, 11)\n", "testinverse.existing_measurements(cards,\"ecdh\")\n", "testinverse.existing_measurements(cards,\"ecdsa\")\n", "testinverse.existing_measurements(cards,\"keygen\")" ] }, { "cell_type": "code", "execution_count": null, "id": "8397c88e", "metadata": {}, "outputs": [], "source": [ "testinverse.print_ecdh(\"N1\")" ] }, { "cell_type": "markdown", "id": "182766b2-aa74-47ea-9d21-3988604c3b6b", "metadata": {}, "source": [ "For some cards, multiple measurements were done (e.g., with a fixed private key).\n", "There is an optional prefix argument to process only files with the specified prefix." ] }, { "cell_type": "code", "execution_count": null, "id": "405df6fc", "metadata": {}, "outputs": [], "source": [ "testinverse.print_ecdsa(\"N1\",\"ecdsa_fixed_11\")" ] }, { "cell_type": "code", "execution_count": null, "id": "2bc5803b", "metadata": {}, "outputs": [], "source": [ "testinverse.print_keygen(\"N1\")" ] }, { "cell_type": "markdown", "id": "7a39d841", "metadata": {}, "source": [ "## Test k=10" ] }, { "cell_type": "markdown", "id": "c9d7bb23-b5f3-430f-ad08-cccfb272eede", "metadata": {}, "source": [ "The test only makes sense for ECDH." ] }, { "cell_type": "code", "execution_count": null, "id": "b197e324", "metadata": {}, "outputs": [], "source": [ "curve_path = \"tests/testk10/secp256r1.csv\"\n", "point_path = \"tests/testk10/secgpoint.csv\"\n", "testk10 = Testk10(curve_path, point_path, 10)\n", "testk10.existing_measurements(cards,\"ecdh\")" ] }, { "cell_type": "code", "execution_count": null, "id": "92616fc3", "metadata": {}, "outputs": [], "source": [ "testk10.print_ecdh(\"N1\")" ] }, { "cell_type": "markdown", "id": "741ae1f0-b943-4421-b936-30ae8ddaa1be", "metadata": {}, "source": [ "## Test n+epsilon GSR" ] }, { "cell_type": "markdown", "id": "2b6474c2-0015-45bb-8a08-503d21662662", "metadata": {}, "source": [ "The test makes sense only for implementations of GSR (or BT bit-length fixing) that permit input parameters, including:\n", "\n", "- ECDH: N6, N8, I1\n", "- ECDSA: N1, N2, N6, N8, N9, I2\n", "- Keygen: N1, N2, N6, N9, I2" ] }, { "cell_type": "code", "execution_count": null, "id": "eb2b8923-5977-4d73-b127-b2773bdde91e", "metadata": {}, "outputs": [], "source": [ "curve_path = \"tests/testdn/weakcurve_32_n_1.csv\"\n", "point_path = \"tests/testdn/weakcurve_32_n_1_point.csv\"\n", "realn_path = \"tests/testdn/realn.csv\"\n", "\n", "testepsilon = TestEpsilon_GSR(curve_path,point_path,realn_path)" ] }, { "cell_type": "code", "execution_count": null, "id": "40dceab4", "metadata": {}, "outputs": [], "source": [ "testepsilon.recover_ecdsa(\"N1\")" ] }, { "cell_type": "code", "execution_count": null, "id": "fa3ecd8d", "metadata": {}, "outputs": [], "source": [ "testepsilon.recover_keygen(\"N1\")" ] }, { "cell_type": "markdown", "id": "444caf43-4f62-4db6-aa67-d8f79f608ce7", "metadata": {}, "source": [ "N8 and I1 needed different parameters for ECDH." ] }, { "cell_type": "code", "execution_count": null, "id": "adba1ff5-4235-4084-b1dd-ab206903bb24", "metadata": {}, "outputs": [], "source": [ "curve_path = \"tests/testdn/weakcurve_32_n_good_gen.csv\"\n", "point_path = \"tests/testdn/weakcurve_32_n_1_point.csv\"\n", "realn_path = \"tests/testdn/realn.csv\"\n", "\n", "testepsilon = TestEpsilon_GSR(curve_path,point_path,realn_path)" ] }, { "cell_type": "code", "execution_count": null, "id": "609ee23f", "metadata": {}, "outputs": [], "source": [ "testepsilon.recover_ecdh_plain(\"N8\")" ] }, { "cell_type": "markdown", "id": "c4395ea6", "metadata": {}, "source": [ "## Test n+epsilon Multiplicative" ] }, { "cell_type": "markdown", "id": "67afdd25-f8b6-47d0-bdd4-e128e5e5724d", "metadata": {}, "source": [ "The test makes sense only for implementations of GSR (or BT bit-length fixing) that permit input parameters, including:\n", "\n", " - ECDH: N10\n", " - ECDSA: N10 - strange behaviour, does not work " ] }, { "cell_type": "code", "execution_count": null, "id": "bab76405", "metadata": {}, "outputs": [], "source": [ "curve_path = \"tests/testdn/weakcurve_32_n_1.csv\"\n", "point_path = \"tests/testdn/weakcurve_32_n_1_point.csv\"\n", "realn_path = \"tests/testdn/realn.csv\"\n", "\n", "testepsilon = TestEpsilon_Multiplicative(curve_path,point_path,realn_path)" ] }, { "cell_type": "markdown", "id": "65bddf04-3572-4a2b-a459-037222d05e87", "metadata": {}, "source": [ "First, we can approximate the bitsizes of the used masks:" ] }, { "cell_type": "code", "execution_count": null, "id": "76362134", "metadata": {}, "outputs": [], "source": [ "testepsilon.recover_ecdh_plain_size(\"N10\")" ] }, { "cell_type": "markdown", "id": "6bdcb776-dbac-4314-b302-270b2f1e4710", "metadata": {}, "source": [ "Second, we list the number of candidates with bitsizes in the specified range:" ] }, { "cell_type": "code", "execution_count": null, "id": "4c9d9898", "metadata": {}, "outputs": [], "source": [ "testepsilon.compute_candidates(61,65)" ] }, { "cell_type": "code", "execution_count": null, "id": "66de5424", "metadata": {}, "outputs": [], "source": [ "# does not work\n", "# testepsilon.recover_ecdsa_size(\"N10\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.7" } }, "nbformat": 4, "nbformat_minor": 5 }