ThePassionate commented on PR #18138:
URL: https://github.com/apache/nuttx/pull/18138#issuecomment-3796024639

   Good point! I notice that `kctx` and `ictx` have the same size 
(`axf->ctxsize`), 
   so we could actually reuse `ictx` for hashing the long key, then 
reinitialize it 
   for computing the ipad. This would save one memory allocation and make the 
code 
   more elegant:
   
   ```c
   /* If the key is too long, hash it first using ictx */
   if (cri->cri_klen / 8 > axf->keysize) {
       axf->init((*swd)->sw_ictx);              // Reuse ictx
       axf->update((*swd)->sw_ictx, 
                   (FAR uint8_t *)cri->cri_key, 
                   cri->cri_klen / 8);
       axf->final((unsigned char *)cri->cri_key, 
                  (*swd)->sw_ictx);
       cri->cri_klen = axf->hashsize * 8;
   }
   ```
   
   This way we avoid allocating a separate kctx while still correctly 
implementing the RFC 2104 requirement to hash long keys before use.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to