nkaje commented on a change in pull request #2176: da1469x: support blocks that 
are not ENC_FLASH_BLK multiples.
URL: https://github.com/apache/mynewt-core/pull/2176#discussion_r375353656
 
 

 ##########
 File path: hw/drivers/flash/enc_flash/ef_da1469x/src/hw_enc_flash.c
 ##########
 @@ -132,18 +133,34 @@ do_encrypt(const struct hal_flash *h_dev, uint32_t *ctr, 
const uint8_t *src, uin
     da1469x_clock_amba_disable(CRG_TOP_CLK_AMBA_REG_AES_CLK_ENABLE_Msk);
 }
 
+static void
+ef_da_get_block(const struct hal_flash *h_dev, uint32_t *ctr, uint32_t addr, 
uint8_t *blk)
+{
+    memcpy(blk, ENC_FLASH_NONCE, 12);
+    memcpy(blk + 12, &addr, sizeof(addr));
+
+    do_encrypt(h_dev, ctr, blk, blk);
+}
+
 void
 enc_flash_crypt_arch(struct enc_flash_dev *edev, uint32_t blk_addr,
                      const uint8_t *src, uint8_t *tgt, int off, int cnt)
 {
     struct eflash_da1469x_dev *dev = EDEV_TO_DA1469X(edev);
     const struct hal_flash *h_dev = edev->efd_hwdev;
     uint32_t ctr[4] = {0};
+    uint8_t blk[ENC_FLASH_BLK];
+    uint8_t *b;
+    int i;
 
     ctr[0] = (uint32_t) ((blk_addr - h_dev->hf_base_addr) / ENC_FLASH_BLK);
 
     os_sem_pend(&dev->ef_sem, OS_TIMEOUT_NEVER);
-    do_encrypt(h_dev, ctr, src, tgt, off, cnt);
+    ef_da_get_block(h_dev, ctr, blk_addr, blk);
+    b = &blk[off];
+    for (i = 0; i < cnt; i++) {
+        *tgt++ = *b++ ^ *src++;
+    }
 
 Review comment:
   Modified by removing the` XOR` operations and using `memcpy` instead.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to