test/micro/org/openjdk/bench/javax/crypto/full/CipherBench.java
author valeriep
Wed, 07 Aug 2019 20:46:28 +0000
changeset 57673 24f1a593dcd0
parent 53124 a22e41395bfa
permissions -rw-r--r--
8229214: Don't use GCM with PKCS5Padding in test/micro/org/openjdk/bench/javax/crypto/ Summary: update AESGCMBench.java and CipherBench.java accordingly Reviewed-by: xuelei, ecaspole
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
53124
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
     1
/*
57673
24f1a593dcd0 8229214: Don't use GCM with PKCS5Padding in test/micro/org/openjdk/bench/javax/crypto/
valeriep
parents: 53124
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
53124
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
     4
 *
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
     8
 *
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    13
 * accompanied this code).
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    14
 *
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    18
 *
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    21
 * questions.
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    22
 */
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    23
package org.openjdk.bench.javax.crypto.full;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    24
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    25
import org.openjdk.jmh.annotations.Benchmark;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    26
import org.openjdk.jmh.annotations.Param;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    27
import org.openjdk.jmh.annotations.Setup;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    28
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    29
import javax.crypto.*;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    30
import javax.crypto.spec.*;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    31
import java.security.*;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    32
import java.security.spec.*;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    33
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    34
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    35
public abstract class CipherBench extends CryptoBase {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    36
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    37
    @Param({})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    38
    private String permutation;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    39
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    40
    @Param({})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    41
    private String mode;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    42
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    43
    @Param({})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    44
    private String padding;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    45
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    46
    @Param({})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    47
    private int keyLength;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    48
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    49
    @Param({})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    50
    private int dataSize;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    51
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    52
    private int decryptCount = 0;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    53
    private byte[] data;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    54
    private byte[][] encryptedData = new byte[2][];
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    55
    private byte[] outBuffer;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    56
    private Cipher[] encryptCipher = new Cipher[2];
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    57
    private Cipher decryptCipher;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    58
    protected SecretKeySpec ks;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    59
    protected byte[] iv;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    60
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    61
    protected abstract int ivLength();
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    62
    protected abstract AlgorithmParameterSpec makeParameterSpec();
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    63
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    64
    protected void init(Cipher c, int mode, SecretKeySpec ks)
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    65
        throws GeneralSecurityException {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    66
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    67
        if (iv == null) {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    68
            iv = fillSecureRandom(new byte[ivLength()]);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    69
        }
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    70
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    71
        // toggle some bits in the IV to get around IV reuse defenses
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    72
        iv[0] ^= 0xFF;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    73
        AlgorithmParameterSpec paramSpec = makeParameterSpec();
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    74
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    75
        c.init(mode, ks, paramSpec);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    76
    }
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    77
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    78
    protected void init(Cipher c, int mode, SecretKeySpec ks, Cipher fromCipher)
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    79
        throws GeneralSecurityException {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    80
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    81
        AlgorithmParameters params = fromCipher.getParameters();
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    82
        c.init(mode, ks, fromCipher.getParameters());
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    83
    }
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    84
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    85
    @Setup
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    86
    public void setup() throws GeneralSecurityException {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    87
        setupProvider();
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    88
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    89
        String transform = permutation + "/" + mode + "/" + padding;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    90
        byte[] keystring = fillSecureRandom(new byte[keyLength / 8]);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    91
        ks = new SecretKeySpec(keystring, permutation);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    92
        data = fillRandom(new byte[dataSize]);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    93
        for (int i = 0; i < 2; i++) {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    94
            encryptCipher[i] = makeCipher(prov, transform);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    95
            init(encryptCipher[i], Cipher.ENCRYPT_MODE, ks);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    96
            encryptedData[i] = encryptCipher[i].doFinal(data);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    97
        }
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    98
        outBuffer = new byte[dataSize + 128]; // extra space for tag, etc
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
    99
        decryptCipher = makeCipher(prov, transform);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   100
    }
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   101
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   102
    @Benchmark
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   103
    public void encrypt() throws GeneralSecurityException {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   104
        init(encryptCipher[1], Cipher.ENCRYPT_MODE, ks);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   105
        encryptCipher[1].doFinal(data, 0, data.length, outBuffer);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   106
    }
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   107
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   108
    @Benchmark
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   109
    public void decrypt() throws GeneralSecurityException {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   110
        init(decryptCipher, Cipher.DECRYPT_MODE, ks,
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   111
            encryptCipher[decryptCount]);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   112
        decryptCipher.doFinal(encryptedData[decryptCount], 0,
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   113
            encryptedData[decryptCount].length, outBuffer);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   114
        decryptCount = (decryptCount + 1) % 2;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   115
    }
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   116
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   117
    public static class GCM extends CipherBench {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   118
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   119
        @Param({"AES"})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   120
        private String permutation;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   121
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   122
        @Param({"GCM"})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   123
        private String mode;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   124
57673
24f1a593dcd0 8229214: Don't use GCM with PKCS5Padding in test/micro/org/openjdk/bench/javax/crypto/
valeriep
parents: 53124
diff changeset
   125
        @Param({"NoPadding"})
53124
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   126
        private String padding;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   127
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   128
        @Param({"128", "256"})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   129
        private int keyLength;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   130
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   131
        @Param({"1024", "" + 16 * 1024})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   132
        private int dataSize;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   133
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   134
        protected int ivLength() {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   135
            return 32;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   136
        }
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   137
        protected AlgorithmParameterSpec makeParameterSpec() {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   138
            return new GCMParameterSpec(96, iv, 0, 16);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   139
        }
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   140
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   141
        private byte[] aad;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   142
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   143
        protected void init(Cipher c, int mode, SecretKeySpec ks)
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   144
            throws GeneralSecurityException {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   145
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   146
            if (aad == null) {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   147
                aad = fillSecureRandom(new byte[5]);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   148
            }
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   149
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   150
            super.init(c, mode, ks);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   151
            c.updateAAD(aad);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   152
        }
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   153
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   154
        protected void init(Cipher c, int mode, SecretKeySpec ks,
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   155
            Cipher fromCipher) throws GeneralSecurityException {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   156
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   157
            super.init(c, mode, ks, fromCipher);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   158
            c.updateAAD(aad);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   159
        }
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   160
    }
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   161
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   162
    public static class CTR extends CipherBench {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   163
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   164
        @Param({"AES"})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   165
        private String permutation;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   166
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   167
        @Param({"CTR"})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   168
        private String mode;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   169
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   170
        @Param({"NoPadding"})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   171
        private String padding;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   172
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   173
        @Param({"128", "256"})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   174
        private int keyLength;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   175
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   176
        @Param({"1024", "" + 16 * 1024})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   177
        private int dataSize;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   178
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   179
        protected int ivLength() {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   180
            return 16;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   181
        }
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   182
        protected AlgorithmParameterSpec makeParameterSpec() {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   183
            return new IvParameterSpec(iv);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   184
        }
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   185
    }
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   186
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   187
    public static class ChaCha20Poly1305 extends CipherBench {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   188
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   189
        @Param({"ChaCha20-Poly1305"})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   190
        private String permutation;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   191
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   192
        @Param({"None"})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   193
        private String mode;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   194
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   195
        @Param({"NoPadding"})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   196
        private String padding;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   197
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   198
        @Param({"256"})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   199
        private int keyLength;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   200
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   201
        @Param({"1024", "" + 16 * 1024})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   202
        private int dataSize;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   203
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   204
        protected int ivLength() {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   205
            return 12;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   206
        }
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   207
        protected AlgorithmParameterSpec makeParameterSpec() {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   208
            return new IvParameterSpec(iv);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   209
        }
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   210
    }
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   211
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   212
    public static class ChaCha20 extends CipherBench {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   213
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   214
        @Param({"ChaCha20"})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   215
        private String permutation;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   216
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   217
        @Param({"None"})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   218
        private String mode;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   219
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   220
        @Param({"NoPadding"})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   221
        private String padding;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   222
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   223
        @Param({"256"})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   224
        private int keyLength;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   225
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   226
        @Param({"1024", "" + 16 * 1024})
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   227
        private int dataSize;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   228
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   229
        protected int ivLength() {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   230
            return 12;
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   231
        }
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   232
        protected AlgorithmParameterSpec makeParameterSpec() {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   233
            return new ChaCha20ParameterSpec(iv, 0);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   234
        }
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   235
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   236
        protected void init(Cipher c, int mode, SecretKeySpec ks,
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   237
            Cipher fromCipher) throws GeneralSecurityException {
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   238
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   239
            AlgorithmParameterSpec paramSpec =
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   240
                new ChaCha20ParameterSpec(fromCipher.getIV(), 0);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   241
            c.init(mode, ks, paramSpec);
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   242
        }
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   243
    }
a22e41395bfa 8215643: Microbenchmarks for KeyAgreement and Cipher
apetcher
parents:
diff changeset
   244
}