17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5734b6a94Sdarrenm * Common Development and Distribution License (the "License"). 6734b6a94Sdarrenm * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*5b675b31SVladimir Kotal * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _SYS_SHA2_H 277c478bd9Sstevel@tonic-gate #define _SYS_SHA2_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/types.h> /* for uint_* */ 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #ifdef __cplusplus 327c478bd9Sstevel@tonic-gate extern "C" { 337c478bd9Sstevel@tonic-gate #endif 347c478bd9Sstevel@tonic-gate 35*5b675b31SVladimir Kotal #define SHA2_HMAC_MIN_KEY_LEN 1 /* SHA2-HMAC min key length in bytes */ 36*5b675b31SVladimir Kotal #define SHA2_HMAC_MAX_KEY_LEN INT_MAX /* SHA2-HMAC max key length in bytes */ 37f66d273dSizick 38f66d273dSizick #define SHA256_DIGEST_LENGTH 32 /* SHA256 digest length in bytes */ 39f66d273dSizick #define SHA384_DIGEST_LENGTH 48 /* SHA384 digest length in bytes */ 40f66d273dSizick #define SHA512_DIGEST_LENGTH 64 /* SHA512 digest length in bytes */ 41f66d273dSizick 42f66d273dSizick #define SHA256_HMAC_BLOCK_SIZE 64 /* SHA256-HMAC block size */ 43f66d273dSizick #define SHA512_HMAC_BLOCK_SIZE 128 /* SHA512-HMAC block size */ 44f66d273dSizick 45734b6a94Sdarrenm #define SHA256 0 46734b6a94Sdarrenm #define SHA256_HMAC 1 47734b6a94Sdarrenm #define SHA256_HMAC_GEN 2 48734b6a94Sdarrenm #define SHA384 3 49734b6a94Sdarrenm #define SHA384_HMAC 4 50734b6a94Sdarrenm #define SHA384_HMAC_GEN 5 51734b6a94Sdarrenm #define SHA512 6 52734b6a94Sdarrenm #define SHA512_HMAC 7 53734b6a94Sdarrenm #define SHA512_HMAC_GEN 8 54f66d273dSizick 55734b6a94Sdarrenm /* 56734b6a94Sdarrenm * SHA2 context. 57734b6a94Sdarrenm * The contents of this structure are a private interface between the 58734b6a94Sdarrenm * Init/Update/Final calls of the functions defined below. 59734b6a94Sdarrenm * Callers must never attempt to read or write any of the fields 6055553f71Sda73024 * in this structure directly. 61734b6a94Sdarrenm */ 627c478bd9Sstevel@tonic-gate typedef struct { 637c478bd9Sstevel@tonic-gate uint32_t algotype; /* Algorithm Type */ 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate /* state (ABCDEFGH) */ 667c478bd9Sstevel@tonic-gate union { 677c478bd9Sstevel@tonic-gate uint32_t s32[8]; /* for SHA256 */ 687c478bd9Sstevel@tonic-gate uint64_t s64[8]; /* for SHA384/512 */ 697c478bd9Sstevel@tonic-gate } state; 707c478bd9Sstevel@tonic-gate /* number of bits */ 717c478bd9Sstevel@tonic-gate union { 727c478bd9Sstevel@tonic-gate uint32_t c32[2]; /* for SHA256 , modulo 2^64 */ 737c478bd9Sstevel@tonic-gate uint64_t c64[2]; /* for SHA384/512, modulo 2^128 */ 747c478bd9Sstevel@tonic-gate } count; 757c478bd9Sstevel@tonic-gate union { 767c478bd9Sstevel@tonic-gate uint8_t buf8[128]; /* undigested input */ 777c478bd9Sstevel@tonic-gate uint32_t buf32[32]; /* realigned input */ 787c478bd9Sstevel@tonic-gate uint64_t buf64[16]; /* realigned input */ 797c478bd9Sstevel@tonic-gate } buf_un; 807c478bd9Sstevel@tonic-gate } SHA2_CTX; 817c478bd9Sstevel@tonic-gate 82734b6a94Sdarrenm typedef SHA2_CTX SHA256_CTX; 83734b6a94Sdarrenm typedef SHA2_CTX SHA384_CTX; 84734b6a94Sdarrenm typedef SHA2_CTX SHA512_CTX; 85734b6a94Sdarrenm 867c478bd9Sstevel@tonic-gate extern void SHA2Init(uint64_t mech, SHA2_CTX *); 877c478bd9Sstevel@tonic-gate 88734b6a94Sdarrenm extern void SHA2Update(SHA2_CTX *, const void *, size_t); 897c478bd9Sstevel@tonic-gate 90734b6a94Sdarrenm extern void SHA2Final(void *, SHA2_CTX *); 91734b6a94Sdarrenm 92734b6a94Sdarrenm extern void SHA256Init(SHA256_CTX *); 93734b6a94Sdarrenm 94734b6a94Sdarrenm extern void SHA256Update(SHA256_CTX *, const void *, size_t); 95734b6a94Sdarrenm 96734b6a94Sdarrenm extern void SHA256Final(void *, SHA256_CTX *); 97734b6a94Sdarrenm 98734b6a94Sdarrenm extern void SHA384Init(SHA384_CTX *); 99734b6a94Sdarrenm 100734b6a94Sdarrenm extern void SHA384Update(SHA384_CTX *, const void *, size_t); 101734b6a94Sdarrenm 102734b6a94Sdarrenm extern void SHA384Final(void *, SHA384_CTX *); 103734b6a94Sdarrenm 104734b6a94Sdarrenm extern void SHA512Init(SHA512_CTX *); 105734b6a94Sdarrenm 106734b6a94Sdarrenm extern void SHA512Update(SHA512_CTX *, const void *, size_t); 107734b6a94Sdarrenm 108734b6a94Sdarrenm extern void SHA512Final(void *, SHA512_CTX *); 109734b6a94Sdarrenm 110734b6a94Sdarrenm #ifdef _SHA2_IMPL 111734b6a94Sdarrenm /* 112734b6a94Sdarrenm * The following types/functions are all private to the implementation 113734b6a94Sdarrenm * of the SHA2 functions and must not be used by consumers of the interface 114734b6a94Sdarrenm */ 115734b6a94Sdarrenm 116734b6a94Sdarrenm /* 117734b6a94Sdarrenm * List of support mechanisms in this module. 118734b6a94Sdarrenm * 119734b6a94Sdarrenm * It is important to note that in the module, division or modulus calculations 120734b6a94Sdarrenm * are used on the enumerated type to determine which mechanism is being used; 121734b6a94Sdarrenm * therefore, changing the order or additional mechanisms should be done 122734b6a94Sdarrenm * carefully 123734b6a94Sdarrenm */ 124734b6a94Sdarrenm typedef enum sha2_mech_type { 125734b6a94Sdarrenm SHA256_MECH_INFO_TYPE, /* SUN_CKM_SHA256 */ 126734b6a94Sdarrenm SHA256_HMAC_MECH_INFO_TYPE, /* SUN_CKM_SHA256_HMAC */ 127734b6a94Sdarrenm SHA256_HMAC_GEN_MECH_INFO_TYPE, /* SUN_CKM_SHA256_HMAC_GENERAL */ 128734b6a94Sdarrenm SHA384_MECH_INFO_TYPE, /* SUN_CKM_SHA384 */ 129734b6a94Sdarrenm SHA384_HMAC_MECH_INFO_TYPE, /* SUN_CKM_SHA384_HMAC */ 130734b6a94Sdarrenm SHA384_HMAC_GEN_MECH_INFO_TYPE, /* SUN_CKM_SHA384_HMAC_GENERAL */ 131734b6a94Sdarrenm SHA512_MECH_INFO_TYPE, /* SUN_CKM_SHA512 */ 132734b6a94Sdarrenm SHA512_HMAC_MECH_INFO_TYPE, /* SUN_CKM_SHA512_HMAC */ 133734b6a94Sdarrenm SHA512_HMAC_GEN_MECH_INFO_TYPE /* SUN_CKM_SHA512_HMAC_GENERAL */ 134734b6a94Sdarrenm } sha2_mech_type_t; 135734b6a94Sdarrenm 136734b6a94Sdarrenm #endif /* _SHA2_IMPL */ 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1397c478bd9Sstevel@tonic-gate } 1407c478bd9Sstevel@tonic-gate #endif 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate #endif /* _SYS_SHA2_H */ 143