Newer
Older
/*
* @author
*
* @version
* 1.0
* @desc
*
* @remark
*
* @see
*
*/
module TestCodec_SecuredFuntions {
// LibCommon
import from LibCommon_BasicTypesAndValues all;
import from LibCommon_DataStrings all;
// LibIts
import from IEEE1609dot2BaseTypes language "ASN.1:1997" all;
import from IEEE1609dot2 language "ASN.1:1997" all;
import from EtsiTs103097Module language "ASN.1:1997" all;
// LibItsSecurity
import from LibItsSecurity_EncdecDeclarations all;
import from LibItsSecurity_TypesAndValues all;
import from LibItsSecurity_Templates all;
import from LibItsSecurity_Functions all;
import from LibItsSecurity_Pixits all;
// TestCodec
import from TestCodec_TestAndSystem all;
testcase tc_sha256_1() runs on TCType system TCType {
var octetstring v_test := '616263'O;
var Oct32 v_exp_hash := 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'O;
var Oct32 v_hash;
v_hash := f_hashWithSha256(v_test);
if (match(v_hash, v_exp_hash) == false) {
setverdict(fail);
} else {
setverdict(pass);
}
} // End of test tc_sha256_1
testcase tc_sha384_1() runs on TCType system TCType {
var octetstring v_test := '616263'O;
var Oct48 v_exp_hash := 'CB00753F45A35E8BB5A03D699AC65007272C32AB0EDED1631A8B605A43FF5BED8086072BA1E7CC2358BAECA134C825A7'O;
var Oct48 v_hash;
v_hash := f_hashWithSha384(v_test);
if (match(v_hash, v_exp_hash) == false) {
setverdict(fail);
} else {
setverdict(pass);
}
} // End of test tc_sha384_1
testcase tc_f_generate_key_pair_1() runs on TCType system TCType {
var Oct32 v_private_key;
var Oct32 v_publicKeyX;
var Oct32 v_publicKeyY;
if (f_generate_key_pair_nistp256(v_private_key, v_publicKeyX, v_publicKeyY) == false) {
setverdict(fail);
stop;
}
log("v_private_key = ", v_private_key);
log("v_public_key X= ", v_publicKeyX);
log("v_public_key Y= ", v_publicKeyY);
setverdict(pass);
} // End of test tc_f_generate_key_pair_1
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
testcase tc_f_generate_key_pair_2() runs on TCType system TCType {
var Oct32 v_private_key;
var Oct32 v_publicKeyX;
var Oct32 v_publicKeyY;
if (f_generate_key_pair_brainpoolp256(v_private_key, v_publicKeyX, v_publicKeyY) == false) {
setverdict(fail);
stop;
}
log("v_private_key = ", v_private_key);
log("v_public_key X= ", v_publicKeyX);
log("v_public_key Y= ", v_publicKeyY);
setverdict(pass);
} // End of test tc_f_generate_key_pair_2
testcase tc_f_generate_key_pair_3() runs on TCType system TCType {
var Oct48 v_private_key;
var Oct48 v_publicKeyX;
var Oct48 v_publicKeyY;
if (f_generate_key_pair_brainpoolp384(v_private_key, v_publicKeyX, v_publicKeyY) == false) {
setverdict(fail);
stop;
}
log("v_private_key = ", v_private_key);
log("v_public_key X= ", v_publicKeyX);
log("v_public_key Y= ", v_publicKeyY);
setverdict(pass);
} // End of test tc_f_generate_key_pair_3
testcase tc_f_signWithEcdsaNistp256WithSha256_1() runs on TCType system TCType {
var Oct32 v_private_key;
var Oct32 v_publicKeyX;
var Oct32 v_publicKeyY;
var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O;
var octetstring v_sig := ''O;
if (f_generate_key_pair_nistp256(v_private_key, v_publicKeyX, v_publicKeyY) == false) {
setverdict(fail);
stop;
}
log("v_private_key = ", v_private_key);
log("v_public_key X= ", v_publicKeyX);
log("v_public_key Y= ", v_publicKeyY);
v_sig := f_signWithEcdsaNistp256WithSha256(v_encMsg, v_private_key);
if (lengthof(v_sig) == 0) {
setverdict(fail);
stop;
}
setverdict(pass);
} // End of test tc_f_signWithEcdsaNistp256WithSha256_1
testcase tc_f_verifyWithEcdsaNistp256WithSha256_1() runs on TCType system TCType {
var Oct32 v_private_key;
var Oct32 v_publicKeyX;
var Oct32 v_publicKeyY;
var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O;
var octetstring v_sig := ''O;
if (f_generate_key_pair_nistp256(v_private_key, v_publicKeyX, v_publicKeyY) == false) {
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
setverdict(fail);
stop;
}
log("v_private_key = ", v_private_key);
log("v_public_key X= ", v_publicKeyX);
log("v_public_key Y= ", v_publicKeyY);
v_sig := f_signWithEcdsaNistp256WithSha256(v_encMsg, v_private_key);
if (lengthof(v_sig) == 0) {
setverdict(fail);
stop;
}
if (f_verifyWithEcdsaNistp256WithSha256(v_encMsg, v_sig, v_publicKeyX, v_publicKeyY) == false) {
setverdict(fail);
stop;
} else {
setverdict(pass);
}
} // End of test tc_f_verifyWithEcdsaNistp256WithSha256_1
testcase tc_f_verifyWithEcdsaNistp256WithSha256_2() runs on TCType system TCType {
var Oct32 v_private_key;
var Oct32 v_publicKeyX;
var Oct32 v_publicKeyY;
var Oct32 v_private_key_wrong;
var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O;
var octetstring v_sig := ''O;
if (f_generate_key_pair_nistp256(v_private_key, v_publicKeyX, v_publicKeyY) == false) {
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
setverdict(fail);
stop;
}
log("v_private_key = ", v_private_key);
log("v_public_key X= ", v_publicKeyX);
log("v_public_key Y= ", v_publicKeyY);
v_private_key_wrong := v_private_key;
v_sig := f_signWithEcdsaNistp256WithSha256(v_encMsg, v_private_key);
if (lengthof(v_sig) == 0) {
setverdict(fail);
stop;
}
if (f_verifyWithEcdsaNistp256WithSha256(v_encMsg, v_sig, v_publicKeyX, v_publicKeyY) == false) {
setverdict(fail);
stop;
} else {
setverdict(pass);
}
v_private_key_wrong[2] := 'AA'O;
v_sig := f_signWithEcdsaNistp256WithSha256(v_encMsg, v_private_key_wrong);
if (lengthof(v_sig) == 0) {
setverdict(fail);
stop;
}
if (f_verifyWithEcdsaNistp256WithSha256(v_encMsg, v_sig, v_publicKeyX, v_publicKeyY) == true) {
setverdict(fail);
stop;
} else {
setverdict(pass);
}
} // End of test tc_f_verifyWithEcdsaNistp256WithSha256_2
testcase tc_f_verifyWithEcdsaNistp256WithSha256_3() runs on TCType system TCType {
var Oct32 v_private_key;
var Oct32 v_publicKeyX;
var Oct32 v_publicKeyY;
var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O;
var octetstring v_sig := ''O;
var octetstring v_sig_wrong := ''O;
var Oct32 v_publicKeyX_wrong;
var Oct32 v_publicKeyY_wrong;
if (f_generate_key_pair_nistp256(v_private_key, v_publicKeyX, v_publicKeyY) == false) {
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
setverdict(fail);
stop;
}
log("v_private_key = ", v_private_key);
log("v_public_key X= ", v_publicKeyX);
log("v_public_key Y= ", v_publicKeyY);
v_sig := f_signWithEcdsaNistp256WithSha256(v_encMsg, v_private_key);
if (f_verifyWithEcdsaNistp256WithSha256(v_encMsg, v_sig, v_publicKeyX, v_publicKeyY) == false) {
setverdict(fail);
stop;
}
if (f_verifyWithEcdsaNistp256WithSha256('0A0A0A0A'O, v_sig, v_publicKeyX, v_publicKeyY) == true) {
setverdict(fail);
stop;
}
v_sig_wrong := v_sig;
v_sig_wrong[0] := 'FF'O;
if (f_verifyWithEcdsaNistp256WithSha256(v_encMsg, v_sig_wrong, v_publicKeyX, v_publicKeyY) == true) {
setverdict(fail);
stop;
}
v_publicKeyX_wrong := v_publicKeyX;
v_publicKeyX_wrong[0] := 'FF'O;
if (f_verifyWithEcdsaNistp256WithSha256(v_encMsg, v_sig, v_publicKeyX_wrong, v_publicKeyY) == true) {
setverdict(fail);
stop;
}
v_publicKeyY_wrong := v_publicKeyY;
v_publicKeyY_wrong[0] := 'FF'O;
if (f_verifyWithEcdsaNistp256WithSha256(v_encMsg, v_sig, v_publicKeyX, v_publicKeyY_wrong) == true) {
setverdict(fail);
stop;
}
setverdict(pass);
} // End of test tc_f_verifyWithEcdsaNistp256WithSha256_3
testcase tc_f_signWithEcdsaBrainpoolp256WithSha256_1() runs on TCType system TCType {
var Oct32 v_private_key;
var Oct32 v_publicKeyX;
var Oct32 v_publicKeyY;
var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O;
var octetstring v_sig := ''O;
if (f_generate_key_pair_brainpoolp256(v_private_key, v_publicKeyX, v_publicKeyY) == false) {
setverdict(fail);
stop;
}
log("v_private_key = ", v_private_key);
log("v_public_key X= ", v_publicKeyX);
log("v_public_key Y= ", v_publicKeyY);
v_sig := f_signWithEcdsaBrainpoolp256WithSha256(v_encMsg, v_private_key);
if (lengthof(v_sig) == 0) {
setverdict(fail);
stop;
}
setverdict(pass);
} // End of test tc_f_signWithEcdsaBrainpoolp256WithSha256_1
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
testcase tc_f_signWithEcdsaBrainpoolp384WithSha384_1() runs on TCType system TCType {
var Oct48 v_private_key;
var Oct48 v_publicKeyX;
var Oct48 v_publicKeyY;
var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O;
var octetstring v_sig := ''O;
if (f_generate_key_pair_brainpoolp384(v_private_key, v_publicKeyX, v_publicKeyY) == false) {
setverdict(fail);
stop;
}
log("v_private_key = ", v_private_key);
log("v_public_key X= ", v_publicKeyX);
log("v_public_key Y= ", v_publicKeyY);
v_sig := f_signWithEcdsaBrainpoolp384WithSha384(v_encMsg, v_private_key);
if (lengthof(v_sig) == 0) {
setverdict(fail);
stop;
}
setverdict(pass);
} // End of test tc_f_signWithEcdsaBrainpoolp384WithSha384_1
testcase tc_f_verifyWithEcdsaBrainpoolp256WithSha256_1() runs on TCType system TCType {
var Oct32 v_private_key;
var Oct32 v_publicKeyX;
var Oct32 v_publicKeyY;
var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O;
var octetstring v_sig := ''O;
if (f_generate_key_pair_brainpoolp256(v_private_key, v_publicKeyX, v_publicKeyY) == false) {
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
setverdict(fail);
stop;
}
log("v_private_key = ", v_private_key);
log("v_public_key X= ", v_publicKeyX);
log("v_public_key Y= ", v_publicKeyY);
v_sig := f_signWithEcdsaBrainpoolp256WithSha256(v_encMsg, v_private_key);
if (lengthof(v_sig) == 0) {
setverdict(fail);
stop;
}
if (f_verifyWithEcdsaBrainpoolp256WithSha256(v_encMsg, v_sig, v_publicKeyX, v_publicKeyY) == false) {
setverdict(fail);
stop;
} else {
setverdict(pass);
}
} // End of test tc_f_verifyWithEcdsaBrainpoolp256WithSha256_1
testcase tc_f_verifyWithEcdsaBrainpoolp256WithSha256_2() runs on TCType system TCType {
var Oct32 v_private_key;
var Oct32 v_publicKeyX;
var Oct32 v_publicKeyY;
var Oct32 v_private_key_wrong;
var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O;
var octetstring v_sig := ''O;
if (f_generate_key_pair_brainpoolp256(v_private_key, v_publicKeyX, v_publicKeyY) == false) {
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
setverdict(fail);
stop;
}
log("v_private_key = ", v_private_key);
log("v_public_key X= ", v_publicKeyX);
log("v_public_key Y= ", v_publicKeyY);
v_private_key_wrong := v_private_key;
v_sig := f_signWithEcdsaBrainpoolp256WithSha256(v_encMsg, v_private_key);
if (lengthof(v_sig) == 0) {
setverdict(fail);
stop;
}
if (f_verifyWithEcdsaBrainpoolp256WithSha256(v_encMsg, v_sig, v_publicKeyX, v_publicKeyY) == false) {
setverdict(fail);
stop;
} else {
setverdict(pass);
}
v_private_key_wrong[2] := 'AA'O;
v_sig := f_signWithEcdsaBrainpoolp256WithSha256(v_encMsg, v_private_key_wrong);
if (lengthof(v_sig) == 0) {
setverdict(fail);
stop;
}
if (f_verifyWithEcdsaBrainpoolp256WithSha256(v_encMsg, v_sig, v_publicKeyX, v_publicKeyY) == true) {
setverdict(fail);
stop;
} else {
setverdict(pass);
}
} // End of test tc_f_verifyWithEcdsaBrainpoolp256WithSha256_2
testcase tc_f_verifyWithEcdsaBrainpoolp256WithSha256_3() runs on TCType system TCType {
var Oct32 v_private_key;
var Oct32 v_publicKeyX;
var Oct32 v_publicKeyY;
var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O;
var octetstring v_sig := ''O;
var octetstring v_sig_wrong := ''O;
var Oct32 v_publicKeyX_wrong;
var Oct32 v_publicKeyY_wrong;
if (f_generate_key_pair_brainpoolp256(v_private_key, v_publicKeyX, v_publicKeyY) == false) {
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
setverdict(fail);
stop;
}
log("v_private_key = ", v_private_key);
log("v_public_key X= ", v_publicKeyX);
log("v_public_key Y= ", v_publicKeyY);
v_sig := f_signWithEcdsaBrainpoolp256WithSha256(v_encMsg, v_private_key);
if (f_verifyWithEcdsaBrainpoolp256WithSha256(v_encMsg, v_sig, v_publicKeyX, v_publicKeyY) == false) {
setverdict(fail);
stop;
}
if (f_verifyWithEcdsaBrainpoolp256WithSha256('0A0A0A0A'O, v_sig, v_publicKeyX, v_publicKeyY) == true) {
setverdict(fail);
stop;
}
v_sig_wrong := v_sig;
v_sig_wrong[0] := 'FF'O;
if (f_verifyWithEcdsaBrainpoolp256WithSha256(v_encMsg, v_sig_wrong, v_publicKeyX, v_publicKeyY) == true) {
setverdict(fail);
stop;
}
v_publicKeyX_wrong := v_publicKeyX;
v_publicKeyX_wrong[0] := 'FF'O;
if (f_verifyWithEcdsaBrainpoolp256WithSha256(v_encMsg, v_sig, v_publicKeyX_wrong, v_publicKeyY) == true) {
setverdict(fail);
stop;
}
v_publicKeyY_wrong := v_publicKeyY;
v_publicKeyY_wrong[0] := 'FF'O;
if (f_verifyWithEcdsaBrainpoolp256WithSha256(v_encMsg, v_sig, v_publicKeyX, v_publicKeyY_wrong) == true) {
setverdict(fail);
stop;
}
setverdict(pass);
} // End of test tc_f_verifyWithEcdsaBrainpoolp256WithSha256_3
testcase tc_f_verifyWithEcdsaBrainpoolp384WithSha384_1() runs on TCType system TCType {
var Oct48 v_private_key;
var Oct48 v_publicKeyX;
var Oct48 v_publicKeyY;
var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O;
var octetstring v_sig := ''O;
if (f_generate_key_pair_brainpoolp384(v_private_key, v_publicKeyX, v_publicKeyY) == false) {
setverdict(fail);
stop;
}
log("v_private_key = ", v_private_key);
log("v_public_key X= ", v_publicKeyX);
log("v_public_key Y= ", v_publicKeyY);
v_sig := f_signWithEcdsaBrainpoolp384WithSha384(v_encMsg, v_private_key);
if (lengthof(v_sig) == 0) {
setverdict(fail);
stop;
}
if (f_verifyWithEcdsaBrainpoolp384WithSha384(v_encMsg, v_sig, v_publicKeyX, v_publicKeyY) == false) {
setverdict(fail);
stop;
} else {
setverdict(pass);
}
} // End of test tc_f_verifyWithEcdsaBrainpoolp384WithSha384_1
testcase tc_f_verifyWithEcdsaBrainpoolp384WithSha384_2() runs on TCType system TCType {
var Oct48 v_private_key;
var Oct48 v_publicKeyX;
var Oct48 v_publicKeyY;
var Oct48 v_private_key_wrong;
var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O;
var octetstring v_sig := ''O;
if (f_generate_key_pair_brainpoolp384(v_private_key, v_publicKeyX, v_publicKeyY) == false) {
setverdict(fail);
stop;
}
log("v_private_key = ", v_private_key);
log("v_public_key X= ", v_publicKeyX);
log("v_public_key Y= ", v_publicKeyY);
v_private_key_wrong := v_private_key;
v_sig := f_signWithEcdsaBrainpoolp384WithSha384(v_encMsg, v_private_key);
if (lengthof(v_sig) == 0) {
setverdict(fail);
stop;
}
if (f_verifyWithEcdsaBrainpoolp384WithSha384(v_encMsg, v_sig, v_publicKeyX, v_publicKeyY) == false) {
setverdict(fail);
stop;
} else {
setverdict(pass);
}
v_private_key_wrong[2] := 'AA'O;
v_sig := f_signWithEcdsaBrainpoolp384WithSha384(v_encMsg, v_private_key_wrong);
if (lengthof(v_sig) == 0) {
setverdict(fail);
stop;
}
if (f_verifyWithEcdsaBrainpoolp384WithSha384(v_encMsg, v_sig, v_publicKeyX, v_publicKeyY) == true) {
setverdict(fail);
stop;
} else {
setverdict(pass);
}
} // End of test tc_f_verifyWithEcdsaBrainpoolp384WithSha384_2
testcase tc_f_verifyWithEcdsaBrainpoolp384WithSha384_3() runs on TCType system TCType {
var Oct48 v_private_key;
var Oct48 v_publicKeyX;
var Oct48 v_publicKeyY;
var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O;
var octetstring v_sig := ''O;
var octetstring v_sig_wrong := ''O;
var Oct48 v_publicKeyX_wrong;
var Oct48 v_publicKeyY_wrong;
if (f_generate_key_pair_brainpoolp384(v_private_key, v_publicKeyX, v_publicKeyY) == false) {
setverdict(fail);
stop;
}
log("v_private_key = ", v_private_key);
log("v_public_key X= ", v_publicKeyX);
log("v_public_key Y= ", v_publicKeyY);
v_sig := f_signWithEcdsaBrainpoolp384WithSha384(v_encMsg, v_private_key);
if (f_verifyWithEcdsaBrainpoolp384WithSha384(v_encMsg, v_sig, v_publicKeyX, v_publicKeyY) == false) {
setverdict(fail);
stop;
}
if (f_verifyWithEcdsaBrainpoolp384WithSha384('0A0A0A0A'O, v_sig, v_publicKeyX, v_publicKeyY) == true) {
setverdict(fail);
stop;
}
v_sig_wrong := v_sig;
v_sig_wrong[0] := 'FF'O;
if (f_verifyWithEcdsaBrainpoolp384WithSha384(v_encMsg, v_sig_wrong, v_publicKeyX, v_publicKeyY) == true) {
setverdict(fail);
stop;
}
v_publicKeyX_wrong := v_publicKeyX;
v_publicKeyX_wrong[0] := 'FF'O;
if (f_verifyWithEcdsaBrainpoolp384WithSha384(v_encMsg, v_sig, v_publicKeyX_wrong, v_publicKeyY) == true) {
setverdict(fail);
stop;
}
v_publicKeyY_wrong := v_publicKeyY;
v_publicKeyY_wrong[0] := 'FF'O;
if (f_verifyWithEcdsaBrainpoolp384WithSha384(v_encMsg, v_sig, v_publicKeyX, v_publicKeyY_wrong) == true) {
setverdict(fail);
stop;
}
setverdict(pass);
} // End of test tc_f_verifyWithEcdsaBrainpoolp384WithSha384_3