1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 /** 19 * @author Vladimir N. Molotkov 20 * @version $Revision$ 21 */ 22 23 package tests.security.spec; 24 25 import dalvik.annotation.TestTargets; 26 import dalvik.annotation.TestLevel; 27 import dalvik.annotation.TestTargetNew; 28 import dalvik.annotation.TestTargetClass; 29 30 import junit.framework.TestCase; 31 32 import java.math.BigInteger; 33 import java.security.spec.KeySpec; 34 import java.security.spec.RSAMultiPrimePrivateCrtKeySpec; 35 import java.security.spec.RSAOtherPrimeInfo; 36 import java.security.spec.RSAPrivateKeySpec; 37 38 /** 39 * Tests for <code>RSAMultiPrimePrivateCrtKeySpec</code> class fields and methods. 40 * 41 */ 42 @TestTargetClass(RSAMultiPrimePrivateCrtKeySpec.class) 43 public class RSAMultiPrimePrivateCrtKeySpecTest extends TestCase { 44 /** 45 * Reference array of RSAOtherPrimeInfo. DO NOT MODIFY 46 */ 47 private static final RSAOtherPrimeInfo[] opi = new RSAOtherPrimeInfo[] { 48 new RSAOtherPrimeInfo(BigInteger.ONE, BigInteger.ONE, BigInteger.ONE), 49 new RSAOtherPrimeInfo(BigInteger.ONE, BigInteger.ONE, BigInteger.ONE), 50 new RSAOtherPrimeInfo(BigInteger.ONE, BigInteger.ONE, BigInteger.ONE) 51 }; 52 53 // Test-cases: 54 55 /** 56 * Test #1 for 57 * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, 58 * BigInteger publicExponent, 59 * BigInteger privateExponent, 60 * BigInteger primeP, 61 * BigInteger primeQ, 62 * BigInteger primeExponentP, 63 * BigInteger primeExponentQ, 64 * BigInteger crtCoefficient, 65 * RSAOtherPrimeInfo[] otherPrimeInfo) 66 * </code> ctor<br> 67 * Assertion: constructs <code>RSAMultiPrimePrivateCrtKeySpec</code> 68 * object using valid parameters 69 */ 70 @TestTargetNew( 71 level = TestLevel.PARTIAL_COMPLETE, 72 notes = "Verifies constructor with valid parameters.", 73 method = "RSAMultiPrimePrivateCrtKeySpec", 74 args = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.security.spec.RSAOtherPrimeInfo[].class} 75 ) 76 public final void testRSAMultiPrimePrivateCrtKeySpec01() { 77 KeySpec ks = new RSAMultiPrimePrivateCrtKeySpec( 78 BigInteger.ONE, 79 BigInteger.ONE, 80 BigInteger.ONE, 81 BigInteger.ONE, 82 BigInteger.ONE, 83 BigInteger.ONE, 84 BigInteger.ONE, 85 BigInteger.ONE, 86 opi); 87 assertTrue(ks instanceof RSAMultiPrimePrivateCrtKeySpec); 88 } 89 90 /** 91 * Test #2 for 92 * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, 93 * BigInteger publicExponent, 94 * BigInteger privateExponent, 95 * BigInteger primeP, 96 * BigInteger primeQ, 97 * BigInteger primeExponentP, 98 * BigInteger primeExponentQ, 99 * BigInteger crtCoefficient, 100 * RSAOtherPrimeInfo[] otherPrimeInfo) 101 * </code> ctor<br> 102 * Assertion: NullPointerException if modulus is null 103 */ 104 @TestTargetNew( 105 level = TestLevel.PARTIAL_COMPLETE, 106 notes = "Verifies NullPointerException.", 107 method = "RSAMultiPrimePrivateCrtKeySpec", 108 args = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.security.spec.RSAOtherPrimeInfo[].class} 109 ) 110 public final void testRSAMultiPrimePrivateCrtKeySpec02() { 111 try { 112 new RSAMultiPrimePrivateCrtKeySpec( 113 null, 114 BigInteger.ONE, 115 BigInteger.ONE, 116 BigInteger.ONE, 117 BigInteger.ONE, 118 BigInteger.ONE, 119 BigInteger.ONE, 120 BigInteger.ONE, 121 opi); 122 fail("Expected NPE not thrown"); 123 } catch (NullPointerException e) { 124 } 125 } 126 127 /** 128 * Test #3 for 129 * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, 130 * BigInteger publicExponent, 131 * BigInteger privateExponent, 132 * BigInteger primeP, 133 * BigInteger primeQ, 134 * BigInteger primeExponentP, 135 * BigInteger primeExponentQ, 136 * BigInteger crtCoefficient, 137 * RSAOtherPrimeInfo[] otherPrimeInfo) 138 * </code> ctor<br> 139 * Assertion: NullPointerException if publicExponent is null 140 */ 141 @TestTargetNew( 142 level = TestLevel.PARTIAL_COMPLETE, 143 notes = "Verifies NullPointerException.", 144 method = "RSAMultiPrimePrivateCrtKeySpec", 145 args = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.security.spec.RSAOtherPrimeInfo[].class} 146 ) 147 public final void testRSAMultiPrimePrivateCrtKeySpec03() { 148 try { 149 new RSAMultiPrimePrivateCrtKeySpec( 150 BigInteger.ONE, 151 null, 152 BigInteger.ONE, 153 BigInteger.ONE, 154 BigInteger.ONE, 155 BigInteger.ONE, 156 BigInteger.ONE, 157 BigInteger.ONE, 158 opi); 159 fail("Expected NPE not thrown"); 160 } catch (NullPointerException e) { 161 } 162 } 163 164 /** 165 * Test #4 for 166 * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, 167 * BigInteger publicExponent, 168 * BigInteger privateExponent, 169 * BigInteger primeP, 170 * BigInteger primeQ, 171 * BigInteger primeExponentP, 172 * BigInteger primeExponentQ, 173 * BigInteger crtCoefficient, 174 * RSAOtherPrimeInfo[] otherPrimeInfo) 175 * </code> ctor<br> 176 * Assertion: NullPointerException if privateExponent is null 177 */ 178 @TestTargetNew( 179 level = TestLevel.PARTIAL_COMPLETE, 180 notes = "Verifies NullPointerException.", 181 method = "RSAMultiPrimePrivateCrtKeySpec", 182 args = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.security.spec.RSAOtherPrimeInfo[].class} 183 ) 184 public final void testRSAMultiPrimePrivateCrtKeySpec04() { 185 try { 186 new RSAMultiPrimePrivateCrtKeySpec( 187 BigInteger.ONE, 188 BigInteger.ONE, 189 null, 190 BigInteger.ONE, 191 BigInteger.ONE, 192 BigInteger.ONE, 193 BigInteger.ONE, 194 BigInteger.ONE, 195 opi); 196 fail("Expected NPE not thrown"); 197 } catch (NullPointerException e) { 198 } 199 } 200 201 /** 202 * Test #5 for 203 * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, 204 * BigInteger publicExponent, 205 * BigInteger privateExponent, 206 * BigInteger primeP, 207 * BigInteger primeQ, 208 * BigInteger primeExponentP, 209 * BigInteger primeExponentQ, 210 * BigInteger crtCoefficient, 211 * RSAOtherPrimeInfo[] otherPrimeInfo) 212 * </code> ctor<br> 213 * Assertion: NullPointerException if primeP is null 214 */ 215 @TestTargetNew( 216 level = TestLevel.PARTIAL_COMPLETE, 217 notes = "Verifies NullPointerException.", 218 method = "RSAMultiPrimePrivateCrtKeySpec", 219 args = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.security.spec.RSAOtherPrimeInfo[].class} 220 ) 221 public final void testRSAMultiPrimePrivateCrtKeySpec05() { 222 try { 223 new RSAMultiPrimePrivateCrtKeySpec( 224 BigInteger.ONE, 225 BigInteger.ONE, 226 BigInteger.ONE, 227 null, 228 BigInteger.ONE, 229 BigInteger.ONE, 230 BigInteger.ONE, 231 BigInteger.ONE, 232 opi); 233 fail("Expected NPE not thrown"); 234 } catch (NullPointerException e) { 235 } 236 } 237 238 /** 239 * Test #6 for 240 * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, 241 * BigInteger publicExponent, 242 * BigInteger privateExponent, 243 * BigInteger primeP, 244 * BigInteger primeQ, 245 * BigInteger primeExponentP, 246 * BigInteger primeExponentQ, 247 * BigInteger crtCoefficient, 248 * RSAOtherPrimeInfo[] otherPrimeInfo) 249 * </code> ctor<br> 250 * Assertion: NullPointerException if primeQ is null 251 */ 252 @TestTargetNew( 253 level = TestLevel.PARTIAL_COMPLETE, 254 notes = "Verifies NullPointerException.", 255 method = "RSAMultiPrimePrivateCrtKeySpec", 256 args = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.security.spec.RSAOtherPrimeInfo[].class} 257 ) 258 public final void testRSAMultiPrimePrivateCrtKeySpec06() { 259 try { 260 new RSAMultiPrimePrivateCrtKeySpec( 261 BigInteger.ONE, 262 BigInteger.ONE, 263 BigInteger.ONE, 264 BigInteger.ONE, 265 null, 266 BigInteger.ONE, 267 BigInteger.ONE, 268 BigInteger.ONE, 269 opi); 270 fail("Expected NPE not thrown"); 271 } catch (NullPointerException e) { 272 } 273 } 274 275 /** 276 * Test #7 for 277 * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, 278 * BigInteger publicExponent, 279 * BigInteger privateExponent, 280 * BigInteger primeP, 281 * BigInteger primeQ, 282 * BigInteger primeExponentP, 283 * BigInteger primeExponentQ, 284 * BigInteger crtCoefficient, 285 * RSAOtherPrimeInfo[] otherPrimeInfo) 286 * </code> ctor<br> 287 * Assertion: NullPointerException if primeExponentP is null 288 */ 289 @TestTargetNew( 290 level = TestLevel.PARTIAL_COMPLETE, 291 notes = "Verifies NullPointerException.", 292 method = "RSAMultiPrimePrivateCrtKeySpec", 293 args = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.security.spec.RSAOtherPrimeInfo[].class} 294 ) 295 public final void testRSAMultiPrimePrivateCrtKeySpec07() { 296 try { 297 new RSAMultiPrimePrivateCrtKeySpec( 298 BigInteger.ONE, 299 BigInteger.ONE, 300 BigInteger.ONE, 301 BigInteger.ONE, 302 BigInteger.ONE, 303 null, 304 BigInteger.ONE, 305 BigInteger.ONE, 306 opi); 307 fail("Expected NPE not thrown"); 308 } catch (NullPointerException e) { 309 } 310 } 311 312 /** 313 * Test #8 for 314 * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, 315 * BigInteger publicExponent, 316 * BigInteger privateExponent, 317 * BigInteger primeP, 318 * BigInteger primeQ, 319 * BigInteger primeExponentP, 320 * BigInteger primeExponentQ, 321 * BigInteger crtCoefficient, 322 * RSAOtherPrimeInfo[] otherPrimeInfo) 323 * </code> ctor<br> 324 * Assertion: NullPointerException if primeExponentQ is null 325 */ 326 @TestTargetNew( 327 level = TestLevel.PARTIAL_COMPLETE, 328 notes = "Verifies NullPointerException.", 329 method = "RSAMultiPrimePrivateCrtKeySpec", 330 args = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.security.spec.RSAOtherPrimeInfo[].class} 331 ) 332 public final void testRSAMultiPrimePrivateCrtKeySpec08() { 333 try { 334 new RSAMultiPrimePrivateCrtKeySpec( 335 BigInteger.ONE, 336 BigInteger.ONE, 337 BigInteger.ONE, 338 BigInteger.ONE, 339 BigInteger.ONE, 340 BigInteger.ONE, 341 null, 342 BigInteger.ONE, 343 opi); 344 fail("Expected NPE not thrown"); 345 } catch (NullPointerException e) { 346 } 347 } 348 349 /** 350 * Test #9 for 351 * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, 352 * BigInteger publicExponent, 353 * BigInteger privateExponent, 354 * BigInteger primeP, 355 * BigInteger primeQ, 356 * BigInteger primeExponentP, 357 * BigInteger primeExponentQ, 358 * BigInteger crtCoefficient, 359 * RSAOtherPrimeInfo[] otherPrimeInfo) 360 * </code> ctor<br> 361 * Assertion: NullPointerException if crtCoefficient is null 362 */ 363 @TestTargetNew( 364 level = TestLevel.PARTIAL_COMPLETE, 365 notes = "Verifies NullPointerException.", 366 method = "RSAMultiPrimePrivateCrtKeySpec", 367 args = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.security.spec.RSAOtherPrimeInfo[].class} 368 ) 369 public final void testRSAMultiPrimePrivateCrtKeySpec09() { 370 try { 371 new RSAMultiPrimePrivateCrtKeySpec( 372 BigInteger.ONE, 373 BigInteger.ONE, 374 BigInteger.ONE, 375 BigInteger.ONE, 376 BigInteger.ONE, 377 BigInteger.ONE, 378 BigInteger.ONE, 379 null, 380 opi); 381 fail("Expected NPE not thrown"); 382 } catch (NullPointerException e) { 383 } 384 } 385 386 /** 387 * Test #10 for 388 * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, 389 * BigInteger publicExponent, 390 * BigInteger privateExponent, 391 * BigInteger primeP, 392 * BigInteger primeQ, 393 * BigInteger primeExponentP, 394 * BigInteger primeExponentQ, 395 * BigInteger crtCoefficient, 396 * RSAOtherPrimeInfo[] otherPrimeInfo) 397 * </code> ctor<br> 398 * Assertion: otherPrimeInfo can be null 399 */ 400 @TestTargetNew( 401 level = TestLevel.PARTIAL_COMPLETE, 402 notes = "Verifies null otherPrimeInfo.", 403 method = "RSAMultiPrimePrivateCrtKeySpec", 404 args = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.security.spec.RSAOtherPrimeInfo[].class} 405 ) 406 public final void testRSAMultiPrimePrivateCrtKeySpec10() { 407 try { 408 new RSAMultiPrimePrivateCrtKeySpec( 409 BigInteger.ONE, 410 BigInteger.ONE, 411 BigInteger.ONE, 412 BigInteger.ONE, 413 BigInteger.ONE, 414 BigInteger.ONE, 415 BigInteger.ONE, 416 BigInteger.ONE, 417 null); 418 } catch (Exception e) { 419 fail("Unexpected exception is thrown"); 420 } 421 } 422 423 /** 424 * Test #11 for 425 * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, 426 * BigInteger publicExponent, 427 * BigInteger privateExponent, 428 * BigInteger primeP, 429 * BigInteger primeQ, 430 * BigInteger primeExponentP, 431 * BigInteger primeExponentQ, 432 * BigInteger crtCoefficient, 433 * RSAOtherPrimeInfo[] otherPrimeInfo) 434 * </code> ctor<br> 435 * Assertion: IllegalArgumentException if otherPrimeInfo length is 0 436 */ 437 @TestTargetNew( 438 level = TestLevel.PARTIAL_COMPLETE, 439 notes = "Verifies IllegalArgumentException.", 440 method = "RSAMultiPrimePrivateCrtKeySpec", 441 args = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.security.spec.RSAOtherPrimeInfo[].class} 442 ) 443 public final void testRSAMultiPrimePrivateCrtKeySpec11() { 444 try { 445 new RSAMultiPrimePrivateCrtKeySpec( 446 BigInteger.ONE, 447 BigInteger.ONE, 448 BigInteger.ONE, 449 BigInteger.ONE, 450 BigInteger.ONE, 451 BigInteger.ONE, 452 BigInteger.ONE, 453 BigInteger.ONE, 454 new RSAOtherPrimeInfo[0]); 455 fail("Expected IAE not thrown"); 456 } catch (IllegalArgumentException e) { 457 } 458 } 459 460 /** 461 * Test #12 for 462 * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, 463 * BigInteger publicExponent, 464 * BigInteger privateExponent, 465 * BigInteger primeP, 466 * BigInteger primeQ, 467 * BigInteger primeExponentP, 468 * BigInteger primeExponentQ, 469 * BigInteger crtCoefficient, 470 * RSAOtherPrimeInfo[] otherPrimeInfo) 471 * </code> ctor<br> 472 * Assertion: constructs <code>RSAMultiPrimePrivateCrtKeySpec</code> 473 * object using valid parameters. Constructed object must be 474 * instance of RSAPrivateKeySpec. 475 */ 476 @TestTargetNew( 477 level = TestLevel.PARTIAL_COMPLETE, 478 notes = "Verifies constructor using valid parameters. Constructed object must be instance of RSAPrivateKeySpec.", 479 method = "RSAMultiPrimePrivateCrtKeySpec", 480 args = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.security.spec.RSAOtherPrimeInfo[].class} 481 ) 482 public final void testRSAMultiPrimePrivateCrtKeySpec12() { 483 KeySpec ks = new RSAMultiPrimePrivateCrtKeySpec( 484 BigInteger.ONE, 485 BigInteger.ONE, 486 BigInteger.ONE, 487 BigInteger.ONE, 488 BigInteger.ONE, 489 BigInteger.ONE, 490 BigInteger.ONE, 491 BigInteger.ONE, 492 opi); 493 assertTrue(ks instanceof RSAPrivateKeySpec); 494 } 495 496 /** 497 * Test for <code>getCrtCoefficient()</code> method<br> 498 * Assertion: returns crt coefficient 499 */ 500 @TestTargetNew( 501 level = TestLevel.COMPLETE, 502 notes = "", 503 method = "getCrtCoefficient", 504 args = {} 505 ) 506 public final void testGetCrtCoefficient() { 507 RSAMultiPrimePrivateCrtKeySpec ks = 508 new RSAMultiPrimePrivateCrtKeySpec( 509 BigInteger.ONE, 510 BigInteger.ONE, 511 BigInteger.ONE, 512 BigInteger.ONE, 513 BigInteger.ONE, 514 BigInteger.ONE, 515 BigInteger.ONE, 516 BigInteger.ONE, 517 opi); 518 assertTrue(BigInteger.ONE.equals(ks.getCrtCoefficient())); 519 } 520 521 /** 522 * Test for <code>getPrimeExponentP()</code> method<br> 523 * Assertion: returns prime exponent P 524 */ 525 @TestTargetNew( 526 level = TestLevel.COMPLETE, 527 notes = "", 528 method = "getPrimeExponentP", 529 args = {} 530 ) 531 public final void testGetPrimeExponentP() { 532 RSAMultiPrimePrivateCrtKeySpec ks = 533 new RSAMultiPrimePrivateCrtKeySpec( 534 BigInteger.ONE, 535 BigInteger.ONE, 536 BigInteger.ONE, 537 BigInteger.ONE, 538 BigInteger.ONE, 539 BigInteger.ONE, 540 BigInteger.ONE, 541 BigInteger.ONE, 542 opi); 543 assertTrue(BigInteger.ONE.equals(ks.getPrimeExponentP())); 544 } 545 546 /** 547 * Test for <code>getPrimeExponentQ()</code> method<br> 548 * Assertion: returns prime exponent Q 549 */ 550 @TestTargetNew( 551 level = TestLevel.COMPLETE, 552 notes = "", 553 method = "getPrimeExponentQ", 554 args = {} 555 ) 556 public final void testGetPrimeExponentQ() { 557 RSAMultiPrimePrivateCrtKeySpec ks = 558 new RSAMultiPrimePrivateCrtKeySpec( 559 BigInteger.ONE, 560 BigInteger.ONE, 561 BigInteger.ONE, 562 BigInteger.ONE, 563 BigInteger.ONE, 564 BigInteger.ONE, 565 BigInteger.ONE, 566 BigInteger.ONE, 567 opi); 568 assertTrue(BigInteger.ONE.equals(ks.getPrimeExponentQ())); 569 } 570 571 /** 572 * Test for <code>getPrimeP()</code> method<br> 573 * Assertion: returns prime P 574 */ 575 @TestTargetNew( 576 level = TestLevel.COMPLETE, 577 notes = "", 578 method = "getPrimeP", 579 args = {} 580 ) 581 public final void testGetPrimeP() { 582 RSAMultiPrimePrivateCrtKeySpec ks = 583 new RSAMultiPrimePrivateCrtKeySpec( 584 BigInteger.ONE, 585 BigInteger.ONE, 586 BigInteger.ONE, 587 BigInteger.ONE, 588 BigInteger.ONE, 589 BigInteger.ONE, 590 BigInteger.ONE, 591 BigInteger.ONE, 592 opi); 593 assertTrue(BigInteger.ONE.equals(ks.getPrimeP())); 594 } 595 596 /** 597 * Test for <code>getPrimeQ()</code> method<br> 598 * Assertion: returns prime Q 599 */ 600 @TestTargetNew( 601 level = TestLevel.COMPLETE, 602 notes = "", 603 method = "getPrimeQ", 604 args = {} 605 ) 606 public final void testGetPrimeQ() { 607 RSAMultiPrimePrivateCrtKeySpec ks = 608 new RSAMultiPrimePrivateCrtKeySpec( 609 BigInteger.ONE, 610 BigInteger.ONE, 611 BigInteger.ONE, 612 BigInteger.ONE, 613 BigInteger.ONE, 614 BigInteger.ONE, 615 BigInteger.ONE, 616 BigInteger.ONE, 617 opi); 618 assertTrue(BigInteger.ONE.equals(ks.getPrimeQ())); 619 } 620 621 /** 622 * Test for <code>getPublicExponent()</code> method<br> 623 * Assertion: returns public exponent 624 */ 625 @TestTargetNew( 626 level = TestLevel.COMPLETE, 627 notes = "", 628 method = "getPublicExponent", 629 args = {} 630 ) 631 public final void testGetPublicExponent() { 632 RSAMultiPrimePrivateCrtKeySpec ks = 633 new RSAMultiPrimePrivateCrtKeySpec( 634 BigInteger.ONE, 635 BigInteger.ONE, 636 BigInteger.ONE, 637 BigInteger.ONE, 638 BigInteger.ONE, 639 BigInteger.ONE, 640 BigInteger.ONE, 641 BigInteger.ONE, 642 opi); 643 assertTrue(BigInteger.ONE.equals(ks.getPublicExponent())); 644 } 645 646 /** 647 * Test #1 for <code>getOtherPrimeInfo()</code> method<br> 648 * Assertion: returns array of RSAOtherPrimeInfo 649 */ 650 @TestTargetNew( 651 level = TestLevel.PARTIAL_COMPLETE, 652 notes = "Verifies positive case.", 653 method = "getOtherPrimeInfo", 654 args = {} 655 ) 656 public final void testGetOtherPrimeInfo01() { 657 RSAMultiPrimePrivateCrtKeySpec ks = 658 new RSAMultiPrimePrivateCrtKeySpec( 659 BigInteger.ONE, 660 BigInteger.ONE, 661 BigInteger.ONE, 662 BigInteger.ONE, 663 BigInteger.ONE, 664 BigInteger.ONE, 665 BigInteger.ONE, 666 BigInteger.ONE, 667 opi); 668 assertTrue(checkOtherPrimeInfo(ks.getOtherPrimeInfo())); 669 } 670 671 /** 672 * Test #2 for <code>getOtherPrimeInfo()</code> method<br> 673 * Assertion: returns null if null has been passed to the 674 * constructor as otherPrimeInfo parameter 675 */ 676 @TestTargetNew( 677 level = TestLevel.PARTIAL_COMPLETE, 678 notes = "Verifies that getOtherPrimeInfo returns null if there are only two prime factors.", 679 method = "getOtherPrimeInfo", 680 args = {} 681 ) 682 public final void testGetOtherPrimeInfo02() { 683 RSAMultiPrimePrivateCrtKeySpec ks = 684 new RSAMultiPrimePrivateCrtKeySpec( 685 BigInteger.ONE, 686 BigInteger.ONE, 687 BigInteger.ONE, 688 BigInteger.ONE, 689 BigInteger.ONE, 690 BigInteger.ONE, 691 BigInteger.ONE, 692 BigInteger.ONE, 693 null); 694 assertNull(ks.getOtherPrimeInfo()); 695 } 696 697 // 698 // immutability tests 699 // 700 701 /** 702 * Tests that internal state of the object 703 * can not be modified by modifying initial array 704 */ 705 @TestTargets({ 706 @TestTargetNew( 707 level = TestLevel.PARTIAL_COMPLETE, 708 notes = "Verifies that internal state of the object can not be modified by modifying initial array.", 709 method = "RSAMultiPrimePrivateCrtKeySpec", 710 args = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.security.spec.RSAOtherPrimeInfo[].class} 711 ), 712 @TestTargetNew( 713 level = TestLevel.PARTIAL_COMPLETE, 714 notes = "Verifies that internal state of the object can not be modified by modifying initial array.", 715 method = "getOtherPrimeInfo", 716 args = {} 717 ) 718 }) 719 public final void testIsStatePreserved1() { 720 // Create initial array 721 RSAOtherPrimeInfo[] opi1 = opi.clone(); 722 723 RSAMultiPrimePrivateCrtKeySpec ks = new RSAMultiPrimePrivateCrtKeySpec( 724 BigInteger.ONE, 725 BigInteger.ONE, 726 BigInteger.ONE, 727 BigInteger.ONE, 728 BigInteger.ONE, 729 BigInteger.ONE, 730 BigInteger.ONE, 731 BigInteger.ONE, 732 opi1); 733 734 // Modify initial array 735 opi1[2] = new RSAOtherPrimeInfo(BigInteger.ZERO, 736 BigInteger.ZERO, 737 BigInteger.ZERO); 738 739 // Check that above modification 740 // does not affect internal state 741 assertTrue(checkOtherPrimeInfo(ks.getOtherPrimeInfo())); 742 } 743 744 /** 745 * Tests that internal state of the object 746 * can not be modified using array reference 747 * returned by <code>getOtherPrimeInfo()</code> 748 * method 749 */ 750 @TestTargets({ 751 @TestTargetNew( 752 level = TestLevel.PARTIAL_COMPLETE, 753 notes = "Verifies that internal state of the object can not be modified using array reference returned by getOtherPrimeInfo() method.", 754 method = "RSAMultiPrimePrivateCrtKeySpec", 755 args = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.security.spec.RSAOtherPrimeInfo[].class} 756 ), 757 @TestTargetNew( 758 level = TestLevel.PARTIAL_COMPLETE, 759 notes = "Verifies that internal state of the object can not be modified using array reference returned by getOtherPrimeInfo() method.", 760 method = "getOtherPrimeInfo", 761 args = {} 762 ) 763 }) 764 public final void testIsStatePreserved2() { 765 // Create initial array 766 RSAOtherPrimeInfo[] opi1 = opi.clone(); 767 768 RSAMultiPrimePrivateCrtKeySpec ks = new RSAMultiPrimePrivateCrtKeySpec( 769 BigInteger.ONE, 770 BigInteger.ONE, 771 BigInteger.ONE, 772 BigInteger.ONE, 773 BigInteger.ONE, 774 BigInteger.ONE, 775 BigInteger.ONE, 776 BigInteger.ONE, 777 opi1); 778 779 RSAOtherPrimeInfo[] ret = ks.getOtherPrimeInfo(); 780 781 // Modify returned array 782 ret[2] = new RSAOtherPrimeInfo(BigInteger.ZERO, 783 BigInteger.ZERO, 784 BigInteger.ZERO); 785 786 // Check that above modification 787 // does not affect internal state 788 assertTrue(checkOtherPrimeInfo(ks.getOtherPrimeInfo())); 789 } 790 791 // 792 // Tests for inherited methods 793 // 794 795 /** 796 * Test for <code>getModulus()</code> method<br> 797 * Assertion: returns modulus 798 */ 799 @TestTargetNew( 800 level = TestLevel.COMPLETE, 801 notes = "", 802 method = "getModulus", 803 args = {} 804 ) 805 public final void testGetModulus() { 806 RSAMultiPrimePrivateCrtKeySpec ks = 807 new RSAMultiPrimePrivateCrtKeySpec( 808 BigInteger.ONE, 809 BigInteger.ONE, 810 BigInteger.ONE, 811 BigInteger.ONE, 812 BigInteger.ONE, 813 BigInteger.ONE, 814 BigInteger.ONE, 815 BigInteger.ONE, 816 opi); 817 assertTrue(BigInteger.ONE.equals(ks.getModulus())); 818 } 819 820 /** 821 * Test for <code>getPrivateExponent()</code> method<br> 822 * Assertion: returns private exponent 823 */ 824 @TestTargetNew( 825 level = TestLevel.COMPLETE, 826 notes = "", 827 method = "getPrivateExponent", 828 args = {} 829 ) 830 public final void testGetPrivateExponent() { 831 RSAMultiPrimePrivateCrtKeySpec ks = 832 new RSAMultiPrimePrivateCrtKeySpec( 833 BigInteger.ONE, 834 BigInteger.ONE, 835 BigInteger.ONE, 836 BigInteger.ONE, 837 BigInteger.ONE, 838 BigInteger.ONE, 839 BigInteger.ONE, 840 BigInteger.ONE, 841 opi); 842 assertTrue(BigInteger.ONE.equals(ks.getPrivateExponent())); 843 } 844 845 // private stuff 846 // 847 /** 848 * Compares array passed as a parameter with reference one<br> 849 * 850 * <code>private static final RSAOtherPrimeInfo[] opi</code> 851 * 852 * @param toBeChecked 853 * Array to be compared 854 * @return 855 * true if arrays are equal 856 */ 857 private boolean checkOtherPrimeInfo(RSAOtherPrimeInfo[] toBeChecked) { 858 if (toBeChecked == null || toBeChecked.length != opi.length) { 859 return false; 860 } 861 for (int i=0; i<opi.length; i++) { 862 if (opi[i].getPrime().equals(toBeChecked[i].getPrime()) && 863 opi[i].getExponent().equals(toBeChecked[i].getExponent()) && 864 opi[i].getCrtCoefficient().equals(toBeChecked[i].getCrtCoefficient())) { 865 continue; 866 } 867 return false; 868 } 869 return true; 870 } 871 872 } 873