Is AES ECB mode safe for one block Encryption then MAC with same key?

I want to do something really basic but I need to be sure that the process is safe :


Alice and Bob have to agree on a secret 6 digits PIN. They each have a pre-shared aes symetric key k and a AES-128 block cipher. The PIN will then be used only once secretly.

I want to take care of Man-in-the-Middle.


  • Alice creates à 128 bits random number : Arand
  • She encrypts Arand with basic ECB(Arand, k) and gets Acipher
  • Again, She encrypts Acipherwith ECB(Acipher, k), as a MAC, and gets Amac
  • Alice sends to Bob Acipher|Amac

Bob does the same and sends Bcipher|Bmac to Alice

  • The two of them verify the Mac by encrypting [A|B]cipher and comparing it to [A|B]mac.

  • If the mac is ok, they uncipher [A|B]cipher and get the [A|B]rand of the other.

  • They compute the 6 digits PIN by taking 3 digits in Arand and 3 in Brand.


Is it safe to use ECB mode in this particular case ? Is it safe to use the same key for encryption and for the mac in this case ? Is there a much easier solution to only agree on 6 digits ?

my answer is : as we use fixed size one-bloc long messages, it’s ok am i right ?

I know we should’nt imagine ourself our own algorithms but this one seems really trivial.

Thanks ! Louis