Exemplo n.º 1
0
char* Sound::fileToData(FILE *file, BasicWAVEHeader* header)
{
    char* buffer = NULL;

    if (fread(header, sizeof(BasicWAVEHeader), 1, file))
    {
        header->riffSize = swapends(header->riffSize);
        header->fmtSize = swapends(header->fmtSize);
        header->format = swapends(header->format);
        header->channels = swapends(header->channels);
        header->samplesPerSec = swapends(header->samplesPerSec);
        header->bytesPerSec = swapends(header->bytesPerSec);
        header->blockAlign = swapends(header->blockAlign);
        header->bitsPerSample = swapends(header->bitsPerSample);
        header->dataSize = swapends(header->dataSize);
        // these things *must* be valid with this basic header
        if (!(memcmp("RIFF", header->riff, 4) ||
              memcmp("WAVE", header->wave, 4) ||
              memcmp("fmt ", header->fmt, 4)  ||
              memcmp("data", header->data, 4)))
        {
            buffer = (char*)malloc(header->dataSize);
            if (buffer)
            {
                if (fread(buffer, header->dataSize, 1, file))
                {
                    return buffer;
                }
                free(buffer);
            }
        }
    }
    return NULL;
}
Exemplo n.º 2
0
void SecureHashAlgorithm::Final() {
    Pad();
    Process();

    for (int t = 0; t < 5; ++t)
        swapends(&H[t]);
}
Exemplo n.º 3
0
void SecureHashAlgorithm::Process() {
    UINT t;

    // Each a...e corresponds to a section in the FIPS 180-3 algorithm.

    // a.
    //
    // W and M are in a union, so no need to memcpy.
    // memcpy(W, M, sizeof(M));
    for (t = 0; t < 16; ++t)
        swapends(&W[t]);

    // b. Extend the sixteen 32-bit words into eighty 32-bit words:
    for (t = 16; t < 80; ++t)
        W[t] = S(1, W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16]);

    // c. Initialize hash value for this chunk:
    A = H[0];
    B = H[1];
    C = H[2];
    D = H[3];
    E = H[4];

    // d.
    for (t = 0; t < 80; ++t) {
        UINT TEMP = S(5, A) + f(t, B, C, D) + E + W[t] + K(t);
        E = D;
        D = C;
        C = S(30, B);
        B = A;
        A = TEMP;
    }

    // e. Add this chunk's hash to result so far:
    H[0] += A;
    H[1] += B;
    H[2] += C;
    H[3] += D;
    H[4] += E;

    cursor = 0;
}