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 | 4 |
5 #ifdef FREEBL_NO_DEPEND | 5 #ifdef FREEBL_NO_DEPEND |
6 #include "stubs.h" | 6 #include "stubs.h" |
7 #endif | 7 #endif |
8 #include "blapii.h" | 8 #include "blapii.h" |
9 #include "blapit.h" | 9 #include "blapit.h" |
10 #include "gcm.h" | 10 #include "gcm.h" |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 if (len != blocksize) { | 223 if (len != blocksize) { |
224 PORT_Memset(X,0,blocksize-len); | 224 PORT_Memset(X,0,blocksize-len); |
225 X += blocksize-len; | 225 X += blocksize-len; |
226 } | 226 } |
227 | 227 |
228 err = mp_to_unsigned_octets(&ghash->X, X, len); | 228 err = mp_to_unsigned_octets(&ghash->X, X, len); |
229 if (err < 0) { | 229 if (err < 0) { |
230 PORT_SetError(SEC_ERROR_LIBRARY_FAILURE); | 230 PORT_SetError(SEC_ERROR_LIBRARY_FAILURE); |
231 return SECFailure; | 231 return SECFailure; |
232 } | 232 } |
233 gcm_reverse(T, X, blocksize); | 233 gcm_reverse(T, tmp_buf, blocksize); |
wtc
2013/03/26 18:24:46
The original code passes |X| as the second argumen
wtc
2013/03/26 18:41:56
If this bug in gcm_getX() only affects the zero-le
| |
234 return SECSuccess; | 234 return SECSuccess; |
235 } | 235 } |
236 | 236 |
237 static SECStatus | 237 static SECStatus |
238 gcm_HashMult(gcmHashContext *ghash, const unsigned char *buf, | 238 gcm_HashMult(gcmHashContext *ghash, const unsigned char *buf, |
239 unsigned int count, unsigned int blocksize) | 239 unsigned int count, unsigned int blocksize) |
240 { | 240 { |
241 SECStatus rv = SECFailure; | 241 SECStatus rv = SECFailure; |
242 mp_err err = MP_OKAY; | 242 mp_err err = MP_OKAY; |
243 unsigned char tmp_buf[MAX_BLOCK_SIZE]; | 243 unsigned char tmp_buf[MAX_BLOCK_SIZE]; |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
568 PORT_Memset(ghash->counterBuf, 0, GCM_HASH_LEN_LEN*2); | 568 PORT_Memset(ghash->counterBuf, 0, GCM_HASH_LEN_LEN*2); |
569 ghash->bufLen = 0; | 569 ghash->bufLen = 0; |
570 gcm_zeroX(ghash); | 570 gcm_zeroX(ghash); |
571 | 571 |
572 /* now kick things off by hashing the Additional Authenticated Data */ | 572 /* now kick things off by hashing the Additional Authenticated Data */ |
573 if (AADLen != 0) { | 573 if (AADLen != 0) { |
574 rv = gcmHash_Update(ghash, AAD, AADLen, blocksize); | 574 rv = gcmHash_Update(ghash, AAD, AADLen, blocksize); |
575 if (rv != SECSuccess) { | 575 if (rv != SECSuccess) { |
576 return SECFailure; | 576 return SECFailure; |
577 } | 577 } |
578 rv = gcmHash_Sync(ghash, blocksize); | |
579 if (rv != SECSuccess) { | |
580 return SECFailure; | |
581 } | |
582 } | 578 } |
579 rv = gcmHash_Sync(ghash, blocksize); | |
580 if (rv != SECSuccess) { | |
581 return SECFailure; | |
582 } | |
wtc
2013/03/26 18:24:46
This change is not necessary (because ghash->count
| |
583 return SECSuccess; | 583 return SECSuccess; |
584 } | 584 } |
585 | 585 |
586 /************************************************************************** | 586 /************************************************************************** |
587 * Now implement the GCM using gcmHash and CTR * | 587 * Now implement the GCM using gcmHash and CTR * |
588 **************************************************************************/ | 588 **************************************************************************/ |
589 | 589 |
590 /* state to handle the full GCM operation (hash and counter) */ | 590 /* state to handle the full GCM operation (hash and counter) */ |
591 struct GCMContextStr { | 591 struct GCMContextStr { |
592 gcmHashContext ghash_context; | 592 gcmHashContext ghash_context; |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
835 * preserve the masked off missing bits. */ | 835 * preserve the masked off missing bits. */ |
836 if (NSS_SecureMemcmp(tag, intag, tagBytes) != 0) { | 836 if (NSS_SecureMemcmp(tag, intag, tagBytes) != 0) { |
837 /* force a CKR_ENCRYPTED_DATA_INVALID error at in softoken */ | 837 /* force a CKR_ENCRYPTED_DATA_INVALID error at in softoken */ |
838 PORT_SetError(SEC_ERROR_BAD_DATA); | 838 PORT_SetError(SEC_ERROR_BAD_DATA); |
839 return SECFailure; | 839 return SECFailure; |
840 } | 840 } |
841 /* finish the decryption */ | 841 /* finish the decryption */ |
842 return CTR_Update(&gcm->ctr_context, outbuf, outlen, maxout, | 842 return CTR_Update(&gcm->ctr_context, outbuf, outlen, maxout, |
843 inbuf, inlen, blocksize); | 843 inbuf, inlen, blocksize); |
844 } | 844 } |
OLD | NEW |