@@ -158,7 +158,7 @@ int ocb_test(void)
158158
159159 int err , x , idx , res ;
160160 unsigned long len ;
161- unsigned char outct [MAXBLOCKSIZE ], outtag [MAXBLOCKSIZE ];
161+ unsigned char outct [MAXBLOCKSIZE ], outtag [MAXBLOCKSIZE ], outpt [ MAXBLOCKSIZE ] ;
162162
163163 /* AES can be under rijndael or aes... try to find it */
164164 if ((idx = find_cipher ("aes" )) == -1 ) {
@@ -179,6 +179,25 @@ int ocb_test(void)
179179 return CRYPT_FAIL_TESTVECTOR ;
180180 }
181181
182+ /* Decrypt with separate input and output buffers. Historically
183+ * s_ocb_done() had an aliasing bug in its decrypt path that only
184+ * surfaced when ct and pt were distinct buffers (the earlier
185+ * in-place call below masked it). Run this case first so it is
186+ * exercised on every test vector.
187+ */
188+ XMEMSET (outpt , 0 , sizeof (outpt ));
189+ if ((err = ocb_decrypt_verify_memory (idx , tests [x ].key , 16 , tests [x ].nonce , outct , tests [x ].ptlen ,
190+ outpt , tests [x ].tag , len , & res )) != CRYPT_OK ) {
191+ return err ;
192+ }
193+ if ((res != 1 ) || ltc_compare_testvector (outpt , tests [x ].ptlen , tests [x ].pt , tests [x ].ptlen , "OCB separate-buffer" , x )) {
194+ #ifdef LTC_TEST_DBG
195+ printf ("\n\nOCB: Failure-decrypt (separate buffers) - res = %d\n" , res );
196+ #endif
197+ return CRYPT_FAIL_TESTVECTOR ;
198+ }
199+
200+ /* Also exercise the in-place form for backward compatibility. */
182201 if ((err = ocb_decrypt_verify_memory (idx , tests [x ].key , 16 , tests [x ].nonce , outct , tests [x ].ptlen ,
183202 outct , tests [x ].tag , len , & res )) != CRYPT_OK ) {
184203 return err ;
0 commit comments