Few questions about CBC MAC I want to use CBC MAC. First I hope to find some implementation of block cipher which I will use in CBC mode, which I understand is CBC MAC. But I have two questions:

1) If the length of the message to be authenticated is not multiple of block cipher block length, what shall I do?

2) Do I need to use session keys with CBC MAC? e.e. use different key for each message. Or I can use one key for long time period?

2) To strengthen CBC MAC one recommended way as mentioned on Wiki is to put the length of the message in the first block. But how should I encode the length, as string? Or in binary? If block length of cipher is say 64 bits, do I encode the number as 64 bit number? e.g. if message length is 230, I should use following value as first block:

00000000 00000000 00000000 00000000 00000000 00000000 00000000 ‭11100110‬

?
1) Fill remaining of last block with nulls.

2) No, you can use same key for more messages, but not the same as encryption key.

3) Usually this is done binary, like you did. If you are going to use CBC MAC with variable length messages, you must do this.

I recommend you to use XCBC or CMAC instead (CBC MAC variants for variable length messages).