Remove current_image global and macro updates

Currently to determine which image is being operated on, there is a global
variable called current_image which is used by most macros and APIs to
correctly access the flash areas required by the bootloader. This moves
this variable to the already existing state struct and refactors all
macros and APIs to receive the current image by parameters. To maintain
compatibility some of the macros were not updated and use image 0 when
called.

The definitions of FLASH_AREA_IMAGE_PRIMARY and FLASH_AREA_IMAGE_SECONDARY
for Mynewt compatibility were moved out of bootutil sources to a Mynewt
specific include file.

Signed-off-by: Fabio Utzig <utzig@apache.org>
diff --git a/boot/bootutil/src/encrypted.c b/boot/bootutil/src/encrypted.c
index 6dcaa22..f421f4c 100644
--- a/boot/bootutil/src/encrypted.c
+++ b/boot/bootutil/src/encrypted.c
@@ -215,8 +215,8 @@
  * Load encryption key.
  */
 int
-boot_enc_load(const struct image_header *hdr, const struct flash_area *fap,
-              uint8_t *enckey)
+boot_enc_load(int image_index, const struct image_header *hdr,
+        const struct flash_area *fap, uint8_t *enckey)
 {
 #if defined(MCUBOOT_ENCRYPT_RSA)
     mbedtls_rsa_context rsa;
@@ -233,7 +233,7 @@
     uint8_t enckey_type;
     int rc;
 
-    rc = flash_area_id_to_image_slot(fap->fa_id);
+    rc = flash_area_id_to_multi_image_slot(image_index, fap->fa_id);
     if (rc < 0) {
         return rc;
     }
@@ -307,14 +307,14 @@
 }
 
 bool
-boot_enc_valid(const struct flash_area *fap)
+boot_enc_valid(int image_index, const struct flash_area *fap)
 {
     int rc;
 
-    rc = flash_area_id_to_image_slot(fap->fa_id);
+    rc = flash_area_id_to_multi_image_slot(image_index, fap->fa_id);
     if (rc < 0) {
         /* can't get proper slot number - skip encryption, */
-        /* postpone the erro for a upper layer */
+        /* postpone the error for a upper layer */
         return false;
     }
 
@@ -332,8 +332,8 @@
 }
 
 void
-boot_encrypt(const struct flash_area *fap, uint32_t off, uint32_t sz,
-        uint32_t blk_off, uint8_t *buf)
+boot_encrypt(int image_index, const struct flash_area *fap, uint32_t off,
+        uint32_t sz, uint32_t blk_off, uint8_t *buf)
 {
     struct enc_key_data *enc;
     uint32_t i, j;
@@ -349,7 +349,7 @@
     nonce[14] = (uint8_t)(off >> 8);
     nonce[15] = (uint8_t)off;
 
-    rc = flash_area_id_to_image_slot(fap->fa_id);
+    rc = flash_area_id_to_multi_image_slot(image_index, fap->fa_id);
     if (rc < 0) {
         assert(0);
         return;