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>


   4  * The contents of this file are subject to the terms of the
   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 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.

  24  */
  25 
  26 #include <strings.h>
  27 #include <md5.h>
  28 #include <pthread.h>
  29 #include <stdlib.h>
  30 #include <sys/sha1.h>
  31 #include <sys/sha2.h>
  32 #include <sys/types.h>
  33 #include <security/cryptoki.h>
  34 #include "softGlobal.h"
  35 #include "softOps.h"
  36 #include "softSession.h"
  37 #include "softObject.h"
  38 
  39 
  40 /*
  41  * soft_digest_init()
  42  *
  43  * Arguments:


 285 
 286                         SHA2Update((SHA2_CTX *)session_p->digest.context,
 287                             pData, ulDataLen);
 288 
 289                         SHA2Final(pDigest,
 290                             (SHA2_CTX *)session_p->digest.context);
 291                 } else {
 292                         /*
 293                          * this is called by soft_digest_final()
 294                          */
 295                         SHA2Final(pDigest,
 296                             (SHA2_CTX *)session_p->digest.context);
 297                         len = sizeof (SHA2_CTX);
 298                 }
 299 
 300                 break;
 301         }
 302 
 303         /* Paranoia on behalf of C_DigestKey callers: bzero the context */
 304         if (session_p->digest.flags & CRYPTO_KEY_DIGESTED) {
 305                 bzero(session_p->digest.context, len);
 306                 session_p->digest.flags &= ~CRYPTO_KEY_DIGESTED;
 307         }
 308         *pulDigestLen = digestLen;
 309         (void) pthread_mutex_lock(&session_p->session_mutex);
 310         free(session_p->digest.context);
 311         session_p->digest.context = NULL;
 312         (void) pthread_mutex_unlock(&session_p->session_mutex);
 313 
 314         return (CKR_OK);
 315 }
 316 
 317 
 318 /*
 319  * soft_digest()
 320  *
 321  * Arguments:
 322  *      session_p:      pointer to soft_session_t struct
 323  *      pData:          pointer to the input data to be digested
 324  *      ulDataLen:      length of the input data
 325  *      pDigest:        pointer to the output data after digesting




   4  * The contents of this file are subject to the terms of the
   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 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  * Copyright (c) 2018, Joyent, Inc.
  25  */
  26 
  27 #include <strings.h>
  28 #include <md5.h>
  29 #include <pthread.h>
  30 #include <stdlib.h>
  31 #include <sys/sha1.h>
  32 #include <sys/sha2.h>
  33 #include <sys/types.h>
  34 #include <security/cryptoki.h>
  35 #include "softGlobal.h"
  36 #include "softOps.h"
  37 #include "softSession.h"
  38 #include "softObject.h"
  39 
  40 
  41 /*
  42  * soft_digest_init()
  43  *
  44  * Arguments:


 286 
 287                         SHA2Update((SHA2_CTX *)session_p->digest.context,
 288                             pData, ulDataLen);
 289 
 290                         SHA2Final(pDigest,
 291                             (SHA2_CTX *)session_p->digest.context);
 292                 } else {
 293                         /*
 294                          * this is called by soft_digest_final()
 295                          */
 296                         SHA2Final(pDigest,
 297                             (SHA2_CTX *)session_p->digest.context);
 298                         len = sizeof (SHA2_CTX);
 299                 }
 300 
 301                 break;
 302         }
 303 
 304         /* Paranoia on behalf of C_DigestKey callers: bzero the context */
 305         if (session_p->digest.flags & CRYPTO_KEY_DIGESTED) {
 306                 explicit_bzero(session_p->digest.context, len);
 307                 session_p->digest.flags &= ~CRYPTO_KEY_DIGESTED;
 308         }
 309         *pulDigestLen = digestLen;
 310         (void) pthread_mutex_lock(&session_p->session_mutex);
 311         free(session_p->digest.context);
 312         session_p->digest.context = NULL;
 313         (void) pthread_mutex_unlock(&session_p->session_mutex);
 314 
 315         return (CKR_OK);
 316 }
 317 
 318 
 319 /*
 320  * soft_digest()
 321  *
 322  * Arguments:
 323  *      session_p:      pointer to soft_session_t struct
 324  *      pData:          pointer to the input data to be digested
 325  *      ulDataLen:      length of the input data
 326  *      pDigest:        pointer to the output data after digesting