| 886 | |
| 887 | |
| 888 | void CKnownFile::CreateHashFromInput(const uint8_t* input, uint32 Length, CMD4Hash* Output, CAICHHashTree* pShaHashOut ) |
| 889 | { |
| 890 | wxASSERT_MSG(Output || pShaHashOut, "Nothing to do in CreateHashFromInput"); |
| 891 | { wxCHECK_RET(input, "No input to hash from in CreateHashFromInput"); } |
| 892 | wxASSERT(Length <= PARTSIZE); // We never hash more than one PARTSIZE |
| 893 | |
| 894 | CMemFile data(input, Length); |
| 895 | |
| 896 | uint32 Required = Length; |
| 897 | uint8 X[64*128]; |
| 898 | |
| 899 | uint32 posCurrentEMBlock = 0; |
| 900 | uint32 nIACHPos = 0; |
| 901 | CScopedPtr<CAICHHashAlgo> pHashAlg(CAICHHashSet::GetNewHashAlgo()); |
| 902 | |
| 903 | // This is all AICH. |
| 904 | while (Required >= 64) { |
| 905 | uint32 len = Required / 64; |
| 906 | if (len > sizeof(X)/(64 * sizeof(X[0]))) { |
| 907 | len = sizeof(X)/(64 * sizeof(X[0])); |
| 908 | } |
| 909 | |
| 910 | data.Read(&X, len * 64); |
| 911 | |
| 912 | // SHA hash needs 180KB blocks |
| 913 | if (pShaHashOut) { |
| 914 | if (nIACHPos + len*64 >= EMBLOCKSIZE) { |
| 915 | uint32 nToComplete = EMBLOCKSIZE - nIACHPos; |
| 916 | pHashAlg->Add(X, nToComplete); |
| 917 | wxASSERT( nIACHPos + nToComplete == EMBLOCKSIZE ); |
| 918 | pShaHashOut->SetBlockHash(EMBLOCKSIZE, posCurrentEMBlock, pHashAlg.get()); |
| 919 | posCurrentEMBlock += EMBLOCKSIZE; |
| 920 | pHashAlg->Reset(); |
| 921 | pHashAlg->Add(X+nToComplete,(len*64) - nToComplete); |
| 922 | nIACHPos = (len*64) - nToComplete; |
| 923 | } |
| 924 | else{ |
| 925 | pHashAlg->Add(X, len*64); |
| 926 | nIACHPos += len*64; |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | Required -= len*64; |
| 931 | } |
| 932 | // bytes to read |
| 933 | Required = Length % 64; |
| 934 | if (Required != 0){ |
| 935 | data.Read(&X,Required); |
| 936 | |
| 937 | if (pShaHashOut != NULL){ |
| 938 | if (nIACHPos + Required >= EMBLOCKSIZE){ |
| 939 | uint32 nToComplete = EMBLOCKSIZE - nIACHPos; |
| 940 | pHashAlg->Add(X, nToComplete); |
| 941 | wxASSERT( nIACHPos + nToComplete == EMBLOCKSIZE ); |
| 942 | pShaHashOut->SetBlockHash(EMBLOCKSIZE, posCurrentEMBlock, pHashAlg.get()); |
| 943 | posCurrentEMBlock += EMBLOCKSIZE; |
| 944 | pHashAlg->Reset(); |
| 945 | pHashAlg->Add(X+nToComplete, Required - nToComplete); |
nothing calls this directly
no test coverage detected