i am trying to generate the nonce for AES-GCM. I know people usually generate it by Counters and LFSRs. I am confused about the meaning of Counters. Is that means Counter (CTR)? Why it can generate unique nonce?
-
$\begingroup$ Thank you so much! $\endgroup$ – FRANKfisher Apr 12 '20 at 11:03
-
$\begingroup$ How do you do AES-GCM on linux? Which program? $\endgroup$ – eli Apr 13 '20 at 15:13
Counters are storing values and have usually clear, set, and increment functions. A counter can be implemented in software very easily by using an integer with enough size or using a library like Java BigInteger
or Gnu/GMP for C/C++.
clear()
makes the all bits zero:unsigned int counter=0
set(y)
set the counter value toy
:counter = y
increment()
increase the current value by 1;counter++
For GCM one needs 32 bits counter and a total 128-bit for the CTR mode's counter with the 96-bit nonce.
Take a 128-bit unsigned integer and init to zero. Then GCM will use it like
$ J_0 = IV || 0^{31} ||1 $
so during the implementation, you need to take a copy of the counter, shift 32 to left, and OR with 0x01
.