Print this page
6799218 RSA using Solaris Kernel Crypto framework lagging behind OpenSSL
5016936 bignumimpl:big_mul: potential memory leak
6810280 panic from bignum module: vmem_xalloc(): size == 0

Split Close
Expand all
Collapse all
          --- old/usr/src/common/bignum/mont_mulf.c
          +++ new/usr/src/common/bignum/mont_mulf.c
   1    1  /*
   2    2   * CDDL HEADER START
   3    3   *
   4    4   * The contents of this file are subject to the terms of the
   5      - * Common Development and Distribution License, Version 1.0 only
   6      - * (the "License").  You may not use this file except in compliance
   7      - * with the License.
        5 + * Common Development and Distribution License (the "License").
        6 + * You may not use this file except in compliance with the License.
   8    7   *
   9    8   * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10    9   * or http://www.opensolaris.org/os/licensing.
  11   10   * See the License for the specific language governing permissions
  12   11   * and limitations under the License.
  13   12   *
  14   13   * When distributing Covered Code, include this CDDL HEADER in each
  15   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16   15   * If applicable, add the following below this CDDL HEADER, with the
  17   16   * fields enclosed by brackets "[]" replaced with your own identifying
  18   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  19   18   *
  20   19   * CDDL HEADER END
  21   20   */
  22   21  /*
  23      - * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
       22 + * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24   23   * Use is subject to license terms.
  25   24   */
  26   25  
  27      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  28      -
  29   26  /*
  30   27   * If compiled without -DRF_INLINE_MACROS then needs -lm at link time
  31   28   * If compiled with -DRF_INLINE_MACROS then needs conv.il at compile time
  32      - * (i.e. cc <compileer_flags> -DRF_INLINE_MACROS conv.il mont_mulf.c )
       29 + * (i.e. cc <compiler_flags> -DRF_INLINE_MACROS conv.il mont_mulf.c )
  33   30   */
  34   31  
  35   32  #include <sys/types.h>
  36   33  #include <math.h>
  37   34  
  38   35  static const double TwoTo16 = 65536.0;
  39   36  static const double TwoToMinus16 = 1.0/65536.0;
  40   37  static const double Zero = 0.0;
  41   38  static const double TwoTo32 = 65536.0 * 65536.0;
  42   39  static const double TwoToMinus32 = 1.0 / (65536.0 * 65536.0);
↓ open down ↓ 44 lines elided ↑ open up ↑
  87   84                  tmp = upper32(x);
  88   85                  tmp1 = upper32(x1);
  89   86          }
  90   87  }
  91   88  
  92   89  
  93   90  void
  94   91  conv_d16_to_i32(uint32_t *i32, double *d16, int64_t *tmp, int ilen)
  95   92  {
  96   93          int i;
  97      -        int64_t t, t1,          /* using int64_t and not uint64_t */
  98      -                a, b, c, d;     /* because more efficient code is */
       94 +        int64_t t, t1,          /* Using int64_t and not uint64_t */
       95 +            a, b, c, d;         /* because more efficient code is */
  99   96                                  /* generated this way, and there  */
 100      -                                /* is no overflow  */
       97 +                                /* is no overflow.  */
 101   98          t1 = 0;
 102   99          a = (int64_t)d16[0];
 103  100          b = (int64_t)d16[1];
 104  101          for (i = 0; i < ilen - 1; i++) {
 105  102                  c = (int64_t)d16[2 * i + 2];
 106  103                  t1 += a & 0xffffffff;
 107  104                  t = (a >> 32);
 108  105                  d = (int64_t)d16[2 * i + 3];
 109  106                  t1 += (b & 0xffff) << 16;
 110  107                  t += (b >> 16) + (t1 >> 32);
↓ open down ↓ 83 lines elided ↑ open up ↑
 194  191  
 195  192  void
 196  193  conv_i32_to_d32_and_d16(double *d32, double *d16, uint32_t *i32, int len)
 197  194  {
 198  195          int i;
 199  196          uint32_t a;
 200  197  
 201  198  #pragma pipeloop(0)
 202  199          for (i = 0; i < len - 3; i += 4) {
 203  200                  i16_to_d16_and_d32x4(&TwoToMinus16, &TwoTo16, &Zero,
 204      -                                        &(d16[2*i]), &(d32[i]),
 205      -                                        (float *)(&(i32[i])));
      201 +                    &(d16[2*i]), &(d32[i]), (float *)(&(i32[i])));
 206  202          }
 207  203          for (; i < len; i++) {
 208  204                  a = i32[i];
 209  205                  d32[i] = (double)(i32[i]);
 210  206                  d16[2 * i] = (double)(a & 0xffff);
 211  207                  d16[2 * i + 1] = (double)(a >> 16);
 212  208          }
 213  209  }
 214  210  
 215  211  
↓ open down ↓ 56 lines elided ↑ open up ↑
 272  268  #pragma pipeloop(0)
 273  269                          for (i = 1; i < nlen; i++) {
 274  270                                  pdtj[2 * i] += pdm1[i] * m2j + pdn[i] * digit;
 275  271                          }
 276  272                          if (jj == 30) {
 277  273                                  cleanup(dt, j / 2 + 1, 2 * nlen + 1);
 278  274                                  jj = 0;
 279  275                          }
 280  276  
 281  277                          digit = mod(lower32(b, Zero) * dn0,
 282      -                                    TwoToMinus16, TwoTo16);
      278 +                            TwoToMinus16, TwoTo16);
 283  279                  }
 284  280          } else {
 285  281                  a = dt[0] = pdm1[0] * pdm2[0];
 286  282  
 287  283                  dt[65] = dt[64] = dt[63] = dt[62] = dt[61] = dt[60] =
 288      -                        dt[59] = dt[58] = dt[57] = dt[56] = dt[55] =
 289      -                        dt[54] = dt[53] = dt[52] = dt[51] = dt[50] =
 290      -                        dt[49] = dt[48] = dt[47] = dt[46] = dt[45] =
 291      -                        dt[44] = dt[43] = dt[42] = dt[41] = dt[40] =
 292      -                        dt[39] = dt[38] = dt[37] = dt[36] = dt[35] =
 293      -                        dt[34] = dt[33] = dt[32] = dt[31] = dt[30] =
 294      -                        dt[29] = dt[28] = dt[27] = dt[26] = dt[25] =
 295      -                        dt[24] = dt[23] = dt[22] = dt[21] = dt[20] =
 296      -                        dt[19] = dt[18] = dt[17] = dt[16] = dt[15] =
 297      -                        dt[14] = dt[13] = dt[12] = dt[11] = dt[10] =
 298      -                        dt[9] = dt[8] = dt[7] = dt[6] = dt[5] = dt[4] =
 299      -                        dt[3] = dt[2] = dt[1] = Zero;
      284 +                    dt[59] = dt[58] = dt[57] = dt[56] = dt[55] =
      285 +                    dt[54] = dt[53] = dt[52] = dt[51] = dt[50] =
      286 +                    dt[49] = dt[48] = dt[47] = dt[46] = dt[45] =
      287 +                    dt[44] = dt[43] = dt[42] = dt[41] = dt[40] =
      288 +                    dt[39] = dt[38] = dt[37] = dt[36] = dt[35] =
      289 +                    dt[34] = dt[33] = dt[32] = dt[31] = dt[30] =
      290 +                    dt[29] = dt[28] = dt[27] = dt[26] = dt[25] =
      291 +                    dt[24] = dt[23] = dt[22] = dt[21] = dt[20] =
      292 +                    dt[19] = dt[18] = dt[17] = dt[16] = dt[15] =
      293 +                    dt[14] = dt[13] = dt[12] = dt[11] = dt[10] =
      294 +                    dt[9] = dt[8] = dt[7] = dt[6] = dt[5] = dt[4] =
      295 +                    dt[3] = dt[2] = dt[1] = Zero;
 300  296  
 301  297                  pdn_0 = pdn[0];
 302  298                  pdm1_0 = pdm1[0];
 303  299  
 304  300                  digit = mod(lower32(a, Zero) * dn0, TwoToMinus16, TwoTo16);
 305  301                  pdtj = &(dt[0]);
 306  302  
 307  303                  for (j = 0; j < 32; j++, pdtj++) {
 308  304  
 309  305                          m2j = pdm2[j];
↓ open down ↓ 9 lines elided ↑ open up ↑
 319  315                          pdtj[12] += pdm1[6] *m2j + pdn[6] * digit;
 320  316                          pdtj[14] += pdm1[7] *m2j + pdn[7] * digit;
 321  317                          pdtj[16] += pdm1[8] *m2j + pdn[8] * digit;
 322  318                          pdtj[18] += pdm1[9] *m2j + pdn[9] * digit;
 323  319                          pdtj[20] += pdm1[10] *m2j + pdn[10] * digit;
 324  320                          pdtj[22] += pdm1[11] *m2j + pdn[11] * digit;
 325  321                          pdtj[24] += pdm1[12] *m2j + pdn[12] * digit;
 326  322                          pdtj[26] += pdm1[13] *m2j + pdn[13] * digit;
 327  323                          pdtj[28] += pdm1[14] *m2j + pdn[14] * digit;
 328  324                          pdtj[30] += pdm1[15] *m2j + pdn[15] * digit;
 329      -                        /* no need for cleenup, cannot overflow */
      325 +                        /* no need for cleanup, cannot overflow */
 330  326                          digit = mod(lower32(b, Zero) * dn0,
 331      -                                    TwoToMinus16, TwoTo16);
      327 +                            TwoToMinus16, TwoTo16);
 332  328                  }
 333  329          }
 334  330  
 335  331          conv_d16_to_i32(result, dt + 2 * nlen, (int64_t *)dt, nlen + 1);
 336  332          adjust_montf_result(result, nint, nlen);
 337  333  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX