Java Code Examples for sun.security.util.ArrayUtil#blockSizeCheck()
The following examples show how to use
sun.security.util.ArrayUtil#blockSizeCheck() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OutputFeedback.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Performs encryption operation. * * <p>The input plain text <code>plain</code>, starting at * <code>plainOffset</code> and ending at * <code>(plainOffset + plainLen - 1)</code>, is encrypted. * The result is stored in <code>cipher</code>, starting at * <code>cipherOffset</code>. * * @param plain the buffer with the input data to be encrypted * @param plainOffset the offset in <code>plain</code> * @param plainLen the length of the input data * @param cipher the buffer for the result * @param cipherOffset the offset in <code>cipher</code> * @exception ProviderException if <code>plainLen</code> is not * a multiple of the <code>numBytes</code> * @return the length of the encrypted data */ int encrypt(byte[] plain, int plainOffset, int plainLen, byte[] cipher, int cipherOffset) { ArrayUtil.blockSizeCheck(plainLen, numBytes); ArrayUtil.nullAndBoundsCheck(plain, plainOffset, plainLen); ArrayUtil.nullAndBoundsCheck(cipher, cipherOffset, plainLen); int nShift = blockSize - numBytes; int loopCount = plainLen / numBytes; for (; loopCount > 0; plainOffset += numBytes, cipherOffset += numBytes, loopCount--) { embeddedCipher.encryptBlock(register, 0, k, 0); for (int i = 0; i < numBytes; i++) { cipher[i + cipherOffset] = (byte)(k[i] ^ plain[i + plainOffset]); } if (nShift != 0) { System.arraycopy(register, numBytes, register, 0, nShift); } System.arraycopy(k, 0, register, nShift, numBytes); } return plainLen; }
Example 2
Source File: PCBC.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Performs encryption operation. * * <p>The input plain text <code>plain</code>, starting at * <code>plainOffset</code> and ending at * <code>(plainOffset + plainLen - 1)</code>, is encrypted. * The result is stored in <code>cipher</code>, starting at * <code>cipherOffset</code>. * * @param plain the buffer with the input data to be encrypted * @param plainOffset the offset in <code>plain</code> * @param plainLen the length of the input data * @param cipher the buffer for the result * @param cipherOffset the offset in <code>cipher</code> * @exception ProviderException if <code>plainLen</code> is not * a multiple of the block size * @return the length of the encrypted data */ int encrypt(byte[] plain, int plainOffset, int plainLen, byte[] cipher, int cipherOffset) { ArrayUtil.blockSizeCheck(plainLen, blockSize); ArrayUtil.nullAndBoundsCheck(plain, plainOffset, plainLen); ArrayUtil.nullAndBoundsCheck(cipher, cipherOffset, plainLen); int i; int endIndex = plainOffset + plainLen; for (; plainOffset < endIndex; plainOffset += blockSize, cipherOffset += blockSize) { for (i = 0; i < blockSize; i++) { k[i] ^= plain[i + plainOffset]; } embeddedCipher.encryptBlock(k, 0, cipher, cipherOffset); for (i = 0; i < blockSize; i++) { k[i] = (byte)(plain[i + plainOffset] ^ cipher[i + cipherOffset]); } } return plainLen; }
Example 3
Source File: PCBC.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Performs decryption operation. * * <p>The input cipher text <code>cipher</code>, starting at * <code>cipherOffset</code> and ending at * <code>(cipherOffset + cipherLen - 1)</code>, is decrypted. * The result is stored in <code>plain</code>, starting at * <code>plainOffset</code>. * * @param cipher the buffer with the input data to be decrypted * @param cipherOffset the offset in <code>cipherOffset</code> * @param cipherLen the length of the input data * @param plain the buffer for the result * @param plainOffset the offset in <code>plain</code> * @exception ProviderException if <code>cipherLen</code> is not * a multiple of the block size * @return the length of the decrypted data */ int decrypt(byte[] cipher, int cipherOffset, int cipherLen, byte[] plain, int plainOffset) { ArrayUtil.blockSizeCheck(cipherLen, blockSize); ArrayUtil.nullAndBoundsCheck(cipher, cipherOffset, cipherLen); ArrayUtil.nullAndBoundsCheck(plain, plainOffset, cipherLen); int i; int endIndex = cipherOffset + cipherLen; for (; cipherOffset < endIndex; plainOffset += blockSize, cipherOffset += blockSize) { embeddedCipher.decryptBlock(cipher, cipherOffset, plain, plainOffset); for (i = 0; i < blockSize; i++) { plain[i + plainOffset] ^= k[i]; } for (i = 0; i < blockSize; i++) { k[i] = (byte)(plain[i + plainOffset] ^ cipher[i + cipherOffset]); } } return cipherLen; }
Example 4
Source File: GaloisCounterMode.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Performs encryption operation. * * <p>The input plain text <code>in</code>, starting at <code>inOfs</code> * and ending at <code>(inOfs + len - 1)</code>, is encrypted. The result * is stored in <code>out</code>, starting at <code>outOfs</code>. * * @param in the buffer with the input data to be encrypted * @param inOfs the offset in <code>in</code> * @param len the length of the input data * @param out the buffer for the result * @param outOfs the offset in <code>out</code> * @exception ProviderException if <code>len</code> is not * a multiple of the block size * @return the number of bytes placed into the <code>out</code> buffer */ int encrypt(byte[] in, int inOfs, int len, byte[] out, int outOfs) { ArrayUtil.blockSizeCheck(len, blockSize); checkDataLength(processed, len); processAAD(); if (len > 0) { ArrayUtil.nullAndBoundsCheck(in, inOfs, len); ArrayUtil.nullAndBoundsCheck(out, outOfs, len); gctrPAndC.update(in, inOfs, len, out, outOfs); processed += len; ghashAllToS.update(out, outOfs, len); } return len; }
Example 5
Source File: CipherFeedback.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Performs encryption operation. * * <p>The input plain text <code>plain</code>, starting at * <code>plainOffset</code> and ending at * <code>(plainOffset + plainLen - 1)</code>, is encrypted. * The result is stored in <code>cipher</code>, starting at * <code>cipherOffset</code>. * * @param plain the buffer with the input data to be encrypted * @param plainOffset the offset in <code>plain</code> * @param plainLen the length of the input data * @param cipher the buffer for the result * @param cipherOffset the offset in <code>cipher</code> * @exception ProviderException if <code>plainLen</code> is not * a multiple of the <code>numBytes</code> * @return the length of the encrypted data */ int encrypt(byte[] plain, int plainOffset, int plainLen, byte[] cipher, int cipherOffset) { ArrayUtil.blockSizeCheck(plainLen, numBytes); ArrayUtil.nullAndBoundsCheck(plain, plainOffset, plainLen); ArrayUtil.nullAndBoundsCheck(cipher, cipherOffset, plainLen); int nShift = blockSize - numBytes; int loopCount = plainLen / numBytes; for (; loopCount > 0 ; plainOffset += numBytes, cipherOffset += numBytes, loopCount--) { embeddedCipher.encryptBlock(register, 0, k, 0); if (nShift != 0) { System.arraycopy(register, numBytes, register, 0, nShift); } for (int i = 0; i < numBytes; i++) { register[nShift + i] = cipher[i + cipherOffset] = (byte)(k[i] ^ plain[i + plainOffset]); } } return plainLen; }
Example 6
Source File: CipherFeedback.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Performs decryption operation. * * <p>The input cipher text <code>cipher</code>, starting at * <code>cipherOffset</code> and ending at * <code>(cipherOffset + cipherLen - 1)</code>, is decrypted. * The result is stored in <code>plain</code>, starting at * <code>plainOffset</code>. * * @param cipher the buffer with the input data to be decrypted * @param cipherOffset the offset in <code>cipherOffset</code> * @param cipherLen the length of the input data * @param plain the buffer for the result * @param plainOffset the offset in <code>plain</code> * @exception ProviderException if <code>cipherLen</code> is not * a multiple of the <code>numBytes</code> * @return the length of the decrypted data */ int decrypt(byte[] cipher, int cipherOffset, int cipherLen, byte[] plain, int plainOffset) { ArrayUtil.blockSizeCheck(cipherLen, numBytes); ArrayUtil.nullAndBoundsCheck(cipher, cipherOffset, cipherLen); ArrayUtil.nullAndBoundsCheck(plain, plainOffset, cipherLen); int nShift = blockSize - numBytes; int loopCount = cipherLen / numBytes; for (; loopCount > 0; plainOffset += numBytes, cipherOffset += numBytes, loopCount--) { embeddedCipher.encryptBlock(register, 0, k, 0); if (nShift != 0) { System.arraycopy(register, numBytes, register, 0, nShift); } for (int i = 0; i < numBytes; i++) { register[i + nShift] = cipher[i + cipherOffset]; plain[i + plainOffset] = (byte)(cipher[i + cipherOffset] ^ k[i]); } } return cipherLen; }
Example 7
Source File: GaloisCounterMode.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * Performs decryption operation. * * <p>The input cipher text <code>in</code>, starting at * <code>inOfs</code> and ending at <code>(inOfs + len - 1)</code>, * is decrypted. The result is stored in <code>out</code>, starting at * <code>outOfs</code>. * * @param in the buffer with the input data to be decrypted * @param inOfs the offset in <code>in</code> * @param len the length of the input data * @param out the buffer for the result * @param outOfs the offset in <code>out</code> * @exception ProviderException if <code>len</code> is not * a multiple of the block size * @return the number of bytes placed into the <code>out</code> buffer */ int decrypt(byte[] in, int inOfs, int len, byte[] out, int outOfs) { ArrayUtil.blockSizeCheck(len, blockSize); checkDataLength(ibuffer.size(), len); processAAD(); if (len > 0) { // store internally until decryptFinal is called because // spec mentioned that only return recovered data after tag // is successfully verified ArrayUtil.nullAndBoundsCheck(in, inOfs, len); ibuffer.write(in, inOfs, len); } return 0; }
Example 8
Source File: CipherBlockChaining.java From Bytecoder with Apache License 2.0 | 3 votes |
/** * Performs encryption operation. * * <p>The input plain text <code>plain</code>, starting at * <code>plainOffset</code> and ending at * <code>(plainOffset + plainLen - 1)</code>, is encrypted. * The result is stored in <code>cipher</code>, starting at * <code>cipherOffset</code>. * * @param plain the buffer with the input data to be encrypted * @param plainOffset the offset in <code>plain</code> * @param plainLen the length of the input data * @param cipher the buffer for the result * @param cipherOffset the offset in <code>cipher</code> * @exception ProviderException if <code>len</code> is not * a multiple of the block size * @return the length of the encrypted data */ int encrypt(byte[] plain, int plainOffset, int plainLen, byte[] cipher, int cipherOffset) { if (plainLen <= 0) { return plainLen; } ArrayUtil.blockSizeCheck(plainLen, blockSize); ArrayUtil.nullAndBoundsCheck(plain, plainOffset, plainLen); ArrayUtil.nullAndBoundsCheck(cipher, cipherOffset, plainLen); return implEncrypt(plain, plainOffset, plainLen, cipher, cipherOffset); }
Example 9
Source File: CipherBlockChaining.java From Bytecoder with Apache License 2.0 | 3 votes |
/** * Performs decryption operation. * * <p>The input cipher text <code>cipher</code>, starting at * <code>cipherOffset</code> and ending at * <code>(cipherOffset + cipherLen - 1)</code>, is decrypted. * The result is stored in <code>plain</code>, starting at * <code>plainOffset</code>. * * <p>It is also the application's responsibility to make sure that * <code>init</code> has been called before this method is called. * (This check is omitted here, to avoid double checking.) * * @param cipher the buffer with the input data to be decrypted * @param cipherOffset the offset in <code>cipherOffset</code> * @param cipherLen the length of the input data * @param plain the buffer for the result * @param plainOffset the offset in <code>plain</code> * @exception ProviderException if <code>len</code> is not * a multiple of the block size * @return the length of the decrypted data */ int decrypt(byte[] cipher, int cipherOffset, int cipherLen, byte[] plain, int plainOffset) { if (cipherLen <= 0) { return cipherLen; } ArrayUtil.blockSizeCheck(cipherLen, blockSize); ArrayUtil.nullAndBoundsCheck(cipher, cipherOffset, cipherLen); ArrayUtil.nullAndBoundsCheck(plain, plainOffset, cipherLen); return implDecrypt(cipher, cipherOffset, cipherLen, plain, plainOffset); }
Example 10
Source File: ElectronicCodeBook.java From Bytecoder with Apache License 2.0 | 3 votes |
/** * Performs encryption operation. * * <p>The input plain text <code>in</code>, starting at * <code>inOff</code> and ending at * <code>(inOff + len - 1)</code>, * is encrypted. The result is stored in <code>out</code>, starting at * <code>outOff</code>. * * @param in the buffer with the input data to be encrypted * @param inOff the offset in <code>plain</code> * @param len the length of the input data * @param out the buffer for the result * @param outOff the offset in <code>cipher</code> * @exception ProviderException if <code>len</code> is not * a multiple of the block size * @return the length of the encrypted data */ int encrypt(byte[] in, int inOff, int len, byte[] out, int outOff) { ArrayUtil.blockSizeCheck(len, blockSize); ArrayUtil.nullAndBoundsCheck(in, inOff, len); ArrayUtil.nullAndBoundsCheck(out, outOff, len); return implECBEncrypt(in, inOff, len, out, outOff); }
Example 11
Source File: ElectronicCodeBook.java From Bytecoder with Apache License 2.0 | 3 votes |
/** * Performs decryption operation. * * <p>The input cipher text <code>in</code>, starting at * <code>inOff</code> and ending at * <code>(inOff + len - 1)</code>, * is decrypted.The result is stored in <code>out</code>, starting at * <code>outOff</code>. * * @param in the buffer with the input data to be decrypted * @param inOff the offset in <code>cipherOffset</code> * @param len the length of the input data * @param out the buffer for the result * @param outOff the offset in <code>plain</code> * @exception ProviderException if <code>len</code> is not * a multiple of the block size * @return the length of the decrypted data */ int decrypt(byte[] in, int inOff, int len, byte[] out, int outOff) { ArrayUtil.blockSizeCheck(len, blockSize); ArrayUtil.nullAndBoundsCheck(in, inOff, len); ArrayUtil.nullAndBoundsCheck(out, outOff, len); return implECBDecrypt(in, inOff, len, out, outOff); }