From a9e52ab31b153505cb405a19601d105ccb5eca9c Mon Sep 17 00:00:00 2001 From: Arnaud Fontaine Date: Thu, 6 Dec 2018 11:02:16 +0100 Subject: [PATCH] TestApplet: add test for EC without W --- .../src/fr/anssi/smartpgp/TestApplet.java | 22 ++++++++++++++++--- test_applet/test.py | 5 +++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/test_applet/src/fr/anssi/smartpgp/TestApplet.java b/test_applet/src/fr/anssi/smartpgp/TestApplet.java index 3d845fe..c569d5b 100644 --- a/test_applet/src/fr/anssi/smartpgp/TestApplet.java +++ b/test_applet/src/fr/anssi/smartpgp/TestApplet.java @@ -141,14 +141,14 @@ public final class TestApplet extends Applet { } private final void processTestEc(final byte p1, final byte p2) { - boolean generate; + boolean generate, provide_w; short size; ECPrivateKey priv; ECPublicKey pub; byte[] field, a, b, g, r, s, w; short k; - switch(p1) { + switch(p1 & (byte)0x01) { case (byte)0x00: generate = false; break; @@ -162,6 +162,20 @@ public final class TestApplet extends Applet { return; } + switch(p1 & (byte)0x10) { + case (byte)0x00: + provide_w = true; + break; + + case (byte)0x10: + provide_w = false; + break; + + default: + ISOException.throwIt(ISO7816.SW_WRONG_P1P2); + return; + } + switch(p2) { case (byte)0x00: size = 256; @@ -237,7 +251,9 @@ public final class TestApplet extends Applet { kp.genKeyPair(); } else { priv.setS(s, (short)0, (short)s.length); - pub.setW(w, (short)0, (short)w.length); + if(provide_w) { + pub.setW(w, (short)0, (short)w.length); + } } if(!pub.isInitialized()) { diff --git a/test_applet/test.py b/test_applet/test.py index 232ac72..bbb2bff 100755 --- a/test_applet/test.py +++ b/test_applet/test.py @@ -40,6 +40,9 @@ TEST_RSA_CRT_2048_GENERATE = [0x00, 0x02, TEST_EC_P256_STATIC = [0x00, 0x03, 0x00, 0x00]; +TEST_EC_P256_STATIC_NO_W = [0x00, 0x03, + 0x10, 0x00]; + TEST_EC_P256_GENERATE = [0x00, 0x03, 0x01, 0x00]; @@ -123,6 +126,8 @@ def test_ec(con): select_applet(con, False) send_apdu(con, "Test NIST P-256 static", TEST_EC_P256_STATIC) select_applet(con, False) + send_apdu(con, "Test NIST P-256 static (without W)", TEST_EC_P256_STATIC_NO_W) + select_applet(con, False) send_apdu(con, "Test NIST P-256 generate", TEST_EC_P256_GENERATE) select_applet(con, False) send_apdu(con, "Test NIST P-521 static", TEST_EC_P521_STATIC)