Commit 22a46b2d authored by Marko Kiiskila's avatar Marko Kiiskila Committed by David Brown
Browse files

Remove PKCSv1.5 sig format option from RSA

Since we are changing the image header format, there is no reason to
continue to support the old PKCS#1 v1.5 signatures.  Remove the
definitions, and conditional complication related to this, and only
support the newer PSS signatures.

Signed-off-by: default avatarMarko Kiiskila <marko@runtime.io>
Signed-off-by: default avatarDavid Brown <david.brown@linaro.org>
parent 833005e2
Loading
Loading
Loading
Loading
−4
Changes for Makefile: 0 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -12,10 +12,6 @@
CONF_FILE = boot/zephyr/prj.conf
CFLAGS += -DMCUBOOT_SIGN_RSA -DMCUBOOT_USE_MBED_TLS

# Newer uses should use the RSA-PSS signature algorithm.  This define
# enables (and requires) this type of signature.
#CFLAGS += -DMCUBOOT_RSA_PKCS1_15

# ECDSA P-256
#CONF_FILE = boot/zephyr/prj-p256.conf
#CFLAGS += -DMCUBOOT_SIGN_EC256 -DMCUBOOT_USE_TINYCRYPT
−60
Changes for boot/bootutil/src/image_rsa.c: 0 added lines, 60 removed lines.
Original line number Diff line number Diff line
@@ -32,15 +32,6 @@

#include "bootutil_priv.h"

#ifdef  MCUBOOT_RSA_PKCS1_15
static const uint8_t sha256_oid[] = {
    0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
    0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
    0x00, 0x04, 0x20
};
#endif

#ifndef MCUBOOT_RSA_PKCS1_15
/*
 * Constants for this particular constrained implementation of
 * RSA-PSS.  In particular, we support RSA 2048, with a SHA256 hash,
@@ -70,7 +61,6 @@ static const uint8_t sha256_oid[] = {
#define PSS_MASK_SALT_POS   (PSS_MASK_ONE_POS + 1)

static const uint8_t pss_zeros[8] = {0};
#endif

/*
 * Parse the public key used for signing. Simple RSA format.
@@ -108,7 +98,6 @@ bootutil_parse_rsakey(mbedtls_rsa_context *ctx, uint8_t **p, uint8_t *end)
    return 0;
}

#ifndef MCUBOOT_RSA_PKCS1_15
/*
 * Compute the RSA-PSS mask-generation function, MGF1.  Assumptions
 * are that the mask length will be less than 256 * PSS_HLEN, and
@@ -263,55 +252,6 @@ bootutil_cmp_rsasig(mbedtls_rsa_context *ctx, uint8_t *hash, uint32_t hlen,

    return 0;
}
#else /* MCUBOOT_RSA_PKCS1_15 */
/*
 * PKCS1.5 using RSA2048 computed over SHA256.
 */
static int
bootutil_cmp_rsasig(mbedtls_rsa_context *ctx, uint8_t *hash, uint32_t hlen,
  uint8_t *sig)
{
    uint8_t buf[MBEDTLS_MPI_MAX_SIZE];
    uint8_t *p;

    if (ctx->len != 256) {
        return -1;
    }

    if (mbedtls_rsa_public(ctx, sig, buf)) {
        return -1;
    }

    p = buf;

    if (*p++ != 0 || *p++ != MBEDTLS_RSA_SIGN) {
        return -1;
    }

    while (*p != 0) {
        if (p >= buf + ctx->len - 1 || *p != 0xFF) {
            return -1;
        }
        p++;
    }
    p++;

    if ((p - buf) + sizeof(sha256_oid) + hlen != ctx->len) {
        return -1;
    }

    if (memcmp(p, sha256_oid, sizeof(sha256_oid))) {
        return -1;
    }
    p += sizeof(sha256_oid);

    if (memcmp(p, hash, hlen)) {
        return -1;
    }

    return 0;
}
#endif

int
bootutil_verify_sig(uint8_t *hash, uint32_t hlen, uint8_t *sig, int slen,
−3
Changes for boot/mynewt/mcuboot_config/include/mcuboot_config/mcuboot_config.h: 0 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -33,9 +33,6 @@
#if MYNEWT_VAL(BOOTUTIL_SIGN_RSA)
#define MCUBOOT_SIGN_RSA 1
#endif
#if MYNEWT_VAL(BOOTUTIL_RSA_PKCS1_15)
#define MCUBOOT_RSA_PKCS1_15 1
#endif
#if MYNEWT_VAL(BOOTUTIL_SIGN_EC)
#define MCUBOOT_SIGN_EC 1
#endif
−3
Changes for boot/mynewt/mcuboot_config/syscfg.yml: 0 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -25,9 +25,6 @@ syscfg.defs:
    BOOTUTIL_SIGN_RSA:
        description: 'Images are signed using RSA2048.'
        value: 0
    BOOTUTIL_RSA_PKCS1_15:
        description: 'Sign using old PKCS#1 1.5 (otherwise uses PSS)'
        value: 0
    BOOTUTIL_SIGN_EC:
        description: 'Images are signed using ECDSA NIST P-224.'
        value: 0