13
13
import org .bouncycastle .tls .crypto .TlsCryptoUtils ;
14
14
import org .bouncycastle .tls .crypto .TlsDecodeResult ;
15
15
import org .bouncycastle .tls .crypto .TlsEncodeResult ;
16
- import org .bouncycastle .tls .crypto .TlsNonceGenerator ;
17
16
import org .bouncycastle .tls .crypto .TlsSecret ;
18
17
import org .bouncycastle .util .Arrays ;
19
18
@@ -31,7 +30,7 @@ public final class TlsAEADCipher
31
30
private static final int NONCE_RFC7905 = 2 ;
32
31
private static final long SEQUENCE_NUMBER_PLACEHOLDER = -1L ;
33
32
34
- private static final byte [] EPOCH_1 = {0x00 , 0x01 };
33
+ private static final byte [] EPOCH_1 = { 0x00 , 0x01 };
35
34
36
35
private final TlsCryptoParameters cryptoParams ;
37
36
private final int keySize ;
@@ -129,9 +128,9 @@ public TlsAEADCipher(TlsCryptoParameters cryptoParams, TlsAEADCipherImpl encrypt
129
128
130
129
if (AEAD_GCM == aeadType && GcmTls12NonceGeneratorUtil .isGcmFipsNonceGeneratorFactorySet ())
131
130
{
132
- final int nonceLength = fixed_iv_length + record_iv_length ;
133
- final byte [] baseNonce = Arrays .copyOf (encryptNonce , nonceLength );
134
- final int counterSizeInBits ;
131
+ int nonceLength = fixed_iv_length + record_iv_length ;
132
+ byte [] baseNonce = Arrays .copyOf (encryptNonce , nonceLength );
133
+ int counterSizeInBits ;
135
134
if (negotiatedVersion .isDTLS ())
136
135
{
137
136
counterSizeInBits = (record_iv_length - 2 ) * 8 ; // 48
@@ -142,7 +141,8 @@ public TlsAEADCipher(TlsCryptoParameters cryptoParams, TlsAEADCipherImpl encrypt
142
141
{
143
142
counterSizeInBits = record_iv_length * 8 ; // 64
144
143
}
145
- gcmFipsNonceGenerator = GcmTls12NonceGeneratorUtil .createGcmFipsNonceGenerator (baseNonce , counterSizeInBits );
144
+ gcmFipsNonceGenerator = GcmTls12NonceGeneratorUtil .createGcmFipsNonceGenerator (baseNonce ,
145
+ counterSizeInBits );
146
146
}
147
147
else
148
148
{
@@ -181,8 +181,7 @@ public int getPlaintextEncodeLimit(int ciphertextLimit)
181
181
public TlsEncodeResult encodePlaintext (long seqNo , short contentType , ProtocolVersion recordVersion ,
182
182
int headerAllocation , byte [] plaintext , int plaintextOffset , int plaintextLength ) throws IOException
183
183
{
184
- final int nonceSize = encryptNonce .length + record_iv_length ;
185
- final byte [] nonce = new byte [nonceSize ];
184
+ byte [] nonce = new byte [encryptNonce .length + record_iv_length ];
186
185
187
186
if (null != gcmFipsNonceGenerator )
188
187
{
@@ -192,20 +191,20 @@ public TlsEncodeResult encodePlaintext(long seqNo, short contentType, ProtocolVe
192
191
{
193
192
switch (nonceMode )
194
193
{
195
- case NONCE_RFC5288 :
196
- System .arraycopy (encryptNonce , 0 , nonce , 0 , encryptNonce .length );
197
- // RFC 5288/6655: The nonce_explicit MAY be the 64-bit sequence number.
198
- TlsUtils .writeUint64 (seqNo , nonce , encryptNonce .length );
199
- break ;
200
- case NONCE_RFC7905 :
201
- TlsUtils .writeUint64 (seqNo , nonce , nonce .length - 8 );
202
- for (int i = 0 ; i < encryptNonce .length ; ++i )
203
- {
204
- nonce [i ] ^= encryptNonce [i ];
205
- }
206
- break ;
207
- default :
208
- throw new TlsFatalAlert (AlertDescription .internal_error );
194
+ case NONCE_RFC5288 :
195
+ System .arraycopy (encryptNonce , 0 , nonce , 0 , encryptNonce .length );
196
+ // RFC 5288/6655: The nonce_explicit MAY be the 64-bit sequence number.
197
+ TlsUtils .writeUint64 (seqNo , nonce , encryptNonce .length );
198
+ break ;
199
+ case NONCE_RFC7905 :
200
+ TlsUtils .writeUint64 (seqNo , nonce , nonce .length - 8 );
201
+ for (int i = 0 ; i < encryptNonce .length ; ++i )
202
+ {
203
+ nonce [i ] ^= encryptNonce [i ];
204
+ }
205
+ break ;
206
+ default :
207
+ throw new TlsFatalAlert (AlertDescription .internal_error );
209
208
}
210
209
}
211
210
0 commit comments