Exemplo n.º 1
0
void Keyak_ProcessAssociatedData(Keccak_DuplexInstance* duplex, const unsigned char *data, unsigned int dataSizeInBytes, int last, int bodyFollows)
{
    unsigned int rhoInBytes = (duplex->rate-4)/8;

    while(dataSizeInBytes > 0) {
        unsigned int localSize;

        if (Keccak_DuplexGetInputIndex(duplex) == rhoInBytes)
            Keccak_Duplexing(duplex, 0, 0, 0, 0, 0x04); // 00

        localSize = dataSizeInBytes;
        if (localSize > (rhoInBytes - Keccak_DuplexGetInputIndex(duplex)))
            localSize = rhoInBytes - Keccak_DuplexGetInputIndex(duplex);

        Keccak_DuplexingFeedPartialInput(duplex, data, localSize);
        data += localSize;
        dataSizeInBytes -= localSize;
    }

    if (last) {
        if (bodyFollows)
            Keccak_Duplexing(duplex, 0, 0, 0, 0, 0x06); // 01
        else
            Keccak_Duplexing(duplex, 0, 0, 0, 0, 0x05); // 10
    }
}
Exemplo n.º 2
0
void Keyak_ProcessForget(Keccak_DuplexInstance* duplex)
{
    unsigned int rhoInBytes = (duplex->rate-4)/8;

    Keccak_Duplexing(duplex, 0, 0, 0, 0, 0x01);
    Keccak_DuplexingOverwriteWithZeroes(duplex, rhoInBytes);
    Keccak_Duplexing(duplex, 0, 0, 0, 0, 0x01);
}
Exemplo n.º 3
0
void displayDuplexIntermediateValuesOne(FILE *f, unsigned int rate, unsigned int capacity)
{
    Keccak_DuplexInstance duplex;
    unsigned char input[512];
    unsigned int inBitLen;
    unsigned char output[512];
    unsigned int outBitLen;
    unsigned int i, j;
    const unsigned int M = 239*251;
    unsigned int x = 33;

    Keccak_DuplexInitialize(&duplex, rate, capacity);
    displayStateAsBytes(1, "Initial state", duplex.state);
    
    for(i=0; i<=rate+120; i+=123) {
        inBitLen = i;
        if (inBitLen > (rate-2)) inBitLen = rate-2;
        memset(input, 0, 512);
        for(j=0; j<inBitLen; j++) {
            x = (x*x) % M;
            if ((x % 2) != 0)
                input[j/8] |= 1 << (j%8);
        }
        {
            char text[100];
            sprintf(text, "Input (%d bits)", inBitLen);
            displayBytes(1, text, input, (inBitLen+7)/8);
        }
        outBitLen = rate;
        if ((inBitLen%8) == 0)
            Keccak_Duplexing(&duplex, input, inBitLen/8, output, (outBitLen+7)/8, 0x01);
        else
            Keccak_Duplexing(&duplex, input, inBitLen/8, output, (outBitLen+7)/8, input[inBitLen/8] | (1 << (inBitLen%8)));
        {
            char text[100];
            sprintf(text, "Output (%d bits)", outBitLen);
            displayBytes(1, text, output, (outBitLen+7)/8);
        }
    }
}
Exemplo n.º 4
0
void Keyak_ProcessCiphertext(Keccak_DuplexInstance* duplex, unsigned char *data, unsigned int dataSizeInBytes, int last)
{
    unsigned int rhoInBytes = (duplex->rate-4)/8;

    while(dataSizeInBytes > 0) {
        unsigned int localSize;

        if (Keccak_DuplexGetInputIndex(duplex) == rhoInBytes)
            Keccak_Duplexing(duplex, 0, 0, 0, 0, 0x07); // 11

        localSize = dataSizeInBytes;
        if (localSize > (rhoInBytes - Keccak_DuplexGetInputIndex(duplex)))
            localSize = rhoInBytes - Keccak_DuplexGetInputIndex(duplex);

        Keccak_DuplexingGetFurtherOutputAndXOR(duplex, data, localSize);
        Keccak_DuplexingFeedPartialInput(duplex, data, localSize);
        data += localSize;
        dataSizeInBytes -= localSize;
    }

    if (last)
        Keccak_Duplexing(duplex, 0, 0, 0, 0, 0x05); // 10
}
Exemplo n.º 5
0
void Keyak_ProcessTag(Keccak_DuplexInstance* duplex, unsigned char *tag, unsigned int tagSizeInBytes)
{
    unsigned int rhoInBytes = (duplex->rate-4)/8;

    while(tagSizeInBytes > 0) {
        unsigned int localSize;

        if (Keccak_DuplexGetInputIndex(duplex) == rhoInBytes)
            Keccak_Duplexing(duplex, 0, 0, 0, 0, 0x02); // 0

        localSize = tagSizeInBytes;
        if (localSize > (rhoInBytes - Keccak_DuplexGetInputIndex(duplex)))
            localSize = rhoInBytes - Keccak_DuplexGetInputIndex(duplex);

        Keccak_DuplexingGetFurtherOutput(duplex, tag, localSize);
        tag += localSize;
        tagSizeInBytes -= localSize;
    }
}