VirtualBox

Ignore:
Timestamp:
Jul 3, 2014 12:16:59 PM (10 years ago)
Author:
vboxsync
Message:

Added alternative SHA-512/224 and SHA-512/256 implementations while at it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/checksum/sha512-alt.cpp

    r51841 r51842  
    481481RT_EXPORT_SYMBOL(RTSha384);
    482482
     483
     484/*
     485 * SHA-512/224 is just SHA-512 with different initial values an a truncated result.
     486 */
     487
     488RTDECL(void) RTSha512t224Init(PRTSHA512T224CONTEXT pCtx)
     489{
     490    pCtx->AltPrivate.cbMessage.s.Lo = 0;
     491    pCtx->AltPrivate.cbMessage.s.Hi = 0;
     492    pCtx->AltPrivate.auH[0] = UINT64_C(0x8c3d37c819544da2);
     493    pCtx->AltPrivate.auH[1] = UINT64_C(0x73e1996689dcd4d6);
     494    pCtx->AltPrivate.auH[2] = UINT64_C(0x1dfab7ae32ff9c82);
     495    pCtx->AltPrivate.auH[3] = UINT64_C(0x679dd514582f9fcf);
     496    pCtx->AltPrivate.auH[4] = UINT64_C(0x0f6d2b697bd44da8);
     497    pCtx->AltPrivate.auH[5] = UINT64_C(0x77e36f7304c48942);
     498    pCtx->AltPrivate.auH[6] = UINT64_C(0x3f9d85a86a1d36c8);
     499    pCtx->AltPrivate.auH[7] = UINT64_C(0x1112e6ad91d692a1);
     500}
     501RT_EXPORT_SYMBOL(RTSha512t224Init);
     502
     503
     504RTDECL(void) RTSha512t224Update(PRTSHA512T224CONTEXT pCtx, const void *pvBuf, size_t cbBuf)
     505{
     506    RTSha512Update(pCtx, pvBuf, cbBuf);
     507}
     508RT_EXPORT_SYMBOL(RTSha512t224Update);
     509
     510
     511RTDECL(void) RTSha512t224Final(PRTSHA512T224CONTEXT pCtx, uint8_t pabDigest[RTSHA512T224_HASH_SIZE])
     512{
     513    rtSha512FinalInternal(pCtx);
     514    memcpy(pabDigest, &pCtx->AltPrivate.auH[0], RTSHA512T224_HASH_SIZE);
     515}
     516RT_EXPORT_SYMBOL(RTSha512t224Final);
     517
     518
     519RTDECL(void) RTSha512t224(const void *pvBuf, size_t cbBuf, uint8_t pabDigest[RTSHA512T224_HASH_SIZE])
     520{
     521    RTSHA512T224CONTEXT Ctx;
     522    RTSha512t224Init(&Ctx);
     523    RTSha512t224Update(&Ctx, pvBuf, cbBuf);
     524    RTSha512t224Final(&Ctx, pabDigest);
     525}
     526RT_EXPORT_SYMBOL(RTSha512t224);
     527
     528
     529/*
     530 * SHA-512/256 is just SHA-512 with different initial values an a truncated result.
     531 */
     532
     533RTDECL(void) RTSha512t256Init(PRTSHA512T256CONTEXT pCtx)
     534{
     535    pCtx->AltPrivate.cbMessage.s.Lo = 0;
     536    pCtx->AltPrivate.cbMessage.s.Hi = 0;
     537    pCtx->AltPrivate.auH[0] = UINT64_C(0x22312194fc2bf72c);
     538    pCtx->AltPrivate.auH[1] = UINT64_C(0x9f555fa3c84c64c2);
     539    pCtx->AltPrivate.auH[2] = UINT64_C(0x2393b86b6f53b151);
     540    pCtx->AltPrivate.auH[3] = UINT64_C(0x963877195940eabd);
     541    pCtx->AltPrivate.auH[4] = UINT64_C(0x96283ee2a88effe3);
     542    pCtx->AltPrivate.auH[5] = UINT64_C(0xbe5e1e2553863992);
     543    pCtx->AltPrivate.auH[6] = UINT64_C(0x2b0199fc2c85b8aa);
     544    pCtx->AltPrivate.auH[7] = UINT64_C(0x0eb72ddc81c52ca2);
     545}
     546RT_EXPORT_SYMBOL(RTSha512t256Init);
     547
     548
     549RTDECL(void) RTSha512t256Update(PRTSHA512T256CONTEXT pCtx, const void *pvBuf, size_t cbBuf)
     550{
     551    RTSha512Update(pCtx, pvBuf, cbBuf);
     552}
     553RT_EXPORT_SYMBOL(RTSha512t256Update);
     554
     555
     556RTDECL(void) RTSha512t256Final(PRTSHA512T256CONTEXT pCtx, uint8_t pabDigest[RTSHA512T256_HASH_SIZE])
     557{
     558    rtSha512FinalInternal(pCtx);
     559    memcpy(pabDigest, &pCtx->AltPrivate.auH[0], RTSHA512T256_HASH_SIZE);
     560}
     561RT_EXPORT_SYMBOL(RTSha512t256Final);
     562
     563
     564RTDECL(void) RTSha512t256(const void *pvBuf, size_t cbBuf, uint8_t pabDigest[RTSHA512T256_HASH_SIZE])
     565{
     566    RTSHA512T256CONTEXT Ctx;
     567    RTSha512t256Init(&Ctx);
     568    RTSha512t256Update(&Ctx, pvBuf, cbBuf);
     569    RTSha512t256Final(&Ctx, pabDigest);
     570}
     571RT_EXPORT_SYMBOL(RTSha512t256);
     572
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