Thread: adler32

  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,424

    adler32

    I did a copy paste then modified the code to be more efficient for this function, anyone have any idea where this prior_key value comes from?

    Linkified source url:
    assorted/Deflate (zlib) compressed data format.asciidoc at main * libyal/assorted * GitHub

    Code:
    /* Modified form of what's provided here:
     * https://github.com/libyal/assorted/blob/main/documentation/Deflate%20(zlib)%20compressed%20data%20format.asciidoc
     */
    ulong adler32_fetch( uint_least8_t *buff, size_t size, ulong prior_key )
    {
    	size_t i, j;
    	uint32_t lower_word    = prior_key & 0xffff;
    	uint32_t upper_word    = (prior_key >> 16) & 0xffff;
    
    	lower_word += buff[0];
    	upper_word += lower_word;
    	--size;
    
    	for( i = 1, j = 1; i < size; ++i, ++j )
    	{
    		lower_word += buff[i];
    		upper_word += lower_word;
    
    		if ( j == 0x15b0 )
    		{
    			lower_word = lower_word % 0xfff1;
    			upper_word = upper_word % 0xfff1;
    			j = 0;
    		}
    	}
    
    	lower_word += buff[i];
    	upper_word += lower_word;
    
    	lower_word = lower_word % 0xfff1;
    	upper_word = upper_word % 0xfff1;
    
    	return( ( upper_word << 16 ) | lower_word );
    }

  2. #2
    Registered User
    Join Date
    Sep 2020
    Posts
    294
    Quote Originally Posted by awsdert View Post
    I did a copy paste then modified the code to be more efficient for this function, anyone have any idea where this prior_key value comes from?

    Linkified source url:
    assorted/Deflate (zlib) compressed data format.asciidoc at main * libyal/assorted * GitHub

    Code:
    /* Modified form of what's provided here:
     * https://github.com/libyal/assorted/blob/main/documentation/Deflate%20(zlib)%20compressed%20data%20format.asciidoc
     */
    ulong adler32_fetch( uint_least8_t *buff, size_t size, ulong prior_key )
    {
        size_t i, j;
        uint32_t lower_word    = prior_key & 0xffff;
        uint32_t upper_word    = (prior_key >> 16) & 0xffff;
    
        lower_word += buff[0];
        upper_word += lower_word;
        --size;
    
        for( i = 1, j = 1; i < size; ++i, ++j )
        {
            lower_word += buff[i];
            upper_word += lower_word;
    
            if ( j == 0x15b0 )
            {
                lower_word = lower_word % 0xfff1;
                upper_word = upper_word % 0xfff1;
                j = 0;
            }
        }
    
        lower_word += buff[i];
        upper_word += lower_word;
    
        lower_word = lower_word % 0xfff1;
        upper_word = upper_word % 0xfff1;
    
        return( ( upper_word << 16 ) | lower_word );
    }
    For a given block of data, prior_key is 0x00000001 for the first time the function is called, and from then on whatever was returned by this function the last time it was called.

  3. #3
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,424
    Quote Originally Posted by hamster_nz View Post
    For a given block of data, prior_key is 0x00000001 for the first time the function is called, and from then on whatever was returned by this function the last time it was called.
    By that I assume I'm supposed to keep hold of each IDAT chunks result then?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. adler32 optimization
    By carrotcake1029 in forum C Programming
    Replies: 4
    Last Post: 07-10-2008, 11:17 AM

Tags for this Thread