static void calculateIV()

in src/main/java/org/apache/commons/crypto/stream/CtrCryptoInputStream.java [76:93]


    static void calculateIV(final byte[] initIV, long counter, final byte[] IV) {
        int i = IV.length; // IV length

        Utils.checkArgument(initIV.length == CryptoCipherFactory.AES_BLOCK_SIZE);
        Utils.checkArgument(i == CryptoCipherFactory.AES_BLOCK_SIZE);

        int j = 0; // counter bytes index
        int sum = 0;
        while (i-- > 0) {
            // (sum >>> Byte.SIZE) is the carry for addition
            sum = (initIV[i] & 0xff) + (sum >>> Byte.SIZE); // NOPMD
            if (j++ < 8) { // Big-endian, and long is 8 bytes length
                sum += (byte) counter & 0xff;
                counter >>>= 8;
            }
            IV[i] = (byte) sum;
        }
    }