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/amd64/bignum_amd64_asm.s
          +++ new/usr/src/common/bignum/amd64/bignum_amd64_asm.s
   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 2004 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  #include <sys/asm_linkage.h>
  30   27  
  31   28  #if defined(lint) || defined(__lint)
  32   29  
  33   30  #include <sys/types.h>
  34   31  
  35   32  /* ARGSUSED */
  36   33  uint64_t
  37      -big_mul_set_vec64(uint64_t *r, uint64_t *a, int len, uint64_t digit)
       34 +big_mul_set_vec(uint64_t *r, uint64_t *a, int len, uint64_t digit)
  38   35  { return (0); }
  39   36  
  40   37  /* ARGSUSED */
  41   38  uint64_t
  42      -big_mul_add_vec64(uint64_t *r, uint64_t *a, int len, uint64_t digit)
       39 +big_mul_add_vec(uint64_t *r, uint64_t *a, int len, uint64_t digit)
  43   40  { return (0); }
  44   41  
  45   42  /* ARGSUSED */
  46   43  void
  47      -big_sqr_vec64(uint64_t *r, uint64_t *a, int len)
       44 +big_sqr_vec(uint64_t *r, uint64_t *a, int len)
  48   45  {}
  49   46  
  50   47  #else   /* lint */
  51   48  
  52   49  / ------------------------------------------------------------------------
  53   50  /
  54   51  /  Implementation of big_mul_set_vec which exploits
  55   52  /  the 64X64->128 bit  unsigned multiply instruction.
  56   53  /
  57   54  /  As defined in Sun's bignum library for pkcs11, bignums are
  58      -/  composed of an array of 32-bit "digits" along with descriptive
  59      -/  information.  The arrays of digits are only required to be
  60      -/  aligned on 32-bit boundary.  This implementation works only
  61      -/  when the two factors and the result happen to be 64 bit aligned
  62      -/  and have an even number of digits.
       55 +/  composed of an array of 64-bit "digits" or "chunks" along with
       56 +/  descriptive information.
  63   57  /
  64   58  / ------------------------------------------------------------------------
  65   59  
  66   60  / r = a * digit, r and a are vectors of length len
  67   61  / returns the carry digit
  68   62  / r and a are 64 bit aligned.
  69   63  /
  70   64  / uint64_t
  71      -/ big_mul_set_vec64(uint64_t *r, uint64_t *a, int len, uint64_t digit)
       65 +/ big_mul_set_vec(uint64_t *r, uint64_t *a, int len, uint64_t digit)
  72   66  /
  73      -        ENTRY(big_mul_set_vec64)
       67 +        ENTRY(big_mul_set_vec)
  74   68          xorq    %rax, %rax              / if (len == 0) return (0)
  75   69          testq   %rdx, %rdx
  76   70          jz      .L17
  77   71  
  78   72          movq    %rdx, %r8               / Use r8 for len; %rdx is used by mul
  79   73          xorq    %r9, %r9                / cy = 0
  80   74  
  81   75  .L15:
  82   76          cmpq    $8, %r8                 / 8 - len
  83   77          jb      .L16
↓ open down ↓ 128 lines elided ↑ open up ↑
 212  206          adcq    $0, %rdx                / p += cy
 213  207          movq    %rax, 48(%rdi)          / r[6] = lo(p)
 214  208          movq    %rdx, %r9               / cy = hi(p)
 215  209          decq    %r8
 216  210          jz      .L17
 217  211  
 218  212  
 219  213  .L17:
 220  214          movq    %r9, %rax
 221  215          ret
 222      -        SET_SIZE(big_mul_set_vec64)
      216 +        SET_SIZE(big_mul_set_vec)
 223  217  
      218 +
 224  219  / ------------------------------------------------------------------------
 225  220  /
 226  221  /  Implementation of big_mul_add_vec which exploits
 227  222  /  the 64X64->128 bit  unsigned multiply instruction.
 228  223  /
 229  224  /  As defined in Sun's bignum library for pkcs11, bignums are
 230      -/  composed of an array of 32-bit "digits" along with descriptive
 231      -/  information.  The arrays of digits are only required to be
 232      -/  aligned on 32-bit boundary.  This implementation works only
 233      -/  when the two factors and the result happen to be 64 bit aligned
 234      -/  and have an even number of digits.
      225 +/  composed of an array of 64-bit "digits" or "chunks" along with
      226 +/  descriptive information.
 235  227  /
 236  228  / ------------------------------------------------------------------------
 237  229  
 238  230  / r += a * digit, r and a are vectors of length len
 239  231  / returns the carry digit
 240  232  / r and a are 64 bit aligned.
 241  233  /
 242  234  / uint64_t
 243      -/ big_mul_add_vec64(uint64_t *r, uint64_t *a, int len, uint64_t digit)
      235 +/ big_mul_add_vec(uint64_t *r, uint64_t *a, int len, uint64_t digit)
 244  236  /
 245      -        ENTRY(big_mul_add_vec64)
      237 +        ENTRY(big_mul_add_vec)
 246  238          xorq    %rax, %rax              / if (len == 0) return (0)
 247  239          testq   %rdx, %rdx
 248  240          jz      .L27
 249  241  
 250  242          movq    %rdx, %r8               / Use r8 for len; %rdx is used by mul
 251  243          xorq    %r9, %r9                / cy = 0
 252  244  
 253  245  .L25:
 254  246          cmpq    $8, %r8                 / 8 - len
 255  247          jb      .L26
↓ open down ↓ 173 lines elided ↑ open up ↑
 429  421          adcq    $0, %rdx                / p += cy
 430  422          movq    %rax, 48(%rdi)          / r[6] = lo(p)
 431  423          movq    %rdx, %r9               / cy = hi(p)
 432  424          decq    %r8
 433  425          jz      .L27
 434  426  
 435  427  
 436  428  .L27:
 437  429          movq    %r9, %rax
 438  430          ret
 439      -        SET_SIZE(big_mul_add_vec64)
      431 +        SET_SIZE(big_mul_add_vec)
 440  432  
 441  433  
 442  434  / void
 443      -/ big_sqr_vec64(uint64_t *r, uint64_t *a, int len)
      435 +/ big_sqr_vec(uint64_t *r, uint64_t *a, int len)
 444  436  
 445      -        ENTRY(big_sqr_vec64)
      437 +        ENTRY(big_sqr_vec)
 446  438          pushq   %rbx
 447  439          pushq   %rbp
 448  440          pushq   %r12
 449  441          pushq   %r13
 450  442          pushq   %r14
 451  443          pushq   %r15
 452  444          pushq   %rdx                    / save arg3, len
 453  445          pushq   %rsi                    / save arg2, a
 454  446          pushq   %rdi                    / save arg1, r
 455  447  
 456  448          leaq    8(%rdi), %r13           / tr = r + 1
 457  449          movq    %rsi, %r14              / ta = a
 458  450          movq    %rdx, %r15              / tlen = len
 459  451          decq    %r15                    / tlen = len - 1
 460  452          movq    %r13, %rdi              / arg1 = tr
 461  453          leaq    8(%r14), %rsi           / arg2 = ta + 1
 462  454          movq    %r15, %rdx              / arg3 = tlen
 463  455          movq    0(%r14), %rcx           / arg4 = ta[0]
 464      -        call    big_mul_set_vec64
      456 +        call    big_mul_set_vec
 465  457          movq    %rax, 0(%r13, %r15, 8)  / tr[tlen] = cy
 466  458  .L31:
 467  459          decq    %r15                    / --tlen
 468  460          jz      .L32                    / while (--tlen != 0)
 469  461  
 470  462          addq    $16, %r13               / tr += 2
 471  463          addq    $8, %r14                / ++ta
 472  464          movq    %r13, %rdi              / arg1 = tr
 473  465          leaq    8(%r14), %rsi           / arg2 = ta + 1
 474  466          movq    %r15, %rdx              / arg3 = tlen
 475  467          movq    0(%r14), %rcx           / arg4 = ta[0]
 476      -        call    big_mul_add_vec64
      468 +        call    big_mul_add_vec
 477  469          movq    %rax, 0(%r13, %r15, 8)  / tr[tlen] = cy
 478  470          jmp     .L31
 479  471  
 480  472  .L32:
 481  473  
 482  474  / No more function calls after this.
 483  475  / Restore arguments to registers.
 484  476  / However, don't use %rdx for arg3, len, because it is heavily
 485  477  / used by the hardware MUL instruction.  Use %r8, instead.
 486  478          movq    0(%rsp), %rdi           / %rdi == arg1 == r
↓ open down ↓ 58 lines elided ↑ open up ↑
 545  537          addq    $24, %rsp               / skip %rdi, %rsi, %rdx
 546  538          popq    %r15
 547  539          popq    %r14
 548  540          popq    %r13
 549  541          popq    %r12
 550  542          popq    %rbp
 551  543          popq    %rbx
 552  544  
 553  545          ret
 554  546  
 555      -        SET_SIZE(big_sqr_vec64)
      547 +        SET_SIZE(big_sqr_vec)
 556  548  
 557  549  #endif  /* lint */
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX