< prev index next >

test/jdk/sun/security/ec/ed/EdDSANegativeTest.java

Print this page
*** 32,18 ***
  import java.security.Signature;
  import java.security.interfaces.EdECPrivateKey;
  import java.security.interfaces.EdECPublicKey;
  import java.security.spec.EdDSAParameterSpec;
  import java.util.Arrays;
! import jdk.test.lib.Convert;
  
  /*
   * @test
   * @bug 8209632
   * @summary Negative cases for EDDSA.
   * @library /test/lib
-  * @build jdk.test.lib.Convert
   * @run main EdDSANegativeTest
   */
  public class EdDSANegativeTest {
  
      private static final String EDDSA = "EdDSA";
--- 32,17 ---
  import java.security.Signature;
  import java.security.interfaces.EdECPrivateKey;
  import java.security.interfaces.EdECPublicKey;
  import java.security.spec.EdDSAParameterSpec;
  import java.util.Arrays;
! import java.util.Hex;
  
  /*
   * @test
   * @bug 8209632
   * @summary Negative cases for EDDSA.
   * @library /test/lib
   * @run main EdDSANegativeTest
   */
  public class EdDSANegativeTest {
  
      private static final String EDDSA = "EdDSA";

*** 136,11 ***
              // As per rfc8032, value of context is maximum of 255 octet
              for (byte[] context : new byte[][]{{}, "other".getBytes(),
              new byte[255], new byte[500]}) {
                  System.out.printf("Testing signature for name: %s, algorithm "
                          + "spec: (prehash:%s, context:%s)%n", name, preHash,
!                         Convert.byteArrayToHexString(context));
                  try {
                      verify(sig, kp.getPublic(), MSG,
                              new EdDSAParameterSpec(preHash, context),
                              initParam, computedSig);
                  } catch (InvalidParameterException e) {
--- 135,11 ---
              // As per rfc8032, value of context is maximum of 255 octet
              for (byte[] context : new byte[][]{{}, "other".getBytes(),
              new byte[255], new byte[500]}) {
                  System.out.printf("Testing signature for name: %s, algorithm "
                          + "spec: (prehash:%s, context:%s)%n", name, preHash,
!                         Hex.encoder().encode(context));
                  try {
                      verify(sig, kp.getPublic(), MSG,
                              new EdDSAParameterSpec(preHash, context),
                              initParam, computedSig);
                  } catch (InvalidParameterException e) {

*** 217,12 ***
              // set through signature instance.
              if (!(equals(context, initContext) && equals(preHash, initPreHash))) {
                  throw new RuntimeException(String.format("Signature verification"
                          + " success with different param context(actual:%s, "
                          + "expected:%s), Prehash(actual:%s, expected:%s)",
!                         Convert.byteArrayToHexString(context),
!                         Convert.byteArrayToHexString(initContext),
                          preHash, initPreHash));
              } else {
                  System.out.println("Atleast a case matched");
              }
          }
--- 216,12 ---
              // set through signature instance.
              if (!(equals(context, initContext) && equals(preHash, initPreHash))) {
                  throw new RuntimeException(String.format("Signature verification"
                          + " success with different param context(actual:%s, "
                          + "expected:%s), Prehash(actual:%s, expected:%s)",
!                         Hex.encoder().encode(context),
!                         Hex.encoder().encode(initContext),
                          preHash, initPreHash));
              } else {
                  System.out.println("Atleast a case matched");
              }
          }

*** 251,12 ***
              return false;
          }
          boolean equals = Arrays.equals(actual, expected);
          if (!equals) {
              throw new RuntimeException(String.format("Actual array: %s, "
!                     + "Expected array:%s", Convert.byteArrayToHexString(actual),
!                     Convert.byteArrayToHexString(expected)));
          }
          return equals;
      }
  
      private static class InvalidPrivateKey implements PrivateKey {
--- 250,12 ---
              return false;
          }
          boolean equals = Arrays.equals(actual, expected);
          if (!equals) {
              throw new RuntimeException(String.format("Actual array: %s, "
!                     + "Expected array:%s", Hex.encoder().encode(actual),
!                     Hex.encoder().encode(expected)));
          }
          return equals;
      }
  
      private static class InvalidPrivateKey implements PrivateKey {
< prev index next >