|
1 | 1 | package cz.crcs.ectester.reader.command;
|
2 | 2 |
|
| 3 | +import cz.crcs.ectester.common.ec.EC_Consts; |
3 | 4 | import cz.crcs.ectester.common.ec.EC_Curve;
|
4 | 5 | import cz.crcs.ectester.common.ec.EC_Params;
|
5 |
| -import cz.crcs.ectester.common.ec.EC_Consts; |
6 | 6 | import cz.crcs.ectester.common.util.ByteUtil;
|
| 7 | +import cz.crcs.ectester.common.util.CardConsts; |
7 | 8 | import cz.crcs.ectester.common.util.CardUtil;
|
8 | 9 | import cz.crcs.ectester.common.util.ECUtil;
|
9 |
| -import cz.crcs.ectester.common.util.CardConsts; |
10 | 10 | import cz.crcs.ectester.data.EC_Store;
|
11 | 11 | import cz.crcs.ectester.reader.CardMngr;
|
12 | 12 | import cz.crcs.ectester.reader.ECTesterReader;
|
|
19 | 19 | import java.io.FileInputStream;
|
20 | 20 | import java.io.IOException;
|
21 | 21 | import java.util.ArrayList;
|
22 |
| -import java.util.Arrays; |
23 | 22 | import java.util.List;
|
24 | 23 |
|
25 | 24 | /**
|
@@ -372,6 +371,25 @@ public Set(CardMngr cardManager, byte keyPair, byte curve, short params, byte[]
|
372 | 371 | ByteUtil.setShort(data, 0, params);
|
373 | 372 | if (external != null) {
|
374 | 373 | System.arraycopy(external, 0, data, 2, external.length);
|
| 374 | + if ((params & EC_Consts.PARAMETER_FP) != 0) { |
| 375 | + EC_Params par = new EC_Params(params); |
| 376 | + par.readBytes(external); |
| 377 | + byte[][] prime = par.getParam(EC_Consts.PARAMETER_FP); |
| 378 | + byte[] p = prime[0]; |
| 379 | + int bytes = p.length; |
| 380 | + if ((params & EC_Consts.PARAMETER_G) != 0) { |
| 381 | + byte[][] generator = par.getParam(EC_Consts.PARAMETER_G); |
| 382 | + if (generator[0].length != bytes || generator[1].length != bytes) { |
| 383 | + throw new IllegalArgumentException("Generator point does not match prime field size."); |
| 384 | + } |
| 385 | + } |
| 386 | + if ((params & EC_Consts.PARAMETER_W) != 0) { |
| 387 | + byte[][] w = par.getParam(EC_Consts.PARAMETER_W); |
| 388 | + if (w[0].length != bytes || w[1].length != bytes) { |
| 389 | + throw new IllegalArgumentException("Public key point does not match prime field size."); |
| 390 | + } |
| 391 | + } |
| 392 | + } |
375 | 393 | }
|
376 | 394 |
|
377 | 395 | this.cmd = new CommandAPDU(CardConsts.CLA_ECTESTERAPPLET, CardConsts.INS_SET, keyPair, curve, data);
|
|
0 commit comments