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>


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.

  25  */
  26 
  27 #include <stdlib.h>
  28 #include <strings.h>
  29 #include <sys/types.h>
  30 #include <security/cryptoki.h>
  31 #include "softObject.h"
  32 #include "softOps.h"
  33 #include "softSession.h"
  34 #include "softMAC.h"
  35 #include "softRSA.h"
  36 #include "softDSA.h"
  37 #include "softEC.h"
  38 #include "softCrypt.h"
  39 
  40 /*
  41  * soft_sign_init()
  42  *
  43  * Arguments:
  44  *      session_p:      pointer to soft_session_t struct


 545 
 546                 if (dsa_ctx != NULL && dsa_ctx->key != NULL) {
 547                         soft_cleanup_object(dsa_ctx->key);
 548                         free(dsa_ctx->key);
 549                 }
 550                 break;
 551 
 552         }
 553         case CKM_SSL3_MD5_MAC:
 554         case CKM_SSL3_SHA1_MAC:
 555         case CKM_MD5_HMAC_GENERAL:
 556         case CKM_MD5_HMAC:
 557         case CKM_SHA_1_HMAC_GENERAL:
 558         case CKM_SHA_1_HMAC:
 559         case CKM_SHA256_HMAC_GENERAL:
 560         case CKM_SHA256_HMAC:
 561         case CKM_SHA384_HMAC_GENERAL:
 562         case CKM_SHA384_HMAC:
 563         case CKM_SHA512_HMAC_GENERAL:
 564         case CKM_SHA512_HMAC:
 565                 if (active_op->context != NULL)
 566                         bzero(active_op->context, sizeof (soft_hmac_ctx_t));


 567                 break;
 568         case CKM_DES_MAC_GENERAL:
 569         case CKM_DES_MAC:
 570                 if (session_p->encrypt.context != NULL) {
 571                         free(session_p->encrypt.context);
 572                         session_p->encrypt.context = NULL;
 573                         session_p->encrypt.flags = 0;
 574                 }
 575                 if (active_op->context != NULL)
 576                         bzero(active_op->context, sizeof (soft_des_ctx_t));


 577                 break;
 578 
 579         case CKM_AES_CMAC_GENERAL:
 580         case CKM_AES_CMAC:
 581                 if (session_p->encrypt.context != NULL) {
 582                         free(session_p->encrypt.context);
 583                         session_p->encrypt.context = NULL;
 584                         session_p->encrypt.flags = 0;
 585                 }
 586                 if (active_op->context != NULL)
 587                         bzero(active_op->context, sizeof (soft_aes_ctx_t));


 588                 break;
 589 
 590         }
 591 
 592         if (active_op->context != NULL) {
 593                 free(active_op->context);
 594                 active_op->context = NULL;
 595         }
 596 
 597         active_op->flags = 0;
 598 
 599         if (!lock_held)
 600                 SES_REFRELE(session_p, lock_true);
 601 }


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
  25  * Copyright (c) 2018, Joyent, Inc.
  26  */
  27 
  28 #include <stdlib.h>
  29 #include <strings.h>
  30 #include <sys/types.h>
  31 #include <security/cryptoki.h>
  32 #include "softObject.h"
  33 #include "softOps.h"
  34 #include "softSession.h"
  35 #include "softMAC.h"
  36 #include "softRSA.h"
  37 #include "softDSA.h"
  38 #include "softEC.h"
  39 #include "softCrypt.h"
  40 
  41 /*
  42  * soft_sign_init()
  43  *
  44  * Arguments:
  45  *      session_p:      pointer to soft_session_t struct


 546 
 547                 if (dsa_ctx != NULL && dsa_ctx->key != NULL) {
 548                         soft_cleanup_object(dsa_ctx->key);
 549                         free(dsa_ctx->key);
 550                 }
 551                 break;
 552 
 553         }
 554         case CKM_SSL3_MD5_MAC:
 555         case CKM_SSL3_SHA1_MAC:
 556         case CKM_MD5_HMAC_GENERAL:
 557         case CKM_MD5_HMAC:
 558         case CKM_SHA_1_HMAC_GENERAL:
 559         case CKM_SHA_1_HMAC:
 560         case CKM_SHA256_HMAC_GENERAL:
 561         case CKM_SHA256_HMAC:
 562         case CKM_SHA384_HMAC_GENERAL:
 563         case CKM_SHA384_HMAC:
 564         case CKM_SHA512_HMAC_GENERAL:
 565         case CKM_SHA512_HMAC:
 566                 if (active_op->context != NULL) {
 567                         explicit_bzero(active_op->context,
 568                             sizeof (soft_hmac_ctx_t));
 569                 }
 570                 break;
 571         case CKM_DES_MAC_GENERAL:
 572         case CKM_DES_MAC:
 573                 if (session_p->encrypt.context != NULL) {
 574                         free(session_p->encrypt.context);
 575                         session_p->encrypt.context = NULL;
 576                         session_p->encrypt.flags = 0;
 577                 }
 578                 if (active_op->context != NULL) {
 579                         explicit_bzero(active_op->context,
 580                             sizeof (soft_des_ctx_t));
 581                 }
 582                 break;
 583 
 584         case CKM_AES_CMAC_GENERAL:
 585         case CKM_AES_CMAC:
 586                 if (session_p->encrypt.context != NULL) {
 587                         free(session_p->encrypt.context);
 588                         session_p->encrypt.context = NULL;
 589                         session_p->encrypt.flags = 0;
 590                 }
 591                 if (active_op->context != NULL) {
 592                         explicit_bzero(active_op->context,
 593                             sizeof (soft_aes_ctx_t));
 594                 }
 595                 break;
 596 
 597         }
 598 
 599         if (active_op->context != NULL) {
 600                 free(active_op->context);
 601                 active_op->context = NULL;
 602         }
 603 
 604         active_op->flags = 0;
 605 
 606         if (!lock_held)
 607                 SES_REFRELE(session_p, lock_true);
 608 }