Commit 6fdbf557 authored by Salome Thirot's avatar Salome Thirot Committed by Fabio Utzig
Browse files

Sim: Add testcases for AES256 image encryption

parent 0f64197a
Loading
Loading
Loading
Loading
+3 −2
Changes for sim/Cargo.lock: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@ dependencies = [
 "serde",
 "serde_derive",
 "simflash",
 "typenum",
 "untrusted",
]

@@ -503,9 +504,9 @@ dependencies = [

[[package]]
name = "typenum"
version = "1.11.2"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9"
checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06"

[[package]]
name = "unicode-segmentation"
+5 −0
Changes for sim/Cargo.toml: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -16,10 +16,14 @@ overwrite-only = ["mcuboot-sys/overwrite-only"]
swap-move = ["mcuboot-sys/swap-move"]
validate-primary-slot = ["mcuboot-sys/validate-primary-slot"]
enc-rsa = ["mcuboot-sys/enc-rsa"]
enc-aes256-rsa = ["mcuboot-sys/enc-aes256-rsa"]
enc-kw = ["mcuboot-sys/enc-kw"]
enc-aes256-kw = ["mcuboot-sys/enc-aes256-kw"]
enc-ec256 = ["mcuboot-sys/enc-ec256"]
enc-ec256-mbedtls = ["mcuboot-sys/enc-ec256-mbedtls"]
enc-aes256-ec256 = ["mcuboot-sys/enc-aes256-ec256"]
enc-x25519 = ["mcuboot-sys/enc-x25519"]
enc-aes256-x25519 = ["mcuboot-sys/enc-aes256-x25519"]
bootstrap = ["mcuboot-sys/bootstrap"]
multiimage = ["mcuboot-sys/multiimage"]
large-write = []
@@ -41,6 +45,7 @@ untrusted = "0.7"
pem = "0.8"
aes-ctr = "0.4.0"
base64 = "0.12.0"
typenum = "1.13.0"

# The simulator runs very slowly without optimization.  A value of 1
# compiles in about half the time, but runs about 5-6 times slower.  2
+13 −0
Changes for sim/mcuboot-sys/Cargo.toml: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -38,18 +38,30 @@ validate-primary-slot = []
# Encrypt image in the secondary slot using RSA-OAEP-2048
enc-rsa = []

# Encrypt  image in the secondary slot using AES-256-CTR and RSA-OAEP-2048
enc-aes256-rsa = []

# Encrypt image in the secondary slot using AES-KW-128
enc-kw = []

# Encrypt image in the secondary slot using AES-256-CTR and AES-KW-256
enc-aes256-kw = []

# Encrypt image in the secondary slot using ECIES-P256
enc-ec256 = []

# Encrypt image in the secondary slot using AES-256-CTR and ECIES-P256
enc-aes256-ec256 = []

# Encrypt image in the secondary slot using ECIES-P256 using Mbed TLS
enc-ec256-mbedtls = []

# Encrypt image in the secondary slot using ECIES-X25519
enc-x25519 = []

# Encrypt image in the secondary slot using AES-256-CTR and ECIES-X25519
enc-aes256-x25519 = []

# Allow bootstrapping an empty/invalid primary slot from a valid secondary slot
bootstrap = []

@@ -59,6 +71,7 @@ multiimage = []
# Check (in software) against version downgrades.
downgrade-prevention = []


[build-dependencies]
cc = "1.0.25"

+43 −6
Changes for sim/mcuboot-sys/build.rs: 43 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -19,10 +19,14 @@ fn main() {
    let validate_primary_slot =
                  env::var("CARGO_FEATURE_VALIDATE_PRIMARY_SLOT").is_ok();
    let enc_rsa = env::var("CARGO_FEATURE_ENC_RSA").is_ok();
    let enc_aes256_rsa = env::var("CARGO_FEATURE_ENC_AES256_RSA").is_ok();
    let enc_kw = env::var("CARGO_FEATURE_ENC_KW").is_ok();
    let enc_aes256_kw = env::var("CARGO_FEATURE_ENC_AES256_KW").is_ok();
    let enc_ec256 = env::var("CARGO_FEATURE_ENC_EC256").is_ok();
    let enc_ec256_mbedtls = env::var("CARGO_FEATURE_ENC_EC256_MBEDTLS").is_ok();
    let enc_aes256_ec256 = env::var("CARGO_FEATURE_ENC_AES256_EC256").is_ok();
    let enc_x25519 = env::var("CARGO_FEATURE_ENC_X25519").is_ok();
    let enc_aes256_x25519 = env::var("CARGO_FEATURE_ENC_AES256_X25519").is_ok();
    let bootstrap = env::var("CARGO_FEATURE_BOOTSTRAP").is_ok();
    let multiimage = env::var("CARGO_FEATURE_MULTIIMAGE").is_ok();
    let downgrade_prevention = env::var("CARGO_FEATURE_DOWNGRADE_PREVENTION").is_ok();
@@ -148,7 +152,10 @@ fn main() {
        conf.define("MCUBOOT_SWAP_USING_SCRATCH", None);
    }

    if enc_rsa {
    if enc_rsa || enc_aes256_rsa {
        if enc_aes256_rsa {
                conf.define("MCUBOOT_AES_256", None);
        }
        conf.define("MCUBOOT_ENCRYPT_RSA", None);
        conf.define("MCUBOOT_ENC_IMAGES", None);
        conf.define("MCUBOOT_USE_MBED_TLS", None);
@@ -169,7 +176,10 @@ fn main() {
        conf.file("../../ext/mbedtls/crypto/library/asn1parse.c");
    }

    if enc_kw {
    if enc_kw || enc_aes256_kw {
        if enc_aes256_kw {
            conf.define("MCUBOOT_AES_256", None);
        }
        conf.define("MCUBOOT_ENCRYPT_KW", None);
        conf.define("MCUBOOT_ENC_IMAGES", None);

@@ -234,7 +244,10 @@ fn main() {
        conf.file("../../ext/tinycrypt/lib/source/ctr_mode.c");
        conf.file("../../ext/tinycrypt/lib/source/hmac.c");
        conf.file("../../ext/tinycrypt/lib/source/ecc_dh.c");
    } else if enc_ec256_mbedtls {
    } else if enc_ec256_mbedtls || enc_aes256_ec256 {
        if enc_aes256_ec256 {
            conf.define("MCUBOOT_AES_256", None);
        }
        conf.define("MCUBOOT_ENCRYPT_EC256", None);
        conf.define("MCUBOOT_ENC_IMAGES", None);
        conf.define("MCUBOOT_USE_MBED_TLS", None);
@@ -283,18 +296,42 @@ fn main() {
        conf.file("../../ext/tinycrypt/lib/source/hmac.c");
    }

    else if enc_aes256_x25519 {
        conf.define("MCUBOOT_AES_256", None);
        conf.define("MCUBOOT_ENCRYPT_X25519", None);
        conf.define("MCUBOOT_ENC_IMAGES", None);
        conf.define("MCUBOOT_USE_MBED_TLS", None);
        conf.define("MCUBOOT_SWAP_SAVE_ENCTLV", None);

        conf.file("../../boot/bootutil/src/encrypted.c");
        conf.file("csupport/keys.c");

        conf.include("../../ext/mbedtls/crypto/include");
        conf.file("../../ext/fiat/src/curve25519.c");
        conf.file("../../ext/mbedtls-asn1/src/platform_util.c");
        conf.file("../../ext/mbedtls-asn1/src/asn1parse.c");
        conf.file("../../ext/mbedtls/crypto/library/platform.c");
        conf.file("../../ext/mbedtls/crypto/library/platform_util.c");
        conf.file("../../ext/mbedtls/crypto/library/aes.c");
        conf.file("../../ext/mbedtls/crypto/library/sha256.c");
        conf.file("../../ext/mbedtls/crypto/library/md.c");
        conf.file("../../ext/mbedtls/crypto/library/sha512.c");
    }

    if sig_rsa && enc_kw {
        conf.define("MBEDTLS_CONFIG_FILE", Some("<config-rsa-kw.h>"));
    } else if sig_rsa || sig_rsa3072 || enc_rsa {
    } else if sig_rsa || sig_rsa3072 || enc_rsa || enc_aes256_rsa {
        conf.define("MBEDTLS_CONFIG_FILE", Some("<config-rsa.h>"));
    } else if sig_ecdsa_mbedtls || enc_ec256_mbedtls {
    } else if sig_ecdsa_mbedtls || enc_ec256_mbedtls || enc_aes256_ec256 {
        conf.define("MBEDTLS_CONFIG_FILE", Some("<config-ec.h>"));
    } else if (sig_ecdsa || enc_ec256) && !enc_kw {
        conf.define("MBEDTLS_CONFIG_FILE", Some("<config-asn1.h>"));
    } else if sig_ed25519 || enc_x25519 {
        conf.define("MBEDTLS_CONFIG_FILE", Some("<config-asn1.h>"));
    } else if enc_kw {
    } else if enc_kw || enc_aes256_kw {
        conf.define("MBEDTLS_CONFIG_FILE", Some("<config-kw.h>"));
    } else if enc_aes256_x25519 {
        conf.define("MBEDTLS_CONFIG_FILE", Some("<config-ed25519.h>"));
    }

    conf.file("../../boot/bootutil/src/image_validate.c");
+9 −0
Changes for sim/mcuboot-sys/csupport/keys.c: 9 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -256,11 +256,20 @@ const struct bootutil_key bootutil_enc_key = {
#endif

#if defined(MCUBOOT_ENCRYPT_KW)
#if defined(MCUBOOT_AES_256)
unsigned char enc_key[] = {
  0xE4, 0x5C, 0x51, 0x46, 0xD2, 0x1C, 0x82, 0x35, 0xCC, 0x1A, 0x19, 0xAF,
  0xA1, 0xF2, 0xAA, 0x20, 0xC8, 0x8C, 0x7F, 0x40, 0x6C, 0xDB, 0x22, 0xAA,
  0x6A, 0xB5, 0xCB, 0xAA, 0xF8, 0xB1, 0x5B, 0xB4
};
static unsigned int enc_key_len = 32;
#else
unsigned char enc_key[] = {
  0xd1, 0x5a, 0x04, 0x95, 0xc4, 0xc2, 0xa8, 0xff, 0x30, 0x78, 0xce, 0x49,
  0xb5, 0xfc, 0xb2, 0xdd
};
static unsigned int enc_key_len = 16;
#endif
const struct bootutil_key bootutil_enc_key = {
    .key = enc_key,
    .len = &enc_key_len,
Loading