< prev index next >

src/java.base/share/classes/sun/security/provider/ByteArrayAccess.java

Print this page
rev 13987 : 8051408: NIST SP 800-90A SecureRandom implementations


 431             // no optimization for big endian, see comments in b2lBig
 432             b2lBig(in, inOfs, out, 0, 128);
 433         }
 434     }
 435 
 436     /**
 437      * long[] to byte[] conversion, big endian byte order.
 438      */
 439     static void l2bBig(long[] in, int inOfs, byte[] out, int outOfs, int len) {
 440         if ((inOfs < 0) || ((in.length - inOfs) < len/8) ||
 441             (outOfs < 0) || ((out.length - outOfs) < len)) {
 442             throw new ArrayIndexOutOfBoundsException();
 443         }
 444         len += outOfs;
 445         while (outOfs < len) {
 446             long i = in[inOfs++];
 447             out[outOfs++] = (byte)(i >> 56);
 448             out[outOfs++] = (byte)(i >> 48);
 449             out[outOfs++] = (byte)(i >> 40);
 450             out[outOfs++] = (byte)(i >> 32);
 451             out[outOfs++] = (byte)(i >> 24);
 452             out[outOfs++] = (byte)(i >> 16);
 453             out[outOfs++] = (byte)(i >>  8);
 454             out[outOfs++] = (byte)(i      );


 455         }
 456     }
 457 }


 431             // no optimization for big endian, see comments in b2lBig
 432             b2lBig(in, inOfs, out, 0, 128);
 433         }
 434     }
 435 
 436     /**
 437      * long[] to byte[] conversion, big endian byte order.
 438      */
 439     static void l2bBig(long[] in, int inOfs, byte[] out, int outOfs, int len) {
 440         if ((inOfs < 0) || ((in.length - inOfs) < len/8) ||
 441             (outOfs < 0) || ((out.length - outOfs) < len)) {
 442             throw new ArrayIndexOutOfBoundsException();
 443         }
 444         len += outOfs;
 445         while (outOfs < len) {
 446             long i = in[inOfs++];
 447             out[outOfs++] = (byte)(i >> 56);
 448             out[outOfs++] = (byte)(i >> 48);
 449             out[outOfs++] = (byte)(i >> 40);
 450             out[outOfs++] = (byte)(i >> 32);
 451             if (outOfs < len) {     // SHA-512/224 is 28 bytes
 452                 out[outOfs++] = (byte) (i >> 24);
 453                 out[outOfs++] = (byte) (i >> 16);
 454                 out[outOfs++] = (byte) (i >> 8);
 455                 out[outOfs++] = (byte) (i);
 456             }
 457         }
 458     }
 459 }
< prev index next >