1 /*
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 /*
23  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 /**
27  * \file KMSAgentCryptoUtilities.h
28  */
29 
30 #ifndef KMSAgentCryptoUtilities_H
31 #define KMSAgentCryptoUtilities_H
32 
33 #ifdef WIN32
34 #pragma warning(disable: 4786)
35 #endif
36 
37 #define HASH_LENGTH     20
38 #define HMAC_LENGTH     20
39 
40 /**
41  *  Generates a random set of bytes of the specified length.
42  *
43  *  @return boolean success indicator
44  */
45 bool GetPseudorandomBytes(
46         int i_iNumBytes,
47         unsigned char* o_pBytes );
48 
49 /**
50  *  computes SHA-1 hash of the buffer
51  *  @param i_pBufferToHash
52  *  @param i_iBufferToHashSize
53  *  @param o_pHashedBuffer buffer to recieve the SHA-1 hash and must be
54  *          #HASH_LENGTH bytes
55  *  @return boolean success indicator
56  */
57 bool HashBuffer(
58         const unsigned char* i_pBufferToHash,
59         int i_iBufferToHashSize,
60         unsigned char* o_pHashedBuffer );
61 
62 #ifdef METAWARE
63 
64 // implemented in KMSAgentCryptoUtilitiesTreckHmac.c
65 extern "C" int HMACBuffers(
66    int i_iBufferCount,
67    const unsigned char** i_pBufferToHMAC,
68    int* i_pBufferToHMACSize,
69    const unsigned char* i_pHMACKey,
70    int i_iHMACKeySize,
71    unsigned char* o_pHMACBuffer );
72 
73 #else
74 /**
75  *  computes HMAC on the supplied buffers using SHA-1
76  *  hashing and the key supplied.  No logging is performed since this
77  *  functions must execute in a Known Answer Test prior to
78  *  #KMSAgent_InitializeLibrary.
79  *  @param i_iBufferCount number of buffers provided in #i_pBufferToHMAC
80  *  @param i_pBufferToHMAC array of buffers
81  *  @param i_pBufferToHMACSize array of sizes corresponding to buffers in
82  *      #i_pBufferToHMAC
83  *  @param i_pHMACKey secret key
84  *  @param i_iHMACKeySize  length of the key in bytes
85  *  @param o_pHMACBuffer  buffer to contain the HMAC, this buffer must be
86  *      #HASH_LENGTH bytes
87  *  @return boolean success indicator
88  */
89 bool HMACBuffers(
90         int i_iBufferCount,
91         const unsigned char** i_pBufferToHMAC,
92         int* i_pBufferToHMACSize,
93         const unsigned char* i_pHMACKey,
94         int i_iHMACKeySize,
95         unsigned char* o_pHMACBuffer );
96 #endif
97 
98 
99 
100 #endif //KMSAgentCryptoUtilities_H
101