A possible error in the book So I have been reading this book called "Implementing SSL/TLS using Cryptography and PKI" While going through it, this snippet of code got me baffled

    static void compute_key_schedule ( 
    const unsigned char *key, int key_length, unsigned char w[ ][ 4 ] ) { 
    int i; int key_words = key_length &gt;&gt; 2; 
    unsigned char rcon = 0x01; // First, copy the key directly into the key schedule 
    memcpy( w, key, key_length ); 
    for ( i = key_words; i &lt; 4 * ( key_words + 7 ); i++ ) { 
        memcpy( w[ i ], w[ i - 1 ], 4 ); 
        if ( !( i % key_words ) ) { 
            rot_word( w[ i ] ); 
            sub_word( w[ i ] ); 
            if ( !( i % 36 ) ) { 
                rcon = 0x1b; 
            } 
            w[ i ][ 0 ] ^= rcon; 
            rcon &lt;&lt;= 1; 
        } 
        else if ( ( key_words &gt; 6 ) &amp;&amp; ( ( i % key_words ) == 4 ) ) { 
            sub_word( w[ i ] ); 
        } 
        w[ i ][ 0 ] ^= w[ i - key_words ][ 0 ];
        w[ i ][ 1 ] ^= w[ i - key_words ][ 1 ];
        w[ i ][ 2 ] ^= w[ i - key_words ][ 2 ]; 
        w[ i ][ 3 ] ^= w[ i - key_words ][ 3 ]; 
    } 
}


The text says that in case of 128-bit key, round constant is shifted every 4 iterations (of forming single word of key for key schedule), making up total of 10 shifts, but at 8th shift, the round constant would be 0, and AES mandates that whenever it overflows, you should XOR it with 0x1b. So I get it that's why we did that if (i%36) rcon = 0x1b It makes sense, but if key_length is 192-bit, it would be problematic, since at iteration 36, it will pass the check if ( ! ( i % key_words)) and would proceed to change rcon to 0x1b, though there won't be any overflow at all! (I believe that key would be 0x10 at that time this shift will occur in case of 192-bit).

So it just doesn't makes sense to me and I wanted to know if there is something I am missing out on. At first I thought maybe it's necessary to rotate it every 4 iteration irrespective of key size but reading text and reading rest of code, I don't think that was an intention ever. Thanks a lot!
The question's code works for AES-128 and AES-256, but indeed does not for AES-192, for the reason pointed in the question.

Yes changing if ( !( i % 36 ) ) into if((!(i%36)) &amp;&amp; (key_words == 4)) as suggested in comment by the OP is enough to make it (and the rest of the code) pass the example of appendix A.2 and C.2 of FIPS&nbsp;197 (as well as A.1, A.3, C.1, C.3).

Reminds me of the book Security for Computer Networks by D.W. Davies (not the same Davies) and W.L. Price (May 1987 edition), which has a typo in the last constant for S4 of DES, causing failures for some test vectors. That drove me nuts for a while in the late 1980s. From that point on I implemented crypto on the basis of the standards.