Changeset 23501 in vbox
- Timestamp:
- Oct 2, 2009 10:59:42 AM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 53140
- Location:
- trunk
- Files:
-
- 3 added
- 3 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/include/iprt/sha.h ¶
r23489 r23501 28 28 */ 29 29 30 #ifndef ___iprt_sha 1_h31 #define ___iprt_sha 1_h32 33 #include <iprt/ cdefs.h>30 #ifndef ___iprt_sha_h 31 #define ___iprt_sha_h 32 33 #include <iprt/types.h> 34 34 35 35 RT_C_DECLS_BEGIN 36 36 37 /** @defgroup grp_rt_sha 1digest RTSha1Digest - SHA1 digest creation37 /** @defgroup grp_rt_sha RTSha - SHA Family of Hash Functions 38 38 * @ingroup grp_rt 39 39 * @{ 40 40 */ 41 41 42 /** The size of a SHA-1 hash. */ 43 #define RTSHA1_HASH_SIZE 20 44 45 /** 46 * SHA-1 context. 47 */ 48 typedef union RTSHA1CONTEXT 49 { 50 uint8_t abPadding[ARCH_BITS == 32 ? 96 : 128]; 51 #ifdef RT_SHA1_PRIVATE_CONTEXT 52 SHA_CTX Private; 53 #endif 54 } RTSHA1CONTEXT; 55 /** Pointer to an SHA-1 context. */ 56 typedef RTSHA1CONTEXT *PRTSHA1CONTEXT; 57 58 /** 59 * Compute the SHA-1 hash of the data. 60 * 61 * @param pvBuf Pointer to the data. 62 * @param cbBuf The amount of data (in bytes). 63 * @param pabDigest Where to store the hash. (What is passed is a pointer to 64 * the caller's buffer.) 65 */ 66 RTDECL(void) RTSha1(const void *pvBuf, size_t cbBuf, uint8_t pabDigest[RTSHA1_HASH_SIZE]); 67 68 /** 69 * Initializes the SHA-1 context. 70 * 71 * @param pCtx Pointer to the SHA-1 context. 72 */ 73 RTDECL(void) RTSha1Init(PRTSHA1CONTEXT pCtx); 74 75 /** 76 * Feed data into the SHA-1 computation. 77 * 78 * @param pCtx Pointer to the SHA-1 context. 79 * @param pvBuf Pointer to the data. 80 * @param cbBuf The length of the data (in bytes). 81 */ 82 RTDECL(void) RTSha1Update(PRTSHA1CONTEXT pCtx, const void *pvBuf, size_t cbBuf); 83 84 /** 85 * Compute the SHA-1 hash of the data. 86 * 87 * @param pCtx Pointer to the SHA-1 context. 88 * @param pabDigest Where to store the hash. (What is passed is a pointer to 89 * the caller's buffer.) 90 */ 91 RTDECL(void) RTSha1Final(PRTSHA1CONTEXT pCtx, uint8_t pabDigest[RTSHA1_HASH_SIZE]); 92 93 42 94 /** 43 95 * Creates a SHA1 digest for the given file. … … 50 102 RTR3DECL(int) RTSha1Digest(const char *pszFile, char **ppszDigest); 51 103 104 105 /** The size of a SHA-256 hash. */ 106 #define RTSHA256_HASH_SIZE 32 107 108 /** 109 * SHA-256 context. 110 */ 111 typedef union RTSHA256CONTEXT 112 { 113 uint8_t abPadding[ARCH_BITS == 32 ? 112 : 160]; 114 #ifdef RT_SHA256_PRIVATE_CONTEXT 115 SHA256_CTX Private; 116 #endif 117 } RTSHA256CONTEXT; 118 /** Pointer to an SHA-256 context. */ 119 typedef RTSHA256CONTEXT *PRTSHA256CONTEXT; 120 121 /** 122 * Compute the SHA-256 hash of the data. 123 * 124 * @param pvBuf Pointer to the data. 125 * @param cbBuf The amount of data (in bytes). 126 * @param pabDigest Where to store the hash. (What is passed is a pointer to 127 * the caller's buffer.) 128 */ 129 RTDECL(void) RTSha256(const void *pvBuf, size_t cbBuf, uint8_t pabDigest[RTSHA256_HASH_SIZE]); 130 131 /** 132 * Initializes the SHA-256 context. 133 * 134 * @param pCtx Pointer to the SHA-256 context. 135 */ 136 RTDECL(void) RTSha256Init(PRTSHA256CONTEXT pCtx); 137 138 /** 139 * Feed data into the SHA-256 computation. 140 * 141 * @param pCtx Pointer to the SHA-256 context. 142 * @param pvBuf Pointer to the data. 143 * @param cbBuf The length of the data (in bytes). 144 */ 145 RTDECL(void) RTSha256Update(PRTSHA256CONTEXT pCtx, const void *pvBuf, size_t cbBuf); 146 147 /** 148 * Compute the SHA-256 hash of the data. 149 * 150 * @param pCtx Pointer to the SHA-256 context. 151 * @param pabDigest Where to store the hash. (What is passed is a pointer to 152 * the caller's buffer.) 153 */ 154 RTDECL(void) RTSha256Final(PRTSHA256CONTEXT pCtx, uint8_t pabDigest[RTSHA256_HASH_SIZE]); 155 156 157 /** The size of a SHA-512 hash. */ 158 #define RTSHA512_HASH_SIZE 64 159 160 /** 161 * SHA-512 context. 162 */ 163 typedef union RTSHA512CONTEXT 164 { 165 uint8_t abPadding[ARCH_BITS == 32 ? 216 : 256]; 166 #ifdef RT_SHA512_PRIVATE_CONTEXT 167 SHA512_CTX Private; 168 #endif 169 } RTSHA512CONTEXT; 170 /** Pointer to an SHA-512 context. */ 171 typedef RTSHA512CONTEXT *PRTSHA512CONTEXT; 172 173 /** 174 * Compute the SHA-512 hash of the data. 175 * 176 * @param pvBuf Pointer to the data. 177 * @param cbBuf The amount of data (in bytes). 178 * @param pabDigest Where to store the hash. (What is passed is a pointer to 179 * the caller's buffer.) 180 */ 181 RTDECL(void) RTSha512(const void *pvBuf, size_t cbBuf, uint8_t pabDigest[RTSHA512_HASH_SIZE]); 182 183 /** 184 * Initializes the SHA-512 context. 185 * 186 * @param pCtx Pointer to the SHA-512 context. 187 */ 188 RTDECL(void) RTSha512Init(PRTSHA512CONTEXT pCtx); 189 190 /** 191 * Feed data into the SHA-512 computation. 192 * 193 * @param pCtx Pointer to the SHA-512 context. 194 * @param pvBuf Pointer to the data. 195 * @param cbBuf The length of the data (in bytes). 196 */ 197 RTDECL(void) RTSha512Update(PRTSHA512CONTEXT pCtx, const void *pvBuf, size_t cbBuf); 198 199 /** 200 * Compute the SHA-512 hash of the data. 201 * 202 * @param pCtx Pointer to the SHA-512 context. 203 * @param pabDigest Where to store the hash. (What is passed is a pointer to 204 * the caller's buffer.) 205 */ 206 RTDECL(void) RTSha512Final(PRTSHA512CONTEXT pCtx, uint8_t pabDigest[RTSHA512_HASH_SIZE]); 207 52 208 /** @} */ 53 209 -
TabularUnified trunk/src/VBox/Runtime/Makefile.kmk ¶
r23452 r23501 848 848 common/misc/s3.cpp \ 849 849 r3/xml.cpp \ 850 common/checksum/RTSha1Digest.cpp \ 851 common/checksum/manifest.cpp \ 850 852 common/checksum/sha1.cpp \ 851 common/checksum/manifest.cpp 853 common/checksum/sha256.cpp \ 854 common/checksum/sha512.cpp 852 855 VBoxRT_SOURCES.$(KBUILD_TARGET) = $(RuntimeR3_SOURCES.$(KBUILD_TARGET)) 853 856 VBoxRT_SOURCES.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH) = $(RuntimeR3_SOURCES.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) -
TabularUnified trunk/src/VBox/Runtime/common/checksum/RTSha1Digest.cpp ¶
r23489 r23501 29 29 */ 30 30 31 #include <iprt/sha1.h> 31 32 /******************************************************************************* 33 * Header Files * 34 *******************************************************************************/ 35 #include "internal/iprt.h" 36 #include <iprt/sha.h> 37 38 #include <iprt/assert.h> 39 #include <iprt/err.h> 32 40 #include <iprt/stream.h> 33 41 #include <iprt/string.h> 34 #include <iprt/assert.h>35 #include <iprt/err.h>36 42 37 43 #include <openssl/sha.h> 38 44 39 /******************************************************************************* 40 * Public RTSha1Digest interface * 41 *******************************************************************************/ 45 42 46 43 47 RTR3DECL(int) RTSha1Digest(const char *pszFile, char **ppszDigest) 44 48 { 45 49 /* Validate input */ 46 if (!pszFile || !ppszDigest) 47 { 48 AssertMsgFailed(("Must supply pszFile and ppszDigest!\n")); 49 return VERR_INVALID_PARAMETER; 50 } 50 AssertPtrReturn(pszFile, VERR_INVALID_POINTER); 51 AssertPtrReturn(ppszDigest, VERR_INVALID_POINTER); 51 52 52 53 *ppszDigest = NULL; … … 56 57 if (!SHA1_Init(&ctx)) 57 58 return VERR_INTERNAL_ERROR; 59 60 /** @todo r=bird: Using a stream here doesn't really serve much purpose as 61 * few stream implementations uses a buffer much larger than 4KB. (The 62 * only I'm aware of is libc on OS/2, which uses 8KB.) */ 58 63 59 64 /* Open the file to calculate a SHA1 sum of */ … … 77 82 break; 78 83 } 79 } 80 while (cbRead > 0); 84 } while (cbRead > 0); 81 85 RTStrmClose(pStream); 82 86 … … 85 89 86 90 /* Finally calculate & format the SHA1 sum */ 87 unsigned char pucDig[20];88 if (!SHA1_Final( pucDig, &ctx))91 unsigned char auchDig[20]; 92 if (!SHA1_Final(auchDig, &ctx)) 89 93 return VERR_INTERNAL_ERROR; 90 94 91 int c bRet= RTStrAPrintf(ppszDigest, "%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x",92 pucDig[0] , pucDig[1] , pucDig[2] , pucDig[3] , pucDig[4],93 pucDig[5] , pucDig[6] , pucDig[7] , pucDig[8] , pucDig[9],94 pucDig[10], pucDig[11], pucDig[12], pucDig[13], pucDig[14],95 pucDig[15], pucDig[16], pucDig[17], pucDig[18], pucDig[19]);96 if (RT_UNLIKELY(c bRet== -1))95 int cch = RTStrAPrintf(ppszDigest, "%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", 96 auchDig[0] , auchDig[1] , auchDig[2] , auchDig[3] , auchDig[4], 97 auchDig[5] , auchDig[6] , auchDig[7] , auchDig[8] , auchDig[9], 98 auchDig[10], auchDig[11], auchDig[12], auchDig[13], auchDig[14], 99 auchDig[15], auchDig[16], auchDig[17], auchDig[18], auchDig[19]); 100 if (RT_UNLIKELY(cch == -1)) 97 101 rc = VERR_INTERNAL_ERROR; 98 102 -
TabularUnified trunk/src/VBox/Runtime/common/checksum/manifest.cpp ¶
r23499 r23501 40 40 #include <iprt/mem.h> 41 41 #include <iprt/path.h> 42 #include <iprt/sha 1.h>42 #include <iprt/sha.h> 43 43 #include <iprt/stream.h> 44 44 #include <iprt/string.h> -
TabularUnified trunk/src/VBox/Runtime/testcase/Makefile.kmk ¶
r23452 r23501 55 55 tstRTCritSect \ 56 56 tstDeadlock \ 57 tstRTDigest \ 57 58 tstDir \ 58 59 tstDir-2 \ … … 167 168 tstDeadlock_SOURCES = tstDeadlock.cpp 168 169 170 tstRTDigest_SOURCES = tstRTDigest.cpp 171 169 172 tstDir_SOURCES = tstDir.cpp 170 173
Note:
See TracChangeset
for help on using the changeset viewer.