VirtualBox

Changeset 23501 in vbox for trunk/src


Ignore:
Timestamp:
Oct 2, 2009 10:59:42 AM (15 years ago)
Author:
vboxsync
Message:

IPRT: Added SHA-1, SHA-256 and SHA-512 APIs. Added a simple digest program for testing these.

Location:
trunk/src/VBox/Runtime
Files:
3 added
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/Makefile.kmk

    r23452 r23501  
    848848        common/misc/s3.cpp \
    849849        r3/xml.cpp \
     850        common/checksum/RTSha1Digest.cpp \
     851        common/checksum/manifest.cpp \
    850852        common/checksum/sha1.cpp \
    851         common/checksum/manifest.cpp
     853        common/checksum/sha256.cpp \
     854        common/checksum/sha512.cpp
    852855VBoxRT_SOURCES.$(KBUILD_TARGET) = $(RuntimeR3_SOURCES.$(KBUILD_TARGET))
    853856VBoxRT_SOURCES.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH) = $(RuntimeR3_SOURCES.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH))
  • trunk/src/VBox/Runtime/common/checksum/RTSha1Digest.cpp

    r23489 r23501  
    2929 */
    3030
    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>
    3240#include <iprt/stream.h>
    3341#include <iprt/string.h>
    34 #include <iprt/assert.h>
    35 #include <iprt/err.h>
    3642
    3743#include <openssl/sha.h>
    3844
    39 /*******************************************************************************
    40 *   Public RTSha1Digest interface                                              *
    41 *******************************************************************************/
     45
    4246
    4347RTR3DECL(int) RTSha1Digest(const char *pszFile, char **ppszDigest)
    4448{
    4549    /* 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);
    5152
    5253    *ppszDigest = NULL;
     
    5657    if (!SHA1_Init(&ctx))
    5758        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.) */
    5863
    5964    /* Open the file to calculate a SHA1 sum of */
     
    7782            break;
    7883        }
    79     }
    80     while (cbRead > 0);
     84    } while (cbRead > 0);
    8185    RTStrmClose(pStream);
    8286
     
    8589
    8690    /* 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))
    8993        return VERR_INTERNAL_ERROR;
    9094
    91     int cbRet = 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(cbRet == -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))
    97101        rc = VERR_INTERNAL_ERROR;
    98102
  • trunk/src/VBox/Runtime/common/checksum/manifest.cpp

    r23499 r23501  
    4040#include <iprt/mem.h>
    4141#include <iprt/path.h>
    42 #include <iprt/sha1.h>
     42#include <iprt/sha.h>
    4343#include <iprt/stream.h>
    4444#include <iprt/string.h>
  • trunk/src/VBox/Runtime/testcase/Makefile.kmk

    r23452 r23501  
    5555        tstRTCritSect \
    5656        tstDeadlock \
     57        tstRTDigest \
    5758        tstDir \
    5859        tstDir-2 \
     
    167168tstDeadlock_SOURCES = tstDeadlock.cpp
    168169
     170tstRTDigest_SOURCES = tstRTDigest.cpp
     171
    169172tstDir_SOURCES = tstDir.cpp
    170173
Note: See TracChangeset for help on using the changeset viewer.

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