Example #1
0
    if (sign == 'auto'):
        print("'rsa2048' key autodetected.")
    elif (sign != 'rsa2048'):
        print("Error: key size %d too large for the selected cipher" %
              wolfboot_key_buffer_len)
else:
    print("Error: key size does not match any cipher")
    sys.exit(2)

if sign == 'none':
    privkey = None
    pubkey = None
elif not sha_only and not manual_sign:
    ''' import (decode) private key for signing '''
    if sign == 'ed25519':
        ed = ciphers.Ed25519Private(key=wolfboot_key_buffer)
        privkey, pubkey = ed.encode_key()

    if sign == 'ed448':
        HDR_SIGNATURE_LEN = 114
        if WOLFBOOT_HEADER_SIZE < 512:
            print("Ed448: header size increased to 512")
            WOLFBOOT_HEADER_SIZE = 512
        ed = ciphers.Ed448Private(key=wolfboot_key_buffer)
        privkey, pubkey = ed.encode_key()

    if sign == 'ecc256':
        ecc = ciphers.EccPrivate()
        ecc.decode_key_raw(wolfboot_key_buffer[0:32],
                           wolfboot_key_buffer[32:64],
                           wolfboot_key_buffer[64:])
Example #2
0
    if sign == 'auto':
        sign = 'ed25519'
        print("'ed25519' key autodetected.")
elif wolfboot_private_key_len == 96:
    if (sign == 'ed25519'):
        print("Error: key size does not match the cipher selected")
        sys.exit(1)
    if sign == 'auto':
        sign = 'ecc256'
        print("'ecc256' key autodetected.")
else:
    print("Error: key size does not match any cipher")
    sys.exit(2)

if sign == 'ed25519':
    ed = ciphers.Ed25519Private(key=wolfboot_private_key)
    privkey, pubkey = ed.encode_key()

if sign == 'ecc256':
    ecc = ciphers.EccPrivate()
    ecc.decode_key_raw(wolfboot_private_key[0:31], wolfboot_private_key[32:63],
                       wolfboot_private_key[64:])
    pubkey = wolfboot_private_key[0:64]

img_size = os.path.getsize(image_file)
# Magic header (spells 'WOLF')
header = struct.pack('<L', WOLFBOOT_MAGIC)
# Image size
header += struct.pack('<L', img_size)

# Two pad bytes so version is aligned