equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
25 |
25 |
26 package com.sun.crypto.provider; |
26 package com.sun.crypto.provider; |
27 |
27 |
28 import java.security.InvalidKeyException; |
28 import java.security.InvalidKeyException; |
29 import java.security.ProviderException; |
29 import java.security.ProviderException; |
|
30 import sun.security.util.ArrayUtil; |
30 |
31 |
31 /** |
32 /** |
32 * This class represents ciphers in electronic codebook (ECB) mode. |
33 * This class represents ciphers in electronic codebook (ECB) mode. |
33 * |
34 * |
34 * <p>This mode is implemented independently of a particular cipher. |
35 * <p>This mode is implemented independently of a particular cipher. |
110 * @exception ProviderException if <code>len</code> is not |
111 * @exception ProviderException if <code>len</code> is not |
111 * a multiple of the block size |
112 * a multiple of the block size |
112 * @return the length of the encrypted data |
113 * @return the length of the encrypted data |
113 */ |
114 */ |
114 int encrypt(byte[] in, int inOff, int len, byte[] out, int outOff) { |
115 int encrypt(byte[] in, int inOff, int len, byte[] out, int outOff) { |
115 if ((len % blockSize) != 0) { |
116 ArrayUtil.blockSizeCheck(len, blockSize); |
116 throw new ProviderException("Internal error in input buffering"); |
117 ArrayUtil.nullAndBoundsCheck(in, inOff, len); |
117 } |
118 ArrayUtil.nullAndBoundsCheck(out, outOff, len); |
|
119 |
118 for (int i = len; i >= blockSize; i -= blockSize) { |
120 for (int i = len; i >= blockSize; i -= blockSize) { |
119 embeddedCipher.encryptBlock(in, inOff, out, outOff); |
121 embeddedCipher.encryptBlock(in, inOff, out, outOff); |
120 inOff += blockSize; |
122 inOff += blockSize; |
121 outOff += blockSize; |
123 outOff += blockSize; |
122 } |
124 } |
139 * @exception ProviderException if <code>len</code> is not |
141 * @exception ProviderException if <code>len</code> is not |
140 * a multiple of the block size |
142 * a multiple of the block size |
141 * @return the length of the decrypted data |
143 * @return the length of the decrypted data |
142 */ |
144 */ |
143 int decrypt(byte[] in, int inOff, int len, byte[] out, int outOff) { |
145 int decrypt(byte[] in, int inOff, int len, byte[] out, int outOff) { |
144 if ((len % blockSize) != 0) { |
146 ArrayUtil.blockSizeCheck(len, blockSize); |
145 throw new ProviderException("Internal error in input buffering"); |
147 ArrayUtil.nullAndBoundsCheck(in, inOff, len); |
146 } |
148 ArrayUtil.nullAndBoundsCheck(out, outOff, len); |
|
149 |
147 for (int i = len; i >= blockSize; i -= blockSize) { |
150 for (int i = len; i >= blockSize; i -= blockSize) { |
148 embeddedCipher.decryptBlock(in, inOff, out, outOff); |
151 embeddedCipher.decryptBlock(in, inOff, out, outOff); |
149 inOff += blockSize; |
152 inOff += blockSize; |
150 outOff += blockSize; |
153 outOff += blockSize; |
151 } |
154 } |