VirtualBox

Changeset 51841 in vbox for trunk/include


Ignore:
Timestamp:
Jul 3, 2014 11:58:27 AM (11 years ago)
Author:
vboxsync
Message:

Alternative SHA-512 and SHA-384 implementation.

Location:
trunk/include/iprt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/mangling.h

    r51840 r51841  
    13361336# define RTSha256Digest                                 RT_MANGLER(RTSha256Digest)
    13371337# define RTSha256DigestFromFile                         RT_MANGLER(RTSha256DigestFromFile)
     1338# define RTSha384                                       RT_MANGLER(RTSha384)
     1339# define RTSha384Final                                  RT_MANGLER(RTSha384Final)
     1340# define RTSha384FromString                             RT_MANGLER(RTSha384FromString)
     1341# define RTSha384Init                                   RT_MANGLER(RTSha384Init)
     1342# define RTSha384ToString                               RT_MANGLER(RTSha384ToString)
     1343# define RTSha384Update                                 RT_MANGLER(RTSha384Update)
    13381344# define RTSha512                                       RT_MANGLER(RTSha512)
    13391345# define RTSha512Final                                  RT_MANGLER(RTSha512Final)
  • trunk/include/iprt/sha.h

    r51838 r51841  
    143143
    144144
     145
    145146/** The size of a SHA-256 hash. */
    146147#define RTSHA256_HASH_SIZE      32
     
    252253
    253254
     255
    254256/** The size of a SHA-224 hash. */
    255257#define RTSHA224_HASH_SIZE      28
     
    347349
    348350
     351
    349352/** The size of a SHA-512 hash. */
    350353#define RTSHA512_HASH_SIZE      64
     
    358361{
    359362    uint64_t                u64BetterAlignment;
    360     uint8_t                 abPadding[ARCH_BITS == 32 ? 216 : 256];
     363    uint8_t                 abPadding[16 + (80 + 8) * 8];
    361364#ifdef RT_SHA512_PRIVATE_CONTEXT
    362365    SHA512_CTX              Private;
     366#endif
     367#ifdef RT_SHA512_PRIVATE_ALT_CONTEXT
     368    RTSHA512ALTPRIVATECTX   AltPrivate;
    363369#endif
    364370} RTSHA512CONTEXT;
     
    425431RTDECL(int) RTSha512FromString(char const *pszDigest, uint8_t pabDigest[RTSHA512_HASH_SIZE]);
    426432
     433
     434
     435/** The size of a SHA-384 hash. */
     436#define RTSHA384_HASH_SIZE      48
     437/** The length of a SHA-384 digest string. The terminator is not included. */
     438#define RTSHA384_DIGEST_LEN     96
     439
     440/** SHA-384 context (same as for SHA-512). */
     441typedef RTSHA512CONTEXT RTSHA384CONTEXT;
     442/** Pointer to an SHA-384 context. */
     443typedef RTSHA512CONTEXT *PRTSHA384CONTEXT;
     444
     445/**
     446 * Compute the SHA-384 hash of the data.
     447 *
     448 * @param   pvBuf       Pointer to the data.
     449 * @param   cbBuf       The amount of data (in bytes).
     450 * @param   pabDigest   Where to store the hash. (What is passed is a pointer to
     451 *                      the caller's buffer.)
     452 */
     453RTDECL(void) RTSha384(const void *pvBuf, size_t cbBuf, uint8_t pabDigest[RTSHA384_HASH_SIZE]);
     454
     455/**
     456 * Initializes the SHA-384 context.
     457 *
     458 * @param   pCtx        Pointer to the SHA-384 context.
     459 */
     460RTDECL(void) RTSha384Init(PRTSHA384CONTEXT pCtx);
     461
     462/**
     463 * Feed data into the SHA-384 computation.
     464 *
     465 * @param   pCtx        Pointer to the SHA-384 context.
     466 * @param   pvBuf       Pointer to the data.
     467 * @param   cbBuf       The length of the data (in bytes).
     468 */
     469RTDECL(void) RTSha384Update(PRTSHA384CONTEXT pCtx, const void *pvBuf, size_t cbBuf);
     470
     471/**
     472 * Compute the SHA-384 hash of the data.
     473 *
     474 * @param   pCtx        Pointer to the SHA-384 context.
     475 * @param   pabDigest   Where to store the hash. (What is passed is a pointer to
     476 *                      the caller's buffer.)
     477 */
     478RTDECL(void) RTSha384Final(PRTSHA384CONTEXT pCtx, uint8_t pabDigest[RTSHA384_HASH_SIZE]);
     479
     480/**
     481 * Converts a SHA-384 hash to a digest string.
     482 *
     483 * @returns IPRT status code.
     484 *
     485 * @param   pabDigest   The binary digest returned by RTSha384Final or RTSha384.
     486 * @param   pszDigest   Where to return the stringified digest.
     487 * @param   cchDigest   The size of the output buffer. Should be at least
     488 *                      RTSHA384_DIGEST_LEN + 1 bytes.
     489 */
     490RTDECL(int) RTSha384ToString(uint8_t const pabDigest[RTSHA384_HASH_SIZE], char *pszDigest, size_t cchDigest);
     491
     492/**
     493 * Converts a SHA-384 hash to a digest string.
     494 *
     495 * @returns IPRT status code.
     496 *
     497 * @param   pszDigest   The stringified digest. Leading and trailing spaces are
     498 *                      ignored.
     499 * @param   pabDigest   Where to store the hash. (What is passed is a pointer to
     500 *                      the caller's buffer.)
     501 */
     502RTDECL(int) RTSha384FromString(char const *pszDigest, uint8_t pabDigest[RTSHA384_HASH_SIZE]);
     503
     504/**
     505 * Creates a SHA384 digest for the given memory buffer.
     506 *
     507 * @returns iprt status code.
     508 *
     509 * @param   pvBuf                 Memory buffer to create a SHA384 digest for.
     510 * @param   cbBuf                 The amount of data (in bytes).
     511 * @param   ppszDigest            On success the SHA384 digest.
     512 * @param   pfnProgressCallback   optional callback for the progress indication
     513 * @param   pvUser                user defined pointer for the callback
     514 */
     515RTR3DECL(int) RTSha384Digest(void* pvBuf, size_t cbBuf, char **ppszDigest, PFNRTPROGRESS pfnProgressCallback, void *pvUser);
     516
     517/**
     518 * Creates a SHA384 digest for the given file.
     519 *
     520 * @returns iprt status code.
     521 *
     522 * @param   pszFile               Filename to create a SHA384 digest for.
     523 * @param   ppszDigest            On success the SHA384 digest.
     524 * @param   pfnProgressCallback   optional callback for the progress indication
     525 * @param   pvUser                user defined pointer for the callback
     526 */
     527RTR3DECL(int) RTSha384DigestFromFile(const char *pszFile, char **ppszDigest, PFNRTPROGRESS pfnProgressCallback, void *pvUser);
     528
     529
     530
    427531/** @} */
    428532
    429533RT_C_DECLS_END
    430534
    431 #endif /* ___iprt_sha1_h */
    432 
     535#endif
     536
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