- Timestamp:
- Jul 3, 2014 6:39:21 PM (11 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 8 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/Makefile.kmk
r51851 r51856 317 317 common/checksum/RTSha256Digest.cpp \ 318 318 common/checksum/sha1str.cpp \ 319 common/checksum/sha224str.cpp \ 319 320 common/checksum/sha256str.cpp \ 321 common/checksum/sha384str.cpp \ 320 322 common/checksum/sha512str.cpp \ 323 common/checksum/sha512t224str.cpp \ 324 common/checksum/sha512t256str.cpp \ 321 325 common/checksum/x509.cpp \ 322 326 common/crypto/digest-core.cpp \ … … 1411 1415 VBoxRT_INST = $(INST_DLL) $(INST_TESTCASE) 1412 1416 endif 1413 VBoxRT_DEFS := $(filter-out RT_NO_GIP,$(RuntimeR3_DEFS)) IN_SUP_R3 IN_SUP_R3 IPRT_WITH_XAR 1417 VBoxRT_DEFS := $(filter-out RT_NO_GIP, $(RuntimeR3_DEFS)) \ 1418 IN_SUP_R3 IN_SUP_R3 IPRT_WITH_XAR \ 1419 $(if-expr !defined(VBOX_WITH_ALT_HASH_CODE),IPRT_WITHOUT_SHA512T224 IPRT_WITHOUT_SHA512T256,) 1414 1420 ifn1of ($(KBUILD_TARGET_ARCH), amd64 x86) 1415 1421 VBoxRT_DEFS += RT_NO_GIP … … 1422 1428 VBox/VBoxRTDeps.cpp \ 1423 1429 $(filter-out common/checksum/crc32.cpp, \ 1424 $(patsubst common/checksum/alt-%,common/checksum/openssl-%,$(RuntimeR3_SOURCES))) \ 1430 $(if-expr defined(VBOX_WITH_ALT_HASH_CODE), $(RuntimeR3_SOURCES), \ 1431 $(patsubst common/checksum/alt-%,common/checksum/openssl-%,$(RuntimeR3_SOURCES)) ) ) \ 1425 1432 common/checksum/crc32-zlib.cpp \ 1426 1433 common/misc/aiomgr.cpp … … 2040 2047 common/checksum/md5str.cpp \ 2041 2048 common/checksum/sha1str.cpp \ 2049 common/checksum/sha224str.cpp \ 2042 2050 common/checksum/sha256str.cpp \ 2051 common/checksum/sha384str.cpp \ 2043 2052 common/checksum/sha512str.cpp \ 2053 common/checksum/sha512t224str.cpp \ 2054 common/checksum/sha512t256str.cpp \ 2044 2055 common/err/errinfo.cpp \ 2045 2056 common/path/RTPathChangeToUnixSlashes.cpp \ -
trunk/src/VBox/Runtime/common/checksum/openssl-sha256.cpp
r51851 r51856 71 71 RT_EXPORT_SYMBOL(RTSha256Final); 72 72 73 74 /* 75 * We have to expose the same API as alt-sha256.cpp, so the SHA-224 76 * implementation also lives here. (SHA-224 is just a truncated SHA-256 with 77 * different initial values.) 78 */ 79 RTDECL(void) RTSha224(const void *pvBuf, size_t cbBuf, uint8_t pabDigest[RTSHA224_HASH_SIZE]) 80 { 81 RTSHA224CONTEXT Ctx; 82 RTSha224Init(&Ctx); 83 RTSha224Update(&Ctx, pvBuf, cbBuf); 84 RTSha224Final(&Ctx, pabDigest); 85 } 86 RT_EXPORT_SYMBOL(RTSha224); 87 88 89 RTDECL(void) RTSha224Init(PRTSHA224CONTEXT pCtx) 90 { 91 SHA224_Init(&pCtx->Private); 92 } 93 RT_EXPORT_SYMBOL(RTSha224Init); 94 95 96 RTDECL(void) RTSha224Update(PRTSHA224CONTEXT pCtx, const void *pvBuf, size_t cbBuf) 97 { 98 SHA224_Update(&pCtx->Private, pvBuf, cbBuf); 99 } 100 RT_EXPORT_SYMBOL(RTSha224Update); 101 102 103 RTDECL(void) RTSha224Final(PRTSHA224CONTEXT pCtx, uint8_t pabDigest[32]) 104 { 105 SHA224_Final((unsigned char *)&pabDigest[0], &pCtx->Private); 106 } 107 RT_EXPORT_SYMBOL(RTSha224Final); 108 -
trunk/src/VBox/Runtime/common/checksum/openssl-sha512.cpp
r51851 r51856 71 71 RT_EXPORT_SYMBOL(RTSha512Final); 72 72 73 74 /* 75 * We have to expose the same API as alt-sha512.cpp, so the SHA-384, 76 * SHA-512/224 and SHA-512/256 implementations also live here. (They are all 77 * just truncted SHA-512 with different initial values.) 78 */ 79 80 RTDECL(void) RTSha384(const void *pvBuf, size_t cbBuf, uint8_t pabDigest[RTSHA384_HASH_SIZE]) 81 { 82 RTSHA384CONTEXT Ctx; 83 RTSha384Init(&Ctx); 84 RTSha384Update(&Ctx, pvBuf, cbBuf); 85 RTSha384Final(&Ctx, pabDigest); 86 } 87 RT_EXPORT_SYMBOL(RTSha384); 88 89 90 RTDECL(void) RTSha384Init(PRTSHA384CONTEXT pCtx) 91 { 92 SHA384_Init(&pCtx->Private); 93 } 94 RT_EXPORT_SYMBOL(RTSha384Init); 95 96 97 RTDECL(void) RTSha384Update(PRTSHA384CONTEXT pCtx, const void *pvBuf, size_t cbBuf) 98 { 99 SHA384_Update(&pCtx->Private, pvBuf, cbBuf); 100 } 101 RT_EXPORT_SYMBOL(RTSha384Update); 102 103 104 RTDECL(void) RTSha384Final(PRTSHA384CONTEXT pCtx, uint8_t pabDigest[32]) 105 { 106 SHA384_Final((unsigned char *)&pabDigest[0], &pCtx->Private); 107 } 108 RT_EXPORT_SYMBOL(RTSha384Final); 109 110 -
trunk/src/VBox/Runtime/common/checksum/sha224str.cpp
r51837 r51856 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - SHA-2 56string functions.3 * IPRT - SHA-224 string functions. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2009-201 0Oracle Corporation7 * Copyright (C) 2009-2014 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 37 37 38 38 39 RTDECL(int) RTSha2 56ToString(uint8_t const pabDigest[RTSHA256_HASH_SIZE], char *pszDigest, size_t cchDigest)39 RTDECL(int) RTSha224ToString(uint8_t const pabDigest[RTSHA224_HASH_SIZE], char *pszDigest, size_t cchDigest) 40 40 { 41 return RTStrPrintHexBytes(pszDigest, cchDigest, &pabDigest[0], RTSHA2 56_HASH_SIZE, 0 /*fFlags*/);41 return RTStrPrintHexBytes(pszDigest, cchDigest, &pabDigest[0], RTSHA224_HASH_SIZE, 0 /*fFlags*/); 42 42 } 43 43 44 44 45 RTDECL(int) RTSha2 56FromString(char const *pszDigest, uint8_t pabDigest[RTSHA256_HASH_SIZE])45 RTDECL(int) RTSha224FromString(char const *pszDigest, uint8_t pabDigest[RTSHA224_HASH_SIZE]) 46 46 { 47 return RTStrConvertHexBytes(RTStrStripL(pszDigest), &pabDigest[0], RTSHA2 56_HASH_SIZE, 0 /*fFlags*/);47 return RTStrConvertHexBytes(RTStrStripL(pszDigest), &pabDigest[0], RTSHA224_HASH_SIZE, 0 /*fFlags*/); 48 48 } 49 49 -
trunk/src/VBox/Runtime/common/checksum/sha384str.cpp
r51837 r51856 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - SHA- 256string functions.3 * IPRT - SHA-384 string functions. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2009-201 0Oracle Corporation7 * Copyright (C) 2009-2014 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 37 37 38 38 39 RTDECL(int) RTSha 256ToString(uint8_t const pabDigest[RTSHA256_HASH_SIZE], char *pszDigest, size_t cchDigest)39 RTDECL(int) RTSha384ToString(uint8_t const pabDigest[RTSHA384_HASH_SIZE], char *pszDigest, size_t cchDigest) 40 40 { 41 return RTStrPrintHexBytes(pszDigest, cchDigest, &pabDigest[0], RTSHA 256_HASH_SIZE, 0 /*fFlags*/);41 return RTStrPrintHexBytes(pszDigest, cchDigest, &pabDigest[0], RTSHA384_HASH_SIZE, 0 /*fFlags*/); 42 42 } 43 43 44 44 45 RTDECL(int) RTSha 256FromString(char const *pszDigest, uint8_t pabDigest[RTSHA256_HASH_SIZE])45 RTDECL(int) RTSha384FromString(char const *pszDigest, uint8_t pabDigest[RTSHA384_HASH_SIZE]) 46 46 { 47 return RTStrConvertHexBytes(RTStrStripL(pszDigest), &pabDigest[0], RTSHA 256_HASH_SIZE, 0 /*fFlags*/);47 return RTStrConvertHexBytes(RTStrStripL(pszDigest), &pabDigest[0], RTSHA384_HASH_SIZE, 0 /*fFlags*/); 48 48 } 49 49 -
trunk/src/VBox/Runtime/common/checksum/sha512t224str.cpp
r51837 r51856 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - SHA- 256string functions.3 * IPRT - SHA-512/224 string functions. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2009-201 0Oracle Corporation7 * Copyright (C) 2009-2014 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 37 37 38 38 39 RTDECL(int) RTSha 256ToString(uint8_t const pabDigest[RTSHA256_HASH_SIZE], char *pszDigest, size_t cchDigest)39 RTDECL(int) RTSha512t224ToString(uint8_t const pabDigest[RTSHA512T224_HASH_SIZE], char *pszDigest, size_t cchDigest) 40 40 { 41 return RTStrPrintHexBytes(pszDigest, cchDigest, &pabDigest[0], RTSHA 256_HASH_SIZE, 0 /*fFlags*/);41 return RTStrPrintHexBytes(pszDigest, cchDigest, &pabDigest[0], RTSHA512T224_HASH_SIZE, 0 /*fFlags*/); 42 42 } 43 43 44 44 45 RTDECL(int) RTSha 256FromString(char const *pszDigest, uint8_t pabDigest[RTSHA256_HASH_SIZE])45 RTDECL(int) RTSha512t224FromString(char const *pszDigest, uint8_t pabDigest[RTSHA512T224_HASH_SIZE]) 46 46 { 47 return RTStrConvertHexBytes(RTStrStripL(pszDigest), &pabDigest[0], RTSHA 256_HASH_SIZE, 0 /*fFlags*/);47 return RTStrConvertHexBytes(RTStrStripL(pszDigest), &pabDigest[0], RTSHA512T224_HASH_SIZE, 0 /*fFlags*/); 48 48 } 49 49 -
trunk/src/VBox/Runtime/common/checksum/sha512t256str.cpp
r51837 r51856 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - SHA- 256 string functions.3 * IPRT - SHA-512/256 string functions. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2009-201 0Oracle Corporation7 * Copyright (C) 2009-2014 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 37 37 38 38 39 RTDECL(int) RTSha 256ToString(uint8_t const pabDigest[RTSHA256_HASH_SIZE], char *pszDigest, size_t cchDigest)39 RTDECL(int) RTSha512t256ToString(uint8_t const pabDigest[RTSHA512T256_HASH_SIZE], char *pszDigest, size_t cchDigest) 40 40 { 41 return RTStrPrintHexBytes(pszDigest, cchDigest, &pabDigest[0], RTSHA 256_HASH_SIZE, 0 /*fFlags*/);41 return RTStrPrintHexBytes(pszDigest, cchDigest, &pabDigest[0], RTSHA512T256_HASH_SIZE, 0 /*fFlags*/); 42 42 } 43 43 44 44 45 RTDECL(int) RTSha 256FromString(char const *pszDigest, uint8_t pabDigest[RTSHA256_HASH_SIZE])45 RTDECL(int) RTSha512t256FromString(char const *pszDigest, uint8_t pabDigest[RTSHA512T256_HASH_SIZE]) 46 46 { 47 return RTStrConvertHexBytes(RTStrStripL(pszDigest), &pabDigest[0], RTSHA 256_HASH_SIZE, 0 /*fFlags*/);47 return RTStrConvertHexBytes(RTStrStripL(pszDigest), &pabDigest[0], RTSHA512T256_HASH_SIZE, 0 /*fFlags*/); 48 48 } 49 49 -
trunk/src/VBox/Runtime/common/crypto/digest-builtin.cpp
r51820 r51856 303 303 304 304 305 /* 306 * SHA-224 307 */ 308 309 /** @impl_interface_method{RTCRDIGESTDESC::pfnUpdate} */ 310 static DECLCALLBACK(void) rtCrDigestSha224_Update(void *pvState, const void *pvData, size_t cbData) 311 { 312 RTSha224Update((PRTSHA224CONTEXT)pvState, pvData, cbData); 313 } 314 315 /** @impl_interface_method{RTCRDIGESTDESC::pfnFinal} */ 316 static DECLCALLBACK(void) rtCrDigestSha224_Final(void *pvState, uint8_t *pbHash) 317 { 318 RTSha224Final((PRTSHA224CONTEXT)pvState, pbHash); 319 } 320 321 /** @impl_interface_method{RTCRDIGESTDESC::pfnInit} */ 322 static DECLCALLBACK(int) rtCrDigestSha224_Init(void *pvState, void *pvOpaque, bool fReInit) 323 { 324 AssertReturn(pvOpaque == NULL, VERR_INVALID_PARAMETER); 325 RTSha224Init((PRTSHA224CONTEXT)pvState); 326 return VINF_SUCCESS; 327 } 328 329 /** SHA-224 alias ODIs. */ 330 static const char * const g_apszSha224Aliases[] = 331 { 332 RTCR_PKCS1_SHA224_WITH_RSA_OID, 333 NULL 334 }; 335 336 /** SHA-224 descriptor. */ 337 static RTCRDIGESTDESC const g_rtCrDigestSha224Desc = 338 { 339 "sha-224", 340 "2.16.840.1.101.3.4.2.4", 341 g_apszSha224Aliases, 342 RTDIGESTTYPE_SHA224, 343 RTSHA224_HASH_SIZE, 344 sizeof(RTSHA224CONTEXT), 345 0, 346 rtCrDigestSha224_Update, 347 rtCrDigestSha224_Final, 348 rtCrDigestSha224_Init, 349 NULL, 350 NULL, 351 NULL, 352 NULL, 353 }; 354 355 356 /* 357 * SHA-384 358 */ 359 360 /** @impl_interface_method{RTCRDIGESTDESC::pfnUpdate} */ 361 static DECLCALLBACK(void) rtCrDigestSha384_Update(void *pvState, const void *pvData, size_t cbData) 362 { 363 RTSha384Update((PRTSHA384CONTEXT)pvState, pvData, cbData); 364 } 365 366 /** @impl_interface_method{RTCRDIGESTDESC::pfnFinal} */ 367 static DECLCALLBACK(void) rtCrDigestSha384_Final(void *pvState, uint8_t *pbHash) 368 { 369 RTSha384Final((PRTSHA384CONTEXT)pvState, pbHash); 370 } 371 372 /** @impl_interface_method{RTCRDIGESTDESC::pfnInit} */ 373 static DECLCALLBACK(int) rtCrDigestSha384_Init(void *pvState, void *pvOpaque, bool fReInit) 374 { 375 AssertReturn(pvOpaque == NULL, VERR_INVALID_PARAMETER); 376 RTSha384Init((PRTSHA384CONTEXT)pvState); 377 return VINF_SUCCESS; 378 } 379 380 /** SHA-384 alias ODIs. */ 381 static const char * const g_apszSha384Aliases[] = 382 { 383 RTCR_PKCS1_SHA384_WITH_RSA_OID, 384 NULL 385 }; 386 387 /** SHA-384 descriptor. */ 388 static RTCRDIGESTDESC const g_rtCrDigestSha384Desc = 389 { 390 "sha-384", 391 "2.16.840.1.101.3.4.2.2", 392 g_apszSha384Aliases, 393 RTDIGESTTYPE_SHA384, 394 RTSHA384_HASH_SIZE, 395 sizeof(RTSHA384CONTEXT), 396 0, 397 rtCrDigestSha384_Update, 398 rtCrDigestSha384_Final, 399 rtCrDigestSha384_Init, 400 NULL, 401 NULL, 402 NULL, 403 NULL, 404 }; 405 406 407 #ifndef IPRT_WITHOUT_SHA512T224 408 /* 409 * SHA-512/224 410 */ 411 412 /** @impl_interface_method{RTCRDIGESTDESC::pfnUpdate} */ 413 static DECLCALLBACK(void) rtCrDigestSha512t224_Update(void *pvState, const void *pvData, size_t cbData) 414 { 415 RTSha512t224Update((PRTSHA512T224CONTEXT)pvState, pvData, cbData); 416 } 417 418 /** @impl_interface_method{RTCRDIGESTDESC::pfnFinal} */ 419 static DECLCALLBACK(void) rtCrDigestSha512t224_Final(void *pvState, uint8_t *pbHash) 420 { 421 RTSha512t224Final((PRTSHA512T224CONTEXT)pvState, pbHash); 422 } 423 424 /** @impl_interface_method{RTCRDIGESTDESC::pfnInit} */ 425 static DECLCALLBACK(int) rtCrDigestSha512t224_Init(void *pvState, void *pvOpaque, bool fReInit) 426 { 427 AssertReturn(pvOpaque == NULL, VERR_INVALID_PARAMETER); 428 RTSha512t224Init((PRTSHA512T224CONTEXT)pvState); 429 return VINF_SUCCESS; 430 } 431 432 /** SHA-512/224 alias ODIs. */ 433 static const char * const g_apszSha512t224Aliases[] = 434 { 435 NULL 436 }; 437 438 /** SHA-512/224 descriptor. */ 439 static RTCRDIGESTDESC const g_rtCrDigestSha512t224Desc = 440 { 441 "sha-512/224", 442 "2.16.840.1.101.3.4.2.5", 443 g_apszSha512t224Aliases, 444 RTDIGESTTYPE_SHA512T224, 445 RTSHA512T224_HASH_SIZE, 446 sizeof(RTSHA512T224CONTEXT), 447 0, 448 rtCrDigestSha512t224_Update, 449 rtCrDigestSha512t224_Final, 450 rtCrDigestSha512t224_Init, 451 NULL, 452 NULL, 453 NULL, 454 NULL, 455 }; 456 #endif /* !IPRT_WITHOUT_SHA512T224 */ 457 458 459 #ifndef IPRT_WITHOUT_SHA512T256 460 /* 461 * SHA-512/256 462 */ 463 464 /** @impl_interface_method{RTCRDIGESTDESC::pfnUpdate} */ 465 static DECLCALLBACK(void) rtCrDigestSha512t256_Update(void *pvState, const void *pvData, size_t cbData) 466 { 467 RTSha512t256Update((PRTSHA512T256CONTEXT)pvState, pvData, cbData); 468 } 469 470 /** @impl_interface_method{RTCRDIGESTDESC::pfnFinal} */ 471 static DECLCALLBACK(void) rtCrDigestSha512t256_Final(void *pvState, uint8_t *pbHash) 472 { 473 RTSha512t256Final((PRTSHA512T256CONTEXT)pvState, pbHash); 474 } 475 476 /** @impl_interface_method{RTCRDIGESTDESC::pfnInit} */ 477 static DECLCALLBACK(int) rtCrDigestSha512t256_Init(void *pvState, void *pvOpaque, bool fReInit) 478 { 479 AssertReturn(pvOpaque == NULL, VERR_INVALID_PARAMETER); 480 RTSha512t256Init((PRTSHA512T256CONTEXT)pvState); 481 return VINF_SUCCESS; 482 } 483 484 /** SHA-512/256 alias ODIs. */ 485 static const char * const g_apszSha512t256Aliases[] = 486 { 487 NULL 488 }; 489 490 /** SHA-512/256 descriptor. */ 491 static RTCRDIGESTDESC const g_rtCrDigestSha512t256Desc = 492 { 493 "sha-512/256", 494 "2.16.840.1.101.3.4.2.6", 495 g_apszSha512t256Aliases, 496 RTDIGESTTYPE_SHA512T256, 497 RTSHA512T256_HASH_SIZE, 498 sizeof(RTSHA512T256CONTEXT), 499 0, 500 rtCrDigestSha512t256_Update, 501 rtCrDigestSha512t256_Final, 502 rtCrDigestSha512t256_Init, 503 NULL, 504 NULL, 505 NULL, 506 NULL, 507 }; 508 #endif /* !IPRT_WITHOUT_SHA512T256 */ 509 510 305 511 /** 306 512 * Array of built in message digest vtables. … … 313 519 &g_rtCrDigestSha256Desc, 314 520 &g_rtCrDigestSha512Desc, 521 &g_rtCrDigestSha224Desc, 522 &g_rtCrDigestSha384Desc, 523 #ifndef IPRT_WITHOUT_SHA512T224 524 &g_rtCrDigestSha512t224Desc, 525 #endif 526 #ifndef IPRT_WITHOUT_SHA512T256 527 &g_rtCrDigestSha512t256Desc, 528 #endif 315 529 }; 316 530 … … 414 628 415 629 416 PCRTCRDIGESTDESCRTCrDigestFindByObjIdString(const char *pszObjId, void **ppvOpaque)630 RTDECL(PCRTCRDIGESTDESC) RTCrDigestFindByObjIdString(const char *pszObjId, void **ppvOpaque) 417 631 { 418 632 if (ppvOpaque) … … 468 682 469 683 470 PCRTCRDIGESTDESCRTCrDigestFindByObjId(PCRTASN1OBJID pObjId, void **ppvOpaque)684 RTDECL(PCRTCRDIGESTDESC) RTCrDigestFindByObjId(PCRTASN1OBJID pObjId, void **ppvOpaque) 471 685 { 472 686 return RTCrDigestFindByObjIdString(pObjId->szObjId, ppvOpaque); … … 493 707 } 494 708 709 710 RTDECL(PCRTCRDIGESTDESC) RTCrDigestFindByType(RTDIGESTTYPE enmDigestType) 711 { 712 AssertReturn(enmDigestType > RTDIGESTTYPE_INVALID && enmDigestType <= RTDIGESTTYPE_END, NULL); 713 714 uint32_t i = RT_ELEMENTS(g_apDigestOps); 715 while (i-- > 0) 716 if (g_apDigestOps[i]->enmType == enmDigestType) 717 return g_apDigestOps[i]; 718 return NULL; 719 } 720 721 722 RTDECL(int) RTCrDigestCreateByType(PRTCRDIGEST phDigest, RTDIGESTTYPE enmDigestType) 723 { 724 PCRTCRDIGESTDESC pDesc = RTCrDigestFindByType(enmDigestType); 725 if (pDesc) 726 return RTCrDigestCreate(phDigest, pDesc, NULL); 727 return VERR_NOT_FOUND; 728 } 729 -
trunk/src/VBox/Runtime/common/crypto/x509-core.cpp
r51770 r51856 74 74 if (!strcmp(pThis->Algorithm.szObjId, RTCRX509ALGORITHMIDENTIFIERID_SHA512)) 75 75 return RTDIGESTTYPE_SHA512; 76 77 if (!strcmp(pThis->Algorithm.szObjId, RTCRX509ALGORITHMIDENTIFIERID_SHA384)) 78 return RTDIGESTTYPE_SHA384; 79 if (!strcmp(pThis->Algorithm.szObjId, RTCRX509ALGORITHMIDENTIFIERID_SHA224)) 80 return RTDIGESTTYPE_SHA224; 81 if (!strcmp(pThis->Algorithm.szObjId, RTCRX509ALGORITHMIDENTIFIERID_SHA512T224)) 82 return RTDIGESTTYPE_SHA512T224; 83 if (!strcmp(pThis->Algorithm.szObjId, RTCRX509ALGORITHMIDENTIFIERID_SHA512T256)) 84 return RTDIGESTTYPE_SHA512T256; 76 85 return RTDIGESTTYPE_INVALID; 77 86 } … … 101 110 if (!strcmp(pThis->Algorithm.szObjId, RTCRX509ALGORITHMIDENTIFIERID_SHA224)) 102 111 return 224 / 8; 112 if (!strcmp(pThis->Algorithm.szObjId, RTCRX509ALGORITHMIDENTIFIERID_SHA512T224)) 113 return 224 / 8; 114 if (!strcmp(pThis->Algorithm.szObjId, RTCRX509ALGORITHMIDENTIFIERID_SHA512T256)) 115 return 256 / 8; 103 116 if (!strcmp(pThis->Algorithm.szObjId, RTCRX509ALGORITHMIDENTIFIERID_WHIRLPOOL)) 104 117 return 512 / 8; -
trunk/src/VBox/Runtime/testcase/Makefile.kmk
r51820 r51856 241 241 242 242 tstRTDigest-2_TEMPLATE = VBOXR3TSTEXE 243 ifndef VBOX_WITH_ALT_HASH_CODE 244 tstRTDigest-2_DEFS = IPRT_WITHOUT_SHA512T224 IPRT_WITHOUT_SHA512T256 245 endif 243 246 tstRTDigest-2_SOURCES = tstRTDigest-2.cpp 244 247 -
trunk/src/VBox/Runtime/testcase/tstRTDigest-2.cpp
r51838 r51856 154 154 */ 155 155 RTTESTI_CHECK_RC_RETV(RTCrDigestCreateByObjIdString(&hDigest, pszDigestObjId), VINF_SUCCESS); 156 uint32_t c onst cChunks = 64;157 uint32_t 158 int 159 160 uint64_t 156 uint32_t cChunks = 64; 157 uint32_t cLeft = cChunks; 158 int rc = VINF_SUCCESS; 159 160 uint64_t uStartTS = RTTimeNanoTS(); 161 161 while (cLeft-- > 0) 162 162 rc |= RTCrDigestUpdate(hDigest, g_abRandom72KB, sizeof(g_abRandom72KB)); 163 163 rc |= RTCrDigestFinal(hDigest, NULL, 0); 164 164 uint64_t cNsElapsed = RTTimeNanoTS() - uStartTS; 165 166 165 RTTESTI_CHECK(rc == VINF_SUCCESS); 166 167 /* If it was too quick, redo with more chunks. */ 168 if (rc == VINF_SUCCESS && cNsElapsed < 100000000 /* 100 ms */) 169 { 170 cChunks = 1024; 171 cLeft = cChunks; 172 RTTESTI_CHECK_RC(RTCrDigestReset(hDigest), VINF_SUCCESS); 173 174 uStartTS = RTTimeNanoTS(); 175 while (cLeft-- > 0) 176 rc |= RTCrDigestUpdate(hDigest, g_abRandom72KB, sizeof(g_abRandom72KB)); 177 rc |= RTCrDigestFinal(hDigest, NULL, 0); 178 cNsElapsed = RTTimeNanoTS() - uStartTS; 179 RTTESTI_CHECK(rc == VINF_SUCCESS); 180 } 167 181 168 182 RTTestIValueF((uint64_t)cChunks * sizeof(g_abRandom72KB) / _1K / (0.000000001 * cNsElapsed), RTTESTUNIT_KILOBYTES_PER_SEC, … … 917 931 918 932 /** 933 * Tests SHA-224 934 */ 935 static void testSha224(void) 936 { 937 RTTestISub("SHA-224"); 938 939 /* 940 * Some quick direct API tests. 941 */ 942 uint8_t *pabHash = (uint8_t *)RTTestGuardedAllocTail(NIL_RTTEST, RTSHA224_HASH_SIZE); 943 char *pszDigest = (char *)RTTestGuardedAllocTail(NIL_RTTEST, RTSHA224_DIGEST_LEN + 1); 944 const char *pszString; 945 946 pszString = "abc"; 947 RTSha224(pszString, strlen(pszString), pabHash); 948 RTTESTI_CHECK_RC_RETV(RTSha224ToString(pabHash, pszDigest, RTSHA224_DIGEST_LEN + 1), VINF_SUCCESS); 949 CHECK_STRING(pszDigest, "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7"); 950 951 952 pszString = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; 953 RTSha224(pszString, strlen(pszString), pabHash); 954 RTTESTI_CHECK_RC_RETV(RTSha224ToString(pabHash, pszDigest, RTSHA224_DIGEST_LEN + 1), VINF_SUCCESS); 955 CHECK_STRING(pszDigest, "75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525"); 956 957 /* 958 * Generic API tests. 959 */ 960 static TESTRTDIGEST const s_abTests[] = 961 { 962 { RT_STR_TUPLE("abc"), "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", "SHA-224 abc" }, 963 { RT_STR_TUPLE("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"), 964 "75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525", "SHA-224 abcdbc..." }, 965 }; 966 testGeneric("2.16.840.1.101.3.4.2.4", s_abTests, RT_ELEMENTS(s_abTests), "SHA-224"); 967 } 968 969 970 /** 919 971 * Tests SHA-512 920 972 */ … … 1084 1136 1085 1137 1138 #ifndef IPRT_WITHOUT_SHA512T224 1139 /** 1140 * Tests SHA-512/224 1141 */ 1142 static void testSha512t224(void) 1143 { 1144 RTTestISub("SHA-512/224"); 1145 1146 /* 1147 * Some quick direct API tests. 1148 */ 1149 uint8_t abHash[RTSHA512T224_HASH_SIZE]; 1150 char szDigest[RTSHA512T224_DIGEST_LEN + 1]; 1151 const char *pszString; 1152 1153 pszString = "abc"; 1154 RTSha512t224(pszString, strlen(pszString), abHash); 1155 RTTESTI_CHECK_RC_RETV(RTSha512t224ToString(abHash, szDigest, sizeof(szDigest)), VINF_SUCCESS); 1156 CHECK_STRING(szDigest, "4634270f707b6a54daae7530460842e20e37ed265ceee9a43e8924aa"); 1157 1158 pszString = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"; 1159 RTSha512t224(pszString, strlen(pszString), abHash); 1160 RTTESTI_CHECK_RC_RETV(RTSha512t224ToString(abHash, szDigest, sizeof(szDigest)), VINF_SUCCESS); 1161 CHECK_STRING(szDigest, "23fec5bb94d60b23308192640b0c453335d664734fe40e7268674af9"); 1162 1163 /* 1164 * Generic API tests. 1165 */ 1166 static TESTRTDIGEST const s_abTests[] = 1167 { 1168 { RT_STR_TUPLE("abc"), "4634270f707b6a54daae7530460842e20e37ed265ceee9a43e8924aa", "SHA-512/224 abc" }, 1169 { RT_STR_TUPLE("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"), 1170 "23fec5bb94d60b23308192640b0c453335d664734fe40e7268674af9", "SHA-512/256 abcdef..." }, 1171 }; 1172 testGeneric("2.16.840.1.101.3.4.2.5", s_abTests, RT_ELEMENTS(s_abTests), "SHA-512/224"); 1173 } 1174 #endif /* IPRT_WITHOUT_SHA512T224 */ 1175 1176 #ifndef IPRT_WITHOUT_SHA512T256 1177 /** 1178 * Tests SHA-512/256 1179 */ 1180 static void testSha512t256(void) 1181 { 1182 RTTestISub("SHA-512/256"); 1183 1184 /* 1185 * Some quick direct API tests. 1186 */ 1187 uint8_t abHash[RTSHA512T256_HASH_SIZE]; 1188 char szDigest[RTSHA512T256_DIGEST_LEN + 1]; 1189 const char *pszString; 1190 1191 pszString = "abc"; 1192 RTSha512t256(pszString, strlen(pszString), abHash); 1193 RTTESTI_CHECK_RC_RETV(RTSha512t256ToString(abHash, szDigest, sizeof(szDigest)), VINF_SUCCESS); 1194 CHECK_STRING(szDigest, "53048e2681941ef99b2e29b76b4c7dabe4c2d0c634fc6d46e0e2f13107e7af23"); 1195 1196 pszString = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"; 1197 RTSha512t256(pszString, strlen(pszString), abHash); 1198 RTTESTI_CHECK_RC_RETV(RTSha512t256ToString(abHash, szDigest, sizeof(szDigest)), VINF_SUCCESS); 1199 CHECK_STRING(szDigest, "3928e184fb8690f840da3988121d31be65cb9d3ef83ee6146feac861e19b563a"); 1200 1201 /* 1202 * Generic API tests. 1203 */ 1204 static TESTRTDIGEST const s_abTests[] = 1205 { 1206 { RT_STR_TUPLE("abc"), "53048e2681941ef99b2e29b76b4c7dabe4c2d0c634fc6d46e0e2f13107e7af23", "SHA-512/256 abc" }, 1207 { RT_STR_TUPLE("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"), 1208 "3928e184fb8690f840da3988121d31be65cb9d3ef83ee6146feac861e19b563a", "SHA-512/256 abcdef..." }, 1209 }; 1210 testGeneric("2.16.840.1.101.3.4.2.6", s_abTests, RT_ELEMENTS(s_abTests), "SHA-512/256"); 1211 } 1212 #endif /* !IPRT_WITHOUT_SHA512T256 */ 1213 1214 /** 1215 * Tests SHA-384 1216 */ 1217 static void testSha384(void) 1218 { 1219 RTTestISub("SHA-384"); 1220 1221 /* 1222 * Some quick direct API tests. 1223 */ 1224 uint8_t abHash[RTSHA384_HASH_SIZE]; 1225 char szDigest[RTSHA384_DIGEST_LEN + 1]; 1226 const char *pszString; 1227 1228 pszString = "abc"; 1229 RTSha384(pszString, strlen(pszString), abHash); 1230 RTTESTI_CHECK_RC_RETV(RTSha384ToString(abHash, szDigest, sizeof(szDigest)), VINF_SUCCESS); 1231 CHECK_STRING(szDigest, "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7"); 1232 1233 pszString = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"; 1234 RTSha384(pszString, strlen(pszString), abHash); 1235 RTTESTI_CHECK_RC_RETV(RTSha384ToString(abHash, szDigest, sizeof(szDigest)), VINF_SUCCESS); 1236 CHECK_STRING(szDigest, "09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039"); 1237 1238 /* 1239 * Generic API tests. 1240 */ 1241 static TESTRTDIGEST const s_abTests[] = 1242 { 1243 { RT_STR_TUPLE("abc"), "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7", "SHA-384 abc" }, 1244 { RT_STR_TUPLE("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"), 1245 "09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039", "SHA-384 abcdef..." }, 1246 }; 1247 testGeneric("2.16.840.1.101.3.4.2.2", s_abTests, RT_ELEMENTS(s_abTests), "SHA-384"); 1248 } 1249 1086 1250 1087 1251 int main() … … 1097 1261 testSha1(); 1098 1262 testSha256(); 1263 testSha224(); 1099 1264 testSha512(); 1265 testSha384(); 1266 #ifndef IPRT_WITHOUT_SHA512T224 1267 testSha512t224(); 1268 #endif 1269 #ifndef IPRT_WITHOUT_SHA512T256 1270 testSha512t256(); 1271 #endif 1100 1272 1101 1273 return RTTestSummaryAndDestroy(hTest); -
trunk/src/VBox/Runtime/testcase/tstRTDigest.cpp
r51820 r51856 44 44 #include <iprt/string.h> 45 45 #include <iprt/stream.h> 46 #include <iprt/crypto/digest.h> 46 47 47 48 … … 79 80 80 81 82 static char *MyGetNextSignificantLine(PRTSTREAM pFile, char *pszBuf, size_t cbBuf, uint32_t *piLine, int *prc) 83 { 84 for (;;) 85 { 86 *pszBuf = '\0'; 87 int rc = RTStrmGetLine(pFile, pszBuf, cbBuf); 88 if (RT_FAILURE(rc)) 89 { 90 if (rc != VERR_EOF) 91 { 92 Error("Read error: %Rrc", rc); 93 *prc = rc; 94 return NULL; 95 } 96 if (!*pszBuf) 97 return NULL; 98 } 99 *piLine += 1; 100 101 /* Significant? */ 102 char *pszStart = RTStrStrip(pszBuf); 103 if (*pszStart && *pszStart != '#') 104 return pszStart; 105 } 106 } 107 81 108 82 109 int main(int argc, char **argv) … … 84 111 RTR3InitExe(argc, &argv, 0); 85 112 86 enum 87 { 88 kDigestType_NotSpecified, 89 kDigestType_CRC32, 90 kDigestType_CRC64, 91 kDigestType_MD2, 92 kDigestType_MD5, 93 kDigestType_SHA1, 94 kDigestType_SHA256, 95 kDigestType_SHA512 96 } enmDigestType = kDigestType_NotSpecified; 97 const char *pszDigestType = "NotSpecified"; 113 RTDIGESTTYPE enmDigestType = RTDIGESTTYPE_INVALID; 114 const char *pszDigestType = "NotSpecified"; 98 115 99 116 enum … … 101 118 kMethod_Full, 102 119 kMethod_Block, 103 kMethod_File 120 kMethod_File, 121 kMethod_CVAS 104 122 } enmMethod = kMethod_Block; 105 123 … … 129 147 if (!RTStrICmp(ValueUnion.psz, "crc32")) 130 148 { 131 pszDigestType = "CRC32";132 enmDigestType = kDigestType_CRC32;149 pszDigestType = "CRC32"; 150 enmDigestType = RTDIGESTTYPE_CRC32; 133 151 } 134 152 else if (!RTStrICmp(ValueUnion.psz, "crc64")) 135 153 { 136 154 pszDigestType = "CRC64"; 137 enmDigestType = kDigestType_CRC64;155 enmDigestType = RTDIGESTTYPE_CRC64; 138 156 } 139 157 else if (!RTStrICmp(ValueUnion.psz, "md2")) 140 158 { 141 159 pszDigestType = "MD2"; 142 enmDigestType = kDigestType_MD2;160 enmDigestType = RTDIGESTTYPE_MD2; 143 161 } 144 162 else if (!RTStrICmp(ValueUnion.psz, "md5")) 145 163 { 146 164 pszDigestType = "MD5"; 147 enmDigestType = kDigestType_MD5;165 enmDigestType = RTDIGESTTYPE_MD5; 148 166 } 149 167 else if (!RTStrICmp(ValueUnion.psz, "sha1")) 150 168 { 151 169 pszDigestType = "SHA-1"; 152 enmDigestType = kDigestType_SHA1; 170 enmDigestType = RTDIGESTTYPE_SHA1; 171 } 172 else if (!RTStrICmp(ValueUnion.psz, "sha224")) 173 { 174 pszDigestType = "SHA-224"; 175 enmDigestType = RTDIGESTTYPE_SHA224; 153 176 } 154 177 else if (!RTStrICmp(ValueUnion.psz, "sha256")) 155 178 { 156 179 pszDigestType = "SHA-256"; 157 enmDigestType = kDigestType_SHA256; 180 enmDigestType = RTDIGESTTYPE_SHA256; 181 } 182 else if (!RTStrICmp(ValueUnion.psz, "sha384")) 183 { 184 pszDigestType = "SHA-384"; 185 enmDigestType = RTDIGESTTYPE_SHA384; 158 186 } 159 187 else if (!RTStrICmp(ValueUnion.psz, "sha512")) 160 188 { 161 189 pszDigestType = "SHA-512"; 162 enmDigestType = kDigestType_SHA512; 190 enmDigestType = RTDIGESTTYPE_SHA512; 191 } 192 else if (!RTStrICmp(ValueUnion.psz, "sha512/224")) 193 { 194 pszDigestType = "SHA-512/224"; 195 enmDigestType = RTDIGESTTYPE_SHA512T224; 196 } 197 else if (!RTStrICmp(ValueUnion.psz, "sha512/256")) 198 { 199 pszDigestType = "SHA-512/256"; 200 enmDigestType = RTDIGESTTYPE_SHA512T256; 163 201 } 164 202 else … … 176 214 else if (!RTStrICmp(ValueUnion.psz, "file")) 177 215 enmMethod = kMethod_File; 216 else if (!RTStrICmp(ValueUnion.psz, "cvas")) 217 enmMethod = kMethod_CVAS; 178 218 else 179 219 { … … 201 241 case VINF_GETOPT_NOT_OPTION: 202 242 { 203 if (enmDigestType == kDigestType_NotSpecified)243 if (enmDigestType == RTDIGESTTYPE_INVALID) 204 244 return Error("No digest type was specified\n"); 205 245 … … 214 254 switch (enmDigestType) 215 255 { 216 case kDigestType_SHA1:256 case RTDIGESTTYPE_SHA1: 217 257 { 218 258 char *pszDigest; … … 225 265 } 226 266 227 case kDigestType_SHA256:267 case RTDIGESTTYPE_SHA256: 228 268 { 229 269 char *pszDigest; … … 259 299 switch (enmDigestType) 260 300 { 261 case kDigestType_CRC32:301 case RTDIGESTTYPE_CRC32: 262 302 { 263 303 uint32_t uCRC32 = RTCrc32Start(); … … 274 314 } 275 315 276 case kDigestType_CRC64:316 case RTDIGESTTYPE_CRC64: 277 317 { 278 318 uint64_t uCRC64 = RTCrc64Start(); … … 289 329 } 290 330 291 case kDigestType_MD2:331 case RTDIGESTTYPE_MD2: 292 332 { 293 333 RTMD2CONTEXT Ctx; … … 306 346 } 307 347 308 case kDigestType_MD5:348 case RTDIGESTTYPE_MD5: 309 349 { 310 350 RTMD5CONTEXT Ctx; … … 323 363 } 324 364 325 case kDigestType_SHA1:365 case RTDIGESTTYPE_SHA1: 326 366 { 327 367 RTSHA1CONTEXT Ctx; … … 340 380 } 341 381 342 case kDigestType_SHA256:382 case RTDIGESTTYPE_SHA256: 343 383 { 344 384 RTSHA256CONTEXT Ctx; … … 357 397 } 358 398 359 case kDigestType_SHA512:399 case RTDIGESTTYPE_SHA512: 360 400 { 361 401 RTSHA512CONTEXT Ctx; … … 395 435 } 396 436 437 438 /* 439 * Process a SHS response file: 440 * http://csrc.nist.gov/groups/STM/cavp/index.html#03 441 */ 442 case kMethod_CVAS: 443 { 444 RTCRDIGEST hDigest; 445 int rc = RTCrDigestCreateByType(&hDigest, enmDigestType); 446 if (RT_FAILURE(rc)) 447 return Error("Failed to create digest calculator for %s: %Rrc", pszDigestType, rc); 448 449 uint32_t const cbDigest = RTCrDigestGetHashSize(hDigest); 450 if (!cbDigest || cbDigest >= _1K) 451 return Error("Unexpected hash size: %#x\n", cbDigest); 452 453 PRTSTREAM pFile; 454 rc = RTStrmOpen(ValueUnion.psz, "r", &pFile); 455 if (RT_FAILURE(rc)) 456 return Error("Failed to open CVAS file '%s': %Rrc", ValueUnion.psz, rc); 457 458 /* 459 * Parse the input file. 460 * ASSUME order: Len, Msg, MD. 461 */ 462 static char s_szLine[_256K]; 463 char *psz; 464 uint32_t cPassed = 0; 465 uint32_t cErrors = 0; 466 uint32_t iLine = 1; 467 for (;;) 468 { 469 psz = MyGetNextSignificantLine(pFile, s_szLine, sizeof(s_szLine), &iLine, &rc); 470 if (!psz) 471 break; 472 473 /* Skip [L = 20] stuff. */ 474 if (*psz == '[') 475 continue; 476 477 /* Message length. */ 478 uint64_t cMessageBits; 479 if (RTStrNICmp(psz, RT_STR_TUPLE("Len ="))) 480 return Error("%s(%d): Expected 'Len =' found '%.10s...'", ValueUnion.psz, iLine, psz); 481 psz = RTStrStripL(psz + 5); 482 rc = RTStrToUInt64Full(psz, 0, &cMessageBits); 483 if (rc != VINF_SUCCESS) 484 return Error("%s(%d): Error parsing length '%s': %Rrc\n", ValueUnion.psz, iLine, psz, rc); 485 486 /* The message text. */ 487 psz = MyGetNextSignificantLine(pFile, s_szLine, sizeof(s_szLine), &iLine, &rc); 488 if (!psz) 489 return Error("%s(%d): Expected message text not EOF.", ValueUnion.psz, iLine); 490 if (RTStrNICmp(psz, RT_STR_TUPLE("Msg ="))) 491 return Error("%s(%d): Expected 'Msg =' found '%.10s...'", ValueUnion.psz, iLine, psz); 492 psz = RTStrStripL(psz + 5); 493 494 size_t const cbMessage = (cMessageBits + 7) / 8; 495 static uint8_t s_abMessage[sizeof(s_szLine) / 2]; 496 if (cbMessage > 0) 497 { 498 rc = RTStrConvertHexBytes(psz, s_abMessage, cbMessage, 0 /*fFlags*/); 499 if (rc != VINF_SUCCESS) 500 return Error("%s(%d): Error parsing message '%.10s...': %Rrc\n", 501 ValueUnion.psz, iLine, psz, rc); 502 } 503 504 /* The message digest. */ 505 psz = MyGetNextSignificantLine(pFile, s_szLine, sizeof(s_szLine), &iLine, &rc); 506 if (!psz) 507 return Error("%s(%d): Expected message digest not EOF.", ValueUnion.psz, iLine); 508 if (RTStrNICmp(psz, RT_STR_TUPLE("MD ="))) 509 return Error("%s(%d): Expected 'MD =' found '%.10s...'", ValueUnion.psz, iLine, psz); 510 psz = RTStrStripL(psz + 4); 511 512 static uint8_t s_abExpectedDigest[_1K]; 513 rc = RTStrConvertHexBytes(psz, s_abExpectedDigest, cbDigest, 0 /*fFlags*/); 514 if (rc != VINF_SUCCESS) 515 return Error("%s(%d): Error parsing message digest '%.10s...': %Rrc\n", 516 ValueUnion.psz, iLine, psz, rc); 517 518 /* 519 * Do the testing. 520 */ 521 rc = RTCrDigestReset(hDigest); 522 if (rc != VINF_SUCCESS) 523 return Error("RTCrDigestReset failed: %Rrc", rc); 524 525 rc = RTCrDigestUpdate(hDigest, s_abMessage, cbMessage); 526 if (rc != VINF_SUCCESS) 527 return Error("RTCrDigestUpdate failed: %Rrc", rc); 528 529 static uint8_t s_abActualDigest[_1K]; 530 rc = RTCrDigestFinal(hDigest, s_abActualDigest, cbDigest); 531 if (rc != VINF_SUCCESS) 532 return Error("RTCrDigestFinal failed: %Rrc", rc); 533 534 if (memcmp(s_abActualDigest, s_abExpectedDigest, cbDigest) == 0) 535 cPassed++; 536 else 537 { 538 Error("%s(%d): Message digest mismatch. Expected %.*RThxs, got %.*RThxs.", 539 ValueUnion.psz, iLine, cbDigest, s_abExpectedDigest, cbDigest, s_abActualDigest); 540 cErrors++; 541 } 542 } 543 544 RTStrmClose(pFile); 545 if (cErrors > 0) 546 return Error("Failed: %u error%s (%u passed)", cErrors, cErrors == 1 ? "" : "s", cPassed); 547 RTPrintf("Passed %u test%s.\n", cPassed, cPassed == 1 ? "" : "s"); 548 if (RT_FAILURE(rc)) 549 return Error("Failed: %Rrc", rc); 550 break; 551 } 552 397 553 default: 398 554 return Error("Internal error #2\n");
Note:
See TracChangeset
for help on using the changeset viewer.