@@ -116,13 +116,13 @@ private void setKey(final byte[] key, final byte[] nonce)
116116 throw new IllegalArgumentException ("Poly1305 requires a 128 bit IV." );
117117 }
118118
119- Poly1305KeyGenerator .checkKey (key );
119+ Poly1305KeyGenerator .clamp (key );
120120
121121 // Extract r portion of key
122- int t0 = Pack .littleEndianToInt (key , BLOCK_SIZE + 0 );
123- int t1 = Pack .littleEndianToInt (key , BLOCK_SIZE + 4 );
124- int t2 = Pack .littleEndianToInt (key , BLOCK_SIZE + 8 );
125- int t3 = Pack .littleEndianToInt (key , BLOCK_SIZE + 12 );
122+ int t0 = Pack .littleEndianToInt (key , 0 );
123+ int t1 = Pack .littleEndianToInt (key , 4 );
124+ int t2 = Pack .littleEndianToInt (key , 8 );
125+ int t3 = Pack .littleEndianToInt (key , 12 );
126126
127127 r0 = t0 & 0x3ffffff ; t0 >>>= 26 ; t0 |= t1 << 6 ;
128128 r1 = t0 & 0x3ffff03 ; t1 >>>= 20 ; t1 |= t2 << 12 ;
@@ -140,19 +140,24 @@ private void setKey(final byte[] key, final byte[] nonce)
140140 if (cipher == null )
141141 {
142142 kBytes = key ;
143+
144+ k0 = Pack .littleEndianToInt (kBytes , BLOCK_SIZE + 0 );
145+ k1 = Pack .littleEndianToInt (kBytes , BLOCK_SIZE + 4 );
146+ k2 = Pack .littleEndianToInt (kBytes , BLOCK_SIZE + 8 );
147+ k3 = Pack .littleEndianToInt (kBytes , BLOCK_SIZE + 12 );
143148 }
144149 else
145150 {
146151 // Compute encrypted nonce
147152 kBytes = new byte [BLOCK_SIZE ];
148- cipher .init (true , new KeyParameter (key , 0 , BLOCK_SIZE ));
153+ cipher .init (true , new KeyParameter (key , BLOCK_SIZE , BLOCK_SIZE ));
149154 cipher .processBlock (nonce , 0 , kBytes , 0 );
150- }
151155
152- k0 = Pack .littleEndianToInt (kBytes , 0 );
153- k1 = Pack .littleEndianToInt (kBytes , 4 );
154- k2 = Pack .littleEndianToInt (kBytes , 8 );
155- k3 = Pack .littleEndianToInt (kBytes , 12 );
156+ k0 = Pack .littleEndianToInt (kBytes , 0 );
157+ k1 = Pack .littleEndianToInt (kBytes , 4 );
158+ k2 = Pack .littleEndianToInt (kBytes , 8 );
159+ k3 = Pack .littleEndianToInt (kBytes , 12 );
160+ }
156161 }
157162
158163 public String getAlgorithmName ()
0 commit comments