Print this page
9642 PKCS#11 softtoken should use explicit_bzero
Reviewed by: Dan McDonald <danmcd@joyent.com>
Reviewed by: Alex Wilson <alex.wilson@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/pkcs11/pkcs11_softtoken/common/softBlowfishCrypt.c
          +++ new/usr/src/lib/pkcs11/pkcs11_softtoken/common/softBlowfishCrypt.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
       24 + * Copyright (c) 2018, Joyent, Inc.
  24   25   */
  25   26  
  26   27  #include <pthread.h>
  27   28  #include <stdlib.h>
  28   29  #include <string.h>
  29   30  #include <strings.h>
  30   31  #include <sys/types.h>
  31   32  #include <security/cryptoki.h>
  32   33  #include "softSession.h"
  33   34  #include "softObject.h"
↓ open down ↓ 256 lines elided ↑ open up ↑
 290  291                  }
 291  292  
 292  293          } else {
 293  294                  *pulEncryptedLen = 0;
 294  295                  rv = CKR_FUNCTION_FAILED;
 295  296          }
 296  297  
 297  298  cleanup:
 298  299          (void) pthread_mutex_lock(&session_p->session_mutex);
 299  300          blowfish_ctx = (blowfish_ctx_t *)soft_blowfish_ctx->blowfish_cbc;
 300      -        if (blowfish_ctx != NULL) {
 301      -                bzero(blowfish_ctx->bc_keysched,
 302      -                    blowfish_ctx->bc_keysched_len);
 303      -                free(soft_blowfish_ctx->blowfish_cbc);
 304      -        }
 305      -
 306      -        bzero(soft_blowfish_ctx->key_sched, soft_blowfish_ctx->keysched_len);
 307      -        free(soft_blowfish_ctx->key_sched);
 308      -        free(session_p->encrypt.context);
      301 +        freezero(blowfish_ctx, sizeof (cbc_ctx_t));
      302 +        freezero(soft_blowfish_ctx->key_sched,
      303 +            soft_blowfish_ctx->keysched_len);
      304 +        freezero(session_p->encrypt.context,
      305 +            sizeof (soft_blowfish_ctx_t));
 309  306          session_p->encrypt.context = NULL;
 310  307          (void) pthread_mutex_unlock(&session_p->session_mutex);
 311  308  
 312  309          return (rv);
 313  310  }
 314  311  
 315  312  
 316  313  CK_RV
 317  314  soft_blowfish_decrypt_common(soft_session_t *session_p, CK_BYTE_PTR pEncrypted,
 318  315      CK_ULONG ulEncryptedLen, CK_BYTE_PTR pData, CK_ULONG_PTR pulDataLen,
↓ open down ↓ 139 lines elided ↑ open up ↑
 458  455  
 459  456  
 460  457          } else {
 461  458                  *pulDataLen = 0;
 462  459                  rv = CKR_FUNCTION_FAILED;
 463  460          }
 464  461  
 465  462  cleanup:
 466  463          (void) pthread_mutex_lock(&session_p->session_mutex);
 467  464          blowfish_ctx = (blowfish_ctx_t *)soft_blowfish_ctx->blowfish_cbc;
 468      -        if (blowfish_ctx != NULL) {
 469      -                bzero(blowfish_ctx->bc_keysched,
 470      -                    blowfish_ctx->bc_keysched_len);
 471      -                free(soft_blowfish_ctx->blowfish_cbc);
 472      -        }
 473      -
 474      -        bzero(soft_blowfish_ctx->key_sched, soft_blowfish_ctx->keysched_len);
 475      -        free(soft_blowfish_ctx->key_sched);
 476      -        free(session_p->decrypt.context);
      465 +        free(blowfish_ctx);
      466 +        freezero(soft_blowfish_ctx->key_sched,
      467 +            soft_blowfish_ctx->keysched_len);
      468 +        freezero(session_p->decrypt.context,
      469 +            sizeof (soft_blowfish_ctx_t));
 477  470          session_p->decrypt.context = NULL;
 478  471          (void) pthread_mutex_unlock(&session_p->session_mutex);
 479  472  
 480  473          return (rv);
 481  474  }
 482  475  
 483  476  /*
 484  477   * Allocate and initialize a context for BLOWFISH CBC mode of operation.
 485  478   */
 486  479  
↓ open down ↓ 19 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX