jdk/test/com/sun/crypto/provider/Cipher/AES/TestGHASH.java
changeset 31462 1d0b519af651
parent 28851 e4c16ed7bffa
child 35315 67dcc46f8241
equal deleted inserted replaced
31254:210db13e7ead 31462:1d0b519af651
     1 /*
     1 /*
     2  * Copyright (c) 2015, Red Hat, Inc.
     2  * Copyright (c) 2015, Red Hat, Inc.
       
     3  * Copyright (c) 2015, Oracle, Inc.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  * published by the Free Software Foundation.
    22  */
    23  */
    23 
    24 
    24 /*
    25 /*
    25  * @test
    26  * @test
    26  * @bug 8069072
    27  * @bug 8069072
    27  * @summary Test vectors for com.sun.crypto.provider.GHASH
    28  * @summary Test vectors for com.sun.crypto.provider.GHASH.
       
    29  *
       
    30  * Single iteration to verify software-only GHASH algorithm.
       
    31  * @run main TestGHASH
       
    32  *
       
    33  * Multi-iteration to verify test intrinsics GHASH, if available.
       
    34  * Many iterations are needed so we are sure hotspot will use intrinsic
       
    35  * @run main TestGHASH -n 10000
    28  */
    36  */
    29 import java.lang.reflect.Constructor;
    37 import java.lang.reflect.Constructor;
    30 import java.lang.reflect.Method;
    38 import java.lang.reflect.Method;
    31 import java.nio.ByteBuffer;
    39 import java.nio.ByteBuffer;
    32 
    40 
   122         }
   130         }
   123     }
   131     }
   124 
   132 
   125     public static void main(String[] args) throws Exception {
   133     public static void main(String[] args) throws Exception {
   126         TestGHASH test;
   134         TestGHASH test;
   127         if (args.length == 0) {
   135         String test_class = "com.sun.crypto.provider.GHASH";
   128             test = new TestGHASH("com.sun.crypto.provider.GHASH");
   136         int i = 0;
   129         } else {
   137         int num_of_loops = 1;
   130             test = new TestGHASH(args[0]);
   138         while (args.length > i) {
       
   139             if (args[i].compareTo("-c") == 0) {
       
   140                 test_class = args[++i];
       
   141             } else if (args[i].compareTo("-n") == 0) {
       
   142                 num_of_loops = Integer.parseInt(args[++i]);
       
   143             }
       
   144             i++;
   131         }
   145         }
   132 
   146 
   133         // Test vectors from David A. McGrew, John Viega,
   147         System.out.println("Running " + num_of_loops + " iterations.");
   134         // "The Galois/Counter Mode of Operation (GCM)", 2005.
   148         test = new TestGHASH(test_class);
   135         // <http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-revised-spec.pdf>
   149         i = 0;
   136 
   150 
   137         test.check(1, "66e94bd4ef8a2c3b884cfa59ca342b2e", "", "",
   151         while (num_of_loops > i) {
   138                 "00000000000000000000000000000000");
   152             // Test vectors from David A. McGrew, John Viega,
   139         test.check(2,
   153             // "The Galois/Counter Mode of Operation (GCM)", 2005.
   140                 "66e94bd4ef8a2c3b884cfa59ca342b2e", "",
   154             // <http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-revised-spec.pdf>
   141                 "0388dace60b6a392f328c2b971b2fe78",
   155             test.check(1, "66e94bd4ef8a2c3b884cfa59ca342b2e", "", "",
   142                 "f38cbb1ad69223dcc3457ae5b6b0f885");
   156                        "00000000000000000000000000000000");
   143         test.check(3,
   157             test.check(2,
   144                 "b83b533708bf535d0aa6e52980d53b78", "",
   158                        "66e94bd4ef8a2c3b884cfa59ca342b2e", "",
   145                 "42831ec2217774244b7221b784d0d49c" +
   159                        "0388dace60b6a392f328c2b971b2fe78",
   146                 "e3aa212f2c02a4e035c17e2329aca12e" +
   160                        "f38cbb1ad69223dcc3457ae5b6b0f885");
   147                 "21d514b25466931c7d8f6a5aac84aa05" +
   161             test.check(3,
   148                 "1ba30b396a0aac973d58e091473f5985",
   162                        "b83b533708bf535d0aa6e52980d53b78", "",
   149                 "7f1b32b81b820d02614f8895ac1d4eac");
   163                        "42831ec2217774244b7221b784d0d49c" +
   150         test.check(4,
   164                        "e3aa212f2c02a4e035c17e2329aca12e" +
   151                 "b83b533708bf535d0aa6e52980d53b78",
   165                        "21d514b25466931c7d8f6a5aac84aa05" +
   152                 "feedfacedeadbeeffeedfacedeadbeef" + "abaddad2",
   166                        "1ba30b396a0aac973d58e091473f5985",
   153                 "42831ec2217774244b7221b784d0d49c" +
   167                        "7f1b32b81b820d02614f8895ac1d4eac");
   154                 "e3aa212f2c02a4e035c17e2329aca12e" +
   168             test.check(4,
   155                 "21d514b25466931c7d8f6a5aac84aa05" +
   169                        "b83b533708bf535d0aa6e52980d53b78",
   156                 "1ba30b396a0aac973d58e091",
   170                        "feedfacedeadbeeffeedfacedeadbeef" + "abaddad2",
   157                 "698e57f70e6ecc7fd9463b7260a9ae5f");
   171                        "42831ec2217774244b7221b784d0d49c" +
   158         test.check(5, "b83b533708bf535d0aa6e52980d53b78",
   172                        "e3aa212f2c02a4e035c17e2329aca12e" +
   159                 "feedfacedeadbeeffeedfacedeadbeef" + "abaddad2",
   173                        "21d514b25466931c7d8f6a5aac84aa05" +
   160                 "61353b4c2806934a777ff51fa22a4755" +
   174                        "1ba30b396a0aac973d58e091",
   161                 "699b2a714fcdc6f83766e5f97b6c7423" +
   175                        "698e57f70e6ecc7fd9463b7260a9ae5f");
   162                 "73806900e49f24b22b097544d4896b42" +
   176             test.check(5, "b83b533708bf535d0aa6e52980d53b78",
   163                 "4989b5e1ebac0f07c23f4598",
   177                        "feedfacedeadbeeffeedfacedeadbeef" + "abaddad2",
   164                 "df586bb4c249b92cb6922877e444d37b");
   178                        "61353b4c2806934a777ff51fa22a4755" +
       
   179                        "699b2a714fcdc6f83766e5f97b6c7423" +
       
   180                        "73806900e49f24b22b097544d4896b42" +
       
   181                        "4989b5e1ebac0f07c23f4598",
       
   182                        "df586bb4c249b92cb6922877e444d37b");
       
   183             i++;
       
   184         }
   165     }
   185     }
   166 }
   186 }