Overview
I'm trying to come up with a way for a server and client to be able to generate a unique IV for each request that is both different for every client and yet deterministic. What I mean by deterministic is that the server can calculate the IV for any request in the future knowing only the starting sequence.
The reason I am need this capability is that I'm using the AES encryption to implement a one time password (OTP) scheme. When the client logs into the server it is given a seed. The first OTP is generated by encrypting this seed. For each subsequent request the client encrypts the last OTP using the shared AES key between the server and the client. Hence, even if an attacker sniffed the last OTP without the shared key they would not be able to get the next OTP. The OTP is being encrypted with AES in CBC mode. The problem comes if the server and client get out of sync. The way I was planning on dealing with this was by generating a few OTP's into the future on the server side and seeing if any of them matched the client's. However, without a way to deterministically calculate the IV for each encryption iteration this is not possible.
Before I get into my proposed solution let me express my understanding about AES, IV's, CBC, and ECB. That way if I have any misunderstandings in my fundamentals they can be pointed out and corrected.
Theory
ECB
I know that ECB will produce the same output for identical blocks of plaintext encrypted with the same keys. Hence it shouldn't be used for multiple blocks of data because information about the plaintext can be discerned by statistically analyzing the data. Based on this it would seem that if you could guarantee your data was always less than 16 bytes (128 bits) it would eliminate the problem of the statistical attack. In addition if you could also guarantee that you never encrypted the same plaintext with the same key you would never get the same output. Therefore it seems to me that using ECB is safe assuming your system will always meet these very strict criteria.
CBC and IV
I know that CBC is meant to eliminate both of these problems. By chaining blocks it eliminates the multi block statistical attack of ECB. By never using the same IV for the same AES key you eliminate the problem of having the same plaintext encrypt to the same output with the same key.
Key Uniqueness
If each client gets a generated AES key then while there is a small probability of multiple users having the same key the chances are extremely small. Therefore it is safe to assume that no two clients will be using the same AES key.
The Proposed Solution
My proposed solution is to give each client a unique AES key. When the key is generated a counter will be initialized to a random number. Each time something must be encrypted the counter will increment by one. This number will be padded to a block and then encrypted using AES in ECB mode. The output of this will be my IV for encrypting the data using CBC.
If the server gets out of sync with the client's counter because it has the same key and ECB requires no IV it can keep generating IV's until it finds one that allows the data to be decrypted.
My thoughts are this IV is safe from the statistical attack because it is equal to the block size of AES. In addition it will be different for every user, every time because each user will have a unique key and the counter will always increment. Obviously the AES keys must be transmitted securely (right now the client is encrypting the generated key with the server's public RSA key).
My Questions
Is my fundamental understanding of the technologies described in the proposed solution correct? Is there anything obviously wrong with my proposed solution? Is there any security flaw of using the same key to generate the IV in the proposed manner as well as to encrypt using CBC?
I realize the last question may be difficult/impossible to answer because cryptography is really hard, but any insight would be appreciated.
Thanks in advance.