module Net::SSH::Transport::GCMCipher
def incr_nonce
MUST be padded out to a multiple of the block size (16-octets for AES-GCM).
The reader is reminded that SSH requires that the data to be encrypted
of key is produced.
The block_counter is initially set to one (1) and increment as each block
unit32 block_counter; // 4 octets
uint64 invocation_counter; // 8 octets
uint32 fixed; // 4 octets
following 16-octet data structure:
encrypt the plaintext. This keystream is produced by encrypting the
AES-GCM produces a keystream in blocks of 16-octets that is used to
each invocation of AES-GCM to process a binary packet.
The invocation field is treated as a 64-bit integer and is increment after
--- RFC 5647 ---
a given encryption device.
The Fixed field MUST remain constant for all nonces that are generated for
by one for each successive nonce that is generated.
The Counter part SHOULD be equal to zero for the first nonce and increment
byte order.
sequence, when those fields are regarded as unsignd integers in network
The Counter fields of successive nonces form a monotonically increasing
the Counter field is four octets long.
Counter field. Implementations SHOULD support 12-octet nonces in which
Initial octets consist of a fixed field and final octets consist of a
| fixed | counter |
- - - - - - - - - - - - - -
<- variable -> <- variable ->
(3.2) The following method to construct nonces is RECOMMENDED.
other method that meets the uniqueness requirement.
formation method defined in Section 3.2, and MAY use any
(2.1) Applications that can generate distinct nonces SHOULD use the nonce
--- RFC 5116 ---
The nonce_explicit MAY be the 64-bit sequence number.
meet this uniqueness requirement can significantly degrade security.
invocation of the GCM encrypt function for any fixed key. Failure to
Each value of the nonce_explicit MUST be distinct for each distinct
--- RFC 5288 ---
def incr_nonce return if nonce[:fixed].nil? nonce[:invocation_counter] = [nonce[:invocation_counter].to_s.unpack1('B*').to_i(2) + 1].pack('Q>*') apply_nonce end