Print this page
5072963 Need an optimized AES implementation for amd64


   2  * CDDL HEADER START
   3  *
   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 2007 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 #ifndef _AES_CBC_CRYPT_H
  27 #define _AES_CBC_CRYPT_H
  28 
  29 #pragma ident   "@(#)aes_cbc_crypt.h    1.6     07/09/11 SMI"
  30 
  31 #ifdef  __cplusplus
  32 extern "C" {
  33 #endif
  34 
  35 #include <sys/crypto/common.h>
  36 #include "aes_impl.h"
  37 
  38 /*
  39  * ac_keysched:         Pointer to key schedule.
  40  *
  41  * ac_keysched_len:     Length of the key schedule.
  42  *
  43  * ac_remainder:        This is for residual data, i.e. data that can't
  44  *                      be processed because there are too few bytes.
  45  *                      Must wait until more data arrives.
  46  *
  47  * ac_remainder_len:    Number of bytes in ac_remainder.
  48  *
  49  * ac_iv:               Scratch buffer that sometimes contains the IV.


  55  * ac_copy_to:          Pointer to where encrypted residual data needs
  56  *                      to be copied.
  57  *
  58  * ac_flags:            AES_PROVIDER_OWNS_KEY_SCHEDULE
  59  *                      When a context is freed, it is necessary
  60  *                      to know whether the key schedule was allocated
  61  *                      by the caller, or by aes_encrypt_init() or
  62  *                      aes_decrypt_init().  If allocated by the latter,
  63  *                      then it needs to be freed.
  64  *
  65  *                      AES_ECB_MODE, AES_CBC_MODE, or AES_CTR_MODE
  66  *                      AES_CCM_MODE
  67  *
  68  * ac_ccm_mac_len:      Stores length of the MAC in CCM mode.
  69  * ac_ccm_mac_buf:      Stores the intermediate value for MAC in CCM encrypt.
  70  *                      In CCM decrypt, stores the input MAC value.
  71  * ac_ccm_data_len:     Length of the plaintext for CCM mode encrypt, or
  72  *                      length of the ciphertext for CCM mode decrypt.
  73  * ac_ccm_processed_data_len:
  74  *                      Length of processed plaintext in CCM mode encrypt,
  75  *                      or length of processed ciphertex for CCM mode decrypt.
  76  * ac_ccm_processed_mac_len:
  77  *                      Length of MAC data accumulated in CCM mode decrypt.
  78  *
  79  * ac_ccm_pt_buf:       Only used in CCM mode decrypt.  It stores the
  80  *                      decrypted plaintext to be returned when
  81  *                      MAC verification succeeds in decrypt_final.
  82  *                      Memory for this should be allocated in the AES module.
  83  *
  84  */
  85 typedef struct aes_ctx {
  86         void *ac_keysched;
  87         size_t ac_keysched_len;
  88         uint64_t ac_iv[2];
  89         uint64_t ac_lastblock[2];
  90         uint64_t ac_remainder[2];
  91         size_t ac_remainder_len;
  92         uint8_t *ac_lastp;
  93         uint8_t *ac_copy_to;
  94         uint32_t ac_flags;
  95         size_t ac_ccm_mac_len;




   2  * CDDL HEADER START
   3  *
   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 #ifndef _AES_CBC_CRYPT_H
  27 #define _AES_CBC_CRYPT_H
  28 
  29 #pragma ident   "@(#)aes_cbc_crypt.h    1.7     08/05/21 SMI"
  30 
  31 #ifdef  __cplusplus
  32 extern "C" {
  33 #endif
  34 
  35 #include <sys/crypto/common.h>
  36 #include "aes_impl.h"
  37 
  38 /*
  39  * ac_keysched:         Pointer to key schedule.
  40  *
  41  * ac_keysched_len:     Length of the key schedule.
  42  *
  43  * ac_remainder:        This is for residual data, i.e. data that can't
  44  *                      be processed because there are too few bytes.
  45  *                      Must wait until more data arrives.
  46  *
  47  * ac_remainder_len:    Number of bytes in ac_remainder.
  48  *
  49  * ac_iv:               Scratch buffer that sometimes contains the IV.


  55  * ac_copy_to:          Pointer to where encrypted residual data needs
  56  *                      to be copied.
  57  *
  58  * ac_flags:            AES_PROVIDER_OWNS_KEY_SCHEDULE
  59  *                      When a context is freed, it is necessary
  60  *                      to know whether the key schedule was allocated
  61  *                      by the caller, or by aes_encrypt_init() or
  62  *                      aes_decrypt_init().  If allocated by the latter,
  63  *                      then it needs to be freed.
  64  *
  65  *                      AES_ECB_MODE, AES_CBC_MODE, or AES_CTR_MODE
  66  *                      AES_CCM_MODE
  67  *
  68  * ac_ccm_mac_len:      Stores length of the MAC in CCM mode.
  69  * ac_ccm_mac_buf:      Stores the intermediate value for MAC in CCM encrypt.
  70  *                      In CCM decrypt, stores the input MAC value.
  71  * ac_ccm_data_len:     Length of the plaintext for CCM mode encrypt, or
  72  *                      length of the ciphertext for CCM mode decrypt.
  73  * ac_ccm_processed_data_len:
  74  *                      Length of processed plaintext in CCM mode encrypt,
  75  *                      or length of processed ciphertext for CCM mode decrypt.
  76  * ac_ccm_processed_mac_len:
  77  *                      Length of MAC data accumulated in CCM mode decrypt.
  78  *
  79  * ac_ccm_pt_buf:       Only used in CCM mode decrypt.  It stores the
  80  *                      decrypted plaintext to be returned when
  81  *                      MAC verification succeeds in decrypt_final.
  82  *                      Memory for this should be allocated in the AES module.
  83  *
  84  */
  85 typedef struct aes_ctx {
  86         void *ac_keysched;
  87         size_t ac_keysched_len;
  88         uint64_t ac_iv[2];
  89         uint64_t ac_lastblock[2];
  90         uint64_t ac_remainder[2];
  91         size_t ac_remainder_len;
  92         uint8_t *ac_lastp;
  93         uint8_t *ac_copy_to;
  94         uint32_t ac_flags;
  95         size_t ac_ccm_mac_len;