test/jdk/sun/security/tools/keytool/fakegen/java.base/sun/security/provider/DSAKeyPairGenerator.java
changeset 55640 3081f39a3d30
equal deleted inserted replaced
55639:4722e5e28449 55640:3081f39a3d30
       
     1 /*
       
     2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * 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  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 package sun.security.provider;
       
    25 
       
    26 import java.math.BigInteger;
       
    27 
       
    28 import java.security.*;
       
    29 import java.security.SecureRandom;
       
    30 import java.security.spec.AlgorithmParameterSpec;
       
    31 
       
    32 /**
       
    33  * A fake DSA key pair generator
       
    34  */
       
    35 class DSAKeyPairGenerator extends KeyPairGenerator {
       
    36 
       
    37     private int plen;
       
    38 
       
    39     DSAKeyPairGenerator(int defaultKeySize) {
       
    40         super("DSA");
       
    41         this.plen = defaultKeySize;
       
    42     }
       
    43 
       
    44     public void initialize(int modlen, SecureRandom random) {
       
    45         this.plen = modlen;
       
    46     }
       
    47 
       
    48     public void initialize(AlgorithmParameterSpec params, SecureRandom random) {
       
    49         throw new UnsupportedOperationException();
       
    50     }
       
    51 
       
    52     public KeyPair generateKeyPair() {
       
    53         BigInteger p, q, g, x, y;
       
    54         switch (plen) {
       
    55             case 1024:
       
    56                 p = new BigInteger("178011905478542266528237562450159990145232"
       
    57                         + "156369120674273274450314442865788737020770612695252"
       
    58                         + "123463079567156784778466449970650770920727857050009"
       
    59                         + "668388144034129745221171818506047231150039301079959"
       
    60                         + "358067395348717066319802262019714966524135060945913"
       
    61                         + "707594956514672855690606794135837542707371727429551"
       
    62                         + "343320695239");
       
    63                 q = new BigInteger("864205495604807476120572616017955259175325"
       
    64                         + "408501");
       
    65                 g = new BigInteger("174068207532402095185811980123523436538604"
       
    66                         + "490794561350978495831040599953488455823147851597408"
       
    67                         + "940950725307797094915759492368300574252438761037084"
       
    68                         + "473467180148876118103083043754985190983472601550494"
       
    69                         + "691329488083395492313850000361646482644608492304078"
       
    70                         + "721818959999056496097769368017749273708962006689187"
       
    71                         + "956744210730");
       
    72                 x = new BigInteger("442684721233431748836258763370873041965448"
       
    73                         + "305045");
       
    74                 y = new BigInteger("123777377875361061959303516913138943002334"
       
    75                         + "907914087825062123737715425120688699041350157178201"
       
    76                         + "400875613890444051801751930684745642628053940339973"
       
    77                         + "838660880918443284038995141330502246221730915504106"
       
    78                         + "313025753680709037893119973285385498869618080832350"
       
    79                         + "844717549458284541384384444940685082987448444197127"
       
    80                         + "109727215326");
       
    81                 break;
       
    82             case 3072:
       
    83                 p = new BigInteger("532424770282957507167558442446475365039221"
       
    84                         + "865310725601984444684810811113744209961033785957055"
       
    85                         + "545569814329215072178264469737927701168579964248618"
       
    86                         + "212671015750272795670312875451455848633455356647610"
       
    87                         + "802537682630581977793580392148938495801039643027210"
       
    88                         + "168055234243089546290868853109011307872303192870862"
       
    89                         + "928522910714047973751079687063489704904165319118754"
       
    90                         + "414656318529199596549052269402875554159175957058778"
       
    91                         + "440558421673575502884909440510567191072050738584727"
       
    92                         + "120524174557883883057055053123583287619621138916493"
       
    93                         + "103747092870334536468061850120264153241617645557971"
       
    94                         + "369719361654590867807897284715299844320510777830158"
       
    95                         + "726099043158186232574541934847234927190558272654504"
       
    96                         + "899757279197741136733127726856995584055651857157703"
       
    97                         + "730144527174175430693903863066052387871964460507889"
       
    98                         + "647358151911550149297202134918108185581732063173116"
       
    99                         + "923323722454275514471399056679497166381315291238166"
       
   100                         + "678637058042047687405023560967657729197010282296512"
       
   101                         + "1019243318222397");
       
   102                 q = new BigInteger("890750162030504407723769200757822201430799"
       
   103                         + "34855896740921457815099167207156753");
       
   104                 g = new BigInteger("151817606774376623890824510431247991418389"
       
   105                         + "715779225250508738780526725946562383344295250350988"
       
   106                         + "771843988677909140611473778208677098146023000408394"
       
   107                         + "159085130929460916510001933636711147155614261913281"
       
   108                         + "024881629605746742555704817858764668833915862917006"
       
   109                         + "598838541275997577579609978297421111961935816027196"
       
   110                         + "483840098753346970227821715342000582711792748060856"
       
   111                         + "726896896804543780217869880654497603605897208724113"
       
   112                         + "159746510357451233393865294043543249227656881945445"
       
   113                         + "911394836487973565655780621125471620102365417701222"
       
   114                         + "942700788591992318925980959657031578942777920589286"
       
   115                         + "616050851348109471636081284309144953091734152913609"
       
   116                         + "446411782660994503265873790796828974300693496175976"
       
   117                         + "687169380996928285288177682058646187108156643041984"
       
   118                         + "849723272840833108573298006600021948389582796433112"
       
   119                         + "947515654733901137745000270350091408182905439114222"
       
   120                         + "789179830877253611946986888461931792357280552721443"
       
   121                         + "254779196196933589018709692301251250169609249601817"
       
   122                         + "4795480503442737");
       
   123                 x = new BigInteger("837184725379267020693579006510066460977336"
       
   124                         + "11851797067505263114214549968402803");
       
   125                 y = new BigInteger("395340495486576955293430186860596538887519"
       
   126                         + "532234445217156133155957480616804094258448364164620"
       
   127                         + "019669119585215430588435624960233328621409901309332"
       
   128                         + "192899527076171337665680476899693664056285881110265"
       
   129                         + "747619109873269836751712303602309960796986216520795"
       
   130                         + "801714761851172570535758859846766099312622783018124"
       
   131                         + "479033035974495130498276693342256396509951099944860"
       
   132                         + "886247767918456849069941054372775951688384599525157"
       
   133                         + "707186634084399395289878437457318095050730531728857"
       
   134                         + "772445883395712924633196197942869159234956079072812"
       
   135                         + "033713932103618702222793066673087288841096282175640"
       
   136                         + "243353943285718935517693389945339235110435667386410"
       
   137                         + "827568246083609394541667076709869892137539964277111"
       
   138                         + "881671381034966060604088870102183420000265271778711"
       
   139                         + "380501229707440889595235145225482336904915838699846"
       
   140                         + "941323450568220944649213026904670943083185766542427"
       
   141                         + "196471392765688014947830444837953042683779059773143"
       
   142                         + "877079141940001705246446188097009313372159366032655"
       
   143                         + "5436444354063312");
       
   144                 break;
       
   145             default:
       
   146                 throw new AssertionError("Unknown keySize " + plen);
       
   147         }
       
   148 
       
   149         try {
       
   150             return new KeyPair(new DSAPublicKeyImpl(y, p, q, g),
       
   151                     new DSAPrivateKey(x, p, q, g));
       
   152         } catch (InvalidKeyException e) {
       
   153             throw new ProviderException(e);
       
   154         }
       
   155     }
       
   156 }