Print this page
6665607 Need a SHA256/SHA384/SHA512 implementation optimized for 64-bit x86


   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 2006 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 #ifndef _SYS_SHA2_H
  27 #define _SYS_SHA2_H
  28 
  29 #pragma ident   "@(#)sha2.h     1.4     06/03/28 SMI"
  30 
  31 #include <sys/types.h>            /* for uint_* */
  32 
  33 #ifdef  __cplusplus
  34 extern "C" {
  35 #endif
  36 
  37 #define SHA2_HMAC_MIN_KEY_LEN   8       /* SHA2-HMAC min key length in bits */
  38 #define SHA2_HMAC_MAX_KEY_LEN   INT_MAX /* SHA2-HMAC max key length in bits */
  39 
  40 #define SHA256_DIGEST_LENGTH    32      /* SHA256 digest length in bytes */
  41 #define SHA384_DIGEST_LENGTH    48      /* SHA384 digest length in bytes */
  42 #define SHA512_DIGEST_LENGTH    64      /* SHA512 digest length in bytes */
  43 
  44 #define SHA256_HMAC_BLOCK_SIZE  64      /* SHA256-HMAC block size */
  45 #define SHA512_HMAC_BLOCK_SIZE  128     /* SHA512-HMAC block size */
  46 
  47 #define SHA256                  0
  48 #define SHA256_HMAC             1
  49 #define SHA256_HMAC_GEN         2
  50 #define SHA384                  3
  51 #define SHA384_HMAC             4
  52 #define SHA384_HMAC_GEN         5
  53 #define SHA512                  6
  54 #define SHA512_HMAC             7
  55 #define SHA512_HMAC_GEN         8
  56 
  57 /*
  58  * SHA2 context.
  59  * The contents of this structure are a private interface between the
  60  * Init/Update/Final calls of the functions defined below.
  61  * Callers must never attempt to read or write any of the fields
  62  * in this strucutre directly.
  63  */
  64 typedef struct  {
  65         uint32_t algotype;              /* Algorithm Type */
  66 
  67         /* state (ABCDEFGH) */
  68         union {
  69                 uint32_t s32[8];        /* for SHA256 */
  70                 uint64_t s64[8];        /* for SHA384/512 */
  71         } state;
  72         /* number of bits */
  73         union {
  74                 uint32_t c32[2];        /* for SHA256 , modulo 2^64 */
  75                 uint64_t c64[2];        /* for SHA384/512, modulo 2^128 */
  76         } count;
  77         union {
  78                 uint8_t         buf8[128];      /* undigested input */
  79                 uint32_t        buf32[32];      /* realigned input */
  80                 uint64_t        buf64[16];      /* realigned input */
  81         } buf_un;
  82 } SHA2_CTX;




   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 _SYS_SHA2_H
  27 #define _SYS_SHA2_H
  28 
  29 #pragma ident   "@(#)sha2.h     1.5     08/03/05 SMI"
  30 
  31 #include <sys/types.h>            /* for uint_* */
  32 
  33 #ifdef  __cplusplus
  34 extern "C" {
  35 #endif
  36 
  37 #define SHA2_HMAC_MIN_KEY_LEN   8       /* SHA2-HMAC min key length in bits */
  38 #define SHA2_HMAC_MAX_KEY_LEN   INT_MAX /* SHA2-HMAC max key length in bits */
  39 
  40 #define SHA256_DIGEST_LENGTH    32      /* SHA256 digest length in bytes */
  41 #define SHA384_DIGEST_LENGTH    48      /* SHA384 digest length in bytes */
  42 #define SHA512_DIGEST_LENGTH    64      /* SHA512 digest length in bytes */
  43 
  44 #define SHA256_HMAC_BLOCK_SIZE  64      /* SHA256-HMAC block size */
  45 #define SHA512_HMAC_BLOCK_SIZE  128     /* SHA512-HMAC block size */
  46 
  47 #define SHA256                  0
  48 #define SHA256_HMAC             1
  49 #define SHA256_HMAC_GEN         2
  50 #define SHA384                  3
  51 #define SHA384_HMAC             4
  52 #define SHA384_HMAC_GEN         5
  53 #define SHA512                  6
  54 #define SHA512_HMAC             7
  55 #define SHA512_HMAC_GEN         8
  56 
  57 /*
  58  * SHA2 context.
  59  * The contents of this structure are a private interface between the
  60  * Init/Update/Final calls of the functions defined below.
  61  * Callers must never attempt to read or write any of the fields
  62  * in this structure directly.
  63  */
  64 typedef struct  {
  65         uint32_t algotype;              /* Algorithm Type */
  66 
  67         /* state (ABCDEFGH) */
  68         union {
  69                 uint32_t s32[8];        /* for SHA256 */
  70                 uint64_t s64[8];        /* for SHA384/512 */
  71         } state;
  72         /* number of bits */
  73         union {
  74                 uint32_t c32[2];        /* for SHA256 , modulo 2^64 */
  75                 uint64_t c64[2];        /* for SHA384/512, modulo 2^128 */
  76         } count;
  77         union {
  78                 uint8_t         buf8[128];      /* undigested input */
  79                 uint32_t        buf32[32];      /* realigned input */
  80                 uint64_t        buf64[16];      /* realigned input */
  81         } buf_un;
  82 } SHA2_CTX;