Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 1 | /* |
Jeff Johnson | 32d95a3 | 2012-09-10 13:15:23 -0700 | [diff] [blame^] | 2 | * Copyright (c) 2012, The Linux Foundation. All rights reserved. |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 3 | * |
| 4 | * Previously licensed under the ISC license by Qualcomm Atheros, Inc. |
| 5 | * |
| 6 | * |
| 7 | * Permission to use, copy, modify, and/or distribute this software for |
| 8 | * any purpose with or without fee is hereby granted, provided that the |
| 9 | * above copyright notice and this permission notice appear in all |
| 10 | * copies. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 13 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 15 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 16 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 17 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 18 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 19 | * PERFORMANCE OF THIS SOFTWARE. |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * */ |
| 24 | #if !defined( __VOS_UTILS_H ) |
| 25 | #define __VOS_UTILS_H |
| 26 | |
| 27 | /**========================================================================= |
| 28 | |
| 29 | \file vos_utils.h |
| 30 | |
| 31 | \brief virtual Operating System Services (vOSS) utility APIs |
| 32 | |
| 33 | Various utility functions |
| 34 | |
| 35 | Copyright 2008 (c) Qualcomm, Incorporated. All Rights Reserved. |
| 36 | |
| 37 | Qualcomm Confidential and Proprietary. |
| 38 | |
| 39 | ========================================================================*/ |
| 40 | |
| 41 | /* $Header$ */ |
| 42 | |
| 43 | /*-------------------------------------------------------------------------- |
| 44 | Include Files |
| 45 | ------------------------------------------------------------------------*/ |
| 46 | #include <vos_types.h> |
| 47 | #include <vos_status.h> |
| 48 | //#include <Wincrypt.h> |
| 49 | |
| 50 | /*-------------------------------------------------------------------------- |
| 51 | Preprocessor definitions and constants |
| 52 | ------------------------------------------------------------------------*/ |
| 53 | #define VOS_DIGEST_SHA1_SIZE 20 |
| 54 | #define VOS_DIGEST_MD5_SIZE 16 |
| 55 | |
| 56 | /*-------------------------------------------------------------------------- |
| 57 | Type declarations |
| 58 | ------------------------------------------------------------------------*/ |
| 59 | |
| 60 | |
| 61 | /*------------------------------------------------------------------------- |
| 62 | Function declarations and documenation |
| 63 | ------------------------------------------------------------------------*/ |
| 64 | |
| 65 | VOS_STATUS vos_crypto_init( v_U32_t *phCryptProv ); |
| 66 | |
| 67 | VOS_STATUS vos_crypto_deinit( v_U32_t hCryptProv ); |
| 68 | |
| 69 | |
| 70 | |
| 71 | /** |
| 72 | * vos_rand_get_bytes |
| 73 | |
| 74 | * FUNCTION: |
| 75 | * Returns cryptographically secure pseudo-random bytes. |
| 76 | * |
| 77 | * |
| 78 | * @param pbBuf - the caller allocated location where the bytes should be copied |
| 79 | * @param numBytes the number of bytes that should be generated and |
| 80 | * copied |
| 81 | * |
| 82 | * @return VOS_STATUS_SUCCSS if the operation succeeds |
| 83 | */ |
| 84 | VOS_STATUS vos_rand_get_bytes( v_U32_t handle, v_U8_t *pbBuf, v_U32_t numBytes ); |
| 85 | |
| 86 | |
| 87 | /** |
| 88 | * vos_sha1_hmac_str |
| 89 | * |
| 90 | * FUNCTION: |
| 91 | * Generate the HMAC-SHA1 of a string given a key. |
| 92 | * |
| 93 | * LOGIC: |
| 94 | * Standard HMAC processing from RFC 2104. The code is provided in the |
| 95 | * appendix of the RFC. |
| 96 | * |
| 97 | * ASSUMPTIONS: |
| 98 | * The RFC is correct. |
| 99 | * |
| 100 | * @param text text to be hashed |
| 101 | * @param textLen length of text |
| 102 | * @param key key to use for HMAC |
| 103 | * @param keyLen length of key |
| 104 | * @param digest holds resultant SHA1 HMAC (20B) |
| 105 | * |
| 106 | * @return VOS_STATUS_SUCCSS if the operation succeeds |
| 107 | * |
| 108 | */ |
| 109 | VOS_STATUS vos_sha1_hmac_str(v_U32_t cryptHandle, /* Handle */ |
| 110 | v_U8_t *text, /* pointer to data stream */ |
| 111 | v_U32_t textLen, /* length of data stream */ |
| 112 | v_U8_t *key, /* pointer to authentication key */ |
| 113 | v_U32_t keyLen, /* length of authentication key */ |
| 114 | v_U8_t digest[VOS_DIGEST_SHA1_SIZE]);/* caller digest to be filled in */ |
| 115 | |
| 116 | /** |
| 117 | * vos_md5_hmac_str |
| 118 | * |
| 119 | * FUNCTION: |
| 120 | * Generate the HMAC-MD5 of a string given a key. |
| 121 | * |
| 122 | * LOGIC: |
| 123 | * Standard HMAC processing from RFC 2104. The code is provided in the |
| 124 | * appendix of the RFC. |
| 125 | * |
| 126 | * ASSUMPTIONS: |
| 127 | * The RFC is correct. |
| 128 | * |
| 129 | * @param text text to be hashed |
| 130 | * @param textLen length of text |
| 131 | * @param key key to use for HMAC |
| 132 | * @param keyLen length of key |
| 133 | * @param digest holds resultant MD5 HMAC (16B) |
| 134 | * |
| 135 | * @return VOS_STATUS_SUCCSS if the operation succeeds |
| 136 | * |
| 137 | */ |
| 138 | VOS_STATUS vos_md5_hmac_str(v_U32_t cryptHandle, /* Handle */ |
| 139 | v_U8_t *text, /* pointer to data stream */ |
| 140 | v_U32_t textLen, /* length of data stream */ |
| 141 | v_U8_t *key, /* pointer to authentication key */ |
| 142 | v_U32_t keyLen, /* length of authentication key */ |
| 143 | v_U8_t digest[VOS_DIGEST_MD5_SIZE]);/* caller digest to be filled in */ |
| 144 | |
| 145 | |
| 146 | |
| 147 | VOS_STATUS vos_encrypt_AES(v_U32_t cryptHandle, /* Handle */ |
| 148 | v_U8_t *pText, /* pointer to data stream */ |
| 149 | v_U8_t *Encrypted, |
| 150 | v_U8_t *pKey); /* pointer to authentication key */ |
| 151 | |
| 152 | |
| 153 | VOS_STATUS vos_decrypt_AES(v_U32_t cryptHandle, /* Handle */ |
| 154 | v_U8_t *pText, /* pointer to data stream */ |
| 155 | v_U8_t *pDecrypted, |
| 156 | v_U8_t *pKey); /* pointer to authentication key */ |
| 157 | |
| 158 | #endif // #if !defined __VOSS_UTILS_H |