Print this page
4185 New hash algorithm support


   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 2009 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 #include <sys/types.h>            /* for uint_* */
  30 
  31 #ifdef  __cplusplus
  32 extern "C" {
  33 #endif
  34 
  35 #define SHA2_HMAC_MIN_KEY_LEN   1       /* SHA2-HMAC min key length in bytes */
  36 #define SHA2_HMAC_MAX_KEY_LEN   INT_MAX /* SHA2-HMAC max key length in bytes */
  37 
  38 #define SHA256_DIGEST_LENGTH    32      /* SHA256 digest length in bytes */
  39 #define SHA384_DIGEST_LENGTH    48      /* SHA384 digest length in bytes */
  40 #define SHA512_DIGEST_LENGTH    64      /* SHA512 digest length in bytes */
  41 




  42 #define SHA256_HMAC_BLOCK_SIZE  64      /* SHA256-HMAC block size */
  43 #define SHA512_HMAC_BLOCK_SIZE  128     /* SHA512-HMAC block size */
  44 
  45 #define SHA256                  0
  46 #define SHA256_HMAC             1
  47 #define SHA256_HMAC_GEN         2
  48 #define SHA384                  3
  49 #define SHA384_HMAC             4
  50 #define SHA384_HMAC_GEN         5
  51 #define SHA512                  6
  52 #define SHA512_HMAC             7
  53 #define SHA512_HMAC_GEN         8


  54 
  55 /*
  56  * SHA2 context.
  57  * The contents of this structure are a private interface between the
  58  * Init/Update/Final calls of the functions defined below.
  59  * Callers must never attempt to read or write any of the fields
  60  * in this structure directly.
  61  */
  62 typedef struct  {
  63         uint32_t algotype;              /* Algorithm Type */
  64 
  65         /* state (ABCDEFGH) */
  66         union {
  67                 uint32_t s32[8];        /* for SHA256 */
  68                 uint64_t s64[8];        /* for SHA384/512 */
  69         } state;
  70         /* number of bits */
  71         union {
  72                 uint32_t c32[2];        /* for SHA256 , modulo 2^64 */
  73                 uint64_t c64[2];        /* for SHA384/512, modulo 2^128 */


 113  * of the SHA2 functions and must not be used by consumers of the interface
 114  */
 115 
 116 /*
 117  * List of support mechanisms in this module.
 118  *
 119  * It is important to note that in the module, division or modulus calculations
 120  * are used on the enumerated type to determine which mechanism is being used;
 121  * therefore, changing the order or additional mechanisms should be done
 122  * carefully
 123  */
 124 typedef enum sha2_mech_type {
 125         SHA256_MECH_INFO_TYPE,          /* SUN_CKM_SHA256 */
 126         SHA256_HMAC_MECH_INFO_TYPE,     /* SUN_CKM_SHA256_HMAC */
 127         SHA256_HMAC_GEN_MECH_INFO_TYPE, /* SUN_CKM_SHA256_HMAC_GENERAL */
 128         SHA384_MECH_INFO_TYPE,          /* SUN_CKM_SHA384 */
 129         SHA384_HMAC_MECH_INFO_TYPE,     /* SUN_CKM_SHA384_HMAC */
 130         SHA384_HMAC_GEN_MECH_INFO_TYPE, /* SUN_CKM_SHA384_HMAC_GENERAL */
 131         SHA512_MECH_INFO_TYPE,          /* SUN_CKM_SHA512 */
 132         SHA512_HMAC_MECH_INFO_TYPE,     /* SUN_CKM_SHA512_HMAC */
 133         SHA512_HMAC_GEN_MECH_INFO_TYPE  /* SUN_CKM_SHA512_HMAC_GENERAL */


 134 } sha2_mech_type_t;
 135 
 136 #endif /* _SHA2_IMPL */
 137 
 138 #ifdef  __cplusplus
 139 }
 140 #endif
 141 
 142 #endif /* _SYS_SHA2_H */


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


 120  * of the SHA2 functions and must not be used by consumers of the interface
 121  */
 122 
 123 /*
 124  * List of support mechanisms in this module.
 125  *
 126  * It is important to note that in the module, division or modulus calculations
 127  * are used on the enumerated type to determine which mechanism is being used;
 128  * therefore, changing the order or additional mechanisms should be done
 129  * carefully
 130  */
 131 typedef enum sha2_mech_type {
 132         SHA256_MECH_INFO_TYPE,          /* SUN_CKM_SHA256 */
 133         SHA256_HMAC_MECH_INFO_TYPE,     /* SUN_CKM_SHA256_HMAC */
 134         SHA256_HMAC_GEN_MECH_INFO_TYPE, /* SUN_CKM_SHA256_HMAC_GENERAL */
 135         SHA384_MECH_INFO_TYPE,          /* SUN_CKM_SHA384 */
 136         SHA384_HMAC_MECH_INFO_TYPE,     /* SUN_CKM_SHA384_HMAC */
 137         SHA384_HMAC_GEN_MECH_INFO_TYPE, /* SUN_CKM_SHA384_HMAC_GENERAL */
 138         SHA512_MECH_INFO_TYPE,          /* SUN_CKM_SHA512 */
 139         SHA512_HMAC_MECH_INFO_TYPE,     /* SUN_CKM_SHA512_HMAC */
 140         SHA512_HMAC_GEN_MECH_INFO_TYPE, /* SUN_CKM_SHA512_HMAC_GENERAL */
 141         SHA512_224_MECH_INFO_TYPE,      /* SUN_CKM_SHA512_224 */
 142         SHA512_256_MECH_INFO_TYPE       /* SUN_CKM_SHA512_256 */
 143 } sha2_mech_type_t;
 144 
 145 #endif /* _SHA2_IMPL */
 146 
 147 #ifdef  __cplusplus
 148 }
 149 #endif
 150 
 151 #endif /* _SYS_SHA2_H */