VirtualBox

Ignore:
Timestamp:
Jul 3, 2014 2:01:28 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
94702
Message:

Renamed hash implementations to fit better into the build system, supplying the missing OpenSSL-based MD5. VBoxRT uses the OpenSSL variants, all other libraries uses the alternatives. Also removed stupid OpenSSL dependencies in RTSha1Digest.cpp and RTSha256Digest.cpp.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/checksum/RTSha256Digest.cpp

    r45234 r51851  
    11/** @file
    22 * IPRT - SHA256 digest creation
     3 *
     4 * @todo Replace this with generic RTCrDigest based implementation. Too much
     5 *       stupid code duplication.
    36 */
    47
    58/*
    6  * Copyright (C) 2009-2013 Oracle Corporation
     9 * Copyright (C) 2009-2014 Oracle Corporation
    710 *
    811 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3740#include <iprt/file.h>
    3841
    39 #include <openssl/sha.h>
    40 
    4142
    4243RTR3DECL(int) RTSha256Digest(void* pvBuf, size_t cbBuf, char **ppszDigest, PFNRTPROGRESS pfnProgressCallback, void *pvUser)
     
    5051    *ppszDigest = NULL;
    5152
    52     /* Initialize OpenSSL. */
    53     SHA256_CTX ctx;
    54     if (!SHA256_Init(&ctx))
    55         return VERR_INTERNAL_ERROR;
     53    /* Initialize the hash context. */
     54    RTSHA256CONTEXT Ctx;
     55    RTSha256Init(&Ctx);
    5656
    5757    /* Buffer size for progress callback */
    58     double rdMulti = 100.0 / cbBuf;
     58    double rdMulti = 100.0 / (cbBuf ? cbBuf : 1);
    5959
    6060    /* Working buffer */
     
    6262
    6363    /* Process the memory in blocks */
    64     size_t cbRead;
    6564    size_t cbReadTotal = 0;
    6665    for (;;)
    6766    {
    68         cbRead = RT_MIN(cbBuf - cbReadTotal, _1M);
    69         if(!SHA256_Update(&ctx, pvTmp, cbRead))
    70         {
    71             rc = VERR_INTERNAL_ERROR;
    72             break;
    73         }
     67        size_t cbRead = RT_MIN(cbBuf - cbReadTotal, _1M);
     68        RTSha256Update(&Ctx, pvTmp, cbRead);
    7469        cbReadTotal += cbRead;
    7570        pvTmp += cbRead;
     
    8984    {
    9085        /* Finally calculate & format the SHA256 sum */
    91         unsigned char auchDig[RTSHA256_HASH_SIZE];
    92         if (!SHA256_Final(auchDig, &ctx))
    93             return VERR_INTERNAL_ERROR;
     86        uint8_t abHash[RTSHA256_HASH_SIZE];
     87        RTSha256Final(&Ctx, abHash);
    9488
    9589        char *pszDigest;
     
    9791        if (RT_SUCCESS(rc))
    9892        {
    99             rc = RTSha256ToString(auchDig, pszDigest, RTSHA256_DIGEST_LEN + 1);
     93            rc = RTSha256ToString(abHash, pszDigest, RTSHA256_DIGEST_LEN + 1);
    10094            if (RT_SUCCESS(rc))
    10195                *ppszDigest = pszDigest;
     
    117111    *ppszDigest = NULL;
    118112
    119     /* Initialize OpenSSL. */
    120     SHA256_CTX ctx;
    121     if (!SHA256_Init(&ctx))
    122         return VERR_INTERNAL_ERROR;
     113    /* Initialize the hash context. */
     114    RTSHA256CONTEXT Ctx;
     115    RTSha256Init(&Ctx);
    123116
    124117    /* Open the file to calculate a SHA256 sum of */
     
    139132            return rc;
    140133        }
    141         rdMulti = 100.0 / cbFile;
     134        rdMulti = 100.0 / (cbFile ? cbFile : 1);
    142135    }
    143136
     
    153146
    154147    /* Read that file in blocks */
    155     size_t cbRead;
    156148    size_t cbReadTotal = 0;
    157149    for (;;)
    158150    {
     151        size_t cbRead;
    159152        rc = RTFileRead(hFile, pvBuf, cbBuf, &cbRead);
    160153        if (RT_FAILURE(rc) || !cbRead)
    161154            break;
    162         if(!SHA256_Update(&ctx, pvBuf, cbRead))
    163         {
    164             rc = VERR_INTERNAL_ERROR;
    165             break;
    166         }
     155        RTSha256Update(&Ctx, pvBuf, cbRead);
    167156        cbReadTotal += cbRead;
    168157
     
    182171
    183172    /* Finally calculate & format the SHA256 sum */
    184     unsigned char auchDig[RTSHA256_HASH_SIZE];
    185     if (!SHA256_Final(auchDig, &ctx))
    186         return VERR_INTERNAL_ERROR;
     173    uint8_t abHash[RTSHA256_HASH_SIZE];
     174    RTSha256Final(&Ctx, abHash);
    187175
    188176    char *pszDigest;
     
    190178    if (RT_SUCCESS(rc))
    191179    {
    192         rc = RTSha256ToString(auchDig, pszDigest, RTSHA256_DIGEST_LEN + 1);
     180        rc = RTSha256ToString(abHash, pszDigest, RTSHA256_DIGEST_LEN + 1);
    193181        if (RT_SUCCESS(rc))
    194182            *ppszDigest = pszDigest;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette