Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 /* $Id: rijndael.c,v 1.30 2013/01/25 18:02:53 rrelyea%redhat.com Exp $ */ | 4 /* $Id: rijndael.c,v 1.30 2013/01/25 18:02:53 rrelyea%redhat.com Exp $ */ |
| 5 | 5 |
| 6 #ifdef FREEBL_NO_DEPEND | 6 #ifdef FREEBL_NO_DEPEND |
| 7 #include "stubs.h" | 7 #include "stubs.h" |
| 8 #endif | 8 #endif |
| 9 | 9 |
| 10 #include "prinit.h" | 10 #include "prinit.h" |
| (...skipping 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1214 * Encrypt an arbitrary-length buffer. The output buffer must already be | 1214 * Encrypt an arbitrary-length buffer. The output buffer must already be |
| 1215 * allocated to at least inputLen. | 1215 * allocated to at least inputLen. |
| 1216 */ | 1216 */ |
| 1217 SECStatus | 1217 SECStatus |
| 1218 AES_Encrypt(AESContext *cx, unsigned char *output, | 1218 AES_Encrypt(AESContext *cx, unsigned char *output, |
| 1219 unsigned int *outputLen, unsigned int maxOutputLen, | 1219 unsigned int *outputLen, unsigned int maxOutputLen, |
| 1220 const unsigned char *input, unsigned int inputLen) | 1220 const unsigned char *input, unsigned int inputLen) |
| 1221 { | 1221 { |
| 1222 int blocksize; | 1222 int blocksize; |
| 1223 /* Check args */ | 1223 /* Check args */ |
| 1224 if (cx == NULL || output == NULL || input == NULL) { | 1224 if (cx == NULL || output == NULL || (input == NULL && inputLen != 0)) { |
|
wtc
2013/03/26 18:24:46
These changes allow an empty input to be represent
Ryan Sleevi
2013/03/26 18:39:14
I checked the PKCS#11 2.30 specs, and this seems v
| |
| 1225 PORT_SetError(SEC_ERROR_INVALID_ARGS); | 1225 PORT_SetError(SEC_ERROR_INVALID_ARGS); |
| 1226 return SECFailure; | 1226 return SECFailure; |
| 1227 } | 1227 } |
| 1228 blocksize = 4 * cx->Nb; | 1228 blocksize = 4 * cx->Nb; |
| 1229 if (cx->isBlock && (inputLen % blocksize != 0)) { | 1229 if (cx->isBlock && (inputLen % blocksize != 0)) { |
| 1230 PORT_SetError(SEC_ERROR_INPUT_LEN); | 1230 PORT_SetError(SEC_ERROR_INPUT_LEN); |
| 1231 return SECFailure; | 1231 return SECFailure; |
| 1232 } | 1232 } |
| 1233 if (maxOutputLen < inputLen) { | 1233 if (maxOutputLen < inputLen) { |
| 1234 PORT_SetError(SEC_ERROR_OUTPUT_LEN); | 1234 PORT_SetError(SEC_ERROR_OUTPUT_LEN); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1245 * Decrypt and arbitrary-length buffer. The output buffer must already be | 1245 * Decrypt and arbitrary-length buffer. The output buffer must already be |
| 1246 * allocated to at least inputLen. | 1246 * allocated to at least inputLen. |
| 1247 */ | 1247 */ |
| 1248 SECStatus | 1248 SECStatus |
| 1249 AES_Decrypt(AESContext *cx, unsigned char *output, | 1249 AES_Decrypt(AESContext *cx, unsigned char *output, |
| 1250 unsigned int *outputLen, unsigned int maxOutputLen, | 1250 unsigned int *outputLen, unsigned int maxOutputLen, |
| 1251 const unsigned char *input, unsigned int inputLen) | 1251 const unsigned char *input, unsigned int inputLen) |
| 1252 { | 1252 { |
| 1253 int blocksize; | 1253 int blocksize; |
| 1254 /* Check args */ | 1254 /* Check args */ |
| 1255 if (cx == NULL || output == NULL || input == NULL) { | 1255 if (cx == NULL || output == NULL || (input == NULL && inputLen != 0)) { |
| 1256 PORT_SetError(SEC_ERROR_INVALID_ARGS); | 1256 PORT_SetError(SEC_ERROR_INVALID_ARGS); |
| 1257 return SECFailure; | 1257 return SECFailure; |
| 1258 } | 1258 } |
| 1259 blocksize = 4 * cx->Nb; | 1259 blocksize = 4 * cx->Nb; |
| 1260 if (cx->isBlock && (inputLen % blocksize != 0)) { | 1260 if (cx->isBlock && (inputLen % blocksize != 0)) { |
| 1261 PORT_SetError(SEC_ERROR_INPUT_LEN); | 1261 PORT_SetError(SEC_ERROR_INPUT_LEN); |
| 1262 return SECFailure; | 1262 return SECFailure; |
| 1263 } | 1263 } |
| 1264 if (maxOutputLen < inputLen) { | 1264 if (maxOutputLen < inputLen) { |
| 1265 PORT_SetError(SEC_ERROR_OUTPUT_LEN); | 1265 PORT_SetError(SEC_ERROR_OUTPUT_LEN); |
| 1266 return SECFailure; | 1266 return SECFailure; |
| 1267 } | 1267 } |
| 1268 *outputLen = inputLen; | 1268 *outputLen = inputLen; |
| 1269 return (*cx->worker)(cx->worker_cx, output, outputLen, maxOutputLen, | 1269 return (*cx->worker)(cx->worker_cx, output, outputLen, maxOutputLen, |
| 1270 input, inputLen, blocksize); | 1270 input, inputLen, blocksize); |
| 1271 } | 1271 } |
| OLD | NEW |