10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51694Sdarrenm * Common Development and Distribution License (the "License"). 61694Sdarrenm * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*9364SVladimir.Kotal@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SYS_SHA2_H 270Sstevel@tonic-gate #define _SYS_SHA2_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/types.h> /* for uint_* */ 300Sstevel@tonic-gate 310Sstevel@tonic-gate #ifdef __cplusplus 320Sstevel@tonic-gate extern "C" { 330Sstevel@tonic-gate #endif 340Sstevel@tonic-gate 35*9364SVladimir.Kotal@Sun.COM #define SHA2_HMAC_MIN_KEY_LEN 1 /* SHA2-HMAC min key length in bytes */ 36*9364SVladimir.Kotal@Sun.COM #define SHA2_HMAC_MAX_KEY_LEN INT_MAX /* SHA2-HMAC max key length in bytes */ 371694Sdarrenm 381694Sdarrenm #define SHA256_DIGEST_LENGTH 32 /* SHA256 digest length in bytes */ 391694Sdarrenm #define SHA384_DIGEST_LENGTH 48 /* SHA384 digest length in bytes */ 401694Sdarrenm #define SHA512_DIGEST_LENGTH 64 /* SHA512 digest length in bytes */ 411694Sdarrenm 421694Sdarrenm #define SHA256_HMAC_BLOCK_SIZE 64 /* SHA256-HMAC block size */ 431694Sdarrenm #define SHA512_HMAC_BLOCK_SIZE 128 /* SHA512-HMAC block size */ 441694Sdarrenm 450Sstevel@tonic-gate #define SHA256 0 460Sstevel@tonic-gate #define SHA256_HMAC 1 470Sstevel@tonic-gate #define SHA256_HMAC_GEN 2 480Sstevel@tonic-gate #define SHA384 3 490Sstevel@tonic-gate #define SHA384_HMAC 4 500Sstevel@tonic-gate #define SHA384_HMAC_GEN 5 510Sstevel@tonic-gate #define SHA512 6 520Sstevel@tonic-gate #define SHA512_HMAC 7 530Sstevel@tonic-gate #define SHA512_HMAC_GEN 8 540Sstevel@tonic-gate 551694Sdarrenm /* 561694Sdarrenm * SHA2 context. 571694Sdarrenm * The contents of this structure are a private interface between the 581694Sdarrenm * Init/Update/Final calls of the functions defined below. 591694Sdarrenm * Callers must never attempt to read or write any of the fields 606281Sda73024 * in this structure directly. 611694Sdarrenm */ 620Sstevel@tonic-gate typedef struct { 630Sstevel@tonic-gate uint32_t algotype; /* Algorithm Type */ 640Sstevel@tonic-gate 650Sstevel@tonic-gate /* state (ABCDEFGH) */ 660Sstevel@tonic-gate union { 670Sstevel@tonic-gate uint32_t s32[8]; /* for SHA256 */ 680Sstevel@tonic-gate uint64_t s64[8]; /* for SHA384/512 */ 690Sstevel@tonic-gate } state; 700Sstevel@tonic-gate /* number of bits */ 710Sstevel@tonic-gate union { 720Sstevel@tonic-gate uint32_t c32[2]; /* for SHA256 , modulo 2^64 */ 730Sstevel@tonic-gate uint64_t c64[2]; /* for SHA384/512, modulo 2^128 */ 740Sstevel@tonic-gate } count; 750Sstevel@tonic-gate union { 760Sstevel@tonic-gate uint8_t buf8[128]; /* undigested input */ 770Sstevel@tonic-gate uint32_t buf32[32]; /* realigned input */ 780Sstevel@tonic-gate uint64_t buf64[16]; /* realigned input */ 790Sstevel@tonic-gate } buf_un; 800Sstevel@tonic-gate } SHA2_CTX; 810Sstevel@tonic-gate 821694Sdarrenm typedef SHA2_CTX SHA256_CTX; 831694Sdarrenm typedef SHA2_CTX SHA384_CTX; 841694Sdarrenm typedef SHA2_CTX SHA512_CTX; 851694Sdarrenm 860Sstevel@tonic-gate extern void SHA2Init(uint64_t mech, SHA2_CTX *); 870Sstevel@tonic-gate 881694Sdarrenm extern void SHA2Update(SHA2_CTX *, const void *, size_t); 891694Sdarrenm 901694Sdarrenm extern void SHA2Final(void *, SHA2_CTX *); 911694Sdarrenm 921694Sdarrenm extern void SHA256Init(SHA256_CTX *); 931694Sdarrenm 941694Sdarrenm extern void SHA256Update(SHA256_CTX *, const void *, size_t); 951694Sdarrenm 961694Sdarrenm extern void SHA256Final(void *, SHA256_CTX *); 971694Sdarrenm 981694Sdarrenm extern void SHA384Init(SHA384_CTX *); 991694Sdarrenm 1001694Sdarrenm extern void SHA384Update(SHA384_CTX *, const void *, size_t); 1011694Sdarrenm 1021694Sdarrenm extern void SHA384Final(void *, SHA384_CTX *); 1031694Sdarrenm 1041694Sdarrenm extern void SHA512Init(SHA512_CTX *); 1051694Sdarrenm 1061694Sdarrenm extern void SHA512Update(SHA512_CTX *, const void *, size_t); 1071694Sdarrenm 1081694Sdarrenm extern void SHA512Final(void *, SHA512_CTX *); 1090Sstevel@tonic-gate 1101694Sdarrenm #ifdef _SHA2_IMPL 1111694Sdarrenm /* 1121694Sdarrenm * The following types/functions are all private to the implementation 1131694Sdarrenm * of the SHA2 functions and must not be used by consumers of the interface 1141694Sdarrenm */ 1151694Sdarrenm 1161694Sdarrenm /* 1171694Sdarrenm * List of support mechanisms in this module. 1181694Sdarrenm * 1191694Sdarrenm * It is important to note that in the module, division or modulus calculations 1201694Sdarrenm * are used on the enumerated type to determine which mechanism is being used; 1211694Sdarrenm * therefore, changing the order or additional mechanisms should be done 1221694Sdarrenm * carefully 1231694Sdarrenm */ 1241694Sdarrenm typedef enum sha2_mech_type { 1251694Sdarrenm SHA256_MECH_INFO_TYPE, /* SUN_CKM_SHA256 */ 1261694Sdarrenm SHA256_HMAC_MECH_INFO_TYPE, /* SUN_CKM_SHA256_HMAC */ 1271694Sdarrenm SHA256_HMAC_GEN_MECH_INFO_TYPE, /* SUN_CKM_SHA256_HMAC_GENERAL */ 1281694Sdarrenm SHA384_MECH_INFO_TYPE, /* SUN_CKM_SHA384 */ 1291694Sdarrenm SHA384_HMAC_MECH_INFO_TYPE, /* SUN_CKM_SHA384_HMAC */ 1301694Sdarrenm SHA384_HMAC_GEN_MECH_INFO_TYPE, /* SUN_CKM_SHA384_HMAC_GENERAL */ 1311694Sdarrenm SHA512_MECH_INFO_TYPE, /* SUN_CKM_SHA512 */ 1321694Sdarrenm SHA512_HMAC_MECH_INFO_TYPE, /* SUN_CKM_SHA512_HMAC */ 1331694Sdarrenm SHA512_HMAC_GEN_MECH_INFO_TYPE /* SUN_CKM_SHA512_HMAC_GENERAL */ 1341694Sdarrenm } sha2_mech_type_t; 1351694Sdarrenm 1361694Sdarrenm #endif /* _SHA2_IMPL */ 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate #ifdef __cplusplus 1390Sstevel@tonic-gate } 1400Sstevel@tonic-gate #endif 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate #endif /* _SYS_SHA2_H */ 143