1*12720SWyllys.Ingersoll@Sun.COM /* 2*12720SWyllys.Ingersoll@Sun.COM * CDDL HEADER START 3*12720SWyllys.Ingersoll@Sun.COM * 4*12720SWyllys.Ingersoll@Sun.COM * The contents of this file are subject to the terms of the 5*12720SWyllys.Ingersoll@Sun.COM * Common Development and Distribution License (the "License"). 6*12720SWyllys.Ingersoll@Sun.COM * You may not use this file except in compliance with the License. 7*12720SWyllys.Ingersoll@Sun.COM * 8*12720SWyllys.Ingersoll@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*12720SWyllys.Ingersoll@Sun.COM * or http://www.opensolaris.org/os/licensing. 10*12720SWyllys.Ingersoll@Sun.COM * See the License for the specific language governing permissions 11*12720SWyllys.Ingersoll@Sun.COM * and limitations under the License. 12*12720SWyllys.Ingersoll@Sun.COM * 13*12720SWyllys.Ingersoll@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each 14*12720SWyllys.Ingersoll@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*12720SWyllys.Ingersoll@Sun.COM * If applicable, add the following below this CDDL HEADER, with the 16*12720SWyllys.Ingersoll@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying 17*12720SWyllys.Ingersoll@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner] 18*12720SWyllys.Ingersoll@Sun.COM * 19*12720SWyllys.Ingersoll@Sun.COM * CDDL HEADER END 20*12720SWyllys.Ingersoll@Sun.COM */ 21*12720SWyllys.Ingersoll@Sun.COM 22*12720SWyllys.Ingersoll@Sun.COM /* 23*12720SWyllys.Ingersoll@Sun.COM * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 24*12720SWyllys.Ingersoll@Sun.COM */ 25*12720SWyllys.Ingersoll@Sun.COM 26*12720SWyllys.Ingersoll@Sun.COM /** 27*12720SWyllys.Ingersoll@Sun.COM * \file KMSAgentCryptoUtilities.h 28*12720SWyllys.Ingersoll@Sun.COM */ 29*12720SWyllys.Ingersoll@Sun.COM 30*12720SWyllys.Ingersoll@Sun.COM #ifndef KMSAgentCryptoUtilities_H 31*12720SWyllys.Ingersoll@Sun.COM #define KMSAgentCryptoUtilities_H 32*12720SWyllys.Ingersoll@Sun.COM 33*12720SWyllys.Ingersoll@Sun.COM #ifdef WIN32 34*12720SWyllys.Ingersoll@Sun.COM #pragma warning(disable: 4786) 35*12720SWyllys.Ingersoll@Sun.COM #endif 36*12720SWyllys.Ingersoll@Sun.COM 37*12720SWyllys.Ingersoll@Sun.COM #define HASH_LENGTH 20 38*12720SWyllys.Ingersoll@Sun.COM #define HMAC_LENGTH 20 39*12720SWyllys.Ingersoll@Sun.COM 40*12720SWyllys.Ingersoll@Sun.COM /** 41*12720SWyllys.Ingersoll@Sun.COM * Generates a random set of bytes of the specified length. 42*12720SWyllys.Ingersoll@Sun.COM * 43*12720SWyllys.Ingersoll@Sun.COM * @return boolean success indicator 44*12720SWyllys.Ingersoll@Sun.COM */ 45*12720SWyllys.Ingersoll@Sun.COM bool GetPseudorandomBytes( 46*12720SWyllys.Ingersoll@Sun.COM int i_iNumBytes, 47*12720SWyllys.Ingersoll@Sun.COM unsigned char* o_pBytes ); 48*12720SWyllys.Ingersoll@Sun.COM 49*12720SWyllys.Ingersoll@Sun.COM /** 50*12720SWyllys.Ingersoll@Sun.COM * computes SHA-1 hash of the buffer 51*12720SWyllys.Ingersoll@Sun.COM * @param i_pBufferToHash 52*12720SWyllys.Ingersoll@Sun.COM * @param i_iBufferToHashSize 53*12720SWyllys.Ingersoll@Sun.COM * @param o_pHashedBuffer buffer to recieve the SHA-1 hash and must be 54*12720SWyllys.Ingersoll@Sun.COM * #HASH_LENGTH bytes 55*12720SWyllys.Ingersoll@Sun.COM * @return boolean success indicator 56*12720SWyllys.Ingersoll@Sun.COM */ 57*12720SWyllys.Ingersoll@Sun.COM bool HashBuffer( 58*12720SWyllys.Ingersoll@Sun.COM const unsigned char* i_pBufferToHash, 59*12720SWyllys.Ingersoll@Sun.COM int i_iBufferToHashSize, 60*12720SWyllys.Ingersoll@Sun.COM unsigned char* o_pHashedBuffer ); 61*12720SWyllys.Ingersoll@Sun.COM 62*12720SWyllys.Ingersoll@Sun.COM #ifdef METAWARE 63*12720SWyllys.Ingersoll@Sun.COM 64*12720SWyllys.Ingersoll@Sun.COM // implemented in KMSAgentCryptoUtilitiesTreckHmac.c 65*12720SWyllys.Ingersoll@Sun.COM extern "C" int HMACBuffers( 66*12720SWyllys.Ingersoll@Sun.COM int i_iBufferCount, 67*12720SWyllys.Ingersoll@Sun.COM const unsigned char** i_pBufferToHMAC, 68*12720SWyllys.Ingersoll@Sun.COM int* i_pBufferToHMACSize, 69*12720SWyllys.Ingersoll@Sun.COM const unsigned char* i_pHMACKey, 70*12720SWyllys.Ingersoll@Sun.COM int i_iHMACKeySize, 71*12720SWyllys.Ingersoll@Sun.COM unsigned char* o_pHMACBuffer ); 72*12720SWyllys.Ingersoll@Sun.COM 73*12720SWyllys.Ingersoll@Sun.COM #else 74*12720SWyllys.Ingersoll@Sun.COM /** 75*12720SWyllys.Ingersoll@Sun.COM * computes HMAC on the supplied buffers using SHA-1 76*12720SWyllys.Ingersoll@Sun.COM * hashing and the key supplied. No logging is performed since this 77*12720SWyllys.Ingersoll@Sun.COM * functions must execute in a Known Answer Test prior to 78*12720SWyllys.Ingersoll@Sun.COM * #KMSAgent_InitializeLibrary. 79*12720SWyllys.Ingersoll@Sun.COM * @param i_iBufferCount number of buffers provided in #i_pBufferToHMAC 80*12720SWyllys.Ingersoll@Sun.COM * @param i_pBufferToHMAC array of buffers 81*12720SWyllys.Ingersoll@Sun.COM * @param i_pBufferToHMACSize array of sizes corresponding to buffers in 82*12720SWyllys.Ingersoll@Sun.COM * #i_pBufferToHMAC 83*12720SWyllys.Ingersoll@Sun.COM * @param i_pHMACKey secret key 84*12720SWyllys.Ingersoll@Sun.COM * @param i_iHMACKeySize length of the key in bytes 85*12720SWyllys.Ingersoll@Sun.COM * @param o_pHMACBuffer buffer to contain the HMAC, this buffer must be 86*12720SWyllys.Ingersoll@Sun.COM * #HASH_LENGTH bytes 87*12720SWyllys.Ingersoll@Sun.COM * @return boolean success indicator 88*12720SWyllys.Ingersoll@Sun.COM */ 89*12720SWyllys.Ingersoll@Sun.COM bool HMACBuffers( 90*12720SWyllys.Ingersoll@Sun.COM int i_iBufferCount, 91*12720SWyllys.Ingersoll@Sun.COM const unsigned char** i_pBufferToHMAC, 92*12720SWyllys.Ingersoll@Sun.COM int* i_pBufferToHMACSize, 93*12720SWyllys.Ingersoll@Sun.COM const unsigned char* i_pHMACKey, 94*12720SWyllys.Ingersoll@Sun.COM int i_iHMACKeySize, 95*12720SWyllys.Ingersoll@Sun.COM unsigned char* o_pHMACBuffer ); 96*12720SWyllys.Ingersoll@Sun.COM #endif 97*12720SWyllys.Ingersoll@Sun.COM 98*12720SWyllys.Ingersoll@Sun.COM 99*12720SWyllys.Ingersoll@Sun.COM 100*12720SWyllys.Ingersoll@Sun.COM #endif //KMSAgentCryptoUtilities_H 101