~ubuntu-branches/ubuntu/precise/classpath/precise

« back to all changes in this revision

Viewing changes to gnu/javax/crypto/key/srp6/SRPAlgorithm.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2006-05-27 16:11:15 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060527161115-h6e39eposdt5snb6
Tags: 2:0.91-3
* Install header files to /usr/include/classpath.
* debian/control: classpath: Conflict with jamvm < 1.4.3 and
  cacao < 0.96 (Closes: #368172).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* SRPAlgorithm.java -- 
 
2
   Copyright (C) 2003, 2006 Free Software Foundation, Inc.
 
3
 
 
4
This file is a part of GNU Classpath.
 
5
 
 
6
GNU Classpath is free software; you can redistribute it and/or modify
 
7
it under the terms of the GNU General Public License as published by
 
8
the Free Software Foundation; either version 2 of the License, or (at
 
9
your option) any later version.
 
10
 
 
11
GNU Classpath is distributed in the hope that it will be useful, but
 
12
WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
General Public License for more details.
 
15
 
 
16
You should have received a copy of the GNU General Public License
 
17
along with GNU Classpath; if not, write to the Free Software
 
18
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
 
19
USA
 
20
 
 
21
Linking this library statically or dynamically with other modules is
 
22
making a combined work based on this library.  Thus, the terms and
 
23
conditions of the GNU General Public License cover the whole
 
24
combination.
 
25
 
 
26
As a special exception, the copyright holders of this library give you
 
27
permission to link this library with independent modules to produce an
 
28
executable, regardless of the license terms of these independent
 
29
modules, and to copy and distribute the resulting executable under
 
30
terms of your choice, provided that you also meet, for each linked
 
31
independent module, the terms and conditions of the license of that
 
32
module.  An independent module is a module which is not derived from
 
33
or based on this library.  If you modify this library, you may extend
 
34
this exception to your version of the library, but you are not
 
35
obligated to do so.  If you do not wish to do so, delete this
 
36
exception statement from your version.  */
 
37
 
 
38
 
 
39
package gnu.javax.crypto.key.srp6;
 
40
 
 
41
import gnu.java.security.util.Prime2;
 
42
import gnu.javax.crypto.sasl.srp.SRPRegistry;
 
43
 
 
44
import java.math.BigInteger;
 
45
 
 
46
/**
 
47
 * <p>Utilities for use with SRP-6 based methods and protocols.</p>
 
48
 *
 
49
 * <p>Reference:</p>
 
50
 * <ol>
 
51
 *    <li><a href="http://srp.stanford.edu/design.html">SRP Protocol Design</a><br>
 
52
 *    Thomas J. Wu.</li>
 
53
 * </ol>
 
54
 */
 
55
public class SRPAlgorithm
 
56
{
 
57
 
 
58
  // Constants and variables
 
59
  // -------------------------------------------------------------------------
 
60
 
 
61
  // lifted from draft-burdis-cat-srp-sasl-09
 
62
  public static final BigInteger N_2048 = new BigInteger(
 
63
                                                         "AC6BDB41324A9A9BF166DE5E1389582FAF72B6651987EE07FC3192943DB56050"
 
64
                                                             + "A37329CBB4A099ED8193E0757767A13DD52312AB4B03310DCD7F48A9DA04FD50"
 
65
                                                             + "E8083969EDB767B0CF6095179A163AB3661A05FBD5FAAAE82918A9962F0B93B8"
 
66
                                                             + "55F97993EC975EEAA80D740ADBF4FF747359D041D5C33EA71D281E446B14773B"
 
67
                                                             + "CA97B43A23FB801676BD207A436C6481F1D2B9078717461A5B9D32E688F87748"
 
68
                                                             + "544523B524B0D57D5EA77A2775D2ECFA032CFBDBF52FB3786160279004E57AE6"
 
69
                                                             + "AF874E7303CE53299CCC041C7BC308D82A5698F3A8D0C38271AE35F8E9DBFBB6"
 
70
                                                             + "94B5C803D89F7AE435DE236D525F54759B65E372FCD68EF20FA7111F9E4AFF73",
 
71
                                                         16);
 
72
 
 
73
  public static final BigInteger N_1536 = new BigInteger(
 
74
                                                         "9DEF3CAFB939277AB1F12A8617A47BBBDBA51DF499AC4C80BEEEA9614B19CC4D"
 
75
                                                             + "5F4F5F556E27CBDE51C6A94BE4607A291558903BA0D0F84380B655BB9A22E8DC"
 
76
                                                             + "DF028A7CEC67F0D08134B1C8B97989149B609E0BE3BAB63D47548381DBC5B1FC"
 
77
                                                             + "764E3F4B53DD9DA1158BFD3E2B9C8CF56EDF019539349627DB2FD53D24B7C486"
 
78
                                                             + "65772E437D6C7F8CE442734AF7CCB7AE837C264AE3A9BEB87F8A2FE9B8B5292E"
 
79
                                                             + "5A021FFF5E91479E8CE7A28C2442C6F315180F93499A234DCF76E3FED135F9BB",
 
80
                                                         16);
 
81
 
 
82
  public static final BigInteger N_1280 = new BigInteger(
 
83
                                                         "D77946826E811914B39401D56A0A7843A8E7575D738C672A090AB1187D690DC4"
 
84
                                                             + "3872FC06A7B6A43F3B95BEAEC7DF04B9D242EBDC481111283216CE816E004B78"
 
85
                                                             + "6C5FCE856780D41837D95AD787A50BBE90BD3A9C98AC0F5FC0DE744B1CDE1891"
 
86
                                                             + "690894BC1F65E00DE15B4B2AA6D87100C9ECC2527E45EB849DEB14BB2049B163"
 
87
                                                             + "EA04187FD27C1BD9C7958CD40CE7067A9C024F9B7C5A0B4F5003686161F0605B",
 
88
                                                         16);
 
89
 
 
90
  public static final BigInteger N_1024 = new BigInteger(
 
91
                                                         "EEAF0AB9ADB38DD69C33F80AFA8FC5E86072618775FF3C0B9EA2314C9C256576"
 
92
                                                             + "D674DF7496EA81D3383B4813D692C6E0E0D5D8E250B98BE48E495C1D6089DAD1"
 
93
                                                             + "5DC7D7B46154D6B6CE8EF4AD69B15D4982559B297BCF1885C529F566660E57EC"
 
94
                                                             + "68EDBC3C05726CC02FD4CBF4976EAA9AFD5138FE8376435B9FC61D2FC0EB06E3",
 
95
                                                         16);
 
96
 
 
97
  public static final BigInteger N_768 = new BigInteger(
 
98
                                                        "B344C7C4F8C495031BB4E04FF8F84EE95008163940B9558276744D91F7CC9F40"
 
99
                                                            + "2653BE7147F00F576B93754BCDDF71B636F2099E6FFF90E79575F3D0DE694AFF"
 
100
                                                            + "737D9BE9713CEF8D837ADA6380B1093E94B6A529A8C6C2BE33E0867C60C3262B",
 
101
                                                        16);
 
102
 
 
103
  public static final BigInteger N_640 = new BigInteger(
 
104
                                                        "C94D67EB5B1A2346E8AB422FC6A0EDAEDA8C7F894C9EEEC42F9ED250FD7F0046"
 
105
                                                            + "E5AF2CF73D6B2FA26BB08033DA4DE322E144E7A8E9B12A0E4637F6371F34A207"
 
106
                                                            + "1C4B3836CBEEAB15034460FAA7ADF483",
 
107
                                                        16);
 
108
 
 
109
  public static final BigInteger N_512 = new BigInteger(
 
110
                                                        "D4C7F8A2B32C11B8FBA9581EC4BA4F1B04215642EF7355E37C0FC0443EF756EA"
 
111
                                                            + "2C6B8EEB755A1C723027663CAA265EF785B8FF6A9B35227A52D86633DBDFCA43",
 
112
                                                        16);
 
113
 
 
114
  public static final BigInteger N_384 = new BigInteger(
 
115
                                                        "8025363296FB943FCE54BE717E0E2958A02A9672EF561953B2BAA3BAACC3ED57"
 
116
                                                            + "54EB764C7AB7184578C57D5949CCB41B",
 
117
                                                        16);
 
118
 
 
119
  public static final BigInteger N_264 = new BigInteger(
 
120
                                                        "115B8B692E0E045692CF280B436735C77A5A9E8A9E7ED56C965F87DB5B2A2ECE3",
 
121
                                                        16);
 
122
 
 
123
  private static final BigInteger ZERO = BigInteger.ZERO;
 
124
 
 
125
  private static final BigInteger ONE = BigInteger.ONE;
 
126
 
 
127
  private static final BigInteger TWO = BigInteger.valueOf(2L);
 
128
 
 
129
  // Constructor(s)
 
130
  // -------------------------------------------------------------------------
 
131
 
 
132
  /** Trivial constructor to enforce usage through class methods. */
 
133
  private SRPAlgorithm()
 
134
  {
 
135
    super();
 
136
  }
 
137
 
 
138
  // Class methods
 
139
  // -------------------------------------------------------------------------
 
140
 
 
141
  public static void checkParams(final BigInteger N, final BigInteger g)
 
142
  {
 
143
    // 1. N should be at least 512-bit long
 
144
    final int blen = N.bitLength();
 
145
    if (blen < SRPRegistry.MINIMUM_MODULUS_BITLENGTH)
 
146
      {
 
147
        throw new IllegalArgumentException(
 
148
                                           "Bit length of N ("
 
149
                                               + blen
 
150
                                               + ") is too low. Should be at least "
 
151
                                               + SRPRegistry.MINIMUM_MODULUS_BITLENGTH);
 
152
      }
 
153
    // 2. N should be a prime
 
154
    if (!Prime2.passEulerCriterion(N))
 
155
      {
 
156
        throw new IllegalArgumentException("N should be prime but isn't");
 
157
      }
 
158
    // 3. N should be of the form 2*q + 1, where q is prime
 
159
    final BigInteger q = N.subtract(ONE).divide(TWO);
 
160
    if (!Prime2.passEulerCriterion(q))
 
161
      {
 
162
        throw new IllegalArgumentException("(N-1)/2 should be prime but isn't");
 
163
      }
 
164
    // 4. g**q should be -1 mod N
 
165
    final BigInteger gq = g.modPow(q, N).add(ONE).mod(N);
 
166
    if (gq.compareTo(ZERO) != 0)
 
167
      {
 
168
        throw new IllegalArgumentException(
 
169
                                           "g**q should be -1 (mod N) but isn't");
 
170
      }
 
171
  }
 
172
 
 
173
  // Instance methods
 
174
  // -------------------------------------------------------------------------
 
175
}