Home | History | Annotate | Download | only in interfaces
      1 /*
      2  * Copyright (C) 2007 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  * http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package tests.security.interfaces;
     17 import java.math.BigInteger;
     18 import java.security.SecureRandomSpi;
     19 import java.security.spec.ECFieldFp;
     20 import java.security.spec.ECParameterSpec;
     21 import java.security.spec.ECPoint;
     22 import java.security.spec.EllipticCurve;
     23 import java.security.spec.RSAPrivateCrtKeySpec;
     24 
     25 /**
     26  * Utility class to provide some constants
     27  */
     28 class Util {
     29 
     30     /**
     31      * Valid P for DSA tests
     32      */
     33     static final BigInteger P = new BigInteger(
     34             "178479572281896551646004364479186243274554253442971675202712037168"
     35                     + "82805439171286757012622742273566628953929784385654859898"
     36                     + "28019943266498970695878014699423565775500281013661604573"
     37                     + "09351370942441879889477647669664876805999161358675121909"
     38                     + "02875461840550932624652402732307184862051812119809510467"
     39                     + "6997149499533466361");
     40 
     41     /**
     42      * Valid Q for DSA tests
     43      */
     44     static final BigInteger Q = new BigInteger(
     45             "764905408100544417452957057404815852894534709423");
     46 
     47     /**
     48      * Valid G for DSA tests
     49      */
     50     static final BigInteger G = new BigInteger(
     51             "250346303870482828530842176986393415513071912937041425322012361012"
     52                     + "16575725689706821855929265075265423817009497798948914793"
     53                     + "36272769721567876826949070538671438636626715308216064610"
     54                     + "91161573885991070984580607652541845127399865661520191726"
     55                     + "47818913386618968229835178446104566543814577436312685021"
     56                     + "713979414153557537");
     57 
     58     /**
     59      * Value returned using MySecureRandomSpi
     60      */
     61     static final BigInteger RND_RET = new BigInteger("10");
     62 
     63     /**
     64      * Valid RSA parameters
     65      */
     66     static final RSAPrivateCrtKeySpec rsaCrtParam = new RSAPrivateCrtKeySpec(
     67             BigInteger.valueOf(3233), BigInteger.valueOf(17),
     68             BigInteger.valueOf(2753), BigInteger.valueOf(61),
     69             BigInteger.valueOf(53), BigInteger.valueOf(53),
     70             BigInteger.valueOf(49), BigInteger.valueOf(52));
     71 
     72     /**
     73      * Valid EC parameters
     74      */
     75     static final ECParameterSpec ecParam = new ECParameterSpec(
     76             new EllipticCurve(
     77                     new ECFieldFp(BigInteger.valueOf(23)),
     78                     BigInteger.valueOf(5), BigInteger.valueOf(3)),
     79             new ECPoint(BigInteger.valueOf(1), BigInteger.valueOf(3)),
     80             BigInteger.valueOf(23), 1);
     81 
     82     private Util() {
     83     }
     84 }
     85 
     86 /**
     87  * Utility class to provide "random" data.
     88  * Returned value is always constant 10 if converted to BigInteger
     89  */
     90 @SuppressWarnings("serial")
     91 class MySecureRandomSpi extends SecureRandomSpi {
     92 
     93     @Override
     94     protected byte[] engineGenerateSeed(int arg0) {
     95         return null;
     96     }
     97 
     98     @Override
     99     protected void engineNextBytes(byte[] bytes) {
    100         java.util.Arrays.fill(bytes, (byte) 0);
    101         bytes[bytes.length - 1] = (byte) 10;
    102     }
    103 
    104     @Override
    105     protected void engineSetSeed(byte[] arg0) {
    106         return;
    107     }
    108 }
    109 
    110