Dr. Steven Henson wrote:
> What you put in SHA_CTX should be irrelevant as long as the entire context is
> contained in a flat structure (so it can be memcpy'ed). If you hang structures
> off the end that will cause problems unless you allow for that at the EVP
> level with the "copy" function.
> 
> I'd suggest you dump the input to your implementation (in the cases it 
> produces
> errors) to a file and check that against OpenSSLs version.
> 
> Steve.

Hi Dr. Steve. I followed your advise, and now I have found a sequence to the 
error I get. It seems predictable. Here is the output of my program ('OK' means 
matching hash values with my hash function and OpenSSL hash function, if not OK 
it will dump both values) :

Creating Random Number....
OpenSSL init done
Enter PEM pass phrase:
OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK
CTX setup done
OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK 
OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK 
OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK 
OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK 
OK OK OK OK OK OK OK OK OK OK OK OK OK 
Not OK!
My Hash         : ADC5464C 4FD6FD25 EED247A2 D8E7A9AC FA79DCB8
OpenSSL Hash : DD6141F4 3D1A3CAB E4F599AD 9BAC6BBD BCBA5A9E

OK OK OK OK OK OK OK OK OK OK OK
Not OK!
My Hash         : E88E289 93BAAB3A 8B413DBD 1BA69BC7 C4566B24
OpenSSL Hash : AE2F0091 F7B25B59 A9564E47 AE5B6A39 905244D4

SSL Connection opened
OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK 
OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK 
OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK 
OK OK OK
SSL Connection closed




Each line of OK means an identical hash value. If it is not OK, it will dump 
the SHA values of my function vs the OpenSSL function.

Apparently, the error I get is the same every time. The mismatching hash value 
comes:
1. Right before the SSL connection opens.
2. 11 hashes right before the above.

This happens every time, which leads me to question the OpenSSL 
protocol/hashing mechanism. Im pretty sure there is something I am missing.

BTW, this is my function (I am using an embbeded system running uClinux with my 
SHA verilog hardware core):

static void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, size_t num)
    {
    unsigned long *data = (unsigned long *)p;
    unsigned int i,j,offset=0;

    //Put in initial values
    IOWR(SHA1COPROCESSOR_BASE,4,c->h0);
    IOWR(SHA1COPROCESSOR_BASE,5,c->h1);
    IOWR(SHA1COPROCESSOR_BASE,6,c->h2);
    IOWR(SHA1COPROCESSOR_BASE,7,c->h3);
    IOWR(SHA1COPROCESSOR_BASE,8,c->h4);

    //Begin
    IOWR(SHA1COPROCESSOR_BASE, 1, 0xE0);

    //Write data sequence
    for (i=0; i<num; i++)
    {
        //Push Data
        for (j=0;j<16;j++)
        {
            // Insert Data
            IOWR(SHA1COPROCESSOR_BASE, 0, data[offset]);
            IOWR(SHA1COPROCESSOR_BASE, 1, 0xD8);
            IOWR(SHA1COPROCESSOR_BASE, 1, 0xD0);
            offset++;
        }
        
        //Reset and start (and clear)
        IOWR(SHA1COPROCESSOR_BASE, 1, 0xC4);
        IOWR(SHA1COPROCESSOR_BASE, 1, 0xC2);        
        IOWR(SHA1COPROCESSOR_BASE, 1, 0xC0);

        //Poll status register
        while (IORD(SHA1COPROCESSOR_BASE,2) == 4);
    }
    
    // Read Message Digest
    c->h4 = IORD(SHA1COPROCESSOR_BASE,3);
    IOWR(SHA1COPROCESSOR_BASE, 1, 0xC1);
    IOWR(SHA1COPROCESSOR_BASE, 1, 0xC0);
    
    c->h3 = IORD(SHA1COPROCESSOR_BASE,3);
    IOWR(SHA1COPROCESSOR_BASE, 1, 0xC1);
    IOWR(SHA1COPROCESSOR_BASE, 1, 0xC0);
    
    c->h2 = IORD(SHA1COPROCESSOR_BASE,3);
    IOWR(SHA1COPROCESSOR_BASE, 1, 0xC1);
    IOWR(SHA1COPROCESSOR_BASE, 1, 0xC0);
    
    c->h1 = IORD(SHA1COPROCESSOR_BASE,3);
    IOWR(SHA1COPROCESSOR_BASE, 1, 0xC1);
    IOWR(SHA1COPROCESSOR_BASE, 1, 0xC0);
    
    c->h0 = IORD(SHA1COPROCESSOR_BASE,3);
    IOWR(SHA1COPROCESSOR_BASE, 1, 0xC1);
    IOWR(SHA1COPROCESSOR_BASE, 1, 0xC0);
    }

_________________________________________________________________
Easily publish your photos to your Spaces with Photo Gallery.
http://get.live.com/photogallery/overview

Reply via email to