Print this page
4896 Performance improvements for KCF AES modes


   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 /*
  23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */



  26 
  27 /*      Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
  28 /*        All Rights Reserved   */
  29 
  30 /*
  31  * Portions of this source code were derived from Berkeley 4.3 BSD
  32  * under license from the Regents of the University of California.
  33  */
  34 
  35 /*
  36  * des_crypt.c, DES encryption library routines
  37  */
  38 
  39 #include <sys/errno.h>
  40 #include <sys/modctl.h>
  41 
  42 #include <sys/systm.h>
  43 #include <sys/cmn_err.h>
  44 #include <sys/ddi.h>
  45 #include <sys/crypto/common.h>


 475                 strength = DES3;
 476                 if (des_ctx == NULL)
 477                         des_ctx = cbc_alloc_ctx(kmflag);
 478                 break;
 479         default:
 480                 return (CRYPTO_MECHANISM_INVALID);
 481         }
 482 
 483         if ((rv = des_common_init_ctx(des_ctx, template, mechanism, key,
 484             strength, kmflag)) != CRYPTO_SUCCESS) {
 485                 crypto_free_mode_ctx(des_ctx);
 486                 return (rv);
 487         }
 488 
 489         ctx->cc_provider_private = des_ctx;
 490 
 491         return (CRYPTO_SUCCESS);
 492 }
 493 
 494 static void
 495 des_copy_block64(uint8_t *in, uint64_t *out)
 496 {
 497         if (IS_P2ALIGNED(in, sizeof (uint64_t))) {
 498                 /* LINTED: pointer alignment */
 499                 out[0] = *(uint64_t *)&in[0];
 500         } else {
 501                 uint64_t tmp64;
 502 
 503 #ifdef _BIG_ENDIAN
 504                 tmp64 = (((uint64_t)in[0] << 56) |
 505                     ((uint64_t)in[1] << 48) |
 506                     ((uint64_t)in[2] << 40) |
 507                     ((uint64_t)in[3] << 32) |
 508                     ((uint64_t)in[4] << 24) |
 509                     ((uint64_t)in[5] << 16) |
 510                     ((uint64_t)in[6] << 8) |
 511                     (uint64_t)in[7]);
 512 #else
 513                 tmp64 = (((uint64_t)in[7] << 56) |
 514                     ((uint64_t)in[6] << 48) |
 515                     ((uint64_t)in[5] << 40) |




   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 /*
  23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 /*
  27  * Copyright 2015 by Saso Kiselkov. All rights reserved.
  28  */
  29 
  30 /*      Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
  31 /*        All Rights Reserved   */
  32 
  33 /*
  34  * Portions of this source code were derived from Berkeley 4.3 BSD
  35  * under license from the Regents of the University of California.
  36  */
  37 
  38 /*
  39  * des_crypt.c, DES encryption library routines
  40  */
  41 
  42 #include <sys/errno.h>
  43 #include <sys/modctl.h>
  44 
  45 #include <sys/systm.h>
  46 #include <sys/cmn_err.h>
  47 #include <sys/ddi.h>
  48 #include <sys/crypto/common.h>


 478                 strength = DES3;
 479                 if (des_ctx == NULL)
 480                         des_ctx = cbc_alloc_ctx(kmflag);
 481                 break;
 482         default:
 483                 return (CRYPTO_MECHANISM_INVALID);
 484         }
 485 
 486         if ((rv = des_common_init_ctx(des_ctx, template, mechanism, key,
 487             strength, kmflag)) != CRYPTO_SUCCESS) {
 488                 crypto_free_mode_ctx(des_ctx);
 489                 return (rv);
 490         }
 491 
 492         ctx->cc_provider_private = des_ctx;
 493 
 494         return (CRYPTO_SUCCESS);
 495 }
 496 
 497 static void
 498 des_copy_block64(const uint8_t *in, uint64_t *out)
 499 {
 500         if (IS_P2ALIGNED(in, sizeof (uint64_t))) {
 501                 /* LINTED: pointer alignment */
 502                 out[0] = *(uint64_t *)&in[0];
 503         } else {
 504                 uint64_t tmp64;
 505 
 506 #ifdef _BIG_ENDIAN
 507                 tmp64 = (((uint64_t)in[0] << 56) |
 508                     ((uint64_t)in[1] << 48) |
 509                     ((uint64_t)in[2] << 40) |
 510                     ((uint64_t)in[3] << 32) |
 511                     ((uint64_t)in[4] << 24) |
 512                     ((uint64_t)in[5] << 16) |
 513                     ((uint64_t)in[6] << 8) |
 514                     (uint64_t)in[7]);
 515 #else
 516                 tmp64 = (((uint64_t)in[7] << 56) |
 517                     ((uint64_t)in[6] << 48) |
 518                     ((uint64_t)in[5] << 40) |